diff options
Diffstat (limited to 'drivers/usb/gadget/net2280.c')
-rw-r--r-- | drivers/usb/gadget/net2280.c | 87 |
1 files changed, 20 insertions, 67 deletions
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index a218a4de5dc9..7f1bc9a73cda 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -33,15 +33,6 @@ | |||
33 | * it under the terms of the GNU General Public License as published by | 33 | * it under the terms of the GNU General Public License as published by |
34 | * the Free Software Foundation; either version 2 of the License, or | 34 | * the Free Software Foundation; either version 2 of the License, or |
35 | * (at your option) any later version. | 35 | * (at your option) any later version. |
36 | * | ||
37 | * This program is distributed in the hope that it will be useful, | ||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | * GNU General Public License for more details. | ||
41 | * | ||
42 | * You should have received a copy of the GNU General Public License | ||
43 | * along with this program; if not, write to the Free Software | ||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
45 | */ | 36 | */ |
46 | 37 | ||
47 | #undef DEBUG /* messages on error and most fault paths */ | 38 | #undef DEBUG /* messages on error and most fault paths */ |
@@ -169,7 +160,7 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
169 | return -EDOM; | 160 | return -EDOM; |
170 | 161 | ||
171 | /* sanity check ep-e/ep-f since their fifos are small */ | 162 | /* sanity check ep-e/ep-f since their fifos are small */ |
172 | max = le16_to_cpu (desc->wMaxPacketSize) & 0x1fff; | 163 | max = usb_endpoint_maxp (desc) & 0x1fff; |
173 | if (ep->num > 4 && max > 64) | 164 | if (ep->num > 4 && max > 64) |
174 | return -ERANGE; | 165 | return -ERANGE; |
175 | 166 | ||
@@ -1410,17 +1401,18 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | |||
1410 | return 0; | 1401 | return 0; |
1411 | } | 1402 | } |
1412 | 1403 | ||
1413 | static int net2280_start(struct usb_gadget_driver *driver, | 1404 | static int net2280_start(struct usb_gadget *_gadget, |
1414 | int (*bind)(struct usb_gadget *)); | 1405 | struct usb_gadget_driver *driver); |
1415 | static int net2280_stop(struct usb_gadget_driver *driver); | 1406 | static int net2280_stop(struct usb_gadget *_gadget, |
1407 | struct usb_gadget_driver *driver); | ||
1416 | 1408 | ||
1417 | static const struct usb_gadget_ops net2280_ops = { | 1409 | static const struct usb_gadget_ops net2280_ops = { |
1418 | .get_frame = net2280_get_frame, | 1410 | .get_frame = net2280_get_frame, |
1419 | .wakeup = net2280_wakeup, | 1411 | .wakeup = net2280_wakeup, |
1420 | .set_selfpowered = net2280_set_selfpowered, | 1412 | .set_selfpowered = net2280_set_selfpowered, |
1421 | .pullup = net2280_pullup, | 1413 | .pullup = net2280_pullup, |
1422 | .start = net2280_start, | 1414 | .udc_start = net2280_start, |
1423 | .stop = net2280_stop, | 1415 | .udc_stop = net2280_stop, |
1424 | }; | 1416 | }; |
1425 | 1417 | ||
1426 | /*-------------------------------------------------------------------------*/ | 1418 | /*-------------------------------------------------------------------------*/ |
@@ -1640,7 +1632,7 @@ show_queues (struct device *_dev, struct device_attribute *attr, char *buf) | |||
1640 | default: | 1632 | default: |
1641 | val = "iso"; break; | 1633 | val = "iso"; break; |
1642 | }; val; }), | 1634 | }; val; }), |
1643 | le16_to_cpu (d->wMaxPacketSize) & 0x1fff, | 1635 | usb_endpoint_maxp (d) & 0x1fff, |
1644 | ep->dma ? "dma" : "pio", ep->fifo_size | 1636 | ep->dma ? "dma" : "pio", ep->fifo_size |
1645 | ); | 1637 | ); |
1646 | } else /* ep0 should only have one transfer queued */ | 1638 | } else /* ep0 should only have one transfer queued */ |
@@ -1753,8 +1745,6 @@ static void set_fifo_mode (struct net2280 *dev, int mode) | |||
1753 | * perhaps to bind specific drivers to specific devices. | 1745 | * perhaps to bind specific drivers to specific devices. |
1754 | */ | 1746 | */ |
1755 | 1747 | ||
1756 | static struct net2280 *the_controller; | ||
1757 | |||
1758 | static void usb_reset (struct net2280 *dev) | 1748 | static void usb_reset (struct net2280 *dev) |
1759 | { | 1749 | { |
1760 | u32 tmp; | 1750 | u32 tmp; |
@@ -1880,10 +1870,10 @@ static void ep0_start (struct net2280 *dev) | |||
1880 | * disconnect is reported. then a host may connect again, or | 1870 | * disconnect is reported. then a host may connect again, or |
1881 | * the driver might get unbound. | 1871 | * the driver might get unbound. |
1882 | */ | 1872 | */ |
1883 | static int net2280_start(struct usb_gadget_driver *driver, | 1873 | static int net2280_start(struct usb_gadget *_gadget, |
1884 | int (*bind)(struct usb_gadget *)) | 1874 | struct usb_gadget_driver *driver) |
1885 | { | 1875 | { |
1886 | struct net2280 *dev = the_controller; | 1876 | struct net2280 *dev; |
1887 | int retval; | 1877 | int retval; |
1888 | unsigned i; | 1878 | unsigned i; |
1889 | 1879 | ||
@@ -1891,14 +1881,11 @@ static int net2280_start(struct usb_gadget_driver *driver, | |||
1891 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) | 1881 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) |
1892 | * "must not be used in normal operation" | 1882 | * "must not be used in normal operation" |
1893 | */ | 1883 | */ |
1894 | if (!driver | 1884 | if (!driver || driver->speed != USB_SPEED_HIGH |
1895 | || driver->speed != USB_SPEED_HIGH | 1885 | || !driver->setup) |
1896 | || !bind || !driver->setup) | ||
1897 | return -EINVAL; | 1886 | return -EINVAL; |
1898 | if (!dev) | 1887 | |
1899 | return -ENODEV; | 1888 | dev = container_of (_gadget, struct net2280, gadget); |
1900 | if (dev->driver) | ||
1901 | return -EBUSY; | ||
1902 | 1889 | ||
1903 | for (i = 0; i < 7; i++) | 1890 | for (i = 0; i < 7; i++) |
1904 | dev->ep [i].irqs = 0; | 1891 | dev->ep [i].irqs = 0; |
@@ -1908,14 +1895,6 @@ static int net2280_start(struct usb_gadget_driver *driver, | |||
1908 | driver->driver.bus = NULL; | 1895 | driver->driver.bus = NULL; |
1909 | dev->driver = driver; | 1896 | dev->driver = driver; |
1910 | dev->gadget.dev.driver = &driver->driver; | 1897 | dev->gadget.dev.driver = &driver->driver; |
1911 | retval = bind(&dev->gadget); | ||
1912 | if (retval) { | ||
1913 | DEBUG (dev, "bind to driver %s --> %d\n", | ||
1914 | driver->driver.name, retval); | ||
1915 | dev->driver = NULL; | ||
1916 | dev->gadget.dev.driver = NULL; | ||
1917 | return retval; | ||
1918 | } | ||
1919 | 1898 | ||
1920 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); | 1899 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); |
1921 | if (retval) goto err_unbind; | 1900 | if (retval) goto err_unbind; |
@@ -1961,33 +1940,21 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) | |||
1961 | for (i = 0; i < 7; i++) | 1940 | for (i = 0; i < 7; i++) |
1962 | nuke (&dev->ep [i]); | 1941 | nuke (&dev->ep [i]); |
1963 | 1942 | ||
1964 | /* report disconnect; the driver is already quiesced */ | ||
1965 | if (driver) { | ||
1966 | spin_unlock (&dev->lock); | ||
1967 | driver->disconnect (&dev->gadget); | ||
1968 | spin_lock (&dev->lock); | ||
1969 | } | ||
1970 | |||
1971 | usb_reinit (dev); | 1943 | usb_reinit (dev); |
1972 | } | 1944 | } |
1973 | 1945 | ||
1974 | static int net2280_stop(struct usb_gadget_driver *driver) | 1946 | static int net2280_stop(struct usb_gadget *_gadget, |
1947 | struct usb_gadget_driver *driver) | ||
1975 | { | 1948 | { |
1976 | struct net2280 *dev = the_controller; | 1949 | struct net2280 *dev; |
1977 | unsigned long flags; | 1950 | unsigned long flags; |
1978 | 1951 | ||
1979 | if (!dev) | 1952 | dev = container_of (_gadget, struct net2280, gadget); |
1980 | return -ENODEV; | ||
1981 | if (!driver || driver != dev->driver || !driver->unbind) | ||
1982 | return -EINVAL; | ||
1983 | 1953 | ||
1984 | spin_lock_irqsave (&dev->lock, flags); | 1954 | spin_lock_irqsave (&dev->lock, flags); |
1985 | stop_activity (dev, driver); | 1955 | stop_activity (dev, driver); |
1986 | spin_unlock_irqrestore (&dev->lock, flags); | 1956 | spin_unlock_irqrestore (&dev->lock, flags); |
1987 | 1957 | ||
1988 | net2280_pullup (&dev->gadget, 0); | ||
1989 | |||
1990 | driver->unbind (&dev->gadget); | ||
1991 | dev->gadget.dev.driver = NULL; | 1958 | dev->gadget.dev.driver = NULL; |
1992 | dev->driver = NULL; | 1959 | dev->driver = NULL; |
1993 | 1960 | ||
@@ -2266,9 +2233,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2266 | else | 2233 | else |
2267 | dev->gadget.speed = USB_SPEED_FULL; | 2234 | dev->gadget.speed = USB_SPEED_FULL; |
2268 | net2280_led_speed (dev, dev->gadget.speed); | 2235 | net2280_led_speed (dev, dev->gadget.speed); |
2269 | DEBUG (dev, "%s speed\n", | 2236 | DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed)); |
2270 | (dev->gadget.speed == USB_SPEED_HIGH) | ||
2271 | ? "high" : "full"); | ||
2272 | } | 2237 | } |
2273 | 2238 | ||
2274 | ep = &dev->ep [0]; | 2239 | ep = &dev->ep [0]; |
@@ -2709,8 +2674,6 @@ static void net2280_remove (struct pci_dev *pdev) | |||
2709 | pci_set_drvdata (pdev, NULL); | 2674 | pci_set_drvdata (pdev, NULL); |
2710 | 2675 | ||
2711 | INFO (dev, "unbind\n"); | 2676 | INFO (dev, "unbind\n"); |
2712 | |||
2713 | the_controller = NULL; | ||
2714 | } | 2677 | } |
2715 | 2678 | ||
2716 | /* wrap this driver around the specified device, but | 2679 | /* wrap this driver around the specified device, but |
@@ -2724,14 +2687,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2724 | void __iomem *base = NULL; | 2687 | void __iomem *base = NULL; |
2725 | int retval, i; | 2688 | int retval, i; |
2726 | 2689 | ||
2727 | /* if you want to support more than one controller in a system, | ||
2728 | * usb_gadget_driver_{register,unregister}() must change. | ||
2729 | */ | ||
2730 | if (the_controller) { | ||
2731 | dev_warn (&pdev->dev, "ignoring\n"); | ||
2732 | return -EBUSY; | ||
2733 | } | ||
2734 | |||
2735 | /* alloc, and start init */ | 2690 | /* alloc, and start init */ |
2736 | dev = kzalloc (sizeof *dev, GFP_KERNEL); | 2691 | dev = kzalloc (sizeof *dev, GFP_KERNEL); |
2737 | if (dev == NULL){ | 2692 | if (dev == NULL){ |
@@ -2858,8 +2813,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2858 | use_dma | 2813 | use_dma |
2859 | ? (use_dma_chaining ? "chaining" : "enabled") | 2814 | ? (use_dma_chaining ? "chaining" : "enabled") |
2860 | : "disabled"); | 2815 | : "disabled"); |
2861 | the_controller = dev; | ||
2862 | |||
2863 | retval = device_register (&dev->gadget.dev); | 2816 | retval = device_register (&dev->gadget.dev); |
2864 | if (retval) goto done; | 2817 | if (retval) goto done; |
2865 | retval = device_create_file (&pdev->dev, &dev_attr_registers); | 2818 | retval = device_create_file (&pdev->dev, &dev_attr_registers); |