common.h 9.6 KB

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