common.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. #include <linux/extcon.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/usb/renesas_usbhs.h>
  22. struct usbhs_priv;
  23. #include "mod.h"
  24. #include "pipe.h"
  25. /*
  26. *
  27. * register define
  28. *
  29. */
  30. #define SYSCFG 0x0000
  31. #define BUSWAIT 0x0002
  32. #define DVSTCTR 0x0008
  33. #define TESTMODE 0x000C
  34. #define CFIFO 0x0014
  35. #define CFIFOSEL 0x0020
  36. #define CFIFOCTR 0x0022
  37. #define D0FIFO 0x0100
  38. #define D0FIFOSEL 0x0028
  39. #define D0FIFOCTR 0x002A
  40. #define D1FIFO 0x0120
  41. #define D1FIFOSEL 0x002C
  42. #define D1FIFOCTR 0x002E
  43. #define INTENB0 0x0030
  44. #define INTENB1 0x0032
  45. #define BRDYENB 0x0036
  46. #define NRDYENB 0x0038
  47. #define BEMPENB 0x003A
  48. #define INTSTS0 0x0040
  49. #define INTSTS1 0x0042
  50. #define BRDYSTS 0x0046
  51. #define NRDYSTS 0x0048
  52. #define BEMPSTS 0x004A
  53. #define FRMNUM 0x004C
  54. #define USBREQ 0x0054 /* USB request type register */
  55. #define USBVAL 0x0056 /* USB request value register */
  56. #define USBINDX 0x0058 /* USB request index register */
  57. #define USBLENG 0x005A /* USB request length register */
  58. #define DCPCFG 0x005C
  59. #define DCPMAXP 0x005E
  60. #define DCPCTR 0x0060
  61. #define PIPESEL 0x0064
  62. #define PIPECFG 0x0068
  63. #define PIPEBUF 0x006A
  64. #define PIPEMAXP 0x006C
  65. #define PIPEPERI 0x006E
  66. #define PIPEnCTR 0x0070
  67. #define PIPE1TRE 0x0090
  68. #define PIPE1TRN 0x0092
  69. #define PIPE2TRE 0x0094
  70. #define PIPE2TRN 0x0096
  71. #define PIPE3TRE 0x0098
  72. #define PIPE3TRN 0x009A
  73. #define PIPE4TRE 0x009C
  74. #define PIPE4TRN 0x009E
  75. #define PIPE5TRE 0x00A0
  76. #define PIPE5TRN 0x00A2
  77. #define PIPEBTRE 0x00A4
  78. #define PIPEBTRN 0x00A6
  79. #define PIPECTRE 0x00A8
  80. #define PIPECTRN 0x00AA
  81. #define PIPEDTRE 0x00AC
  82. #define PIPEDTRN 0x00AE
  83. #define PIPEETRE 0x00B0
  84. #define PIPEETRN 0x00B2
  85. #define PIPEFTRE 0x00B4
  86. #define PIPEFTRN 0x00B6
  87. #define PIPE9TRE 0x00B8
  88. #define PIPE9TRN 0x00BA
  89. #define PIPEATRE 0x00BC
  90. #define PIPEATRN 0x00BE
  91. #define DEVADD0 0x00D0 /* Device address n configuration */
  92. #define DEVADD1 0x00D2
  93. #define DEVADD2 0x00D4
  94. #define DEVADD3 0x00D6
  95. #define DEVADD4 0x00D8
  96. #define DEVADD5 0x00DA
  97. #define DEVADD6 0x00DC
  98. #define DEVADD7 0x00DE
  99. #define DEVADD8 0x00E0
  100. #define DEVADD9 0x00E2
  101. #define DEVADDA 0x00E4
  102. #define D2FIFOSEL 0x00F0 /* for R-Car Gen2 */
  103. #define D2FIFOCTR 0x00F2 /* for R-Car Gen2 */
  104. #define D3FIFOSEL 0x00F4 /* for R-Car Gen2 */
  105. #define D3FIFOCTR 0x00F6 /* for R-Car Gen2 */
  106. /* SYSCFG */
  107. #define SCKE (1 << 10) /* USB Module Clock Enable */
  108. #define HSE (1 << 7) /* High-Speed Operation Enable */
  109. #define DCFM (1 << 6) /* Controller Function Select */
  110. #define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */
  111. #define DPRPU (1 << 4) /* D+ Line Resistance Control */
  112. #define USBE (1 << 0) /* USB Module Operation Enable */
  113. /* DVSTCTR */
  114. #define EXTLP (1 << 10) /* Controls the EXTLP pin output state */
  115. #define PWEN (1 << 9) /* Controls the PWEN pin output state */
  116. #define USBRST (1 << 6) /* Bus Reset Output */
  117. #define UACT (1 << 4) /* USB Bus Enable */
  118. #define RHST (0x7) /* Reset Handshake */
  119. #define RHST_LOW_SPEED 1 /* Low-speed connection */
  120. #define RHST_FULL_SPEED 2 /* Full-speed connection */
  121. #define RHST_HIGH_SPEED 3 /* High-speed connection */
  122. /* CFIFOSEL */
  123. #define DREQE (1 << 12) /* DMA Transfer Request Enable */
  124. #define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
  125. /* CFIFOCTR */
  126. #define BVAL (1 << 15) /* Buffer Memory Enable Flag */
  127. #define BCLR (1 << 14) /* CPU buffer clear */
  128. #define FRDY (1 << 13) /* FIFO Port Ready */
  129. #define DTLN_MASK (0x0FFF) /* Receive Data Length */
  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. /* INTENB1 */
  140. #define BCHGE (1 << 14) /* USB Bus Change Interrupt Enable */
  141. #define DTCHE (1 << 12) /* Disconnection Detect Interrupt Enable */
  142. #define ATTCHE (1 << 11) /* Connection Detect Interrupt Enable */
  143. #define EOFERRE (1 << 6) /* EOF Error Detect Interrupt Enable */
  144. #define SIGNE (1 << 5) /* Setup Transaction Error Interrupt Enable */
  145. #define SACKE (1 << 4) /* Setup Transaction ACK Interrupt Enable */
  146. /* INTSTS0 */
  147. #define VBINT (1 << 15) /* VBUS0_0 and VBUS1_0 Interrupt Status */
  148. #define DVST (1 << 12) /* Device State Transition Interrupt Status */
  149. #define CTRT (1 << 11) /* Control Stage Interrupt Status */
  150. #define BEMP (1 << 10) /* Buffer Empty Interrupt Status */
  151. #define BRDY (1 << 8) /* Buffer Ready Interrupt Status */
  152. #define VBSTS (1 << 7) /* VBUS_0 and VBUSIN_0 Input Status */
  153. #define VALID (1 << 3) /* USB Request Receive */
  154. #define DVSQ_MASK (0x3 << 4) /* Device State */
  155. #define POWER_STATE (0 << 4)
  156. #define DEFAULT_STATE (1 << 4)
  157. #define ADDRESS_STATE (2 << 4)
  158. #define CONFIGURATION_STATE (3 << 4)
  159. #define CTSQ_MASK (0x7) /* Control Transfer Stage */
  160. #define IDLE_SETUP_STAGE 0 /* Idle stage or setup stage */
  161. #define READ_DATA_STAGE 1 /* Control read data stage */
  162. #define READ_STATUS_STAGE 2 /* Control read status stage */
  163. #define WRITE_DATA_STAGE 3 /* Control write data stage */
  164. #define WRITE_STATUS_STAGE 4 /* Control write status stage */
  165. #define NODATA_STATUS_STAGE 5 /* Control write NoData status stage */
  166. #define SEQUENCE_ERROR 6 /* Control transfer sequence error */
  167. /* INTSTS1 */
  168. #define OVRCR (1 << 15) /* OVRCR Interrupt Status */
  169. #define BCHG (1 << 14) /* USB Bus Change Interrupt Status */
  170. #define DTCH (1 << 12) /* USB Disconnection Detect Interrupt Status */
  171. #define ATTCH (1 << 11) /* ATTCH Interrupt Status */
  172. #define EOFERR (1 << 6) /* EOF Error Detect Interrupt Status */
  173. #define SIGN (1 << 5) /* Setup Transaction Error Interrupt Status */
  174. #define SACK (1 << 4) /* Setup Transaction ACK Response Interrupt Status */
  175. /* PIPECFG */
  176. /* DCPCFG */
  177. #define TYPE_NONE (0 << 14) /* Transfer Type */
  178. #define TYPE_BULK (1 << 14)
  179. #define TYPE_INT (2 << 14)
  180. #define TYPE_ISO (3 << 14)
  181. #define BFRE (1 << 10) /* BRDY Interrupt Operation Spec. */
  182. #define DBLB (1 << 9) /* Double Buffer Mode */
  183. #define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */
  184. #define DIR_OUT (1 << 4) /* Transfer Direction */
  185. /* PIPEMAXP */
  186. /* DCPMAXP */
  187. #define DEVSEL_MASK (0xF << 12) /* Device Select */
  188. #define DCP_MAXP_MASK (0x7F)
  189. #define PIPE_MAXP_MASK (0x7FF)
  190. /* PIPEBUF */
  191. #define BUFSIZE_SHIFT 10
  192. #define BUFSIZE_MASK (0x1F << BUFSIZE_SHIFT)
  193. #define BUFNMB_MASK (0xFF)
  194. /* PIPEnCTR */
  195. /* DCPCTR */
  196. #define BSTS (1 << 15) /* Buffer Status */
  197. #define SUREQ (1 << 14) /* Sending SETUP Token */
  198. #define CSSTS (1 << 12) /* CSSTS Status */
  199. #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
  200. #define SQCLR (1 << 8) /* Toggle Bit Clear */
  201. #define SQSET (1 << 7) /* Toggle Bit Set */
  202. #define SQMON (1 << 6) /* Toggle Bit Check */
  203. #define PBUSY (1 << 5) /* Pipe Busy */
  204. #define PID_MASK (0x3) /* Response PID */
  205. #define PID_NAK 0
  206. #define PID_BUF 1
  207. #define PID_STALL10 2
  208. #define PID_STALL11 3
  209. #define CCPL (1 << 2) /* Control Transfer End Enable */
  210. /* PIPEnTRE */
  211. #define TRENB (1 << 9) /* Transaction Counter Enable */
  212. #define TRCLR (1 << 8) /* Transaction Counter Clear */
  213. /* FRMNUM */
  214. #define FRNM_MASK (0x7FF)
  215. /* DEVADDn */
  216. #define UPPHUB(x) (((x) & 0xF) << 11) /* HUB Register */
  217. #define HUBPORT(x) (((x) & 0x7) << 8) /* HUB Port for Target Device */
  218. #define USBSPD(x) (((x) & 0x3) << 6) /* Device Transfer Rate */
  219. #define USBSPD_SPEED_LOW 0x1
  220. #define USBSPD_SPEED_FULL 0x2
  221. #define USBSPD_SPEED_HIGH 0x3
  222. /*
  223. * struct
  224. */
  225. struct usbhs_priv {
  226. void __iomem *base;
  227. unsigned int irq;
  228. unsigned long irqflags;
  229. struct renesas_usbhs_platform_callback pfunc;
  230. struct renesas_usbhs_driver_param dparam;
  231. struct delayed_work notify_hotplug_work;
  232. struct platform_device *pdev;
  233. struct extcon_dev *edev;
  234. spinlock_t lock;
  235. u32 flags;
  236. /*
  237. * module control
  238. */
  239. struct usbhs_mod_info mod_info;
  240. /*
  241. * pipe control
  242. */
  243. struct usbhs_pipe_info pipe_info;
  244. /*
  245. * fifo control
  246. */
  247. struct usbhs_fifo_info fifo_info;
  248. struct usb_phy *usb_phy;
  249. struct phy *phy;
  250. };
  251. /*
  252. * common
  253. */
  254. u16 usbhs_read(struct usbhs_priv *priv, u32 reg);
  255. void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
  256. void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
  257. #define usbhs_lock(p, f) spin_lock_irqsave(usbhs_priv_to_lock(p), f)
  258. #define usbhs_unlock(p, f) spin_unlock_irqrestore(usbhs_priv_to_lock(p), f)
  259. /*
  260. * sysconfig
  261. */
  262. void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable);
  263. void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable);
  264. void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable);
  265. void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode);
  266. /*
  267. * usb request
  268. */
  269. void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
  270. void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
  271. /*
  272. * bus
  273. */
  274. void usbhs_bus_send_sof_enable(struct usbhs_priv *priv);
  275. void usbhs_bus_send_reset(struct usbhs_priv *priv);
  276. int usbhs_bus_get_speed(struct usbhs_priv *priv);
  277. int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable);
  278. /*
  279. * frame
  280. */
  281. int usbhs_frame_get_num(struct usbhs_priv *priv);
  282. /*
  283. * device config
  284. */
  285. int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, u16 upphub,
  286. u16 hubport, u16 speed);
  287. /*
  288. * interrupt functions
  289. */
  290. void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit);
  291. /*
  292. * data
  293. */
  294. struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev);
  295. #define usbhs_get_dparam(priv, param) (priv->dparam.param)
  296. #define usbhs_priv_to_pdev(priv) (priv->pdev)
  297. #define usbhs_priv_to_dev(priv) (&priv->pdev->dev)
  298. #define usbhs_priv_to_lock(priv) (&priv->lock)
  299. #endif /* RENESAS_USB_DRIVER_H */