Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: nop-usb-xceiv: behave when linked as a module

The NOP OTG transceiver driver needs to be usable from modules.
Make sure its symbols are always accessible at both compile and
link time, and make sure the device instance is allocated from
the heap so that device lifetime rules are obeyed.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
cc835e32 def6f8b9

+12 -17
+10 -15
drivers/usb/otg/nop-usb-xceiv.c
··· 22 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 23 * 24 24 * Current status: 25 - * this is to add "nop" transceiver for all those phy which is 26 - * autonomous such as isp1504 etc. 25 + * This provides a "nop" transceiver for PHYs which are 26 + * autonomous such as isp1504, isp1707, etc. 27 27 */ 28 28 29 29 #include <linux/module.h> ··· 36 36 struct device *dev; 37 37 }; 38 38 39 - static u64 nop_xceiv_dmamask = DMA_BIT_MASK(32); 40 - 41 - static struct platform_device nop_xceiv_device = { 42 - .name = "nop_usb_xceiv", 43 - .id = -1, 44 - .dev = { 45 - .dma_mask = &nop_xceiv_dmamask, 46 - .coherent_dma_mask = DMA_BIT_MASK(32), 47 - .platform_data = NULL, 48 - }, 49 - }; 39 + static struct platform_device *pd; 50 40 51 41 void usb_nop_xceiv_register(void) 52 42 { 53 - if (platform_device_register(&nop_xceiv_device) < 0) { 43 + if (pd) 44 + return; 45 + pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0); 46 + if (!pd) { 54 47 printk(KERN_ERR "Unable to register usb nop transceiver\n"); 55 48 return; 56 49 } 57 50 } 51 + EXPORT_SYMBOL(usb_nop_xceiv_register); 58 52 59 53 void usb_nop_xceiv_unregister(void) 60 54 { 61 - platform_device_unregister(&nop_xceiv_device); 55 + platform_device_unregister(pd); 62 56 } 57 + EXPORT_SYMBOL(usb_nop_xceiv_unregister); 63 58 64 59 static inline struct nop_usb_xceiv *xceiv_to_nop(struct otg_transceiver *x) 65 60 {
+2 -2
include/linux/usb/otg.h
··· 80 80 81 81 /* for board-specific init logic */ 82 82 extern int otg_set_transceiver(struct otg_transceiver *); 83 - #ifdef CONFIG_NOP_USB_XCEIV 83 + 84 + /* sometimes transceivers are accessed only through e.g. ULPI */ 84 85 extern void usb_nop_xceiv_register(void); 85 86 extern void usb_nop_xceiv_unregister(void); 86 - #endif 87 87 88 88 89 89 /* for usb host and peripheral controller drivers */