blob: 64797784a6df1a6232b1b9321932a94a490e54a7 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-1.0+
Kuninori Morimotof1407d52011-04-04 13:44:59 +09002/*
3 * Renesas USB driver
4 *
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Kuninori Morimotof1407d52011-04-04 13:44:59 +09007 */
8#ifndef RENESAS_USB_DRIVER_H
9#define RENESAS_USB_DRIVER_H
10
Sergei Shtylyovd7b39682014-12-16 01:42:13 +030011#include <linux/extcon.h>
Kuninori Morimotof1407d52011-04-04 13:44:59 +090012#include <linux/platform_device.h>
13#include <linux/usb/renesas_usbhs.h>
14
15struct usbhs_priv;
16
Paul Bollecc502bb2012-06-03 18:39:13 +020017#include "mod.h"
18#include "pipe.h"
Kuninori Morimotof1407d52011-04-04 13:44:59 +090019
20/*
21 *
22 * register define
23 *
24 */
25#define SYSCFG 0x0000
26#define BUSWAIT 0x0002
27#define DVSTCTR 0x0008
Kuninori Morimotodfbb7f42011-11-24 17:28:35 -080028#define TESTMODE 0x000C
Kuninori Morimotof1407d52011-04-04 13:44:59 +090029#define CFIFO 0x0014
30#define CFIFOSEL 0x0020
31#define CFIFOCTR 0x0022
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090032#define D0FIFO 0x0100
33#define D0FIFOSEL 0x0028
34#define D0FIFOCTR 0x002A
35#define D1FIFO 0x0120
36#define D1FIFOSEL 0x002C
37#define D1FIFOCTR 0x002E
Kuninori Morimotof1407d52011-04-04 13:44:59 +090038#define INTENB0 0x0030
39#define INTENB1 0x0032
40#define BRDYENB 0x0036
41#define NRDYENB 0x0038
42#define BEMPENB 0x003A
43#define INTSTS0 0x0040
44#define INTSTS1 0x0042
45#define BRDYSTS 0x0046
46#define NRDYSTS 0x0048
47#define BEMPSTS 0x004A
48#define FRMNUM 0x004C
49#define USBREQ 0x0054 /* USB request type register */
50#define USBVAL 0x0056 /* USB request value register */
51#define USBINDX 0x0058 /* USB request index register */
52#define USBLENG 0x005A /* USB request length register */
53#define DCPCFG 0x005C
54#define DCPMAXP 0x005E
55#define DCPCTR 0x0060
56#define PIPESEL 0x0064
57#define PIPECFG 0x0068
58#define PIPEBUF 0x006A
59#define PIPEMAXP 0x006C
60#define PIPEPERI 0x006E
61#define PIPEnCTR 0x0070
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090062#define PIPE1TRE 0x0090
63#define PIPE1TRN 0x0092
64#define PIPE2TRE 0x0094
65#define PIPE2TRN 0x0096
66#define PIPE3TRE 0x0098
67#define PIPE3TRN 0x009A
68#define PIPE4TRE 0x009C
69#define PIPE4TRN 0x009E
70#define PIPE5TRE 0x00A0
71#define PIPE5TRN 0x00A2
72#define PIPEBTRE 0x00A4
73#define PIPEBTRN 0x00A6
74#define PIPECTRE 0x00A8
75#define PIPECTRN 0x00AA
76#define PIPEDTRE 0x00AC
77#define PIPEDTRN 0x00AE
78#define PIPEETRE 0x00B0
79#define PIPEETRN 0x00B2
80#define PIPEFTRE 0x00B4
81#define PIPEFTRN 0x00B6
82#define PIPE9TRE 0x00B8
83#define PIPE9TRN 0x00BA
84#define PIPEATRE 0x00BC
85#define PIPEATRN 0x00BE
Kuninori Morimotoeb051912011-10-10 22:06:46 -070086#define DEVADD0 0x00D0 /* Device address n configuration */
87#define DEVADD1 0x00D2
88#define DEVADD2 0x00D4
89#define DEVADD3 0x00D6
90#define DEVADD4 0x00D8
91#define DEVADD5 0x00DA
92#define DEVADD6 0x00DC
93#define DEVADD7 0x00DE
94#define DEVADD8 0x00E0
95#define DEVADD9 0x00E2
96#define DEVADDA 0x00E4
Yoshihiro Shimodad3cf6a42014-11-10 20:02:47 +090097#define D2FIFOSEL 0x00F0 /* for R-Car Gen2 */
98#define D2FIFOCTR 0x00F2 /* for R-Car Gen2 */
99#define D3FIFOSEL 0x00F4 /* for R-Car Gen2 */
100#define D3FIFOCTR 0x00F6 /* for R-Car Gen2 */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900101
102/* SYSCFG */
103#define SCKE (1 << 10) /* USB Module Clock Enable */
104#define HSE (1 << 7) /* High-Speed Operation Enable */
105#define DCFM (1 << 6) /* Controller Function Select */
106#define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */
107#define DPRPU (1 << 4) /* D+ Line Resistance Control */
108#define USBE (1 << 0) /* USB Module Operation Enable */
109
110/* DVSTCTR */
111#define EXTLP (1 << 10) /* Controls the EXTLP pin output state */
112#define PWEN (1 << 9) /* Controls the PWEN pin output state */
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700113#define USBRST (1 << 6) /* Bus Reset Output */
114#define UACT (1 << 4) /* USB Bus Enable */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900115#define RHST (0x7) /* Reset Handshake */
116#define RHST_LOW_SPEED 1 /* Low-speed connection */
117#define RHST_FULL_SPEED 2 /* Full-speed connection */
118#define RHST_HIGH_SPEED 3 /* High-speed connection */
119
120/* CFIFOSEL */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900121#define DREQE (1 << 12) /* DMA Transfer Request Enable */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900122#define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
123
124/* CFIFOCTR */
125#define BVAL (1 << 15) /* Buffer Memory Enable Flag */
126#define BCLR (1 << 14) /* CPU buffer clear */
127#define FRDY (1 << 13) /* FIFO Port Ready */
128#define DTLN_MASK (0x0FFF) /* Receive Data Length */
129
130/* INTENB0 */
131#define VBSE (1 << 15) /* Enable IRQ VBUS_0 and VBUSIN_0 */
132#define RSME (1 << 14) /* Enable IRQ Resume */
133#define SOFE (1 << 13) /* Enable IRQ Frame Number Update */
134#define DVSE (1 << 12) /* Enable IRQ Device State Transition */
135#define CTRE (1 << 11) /* Enable IRQ Control Stage Transition */
136#define BEMPE (1 << 10) /* Enable IRQ Buffer Empty */
137#define NRDYE (1 << 9) /* Enable IRQ Buffer Not Ready Response */
138#define BRDYE (1 << 8) /* Enable IRQ Buffer Ready */
139
140/* INTENB1 */
141#define BCHGE (1 << 14) /* USB Bus Change Interrupt Enable */
142#define DTCHE (1 << 12) /* Disconnection Detect Interrupt Enable */
143#define ATTCHE (1 << 11) /* Connection Detect Interrupt Enable */
144#define EOFERRE (1 << 6) /* EOF Error Detect Interrupt Enable */
145#define SIGNE (1 << 5) /* Setup Transaction Error Interrupt Enable */
146#define SACKE (1 << 4) /* Setup Transaction ACK Interrupt Enable */
147
148/* INTSTS0 */
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900149#define VBINT (1 << 15) /* VBUS0_0 and VBUS1_0 Interrupt Status */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900150#define DVST (1 << 12) /* Device State Transition Interrupt Status */
151#define CTRT (1 << 11) /* Control Stage Interrupt Status */
152#define BEMP (1 << 10) /* Buffer Empty Interrupt Status */
153#define BRDY (1 << 8) /* Buffer Ready Interrupt Status */
154#define VBSTS (1 << 7) /* VBUS_0 and VBUSIN_0 Input Status */
155#define VALID (1 << 3) /* USB Request Receive */
156
157#define DVSQ_MASK (0x3 << 4) /* Device State */
158#define POWER_STATE (0 << 4)
159#define DEFAULT_STATE (1 << 4)
160#define ADDRESS_STATE (2 << 4)
161#define CONFIGURATION_STATE (3 << 4)
162
163#define CTSQ_MASK (0x7) /* Control Transfer Stage */
164#define IDLE_SETUP_STAGE 0 /* Idle stage or setup stage */
165#define READ_DATA_STAGE 1 /* Control read data stage */
166#define READ_STATUS_STAGE 2 /* Control read status stage */
167#define WRITE_DATA_STAGE 3 /* Control write data stage */
168#define WRITE_STATUS_STAGE 4 /* Control write status stage */
169#define NODATA_STATUS_STAGE 5 /* Control write NoData status stage */
170#define SEQUENCE_ERROR 6 /* Control transfer sequence error */
171
Kuninori Morimoto89c1d2e2011-10-10 22:06:57 -0700172/* INTSTS1 */
173#define OVRCR (1 << 15) /* OVRCR Interrupt Status */
174#define BCHG (1 << 14) /* USB Bus Change Interrupt Status */
175#define DTCH (1 << 12) /* USB Disconnection Detect Interrupt Status */
176#define ATTCH (1 << 11) /* ATTCH Interrupt Status */
177#define EOFERR (1 << 6) /* EOF Error Detect Interrupt Status */
178#define SIGN (1 << 5) /* Setup Transaction Error Interrupt Status */
179#define SACK (1 << 4) /* Setup Transaction ACK Response Interrupt Status */
180
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900181/* PIPECFG */
182/* DCPCFG */
183#define TYPE_NONE (0 << 14) /* Transfer Type */
184#define TYPE_BULK (1 << 14)
185#define TYPE_INT (2 << 14)
186#define TYPE_ISO (3 << 14)
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +0900187#define BFRE (1 << 10) /* BRDY Interrupt Operation Spec. */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900188#define DBLB (1 << 9) /* Double Buffer Mode */
189#define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */
190#define DIR_OUT (1 << 4) /* Transfer Direction */
191
192/* PIPEMAXP */
193/* DCPMAXP */
194#define DEVSEL_MASK (0xF << 12) /* Device Select */
195#define DCP_MAXP_MASK (0x7F)
196#define PIPE_MAXP_MASK (0x7FF)
197
198/* PIPEBUF */
199#define BUFSIZE_SHIFT 10
200#define BUFSIZE_MASK (0x1F << BUFSIZE_SHIFT)
201#define BUFNMB_MASK (0xFF)
202
203/* PIPEnCTR */
204/* DCPCTR */
205#define BSTS (1 << 15) /* Buffer Status */
Kuninori Morimotoef8bedb2011-10-10 22:02:33 -0700206#define SUREQ (1 << 14) /* Sending SETUP Token */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900207#define CSSTS (1 << 12) /* CSSTS Status */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900208#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
Kuninori Morimoto6e6db822011-10-10 22:05:30 -0700209#define SQCLR (1 << 8) /* Toggle Bit Clear */
210#define SQSET (1 << 7) /* Toggle Bit Set */
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +0900211#define SQMON (1 << 6) /* Toggle Bit Check */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900212#define PBUSY (1 << 5) /* Pipe Busy */
213#define PID_MASK (0x3) /* Response PID */
214#define PID_NAK 0
215#define PID_BUF 1
216#define PID_STALL10 2
217#define PID_STALL11 3
218
219#define CCPL (1 << 2) /* Control Transfer End Enable */
220
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900221/* PIPEnTRE */
222#define TRENB (1 << 9) /* Transaction Counter Enable */
223#define TRCLR (1 << 8) /* Transaction Counter Clear */
224
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900225/* FRMNUM */
226#define FRNM_MASK (0x7FF)
227
Kuninori Morimotoeb051912011-10-10 22:06:46 -0700228/* DEVADDn */
229#define UPPHUB(x) (((x) & 0xF) << 11) /* HUB Register */
230#define HUBPORT(x) (((x) & 0x7) << 8) /* HUB Port for Target Device */
231#define USBSPD(x) (((x) & 0x3) << 6) /* Device Transfer Rate */
232#define USBSPD_SPEED_LOW 0x1
233#define USBSPD_SPEED_FULL 0x2
234#define USBSPD_SPEED_HIGH 0x3
235
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900236/*
237 * struct
238 */
239struct usbhs_priv {
240
241 void __iomem *base;
242 unsigned int irq;
Shimoda, Yoshihiro53069af2012-01-05 15:37:18 +0900243 unsigned long irqflags;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900244
Kuninori Morimoto48298202011-10-12 21:02:22 -0700245 struct renesas_usbhs_platform_callback pfunc;
246 struct renesas_usbhs_driver_param dparam;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900247
Kuninori Morimotobc573812011-04-28 16:41:14 +0900248 struct delayed_work notify_hotplug_work;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900249 struct platform_device *pdev;
250
Sergei Shtylyovd7b39682014-12-16 01:42:13 +0300251 struct extcon_dev *edev;
252
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900253 spinlock_t lock;
254
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900255 u32 flags;
256
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900257 /*
258 * module control
259 */
260 struct usbhs_mod_info mod_info;
261
262 /*
263 * pipe control
264 */
265 struct usbhs_pipe_info pipe_info;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900266
267 /*
268 * fifo control
269 */
270 struct usbhs_fifo_info fifo_info;
Ulrich Hecht8ecef002014-07-10 09:53:59 +0200271
Yoshihiro Shimodac042b852014-10-07 12:43:04 +0900272 struct usb_phy *usb_phy;
Yoshihiro Shimoda420974a2014-10-07 12:43:06 +0900273 struct phy *phy;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900274};
275
276/*
277 * common
278 */
279u16 usbhs_read(struct usbhs_priv *priv, u32 reg);
280void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
281void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
282
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900283#define usbhs_lock(p, f) spin_lock_irqsave(usbhs_priv_to_lock(p), f)
284#define usbhs_unlock(p, f) spin_unlock_irqrestore(usbhs_priv_to_lock(p), f)
285
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900286/*
287 * sysconfig
288 */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900289void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable);
290void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable);
kuninori.morimoto.gx@renesas.com4cd2f592012-10-15 23:24:19 -0700291void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable);
Kuninori Morimotodfbb7f42011-11-24 17:28:35 -0800292void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900293
294/*
Kuninori Morimotoef8bedb2011-10-10 22:02:33 -0700295 * usb request
296 */
297void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
298void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
299
300/*
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700301 * bus
302 */
303void usbhs_bus_send_sof_enable(struct usbhs_priv *priv);
304void usbhs_bus_send_reset(struct usbhs_priv *priv);
Kuninori Morimoto75587f52011-10-10 22:01:51 -0700305int usbhs_bus_get_speed(struct usbhs_priv *priv);
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700306int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable);
307
308/*
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900309 * frame
310 */
311int usbhs_frame_get_num(struct usbhs_priv *priv);
312
313/*
Kuninori Morimotoeb051912011-10-10 22:06:46 -0700314 * device config
315 */
Kuninori Morimoto3dd49262011-10-31 00:47:13 -0700316int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, u16 upphub,
Kuninori Morimotoeb051912011-10-10 22:06:46 -0700317 u16 hubport, u16 speed);
318
319/*
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +0900320 * interrupt functions
321 */
322void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit);
323
324/*
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900325 * data
326 */
Kuninori Morimoto206dcc22011-04-28 16:40:54 +0900327struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev);
Kuninori Morimoto48298202011-10-12 21:02:22 -0700328#define usbhs_get_dparam(priv, param) (priv->dparam.param)
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900329#define usbhs_priv_to_pdev(priv) (priv->pdev)
330#define usbhs_priv_to_dev(priv) (&priv->pdev->dev)
331#define usbhs_priv_to_lock(priv) (&priv->lock)
332
333#endif /* RENESAS_USB_DRIVER_H */