diff options
author | Heiko Stübner <heiko@sntech.de> | 2011-12-19 13:41:45 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2011-12-21 06:24:39 -0500 |
commit | d93e2600d80fc41ccf339b4a2843a3007d479907 (patch) | |
tree | f4cdbbb75e2424f3ab8b57965f9df03fb9f44167 /drivers/usb/gadget | |
parent | 103495aaf0e7674f6d7995982b48118188c247eb (diff) |
usb: gadget: s3c-hsudc: use udc_start and udc_stop functions
udc_start and udc_stop reduce code duplication in comparison to
start and stop generalising calls done by all drivers
(i.e. bind and unbind) and moving these calls to common code.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/s3c-hsudc.c | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index fd181329f451..1de955082abc 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -282,8 +282,7 @@ static void s3c_hsudc_nuke_ep(struct s3c_hsudc_ep *hsep, int status) | |||
282 | * All the endpoints are stopped and any pending transfer requests if any on | 282 | * All the endpoints are stopped and any pending transfer requests if any on |
283 | * the endpoint are terminated. | 283 | * the endpoint are terminated. |
284 | */ | 284 | */ |
285 | static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc, | 285 | static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc) |
286 | struct usb_gadget_driver *driver) | ||
287 | { | 286 | { |
288 | struct s3c_hsudc_ep *hsep; | 287 | struct s3c_hsudc_ep *hsep; |
289 | int epnum; | 288 | int epnum; |
@@ -295,10 +294,6 @@ static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc, | |||
295 | hsep->stopped = 1; | 294 | hsep->stopped = 1; |
296 | s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); | 295 | s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); |
297 | } | 296 | } |
298 | |||
299 | spin_unlock(&hsudc->lock); | ||
300 | driver->disconnect(&hsudc->gadget); | ||
301 | spin_lock(&hsudc->lock); | ||
302 | } | 297 | } |
303 | 298 | ||
304 | /** | 299 | /** |
@@ -1135,16 +1130,15 @@ static irqreturn_t s3c_hsudc_irq(int irq, void *_dev) | |||
1135 | return IRQ_HANDLED; | 1130 | return IRQ_HANDLED; |
1136 | } | 1131 | } |
1137 | 1132 | ||
1138 | static int s3c_hsudc_start(struct usb_gadget_driver *driver, | 1133 | static int s3c_hsudc_start(struct usb_gadget *gadget, |
1139 | int (*bind)(struct usb_gadget *)) | 1134 | struct usb_gadget_driver *driver) |
1140 | { | 1135 | { |
1141 | struct s3c_hsudc *hsudc = the_controller; | 1136 | struct s3c_hsudc *hsudc = the_controller; |
1142 | int ret; | 1137 | int ret; |
1143 | 1138 | ||
1144 | if (!driver | 1139 | if (!driver |
1145 | || driver->max_speed < USB_SPEED_FULL | 1140 | || driver->max_speed < USB_SPEED_FULL |
1146 | || !bind | 1141 | || !driver->setup) |
1147 | || !driver->unbind || !driver->disconnect || !driver->setup) | ||
1148 | return -EINVAL; | 1142 | return -EINVAL; |
1149 | 1143 | ||
1150 | if (!hsudc) | 1144 | if (!hsudc) |
@@ -1155,17 +1149,6 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver, | |||
1155 | 1149 | ||
1156 | hsudc->driver = driver; | 1150 | hsudc->driver = driver; |
1157 | hsudc->gadget.dev.driver = &driver->driver; | 1151 | hsudc->gadget.dev.driver = &driver->driver; |
1158 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1159 | |||
1160 | ret = bind(&hsudc->gadget); | ||
1161 | if (ret) { | ||
1162 | dev_err(hsudc->dev, "%s: bind failed\n", hsudc->gadget.name); | ||
1163 | device_del(&hsudc->gadget.dev); | ||
1164 | |||
1165 | hsudc->driver = NULL; | ||
1166 | hsudc->gadget.dev.driver = NULL; | ||
1167 | return ret; | ||
1168 | } | ||
1169 | 1152 | ||
1170 | /* connect to bus through transceiver */ | 1153 | /* connect to bus through transceiver */ |
1171 | if (hsudc->transceiver) { | 1154 | if (hsudc->transceiver) { |
@@ -1173,8 +1156,6 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver, | |||
1173 | if (ret) { | 1156 | if (ret) { |
1174 | dev_err(hsudc->dev, "%s: can't bind to transceiver\n", | 1157 | dev_err(hsudc->dev, "%s: can't bind to transceiver\n", |
1175 | hsudc->gadget.name); | 1158 | hsudc->gadget.name); |
1176 | driver->unbind(&hsudc->gadget); | ||
1177 | |||
1178 | hsudc->driver = NULL; | 1159 | hsudc->driver = NULL; |
1179 | hsudc->gadget.dev.driver = NULL; | 1160 | hsudc->gadget.dev.driver = NULL; |
1180 | return ret; | 1161 | return ret; |
@@ -1192,7 +1173,8 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver, | |||
1192 | return 0; | 1173 | return 0; |
1193 | } | 1174 | } |
1194 | 1175 | ||
1195 | static int s3c_hsudc_stop(struct usb_gadget_driver *driver) | 1176 | static int s3c_hsudc_stop(struct usb_gadget *gadget, |
1177 | struct usb_gadget_driver *driver) | ||
1196 | { | 1178 | { |
1197 | struct s3c_hsudc *hsudc = the_controller; | 1179 | struct s3c_hsudc *hsudc = the_controller; |
1198 | unsigned long flags; | 1180 | unsigned long flags; |
@@ -1200,21 +1182,22 @@ static int s3c_hsudc_stop(struct usb_gadget_driver *driver) | |||
1200 | if (!hsudc) | 1182 | if (!hsudc) |
1201 | return -ENODEV; | 1183 | return -ENODEV; |
1202 | 1184 | ||
1203 | if (!driver || driver != hsudc->driver || !driver->unbind) | 1185 | if (!driver || driver != hsudc->driver) |
1204 | return -EINVAL; | 1186 | return -EINVAL; |
1205 | 1187 | ||
1206 | spin_lock_irqsave(&hsudc->lock, flags); | 1188 | spin_lock_irqsave(&hsudc->lock, flags); |
1207 | hsudc->driver = 0; | 1189 | hsudc->driver = NULL; |
1190 | hsudc->gadget.dev.driver = NULL; | ||
1191 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1208 | s3c_hsudc_uninit_phy(); | 1192 | s3c_hsudc_uninit_phy(); |
1209 | if (hsudc->pd->gpio_uninit) | 1193 | if (hsudc->pd->gpio_uninit) |
1210 | hsudc->pd->gpio_uninit(); | 1194 | hsudc->pd->gpio_uninit(); |
1211 | s3c_hsudc_stop_activity(hsudc, driver); | 1195 | s3c_hsudc_stop_activity(hsudc); |
1212 | spin_unlock_irqrestore(&hsudc->lock, flags); | 1196 | spin_unlock_irqrestore(&hsudc->lock, flags); |
1213 | 1197 | ||
1214 | if (hsudc->transceiver) | 1198 | if (hsudc->transceiver) |
1215 | (void) otg_set_peripheral(hsudc->transceiver, NULL); | 1199 | (void) otg_set_peripheral(hsudc->transceiver, NULL); |
1216 | 1200 | ||
1217 | driver->unbind(&hsudc->gadget); | ||
1218 | disable_irq(hsudc->irq); | 1201 | disable_irq(hsudc->irq); |
1219 | 1202 | ||
1220 | dev_info(hsudc->dev, "unregistered gadget driver '%s'\n", | 1203 | dev_info(hsudc->dev, "unregistered gadget driver '%s'\n", |
@@ -1247,8 +1230,8 @@ static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA) | |||
1247 | 1230 | ||
1248 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { | 1231 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { |
1249 | .get_frame = s3c_hsudc_gadget_getframe, | 1232 | .get_frame = s3c_hsudc_gadget_getframe, |
1250 | .start = s3c_hsudc_start, | 1233 | .udc_start = s3c_hsudc_start, |
1251 | .stop = s3c_hsudc_stop, | 1234 | .udc_stop = s3c_hsudc_stop, |
1252 | .vbus_draw = s3c_hsudc_vbus_draw, | 1235 | .vbus_draw = s3c_hsudc_vbus_draw, |
1253 | }; | 1236 | }; |
1254 | 1237 | ||
@@ -1310,6 +1293,7 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev) | |||
1310 | 1293 | ||
1311 | hsudc->gadget.is_otg = 0; | 1294 | hsudc->gadget.is_otg = 0; |
1312 | hsudc->gadget.is_a_peripheral = 0; | 1295 | hsudc->gadget.is_a_peripheral = 0; |
1296 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1313 | 1297 | ||
1314 | s3c_hsudc_setup_ep(hsudc); | 1298 | s3c_hsudc_setup_ep(hsudc); |
1315 | 1299 | ||