.. | .. |
---|
7 | 7 | #include <linux/module.h> |
---|
8 | 8 | #include <linux/pci.h> |
---|
9 | 9 | #include <linux/delay.h> |
---|
| 10 | +#include <linux/dmi.h> |
---|
10 | 11 | #include <linux/errno.h> |
---|
| 12 | +#include <linux/gpio/consumer.h> |
---|
| 13 | +#include <linux/gpio/machine.h> |
---|
11 | 14 | #include <linux/list.h> |
---|
12 | 15 | #include <linux/interrupt.h> |
---|
13 | 16 | #include <linux/usb/ch9.h> |
---|
14 | 17 | #include <linux/usb/gadget.h> |
---|
15 | | -#include <linux/gpio.h> |
---|
16 | 18 | #include <linux/irq.h> |
---|
17 | | - |
---|
18 | | -/* GPIO port for VBUS detecting */ |
---|
19 | | -static int vbus_gpio_port = -1; /* GPIO port number (-1:Not used) */ |
---|
20 | 19 | |
---|
21 | 20 | #define PCH_VBUS_PERIOD 3000 /* VBUS polling period (msec) */ |
---|
22 | 21 | #define PCH_VBUS_INTERVAL 10 /* VBUS polling interval (msec) */ |
---|
.. | .. |
---|
229 | 228 | * for control data |
---|
230 | 229 | * @status: Status |
---|
231 | 230 | * @reserved: Reserved |
---|
232 | | - * @data12: First setup word |
---|
233 | | - * @data34: Second setup word |
---|
| 231 | + * @request: Control Request |
---|
234 | 232 | */ |
---|
235 | 233 | struct pch_udc_stp_dma_desc { |
---|
236 | 234 | u32 status; |
---|
.. | .. |
---|
302 | 300 | /** |
---|
303 | 301 | * struct pch_vbus_gpio_data - Structure holding GPIO informaton |
---|
304 | 302 | * for detecting VBUS |
---|
305 | | - * @port: gpio port number |
---|
| 303 | + * @port: gpio descriptor for the VBUS GPIO |
---|
306 | 304 | * @intr: gpio interrupt number |
---|
307 | | - * @irq_work_fall Structure for WorkQueue |
---|
308 | | - * @irq_work_rise Structure for WorkQueue |
---|
| 305 | + * @irq_work_fall: Structure for WorkQueue |
---|
| 306 | + * @irq_work_rise: Structure for WorkQueue |
---|
309 | 307 | */ |
---|
310 | 308 | struct pch_vbus_gpio_data { |
---|
311 | | - int port; |
---|
| 309 | + struct gpio_desc *port; |
---|
312 | 310 | int intr; |
---|
313 | 311 | struct work_struct irq_work_fall; |
---|
314 | 312 | struct work_struct irq_work_rise; |
---|
.. | .. |
---|
475 | 473 | * pch_udc_write_csr() - Write the command and status registers. |
---|
476 | 474 | * @dev: Reference to pch_udc_dev structure |
---|
477 | 475 | * @val: value to be written to CSR register |
---|
478 | | - * @addr: address of CSR register |
---|
| 476 | + * @ep: end-point number |
---|
479 | 477 | */ |
---|
480 | 478 | static void pch_udc_write_csr(struct pch_udc_dev *dev, unsigned long val, |
---|
481 | 479 | unsigned int ep) |
---|
.. | .. |
---|
490 | 488 | /** |
---|
491 | 489 | * pch_udc_read_csr() - Read the command and status registers. |
---|
492 | 490 | * @dev: Reference to pch_udc_dev structure |
---|
493 | | - * @addr: address of CSR register |
---|
| 491 | + * @ep: end-point number |
---|
494 | 492 | * |
---|
495 | 493 | * Return codes: content of CSR register |
---|
496 | 494 | */ |
---|
.. | .. |
---|
660 | 658 | * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint |
---|
661 | 659 | * @ep: Reference to structure of type pch_udc_ep_regs |
---|
662 | 660 | * @buf_size: The buffer word size |
---|
| 661 | + * @ep_in: EP is IN |
---|
663 | 662 | */ |
---|
664 | 663 | static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep, |
---|
665 | 664 | u32 buf_size, u32 ep_in) |
---|
.. | .. |
---|
972 | 971 | |
---|
973 | 972 | /** |
---|
974 | 973 | * pch_udc_ep_enable() - This api enables endpoint |
---|
975 | | - * @regs: Reference to structure pch_udc_ep_regs |
---|
| 974 | + * @ep: reference to structure of type pch_udc_ep_regs |
---|
| 975 | + * @cfg: current configuration information |
---|
976 | 976 | * @desc: endpoint descriptor |
---|
977 | 977 | */ |
---|
978 | 978 | static void pch_udc_ep_enable(struct pch_udc_ep *ep, |
---|
.. | .. |
---|
1008 | 1008 | |
---|
1009 | 1009 | /** |
---|
1010 | 1010 | * pch_udc_ep_disable() - This api disables endpoint |
---|
1011 | | - * @regs: Reference to structure pch_udc_ep_regs |
---|
| 1011 | + * @ep: reference to structure of type pch_udc_ep_regs |
---|
1012 | 1012 | */ |
---|
1013 | 1013 | static void pch_udc_ep_disable(struct pch_udc_ep *ep) |
---|
1014 | 1014 | { |
---|
.. | .. |
---|
1028 | 1028 | |
---|
1029 | 1029 | /** |
---|
1030 | 1030 | * pch_udc_wait_ep_stall() - Wait EP stall. |
---|
1031 | | - * @dev: Reference to pch_udc_dev structure |
---|
| 1031 | + * @ep: reference to structure of type pch_udc_ep_regs |
---|
1032 | 1032 | */ |
---|
1033 | 1033 | static void pch_udc_wait_ep_stall(struct pch_udc_ep *ep) |
---|
1034 | 1034 | { |
---|
.. | .. |
---|
1262 | 1262 | int vbus = 0; |
---|
1263 | 1263 | |
---|
1264 | 1264 | if (dev->vbus_gpio.port) |
---|
1265 | | - vbus = gpio_get_value(dev->vbus_gpio.port) ? 1 : 0; |
---|
| 1265 | + vbus = gpiod_get_value(dev->vbus_gpio.port) ? 1 : 0; |
---|
1266 | 1266 | else |
---|
1267 | 1267 | vbus = -1; |
---|
1268 | 1268 | |
---|
.. | .. |
---|
1338 | 1338 | } |
---|
1339 | 1339 | |
---|
1340 | 1340 | /** |
---|
1341 | | - * pch_vbus_gpio_irq() - IRQ handler for GPIO intrerrupt for changing VBUS |
---|
| 1341 | + * pch_vbus_gpio_irq() - IRQ handler for GPIO interrupt for changing VBUS |
---|
1342 | 1342 | * @irq: Interrupt request number |
---|
1343 | | - * @dev: Reference to the device structure |
---|
| 1343 | + * @data: Reference to the device structure |
---|
1344 | 1344 | * |
---|
1345 | 1345 | * Return codes: |
---|
1346 | 1346 | * 0: Success |
---|
.. | .. |
---|
1361 | 1361 | return IRQ_HANDLED; |
---|
1362 | 1362 | } |
---|
1363 | 1363 | |
---|
| 1364 | +static struct gpiod_lookup_table minnowboard_udc_gpios = { |
---|
| 1365 | + .dev_id = "0000:02:02.4", |
---|
| 1366 | + .table = { |
---|
| 1367 | + GPIO_LOOKUP("sch_gpio.33158", 12, NULL, GPIO_ACTIVE_HIGH), |
---|
| 1368 | + {} |
---|
| 1369 | + }, |
---|
| 1370 | +}; |
---|
| 1371 | + |
---|
| 1372 | +static const struct dmi_system_id pch_udc_gpio_dmi_table[] = { |
---|
| 1373 | + { |
---|
| 1374 | + .ident = "MinnowBoard", |
---|
| 1375 | + .matches = { |
---|
| 1376 | + DMI_MATCH(DMI_BOARD_NAME, "MinnowBoard"), |
---|
| 1377 | + }, |
---|
| 1378 | + .driver_data = &minnowboard_udc_gpios, |
---|
| 1379 | + }, |
---|
| 1380 | + { } |
---|
| 1381 | +}; |
---|
| 1382 | + |
---|
| 1383 | +static void pch_vbus_gpio_remove_table(void *table) |
---|
| 1384 | +{ |
---|
| 1385 | + gpiod_remove_lookup_table(table); |
---|
| 1386 | +} |
---|
| 1387 | + |
---|
| 1388 | +static int pch_vbus_gpio_add_table(struct pch_udc_dev *dev) |
---|
| 1389 | +{ |
---|
| 1390 | + struct device *d = &dev->pdev->dev; |
---|
| 1391 | + const struct dmi_system_id *dmi; |
---|
| 1392 | + |
---|
| 1393 | + dmi = dmi_first_match(pch_udc_gpio_dmi_table); |
---|
| 1394 | + if (!dmi) |
---|
| 1395 | + return 0; |
---|
| 1396 | + |
---|
| 1397 | + gpiod_add_lookup_table(dmi->driver_data); |
---|
| 1398 | + return devm_add_action_or_reset(d, pch_vbus_gpio_remove_table, dmi->driver_data); |
---|
| 1399 | +} |
---|
| 1400 | + |
---|
1364 | 1401 | /** |
---|
1365 | 1402 | * pch_vbus_gpio_init() - This API initializes GPIO port detecting VBUS. |
---|
1366 | | - * @dev: Reference to the driver structure |
---|
1367 | | - * @vbus_gpio Number of GPIO port to detect gpio |
---|
| 1403 | + * @dev: Reference to the driver structure |
---|
1368 | 1404 | * |
---|
1369 | 1405 | * Return codes: |
---|
1370 | 1406 | * 0: Success |
---|
1371 | 1407 | * -EINVAL: GPIO port is invalid or can't be initialized. |
---|
1372 | 1408 | */ |
---|
1373 | | -static int pch_vbus_gpio_init(struct pch_udc_dev *dev, int vbus_gpio_port) |
---|
| 1409 | +static int pch_vbus_gpio_init(struct pch_udc_dev *dev) |
---|
1374 | 1410 | { |
---|
| 1411 | + struct device *d = &dev->pdev->dev; |
---|
1375 | 1412 | int err; |
---|
1376 | 1413 | int irq_num = 0; |
---|
| 1414 | + struct gpio_desc *gpiod; |
---|
1377 | 1415 | |
---|
1378 | | - dev->vbus_gpio.port = 0; |
---|
| 1416 | + dev->vbus_gpio.port = NULL; |
---|
1379 | 1417 | dev->vbus_gpio.intr = 0; |
---|
1380 | 1418 | |
---|
1381 | | - if (vbus_gpio_port <= -1) |
---|
1382 | | - return -EINVAL; |
---|
| 1419 | + err = pch_vbus_gpio_add_table(dev); |
---|
| 1420 | + if (err) |
---|
| 1421 | + return err; |
---|
1383 | 1422 | |
---|
1384 | | - err = gpio_is_valid(vbus_gpio_port); |
---|
1385 | | - if (!err) { |
---|
1386 | | - pr_err("%s: gpio port %d is invalid\n", |
---|
1387 | | - __func__, vbus_gpio_port); |
---|
1388 | | - return -EINVAL; |
---|
1389 | | - } |
---|
| 1423 | + /* Retrieve the GPIO line from the USB gadget device */ |
---|
| 1424 | + gpiod = devm_gpiod_get_optional(d, NULL, GPIOD_IN); |
---|
| 1425 | + if (IS_ERR(gpiod)) |
---|
| 1426 | + return PTR_ERR(gpiod); |
---|
| 1427 | + gpiod_set_consumer_name(gpiod, "pch_vbus"); |
---|
1390 | 1428 | |
---|
1391 | | - err = gpio_request(vbus_gpio_port, "pch_vbus"); |
---|
1392 | | - if (err) { |
---|
1393 | | - pr_err("%s: can't request gpio port %d, err: %d\n", |
---|
1394 | | - __func__, vbus_gpio_port, err); |
---|
1395 | | - return -EINVAL; |
---|
1396 | | - } |
---|
1397 | | - |
---|
1398 | | - dev->vbus_gpio.port = vbus_gpio_port; |
---|
1399 | | - gpio_direction_input(vbus_gpio_port); |
---|
| 1429 | + dev->vbus_gpio.port = gpiod; |
---|
1400 | 1430 | INIT_WORK(&dev->vbus_gpio.irq_work_fall, pch_vbus_gpio_work_fall); |
---|
1401 | 1431 | |
---|
1402 | | - irq_num = gpio_to_irq(vbus_gpio_port); |
---|
| 1432 | + irq_num = gpiod_to_irq(gpiod); |
---|
1403 | 1433 | if (irq_num > 0) { |
---|
1404 | 1434 | irq_set_irq_type(irq_num, IRQ_TYPE_EDGE_BOTH); |
---|
1405 | 1435 | err = request_irq(irq_num, pch_vbus_gpio_irq, 0, |
---|
.. | .. |
---|
1425 | 1455 | { |
---|
1426 | 1456 | if (dev->vbus_gpio.intr) |
---|
1427 | 1457 | free_irq(dev->vbus_gpio.intr, dev); |
---|
1428 | | - |
---|
1429 | | - if (dev->vbus_gpio.port) |
---|
1430 | | - gpio_free(dev->vbus_gpio.port); |
---|
1431 | 1458 | } |
---|
1432 | 1459 | |
---|
1433 | 1460 | /** |
---|
.. | .. |
---|
1508 | 1535 | /** |
---|
1509 | 1536 | * pch_udc_free_dma_chain() - This function frees the DMA chain created |
---|
1510 | 1537 | * for the request |
---|
1511 | | - * @dev Reference to the driver structure |
---|
1512 | | - * @req Reference to the request to be freed |
---|
| 1538 | + * @dev: Reference to the driver structure |
---|
| 1539 | + * @req: Reference to the request to be freed |
---|
1513 | 1540 | * |
---|
1514 | 1541 | * Return codes: |
---|
1515 | 1542 | * 0: Success |
---|
.. | .. |
---|
1716 | 1743 | /** |
---|
1717 | 1744 | * pch_udc_pcd_ep_disable() - This API disables endpoint and is called |
---|
1718 | 1745 | * from gadget driver |
---|
1719 | | - * @usbep Reference to the USB endpoint structure |
---|
| 1746 | + * @usbep: Reference to the USB endpoint structure |
---|
1720 | 1747 | * |
---|
1721 | 1748 | * Return codes: |
---|
1722 | 1749 | * 0: Success |
---|
.. | .. |
---|
2005 | 2032 | * pch_udc_pcd_set_wedge() - This function Sets or clear the endpoint |
---|
2006 | 2033 | * halt feature |
---|
2007 | 2034 | * @usbep: Reference to the USB endpoint structure |
---|
2008 | | - * @halt: Specifies whether to set or clear the feature |
---|
2009 | 2035 | * |
---|
2010 | 2036 | * Return codes: |
---|
2011 | 2037 | * 0: Success |
---|
.. | .. |
---|
2767 | 2793 | /** |
---|
2768 | 2794 | * pch_udc_isr() - This function handles interrupts from the PCH USB Device |
---|
2769 | 2795 | * @irq: Interrupt request number |
---|
2770 | | - * @dev: Reference to the device structure |
---|
| 2796 | + * @pdev: Reference to the device structure |
---|
2771 | 2797 | */ |
---|
2772 | 2798 | static irqreturn_t pch_udc_isr(int irq, void *pdev) |
---|
2773 | 2799 | { |
---|
.. | .. |
---|
2905 | 2931 | * @dev: Reference to the driver structure |
---|
2906 | 2932 | * |
---|
2907 | 2933 | * Return codes: |
---|
2908 | | - * 0: Success |
---|
| 2934 | + * 0: Success |
---|
| 2935 | + * -%ERRNO: All kind of errors when retrieving VBUS GPIO |
---|
2909 | 2936 | */ |
---|
2910 | 2937 | static int pch_udc_pcd_init(struct pch_udc_dev *dev) |
---|
2911 | 2938 | { |
---|
| 2939 | + int ret; |
---|
| 2940 | + |
---|
2912 | 2941 | pch_udc_init(dev); |
---|
2913 | 2942 | pch_udc_pcd_reinit(dev); |
---|
2914 | | - pch_vbus_gpio_init(dev, vbus_gpio_port); |
---|
2915 | | - return 0; |
---|
| 2943 | + |
---|
| 2944 | + ret = pch_vbus_gpio_init(dev); |
---|
| 2945 | + if (ret) |
---|
| 2946 | + pch_udc_exit(dev); |
---|
| 2947 | + return ret; |
---|
2916 | 2948 | } |
---|
2917 | 2949 | |
---|
2918 | 2950 | /** |
---|
2919 | 2951 | * init_dma_pools() - create dma pools during initialization |
---|
2920 | | - * @pdev: reference to struct pci_dev |
---|
| 2952 | + * @dev: reference to struct pci_dev |
---|
2921 | 2953 | */ |
---|
2922 | 2954 | static int init_dma_pools(struct pch_udc_dev *dev) |
---|
2923 | 2955 | { |
---|
.. | .. |
---|
3062 | 3094 | #ifdef CONFIG_PM_SLEEP |
---|
3063 | 3095 | static int pch_udc_suspend(struct device *d) |
---|
3064 | 3096 | { |
---|
3065 | | - struct pci_dev *pdev = to_pci_dev(d); |
---|
3066 | | - struct pch_udc_dev *dev = pci_get_drvdata(pdev); |
---|
| 3097 | + struct pch_udc_dev *dev = dev_get_drvdata(d); |
---|
3067 | 3098 | |
---|
3068 | 3099 | pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); |
---|
3069 | 3100 | pch_udc_disable_ep_interrupts(dev, UDC_EPINT_MSK_DISABLE_ALL); |
---|
.. | .. |
---|
3099 | 3130 | if (retval) |
---|
3100 | 3131 | return retval; |
---|
3101 | 3132 | |
---|
| 3133 | + dev->pdev = pdev; |
---|
3102 | 3134 | pci_set_drvdata(pdev, dev); |
---|
3103 | 3135 | |
---|
3104 | 3136 | /* Determine BAR based on PCI ID */ |
---|
.. | .. |
---|
3115 | 3147 | dev->base_addr = pcim_iomap_table(pdev)[bar]; |
---|
3116 | 3148 | |
---|
3117 | 3149 | /* initialize the hardware */ |
---|
3118 | | - if (pch_udc_pcd_init(dev)) |
---|
3119 | | - return -ENODEV; |
---|
| 3150 | + retval = pch_udc_pcd_init(dev); |
---|
| 3151 | + if (retval) |
---|
| 3152 | + return retval; |
---|
3120 | 3153 | |
---|
3121 | 3154 | pci_enable_msi(pdev); |
---|
3122 | 3155 | |
---|
.. | .. |
---|
3133 | 3166 | |
---|
3134 | 3167 | /* device struct setup */ |
---|
3135 | 3168 | spin_lock_init(&dev->lock); |
---|
3136 | | - dev->pdev = pdev; |
---|
3137 | 3169 | dev->gadget.ops = &pch_udc_ops; |
---|
3138 | 3170 | |
---|
3139 | 3171 | retval = init_dma_pools(dev); |
---|