Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Renesas USB driver |
| 3 | * |
| 4 | * Copyright (C) 2011 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | * |
| 16 | */ |
Kuninori Morimoto | dfbb7f4 | 2011-11-24 17:28:35 -0800 | [diff] [blame] | 17 | #include <linux/delay.h> |
Kuninori Morimoto | d128a259 | 2011-08-03 21:41:26 -0700 | [diff] [blame] | 18 | #include <linux/dma-mapping.h> |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 19 | #include <linux/io.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/usb/ch9.h> |
| 23 | #include <linux/usb/gadget.h> |
| 24 | #include "common.h" |
| 25 | |
| 26 | /* |
| 27 | * struct |
| 28 | */ |
| 29 | struct usbhsg_request { |
| 30 | struct usb_request req; |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 31 | struct usbhs_pkt pkt; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | #define EP_NAME_SIZE 8 |
| 35 | struct usbhsg_gpriv; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 36 | struct usbhsg_uep { |
| 37 | struct usb_ep ep; |
| 38 | struct usbhs_pipe *pipe; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 39 | |
| 40 | char ep_name[EP_NAME_SIZE]; |
| 41 | |
| 42 | struct usbhsg_gpriv *gpriv; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct usbhsg_gpriv { |
| 46 | struct usb_gadget gadget; |
| 47 | struct usbhs_mod mod; |
| 48 | |
| 49 | struct usbhsg_uep *uep; |
| 50 | int uep_size; |
| 51 | |
| 52 | struct usb_gadget_driver *driver; |
| 53 | |
| 54 | u32 status; |
| 55 | #define USBHSG_STATUS_STARTED (1 << 0) |
| 56 | #define USBHSG_STATUS_REGISTERD (1 << 1) |
| 57 | #define USBHSG_STATUS_WEDGE (1 << 2) |
Shimoda, Yoshihiro | cac402d | 2012-03-16 13:10:15 +0900 | [diff] [blame] | 58 | #define USBHSG_STATUS_SELF_POWERED (1 << 3) |
Takeshi Kihara | 04a5def | 2014-11-04 10:05:43 +0900 | [diff] [blame] | 59 | #define USBHSG_STATUS_SOFT_CONNECT (1 << 4) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 60 | }; |
| 61 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 62 | struct usbhsg_recip_handle { |
| 63 | char *name; |
| 64 | int (*device)(struct usbhs_priv *priv, struct usbhsg_uep *uep, |
| 65 | struct usb_ctrlrequest *ctrl); |
| 66 | int (*interface)(struct usbhs_priv *priv, struct usbhsg_uep *uep, |
| 67 | struct usb_ctrlrequest *ctrl); |
| 68 | int (*endpoint)(struct usbhs_priv *priv, struct usbhsg_uep *uep, |
| 69 | struct usb_ctrlrequest *ctrl); |
| 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * macro |
| 74 | */ |
| 75 | #define usbhsg_priv_to_gpriv(priv) \ |
| 76 | container_of( \ |
| 77 | usbhs_mod_get(priv, USBHS_GADGET), \ |
| 78 | struct usbhsg_gpriv, mod) |
| 79 | |
| 80 | #define __usbhsg_for_each_uep(start, pos, g, i) \ |
Kuninori Morimoto | 925403f | 2013-07-11 22:32:31 -0700 | [diff] [blame] | 81 | for ((i) = start; \ |
| 82 | ((i) < (g)->uep_size) && ((pos) = (g)->uep + (i)); \ |
| 83 | (i)++) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 84 | |
| 85 | #define usbhsg_for_each_uep(pos, gpriv, i) \ |
| 86 | __usbhsg_for_each_uep(1, pos, gpriv, i) |
| 87 | |
| 88 | #define usbhsg_for_each_uep_with_dcp(pos, gpriv, i) \ |
| 89 | __usbhsg_for_each_uep(0, pos, gpriv, i) |
| 90 | |
| 91 | #define usbhsg_gadget_to_gpriv(g)\ |
| 92 | container_of(g, struct usbhsg_gpriv, gadget) |
| 93 | |
| 94 | #define usbhsg_req_to_ureq(r)\ |
| 95 | container_of(r, struct usbhsg_request, req) |
| 96 | |
| 97 | #define usbhsg_ep_to_uep(e) container_of(e, struct usbhsg_uep, ep) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 98 | #define usbhsg_gpriv_to_dev(gp) usbhs_priv_to_dev((gp)->mod.priv) |
| 99 | #define usbhsg_gpriv_to_priv(gp) ((gp)->mod.priv) |
| 100 | #define usbhsg_gpriv_to_dcp(gp) ((gp)->uep) |
| 101 | #define usbhsg_gpriv_to_nth_uep(gp, i) ((gp)->uep + i) |
| 102 | #define usbhsg_uep_to_gpriv(u) ((u)->gpriv) |
| 103 | #define usbhsg_uep_to_pipe(u) ((u)->pipe) |
| 104 | #define usbhsg_pipe_to_uep(p) ((p)->mod_private) |
| 105 | #define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv)) |
| 106 | |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 107 | #define usbhsg_ureq_to_pkt(u) (&(u)->pkt) |
| 108 | #define usbhsg_pkt_to_ureq(i) \ |
| 109 | container_of(i, struct usbhsg_request, pkt) |
| 110 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 111 | #define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN) |
| 112 | |
| 113 | /* status */ |
| 114 | #define usbhsg_status_init(gp) do {(gp)->status = 0; } while (0) |
| 115 | #define usbhsg_status_set(gp, b) (gp->status |= b) |
| 116 | #define usbhsg_status_clr(gp, b) (gp->status &= ~b) |
| 117 | #define usbhsg_status_has(gp, b) (gp->status & b) |
| 118 | |
| 119 | /* |
Kuninori Morimoto | 233f519 | 2011-07-07 00:23:24 -0700 | [diff] [blame] | 120 | * queue push/pop |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 121 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 122 | static void usbhsg_queue_pop(struct usbhsg_uep *uep, |
| 123 | struct usbhsg_request *ureq, |
| 124 | int status) |
| 125 | { |
| 126 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 127 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 128 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 129 | |
| 130 | dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); |
| 131 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 132 | ureq->req.status = status; |
Michal Sojka | 304f7e5 | 2014-09-24 22:43:19 +0200 | [diff] [blame] | 133 | usb_gadget_giveback_request(&uep->ep, &ureq->req); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Kuninori Morimoto | 2cc9719 | 2011-10-10 22:03:39 -0700 | [diff] [blame] | 136 | static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 137 | { |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 138 | struct usbhs_pipe *pipe = pkt->pipe; |
| 139 | struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe); |
| 140 | struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt); |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 141 | |
Kuninori Morimoto | 659d495 | 2011-06-06 14:18:23 +0900 | [diff] [blame] | 142 | ureq->req.actual = pkt->actual; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 143 | |
Kuninori Morimoto | 659d495 | 2011-06-06 14:18:23 +0900 | [diff] [blame] | 144 | usbhsg_queue_pop(uep, ureq, 0); |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Kuninori Morimoto | b331872 | 2011-10-10 22:04:41 -0700 | [diff] [blame] | 147 | static void usbhsg_queue_push(struct usbhsg_uep *uep, |
| 148 | struct usbhsg_request *ureq) |
| 149 | { |
| 150 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 151 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
| 152 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 153 | struct usbhs_pkt *pkt = usbhsg_ureq_to_pkt(ureq); |
| 154 | struct usb_request *req = &ureq->req; |
| 155 | |
| 156 | req->actual = 0; |
| 157 | req->status = -EINPROGRESS; |
| 158 | usbhs_pkt_push(pipe, pkt, usbhsg_queue_done, |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 159 | req->buf, req->length, req->zero, -1); |
Kuninori Morimoto | 654c35a | 2011-10-10 22:04:53 -0700 | [diff] [blame] | 160 | usbhs_pkt_start(pipe); |
Kuninori Morimoto | b331872 | 2011-10-10 22:04:41 -0700 | [diff] [blame] | 161 | |
| 162 | dev_dbg(dev, "pipe %d : queue push (%d)\n", |
| 163 | usbhs_pipe_number(pipe), |
| 164 | req->length); |
| 165 | } |
| 166 | |
Kuninori Morimoto | 233f519 | 2011-07-07 00:23:24 -0700 | [diff] [blame] | 167 | /* |
| 168 | * dma map/unmap |
| 169 | */ |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 170 | static int usbhsg_dma_map_ctrl(struct usbhs_pkt *pkt, int map) |
| 171 | { |
Felipe Balbi | ade78f9 | 2011-12-19 11:57:16 +0200 | [diff] [blame] | 172 | struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt); |
| 173 | struct usb_request *req = &ureq->req; |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 174 | struct usbhs_pipe *pipe = pkt->pipe; |
| 175 | struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe); |
| 176 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 177 | enum dma_data_direction dir; |
Felipe Balbi | ade78f9 | 2011-12-19 11:57:16 +0200 | [diff] [blame] | 178 | int ret = 0; |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 179 | |
Felipe Balbi | ade78f9 | 2011-12-19 11:57:16 +0200 | [diff] [blame] | 180 | dir = usbhs_pipe_is_dir_host(pipe); |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 181 | |
Felipe Balbi | ade78f9 | 2011-12-19 11:57:16 +0200 | [diff] [blame] | 182 | if (map) { |
| 183 | /* it can not use scatter/gather */ |
| 184 | WARN_ON(req->num_sgs); |
| 185 | |
| 186 | ret = usb_gadget_map_request(&gpriv->gadget, req, dir); |
| 187 | if (ret < 0) |
| 188 | return ret; |
| 189 | |
| 190 | pkt->dma = req->dma; |
| 191 | } else { |
| 192 | usb_gadget_unmap_request(&gpriv->gadget, req, dir); |
| 193 | } |
| 194 | |
| 195 | return ret; |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 196 | } |
| 197 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 198 | /* |
| 199 | * USB_TYPE_STANDARD / clear feature functions |
| 200 | */ |
| 201 | static int usbhsg_recip_handler_std_control_done(struct usbhs_priv *priv, |
| 202 | struct usbhsg_uep *uep, |
| 203 | struct usb_ctrlrequest *ctrl) |
| 204 | { |
| 205 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 206 | struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); |
| 207 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp); |
| 208 | |
| 209 | usbhs_dcp_control_transfer_done(pipe); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv, |
| 215 | struct usbhsg_uep *uep, |
| 216 | struct usb_ctrlrequest *ctrl) |
| 217 | { |
| 218 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 219 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 220 | |
| 221 | if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) { |
Kuninori Morimoto | e8d548d | 2011-06-06 14:18:03 +0900 | [diff] [blame] | 222 | usbhs_pipe_disable(pipe); |
Kuninori Morimoto | 6e6db82 | 2011-10-10 22:05:30 -0700 | [diff] [blame] | 223 | usbhs_pipe_sequence_data0(pipe); |
Kuninori Morimoto | e8d548d | 2011-06-06 14:18:03 +0900 | [diff] [blame] | 224 | usbhs_pipe_enable(pipe); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | usbhsg_recip_handler_std_control_done(priv, uep, ctrl); |
| 228 | |
Kuninori Morimoto | 25fa707 | 2011-11-24 17:28:17 -0800 | [diff] [blame] | 229 | usbhs_pkt_start(pipe); |
| 230 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 234 | static struct usbhsg_recip_handle req_clear_feature = { |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 235 | .name = "clear feature", |
| 236 | .device = usbhsg_recip_handler_std_control_done, |
| 237 | .interface = usbhsg_recip_handler_std_control_done, |
| 238 | .endpoint = usbhsg_recip_handler_std_clear_endpoint, |
| 239 | }; |
| 240 | |
| 241 | /* |
Kuninori Morimoto | ced6e09 | 2011-11-24 17:27:50 -0800 | [diff] [blame] | 242 | * USB_TYPE_STANDARD / set feature functions |
| 243 | */ |
Kuninori Morimoto | dfbb7f4 | 2011-11-24 17:28:35 -0800 | [diff] [blame] | 244 | static int usbhsg_recip_handler_std_set_device(struct usbhs_priv *priv, |
| 245 | struct usbhsg_uep *uep, |
| 246 | struct usb_ctrlrequest *ctrl) |
| 247 | { |
| 248 | switch (le16_to_cpu(ctrl->wValue)) { |
| 249 | case USB_DEVICE_TEST_MODE: |
| 250 | usbhsg_recip_handler_std_control_done(priv, uep, ctrl); |
| 251 | udelay(100); |
| 252 | usbhs_sys_set_test_mode(priv, le16_to_cpu(ctrl->wIndex >> 8)); |
| 253 | break; |
| 254 | default: |
| 255 | usbhsg_recip_handler_std_control_done(priv, uep, ctrl); |
| 256 | break; |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Kuninori Morimoto | ced6e09 | 2011-11-24 17:27:50 -0800 | [diff] [blame] | 262 | static int usbhsg_recip_handler_std_set_endpoint(struct usbhs_priv *priv, |
| 263 | struct usbhsg_uep *uep, |
| 264 | struct usb_ctrlrequest *ctrl) |
| 265 | { |
| 266 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 267 | |
| 268 | usbhs_pipe_stall(pipe); |
| 269 | |
| 270 | usbhsg_recip_handler_std_control_done(priv, uep, ctrl); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 275 | static struct usbhsg_recip_handle req_set_feature = { |
Kuninori Morimoto | ced6e09 | 2011-11-24 17:27:50 -0800 | [diff] [blame] | 276 | .name = "set feature", |
Kuninori Morimoto | dfbb7f4 | 2011-11-24 17:28:35 -0800 | [diff] [blame] | 277 | .device = usbhsg_recip_handler_std_set_device, |
Kuninori Morimoto | ced6e09 | 2011-11-24 17:27:50 -0800 | [diff] [blame] | 278 | .interface = usbhsg_recip_handler_std_control_done, |
| 279 | .endpoint = usbhsg_recip_handler_std_set_endpoint, |
| 280 | }; |
| 281 | |
| 282 | /* |
Kuninori Morimoto | 17f7f76 | 2011-11-24 17:28:04 -0800 | [diff] [blame] | 283 | * USB_TYPE_STANDARD / get status functions |
| 284 | */ |
| 285 | static void __usbhsg_recip_send_complete(struct usb_ep *ep, |
| 286 | struct usb_request *req) |
| 287 | { |
| 288 | struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); |
| 289 | |
| 290 | /* free allocated recip-buffer/usb_request */ |
| 291 | kfree(ureq->pkt.buf); |
| 292 | usb_ep_free_request(ep, req); |
| 293 | } |
| 294 | |
| 295 | static void __usbhsg_recip_send_status(struct usbhsg_gpriv *gpriv, |
| 296 | unsigned short status) |
| 297 | { |
| 298 | struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); |
| 299 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp); |
| 300 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
| 301 | struct usb_request *req; |
| 302 | unsigned short *buf; |
| 303 | |
| 304 | /* alloc new usb_request for recip */ |
| 305 | req = usb_ep_alloc_request(&dcp->ep, GFP_ATOMIC); |
| 306 | if (!req) { |
| 307 | dev_err(dev, "recip request allocation fail\n"); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | /* alloc recip data buffer */ |
| 312 | buf = kmalloc(sizeof(*buf), GFP_ATOMIC); |
| 313 | if (!buf) { |
| 314 | usb_ep_free_request(&dcp->ep, req); |
| 315 | dev_err(dev, "recip data allocation fail\n"); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | /* recip data is status */ |
| 320 | *buf = cpu_to_le16(status); |
| 321 | |
| 322 | /* allocated usb_request/buffer will be freed */ |
| 323 | req->complete = __usbhsg_recip_send_complete; |
| 324 | req->buf = buf; |
| 325 | req->length = sizeof(*buf); |
| 326 | req->zero = 0; |
| 327 | |
| 328 | /* push packet */ |
| 329 | pipe->handler = &usbhs_fifo_pio_push_handler; |
| 330 | usbhsg_queue_push(dcp, usbhsg_req_to_ureq(req)); |
| 331 | } |
| 332 | |
| 333 | static int usbhsg_recip_handler_std_get_device(struct usbhs_priv *priv, |
| 334 | struct usbhsg_uep *uep, |
| 335 | struct usb_ctrlrequest *ctrl) |
| 336 | { |
| 337 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
Shimoda, Yoshihiro | cac402d | 2012-03-16 13:10:15 +0900 | [diff] [blame] | 338 | unsigned short status = 0; |
| 339 | |
| 340 | if (usbhsg_status_has(gpriv, USBHSG_STATUS_SELF_POWERED)) |
| 341 | status = 1 << USB_DEVICE_SELF_POWERED; |
Kuninori Morimoto | 17f7f76 | 2011-11-24 17:28:04 -0800 | [diff] [blame] | 342 | |
| 343 | __usbhsg_recip_send_status(gpriv, status); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static int usbhsg_recip_handler_std_get_interface(struct usbhs_priv *priv, |
| 349 | struct usbhsg_uep *uep, |
| 350 | struct usb_ctrlrequest *ctrl) |
| 351 | { |
| 352 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 353 | unsigned short status = 0; |
| 354 | |
| 355 | __usbhsg_recip_send_status(gpriv, status); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int usbhsg_recip_handler_std_get_endpoint(struct usbhs_priv *priv, |
| 361 | struct usbhsg_uep *uep, |
| 362 | struct usb_ctrlrequest *ctrl) |
| 363 | { |
| 364 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 365 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 366 | unsigned short status = 0; |
| 367 | |
| 368 | if (usbhs_pipe_is_stall(pipe)) |
| 369 | status = 1 << USB_ENDPOINT_HALT; |
| 370 | |
| 371 | __usbhsg_recip_send_status(gpriv, status); |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 376 | static struct usbhsg_recip_handle req_get_status = { |
Kuninori Morimoto | 17f7f76 | 2011-11-24 17:28:04 -0800 | [diff] [blame] | 377 | .name = "get status", |
| 378 | .device = usbhsg_recip_handler_std_get_device, |
| 379 | .interface = usbhsg_recip_handler_std_get_interface, |
| 380 | .endpoint = usbhsg_recip_handler_std_get_endpoint, |
| 381 | }; |
| 382 | |
| 383 | /* |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 384 | * USB_TYPE handler |
| 385 | */ |
| 386 | static int usbhsg_recip_run_handle(struct usbhs_priv *priv, |
| 387 | struct usbhsg_recip_handle *handler, |
| 388 | struct usb_ctrlrequest *ctrl) |
| 389 | { |
| 390 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 391 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
| 392 | struct usbhsg_uep *uep; |
Kuninori Morimoto | 0432eed | 2011-06-06 14:18:54 +0900 | [diff] [blame] | 393 | struct usbhs_pipe *pipe; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 394 | int recip = ctrl->bRequestType & USB_RECIP_MASK; |
| 395 | int nth = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; |
Jesper Juhl | 7983bc7 | 2012-01-16 22:42:10 +0100 | [diff] [blame] | 396 | int ret = 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 397 | int (*func)(struct usbhs_priv *priv, struct usbhsg_uep *uep, |
| 398 | struct usb_ctrlrequest *ctrl); |
| 399 | char *msg; |
| 400 | |
| 401 | uep = usbhsg_gpriv_to_nth_uep(gpriv, nth); |
Kuninori Morimoto | 0432eed | 2011-06-06 14:18:54 +0900 | [diff] [blame] | 402 | pipe = usbhsg_uep_to_pipe(uep); |
| 403 | if (!pipe) { |
Kuninori Morimoto | 9a28b7b | 2011-04-21 14:10:12 +0900 | [diff] [blame] | 404 | dev_err(dev, "wrong recip request\n"); |
Kuninori Morimoto | 25fa707 | 2011-11-24 17:28:17 -0800 | [diff] [blame] | 405 | return -EINVAL; |
Kuninori Morimoto | 9a28b7b | 2011-04-21 14:10:12 +0900 | [diff] [blame] | 406 | } |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 407 | |
| 408 | switch (recip) { |
| 409 | case USB_RECIP_DEVICE: |
| 410 | msg = "DEVICE"; |
| 411 | func = handler->device; |
| 412 | break; |
| 413 | case USB_RECIP_INTERFACE: |
| 414 | msg = "INTERFACE"; |
| 415 | func = handler->interface; |
| 416 | break; |
| 417 | case USB_RECIP_ENDPOINT: |
| 418 | msg = "ENDPOINT"; |
| 419 | func = handler->endpoint; |
| 420 | break; |
| 421 | default: |
| 422 | dev_warn(dev, "unsupported RECIP(%d)\n", recip); |
| 423 | func = NULL; |
| 424 | ret = -EINVAL; |
| 425 | } |
| 426 | |
| 427 | if (func) { |
| 428 | dev_dbg(dev, "%s (pipe %d :%s)\n", handler->name, nth, msg); |
| 429 | ret = func(priv, uep, ctrl); |
| 430 | } |
| 431 | |
| 432 | return ret; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * irq functions |
| 437 | * |
| 438 | * it will be called from usbhs_interrupt |
| 439 | */ |
| 440 | static int usbhsg_irq_dev_state(struct usbhs_priv *priv, |
| 441 | struct usbhs_irq_state *irq_state) |
| 442 | { |
| 443 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 444 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
| 445 | |
Kuninori Morimoto | 75587f5 | 2011-10-10 22:01:51 -0700 | [diff] [blame] | 446 | gpriv->gadget.speed = usbhs_bus_get_speed(priv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 447 | |
| 448 | dev_dbg(dev, "state = %x : speed : %d\n", |
| 449 | usbhs_status_get_device_state(irq_state), |
| 450 | gpriv->gadget.speed); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv, |
| 456 | struct usbhs_irq_state *irq_state) |
| 457 | { |
| 458 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 459 | struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); |
| 460 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp); |
| 461 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
| 462 | struct usb_ctrlrequest ctrl; |
| 463 | struct usbhsg_recip_handle *recip_handler = NULL; |
| 464 | int stage = usbhs_status_get_ctrl_stage(irq_state); |
| 465 | int ret = 0; |
| 466 | |
| 467 | dev_dbg(dev, "stage = %d\n", stage); |
| 468 | |
| 469 | /* |
| 470 | * see Manual |
| 471 | * |
| 472 | * "Operation" |
| 473 | * - "Interrupt Function" |
| 474 | * - "Control Transfer Stage Transition Interrupt" |
| 475 | * - Fig. "Control Transfer Stage Transitions" |
| 476 | */ |
| 477 | |
| 478 | switch (stage) { |
| 479 | case READ_DATA_STAGE: |
Kuninori Morimoto | 0c6ef98 | 2011-10-10 22:00:59 -0700 | [diff] [blame] | 480 | pipe->handler = &usbhs_fifo_pio_push_handler; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 481 | break; |
| 482 | case WRITE_DATA_STAGE: |
Kuninori Morimoto | 0c6ef98 | 2011-10-10 22:00:59 -0700 | [diff] [blame] | 483 | pipe->handler = &usbhs_fifo_pio_pop_handler; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 484 | break; |
| 485 | case NODATA_STATUS_STAGE: |
Kuninori Morimoto | 0c6ef98 | 2011-10-10 22:00:59 -0700 | [diff] [blame] | 486 | pipe->handler = &usbhs_ctrl_stage_end_handler; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 487 | break; |
Yoshihiro Shimoda | 4ef35b1 | 2014-11-04 10:05:44 +0900 | [diff] [blame] | 488 | case READ_STATUS_STAGE: |
| 489 | case WRITE_STATUS_STAGE: |
| 490 | usbhs_dcp_control_transfer_done(pipe); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 491 | default: |
| 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * get usb request |
| 497 | */ |
| 498 | usbhs_usbreq_get_val(priv, &ctrl); |
| 499 | |
| 500 | switch (ctrl.bRequestType & USB_TYPE_MASK) { |
| 501 | case USB_TYPE_STANDARD: |
| 502 | switch (ctrl.bRequest) { |
| 503 | case USB_REQ_CLEAR_FEATURE: |
| 504 | recip_handler = &req_clear_feature; |
| 505 | break; |
Kuninori Morimoto | ced6e09 | 2011-11-24 17:27:50 -0800 | [diff] [blame] | 506 | case USB_REQ_SET_FEATURE: |
| 507 | recip_handler = &req_set_feature; |
| 508 | break; |
Kuninori Morimoto | 17f7f76 | 2011-11-24 17:28:04 -0800 | [diff] [blame] | 509 | case USB_REQ_GET_STATUS: |
| 510 | recip_handler = &req_get_status; |
| 511 | break; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * setup stage / run recip |
| 517 | */ |
| 518 | if (recip_handler) |
| 519 | ret = usbhsg_recip_run_handle(priv, recip_handler, &ctrl); |
| 520 | else |
| 521 | ret = gpriv->driver->setup(&gpriv->gadget, &ctrl); |
| 522 | |
| 523 | if (ret < 0) |
Kuninori Morimoto | e8d548d | 2011-06-06 14:18:03 +0900 | [diff] [blame] | 524 | usbhs_pipe_stall(pipe); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 529 | /* |
| 530 | * |
| 531 | * usb_dcp_ops |
| 532 | * |
| 533 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 534 | static int usbhsg_pipe_disable(struct usbhsg_uep *uep) |
| 535 | { |
| 536 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
Kuninori Morimoto | 8a2c225 | 2011-06-06 14:18:33 +0900 | [diff] [blame] | 537 | struct usbhs_pkt *pkt; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 538 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 539 | while (1) { |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 540 | pkt = usbhs_pkt_pop(pipe, NULL); |
Kuninori Morimoto | 8a2c225 | 2011-06-06 14:18:33 +0900 | [diff] [blame] | 541 | if (!pkt) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 542 | break; |
Kuninori Morimoto | 91b158f | 2011-11-24 17:28:26 -0800 | [diff] [blame] | 543 | |
| 544 | usbhsg_queue_pop(uep, usbhsg_pkt_to_ureq(pkt), -ECONNRESET); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 545 | } |
| 546 | |
Kuninori Morimoto | 91b158f | 2011-11-24 17:28:26 -0800 | [diff] [blame] | 547 | usbhs_pipe_disable(pipe); |
| 548 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * |
| 554 | * usb_ep_ops |
| 555 | * |
| 556 | */ |
| 557 | static int usbhsg_ep_enable(struct usb_ep *ep, |
| 558 | const struct usb_endpoint_descriptor *desc) |
| 559 | { |
| 560 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
| 561 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 562 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
| 563 | struct usbhs_pipe *pipe; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 564 | int ret = -EIO; |
| 565 | |
Kuninori Morimoto | 409ba9e | 2011-04-26 09:21:35 +0900 | [diff] [blame] | 566 | /* |
| 567 | * if it already have pipe, |
| 568 | * nothing to do |
| 569 | */ |
Kuninori Morimoto | 08e6c61 | 2011-06-09 16:48:25 +0900 | [diff] [blame] | 570 | if (uep->pipe) { |
| 571 | usbhs_pipe_clear(uep->pipe); |
Kuninori Morimoto | 6e6db82 | 2011-10-10 22:05:30 -0700 | [diff] [blame] | 572 | usbhs_pipe_sequence_data0(uep->pipe); |
Kuninori Morimoto | 409ba9e | 2011-04-26 09:21:35 +0900 | [diff] [blame] | 573 | return 0; |
Kuninori Morimoto | 08e6c61 | 2011-06-09 16:48:25 +0900 | [diff] [blame] | 574 | } |
Kuninori Morimoto | 409ba9e | 2011-04-26 09:21:35 +0900 | [diff] [blame] | 575 | |
Kuninori Morimoto | f5aa889 | 2011-10-10 21:59:46 -0700 | [diff] [blame] | 576 | pipe = usbhs_pipe_malloc(priv, |
| 577 | usb_endpoint_type(desc), |
| 578 | usb_endpoint_dir_in(desc)); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 579 | if (pipe) { |
| 580 | uep->pipe = pipe; |
| 581 | pipe->mod_private = uep; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 582 | |
Kuninori Morimoto | f5aa889 | 2011-10-10 21:59:46 -0700 | [diff] [blame] | 583 | /* set epnum / maxp */ |
Kuninori Morimoto | bc6fbf5 | 2011-10-10 22:04:00 -0700 | [diff] [blame] | 584 | usbhs_pipe_config_update(pipe, 0, |
Kuninori Morimoto | f5aa889 | 2011-10-10 21:59:46 -0700 | [diff] [blame] | 585 | usb_endpoint_num(desc), |
| 586 | usb_endpoint_maxp(desc)); |
| 587 | |
Kuninori Morimoto | 233f519 | 2011-07-07 00:23:24 -0700 | [diff] [blame] | 588 | /* |
| 589 | * usbhs_fifo_dma_push/pop_handler try to |
| 590 | * use dmaengine if possible. |
| 591 | * It will use pio handler if impossible. |
| 592 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 593 | if (usb_endpoint_dir_in(desc)) |
Kuninori Morimoto | 0c6ef98 | 2011-10-10 22:00:59 -0700 | [diff] [blame] | 594 | pipe->handler = &usbhs_fifo_dma_push_handler; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 595 | else |
Kuninori Morimoto | 0c6ef98 | 2011-10-10 22:00:59 -0700 | [diff] [blame] | 596 | pipe->handler = &usbhs_fifo_dma_pop_handler; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 597 | |
| 598 | ret = 0; |
| 599 | } |
Kuninori Morimoto | cb96632 | 2011-04-21 14:10:08 +0900 | [diff] [blame] | 600 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 601 | return ret; |
| 602 | } |
| 603 | |
| 604 | static int usbhsg_ep_disable(struct usb_ep *ep) |
| 605 | { |
| 606 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
Yoshihiro Shimoda | dfb87b8 | 2014-07-09 20:30:13 +0900 | [diff] [blame] | 607 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 608 | |
Kazuya Mizuguchi | 1143205 | 2014-11-04 10:05:42 +0900 | [diff] [blame] | 609 | if (!pipe) |
| 610 | return -EINVAL; |
| 611 | |
Kuninori Morimoto | d9fa298 | 2012-12-10 22:44:07 -0800 | [diff] [blame] | 612 | usbhsg_pipe_disable(uep); |
Yoshihiro Shimoda | dfb87b8 | 2014-07-09 20:30:13 +0900 | [diff] [blame] | 613 | usbhs_pipe_free(pipe); |
Kuninori Morimoto | d9fa298 | 2012-12-10 22:44:07 -0800 | [diff] [blame] | 614 | |
| 615 | uep->pipe->mod_private = NULL; |
| 616 | uep->pipe = NULL; |
| 617 | |
| 618 | return 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep, |
| 622 | gfp_t gfp_flags) |
| 623 | { |
| 624 | struct usbhsg_request *ureq; |
| 625 | |
| 626 | ureq = kzalloc(sizeof *ureq, gfp_flags); |
| 627 | if (!ureq) |
| 628 | return NULL; |
| 629 | |
Kuninori Morimoto | 6acb95d | 2011-06-06 14:18:16 +0900 | [diff] [blame] | 630 | usbhs_pkt_init(usbhsg_ureq_to_pkt(ureq)); |
| 631 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 632 | return &ureq->req; |
| 633 | } |
| 634 | |
| 635 | static void usbhsg_ep_free_request(struct usb_ep *ep, |
| 636 | struct usb_request *req) |
| 637 | { |
| 638 | struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); |
| 639 | |
Kuninori Morimoto | 6acb95d | 2011-06-06 14:18:16 +0900 | [diff] [blame] | 640 | WARN_ON(!list_empty(&ureq->pkt.node)); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 641 | kfree(ureq); |
| 642 | } |
| 643 | |
| 644 | static int usbhsg_ep_queue(struct usb_ep *ep, struct usb_request *req, |
| 645 | gfp_t gfp_flags) |
| 646 | { |
| 647 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
| 648 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
| 649 | struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); |
| 650 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 651 | |
| 652 | /* param check */ |
| 653 | if (usbhsg_is_not_connected(gpriv) || |
| 654 | unlikely(!gpriv->driver) || |
| 655 | unlikely(!pipe)) |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 656 | return -ESHUTDOWN; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 657 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 658 | usbhsg_queue_push(uep, ureq); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 659 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 660 | return 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) |
| 664 | { |
| 665 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
| 666 | struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 667 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 668 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 669 | usbhs_pkt_pop(pipe, usbhsg_ureq_to_pkt(ureq)); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 670 | usbhsg_queue_pop(uep, ureq, -ECONNRESET); |
| 671 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge) |
| 676 | { |
| 677 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
| 678 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
| 679 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 680 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 681 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 682 | unsigned long flags; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 683 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 684 | usbhsg_pipe_disable(uep); |
| 685 | |
| 686 | dev_dbg(dev, "set halt %d (pipe %d)\n", |
| 687 | halt, usbhs_pipe_number(pipe)); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 688 | |
| 689 | /******************** spin lock ********************/ |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 690 | usbhs_lock(priv, flags); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 691 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 692 | if (halt) |
| 693 | usbhs_pipe_stall(pipe); |
| 694 | else |
| 695 | usbhs_pipe_disable(pipe); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 696 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 697 | if (halt && wedge) |
| 698 | usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE); |
| 699 | else |
| 700 | usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 701 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 702 | usbhs_unlock(priv, flags); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 703 | /******************** spin unlock ******************/ |
| 704 | |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 705 | return 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static int usbhsg_ep_set_halt(struct usb_ep *ep, int value) |
| 709 | { |
| 710 | return __usbhsg_ep_set_halt_wedge(ep, value, 0); |
| 711 | } |
| 712 | |
| 713 | static int usbhsg_ep_set_wedge(struct usb_ep *ep) |
| 714 | { |
| 715 | return __usbhsg_ep_set_halt_wedge(ep, 1, 1); |
| 716 | } |
| 717 | |
| 718 | static struct usb_ep_ops usbhsg_ep_ops = { |
| 719 | .enable = usbhsg_ep_enable, |
| 720 | .disable = usbhsg_ep_disable, |
| 721 | |
| 722 | .alloc_request = usbhsg_ep_alloc_request, |
| 723 | .free_request = usbhsg_ep_free_request, |
| 724 | |
| 725 | .queue = usbhsg_ep_queue, |
| 726 | .dequeue = usbhsg_ep_dequeue, |
| 727 | |
| 728 | .set_halt = usbhsg_ep_set_halt, |
| 729 | .set_wedge = usbhsg_ep_set_wedge, |
| 730 | }; |
| 731 | |
| 732 | /* |
Takeshi Kihara | 04a5def | 2014-11-04 10:05:43 +0900 | [diff] [blame] | 733 | * pullup control |
| 734 | */ |
| 735 | static int usbhsg_can_pullup(struct usbhs_priv *priv) |
| 736 | { |
| 737 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 738 | |
| 739 | return gpriv->driver && |
| 740 | usbhsg_status_has(gpriv, USBHSG_STATUS_SOFT_CONNECT); |
| 741 | } |
| 742 | |
| 743 | static void usbhsg_update_pullup(struct usbhs_priv *priv) |
| 744 | { |
| 745 | if (usbhsg_can_pullup(priv)) |
| 746 | usbhs_sys_function_pullup(priv, 1); |
| 747 | else |
| 748 | usbhs_sys_function_pullup(priv, 0); |
| 749 | } |
| 750 | |
| 751 | /* |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 752 | * usb module start/end |
| 753 | */ |
| 754 | static int usbhsg_try_start(struct usbhs_priv *priv, u32 status) |
| 755 | { |
| 756 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 757 | struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); |
| 758 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
| 759 | struct device *dev = usbhs_priv_to_dev(priv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 760 | unsigned long flags; |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 761 | int ret = 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 762 | |
| 763 | /******************** spin lock ********************/ |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 764 | usbhs_lock(priv, flags); |
| 765 | |
| 766 | usbhsg_status_set(gpriv, status); |
| 767 | if (!(usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) && |
| 768 | usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD))) |
| 769 | ret = -1; /* not ready */ |
| 770 | |
| 771 | usbhs_unlock(priv, flags); |
| 772 | /******************** spin unlock ********************/ |
| 773 | |
| 774 | if (ret < 0) |
| 775 | return 0; /* not ready is not error */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 776 | |
| 777 | /* |
| 778 | * enable interrupt and systems if ready |
| 779 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 780 | dev_dbg(dev, "start gadget\n"); |
| 781 | |
| 782 | /* |
| 783 | * pipe initialize and enable DCP |
| 784 | */ |
Yoshihiro Shimoda | cdeb794 | 2014-11-04 10:05:45 +0900 | [diff] [blame^] | 785 | usbhs_fifo_init(priv); |
Kuninori Morimoto | 4bd0481 | 2011-06-06 14:18:07 +0900 | [diff] [blame] | 786 | usbhs_pipe_init(priv, |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 787 | usbhsg_dma_map_ctrl); |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 788 | |
Kuninori Morimoto | d9fa298 | 2012-12-10 22:44:07 -0800 | [diff] [blame] | 789 | /* dcp init instead of usbhsg_ep_enable() */ |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 790 | dcp->pipe = usbhs_dcp_malloc(priv); |
| 791 | dcp->pipe->mod_private = dcp; |
Kuninori Morimoto | bc6fbf5 | 2011-10-10 22:04:00 -0700 | [diff] [blame] | 792 | usbhs_pipe_config_update(dcp->pipe, 0, 0, 64); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 793 | |
| 794 | /* |
| 795 | * system config enble |
| 796 | * - HI speed |
| 797 | * - function |
| 798 | * - usb module |
| 799 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 800 | usbhs_sys_function_ctrl(priv, 1); |
Takeshi Kihara | 04a5def | 2014-11-04 10:05:43 +0900 | [diff] [blame] | 801 | usbhsg_update_pullup(priv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 802 | |
| 803 | /* |
| 804 | * enable irq callback |
| 805 | */ |
| 806 | mod->irq_dev_state = usbhsg_irq_dev_state; |
| 807 | mod->irq_ctrl_stage = usbhsg_irq_ctrl_stage; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 808 | usbhs_irq_callback_update(priv, mod); |
| 809 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status) |
| 814 | { |
| 815 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 816 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
| 817 | struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); |
| 818 | struct device *dev = usbhs_priv_to_dev(priv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 819 | unsigned long flags; |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 820 | int ret = 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 821 | |
| 822 | /******************** spin lock ********************/ |
Kuninori Morimoto | 97664a2 | 2011-06-06 14:18:38 +0900 | [diff] [blame] | 823 | usbhs_lock(priv, flags); |
| 824 | |
| 825 | usbhsg_status_clr(gpriv, status); |
| 826 | if (!usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) && |
| 827 | !usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD)) |
| 828 | ret = -1; /* already done */ |
| 829 | |
| 830 | usbhs_unlock(priv, flags); |
| 831 | /******************** spin unlock ********************/ |
| 832 | |
| 833 | if (ret < 0) |
| 834 | return 0; /* already done is not error */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 835 | |
| 836 | /* |
| 837 | * disable interrupt and systems if 1st try |
| 838 | */ |
Kuninori Morimoto | dad6739 | 2011-06-06 14:18:28 +0900 | [diff] [blame] | 839 | usbhs_fifo_quit(priv); |
| 840 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 841 | /* disable all irq */ |
| 842 | mod->irq_dev_state = NULL; |
| 843 | mod->irq_ctrl_stage = NULL; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 844 | usbhs_irq_callback_update(priv, mod); |
| 845 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 846 | gpriv->gadget.speed = USB_SPEED_UNKNOWN; |
| 847 | |
| 848 | /* disable sys */ |
Kuninori Morimoto | dfbb7f4 | 2011-11-24 17:28:35 -0800 | [diff] [blame] | 849 | usbhs_sys_set_test_mode(priv, 0); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 850 | usbhs_sys_function_ctrl(priv, 0); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 851 | |
Kuninori Morimoto | d9fa298 | 2012-12-10 22:44:07 -0800 | [diff] [blame] | 852 | usbhsg_ep_disable(&dcp->ep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 853 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 854 | dev_dbg(dev, "stop gadget\n"); |
| 855 | |
| 856 | return 0; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | /* |
| 860 | * |
| 861 | * linux usb function |
| 862 | * |
| 863 | */ |
Felipe Balbi | af1d705 | 2011-10-10 17:11:20 +0300 | [diff] [blame] | 864 | static int usbhsg_gadget_start(struct usb_gadget *gadget, |
| 865 | struct usb_gadget_driver *driver) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 866 | { |
Felipe Balbi | af1d705 | 2011-10-10 17:11:20 +0300 | [diff] [blame] | 867 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
Kuninori Morimoto | f8eff0a | 2011-11-17 18:19:06 -0800 | [diff] [blame] | 868 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 869 | |
Felipe Balbi | af1d705 | 2011-10-10 17:11:20 +0300 | [diff] [blame] | 870 | if (!driver || |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 871 | !driver->setup || |
Michal Nazarewicz | 7177aed | 2011-11-19 18:27:38 +0100 | [diff] [blame] | 872 | driver->max_speed < USB_SPEED_FULL) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 873 | return -EINVAL; |
Kuninori Morimoto | 3b87218 | 2011-07-03 17:42:35 -0700 | [diff] [blame] | 874 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 875 | /* first hook up the driver ... */ |
| 876 | gpriv->driver = driver; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 877 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 878 | return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 879 | } |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 880 | |
Felipe Balbi | 22835b8 | 2014-10-17 12:05:12 -0500 | [diff] [blame] | 881 | static int usbhsg_gadget_stop(struct usb_gadget *gadget) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 882 | { |
Felipe Balbi | af1d705 | 2011-10-10 17:11:20 +0300 | [diff] [blame] | 883 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
Kuninori Morimoto | f8eff0a | 2011-11-17 18:19:06 -0800 | [diff] [blame] | 884 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 885 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 886 | usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 887 | gpriv->driver = NULL; |
| 888 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 889 | return 0; |
| 890 | } |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 891 | |
| 892 | /* |
| 893 | * usb gadget ops |
| 894 | */ |
| 895 | static int usbhsg_get_frame(struct usb_gadget *gadget) |
| 896 | { |
| 897 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
| 898 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
| 899 | |
| 900 | return usbhs_frame_get_num(priv); |
| 901 | } |
| 902 | |
kuninori.morimoto.gx@renesas.com | 4cd2f59 | 2012-10-15 23:24:19 -0700 | [diff] [blame] | 903 | static int usbhsg_pullup(struct usb_gadget *gadget, int is_on) |
| 904 | { |
| 905 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
| 906 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
Takeshi Kihara | 04a5def | 2014-11-04 10:05:43 +0900 | [diff] [blame] | 907 | unsigned long flags; |
kuninori.morimoto.gx@renesas.com | 4cd2f59 | 2012-10-15 23:24:19 -0700 | [diff] [blame] | 908 | |
Takeshi Kihara | 04a5def | 2014-11-04 10:05:43 +0900 | [diff] [blame] | 909 | usbhs_lock(priv, flags); |
| 910 | if (is_on) |
| 911 | usbhsg_status_set(gpriv, USBHSG_STATUS_SOFT_CONNECT); |
| 912 | else |
| 913 | usbhsg_status_clr(gpriv, USBHSG_STATUS_SOFT_CONNECT); |
| 914 | usbhsg_update_pullup(priv); |
| 915 | usbhs_unlock(priv, flags); |
kuninori.morimoto.gx@renesas.com | 4cd2f59 | 2012-10-15 23:24:19 -0700 | [diff] [blame] | 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
Shimoda, Yoshihiro | cac402d | 2012-03-16 13:10:15 +0900 | [diff] [blame] | 920 | static int usbhsg_set_selfpowered(struct usb_gadget *gadget, int is_self) |
| 921 | { |
| 922 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
| 923 | |
| 924 | if (is_self) |
| 925 | usbhsg_status_set(gpriv, USBHSG_STATUS_SELF_POWERED); |
| 926 | else |
| 927 | usbhsg_status_clr(gpriv, USBHSG_STATUS_SELF_POWERED); |
| 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
Felipe Balbi | eeef458 | 2013-01-24 17:58:16 +0200 | [diff] [blame] | 932 | static const struct usb_gadget_ops usbhsg_gadget_ops = { |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 933 | .get_frame = usbhsg_get_frame, |
Shimoda, Yoshihiro | cac402d | 2012-03-16 13:10:15 +0900 | [diff] [blame] | 934 | .set_selfpowered = usbhsg_set_selfpowered, |
Felipe Balbi | af1d705 | 2011-10-10 17:11:20 +0300 | [diff] [blame] | 935 | .udc_start = usbhsg_gadget_start, |
| 936 | .udc_stop = usbhsg_gadget_stop, |
kuninori.morimoto.gx@renesas.com | 4cd2f59 | 2012-10-15 23:24:19 -0700 | [diff] [blame] | 937 | .pullup = usbhsg_pullup, |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 938 | }; |
| 939 | |
| 940 | static int usbhsg_start(struct usbhs_priv *priv) |
| 941 | { |
| 942 | return usbhsg_try_start(priv, USBHSG_STATUS_STARTED); |
| 943 | } |
| 944 | |
| 945 | static int usbhsg_stop(struct usbhs_priv *priv) |
| 946 | { |
Kuninori Morimoto | 8885a89 | 2011-11-17 18:19:38 -0800 | [diff] [blame] | 947 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 948 | |
| 949 | /* cable disconnect */ |
| 950 | if (gpriv->driver && |
| 951 | gpriv->driver->disconnect) |
| 952 | gpriv->driver->disconnect(&gpriv->gadget); |
| 953 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 954 | return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); |
| 955 | } |
| 956 | |
Kuninori Morimoto | b7a8d17 | 2011-10-26 19:33:49 -0700 | [diff] [blame] | 957 | int usbhs_mod_gadget_probe(struct usbhs_priv *priv) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 958 | { |
| 959 | struct usbhsg_gpriv *gpriv; |
| 960 | struct usbhsg_uep *uep; |
| 961 | struct device *dev = usbhs_priv_to_dev(priv); |
| 962 | int pipe_size = usbhs_get_dparam(priv, pipe_size); |
| 963 | int i; |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 964 | int ret; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 965 | |
| 966 | gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL); |
| 967 | if (!gpriv) { |
| 968 | dev_err(dev, "Could not allocate gadget priv\n"); |
| 969 | return -ENOMEM; |
| 970 | } |
| 971 | |
| 972 | uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL); |
| 973 | if (!uep) { |
| 974 | dev_err(dev, "Could not allocate ep\n"); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 975 | ret = -ENOMEM; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 976 | goto usbhs_mod_gadget_probe_err_gpriv; |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | * CAUTION |
| 981 | * |
| 982 | * There is no guarantee that it is possible to access usb module here. |
| 983 | * Don't accesses to it. |
| 984 | * The accesse will be enable after "usbhsg_start" |
| 985 | */ |
| 986 | |
| 987 | /* |
| 988 | * register itself |
| 989 | */ |
| 990 | usbhs_mod_register(priv, &gpriv->mod, USBHS_GADGET); |
| 991 | |
| 992 | /* init gpriv */ |
| 993 | gpriv->mod.name = "gadget"; |
| 994 | gpriv->mod.start = usbhsg_start; |
| 995 | gpriv->mod.stop = usbhsg_stop; |
| 996 | gpriv->uep = uep; |
| 997 | gpriv->uep_size = pipe_size; |
| 998 | usbhsg_status_init(gpriv); |
| 999 | |
| 1000 | /* |
| 1001 | * init gadget |
| 1002 | */ |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1003 | gpriv->gadget.dev.parent = dev; |
| 1004 | gpriv->gadget.name = "renesas_usbhs_udc"; |
| 1005 | gpriv->gadget.ops = &usbhsg_gadget_ops; |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 1006 | gpriv->gadget.max_speed = USB_SPEED_HIGH; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1007 | |
| 1008 | INIT_LIST_HEAD(&gpriv->gadget.ep_list); |
| 1009 | |
| 1010 | /* |
| 1011 | * init usb_ep |
| 1012 | */ |
| 1013 | usbhsg_for_each_uep_with_dcp(uep, gpriv, i) { |
| 1014 | uep->gpriv = gpriv; |
Kuninori Morimoto | 5848294 | 2012-12-10 22:43:45 -0800 | [diff] [blame] | 1015 | uep->pipe = NULL; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1016 | snprintf(uep->ep_name, EP_NAME_SIZE, "ep%d", i); |
| 1017 | |
| 1018 | uep->ep.name = uep->ep_name; |
| 1019 | uep->ep.ops = &usbhsg_ep_ops; |
| 1020 | INIT_LIST_HEAD(&uep->ep.ep_list); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1021 | |
| 1022 | /* init DCP */ |
| 1023 | if (usbhsg_is_dcp(uep)) { |
| 1024 | gpriv->gadget.ep0 = &uep->ep; |
Robert Baldyga | e117e74 | 2013-12-13 12:23:38 +0100 | [diff] [blame] | 1025 | usb_ep_set_maxpacket_limit(&uep->ep, 64); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1026 | } |
| 1027 | /* init normal pipe */ |
| 1028 | else { |
Robert Baldyga | e117e74 | 2013-12-13 12:23:38 +0100 | [diff] [blame] | 1029 | usb_ep_set_maxpacket_limit(&uep->ep, 512); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1030 | list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); |
| 1031 | } |
| 1032 | } |
| 1033 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1034 | ret = usb_add_gadget_udc(dev, &gpriv->gadget); |
| 1035 | if (ret) |
Felipe Balbi | 0972ef7 | 2013-01-24 17:08:01 +0200 | [diff] [blame] | 1036 | goto err_add_udc; |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1037 | |
| 1038 | |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1039 | dev_info(dev, "gadget probed\n"); |
| 1040 | |
| 1041 | return 0; |
Kuninori Morimoto | f8eff0a | 2011-11-17 18:19:06 -0800 | [diff] [blame] | 1042 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1043 | err_add_udc: |
| 1044 | kfree(gpriv->uep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1045 | |
| 1046 | usbhs_mod_gadget_probe_err_gpriv: |
| 1047 | kfree(gpriv); |
| 1048 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1049 | return ret; |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1050 | } |
| 1051 | |
Kuninori Morimoto | b7a8d17 | 2011-10-26 19:33:49 -0700 | [diff] [blame] | 1052 | void usbhs_mod_gadget_remove(struct usbhs_priv *priv) |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1053 | { |
| 1054 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); |
| 1055 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1056 | usb_del_gadget_udc(&gpriv->gadget); |
Kuninori Morimoto | 3b87218 | 2011-07-03 17:42:35 -0700 | [diff] [blame] | 1057 | |
Sebastian Andrzej Siewior | 3af51ac | 2011-06-03 19:50:48 +0200 | [diff] [blame] | 1058 | kfree(gpriv->uep); |
Kuninori Morimoto | 2f98382 | 2011-04-05 11:40:54 +0900 | [diff] [blame] | 1059 | kfree(gpriv); |
| 1060 | } |