Skip to content

Commit 01cced2

Browse files
kumargalagregkh
authored andcommitted
[PATCH] USB: allow multiple types of EHCI controllers to be built as modules
In some systems we may have both a platform EHCI controller and PCI EHCI controller. Previously we couldn't build the EHCI support as a module due to conflicting module_init() calls in the code. Signed-off-by: Kumar Gala <[email protected]> Signed-off-by: David Brownell <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent df47e53 commit 01cced2

File tree

6 files changed

+78
-116
lines changed

6 files changed

+78
-116
lines changed

arch/powerpc/sysdev/fsl_soc.c

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static int __init fsl_usb_of_init(void)
372372
{
373373
struct device_node *np;
374374
unsigned int i;
375-
struct platform_device *usb_dev;
375+
struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
376376
int ret;
377377

378378
for (np = NULL, i = 0;
@@ -393,15 +393,15 @@ static int __init fsl_usb_of_init(void)
393393
r[1].end = np->intrs[0].line;
394394
r[1].flags = IORESOURCE_IRQ;
395395

396-
usb_dev =
397-
platform_device_register_simple("fsl-usb2-mph", i, r, 2);
398-
if (IS_ERR(usb_dev)) {
399-
ret = PTR_ERR(usb_dev);
396+
usb_dev_mph =
397+
platform_device_register_simple("fsl-ehci", i, r, 2);
398+
if (IS_ERR(usb_dev_mph)) {
399+
ret = PTR_ERR(usb_dev_mph);
400400
goto err;
401401
}
402402

403-
usb_dev->dev.coherent_dma_mask = 0xffffffffUL;
404-
usb_dev->dev.dma_mask = &usb_dev->dev.coherent_dma_mask;
403+
usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
404+
usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
405405

406406
usb_data.operating_mode = FSL_USB2_MPH_HOST;
407407

@@ -417,31 +417,14 @@ static int __init fsl_usb_of_init(void)
417417
usb_data.phy_mode = determine_usb_phy(prop);
418418

419419
ret =
420-
platform_device_add_data(usb_dev, &usb_data,
420+
platform_device_add_data(usb_dev_mph, &usb_data,
421421
sizeof(struct
422422
fsl_usb2_platform_data));
423423
if (ret)
424-
goto unreg;
424+
goto unreg_mph;
425425
}
426426

427-
return 0;
428-
429-
unreg:
430-
platform_device_unregister(usb_dev);
431-
err:
432-
return ret;
433-
}
434-
435-
arch_initcall(fsl_usb_of_init);
436-
437-
static int __init fsl_usb_dr_of_init(void)
438-
{
439-
struct device_node *np;
440-
unsigned int i;
441-
struct platform_device *usb_dev;
442-
int ret;
443-
444-
for (np = NULL, i = 0;
427+
for (np = NULL;
445428
(np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
446429
i++) {
447430
struct resource r[2];
@@ -453,41 +436,44 @@ static int __init fsl_usb_dr_of_init(void)
453436

454437
ret = of_address_to_resource(np, 0, &r[0]);
455438
if (ret)
456-
goto err;
439+
goto unreg_mph;
457440

458441
r[1].start = np->intrs[0].line;
459442
r[1].end = np->intrs[0].line;
460443
r[1].flags = IORESOURCE_IRQ;
461444

462-
usb_dev =
463-
platform_device_register_simple("fsl-usb2-dr", i, r, 2);
464-
if (IS_ERR(usb_dev)) {
465-
ret = PTR_ERR(usb_dev);
445+
usb_dev_dr =
446+
platform_device_register_simple("fsl-ehci", i, r, 2);
447+
if (IS_ERR(usb_dev_dr)) {
448+
ret = PTR_ERR(usb_dev_dr);
466449
goto err;
467450
}
468451

469-
usb_dev->dev.coherent_dma_mask = 0xffffffffUL;
470-
usb_dev->dev.dma_mask = &usb_dev->dev.coherent_dma_mask;
452+
usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
453+
usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
471454

472455
usb_data.operating_mode = FSL_USB2_DR_HOST;
473456

474457
prop = get_property(np, "phy_type", NULL);
475458
usb_data.phy_mode = determine_usb_phy(prop);
476459

477460
ret =
478-
platform_device_add_data(usb_dev, &usb_data,
461+
platform_device_add_data(usb_dev_dr, &usb_data,
479462
sizeof(struct
480463
fsl_usb2_platform_data));
481464
if (ret)
482-
goto unreg;
465+
goto unreg_dr;
483466
}
484-
485467
return 0;
486468

487-
unreg:
488-
platform_device_unregister(usb_dev);
469+
unreg_dr:
470+
if (usb_dev_dr)
471+
platform_device_unregister(usb_dev_dr);
472+
unreg_mph:
473+
if (usb_dev_mph)
474+
platform_device_unregister(usb_dev_mph);
489475
err:
490476
return ret;
491477
}
492478

493-
arch_initcall(fsl_usb_dr_of_init);
479+
arch_initcall(fsl_usb_of_init);

arch/ppc/syslib/mpc83xx_devices.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct platform_device ppc_sys_platform_devices[] = {
186186
},
187187
},
188188
[MPC83xx_USB2_DR] = {
189-
.name = "fsl-usb2-dr",
189+
.name = "fsl-ehci",
190190
.id = 1,
191191
.num_resources = 2,
192192
.resource = (struct resource[]) {
@@ -203,8 +203,8 @@ struct platform_device ppc_sys_platform_devices[] = {
203203
},
204204
},
205205
[MPC83xx_USB2_MPH] = {
206-
.name = "fsl-usb2-mph",
207-
.id = 1,
206+
.name = "fsl-ehci",
207+
.id = 2,
208208
.num_resources = 2,
209209
.resource = (struct resource[]) {
210210
{

drivers/usb/host/ehci-au1xxx.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
272272
return 0;
273273
}
274274
*/
275+
MODULE_ALIAS("au1xxx-ehci");
276+
/* FIXME use "struct platform_driver" */
275277
static struct device_driver ehci_hcd_au1xxx_driver = {
276278
.name = "au1xxx-ehci",
277279
.bus = &platform_bus_type,
@@ -280,18 +282,3 @@ static struct device_driver ehci_hcd_au1xxx_driver = {
280282
/*.suspend = ehci_hcd_au1xxx_drv_suspend, */
281283
/*.resume = ehci_hcd_au1xxx_drv_resume, */
282284
};
283-
284-
static int __init ehci_hcd_au1xxx_init(void)
285-
{
286-
pr_debug(DRIVER_INFO " (Au1xxx)\n");
287-
288-
return driver_register(&ehci_hcd_au1xxx_driver);
289-
}
290-
291-
static void __exit ehci_hcd_au1xxx_cleanup(void)
292-
{
293-
driver_unregister(&ehci_hcd_au1xxx_driver);
294-
}
295-
296-
module_init(ehci_hcd_au1xxx_init);
297-
module_exit(ehci_hcd_au1xxx_cleanup);

drivers/usb/host/ehci-fsl.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -324,43 +324,12 @@ static int ehci_fsl_drv_remove(struct platform_device *pdev)
324324
return 0;
325325
}
326326

327-
static struct platform_driver ehci_fsl_dr_driver = {
328-
.probe = ehci_fsl_drv_probe,
329-
.remove = ehci_fsl_drv_remove,
330-
.driver = {
331-
.name = "fsl-usb2-dr",
332-
},
333-
};
327+
MODULE_ALIAS("fsl-ehci");
334328

335-
static struct platform_driver ehci_fsl_mph_driver = {
329+
static struct platform_driver ehci_fsl_driver = {
336330
.probe = ehci_fsl_drv_probe,
337331
.remove = ehci_fsl_drv_remove,
338332
.driver = {
339-
.name = "fsl-usb2-mph",
333+
.name = "fsl-ehci",
340334
},
341335
};
342-
343-
static int __init ehci_fsl_init(void)
344-
{
345-
int retval;
346-
347-
pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
348-
hcd_name,
349-
sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
350-
sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
351-
352-
retval = platform_driver_register(&ehci_fsl_dr_driver);
353-
if (retval)
354-
return retval;
355-
356-
return platform_driver_register(&ehci_fsl_mph_driver);
357-
}
358-
359-
static void __exit ehci_fsl_cleanup(void)
360-
{
361-
platform_driver_unregister(&ehci_fsl_mph_driver);
362-
platform_driver_unregister(&ehci_fsl_dr_driver);
363-
}
364-
365-
module_init(ehci_fsl_init);
366-
module_exit(ehci_fsl_cleanup);

drivers/usb/host/ehci-hcd.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,19 +889,59 @@ MODULE_LICENSE ("GPL");
889889

890890
#ifdef CONFIG_PCI
891891
#include "ehci-pci.c"
892-
#define EHCI_BUS_GLUED
892+
#define PCI_DRIVER ehci_pci_driver
893893
#endif
894894

895895
#ifdef CONFIG_PPC_83xx
896896
#include "ehci-fsl.c"
897-
#define EHCI_BUS_GLUED
897+
#define PLATFORM_DRIVER ehci_fsl_driver
898898
#endif
899899

900900
#ifdef CONFIG_SOC_AU1X00
901901
#include "ehci-au1xxx.c"
902-
#define EHCI_BUS_GLUED
902+
#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
903903
#endif
904904

905-
#ifndef EHCI_BUS_GLUED
905+
#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER)
906906
#error "missing bus glue for ehci-hcd"
907907
#endif
908+
909+
static int __init ehci_hcd_init(void)
910+
{
911+
int retval = 0;
912+
913+
pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
914+
hcd_name,
915+
sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
916+
sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
917+
918+
#ifdef PLATFORM_DRIVER
919+
retval = platform_driver_register(&PLATFORM_DRIVER);
920+
if (retval < 0)
921+
return retval;
922+
#endif
923+
924+
#ifdef PCI_DRIVER
925+
retval = pci_register_driver(&PCI_DRIVER);
926+
if (retval < 0) {
927+
#ifdef PLATFORM_DRIVER
928+
platform_driver_unregister(&PLATFORM_DRIVER);
929+
#endif
930+
}
931+
#endif
932+
933+
return retval;
934+
}
935+
module_init(ehci_hcd_init);
936+
937+
static void __exit ehci_hcd_cleanup(void)
938+
{
939+
#ifdef PLATFORM_DRIVER
940+
platform_driver_unregister(&PLATFORM_DRIVER);
941+
#endif
942+
#ifdef PCI_DRIVER
943+
pci_unregister_driver(&PCI_DRIVER);
944+
#endif
945+
}
946+
module_exit(ehci_hcd_cleanup);
947+

drivers/usb/host/ehci-pci.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -379,23 +379,3 @@ static struct pci_driver ehci_pci_driver = {
379379
.resume = usb_hcd_pci_resume,
380380
#endif
381381
};
382-
383-
static int __init ehci_hcd_pci_init(void)
384-
{
385-
if (usb_disabled())
386-
return -ENODEV;
387-
388-
pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
389-
hcd_name,
390-
sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
391-
sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
392-
393-
return pci_register_driver(&ehci_pci_driver);
394-
}
395-
module_init(ehci_hcd_pci_init);
396-
397-
static void __exit ehci_hcd_pci_cleanup(void)
398-
{
399-
pci_unregister_driver(&ehci_pci_driver);
400-
}
401-
module_exit(ehci_hcd_pci_cleanup);

0 commit comments

Comments
 (0)