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

USB: gadget: atmel_usba: add DT support

Allow to compile the driver all the time if AT91 enabled.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Felipe Balbi <balbi@ti.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Tested-by: Bo Shen <voice.shen@atmel.com>

+245 -60
+82
Documentation/devicetree/bindings/usb/atmel-usb.txt
··· 47 47 interrupts = <10 4>; 48 48 atmel,vbus-gpio = <&pioC 5 0>; 49 49 }; 50 + 51 + Atmel High-Speed USB device controller 52 + 53 + Required properties: 54 + - compatible: Should be "atmel,at91sam9rl-udc" 55 + - reg: Address and length of the register set for the device 56 + - interrupts: Should contain usba interrupt 57 + - ep childnode: To specify the number of endpoints and their properties. 58 + 59 + Optional properties: 60 + - atmel,vbus-gpio: If present, specifies a gpio that needs to be 61 + activated for the bus to be powered. 62 + 63 + Required child node properties: 64 + - name: Name of the endpoint. 65 + - reg: Num of the endpoint. 66 + - atmel,fifo-size: Size of the fifo. 67 + - atmel,nb-banks: Number of banks. 68 + - atmel,can-dma: Boolean to specify if the endpoint support DMA. 69 + - atmel,can-isoc: Boolean to specify if the endpoint support ISOC. 70 + 71 + usb2: gadget@fff78000 { 72 + #address-cells = <1>; 73 + #size-cells = <0>; 74 + compatible = "atmel,at91sam9rl-udc"; 75 + reg = <0x00600000 0x80000 76 + 0xfff78000 0x400>; 77 + interrupts = <27 4 0>; 78 + atmel,vbus-gpio = <&pioB 19 0>; 79 + 80 + ep0 { 81 + reg = <0>; 82 + atmel,fifo-size = <64>; 83 + atmel,nb-banks = <1>; 84 + }; 85 + 86 + ep1 { 87 + reg = <1>; 88 + atmel,fifo-size = <1024>; 89 + atmel,nb-banks = <2>; 90 + atmel,can-dma; 91 + atmel,can-isoc; 92 + }; 93 + 94 + ep2 { 95 + reg = <2>; 96 + atmel,fifo-size = <1024>; 97 + atmel,nb-banks = <2>; 98 + atmel,can-dma; 99 + atmel,can-isoc; 100 + }; 101 + 102 + ep3 { 103 + reg = <3>; 104 + atmel,fifo-size = <1024>; 105 + atmel,nb-banks = <3>; 106 + atmel,can-dma; 107 + }; 108 + 109 + ep4 { 110 + reg = <4>; 111 + atmel,fifo-size = <1024>; 112 + atmel,nb-banks = <3>; 113 + atmel,can-dma; 114 + }; 115 + 116 + ep5 { 117 + reg = <5>; 118 + atmel,fifo-size = <1024>; 119 + atmel,nb-banks = <3>; 120 + atmel,can-dma; 121 + atmel,can-isoc; 122 + }; 123 + 124 + ep6 { 125 + reg = <6>; 126 + atmel,fifo-size = <1024>; 127 + atmel,nb-banks = <3>; 128 + atmel,can-dma; 129 + atmel,can-isoc; 130 + }; 131 + };
+1 -1
drivers/usb/gadget/Kconfig
··· 156 156 157 157 config USB_ATMEL_USBA 158 158 tristate "Atmel USBA" 159 - depends on AVR32 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 159 + depends on AVR32 || ARCH_AT91 160 160 help 161 161 USBA is the integrated high-speed USB Device controller on 162 162 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
+161 -59
drivers/usb/gadget/atmel_usba_udc.c
··· 22 22 #include <linux/usb/atmel_usba_udc.h> 23 23 #include <linux/delay.h> 24 24 #include <linux/platform_data/atmel.h> 25 + #include <linux/of.h> 26 + #include <linux/of_gpio.h> 25 27 26 28 #include <asm/gpio.h> 27 29 ··· 1830 1828 return 0; 1831 1829 } 1832 1830 1833 - static int __init usba_udc_probe(struct platform_device *pdev) 1831 + #ifdef CONFIG_OF 1832 + static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, 1833 + struct usba_udc *udc) 1834 + { 1835 + u32 val; 1836 + const char *name; 1837 + enum of_gpio_flags flags; 1838 + struct device_node *np = pdev->dev.of_node; 1839 + struct device_node *pp; 1840 + int i, ret; 1841 + struct usba_ep *eps, *ep; 1842 + 1843 + udc->num_ep = 0; 1844 + 1845 + udc->vbus_pin = of_get_named_gpio_flags(np, "atmel,vbus-gpio", 0, 1846 + &flags); 1847 + udc->vbus_pin_inverted = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0; 1848 + 1849 + pp = NULL; 1850 + while ((pp = of_get_next_child(np, pp))) 1851 + udc->num_ep++; 1852 + 1853 + eps = devm_kzalloc(&pdev->dev, sizeof(struct usba_ep) * udc->num_ep, 1854 + GFP_KERNEL); 1855 + if (!eps) 1856 + return ERR_PTR(-ENOMEM); 1857 + 1858 + udc->gadget.ep0 = &eps[0].ep; 1859 + 1860 + INIT_LIST_HEAD(&eps[0].ep.ep_list); 1861 + 1862 + pp = NULL; 1863 + i = 0; 1864 + while ((pp = of_get_next_child(np, pp))) { 1865 + ep = &eps[i]; 1866 + 1867 + ret = of_property_read_u32(pp, "reg", &val); 1868 + if (ret) { 1869 + dev_err(&pdev->dev, "of_probe: reg error(%d)\n", ret); 1870 + goto err; 1871 + } 1872 + ep->index = val; 1873 + 1874 + ret = of_property_read_u32(pp, "atmel,fifo-size", &val); 1875 + if (ret) { 1876 + dev_err(&pdev->dev, "of_probe: fifo-size error(%d)\n", ret); 1877 + goto err; 1878 + } 1879 + ep->fifo_size = val; 1880 + 1881 + ret = of_property_read_u32(pp, "atmel,nb-banks", &val); 1882 + if (ret) { 1883 + dev_err(&pdev->dev, "of_probe: nb-banks error(%d)\n", ret); 1884 + goto err; 1885 + } 1886 + ep->nr_banks = val; 1887 + 1888 + ep->can_dma = of_property_read_bool(pp, "atmel,can-dma"); 1889 + ep->can_isoc = of_property_read_bool(pp, "atmel,can-isoc"); 1890 + 1891 + ret = of_property_read_string(pp, "name", &name); 1892 + ep->ep.name = name; 1893 + 1894 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1895 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1896 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 1897 + ep->ep.ops = &usba_ep_ops; 1898 + ep->ep.maxpacket = ep->fifo_size; 1899 + ep->udc = udc; 1900 + INIT_LIST_HEAD(&ep->queue); 1901 + 1902 + if (i) 1903 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1904 + 1905 + i++; 1906 + } 1907 + 1908 + return eps; 1909 + err: 1910 + return ERR_PTR(ret); 1911 + } 1912 + #else 1913 + static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, 1914 + struct usba_udc *udc) 1915 + { 1916 + return ERR_PTR(-ENOSYS); 1917 + } 1918 + #endif 1919 + 1920 + static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, 1921 + struct usba_udc *udc) 1834 1922 { 1835 1923 struct usba_platform_data *pdata = pdev->dev.platform_data; 1924 + struct usba_ep *eps; 1925 + int i; 1926 + 1927 + if (!pdata) 1928 + return ERR_PTR(-ENXIO); 1929 + 1930 + eps = devm_kzalloc(&pdev->dev, sizeof(struct usba_ep) * pdata->num_ep, 1931 + GFP_KERNEL); 1932 + if (!eps) 1933 + return ERR_PTR(-ENOMEM); 1934 + 1935 + udc->gadget.ep0 = &eps[0].ep; 1936 + 1937 + udc->vbus_pin = pdata->vbus_pin; 1938 + udc->vbus_pin_inverted = pdata->vbus_pin_inverted; 1939 + udc->num_ep = pdata->num_ep; 1940 + 1941 + INIT_LIST_HEAD(&eps[0].ep.ep_list); 1942 + 1943 + for (i = 0; i < pdata->num_ep; i++) { 1944 + struct usba_ep *ep = &eps[i]; 1945 + 1946 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1947 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1948 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 1949 + ep->ep.ops = &usba_ep_ops; 1950 + ep->ep.name = pdata->ep[i].name; 1951 + ep->fifo_size = ep->ep.maxpacket = pdata->ep[i].fifo_size; 1952 + ep->udc = udc; 1953 + INIT_LIST_HEAD(&ep->queue); 1954 + ep->nr_banks = pdata->ep[i].nr_banks; 1955 + ep->index = pdata->ep[i].index; 1956 + ep->can_dma = pdata->ep[i].can_dma; 1957 + ep->can_isoc = pdata->ep[i].can_isoc; 1958 + 1959 + if (i) 1960 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1961 + } 1962 + 1963 + return eps; 1964 + } 1965 + 1966 + static int __init usba_udc_probe(struct platform_device *pdev) 1967 + { 1836 1968 struct resource *regs, *fifo; 1837 1969 struct clk *pclk, *hclk; 1838 1970 struct usba_udc *udc; 1839 - static struct usba_ep *usba_ep; 1840 1971 int irq, ret, i; 1841 1972 1842 1973 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); ··· 1981 1846 1982 1847 regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID); 1983 1848 fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID); 1984 - if (!regs || !fifo || !pdata) 1849 + if (!regs || !fifo) 1985 1850 return -ENXIO; 1986 1851 1987 1852 irq = platform_get_irq(pdev, 0); ··· 2027 1892 usba_writel(udc, CTRL, USBA_DISABLE_MASK); 2028 1893 clk_disable(pclk); 2029 1894 2030 - usba_ep = kzalloc(sizeof(struct usba_ep) * pdata->num_ep, 2031 - GFP_KERNEL); 2032 - if (!usba_ep) 1895 + if (pdev->dev.of_node) 1896 + udc->usba_ep = atmel_udc_of_init(pdev, udc); 1897 + else 1898 + udc->usba_ep = usba_udc_pdata(pdev, udc); 1899 + 1900 + if (IS_ERR(udc->usba_ep)) { 1901 + ret = PTR_ERR(udc->usba_ep); 2033 1902 goto err_alloc_ep; 2034 - 2035 - udc->usba_ep = usba_ep; 2036 - udc->gadget.ep0 = &usba_ep[0].ep; 2037 - 2038 - INIT_LIST_HEAD(&usba_ep[0].ep.ep_list); 2039 - usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0); 2040 - usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0); 2041 - usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0); 2042 - usba_ep[0].ep.ops = &usba_ep_ops; 2043 - usba_ep[0].ep.name = pdata->ep[0].name; 2044 - usba_ep[0].ep.maxpacket = pdata->ep[0].fifo_size; 2045 - usba_ep[0].udc = udc; 2046 - INIT_LIST_HEAD(&usba_ep[0].queue); 2047 - usba_ep[0].fifo_size = pdata->ep[0].fifo_size; 2048 - usba_ep[0].nr_banks = pdata->ep[0].nr_banks; 2049 - usba_ep[0].index = pdata->ep[0].index; 2050 - usba_ep[0].can_dma = pdata->ep[0].can_dma; 2051 - usba_ep[0].can_isoc = pdata->ep[0].can_isoc; 2052 - 2053 - for (i = 1; i < pdata->num_ep; i++) { 2054 - struct usba_ep *ep = &usba_ep[i]; 2055 - 2056 - ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 2057 - ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 2058 - ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 2059 - ep->ep.ops = &usba_ep_ops; 2060 - ep->ep.name = pdata->ep[i].name; 2061 - ep->ep.maxpacket = pdata->ep[i].fifo_size; 2062 - ep->udc = udc; 2063 - INIT_LIST_HEAD(&ep->queue); 2064 - ep->fifo_size = pdata->ep[i].fifo_size; 2065 - ep->nr_banks = pdata->ep[i].nr_banks; 2066 - ep->index = pdata->ep[i].index; 2067 - ep->can_dma = pdata->ep[i].can_dma; 2068 - ep->can_isoc = pdata->ep[i].can_isoc; 2069 - 2070 - list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 2071 1903 } 2072 1904 2073 1905 ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc); ··· 2045 1943 } 2046 1944 udc->irq = irq; 2047 1945 2048 - if (gpio_is_valid(pdata->vbus_pin)) { 2049 - if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { 2050 - udc->vbus_pin = pdata->vbus_pin; 2051 - udc->vbus_pin_inverted = pdata->vbus_pin_inverted; 2052 - 1946 + if (gpio_is_valid(udc->vbus_pin)) { 1947 + if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { 2053 1948 ret = request_irq(gpio_to_irq(udc->vbus_pin), 2054 1949 usba_vbus_irq, 0, 2055 1950 "atmel_usba_udc", udc); 2056 1951 if (ret) { 2057 - gpio_free(udc->vbus_pin); 2058 1952 udc->vbus_pin = -ENODEV; 2059 1953 dev_warn(&udc->pdev->dev, 2060 1954 "failed to request vbus irq; " ··· 2069 1971 goto err_add_udc; 2070 1972 2071 1973 usba_init_debugfs(udc); 2072 - for (i = 1; i < pdata->num_ep; i++) 2073 - usba_ep_init_debugfs(udc, &usba_ep[i]); 1974 + for (i = 1; i < udc->num_ep; i++) 1975 + usba_ep_init_debugfs(udc, &udc->usba_ep[i]); 2074 1976 2075 1977 return 0; 2076 1978 2077 1979 err_add_udc: 2078 - if (gpio_is_valid(pdata->vbus_pin)) { 1980 + if (gpio_is_valid(udc->vbus_pin)) 2079 1981 free_irq(gpio_to_irq(udc->vbus_pin), udc); 2080 - gpio_free(udc->vbus_pin); 2081 - } 2082 1982 2083 1983 free_irq(irq, udc); 2084 1984 err_request_irq: 2085 - kfree(usba_ep); 2086 1985 err_alloc_ep: 2087 1986 iounmap(udc->fifo); 2088 1987 err_map_fifo: ··· 2098 2003 { 2099 2004 struct usba_udc *udc; 2100 2005 int i; 2101 - struct usba_platform_data *pdata = pdev->dev.platform_data; 2102 2006 2103 2007 udc = platform_get_drvdata(pdev); 2104 2008 2105 2009 usb_del_gadget_udc(&udc->gadget); 2106 2010 2107 - for (i = 1; i < pdata->num_ep; i++) 2011 + for (i = 1; i < udc->num_ep; i++) 2108 2012 usba_ep_cleanup_debugfs(&udc->usba_ep[i]); 2109 2013 usba_cleanup_debugfs(udc); 2110 2014 2111 2015 if (gpio_is_valid(udc->vbus_pin)) { 2112 2016 free_irq(gpio_to_irq(udc->vbus_pin), udc); 2113 - gpio_free(udc->vbus_pin); 2114 2017 } 2115 2018 2116 2019 free_irq(udc->irq, udc); 2117 - kfree(usba_ep); 2118 2020 iounmap(udc->fifo); 2119 2021 iounmap(udc->regs); 2120 2022 clk_put(udc->hclk); ··· 2120 2028 return 0; 2121 2029 } 2122 2030 2031 + #if defined(CONFIG_OF) 2032 + static const struct of_device_id atmel_udc_dt_ids[] = { 2033 + { .compatible = "atmel,at91sam9rl-udc" }, 2034 + { /* sentinel */ } 2035 + }; 2036 + 2037 + MODULE_DEVICE_TABLE(of, atmel_udc_dt_ids); 2038 + #endif 2039 + 2123 2040 static struct platform_driver udc_driver = { 2124 2041 .remove = __exit_p(usba_udc_remove), 2125 2042 .driver = { 2126 2043 .name = "atmel_usba_udc", 2127 2044 .owner = THIS_MODULE, 2045 + .of_match_table = of_match_ptr(atmel_udc_dt_ids), 2128 2046 }, 2129 2047 }; 2130 2048
+1
drivers/usb/gadget/atmel_usba_udc.h
··· 317 317 int irq; 318 318 int vbus_pin; 319 319 int vbus_pin_inverted; 320 + int num_ep; 320 321 struct clk *pclk; 321 322 struct clk *hclk; 322 323 struct usba_ep *usba_ep;