common.h 10 KB

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