aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/renesas_usbhs
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/renesas_usbhs')
-rw-r--r--drivers/usb/renesas_usbhs/Kconfig16
-rw-r--r--drivers/usb/renesas_usbhs/Makefile9
-rw-r--r--drivers/usb/renesas_usbhs/common.c437
-rw-r--r--drivers/usb/renesas_usbhs/common.h230
-rw-r--r--drivers/usb/renesas_usbhs/mod.c328
-rw-r--r--drivers/usb/renesas_usbhs/mod.h137
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c1385
-rw-r--r--drivers/usb/renesas_usbhs/pipe.c874
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h104
9 files changed, 3520 insertions, 0 deletions
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig
new file mode 100644
index 000000000000..b2e64918884c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/Kconfig
@@ -0,0 +1,16 @@
1#
2# Renesas USB Controller Drivers
3#
4
5config USB_RENESAS_USBHS
6 tristate 'Renesas USBHS controller'
7 depends on SUPERH || ARCH_SHMOBILE
8 default n
9 help
10 Renesas USBHS is a discrete USB host and peripheral controller chip
11 that supports both full and high speed USB 2.0 data transfers.
12 It has nine or more configurable endpoints, and endpoint zero.
13
14 Say "y" to link the driver statically, or "m" to build a
15 dynamically linked module called "renesas_usbhs" and force all
16 gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/renesas_usbhs/Makefile b/drivers/usb/renesas_usbhs/Makefile
new file mode 100644
index 000000000000..b8798ad16278
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/Makefile
@@ -0,0 +1,9 @@
1#
2# for Renesas USB
3#
4
5obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o
6
7renesas_usbhs-y := common.o mod.o pipe.o
8
9renesas_usbhs-$(CONFIG_USB_RENESAS_USBHS_UDC) += mod_gadget.o
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
new file mode 100644
index 000000000000..f3664d6af661
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -0,0 +1,437 @@
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 */
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/pm_runtime.h>
20#include <linux/slab.h>
21#include <linux/sysfs.h>
22#include "./common.h"
23
24#define USBHSF_RUNTIME_PWCTRL (1 << 0)
25
26/* status */
27#define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0)
28#define usbhsc_flags_set(p, b) ((p)->flags |= (b))
29#define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b))
30#define usbhsc_flags_has(p, b) ((p)->flags & (b))
31
32/*
33 * platform call back
34 *
35 * renesas usb support platform callback function.
36 * Below macro call it.
37 * if platform doesn't have callback, it return 0 (no error)
38 */
39#define usbhs_platform_call(priv, func, args...)\
40 (!(priv) ? -ENODEV : \
41 !((priv)->pfunc->func) ? 0 : \
42 (priv)->pfunc->func(args))
43
44/*
45 * common functions
46 */
47u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
48{
49 return ioread16(priv->base + reg);
50}
51
52void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
53{
54 iowrite16(data, priv->base + reg);
55}
56
57void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
58{
59 u16 val = usbhs_read(priv, reg);
60
61 val &= ~mask;
62 val |= data & mask;
63
64 usbhs_write(priv, reg, val);
65}
66
67struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
68{
69 return dev_get_drvdata(&pdev->dev);
70}
71
72/*
73 * syscfg functions
74 */
75void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
76{
77 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
78}
79
80void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable)
81{
82 usbhs_bset(priv, SYSCFG, HSE, enable ? HSE : 0);
83}
84
85void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable)
86{
87 usbhs_bset(priv, SYSCFG, USBE, enable ? USBE : 0);
88}
89
90void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
91{
92 u16 mask = DCFM | DRPD | DPRPU;
93 u16 val = DCFM | DRPD;
94
95 /*
96 * if enable
97 *
98 * - select Host mode
99 * - D+ Line/D- Line Pull-down
100 */
101 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
102}
103
104void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
105{
106 u16 mask = DCFM | DRPD | DPRPU;
107 u16 val = DPRPU;
108
109 /*
110 * if enable
111 *
112 * - select Function mode
113 * - D+ Line Pull-up
114 */
115 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
116}
117
118/*
119 * frame functions
120 */
121int usbhs_frame_get_num(struct usbhs_priv *priv)
122{
123 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
124}
125
126/*
127 * local functions
128 */
129static void usbhsc_bus_ctrl(struct usbhs_priv *priv, int enable)
130{
131 int wait = usbhs_get_dparam(priv, buswait_bwait);
132 u16 data = 0;
133
134 if (enable) {
135 /* set bus wait if platform have */
136 if (wait)
137 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
138 }
139 usbhs_write(priv, DVSTCTR, data);
140}
141
142/*
143 * platform default param
144 */
145static u32 usbhsc_default_pipe_type[] = {
146 USB_ENDPOINT_XFER_CONTROL,
147 USB_ENDPOINT_XFER_ISOC,
148 USB_ENDPOINT_XFER_ISOC,
149 USB_ENDPOINT_XFER_BULK,
150 USB_ENDPOINT_XFER_BULK,
151 USB_ENDPOINT_XFER_BULK,
152 USB_ENDPOINT_XFER_INT,
153 USB_ENDPOINT_XFER_INT,
154 USB_ENDPOINT_XFER_INT,
155 USB_ENDPOINT_XFER_INT,
156};
157
158/*
159 * power control
160 */
161static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
162{
163 struct device *dev = usbhs_priv_to_dev(priv);
164
165 if (enable) {
166 /* enable PM */
167 pm_runtime_get_sync(dev);
168
169 /* USB on */
170 usbhs_sys_clock_ctrl(priv, enable);
171 usbhsc_bus_ctrl(priv, enable);
172 } else {
173 /* USB off */
174 usbhsc_bus_ctrl(priv, enable);
175 usbhs_sys_clock_ctrl(priv, enable);
176
177 /* disable PM */
178 pm_runtime_put_sync(dev);
179 }
180}
181
182/*
183 * notify hotplug
184 */
185static void usbhsc_notify_hotplug(struct work_struct *work)
186{
187 struct usbhs_priv *priv = container_of(work,
188 struct usbhs_priv,
189 notify_hotplug_work.work);
190 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
191 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
192 int id;
193 int enable;
194 int ret;
195
196 /*
197 * get vbus status from platform
198 */
199 enable = usbhs_platform_call(priv, get_vbus, pdev);
200
201 /*
202 * get id from platform
203 */
204 id = usbhs_platform_call(priv, get_id, pdev);
205
206 if (enable && !mod) {
207 ret = usbhs_mod_change(priv, id);
208 if (ret < 0)
209 return;
210
211 dev_dbg(&pdev->dev, "%s enable\n", __func__);
212
213 /* power on */
214 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
215 usbhsc_power_ctrl(priv, enable);
216
217 /* module start */
218 usbhs_mod_call(priv, start, priv);
219
220 } else if (!enable && mod) {
221 dev_dbg(&pdev->dev, "%s disable\n", __func__);
222
223 /* module stop */
224 usbhs_mod_call(priv, stop, priv);
225
226 /* power off */
227 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
228 usbhsc_power_ctrl(priv, enable);
229
230 usbhs_mod_change(priv, -1);
231
232 /* reset phy for next connection */
233 usbhs_platform_call(priv, phy_reset, pdev);
234 }
235}
236
237int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
238{
239 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
240 int delay = usbhs_get_dparam(priv, detection_delay);
241
242 /*
243 * This functions will be called in interrupt.
244 * To make sure safety context,
245 * use workqueue for usbhs_notify_hotplug
246 */
247 schedule_delayed_work(&priv->notify_hotplug_work, delay);
248 return 0;
249}
250
251/*
252 * platform functions
253 */
254static int __devinit usbhs_probe(struct platform_device *pdev)
255{
256 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
257 struct renesas_usbhs_driver_callback *dfunc;
258 struct usbhs_priv *priv;
259 struct resource *res;
260 unsigned int irq;
261 int ret;
262
263 /* check platform information */
264 if (!info ||
265 !info->platform_callback.get_id) {
266 dev_err(&pdev->dev, "no platform information\n");
267 return -EINVAL;
268 }
269
270 /* platform data */
271 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
272 irq = platform_get_irq(pdev, 0);
273 if (!res || (int)irq <= 0) {
274 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
275 return -ENODEV;
276 }
277
278 /* usb private data */
279 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
280 if (!priv) {
281 dev_err(&pdev->dev, "Could not allocate priv\n");
282 return -ENOMEM;
283 }
284
285 priv->base = ioremap_nocache(res->start, resource_size(res));
286 if (!priv->base) {
287 dev_err(&pdev->dev, "ioremap error.\n");
288 ret = -ENOMEM;
289 goto probe_end_kfree;
290 }
291
292 /*
293 * care platform info
294 */
295 priv->pfunc = &info->platform_callback;
296 priv->dparam = &info->driver_param;
297
298 /* set driver callback functions for platform */
299 dfunc = &info->driver_callback;
300 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
301
302 /* set default param if platform doesn't have */
303 if (!priv->dparam->pipe_type) {
304 priv->dparam->pipe_type = usbhsc_default_pipe_type;
305 priv->dparam->pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
306 }
307
308 /* FIXME */
309 /* runtime power control ? */
310 if (priv->pfunc->get_vbus)
311 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
312
313 /*
314 * priv settings
315 */
316 priv->irq = irq;
317 priv->pdev = pdev;
318 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
319 spin_lock_init(usbhs_priv_to_lock(priv));
320
321 /* call pipe and module init */
322 ret = usbhs_pipe_probe(priv);
323 if (ret < 0)
324 goto probe_end_iounmap;
325
326 ret = usbhs_mod_probe(priv);
327 if (ret < 0)
328 goto probe_end_pipe_exit;
329
330 /* dev_set_drvdata should be called after usbhs_mod_init */
331 dev_set_drvdata(&pdev->dev, priv);
332
333 /*
334 * deviece reset here because
335 * USB device might be used in boot loader.
336 */
337 usbhs_sys_clock_ctrl(priv, 0);
338
339 /*
340 * platform call
341 *
342 * USB phy setup might depend on CPU/Board.
343 * If platform has its callback functions,
344 * call it here.
345 */
346 ret = usbhs_platform_call(priv, hardware_init, pdev);
347 if (ret < 0) {
348 dev_err(&pdev->dev, "platform prove failed.\n");
349 goto probe_end_mod_exit;
350 }
351
352 /* reset phy for connection */
353 usbhs_platform_call(priv, phy_reset, pdev);
354
355 /* power control */
356 pm_runtime_enable(&pdev->dev);
357 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
358 usbhsc_power_ctrl(priv, 1);
359 usbhs_mod_autonomy_mode(priv);
360 }
361
362 /*
363 * manual call notify_hotplug for cold plug
364 */
365 ret = usbhsc_drvcllbck_notify_hotplug(pdev);
366 if (ret < 0)
367 goto probe_end_call_remove;
368
369 dev_info(&pdev->dev, "probed\n");
370
371 return ret;
372
373probe_end_call_remove:
374 usbhs_platform_call(priv, hardware_exit, pdev);
375probe_end_mod_exit:
376 usbhs_mod_remove(priv);
377probe_end_pipe_exit:
378 usbhs_pipe_remove(priv);
379probe_end_iounmap:
380 iounmap(priv->base);
381probe_end_kfree:
382 kfree(priv);
383
384 dev_info(&pdev->dev, "probe failed\n");
385
386 return ret;
387}
388
389static int __devexit usbhs_remove(struct platform_device *pdev)
390{
391 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
392 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
393 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
394
395 dev_dbg(&pdev->dev, "usb remove\n");
396
397 dfunc->notify_hotplug = NULL;
398
399 /* power off */
400 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
401 usbhsc_power_ctrl(priv, 0);
402
403 pm_runtime_disable(&pdev->dev);
404
405 usbhs_platform_call(priv, hardware_exit, pdev);
406 usbhs_mod_remove(priv);
407 usbhs_pipe_remove(priv);
408 iounmap(priv->base);
409 kfree(priv);
410
411 return 0;
412}
413
414static struct platform_driver renesas_usbhs_driver = {
415 .driver = {
416 .name = "renesas_usbhs",
417 },
418 .probe = usbhs_probe,
419 .remove = __devexit_p(usbhs_remove),
420};
421
422static int __init usbhs_init(void)
423{
424 return platform_driver_register(&renesas_usbhs_driver);
425}
426
427static void __exit usbhs_exit(void)
428{
429 platform_driver_unregister(&renesas_usbhs_driver);
430}
431
432module_init(usbhs_init);
433module_exit(usbhs_exit);
434
435MODULE_LICENSE("GPL");
436MODULE_DESCRIPTION("Renesas USB driver");
437MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
new file mode 100644
index 000000000000..0aadcb402764
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -0,0 +1,230 @@
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 */
17#ifndef RENESAS_USB_DRIVER_H
18#define RENESAS_USB_DRIVER_H
19
20#include <linux/platform_device.h>
21#include <linux/usb/renesas_usbhs.h>
22
23struct usbhs_priv;
24
25#include "./mod.h"
26#include "./pipe.h"
27
28/*
29 *
30 * register define
31 *
32 */
33#define SYSCFG 0x0000
34#define BUSWAIT 0x0002
35#define DVSTCTR 0x0008
36#define CFIFO 0x0014
37#define CFIFOSEL 0x0020
38#define CFIFOCTR 0x0022
39#define INTENB0 0x0030
40#define INTENB1 0x0032
41#define BRDYENB 0x0036
42#define NRDYENB 0x0038
43#define BEMPENB 0x003A
44#define INTSTS0 0x0040
45#define INTSTS1 0x0042
46#define BRDYSTS 0x0046
47#define NRDYSTS 0x0048
48#define BEMPSTS 0x004A
49#define FRMNUM 0x004C
50#define USBREQ 0x0054 /* USB request type register */
51#define USBVAL 0x0056 /* USB request value register */
52#define USBINDX 0x0058 /* USB request index register */
53#define USBLENG 0x005A /* USB request length register */
54#define DCPCFG 0x005C
55#define DCPMAXP 0x005E
56#define DCPCTR 0x0060
57#define PIPESEL 0x0064
58#define PIPECFG 0x0068
59#define PIPEBUF 0x006A
60#define PIPEMAXP 0x006C
61#define PIPEPERI 0x006E
62#define PIPEnCTR 0x0070
63
64/* SYSCFG */
65#define SCKE (1 << 10) /* USB Module Clock Enable */
66#define HSE (1 << 7) /* High-Speed Operation Enable */
67#define DCFM (1 << 6) /* Controller Function Select */
68#define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */
69#define DPRPU (1 << 4) /* D+ Line Resistance Control */
70#define USBE (1 << 0) /* USB Module Operation Enable */
71
72/* DVSTCTR */
73#define EXTLP (1 << 10) /* Controls the EXTLP pin output state */
74#define PWEN (1 << 9) /* Controls the PWEN pin output state */
75#define RHST (0x7) /* Reset Handshake */
76#define RHST_LOW_SPEED 1 /* Low-speed connection */
77#define RHST_FULL_SPEED 2 /* Full-speed connection */
78#define RHST_HIGH_SPEED 3 /* High-speed connection */
79
80/* CFIFOSEL */
81#define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
82
83/* CFIFOCTR */
84#define BVAL (1 << 15) /* Buffer Memory Enable Flag */
85#define BCLR (1 << 14) /* CPU buffer clear */
86#define FRDY (1 << 13) /* FIFO Port Ready */
87#define DTLN_MASK (0x0FFF) /* Receive Data Length */
88
89/* INTENB0 */
90#define VBSE (1 << 15) /* Enable IRQ VBUS_0 and VBUSIN_0 */
91#define RSME (1 << 14) /* Enable IRQ Resume */
92#define SOFE (1 << 13) /* Enable IRQ Frame Number Update */
93#define DVSE (1 << 12) /* Enable IRQ Device State Transition */
94#define CTRE (1 << 11) /* Enable IRQ Control Stage Transition */
95#define BEMPE (1 << 10) /* Enable IRQ Buffer Empty */
96#define NRDYE (1 << 9) /* Enable IRQ Buffer Not Ready Response */
97#define BRDYE (1 << 8) /* Enable IRQ Buffer Ready */
98
99/* INTENB1 */
100#define BCHGE (1 << 14) /* USB Bus Change Interrupt Enable */
101#define DTCHE (1 << 12) /* Disconnection Detect Interrupt Enable */
102#define ATTCHE (1 << 11) /* Connection Detect Interrupt Enable */
103#define EOFERRE (1 << 6) /* EOF Error Detect Interrupt Enable */
104#define SIGNE (1 << 5) /* Setup Transaction Error Interrupt Enable */
105#define SACKE (1 << 4) /* Setup Transaction ACK Interrupt Enable */
106
107/* INTSTS0 */
108#define VBINT (1 << 15) /* VBUS0_0 and VBUS1_0 Interrupt Status */
109#define DVST (1 << 12) /* Device State Transition Interrupt Status */
110#define CTRT (1 << 11) /* Control Stage Interrupt Status */
111#define BEMP (1 << 10) /* Buffer Empty Interrupt Status */
112#define BRDY (1 << 8) /* Buffer Ready Interrupt Status */
113#define VBSTS (1 << 7) /* VBUS_0 and VBUSIN_0 Input Status */
114#define VALID (1 << 3) /* USB Request Receive */
115
116#define DVSQ_MASK (0x3 << 4) /* Device State */
117#define POWER_STATE (0 << 4)
118#define DEFAULT_STATE (1 << 4)
119#define ADDRESS_STATE (2 << 4)
120#define CONFIGURATION_STATE (3 << 4)
121
122#define CTSQ_MASK (0x7) /* Control Transfer Stage */
123#define IDLE_SETUP_STAGE 0 /* Idle stage or setup stage */
124#define READ_DATA_STAGE 1 /* Control read data stage */
125#define READ_STATUS_STAGE 2 /* Control read status stage */
126#define WRITE_DATA_STAGE 3 /* Control write data stage */
127#define WRITE_STATUS_STAGE 4 /* Control write status stage */
128#define NODATA_STATUS_STAGE 5 /* Control write NoData status stage */
129#define SEQUENCE_ERROR 6 /* Control transfer sequence error */
130
131/* PIPECFG */
132/* DCPCFG */
133#define TYPE_NONE (0 << 14) /* Transfer Type */
134#define TYPE_BULK (1 << 14)
135#define TYPE_INT (2 << 14)
136#define TYPE_ISO (3 << 14)
137#define DBLB (1 << 9) /* Double Buffer Mode */
138#define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */
139#define DIR_OUT (1 << 4) /* Transfer Direction */
140
141/* PIPEMAXP */
142/* DCPMAXP */
143#define DEVSEL_MASK (0xF << 12) /* Device Select */
144#define DCP_MAXP_MASK (0x7F)
145#define PIPE_MAXP_MASK (0x7FF)
146
147/* PIPEBUF */
148#define BUFSIZE_SHIFT 10
149#define BUFSIZE_MASK (0x1F << BUFSIZE_SHIFT)
150#define BUFNMB_MASK (0xFF)
151
152/* PIPEnCTR */
153/* DCPCTR */
154#define BSTS (1 << 15) /* Buffer Status */
155#define CSSTS (1 << 12) /* CSSTS Status */
156#define SQCLR (1 << 8) /* Toggle Bit Clear */
157#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
158#define PBUSY (1 << 5) /* Pipe Busy */
159#define PID_MASK (0x3) /* Response PID */
160#define PID_NAK 0
161#define PID_BUF 1
162#define PID_STALL10 2
163#define PID_STALL11 3
164
165#define CCPL (1 << 2) /* Control Transfer End Enable */
166
167/* FRMNUM */
168#define FRNM_MASK (0x7FF)
169
170/*
171 * struct
172 */
173struct usbhs_priv {
174
175 void __iomem *base;
176 unsigned int irq;
177
178 struct renesas_usbhs_platform_callback *pfunc;
179 struct renesas_usbhs_driver_param *dparam;
180
181 struct delayed_work notify_hotplug_work;
182 struct platform_device *pdev;
183
184 spinlock_t lock;
185
186 u32 flags;
187
188 /*
189 * module control
190 */
191 struct usbhs_mod_info mod_info;
192
193 /*
194 * pipe control
195 */
196 struct usbhs_pipe_info pipe_info;
197};
198
199/*
200 * common
201 */
202u16 usbhs_read(struct usbhs_priv *priv, u32 reg);
203void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
204void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
205
206int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev);
207/*
208 * sysconfig
209 */
210void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable);
211void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable);
212void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable);
213void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable);
214void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable);
215
216/*
217 * frame
218 */
219int usbhs_frame_get_num(struct usbhs_priv *priv);
220
221/*
222 * data
223 */
224struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev);
225#define usbhs_get_dparam(priv, param) (priv->dparam->param)
226#define usbhs_priv_to_pdev(priv) (priv->pdev)
227#define usbhs_priv_to_dev(priv) (&priv->pdev->dev)
228#define usbhs_priv_to_lock(priv) (&priv->lock)
229
230#endif /* RENESAS_USB_DRIVER_H */
diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c
new file mode 100644
index 000000000000..a577f8f4064c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod.c
@@ -0,0 +1,328 @@
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 */
17#include <linux/interrupt.h>
18
19#include "./common.h"
20#include "./mod.h"
21
22#define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
23#define usbhs_mod_info_call(priv, func, param...) \
24({ \
25 struct usbhs_mod_info *info; \
26 info = usbhs_priv_to_modinfo(priv); \
27 !info->func ? 0 : \
28 info->func(param); \
29})
30
31/*
32 * autonomy
33 *
34 * these functions are used if platform doesn't have external phy.
35 * -> there is no "notify_hotplug" callback from platform
36 * -> call "notify_hotplug" by itself
37 * -> use own interrupt to connect/disconnect
38 * -> it mean module clock is always ON
39 * ~~~~~~~~~~~~~~~~~~~~~~~~~
40 */
41static int usbhsm_autonomy_get_vbus(struct platform_device *pdev)
42{
43 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
44
45 return VBSTS & usbhs_read(priv, INTSTS0);
46}
47
48static int usbhsm_autonomy_irq_vbus(struct usbhs_priv *priv,
49 struct usbhs_irq_state *irq_state)
50{
51 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
52
53 return usbhsc_drvcllbck_notify_hotplug(pdev);
54}
55
56void usbhs_mod_autonomy_mode(struct usbhs_priv *priv)
57{
58 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
59
60 info->irq_vbus = usbhsm_autonomy_irq_vbus;
61 priv->pfunc->get_vbus = usbhsm_autonomy_get_vbus;
62
63 usbhs_irq_callback_update(priv, NULL);
64}
65
66/*
67 * host / gadget functions
68 *
69 * renesas_usbhs host/gadget can register itself by below functions.
70 * these functions are called when probe
71 *
72 */
73void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *mod, int id)
74{
75 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
76
77 info->mod[id] = mod;
78 mod->priv = priv;
79}
80
81struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id)
82{
83 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
84 struct usbhs_mod *ret = NULL;
85
86 switch (id) {
87 case USBHS_HOST:
88 case USBHS_GADGET:
89 ret = info->mod[id];
90 break;
91 }
92
93 return ret;
94}
95
96int usbhs_mod_is_host(struct usbhs_priv *priv, struct usbhs_mod *mod)
97{
98 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
99
100 if (!mod)
101 return -EINVAL;
102
103 return info->mod[USBHS_HOST] == mod;
104}
105
106struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv)
107{
108 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
109
110 return info->curt;
111}
112
113int usbhs_mod_change(struct usbhs_priv *priv, int id)
114{
115 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
116 struct usbhs_mod *mod = NULL;
117 int ret = 0;
118
119 /* id < 0 mean no current */
120 switch (id) {
121 case USBHS_HOST:
122 case USBHS_GADGET:
123 mod = info->mod[id];
124 break;
125 default:
126 ret = -EINVAL;
127 }
128 info->curt = mod;
129
130 return ret;
131}
132
133static irqreturn_t usbhs_interrupt(int irq, void *data);
134int usbhs_mod_probe(struct usbhs_priv *priv)
135{
136 struct device *dev = usbhs_priv_to_dev(priv);
137 int ret;
138
139 /*
140 * install host/gadget driver
141 */
142 ret = usbhs_mod_gadget_probe(priv);
143 if (ret < 0)
144 return ret;
145
146 /* irq settings */
147 ret = request_irq(priv->irq, usbhs_interrupt,
148 IRQF_DISABLED, dev_name(dev), priv);
149 if (ret) {
150 dev_err(dev, "irq request err\n");
151 goto mod_init_gadget_err;
152 }
153
154 return ret;
155
156mod_init_gadget_err:
157 usbhs_mod_gadget_remove(priv);
158
159 return ret;
160}
161
162void usbhs_mod_remove(struct usbhs_priv *priv)
163{
164 usbhs_mod_gadget_remove(priv);
165 free_irq(priv->irq, priv);
166}
167
168/*
169 * status functions
170 */
171int usbhs_status_get_usb_speed(struct usbhs_irq_state *irq_state)
172{
173 switch (irq_state->dvstctr & RHST) {
174 case RHST_LOW_SPEED:
175 return USB_SPEED_LOW;
176 case RHST_FULL_SPEED:
177 return USB_SPEED_FULL;
178 case RHST_HIGH_SPEED:
179 return USB_SPEED_HIGH;
180 }
181
182 return USB_SPEED_UNKNOWN;
183}
184
185int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state)
186{
187 int state = irq_state->intsts0 & DVSQ_MASK;
188
189 switch (state) {
190 case POWER_STATE:
191 case DEFAULT_STATE:
192 case ADDRESS_STATE:
193 case CONFIGURATION_STATE:
194 return state;
195 }
196
197 return -EIO;
198}
199
200int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state)
201{
202 /*
203 * return value
204 *
205 * IDLE_SETUP_STAGE
206 * READ_DATA_STAGE
207 * READ_STATUS_STAGE
208 * WRITE_DATA_STAGE
209 * WRITE_STATUS_STAGE
210 * NODATA_STATUS_STAGE
211 * SEQUENCE_ERROR
212 */
213 return (int)irq_state->intsts0 & CTSQ_MASK;
214}
215
216static void usbhs_status_get_each_irq(struct usbhs_priv *priv,
217 struct usbhs_irq_state *state)
218{
219 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
220
221 state->intsts0 = usbhs_read(priv, INTSTS0);
222 state->intsts1 = usbhs_read(priv, INTSTS1);
223
224 state->dvstctr = usbhs_read(priv, DVSTCTR);
225
226 /* mask */
227 if (mod) {
228 state->brdysts = usbhs_read(priv, BRDYSTS);
229 state->nrdysts = usbhs_read(priv, NRDYSTS);
230 state->bempsts = usbhs_read(priv, BEMPSTS);
231
232 state->bempsts &= mod->irq_bempsts;
233 state->brdysts &= mod->irq_brdysts;
234 }
235}
236
237/*
238 * interrupt
239 */
240#define INTSTS0_MAGIC 0xF800 /* acknowledge magical interrupt sources */
241#define INTSTS1_MAGIC 0xA870 /* acknowledge magical interrupt sources */
242static irqreturn_t usbhs_interrupt(int irq, void *data)
243{
244 struct usbhs_priv *priv = data;
245 struct usbhs_irq_state irq_state;
246
247 usbhs_status_get_each_irq(priv, &irq_state);
248
249 /*
250 * clear interrupt
251 *
252 * The hardware is _very_ picky to clear interrupt bit.
253 * Especially INTSTS0_MAGIC, INTSTS1_MAGIC value.
254 *
255 * see
256 * "Operation"
257 * - "Control Transfer (DCP)"
258 * - Function :: VALID bit should 0
259 */
260 usbhs_write(priv, INTSTS0, ~irq_state.intsts0 & INTSTS0_MAGIC);
261 usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC);
262
263 usbhs_write(priv, BRDYSTS, 0);
264 usbhs_write(priv, NRDYSTS, 0);
265 usbhs_write(priv, BEMPSTS, 0);
266
267 /*
268 * call irq callback functions
269 * see also
270 * usbhs_irq_setting_update
271 */
272 if (irq_state.intsts0 & VBINT)
273 usbhs_mod_info_call(priv, irq_vbus, priv, &irq_state);
274
275 if (irq_state.intsts0 & DVST)
276 usbhs_mod_call(priv, irq_dev_state, priv, &irq_state);
277
278 if (irq_state.intsts0 & CTRT)
279 usbhs_mod_call(priv, irq_ctrl_stage, priv, &irq_state);
280
281 if (irq_state.intsts0 & BEMP)
282 usbhs_mod_call(priv, irq_empty, priv, &irq_state);
283
284 if (irq_state.intsts0 & BRDY)
285 usbhs_mod_call(priv, irq_ready, priv, &irq_state);
286
287 return IRQ_HANDLED;
288}
289
290void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod)
291{
292 u16 intenb0 = 0;
293 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
294
295 usbhs_write(priv, INTENB0, 0);
296
297 usbhs_write(priv, BEMPENB, 0);
298 usbhs_write(priv, BRDYENB, 0);
299
300 /*
301 * see also
302 * usbhs_interrupt
303 */
304
305 /*
306 * it don't enable DVSE (intenb0) here
307 * but "mod->irq_dev_state" will be called.
308 */
309 if (info->irq_vbus)
310 intenb0 |= VBSE;
311
312 if (mod) {
313 if (mod->irq_ctrl_stage)
314 intenb0 |= CTRE;
315
316 if (mod->irq_empty && mod->irq_bempsts) {
317 usbhs_write(priv, BEMPENB, mod->irq_bempsts);
318 intenb0 |= BEMPE;
319 }
320
321 if (mod->irq_ready && mod->irq_brdysts) {
322 usbhs_write(priv, BRDYENB, mod->irq_brdysts);
323 intenb0 |= BRDYE;
324 }
325 }
326
327 usbhs_write(priv, INTENB0, intenb0);
328}
diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h
new file mode 100644
index 000000000000..5c845a28a21c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod.h
@@ -0,0 +1,137 @@
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 */
17#ifndef RENESAS_USB_MOD_H
18#define RENESAS_USB_MOD_H
19
20#include <linux/spinlock.h>
21#include <linux/usb/renesas_usbhs.h>
22#include "./common.h"
23
24/*
25 * struct
26 */
27struct usbhs_irq_state {
28 u16 intsts0;
29 u16 intsts1;
30 u16 brdysts;
31 u16 nrdysts;
32 u16 bempsts;
33 u16 dvstctr;
34};
35
36struct usbhs_mod {
37 char *name;
38
39 /*
40 * entry point from common.c
41 */
42 int (*start)(struct usbhs_priv *priv);
43 int (*stop)(struct usbhs_priv *priv);
44
45 /* INTSTS0 :: DVST (DVSQ) */
46 int (*irq_dev_state)(struct usbhs_priv *priv,
47 struct usbhs_irq_state *irq_state);
48
49 /* INTSTS0 :: CTRT (CTSQ) */
50 int (*irq_ctrl_stage)(struct usbhs_priv *priv,
51 struct usbhs_irq_state *irq_state);
52
53 /* INTSTS0 :: BEMP */
54 /* BEMPSTS */
55 int (*irq_empty)(struct usbhs_priv *priv,
56 struct usbhs_irq_state *irq_state);
57 u16 irq_bempsts;
58
59 /* INTSTS0 :: BRDY */
60 /* BRDYSTS */
61 int (*irq_ready)(struct usbhs_priv *priv,
62 struct usbhs_irq_state *irq_state);
63 u16 irq_brdysts;
64
65 struct usbhs_priv *priv;
66};
67
68struct usbhs_mod_info {
69 struct usbhs_mod *mod[USBHS_MAX];
70 struct usbhs_mod *curt; /* current mod */
71
72 /*
73 * INTSTS0 :: VBINT
74 *
75 * This function will be used as autonomy mode
76 * when platform cannot call notify_hotplug.
77 *
78 * This callback cannot be member of "struct usbhs_mod"
79 * because it will be used even though
80 * host/gadget has not been selected.
81 */
82 int (*irq_vbus)(struct usbhs_priv *priv,
83 struct usbhs_irq_state *irq_state);
84};
85
86/*
87 * for host/gadget module
88 */
89struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
90struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
91void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
92int usbhs_mod_is_host(struct usbhs_priv *priv, struct usbhs_mod *mod);
93int usbhs_mod_change(struct usbhs_priv *priv, int id);
94int usbhs_mod_probe(struct usbhs_priv *priv);
95void usbhs_mod_remove(struct usbhs_priv *priv);
96
97void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
98
99/*
100 * status functions
101 */
102int usbhs_status_get_usb_speed(struct usbhs_irq_state *irq_state);
103int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
104int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
105
106/*
107 * callback functions
108 */
109void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
110
111
112#define usbhs_mod_call(priv, func, param...) \
113 ({ \
114 struct usbhs_mod *mod; \
115 mod = usbhs_mod_get_current(priv); \
116 !mod ? -ENODEV : \
117 !mod->func ? 0 : \
118 mod->func(param); \
119 })
120
121/*
122 * gadget control
123 */
124#ifdef CONFIG_USB_RENESAS_USBHS_UDC
125extern int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv);
126extern void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv);
127#else
128static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
129{
130 return 0;
131}
132static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
133{
134}
135#endif
136
137#endif /* RENESAS_USB_MOD_H */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
new file mode 100644
index 000000000000..547486ccd059
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -0,0 +1,1385 @@
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 */
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/usb/ch9.h>
21#include <linux/usb/gadget.h>
22#include "common.h"
23
24/*
25 * struct
26 */
27struct usbhsg_request {
28 struct usb_request req;
29 struct list_head node;
30};
31
32#define EP_NAME_SIZE 8
33struct usbhsg_gpriv;
34struct usbhsg_pipe_handle;
35struct usbhsg_uep {
36 struct usb_ep ep;
37 struct usbhs_pipe *pipe;
38 struct list_head list;
39
40 char ep_name[EP_NAME_SIZE];
41
42 struct usbhsg_gpriv *gpriv;
43 struct usbhsg_pipe_handle *handler;
44};
45
46struct usbhsg_gpriv {
47 struct usb_gadget gadget;
48 struct usbhs_mod mod;
49
50 struct usbhsg_uep *uep;
51 int uep_size;
52
53 struct usb_gadget_driver *driver;
54
55 u32 status;
56#define USBHSG_STATUS_STARTED (1 << 0)
57#define USBHSG_STATUS_REGISTERD (1 << 1)
58#define USBHSG_STATUS_WEDGE (1 << 2)
59};
60
61struct usbhsg_pipe_handle {
62 int (*prepare)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
63 int (*try_run)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
64 void (*irq_mask)(struct usbhsg_uep *uep, int enable);
65};
66
67struct usbhsg_recip_handle {
68 char *name;
69 int (*device)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
70 struct usb_ctrlrequest *ctrl);
71 int (*interface)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
72 struct usb_ctrlrequest *ctrl);
73 int (*endpoint)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
74 struct usb_ctrlrequest *ctrl);
75};
76
77/*
78 * macro
79 */
80#define usbhsg_priv_to_gpriv(priv) \
81 container_of( \
82 usbhs_mod_get(priv, USBHS_GADGET), \
83 struct usbhsg_gpriv, mod)
84
85#define __usbhsg_for_each_uep(start, pos, g, i) \
86 for (i = start, pos = (g)->uep; \
87 i < (g)->uep_size; \
88 i++, pos = (g)->uep + i)
89
90#define usbhsg_for_each_uep(pos, gpriv, i) \
91 __usbhsg_for_each_uep(1, pos, gpriv, i)
92
93#define usbhsg_for_each_uep_with_dcp(pos, gpriv, i) \
94 __usbhsg_for_each_uep(0, pos, gpriv, i)
95
96#define usbhsg_gadget_to_gpriv(g)\
97 container_of(g, struct usbhsg_gpriv, gadget)
98
99#define usbhsg_req_to_ureq(r)\
100 container_of(r, struct usbhsg_request, req)
101
102#define usbhsg_ep_to_uep(e) container_of(e, struct usbhsg_uep, ep)
103#define usbhsg_gpriv_to_lock(gp) usbhs_priv_to_lock((gp)->mod.priv)
104#define usbhsg_gpriv_to_dev(gp) usbhs_priv_to_dev((gp)->mod.priv)
105#define usbhsg_gpriv_to_priv(gp) ((gp)->mod.priv)
106#define usbhsg_gpriv_to_dcp(gp) ((gp)->uep)
107#define usbhsg_gpriv_to_nth_uep(gp, i) ((gp)->uep + i)
108#define usbhsg_uep_to_gpriv(u) ((u)->gpriv)
109#define usbhsg_uep_to_pipe(u) ((u)->pipe)
110#define usbhsg_pipe_to_uep(p) ((p)->mod_private)
111#define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv))
112
113#define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN)
114
115/* status */
116#define usbhsg_status_init(gp) do {(gp)->status = 0; } while (0)
117#define usbhsg_status_set(gp, b) (gp->status |= b)
118#define usbhsg_status_clr(gp, b) (gp->status &= ~b)
119#define usbhsg_status_has(gp, b) (gp->status & b)
120
121/*
122 * usbhsg_trylock
123 *
124 * This driver don't use spin_try_lock
125 * to avoid warning of CONFIG_DEBUG_SPINLOCK
126 */
127static spinlock_t *usbhsg_trylock(struct usbhsg_gpriv *gpriv,
128 unsigned long *flags)
129{
130 spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
131
132 /* check spin lock status
133 * to avoid deadlock/nest */
134 if (spin_is_locked(lock))
135 return NULL;
136
137 spin_lock_irqsave(lock, *flags);
138
139 return lock;
140}
141
142static void usbhsg_unlock(spinlock_t *lock, unsigned long *flags)
143{
144 if (!lock)
145 return;
146
147 spin_unlock_irqrestore(lock, *flags);
148}
149
150/*
151 * list push/pop
152 */
153static void usbhsg_queue_push(struct usbhsg_uep *uep,
154 struct usbhsg_request *ureq)
155{
156 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
157 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
158 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
159
160 /*
161 ********* assume under spin lock *********
162 */
163 list_del_init(&ureq->node);
164 list_add_tail(&ureq->node, &uep->list);
165 ureq->req.actual = 0;
166 ureq->req.status = -EINPROGRESS;
167
168 dev_dbg(dev, "pipe %d : queue push (%d)\n",
169 usbhs_pipe_number(pipe),
170 ureq->req.length);
171}
172
173static struct usbhsg_request *usbhsg_queue_get(struct usbhsg_uep *uep)
174{
175 /*
176 ********* assume under spin lock *********
177 */
178 if (list_empty(&uep->list))
179 return NULL;
180
181 return list_entry(uep->list.next, struct usbhsg_request, node);
182}
183
184#define usbhsg_queue_prepare(uep) __usbhsg_queue_handler(uep, 1);
185#define usbhsg_queue_handle(uep) __usbhsg_queue_handler(uep, 0);
186static int __usbhsg_queue_handler(struct usbhsg_uep *uep, int prepare)
187{
188 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
189 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
190 struct usbhsg_request *ureq;
191 spinlock_t *lock;
192 unsigned long flags;
193 int ret = 0;
194
195 if (!uep->handler) {
196 dev_err(dev, "no handler function\n");
197 return -EIO;
198 }
199
200 /*
201 * CAUTION [*queue handler*]
202 *
203 * This function will be called for start/restart queue operation.
204 * OTOH the most much worry for USB driver is spinlock nest.
205 * Specially it are
206 * - usb_ep_ops :: queue
207 * - usb_request :: complete
208 *
209 * But the caller of this function need not care about spinlock.
210 * This function is using usbhsg_trylock for it.
211 * if "is_locked" is 1, this mean this function lock it.
212 * but if it is 0, this mean it is already under spin lock.
213 * see also
214 * CAUTION [*endpoint queue*]
215 * CAUTION [*request complete*]
216 */
217
218 /****************** spin try lock *******************/
219 lock = usbhsg_trylock(gpriv, &flags);
220
221 ureq = usbhsg_queue_get(uep);
222 if (ureq) {
223 if (prepare)
224 ret = uep->handler->prepare(uep, ureq);
225 else
226 ret = uep->handler->try_run(uep, ureq);
227 }
228 usbhsg_unlock(lock, &flags);
229 /******************** spin unlock ******************/
230
231 return ret;
232}
233
234static void usbhsg_queue_pop(struct usbhsg_uep *uep,
235 struct usbhsg_request *ureq,
236 int status)
237{
238 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
239 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
240 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
241
242 /*
243 ********* assume under spin lock *********
244 */
245
246 /*
247 * CAUTION [*request complete*]
248 *
249 * There is a possibility not to be called in correct order
250 * if "complete" is called without spinlock.
251 *
252 * So, this function assume it is under spinlock,
253 * and call usb_request :: complete.
254 *
255 * But this "complete" will push next usb_request.
256 * It mean "usb_ep_ops :: queue" which is using spinlock is called
257 * under spinlock.
258 *
259 * To avoid dead-lock, this driver is using usbhsg_trylock.
260 * CAUTION [*endpoint queue*]
261 * CAUTION [*queue handler*]
262 */
263
264 dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe));
265
266 list_del_init(&ureq->node);
267
268 ureq->req.status = status;
269 ureq->req.complete(&uep->ep, &ureq->req);
270
271 /* more request ? */
272 if (0 == status)
273 usbhsg_queue_prepare(uep);
274}
275
276/*
277 * irq enable/disable function
278 */
279#define usbhsg_irq_callback_ctrl(uep, status, enable) \
280 ({ \
281 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); \
282 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); \
283 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); \
284 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
285 if (!mod) \
286 return; \
287 if (enable) \
288 mod->irq_##status |= (1 << usbhs_pipe_number(pipe)); \
289 else \
290 mod->irq_##status &= ~(1 << usbhs_pipe_number(pipe)); \
291 usbhs_irq_callback_update(priv, mod); \
292 })
293
294static void usbhsg_irq_empty_ctrl(struct usbhsg_uep *uep, int enable)
295{
296 usbhsg_irq_callback_ctrl(uep, bempsts, enable);
297}
298
299static void usbhsg_irq_ready_ctrl(struct usbhsg_uep *uep, int enable)
300{
301 usbhsg_irq_callback_ctrl(uep, brdysts, enable);
302}
303
304/*
305 * handler function
306 */
307static int usbhsg_try_run_ctrl_stage_end(struct usbhsg_uep *uep,
308 struct usbhsg_request *ureq)
309{
310 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
311
312 /*
313 ********* assume under spin lock *********
314 */
315
316 usbhs_dcp_control_transfer_done(pipe);
317 usbhsg_queue_pop(uep, ureq, 0);
318
319 return 0;
320}
321
322static int usbhsg_try_run_send_packet(struct usbhsg_uep *uep,
323 struct usbhsg_request *ureq)
324{
325 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
326 struct usb_request *req = &ureq->req;
327 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
328 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
329 void *buf;
330 int remainder, send;
331 int is_done = 0;
332 int enable;
333 int maxp;
334
335 /*
336 ********* assume under spin lock *********
337 */
338
339 maxp = usbhs_pipe_get_maxpacket(pipe);
340 buf = req->buf + req->actual;
341 remainder = req->length - req->actual;
342
343 send = usbhs_fifo_write(pipe, buf, remainder);
344
345 /*
346 * send < 0 : pipe busy
347 * send = 0 : send zero packet
348 * send > 0 : send data
349 *
350 * send <= max_packet
351 */
352 if (send > 0)
353 req->actual += send;
354
355 /* send all packet ? */
356 if (send < remainder)
357 is_done = 0; /* there are remainder data */
358 else if (send < maxp)
359 is_done = 1; /* short packet */
360 else
361 is_done = !req->zero; /* send zero packet ? */
362
363 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
364 usbhs_pipe_number(pipe),
365 remainder, send, is_done, req->zero);
366
367 /*
368 * enable interrupt and send again in irq handler
369 * if it still have remainder data which should be sent.
370 */
371 enable = !is_done;
372 uep->handler->irq_mask(uep, enable);
373
374 /*
375 * usbhs_fifo_enable execute
376 * - after callback_update,
377 * - before queue_pop / stage_end
378 */
379 usbhs_fifo_enable(pipe);
380
381 /*
382 * all data were sent ?
383 */
384 if (is_done) {
385 /* it care below call in
386 "function mode" */
387 if (usbhsg_is_dcp(uep))
388 usbhs_dcp_control_transfer_done(pipe);
389
390 usbhsg_queue_pop(uep, ureq, 0);
391 }
392
393 return 0;
394}
395
396static int usbhsg_prepare_send_packet(struct usbhsg_uep *uep,
397 struct usbhsg_request *ureq)
398{
399 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
400
401 /*
402 ********* assume under spin lock *********
403 */
404
405 usbhs_fifo_prepare_write(pipe);
406 usbhsg_try_run_send_packet(uep, ureq);
407
408 return 0;
409}
410
411static int usbhsg_try_run_receive_packet(struct usbhsg_uep *uep,
412 struct usbhsg_request *ureq)
413{
414 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
415 struct usb_request *req = &ureq->req;
416 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
417 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
418 void *buf;
419 int maxp;
420 int remainder, recv;
421 int is_done = 0;
422
423 /*
424 ********* assume under spin lock *********
425 */
426
427 maxp = usbhs_pipe_get_maxpacket(pipe);
428 buf = req->buf + req->actual;
429 remainder = req->length - req->actual;
430
431 recv = usbhs_fifo_read(pipe, buf, remainder);
432 /*
433 * recv < 0 : pipe busy
434 * recv >= 0 : receive data
435 *
436 * recv <= max_packet
437 */
438 if (recv < 0)
439 return -EBUSY;
440
441 /* update parameters */
442 req->actual += recv;
443
444 if ((recv == remainder) || /* receive all data */
445 (recv < maxp)) /* short packet */
446 is_done = 1;
447
448 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
449 usbhs_pipe_number(pipe),
450 remainder, recv, is_done, req->zero);
451
452 /* read all data ? */
453 if (is_done) {
454 int disable = 0;
455
456 uep->handler->irq_mask(uep, disable);
457 usbhs_fifo_disable(pipe);
458 usbhsg_queue_pop(uep, ureq, 0);
459 }
460
461 return 0;
462}
463
464static int usbhsg_prepare_receive_packet(struct usbhsg_uep *uep,
465 struct usbhsg_request *ureq)
466{
467 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
468 int enable = 1;
469 int ret;
470
471 /*
472 ********* assume under spin lock *********
473 */
474
475 ret = usbhs_fifo_prepare_read(pipe);
476 if (ret < 0)
477 return ret;
478
479 /*
480 * data will be read in interrupt handler
481 */
482 uep->handler->irq_mask(uep, enable);
483
484 return ret;
485}
486
487static struct usbhsg_pipe_handle usbhsg_handler_send_by_empty = {
488 .prepare = usbhsg_prepare_send_packet,
489 .try_run = usbhsg_try_run_send_packet,
490 .irq_mask = usbhsg_irq_empty_ctrl,
491};
492
493static struct usbhsg_pipe_handle usbhsg_handler_send_by_ready = {
494 .prepare = usbhsg_prepare_send_packet,
495 .try_run = usbhsg_try_run_send_packet,
496 .irq_mask = usbhsg_irq_ready_ctrl,
497};
498
499static struct usbhsg_pipe_handle usbhsg_handler_recv_by_ready = {
500 .prepare = usbhsg_prepare_receive_packet,
501 .try_run = usbhsg_try_run_receive_packet,
502 .irq_mask = usbhsg_irq_ready_ctrl,
503};
504
505static struct usbhsg_pipe_handle usbhsg_handler_ctrl_stage_end = {
506 .prepare = usbhsg_try_run_ctrl_stage_end,
507 .try_run = usbhsg_try_run_ctrl_stage_end,
508};
509
510/*
511 * DCP pipe can NOT use "ready interrupt" for "send"
512 * it should use "empty" interrupt.
513 * see
514 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
515 *
516 * on the other hand, normal pipe can use "ready interrupt" for "send"
517 * even though it is single/double buffer
518 */
519#define usbhsg_handler_send_ctrl usbhsg_handler_send_by_empty
520#define usbhsg_handler_recv_ctrl usbhsg_handler_recv_by_ready
521
522#define usbhsg_handler_send_packet usbhsg_handler_send_by_ready
523#define usbhsg_handler_recv_packet usbhsg_handler_recv_by_ready
524
525/*
526 * USB_TYPE_STANDARD / clear feature functions
527 */
528static int usbhsg_recip_handler_std_control_done(struct usbhs_priv *priv,
529 struct usbhsg_uep *uep,
530 struct usb_ctrlrequest *ctrl)
531{
532 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
533 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
534 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp);
535
536 usbhs_dcp_control_transfer_done(pipe);
537
538 return 0;
539}
540
541static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv,
542 struct usbhsg_uep *uep,
543 struct usb_ctrlrequest *ctrl)
544{
545 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
546 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
547
548 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) {
549 usbhs_fifo_disable(pipe);
550 usbhs_pipe_clear_sequence(pipe);
551 usbhs_fifo_enable(pipe);
552 }
553
554 usbhsg_recip_handler_std_control_done(priv, uep, ctrl);
555
556 usbhsg_queue_prepare(uep);
557
558 return 0;
559}
560
561struct usbhsg_recip_handle req_clear_feature = {
562 .name = "clear feature",
563 .device = usbhsg_recip_handler_std_control_done,
564 .interface = usbhsg_recip_handler_std_control_done,
565 .endpoint = usbhsg_recip_handler_std_clear_endpoint,
566};
567
568/*
569 * USB_TYPE handler
570 */
571static int usbhsg_recip_run_handle(struct usbhs_priv *priv,
572 struct usbhsg_recip_handle *handler,
573 struct usb_ctrlrequest *ctrl)
574{
575 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
576 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
577 struct usbhsg_uep *uep;
578 int recip = ctrl->bRequestType & USB_RECIP_MASK;
579 int nth = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK;
580 int ret;
581 int (*func)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
582 struct usb_ctrlrequest *ctrl);
583 char *msg;
584
585 uep = usbhsg_gpriv_to_nth_uep(gpriv, nth);
586 if (!usbhsg_uep_to_pipe(uep)) {
587 dev_err(dev, "wrong recip request\n");
588 return -EINVAL;
589 }
590
591 switch (recip) {
592 case USB_RECIP_DEVICE:
593 msg = "DEVICE";
594 func = handler->device;
595 break;
596 case USB_RECIP_INTERFACE:
597 msg = "INTERFACE";
598 func = handler->interface;
599 break;
600 case USB_RECIP_ENDPOINT:
601 msg = "ENDPOINT";
602 func = handler->endpoint;
603 break;
604 default:
605 dev_warn(dev, "unsupported RECIP(%d)\n", recip);
606 func = NULL;
607 ret = -EINVAL;
608 }
609
610 if (func) {
611 dev_dbg(dev, "%s (pipe %d :%s)\n", handler->name, nth, msg);
612 ret = func(priv, uep, ctrl);
613 }
614
615 return ret;
616}
617
618/*
619 * irq functions
620 *
621 * it will be called from usbhs_interrupt
622 */
623static int usbhsg_irq_dev_state(struct usbhs_priv *priv,
624 struct usbhs_irq_state *irq_state)
625{
626 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
627 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
628
629 gpriv->gadget.speed = usbhs_status_get_usb_speed(irq_state);
630
631 dev_dbg(dev, "state = %x : speed : %d\n",
632 usbhs_status_get_device_state(irq_state),
633 gpriv->gadget.speed);
634
635 return 0;
636}
637
638static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv,
639 struct usbhs_irq_state *irq_state)
640{
641 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
642 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
643 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp);
644 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
645 struct usb_ctrlrequest ctrl;
646 struct usbhsg_recip_handle *recip_handler = NULL;
647 int stage = usbhs_status_get_ctrl_stage(irq_state);
648 int ret = 0;
649
650 dev_dbg(dev, "stage = %d\n", stage);
651
652 /*
653 * see Manual
654 *
655 * "Operation"
656 * - "Interrupt Function"
657 * - "Control Transfer Stage Transition Interrupt"
658 * - Fig. "Control Transfer Stage Transitions"
659 */
660
661 switch (stage) {
662 case READ_DATA_STAGE:
663 dcp->handler = &usbhsg_handler_send_ctrl;
664 break;
665 case WRITE_DATA_STAGE:
666 dcp->handler = &usbhsg_handler_recv_ctrl;
667 break;
668 case NODATA_STATUS_STAGE:
669 dcp->handler = &usbhsg_handler_ctrl_stage_end;
670 break;
671 default:
672 return ret;
673 }
674
675 /*
676 * get usb request
677 */
678 usbhs_usbreq_get_val(priv, &ctrl);
679
680 switch (ctrl.bRequestType & USB_TYPE_MASK) {
681 case USB_TYPE_STANDARD:
682 switch (ctrl.bRequest) {
683 case USB_REQ_CLEAR_FEATURE:
684 recip_handler = &req_clear_feature;
685 break;
686 }
687 }
688
689 /*
690 * setup stage / run recip
691 */
692 if (recip_handler)
693 ret = usbhsg_recip_run_handle(priv, recip_handler, &ctrl);
694 else
695 ret = gpriv->driver->setup(&gpriv->gadget, &ctrl);
696
697 if (ret < 0)
698 usbhs_fifo_stall(pipe);
699
700 return ret;
701}
702
703static int usbhsg_irq_empty(struct usbhs_priv *priv,
704 struct usbhs_irq_state *irq_state)
705{
706 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
707 struct usbhsg_uep *uep;
708 struct usbhs_pipe *pipe;
709 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
710 int i, ret;
711
712 if (!irq_state->bempsts) {
713 dev_err(dev, "debug %s !!\n", __func__);
714 return -EIO;
715 }
716
717 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
718
719 /*
720 * search interrupted "pipe"
721 * not "uep".
722 */
723 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
724 if (!(irq_state->bempsts & (1 << i)))
725 continue;
726
727 uep = usbhsg_pipe_to_uep(pipe);
728 ret = usbhsg_queue_handle(uep);
729 if (ret < 0)
730 dev_err(dev, "send error %d : %d\n", i, ret);
731 }
732
733 return 0;
734}
735
736static int usbhsg_irq_ready(struct usbhs_priv *priv,
737 struct usbhs_irq_state *irq_state)
738{
739 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
740 struct usbhsg_uep *uep;
741 struct usbhs_pipe *pipe;
742 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
743 int i, ret;
744
745 if (!irq_state->brdysts) {
746 dev_err(dev, "debug %s !!\n", __func__);
747 return -EIO;
748 }
749
750 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
751
752 /*
753 * search interrupted "pipe"
754 * not "uep".
755 */
756 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
757 if (!(irq_state->brdysts & (1 << i)))
758 continue;
759
760 uep = usbhsg_pipe_to_uep(pipe);
761 ret = usbhsg_queue_handle(uep);
762 if (ret < 0)
763 dev_err(dev, "receive error %d : %d\n", i, ret);
764 }
765
766 return 0;
767}
768
769/*
770 *
771 * usb_dcp_ops
772 *
773 */
774static int usbhsg_dcp_enable(struct usbhsg_uep *uep)
775{
776 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
777 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
778 struct usbhs_pipe *pipe;
779
780 /*
781 ********* assume under spin lock *********
782 */
783
784 pipe = usbhs_dcp_malloc(priv);
785 if (!pipe)
786 return -EIO;
787
788 uep->pipe = pipe;
789 uep->pipe->mod_private = uep;
790 INIT_LIST_HEAD(&uep->list);
791
792 return 0;
793}
794
795#define usbhsg_dcp_disable usbhsg_pipe_disable
796static int usbhsg_pipe_disable(struct usbhsg_uep *uep)
797{
798 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
799 struct usbhsg_request *ureq;
800 int disable = 0;
801
802 /*
803 ********* assume under spin lock *********
804 */
805
806 usbhs_fifo_disable(pipe);
807
808 /*
809 * disable pipe irq
810 */
811 usbhsg_irq_empty_ctrl(uep, disable);
812 usbhsg_irq_ready_ctrl(uep, disable);
813
814 while (1) {
815 ureq = usbhsg_queue_get(uep);
816 if (!ureq)
817 break;
818
819 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
820 }
821
822 return 0;
823}
824
825static void usbhsg_uep_init(struct usbhsg_gpriv *gpriv)
826{
827 int i;
828 struct usbhsg_uep *uep;
829
830 usbhsg_for_each_uep_with_dcp(uep, gpriv, i)
831 uep->pipe = NULL;
832}
833
834/*
835 *
836 * usb_ep_ops
837 *
838 */
839static int usbhsg_ep_enable(struct usb_ep *ep,
840 const struct usb_endpoint_descriptor *desc)
841{
842 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
843 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
844 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
845 struct usbhs_pipe *pipe;
846 spinlock_t *lock;
847 unsigned long flags;
848 int ret = -EIO;
849
850 /*
851 * if it already have pipe,
852 * nothing to do
853 */
854 if (uep->pipe)
855 return 0;
856
857 /******************** spin lock ********************/
858 lock = usbhsg_trylock(gpriv, &flags);
859
860 pipe = usbhs_pipe_malloc(priv, desc);
861 if (pipe) {
862 uep->pipe = pipe;
863 pipe->mod_private = uep;
864 INIT_LIST_HEAD(&uep->list);
865
866 if (usb_endpoint_dir_in(desc))
867 uep->handler = &usbhsg_handler_send_packet;
868 else
869 uep->handler = &usbhsg_handler_recv_packet;
870
871 ret = 0;
872 }
873
874 usbhsg_unlock(lock, &flags);
875 /******************** spin unlock ******************/
876
877 return ret;
878}
879
880static int usbhsg_ep_disable(struct usb_ep *ep)
881{
882 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
883 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
884 spinlock_t *lock;
885 unsigned long flags;
886 int ret;
887
888 /******************** spin lock ********************/
889 lock = usbhsg_trylock(gpriv, &flags);
890
891 ret = usbhsg_pipe_disable(uep);
892
893 usbhsg_unlock(lock, &flags);
894 /******************** spin unlock ******************/
895
896 return ret;
897}
898
899static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep,
900 gfp_t gfp_flags)
901{
902 struct usbhsg_request *ureq;
903
904 ureq = kzalloc(sizeof *ureq, gfp_flags);
905 if (!ureq)
906 return NULL;
907
908 INIT_LIST_HEAD(&ureq->node);
909 return &ureq->req;
910}
911
912static void usbhsg_ep_free_request(struct usb_ep *ep,
913 struct usb_request *req)
914{
915 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
916
917 WARN_ON(!list_empty(&ureq->node));
918 kfree(ureq);
919}
920
921static int usbhsg_ep_queue(struct usb_ep *ep, struct usb_request *req,
922 gfp_t gfp_flags)
923{
924 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
925 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
926 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
927 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
928 spinlock_t *lock;
929 unsigned long flags;
930 int ret = 0;
931
932 /*
933 * CAUTION [*endpoint queue*]
934 *
935 * This function will be called from usb_request :: complete
936 * or usb driver timing.
937 * If this function is called from usb_request :: complete,
938 * it is already under spinlock on this driver.
939 * but it is called frm usb driver, this function should call spinlock.
940 *
941 * This function is using usbshg_trylock to solve this issue.
942 * if "is_locked" is 1, this mean this function lock it.
943 * but if it is 0, this mean it is already under spin lock.
944 * see also
945 * CAUTION [*queue handler*]
946 * CAUTION [*request complete*]
947 */
948
949 /******************** spin lock ********************/
950 lock = usbhsg_trylock(gpriv, &flags);
951
952 /* param check */
953 if (usbhsg_is_not_connected(gpriv) ||
954 unlikely(!gpriv->driver) ||
955 unlikely(!pipe))
956 ret = -ESHUTDOWN;
957 else
958 usbhsg_queue_push(uep, ureq);
959
960 usbhsg_unlock(lock, &flags);
961 /******************** spin unlock ******************/
962
963 usbhsg_queue_prepare(uep);
964
965 return ret;
966}
967
968static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
969{
970 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
971 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
972 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
973 spinlock_t *lock;
974 unsigned long flags;
975
976 /*
977 * see
978 * CAUTION [*queue handler*]
979 * CAUTION [*endpoint queue*]
980 * CAUTION [*request complete*]
981 */
982
983 /******************** spin lock ********************/
984 lock = usbhsg_trylock(gpriv, &flags);
985
986 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
987
988 usbhsg_unlock(lock, &flags);
989 /******************** spin unlock ******************/
990
991 return 0;
992}
993
994static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
995{
996 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
997 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
998 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
999 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
1000 spinlock_t *lock;
1001 unsigned long flags;
1002 int ret = -EAGAIN;
1003
1004 /*
1005 * see
1006 * CAUTION [*queue handler*]
1007 * CAUTION [*endpoint queue*]
1008 * CAUTION [*request complete*]
1009 */
1010
1011 /******************** spin lock ********************/
1012 lock = usbhsg_trylock(gpriv, &flags);
1013 if (!usbhsg_queue_get(uep)) {
1014
1015 dev_dbg(dev, "set halt %d (pipe %d)\n",
1016 halt, usbhs_pipe_number(pipe));
1017
1018 if (halt)
1019 usbhs_fifo_stall(pipe);
1020 else
1021 usbhs_fifo_disable(pipe);
1022
1023 if (halt && wedge)
1024 usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE);
1025 else
1026 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
1027
1028 ret = 0;
1029 }
1030
1031 usbhsg_unlock(lock, &flags);
1032 /******************** spin unlock ******************/
1033
1034 return ret;
1035}
1036
1037static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
1038{
1039 return __usbhsg_ep_set_halt_wedge(ep, value, 0);
1040}
1041
1042static int usbhsg_ep_set_wedge(struct usb_ep *ep)
1043{
1044 return __usbhsg_ep_set_halt_wedge(ep, 1, 1);
1045}
1046
1047static struct usb_ep_ops usbhsg_ep_ops = {
1048 .enable = usbhsg_ep_enable,
1049 .disable = usbhsg_ep_disable,
1050
1051 .alloc_request = usbhsg_ep_alloc_request,
1052 .free_request = usbhsg_ep_free_request,
1053
1054 .queue = usbhsg_ep_queue,
1055 .dequeue = usbhsg_ep_dequeue,
1056
1057 .set_halt = usbhsg_ep_set_halt,
1058 .set_wedge = usbhsg_ep_set_wedge,
1059};
1060
1061/*
1062 * usb module start/end
1063 */
1064static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
1065{
1066 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1067 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1068 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1069 struct device *dev = usbhs_priv_to_dev(priv);
1070 spinlock_t *lock;
1071 unsigned long flags;
1072
1073 /******************** spin lock ********************/
1074 lock = usbhsg_trylock(gpriv, &flags);
1075
1076 /*
1077 * enable interrupt and systems if ready
1078 */
1079 usbhsg_status_set(gpriv, status);
1080 if (!(usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1081 usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD)))
1082 goto usbhsg_try_start_unlock;
1083
1084 dev_dbg(dev, "start gadget\n");
1085
1086 /*
1087 * pipe initialize and enable DCP
1088 */
1089 usbhs_pipe_init(priv);
1090 usbhsg_uep_init(gpriv);
1091 usbhsg_dcp_enable(dcp);
1092
1093 /*
1094 * system config enble
1095 * - HI speed
1096 * - function
1097 * - usb module
1098 */
1099 usbhs_sys_hispeed_ctrl(priv, 1);
1100 usbhs_sys_function_ctrl(priv, 1);
1101 usbhs_sys_usb_ctrl(priv, 1);
1102
1103 /*
1104 * enable irq callback
1105 */
1106 mod->irq_dev_state = usbhsg_irq_dev_state;
1107 mod->irq_ctrl_stage = usbhsg_irq_ctrl_stage;
1108 mod->irq_empty = usbhsg_irq_empty;
1109 mod->irq_ready = usbhsg_irq_ready;
1110 mod->irq_bempsts = 0;
1111 mod->irq_brdysts = 0;
1112 usbhs_irq_callback_update(priv, mod);
1113
1114usbhsg_try_start_unlock:
1115 usbhsg_unlock(lock, &flags);
1116 /******************** spin unlock ********************/
1117
1118 return 0;
1119}
1120
1121static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
1122{
1123 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1124 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1125 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1126 struct device *dev = usbhs_priv_to_dev(priv);
1127 spinlock_t *lock;
1128 unsigned long flags;
1129
1130 /******************** spin lock ********************/
1131 lock = usbhsg_trylock(gpriv, &flags);
1132
1133 /*
1134 * disable interrupt and systems if 1st try
1135 */
1136 usbhsg_status_clr(gpriv, status);
1137 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1138 !usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD))
1139 goto usbhsg_try_stop_unlock;
1140
1141 /* disable all irq */
1142 mod->irq_dev_state = NULL;
1143 mod->irq_ctrl_stage = NULL;
1144 mod->irq_empty = NULL;
1145 mod->irq_ready = NULL;
1146 mod->irq_bempsts = 0;
1147 mod->irq_brdysts = 0;
1148 usbhs_irq_callback_update(priv, mod);
1149
1150 usbhsg_dcp_disable(dcp);
1151
1152 gpriv->gadget.speed = USB_SPEED_UNKNOWN;
1153
1154 /* disable sys */
1155 usbhs_sys_hispeed_ctrl(priv, 0);
1156 usbhs_sys_function_ctrl(priv, 0);
1157 usbhs_sys_usb_ctrl(priv, 0);
1158
1159 usbhsg_unlock(lock, &flags);
1160 /******************** spin unlock ********************/
1161
1162 if (gpriv->driver &&
1163 gpriv->driver->disconnect)
1164 gpriv->driver->disconnect(&gpriv->gadget);
1165
1166 dev_dbg(dev, "stop gadget\n");
1167
1168 return 0;
1169
1170usbhsg_try_stop_unlock:
1171 usbhsg_unlock(lock, &flags);
1172
1173 return 0;
1174}
1175
1176/*
1177 *
1178 * linux usb function
1179 *
1180 */
1181struct usbhsg_gpriv *the_controller;
1182int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1183 int (*bind)(struct usb_gadget *))
1184{
1185 struct usbhsg_gpriv *gpriv = the_controller;
1186 struct usbhs_priv *priv;
1187 struct device *dev;
1188 int ret;
1189
1190 if (!bind ||
1191 !driver ||
1192 !driver->setup ||
1193 driver->speed != USB_SPEED_HIGH)
1194 return -EINVAL;
1195 if (!gpriv)
1196 return -ENODEV;
1197 if (gpriv->driver)
1198 return -EBUSY;
1199
1200 dev = usbhsg_gpriv_to_dev(gpriv);
1201 priv = usbhsg_gpriv_to_priv(gpriv);
1202
1203 /* first hook up the driver ... */
1204 gpriv->driver = driver;
1205 gpriv->gadget.dev.driver = &driver->driver;
1206
1207 ret = device_add(&gpriv->gadget.dev);
1208 if (ret) {
1209 dev_err(dev, "device_add error %d\n", ret);
1210 goto add_fail;
1211 }
1212
1213 ret = bind(&gpriv->gadget);
1214 if (ret) {
1215 dev_err(dev, "bind to driver %s error %d\n",
1216 driver->driver.name, ret);
1217 goto bind_fail;
1218 }
1219
1220 dev_dbg(dev, "bind %s\n", driver->driver.name);
1221
1222 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
1223
1224bind_fail:
1225 device_del(&gpriv->gadget.dev);
1226add_fail:
1227 gpriv->driver = NULL;
1228 gpriv->gadget.dev.driver = NULL;
1229
1230 return ret;
1231}
1232EXPORT_SYMBOL(usb_gadget_probe_driver);
1233
1234int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1235{
1236 struct usbhsg_gpriv *gpriv = the_controller;
1237 struct usbhs_priv *priv;
1238 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
1239
1240 if (!gpriv)
1241 return -ENODEV;
1242
1243 if (!driver ||
1244 !driver->unbind ||
1245 driver != gpriv->driver)
1246 return -EINVAL;
1247
1248 dev = usbhsg_gpriv_to_dev(gpriv);
1249 priv = usbhsg_gpriv_to_priv(gpriv);
1250
1251 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
1252 device_del(&gpriv->gadget.dev);
1253 gpriv->driver = NULL;
1254
1255 if (driver->disconnect)
1256 driver->disconnect(&gpriv->gadget);
1257
1258 driver->unbind(&gpriv->gadget);
1259 dev_dbg(dev, "unbind %s\n", driver->driver.name);
1260
1261 return 0;
1262}
1263EXPORT_SYMBOL(usb_gadget_unregister_driver);
1264
1265/*
1266 * usb gadget ops
1267 */
1268static int usbhsg_get_frame(struct usb_gadget *gadget)
1269{
1270 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
1271 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
1272
1273 return usbhs_frame_get_num(priv);
1274}
1275
1276static struct usb_gadget_ops usbhsg_gadget_ops = {
1277 .get_frame = usbhsg_get_frame,
1278};
1279
1280static int usbhsg_start(struct usbhs_priv *priv)
1281{
1282 return usbhsg_try_start(priv, USBHSG_STATUS_STARTED);
1283}
1284
1285static int usbhsg_stop(struct usbhs_priv *priv)
1286{
1287 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
1288}
1289
1290int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1291{
1292 struct usbhsg_gpriv *gpriv;
1293 struct usbhsg_uep *uep;
1294 struct device *dev = usbhs_priv_to_dev(priv);
1295 int pipe_size = usbhs_get_dparam(priv, pipe_size);
1296 int i;
1297
1298 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL);
1299 if (!gpriv) {
1300 dev_err(dev, "Could not allocate gadget priv\n");
1301 return -ENOMEM;
1302 }
1303
1304 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL);
1305 if (!uep) {
1306 dev_err(dev, "Could not allocate ep\n");
1307 goto usbhs_mod_gadget_probe_err_gpriv;
1308 }
1309
1310 /*
1311 * CAUTION
1312 *
1313 * There is no guarantee that it is possible to access usb module here.
1314 * Don't accesses to it.
1315 * The accesse will be enable after "usbhsg_start"
1316 */
1317
1318 /*
1319 * register itself
1320 */
1321 usbhs_mod_register(priv, &gpriv->mod, USBHS_GADGET);
1322
1323 /* init gpriv */
1324 gpriv->mod.name = "gadget";
1325 gpriv->mod.start = usbhsg_start;
1326 gpriv->mod.stop = usbhsg_stop;
1327 gpriv->uep = uep;
1328 gpriv->uep_size = pipe_size;
1329 usbhsg_status_init(gpriv);
1330
1331 /*
1332 * init gadget
1333 */
1334 device_initialize(&gpriv->gadget.dev);
1335 dev_set_name(&gpriv->gadget.dev, "gadget");
1336 gpriv->gadget.dev.parent = dev;
1337 gpriv->gadget.name = "renesas_usbhs_udc";
1338 gpriv->gadget.ops = &usbhsg_gadget_ops;
1339 gpriv->gadget.is_dualspeed = 1;
1340
1341 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
1342
1343 /*
1344 * init usb_ep
1345 */
1346 usbhsg_for_each_uep_with_dcp(uep, gpriv, i) {
1347 uep->gpriv = gpriv;
1348 snprintf(uep->ep_name, EP_NAME_SIZE, "ep%d", i);
1349
1350 uep->ep.name = uep->ep_name;
1351 uep->ep.ops = &usbhsg_ep_ops;
1352 INIT_LIST_HEAD(&uep->ep.ep_list);
1353 INIT_LIST_HEAD(&uep->list);
1354
1355 /* init DCP */
1356 if (usbhsg_is_dcp(uep)) {
1357 gpriv->gadget.ep0 = &uep->ep;
1358 uep->ep.maxpacket = 64;
1359 }
1360 /* init normal pipe */
1361 else {
1362 uep->ep.maxpacket = 512;
1363 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list);
1364 }
1365 }
1366
1367 the_controller = gpriv;
1368
1369 dev_info(dev, "gadget probed\n");
1370
1371 return 0;
1372
1373usbhs_mod_gadget_probe_err_gpriv:
1374 kfree(gpriv);
1375
1376 return -ENOMEM;
1377}
1378
1379void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv)
1380{
1381 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1382
1383 kfree(gpriv->uep);
1384 kfree(gpriv);
1385}
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
new file mode 100644
index 000000000000..bc4521c54261
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/pipe.c
@@ -0,0 +1,874 @@
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 */
17#include <linux/delay.h>
18#include <linux/io.h>
19#include <linux/slab.h>
20#include "./common.h"
21#include "./pipe.h"
22
23/*
24 * macros
25 */
26#define usbhsp_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
27#define usbhsp_pipe_to_priv(p) ((p)->priv)
28
29#define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
30
31#define usbhsp_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
32
33#define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
34#define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
35#define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
36#define usbhsp_flags_init(p) do {(p)->flags = 0; } while (0)
37
38#define usbhsp_type(p) ((p)->pipe_type)
39#define usbhsp_type_is(p, t) ((p)->pipe_type == t)
40
41/*
42 * for debug
43 */
44static char *usbhsp_pipe_name[] = {
45 [USB_ENDPOINT_XFER_CONTROL] = "DCP",
46 [USB_ENDPOINT_XFER_BULK] = "BULK",
47 [USB_ENDPOINT_XFER_INT] = "INT",
48 [USB_ENDPOINT_XFER_ISOC] = "ISO",
49};
50
51/*
52 * usb request functions
53 */
54void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
55{
56 u16 val;
57
58 val = usbhs_read(priv, USBREQ);
59 req->bRequest = (val >> 8) & 0xFF;
60 req->bRequestType = (val >> 0) & 0xFF;
61
62 req->wValue = usbhs_read(priv, USBVAL);
63 req->wIndex = usbhs_read(priv, USBINDX);
64 req->wLength = usbhs_read(priv, USBLENG);
65}
66
67void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
68{
69 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
70 usbhs_write(priv, USBVAL, req->wValue);
71 usbhs_write(priv, USBINDX, req->wIndex);
72 usbhs_write(priv, USBLENG, req->wLength);
73}
74
75/*
76 * DCPCTR/PIPEnCTR functions
77 */
78static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
79{
80 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
81 int offset = usbhsp_addr_offset(pipe);
82
83 if (usbhsp_is_dcp(pipe))
84 usbhs_bset(priv, DCPCTR, mask, val);
85 else
86 usbhs_bset(priv, PIPEnCTR + offset, mask, val);
87}
88
89static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
90{
91 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
92 int offset = usbhsp_addr_offset(pipe);
93
94 if (usbhsp_is_dcp(pipe))
95 return usbhs_read(priv, DCPCTR);
96 else
97 return usbhs_read(priv, PIPEnCTR + offset);
98}
99
100/*
101 * DCP/PIPE functions
102 */
103static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
104 u16 dcp_reg, u16 pipe_reg,
105 u16 mask, u16 val)
106{
107 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
108
109 if (usbhsp_is_dcp(pipe))
110 usbhs_bset(priv, dcp_reg, mask, val);
111 else
112 usbhs_bset(priv, pipe_reg, mask, val);
113}
114
115static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
116 u16 dcp_reg, u16 pipe_reg)
117{
118 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
119
120 if (usbhsp_is_dcp(pipe))
121 return usbhs_read(priv, dcp_reg);
122 else
123 return usbhs_read(priv, pipe_reg);
124}
125
126/*
127 * DCPCFG/PIPECFG functions
128 */
129static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
130{
131 __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
132}
133
134/*
135 * PIPEBUF
136 */
137static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
138{
139 if (usbhsp_is_dcp(pipe))
140 return;
141
142 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
143}
144
145/*
146 * DCPMAXP/PIPEMAXP
147 */
148static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
149{
150 __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
151}
152
153static u16 usbhsp_pipe_maxp_get(struct usbhs_pipe *pipe)
154{
155 return __usbhsp_pipe_xxx_get(pipe, DCPMAXP, PIPEMAXP);
156}
157
158/*
159 * pipe control functions
160 */
161static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
162{
163 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
164
165 /*
166 * On pipe, this is necessary before
167 * accesses to below registers.
168 *
169 * PIPESEL : usbhsp_pipe_select
170 * PIPECFG : usbhsp_pipe_cfg_xxx
171 * PIPEBUF : usbhsp_pipe_buf_xxx
172 * PIPEMAXP : usbhsp_pipe_maxp_xxx
173 * PIPEPERI
174 */
175
176 /*
177 * if pipe is dcp, no pipe is selected.
178 * it is no problem, because dcp have its register
179 */
180 usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
181}
182
183static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
184{
185 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
186 int timeout = 1024;
187 u16 val;
188
189 /*
190 * make sure....
191 *
192 * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
193 * specified by the CURPIPE bits.
194 * When changing the setting of this bit after changing
195 * the PID bits for the selected pipe from BUF to NAK,
196 * check that CSSTS = 0 and PBUSY = 0.
197 */
198
199 /*
200 * CURPIPE bit = 0
201 *
202 * see also
203 * "Operation"
204 * - "Pipe Control"
205 * - "Pipe Control Registers Switching Procedure"
206 */
207 usbhs_write(priv, CFIFOSEL, 0);
208 usbhs_fifo_disable(pipe);
209
210 do {
211 val = usbhsp_pipectrl_get(pipe);
212 val &= CSSTS | PID_MASK;
213 if (!val)
214 return 0;
215
216 udelay(10);
217
218 } while (timeout--);
219
220 return -EBUSY;
221}
222
223static int usbhsp_pipe_is_accessible(struct usbhs_pipe *pipe)
224{
225 u16 val;
226
227 val = usbhsp_pipectrl_get(pipe);
228 if (val & BSTS)
229 return 0;
230
231 return -EBUSY;
232}
233
234/*
235 * PID ctrl
236 */
237static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
238{
239 u16 pid = usbhsp_pipectrl_get(pipe);
240
241 pid &= PID_MASK;
242
243 /*
244 * see
245 * "Pipe n Control Register" - "PID"
246 */
247 switch (pid) {
248 case PID_STALL11:
249 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
250 /* fall-through */
251 case PID_STALL10:
252 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
253 }
254}
255
256void usbhs_fifo_disable(struct usbhs_pipe *pipe)
257{
258 int timeout = 1024;
259 u16 val;
260
261 /* see "Pipe n Control Register" - "PID" */
262 __usbhsp_pid_try_nak_if_stall(pipe);
263
264 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
265
266 do {
267 val = usbhsp_pipectrl_get(pipe);
268 val &= PBUSY;
269 if (!val)
270 break;
271
272 udelay(10);
273 } while (timeout--);
274}
275
276void usbhs_fifo_enable(struct usbhs_pipe *pipe)
277{
278 /* see "Pipe n Control Register" - "PID" */
279 __usbhsp_pid_try_nak_if_stall(pipe);
280
281 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
282}
283
284void usbhs_fifo_stall(struct usbhs_pipe *pipe)
285{
286 u16 pid = usbhsp_pipectrl_get(pipe);
287
288 pid &= PID_MASK;
289
290 /*
291 * see
292 * "Pipe n Control Register" - "PID"
293 */
294 switch (pid) {
295 case PID_NAK:
296 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
297 break;
298 case PID_BUF:
299 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
300 break;
301 }
302}
303
304/*
305 * CFIFO ctrl
306 */
307void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe)
308{
309 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
310
311 usbhs_bset(priv, CFIFOCTR, BVAL, BVAL);
312}
313
314static void usbhsp_fifo_clear(struct usbhs_pipe *pipe)
315{
316 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
317
318 usbhs_write(priv, CFIFOCTR, BCLR);
319}
320
321static int usbhsp_fifo_barrier(struct usbhs_priv *priv)
322{
323 int timeout = 1024;
324
325 do {
326 /* The FIFO port is accessible */
327 if (usbhs_read(priv, CFIFOCTR) & FRDY)
328 return 0;
329
330 udelay(10);
331 } while (timeout--);
332
333 return -EBUSY;
334}
335
336static int usbhsp_fifo_rcv_len(struct usbhs_priv *priv)
337{
338 return usbhs_read(priv, CFIFOCTR) & DTLN_MASK;
339}
340
341static int usbhsp_fifo_select(struct usbhs_pipe *pipe, int write)
342{
343 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
344 struct device *dev = usbhs_priv_to_dev(priv);
345 int timeout = 1024;
346 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
347 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
348
349 if (usbhsp_is_dcp(pipe))
350 base |= (1 == write) << 5; /* ISEL */
351
352 /* "base" will be used below */
353 usbhs_write(priv, CFIFOSEL, base | MBW_32);
354
355 /* check ISEL and CURPIPE value */
356 while (timeout--) {
357 if (base == (mask & usbhs_read(priv, CFIFOSEL)))
358 return 0;
359 udelay(10);
360 }
361
362 dev_err(dev, "fifo select error\n");
363
364 return -EIO;
365}
366
367int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe)
368{
369 return usbhsp_fifo_select(pipe, 1);
370}
371
372int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len)
373{
374 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
375 void __iomem *addr = priv->base + CFIFO;
376 int maxp = usbhs_pipe_get_maxpacket(pipe);
377 int total_len;
378 int i, ret;
379
380 ret = usbhsp_pipe_is_accessible(pipe);
381 if (ret < 0)
382 return ret;
383
384 ret = usbhsp_fifo_select(pipe, 1);
385 if (ret < 0)
386 return ret;
387
388 ret = usbhsp_fifo_barrier(priv);
389 if (ret < 0)
390 return ret;
391
392 len = min(len, maxp);
393 total_len = len;
394
395 /*
396 * FIXME
397 *
398 * 32-bit access only
399 */
400 if (len >= 4 &&
401 !((unsigned long)buf & 0x03)) {
402 iowrite32_rep(addr, buf, len / 4);
403 len %= 4;
404 buf += total_len - len;
405 }
406
407 /* the rest operation */
408 for (i = 0; i < len; i++)
409 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
410
411 if (total_len < maxp)
412 usbhs_fifo_send_terminator(pipe);
413
414 return total_len;
415}
416
417int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe)
418{
419 int ret;
420
421 /*
422 * select pipe and enable it to prepare packet receive
423 */
424 ret = usbhsp_fifo_select(pipe, 0);
425 if (ret < 0)
426 return ret;
427
428 usbhs_fifo_enable(pipe);
429
430 return ret;
431}
432
433int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len)
434{
435 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
436 void __iomem *addr = priv->base + CFIFO;
437 int rcv_len;
438 int i, ret;
439 int total_len;
440 u32 data = 0;
441
442 ret = usbhsp_fifo_select(pipe, 0);
443 if (ret < 0)
444 return ret;
445
446 ret = usbhsp_fifo_barrier(priv);
447 if (ret < 0)
448 return ret;
449
450 rcv_len = usbhsp_fifo_rcv_len(priv);
451
452 /*
453 * Buffer clear if Zero-Length packet
454 *
455 * see
456 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
457 */
458 if (0 == rcv_len) {
459 usbhsp_fifo_clear(pipe);
460 return 0;
461 }
462
463 len = min(rcv_len, len);
464 total_len = len;
465
466 /*
467 * FIXME
468 *
469 * 32-bit access only
470 */
471 if (len >= 4 &&
472 !((unsigned long)buf & 0x03)) {
473 ioread32_rep(addr, buf, len / 4);
474 len %= 4;
475 buf += rcv_len - len;
476 }
477
478 /* the rest operation */
479 for (i = 0; i < len; i++) {
480 if (!(i & 0x03))
481 data = ioread32(addr);
482
483 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
484 }
485
486 return total_len;
487}
488
489/*
490 * pipe setup
491 */
492static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
493{
494 /*
495 * only ISO / BULK pipe can use double buffer
496 */
497 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) ||
498 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
499 return 1;
500
501 return 0;
502}
503
504static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
505 const struct usb_endpoint_descriptor *desc,
506 int is_host)
507{
508 u16 type = 0;
509 u16 bfre = 0;
510 u16 dblb = 0;
511 u16 cntmd = 0;
512 u16 dir = 0;
513 u16 epnum = 0;
514 u16 shtnak = 0;
515 u16 type_array[] = {
516 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
517 [USB_ENDPOINT_XFER_INT] = TYPE_INT,
518 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
519 };
520 int is_double = usbhsp_possible_double_buffer(pipe);
521
522 if (usbhsp_is_dcp(pipe))
523 return -EINVAL;
524
525 /*
526 * PIPECFG
527 *
528 * see
529 * - "Register Descriptions" - "PIPECFG" register
530 * - "Features" - "Pipe configuration"
531 * - "Operation" - "Pipe Control"
532 */
533
534 /* TYPE */
535 type = type_array[usbhsp_type(pipe)];
536
537 /* BFRE */
538 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
539 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
540 bfre = 0; /* FIXME */
541
542 /* DBLB */
543 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
544 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
545 dblb = (is_double) ? DBLB : 0;
546
547 /* CNTMD */
548 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
549 cntmd = 0; /* FIXME */
550
551 /* DIR */
552 if (usb_endpoint_dir_in(desc))
553 usbhsp_flags_set(pipe, IS_DIR_IN);
554
555 if ((is_host && usb_endpoint_dir_out(desc)) ||
556 (!is_host && usb_endpoint_dir_in(desc)))
557 dir |= DIR_OUT;
558
559 /* SHTNAK */
560 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
561 !dir)
562 shtnak = SHTNAK;
563
564 /* EPNUM */
565 epnum = 0xF & usb_endpoint_num(desc);
566
567 return type |
568 bfre |
569 dblb |
570 cntmd |
571 dir |
572 shtnak |
573 epnum;
574}
575
576static u16 usbhsp_setup_pipemaxp(struct usbhs_pipe *pipe,
577 const struct usb_endpoint_descriptor *desc,
578 int is_host)
579{
580 /* host should set DEVSEL */
581
582 /* reutn MXPS */
583 return PIPE_MAXP_MASK & le16_to_cpu(desc->wMaxPacketSize);
584}
585
586static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
587 const struct usb_endpoint_descriptor *desc,
588 int is_host)
589{
590 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
591 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
592 struct device *dev = usbhs_priv_to_dev(priv);
593 int pipe_num = usbhs_pipe_number(pipe);
594 int is_double = usbhsp_possible_double_buffer(pipe);
595 u16 buff_size;
596 u16 bufnmb;
597 u16 bufnmb_cnt;
598
599 /*
600 * PIPEBUF
601 *
602 * see
603 * - "Register Descriptions" - "PIPEBUF" register
604 * - "Features" - "Pipe configuration"
605 * - "Operation" - "FIFO Buffer Memory"
606 * - "Operation" - "Pipe Control"
607 *
608 * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724)
609 *
610 * BUFNMB: PIPE
611 * 0: pipe0 (DCP 256byte)
612 * 1: -
613 * 2: -
614 * 3: -
615 * 4: pipe6 (INT 64byte)
616 * 5: pipe7 (INT 64byte)
617 * 6: pipe8 (INT 64byte)
618 * 7: pipe9 (INT 64byte)
619 * 8 - xx: free (for BULK, ISOC)
620 */
621
622 /*
623 * FIXME
624 *
625 * it doesn't have good buffer allocator
626 *
627 * DCP : 256 byte
628 * BULK: 512 byte
629 * INT : 64 byte
630 * ISOC: 512 byte
631 */
632 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_CONTROL))
633 buff_size = 256;
634 else if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
635 buff_size = 64;
636 else
637 buff_size = 512;
638
639 /* change buff_size to register value */
640 bufnmb_cnt = (buff_size / 64) - 1;
641
642 /* BUFNMB has been reserved for INT pipe
643 * see above */
644 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT)) {
645 bufnmb = pipe_num - 2;
646 } else {
647 bufnmb = info->bufnmb_last;
648 info->bufnmb_last += bufnmb_cnt + 1;
649
650 /*
651 * double buffer
652 */
653 if (is_double)
654 info->bufnmb_last += bufnmb_cnt + 1;
655 }
656
657 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
658 pipe_num, buff_size, bufnmb);
659
660 return (0x1f & bufnmb_cnt) << 10 |
661 (0xff & bufnmb) << 0;
662}
663
664/*
665 * pipe control
666 */
667int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
668{
669 u16 mask = usbhsp_is_dcp(pipe) ? DCP_MAXP_MASK : PIPE_MAXP_MASK;
670
671 usbhsp_pipe_select(pipe);
672
673 return (int)(usbhsp_pipe_maxp_get(pipe) & mask);
674}
675
676int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
677{
678 return usbhsp_flags_has(pipe, IS_DIR_IN);
679}
680
681void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe)
682{
683 usbhsp_pipectrl_set(pipe, SQCLR, SQCLR);
684}
685
686static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
687{
688 struct usbhs_pipe *pos, *pipe;
689 int i;
690
691 /*
692 * find target pipe
693 */
694 pipe = NULL;
695 usbhs_for_each_pipe_with_dcp(pos, priv, i) {
696 if (!usbhsp_type_is(pos, type))
697 continue;
698 if (usbhsp_flags_has(pos, IS_USED))
699 continue;
700
701 pipe = pos;
702 break;
703 }
704
705 if (!pipe)
706 return NULL;
707
708 /*
709 * initialize pipe flags
710 */
711 usbhsp_flags_init(pipe);
712 usbhsp_flags_set(pipe, IS_USED);
713
714 return pipe;
715}
716
717void usbhs_pipe_init(struct usbhs_priv *priv)
718{
719 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
720 struct usbhs_pipe *pipe;
721 int i;
722
723 /*
724 * FIXME
725 *
726 * driver needs good allocator.
727 *
728 * find first free buffer area (BULK, ISOC)
729 * (DCP, INT area is fixed)
730 *
731 * buffer number 0 - 3 have been reserved for DCP
732 * see
733 * usbhsp_to_bufnmb
734 */
735 info->bufnmb_last = 4;
736 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
737 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
738 info->bufnmb_last++;
739
740 usbhsp_flags_init(pipe);
741 pipe->mod_private = NULL;
742
743 usbhsp_fifo_clear(pipe);
744 }
745}
746
747struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
748 const struct usb_endpoint_descriptor *desc)
749{
750 struct device *dev = usbhs_priv_to_dev(priv);
751 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
752 struct usbhs_pipe *pipe;
753 int is_host = usbhs_mod_is_host(priv, mod);
754 int ret;
755 u16 pipecfg, pipebuf, pipemaxp;
756
757 pipe = usbhsp_get_pipe(priv, usb_endpoint_type(desc));
758 if (!pipe) {
759 dev_err(dev, "can't get pipe (%s)\n",
760 usbhsp_pipe_name[usb_endpoint_type(desc)]);
761 return NULL;
762 }
763
764 usbhs_fifo_disable(pipe);
765
766 /* make sure pipe is not busy */
767 ret = usbhsp_pipe_barrier(pipe);
768 if (ret < 0) {
769 dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
770 return NULL;
771 }
772
773 pipecfg = usbhsp_setup_pipecfg(pipe, desc, is_host);
774 pipebuf = usbhsp_setup_pipebuff(pipe, desc, is_host);
775 pipemaxp = usbhsp_setup_pipemaxp(pipe, desc, is_host);
776
777 /* buffer clear
778 * see PIPECFG :: BFRE */
779 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
780 usbhsp_pipectrl_set(pipe, ACLRM, 0);
781
782 usbhsp_pipe_select(pipe);
783 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
784 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
785 usbhsp_pipe_maxp_set(pipe, 0xFFFF, pipemaxp);
786
787 usbhs_pipe_clear_sequence(pipe);
788
789 dev_dbg(dev, "enable pipe %d : %s (%s)\n",
790 usbhs_pipe_number(pipe),
791 usbhsp_pipe_name[usb_endpoint_type(desc)],
792 usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
793
794 return pipe;
795}
796
797/*
798 * dcp control
799 */
800struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
801{
802 struct usbhs_pipe *pipe;
803
804 pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
805 if (!pipe)
806 return NULL;
807
808 /*
809 * dcpcfg : default
810 * dcpmaxp : default
811 * pipebuf : nothing to do
812 */
813
814 usbhsp_pipe_select(pipe);
815 usbhs_pipe_clear_sequence(pipe);
816
817 return pipe;
818}
819
820void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
821{
822 WARN_ON(!usbhsp_is_dcp(pipe));
823
824 usbhs_fifo_enable(pipe);
825 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
826}
827
828
829/*
830 * pipe module function
831 */
832int usbhs_pipe_probe(struct usbhs_priv *priv)
833{
834 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
835 struct usbhs_pipe *pipe;
836 struct device *dev = usbhs_priv_to_dev(priv);
837 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
838 int pipe_size = usbhs_get_dparam(priv, pipe_size);
839 int i;
840
841 /* This driver expects 1st pipe is DCP */
842 if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
843 dev_err(dev, "1st PIPE is not DCP\n");
844 return -EINVAL;
845 }
846
847 info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
848 if (!info->pipe) {
849 dev_err(dev, "Could not allocate pipe\n");
850 return -ENOMEM;
851 }
852
853 info->size = pipe_size;
854
855 /*
856 * init pipe
857 */
858 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
859 pipe->priv = priv;
860 usbhsp_type(pipe) = pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
861
862 dev_dbg(dev, "pipe %x\t: %s\n",
863 i, usbhsp_pipe_name[pipe_type[i]]);
864 }
865
866 return 0;
867}
868
869void usbhs_pipe_remove(struct usbhs_priv *priv)
870{
871 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
872
873 kfree(info->pipe);
874}
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
new file mode 100644
index 000000000000..1cca9b7fb266
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -0,0 +1,104 @@
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 */
17#ifndef RENESAS_USB_PIPE_H
18#define RENESAS_USB_PIPE_H
19
20#include "./common.h"
21
22/*
23 * struct
24 */
25struct usbhs_pipe {
26 u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */
27
28 struct usbhs_priv *priv;
29
30 u32 flags;
31#define USBHS_PIPE_FLAGS_IS_USED (1 << 0)
32#define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1)
33
34 void *mod_private;
35};
36
37struct usbhs_pipe_info {
38 struct usbhs_pipe *pipe;
39 int size; /* array size of "pipe" */
40 int bufnmb_last; /* FIXME : driver needs good allocator */
41};
42
43/*
44 * pipe list
45 */
46#define __usbhs_for_each_pipe(start, pos, info, i) \
47 for (i = start, pos = (info)->pipe; \
48 i < (info)->size; \
49 i++, pos = (info)->pipe + i)
50
51#define usbhs_for_each_pipe(pos, priv, i) \
52 __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)
53
54#define usbhs_for_each_pipe_with_dcp(pos, priv, i) \
55 __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i)
56
57/*
58 * pipe module probe / remove
59 */
60int usbhs_pipe_probe(struct usbhs_priv *priv);
61void usbhs_pipe_remove(struct usbhs_priv *priv);
62
63/*
64 * cfifo
65 */
66int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len);
67int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len);
68int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe);
69int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe);
70
71void usbhs_fifo_enable(struct usbhs_pipe *pipe);
72void usbhs_fifo_disable(struct usbhs_pipe *pipe);
73void usbhs_fifo_stall(struct usbhs_pipe *pipe);
74
75void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe);
76
77
78/*
79 * usb request
80 */
81void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
82void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
83
84/*
85 * pipe control
86 */
87struct usbhs_pipe
88*usbhs_pipe_malloc(struct usbhs_priv *priv,
89 const struct usb_endpoint_descriptor *desc);
90
91int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe);
92void usbhs_pipe_init(struct usbhs_priv *priv);
93int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
94void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe);
95
96#define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe)
97
98/*
99 * dcp control
100 */
101struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv);
102void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe);
103
104#endif /* RENESAS_USB_PIPE_H */