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

USB: add platform glue driver for FSL USB DR controller

Replace FSL USB platform code by simple platform driver for
creation of FSL USB platform devices.

The driver creates platform devices based on the information
from USB nodes in the flat device tree. This is the replacement
for old arch fsl_soc usb code removed by this patch. The driver
uses usual of-style binding, available EHCI-HCD and UDC
drivers can be bound to the created devices. The new of-style
driver additionaly instantiates USB OTG platform device, as the
appropriate USB OTG driver will be added soon.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Cc: Kumar Gala <galak@kernel.crashing.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Anatolij Gustschin and committed by
Greg Kroah-Hartman
126512e3 99c1e4f8

+225 -163
-163
arch/powerpc/sysdev/fsl_soc.c
··· 209 209 arch_initcall(of_add_fixed_phys); 210 210 #endif /* CONFIG_FIXED_PHY */ 211 211 212 - static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type) 213 - { 214 - if (!phy_type) 215 - return FSL_USB2_PHY_NONE; 216 - if (!strcasecmp(phy_type, "ulpi")) 217 - return FSL_USB2_PHY_ULPI; 218 - if (!strcasecmp(phy_type, "utmi")) 219 - return FSL_USB2_PHY_UTMI; 220 - if (!strcasecmp(phy_type, "utmi_wide")) 221 - return FSL_USB2_PHY_UTMI_WIDE; 222 - if (!strcasecmp(phy_type, "serial")) 223 - return FSL_USB2_PHY_SERIAL; 224 - 225 - return FSL_USB2_PHY_NONE; 226 - } 227 - 228 - static int __init fsl_usb_of_init(void) 229 - { 230 - struct device_node *np; 231 - unsigned int i = 0; 232 - struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, 233 - *usb_dev_dr_client = NULL; 234 - int ret; 235 - 236 - for_each_compatible_node(np, NULL, "fsl-usb2-mph") { 237 - struct resource r[2]; 238 - struct fsl_usb2_platform_data usb_data; 239 - const unsigned char *prop = NULL; 240 - 241 - memset(&r, 0, sizeof(r)); 242 - memset(&usb_data, 0, sizeof(usb_data)); 243 - 244 - ret = of_address_to_resource(np, 0, &r[0]); 245 - if (ret) 246 - goto err; 247 - 248 - of_irq_to_resource(np, 0, &r[1]); 249 - 250 - usb_dev_mph = 251 - platform_device_register_simple("fsl-ehci", i, r, 2); 252 - if (IS_ERR(usb_dev_mph)) { 253 - ret = PTR_ERR(usb_dev_mph); 254 - goto err; 255 - } 256 - 257 - usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; 258 - usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; 259 - 260 - usb_data.operating_mode = FSL_USB2_MPH_HOST; 261 - 262 - prop = of_get_property(np, "port0", NULL); 263 - if (prop) 264 - usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; 265 - 266 - prop = of_get_property(np, "port1", NULL); 267 - if (prop) 268 - usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; 269 - 270 - prop = of_get_property(np, "phy_type", NULL); 271 - usb_data.phy_mode = determine_usb_phy(prop); 272 - 273 - ret = 274 - platform_device_add_data(usb_dev_mph, &usb_data, 275 - sizeof(struct 276 - fsl_usb2_platform_data)); 277 - if (ret) 278 - goto unreg_mph; 279 - i++; 280 - } 281 - 282 - for_each_compatible_node(np, NULL, "fsl-usb2-dr") { 283 - struct resource r[2]; 284 - struct fsl_usb2_platform_data usb_data; 285 - const unsigned char *prop = NULL; 286 - 287 - if (!of_device_is_available(np)) 288 - continue; 289 - 290 - memset(&r, 0, sizeof(r)); 291 - memset(&usb_data, 0, sizeof(usb_data)); 292 - 293 - ret = of_address_to_resource(np, 0, &r[0]); 294 - if (ret) 295 - goto unreg_mph; 296 - 297 - of_irq_to_resource(np, 0, &r[1]); 298 - 299 - prop = of_get_property(np, "dr_mode", NULL); 300 - 301 - if (!prop || !strcmp(prop, "host")) { 302 - usb_data.operating_mode = FSL_USB2_DR_HOST; 303 - usb_dev_dr_host = platform_device_register_simple( 304 - "fsl-ehci", i, r, 2); 305 - if (IS_ERR(usb_dev_dr_host)) { 306 - ret = PTR_ERR(usb_dev_dr_host); 307 - goto err; 308 - } 309 - } else if (prop && !strcmp(prop, "peripheral")) { 310 - usb_data.operating_mode = FSL_USB2_DR_DEVICE; 311 - usb_dev_dr_client = platform_device_register_simple( 312 - "fsl-usb2-udc", i, r, 2); 313 - if (IS_ERR(usb_dev_dr_client)) { 314 - ret = PTR_ERR(usb_dev_dr_client); 315 - goto err; 316 - } 317 - } else if (prop && !strcmp(prop, "otg")) { 318 - usb_data.operating_mode = FSL_USB2_DR_OTG; 319 - usb_dev_dr_host = platform_device_register_simple( 320 - "fsl-ehci", i, r, 2); 321 - if (IS_ERR(usb_dev_dr_host)) { 322 - ret = PTR_ERR(usb_dev_dr_host); 323 - goto err; 324 - } 325 - usb_dev_dr_client = platform_device_register_simple( 326 - "fsl-usb2-udc", i, r, 2); 327 - if (IS_ERR(usb_dev_dr_client)) { 328 - ret = PTR_ERR(usb_dev_dr_client); 329 - goto err; 330 - } 331 - } else { 332 - ret = -EINVAL; 333 - goto err; 334 - } 335 - 336 - prop = of_get_property(np, "phy_type", NULL); 337 - usb_data.phy_mode = determine_usb_phy(prop); 338 - 339 - if (usb_dev_dr_host) { 340 - usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; 341 - usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> 342 - dev.coherent_dma_mask; 343 - if ((ret = platform_device_add_data(usb_dev_dr_host, 344 - &usb_data, sizeof(struct 345 - fsl_usb2_platform_data)))) 346 - goto unreg_dr; 347 - } 348 - if (usb_dev_dr_client) { 349 - usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; 350 - usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> 351 - dev.coherent_dma_mask; 352 - if ((ret = platform_device_add_data(usb_dev_dr_client, 353 - &usb_data, sizeof(struct 354 - fsl_usb2_platform_data)))) 355 - goto unreg_dr; 356 - } 357 - i++; 358 - } 359 - return 0; 360 - 361 - unreg_dr: 362 - if (usb_dev_dr_host) 363 - platform_device_unregister(usb_dev_dr_host); 364 - if (usb_dev_dr_client) 365 - platform_device_unregister(usb_dev_dr_client); 366 - unreg_mph: 367 - if (usb_dev_mph) 368 - platform_device_unregister(usb_dev_mph); 369 - err: 370 - return ret; 371 - } 372 - 373 - arch_initcall(fsl_usb_of_init); 374 - 375 212 #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx) 376 213 static __be32 __iomem *rstcr; 377 214
+1
drivers/usb/gadget/Kconfig
··· 158 158 boolean "Freescale Highspeed USB DR Peripheral Controller" 159 159 depends on FSL_SOC || ARCH_MXC 160 160 select USB_GADGET_DUALSPEED 161 + select USB_FSL_MPH_DR_OF 161 162 help 162 163 Some of Freescale PowerPC processors have a High Speed 163 164 Dual-Role(DR) USB controller, which supports device mode.
+4
drivers/usb/host/Kconfig
··· 112 112 support both high speed and full speed devices, or high speed 113 113 devices only. 114 114 115 + config USB_FSL_MPH_DR_OF 116 + tristate 117 + 115 118 config USB_EHCI_FSL 116 119 bool "Support for Freescale on-chip EHCI USB controller" 117 120 depends on USB_EHCI_HCD && FSL_SOC 118 121 select USB_EHCI_ROOT_HUB_TT 122 + select USB_FSL_MPH_DR_OF 119 123 ---help--- 120 124 Variation of ARC USB block used in some Freescale chips. 121 125
+1
drivers/usb/host/Makefile
··· 31 31 obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o 32 32 obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o 33 33 obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o 34 + obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o 34 35
+219
drivers/usb/host/fsl-mph-dr-of.c
··· 1 + /* 2 + * Setup platform devices needed by the Freescale multi-port host 3 + * and/or dual-role USB controller modules based on the description 4 + * in flat device tree. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License as published by the 8 + * Free Software Foundation; either version 2 of the License, or (at your 9 + * option) any later version. 10 + */ 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/fsl_devices.h> 15 + #include <linux/err.h> 16 + #include <linux/io.h> 17 + #include <linux/of_platform.h> 18 + 19 + struct fsl_usb2_dev_data { 20 + char *dr_mode; /* controller mode */ 21 + char *drivers[3]; /* drivers to instantiate for this mode */ 22 + enum fsl_usb2_operating_modes op_mode; /* operating mode */ 23 + }; 24 + 25 + struct fsl_usb2_dev_data dr_mode_data[] __devinitdata = { 26 + { 27 + .dr_mode = "host", 28 + .drivers = { "fsl-ehci", NULL, NULL, }, 29 + .op_mode = FSL_USB2_DR_HOST, 30 + }, 31 + { 32 + .dr_mode = "otg", 33 + .drivers = { "fsl-usb2-otg", "fsl-ehci", "fsl-usb2-udc", }, 34 + .op_mode = FSL_USB2_DR_OTG, 35 + }, 36 + { 37 + .dr_mode = "peripheral", 38 + .drivers = { "fsl-usb2-udc", NULL, NULL, }, 39 + .op_mode = FSL_USB2_DR_DEVICE, 40 + }, 41 + }; 42 + 43 + struct fsl_usb2_dev_data * __devinit get_dr_mode_data(struct device_node *np) 44 + { 45 + const unsigned char *prop; 46 + int i; 47 + 48 + prop = of_get_property(np, "dr_mode", NULL); 49 + if (prop) { 50 + for (i = 0; i < ARRAY_SIZE(dr_mode_data); i++) { 51 + if (!strcmp(prop, dr_mode_data[i].dr_mode)) 52 + return &dr_mode_data[i]; 53 + } 54 + } 55 + pr_warn("%s: Invalid 'dr_mode' property, fallback to host mode\n", 56 + np->full_name); 57 + return &dr_mode_data[0]; /* mode not specified, use host */ 58 + } 59 + 60 + static enum fsl_usb2_phy_modes __devinit determine_usb_phy(const char *phy_type) 61 + { 62 + if (!phy_type) 63 + return FSL_USB2_PHY_NONE; 64 + if (!strcasecmp(phy_type, "ulpi")) 65 + return FSL_USB2_PHY_ULPI; 66 + if (!strcasecmp(phy_type, "utmi")) 67 + return FSL_USB2_PHY_UTMI; 68 + if (!strcasecmp(phy_type, "utmi_wide")) 69 + return FSL_USB2_PHY_UTMI_WIDE; 70 + if (!strcasecmp(phy_type, "serial")) 71 + return FSL_USB2_PHY_SERIAL; 72 + 73 + return FSL_USB2_PHY_NONE; 74 + } 75 + 76 + struct platform_device * __devinit fsl_usb2_device_register( 77 + struct platform_device *ofdev, 78 + struct fsl_usb2_platform_data *pdata, 79 + const char *name, int id) 80 + { 81 + struct platform_device *pdev; 82 + const struct resource *res = ofdev->resource; 83 + unsigned int num = ofdev->num_resources; 84 + int retval; 85 + 86 + pdev = platform_device_alloc(name, id); 87 + if (!pdev) { 88 + retval = -ENOMEM; 89 + goto error; 90 + } 91 + 92 + pdev->dev.parent = &ofdev->dev; 93 + 94 + pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask; 95 + pdev->dev.dma_mask = &pdev->archdata.dma_mask; 96 + *pdev->dev.dma_mask = *ofdev->dev.dma_mask; 97 + 98 + retval = platform_device_add_data(pdev, pdata, sizeof(*pdata)); 99 + if (retval) 100 + goto error; 101 + 102 + if (num) { 103 + retval = platform_device_add_resources(pdev, res, num); 104 + if (retval) 105 + goto error; 106 + } 107 + 108 + retval = platform_device_add(pdev); 109 + if (retval) 110 + goto error; 111 + 112 + return pdev; 113 + 114 + error: 115 + platform_device_put(pdev); 116 + return ERR_PTR(retval); 117 + } 118 + 119 + static const struct of_device_id fsl_usb2_mph_dr_of_match[]; 120 + 121 + static int __devinit fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev) 122 + { 123 + struct device_node *np = ofdev->dev.of_node; 124 + struct platform_device *usb_dev; 125 + struct fsl_usb2_platform_data data, *pdata; 126 + struct fsl_usb2_dev_data *dev_data; 127 + const struct of_device_id *match; 128 + const unsigned char *prop; 129 + static unsigned int idx; 130 + int i; 131 + 132 + if (!of_device_is_available(np)) 133 + return -ENODEV; 134 + 135 + match = of_match_device(fsl_usb2_mph_dr_of_match, &ofdev->dev); 136 + if (!match) 137 + return -ENODEV; 138 + 139 + pdata = &data; 140 + if (match->data) 141 + memcpy(pdata, match->data, sizeof(data)); 142 + else 143 + memset(pdata, 0, sizeof(data)); 144 + 145 + dev_data = get_dr_mode_data(np); 146 + 147 + if (of_device_is_compatible(np, "fsl-usb2-mph")) { 148 + if (of_get_property(np, "port0", NULL)) 149 + pdata->port_enables |= FSL_USB2_PORT0_ENABLED; 150 + 151 + if (of_get_property(np, "port1", NULL)) 152 + pdata->port_enables |= FSL_USB2_PORT1_ENABLED; 153 + 154 + pdata->operating_mode = FSL_USB2_MPH_HOST; 155 + } else { 156 + /* setup mode selected in the device tree */ 157 + pdata->operating_mode = dev_data->op_mode; 158 + } 159 + 160 + prop = of_get_property(np, "phy_type", NULL); 161 + pdata->phy_mode = determine_usb_phy(prop); 162 + 163 + for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) { 164 + if (!dev_data->drivers[i]) 165 + continue; 166 + usb_dev = fsl_usb2_device_register(ofdev, pdata, 167 + dev_data->drivers[i], idx); 168 + if (IS_ERR(usb_dev)) { 169 + dev_err(&ofdev->dev, "Can't register usb device\n"); 170 + return PTR_ERR(usb_dev); 171 + } 172 + } 173 + idx++; 174 + return 0; 175 + } 176 + 177 + static int __devexit __unregister_subdev(struct device *dev, void *d) 178 + { 179 + platform_device_unregister(to_platform_device(dev)); 180 + return 0; 181 + } 182 + 183 + static int __devexit fsl_usb2_mph_dr_of_remove(struct platform_device *ofdev) 184 + { 185 + device_for_each_child(&ofdev->dev, NULL, __unregister_subdev); 186 + return 0; 187 + } 188 + 189 + static const struct of_device_id fsl_usb2_mph_dr_of_match[] = { 190 + { .compatible = "fsl-usb2-mph", }, 191 + { .compatible = "fsl-usb2-dr", }, 192 + {}, 193 + }; 194 + 195 + static struct platform_driver fsl_usb2_mph_dr_driver = { 196 + .driver = { 197 + .name = "fsl-usb2-mph-dr", 198 + .owner = THIS_MODULE, 199 + .of_match_table = fsl_usb2_mph_dr_of_match, 200 + }, 201 + .probe = fsl_usb2_mph_dr_of_probe, 202 + .remove = __devexit_p(fsl_usb2_mph_dr_of_remove), 203 + }; 204 + 205 + static int __init fsl_usb2_mph_dr_init(void) 206 + { 207 + return platform_driver_register(&fsl_usb2_mph_dr_driver); 208 + } 209 + module_init(fsl_usb2_mph_dr_init); 210 + 211 + static void __exit fsl_usb2_mph_dr_exit(void) 212 + { 213 + platform_driver_unregister(&fsl_usb2_mph_dr_driver); 214 + } 215 + module_exit(fsl_usb2_mph_dr_exit); 216 + 217 + MODULE_DESCRIPTION("FSL MPH DR OF devices driver"); 218 + MODULE_AUTHOR("Anatolij Gustschin <agust@denx.de>"); 219 + MODULE_LICENSE("GPL");