common.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 CFIFO 0x0014
  33. #define CFIFOSEL 0x0020
  34. #define CFIFOCTR 0x0022
  35. #define INTENB0 0x0030
  36. #define INTENB1 0x0032
  37. #define BRDYENB 0x0036
  38. #define NRDYENB 0x0038
  39. #define BEMPENB 0x003A
  40. #define INTSTS0 0x0040
  41. #define INTSTS1 0x0042
  42. #define BRDYSTS 0x0046
  43. #define NRDYSTS 0x0048
  44. #define BEMPSTS 0x004A
  45. #define FRMNUM 0x004C
  46. #define USBREQ 0x0054 /* USB request type register */
  47. #define USBVAL 0x0056 /* USB request value register */
  48. #define USBINDX 0x0058 /* USB request index register */
  49. #define USBLENG 0x005A /* USB request length register */
  50. #define DCPCFG 0x005C
  51. #define DCPMAXP 0x005E
  52. #define DCPCTR 0x0060
  53. #define PIPESEL 0x0064
  54. #define PIPECFG 0x0068
  55. #define PIPEBUF 0x006A
  56. #define PIPEMAXP 0x006C
  57. #define PIPEPERI 0x006E
  58. #define PIPEnCTR 0x0070
  59. /* SYSCFG */
  60. #define SCKE (1 << 10) /* USB Module Clock Enable */
  61. #define HSE (1 << 7) /* High-Speed Operation Enable */
  62. #define DCFM (1 << 6) /* Controller Function Select */
  63. #define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */
  64. #define DPRPU (1 << 4) /* D+ Line Resistance Control */
  65. #define USBE (1 << 0) /* USB Module Operation Enable */
  66. /* DVSTCTR */
  67. #define EXTLP (1 << 10) /* Controls the EXTLP pin output state */
  68. #define PWEN (1 << 9) /* Controls the PWEN pin output state */
  69. #define RHST (0x7) /* Reset Handshake */
  70. #define RHST_LOW_SPEED 1 /* Low-speed connection */
  71. #define RHST_FULL_SPEED 2 /* Full-speed connection */
  72. #define RHST_HIGH_SPEED 3 /* High-speed connection */
  73. /* CFIFOSEL */
  74. #define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
  75. /* CFIFOCTR */
  76. #define BVAL (1 << 15) /* Buffer Memory Enable Flag */
  77. #define BCLR (1 << 14) /* CPU buffer clear */
  78. #define FRDY (1 << 13) /* FIFO Port Ready */
  79. #define DTLN_MASK (0x0FFF) /* Receive Data Length */
  80. /* INTENB0 */
  81. #define VBSE (1 << 15) /* Enable IRQ VBUS_0 and VBUSIN_0 */
  82. #define RSME (1 << 14) /* Enable IRQ Resume */
  83. #define SOFE (1 << 13) /* Enable IRQ Frame Number Update */
  84. #define DVSE (1 << 12) /* Enable IRQ Device State Transition */
  85. #define CTRE (1 << 11) /* Enable IRQ Control Stage Transition */
  86. #define BEMPE (1 << 10) /* Enable IRQ Buffer Empty */
  87. #define NRDYE (1 << 9) /* Enable IRQ Buffer Not Ready Response */
  88. #define BRDYE (1 << 8) /* Enable IRQ Buffer Ready */
  89. /* INTENB1 */
  90. #define BCHGE (1 << 14) /* USB Bus Change Interrupt Enable */
  91. #define DTCHE (1 << 12) /* Disconnection Detect Interrupt Enable */
  92. #define ATTCHE (1 << 11) /* Connection Detect Interrupt Enable */
  93. #define EOFERRE (1 << 6) /* EOF Error Detect Interrupt Enable */
  94. #define SIGNE (1 << 5) /* Setup Transaction Error Interrupt Enable */
  95. #define SACKE (1 << 4) /* Setup Transaction ACK Interrupt Enable */
  96. /* INTSTS0 */
  97. #define VBINT (1 << 15) /* VBUS0_0 and VBUS1_0 Interrupt Status */
  98. #define DVST (1 << 12) /* Device State Transition Interrupt Status */
  99. #define CTRT (1 << 11) /* Control Stage Interrupt Status */
  100. #define BEMP (1 << 10) /* Buffer Empty Interrupt Status */
  101. #define BRDY (1 << 8) /* Buffer Ready Interrupt Status */
  102. #define VBSTS (1 << 7) /* VBUS_0 and VBUSIN_0 Input Status */
  103. #define VALID (1 << 3) /* USB Request Receive */
  104. #define DVSQ_MASK (0x3 << 4) /* Device State */
  105. #define POWER_STATE (0 << 4)
  106. #define DEFAULT_STATE (1 << 4)
  107. #define ADDRESS_STATE (2 << 4)
  108. #define CONFIGURATION_STATE (3 << 4)
  109. #define CTSQ_MASK (0x7) /* Control Transfer Stage */
  110. #define IDLE_SETUP_STAGE 0 /* Idle stage or setup stage */
  111. #define READ_DATA_STAGE 1 /* Control read data stage */
  112. #define READ_STATUS_STAGE 2 /* Control read status stage */
  113. #define WRITE_DATA_STAGE 3 /* Control write data stage */
  114. #define WRITE_STATUS_STAGE 4 /* Control write status stage */
  115. #define NODATA_STATUS_STAGE 5 /* Control write NoData status stage */
  116. #define SEQUENCE_ERROR 6 /* Control transfer sequence error */
  117. /* PIPECFG */
  118. /* DCPCFG */
  119. #define TYPE_NONE (0 << 14) /* Transfer Type */
  120. #define TYPE_BULK (1 << 14)
  121. #define TYPE_INT (2 << 14)
  122. #define TYPE_ISO (3 << 14)
  123. #define DBLB (1 << 9) /* Double Buffer Mode */
  124. #define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */
  125. #define DIR_OUT (1 << 4) /* Transfer Direction */
  126. /* PIPEMAXP */
  127. /* DCPMAXP */
  128. #define DEVSEL_MASK (0xF << 12) /* Device Select */
  129. #define DCP_MAXP_MASK (0x7F)
  130. #define PIPE_MAXP_MASK (0x7FF)
  131. /* PIPEBUF */
  132. #define BUFSIZE_SHIFT 10
  133. #define BUFSIZE_MASK (0x1F << BUFSIZE_SHIFT)
  134. #define BUFNMB_MASK (0xFF)
  135. /* PIPEnCTR */
  136. /* DCPCTR */
  137. #define BSTS (1 << 15) /* Buffer Status */
  138. #define CSSTS (1 << 12) /* CSSTS Status */
  139. #define SQCLR (1 << 8) /* Toggle Bit Clear */
  140. #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
  141. #define PBUSY (1 << 5) /* Pipe Busy */
  142. #define PID_MASK (0x3) /* Response PID */
  143. #define PID_NAK 0
  144. #define PID_BUF 1
  145. #define PID_STALL10 2
  146. #define PID_STALL11 3
  147. #define CCPL (1 << 2) /* Control Transfer End Enable */
  148. /* FRMNUM */
  149. #define FRNM_MASK (0x7FF)
  150. /*
  151. * struct
  152. */
  153. struct usbhs_priv {
  154. void __iomem *base;
  155. unsigned int irq;
  156. struct renesas_usbhs_platform_callback *pfunc;
  157. struct renesas_usbhs_driver_param *dparam;
  158. struct delayed_work notify_hotplug_work;
  159. struct platform_device *pdev;
  160. spinlock_t lock;
  161. u32 flags;
  162. /*
  163. * module control
  164. */
  165. struct usbhs_mod_info mod_info;
  166. /*
  167. * pipe control
  168. */
  169. struct usbhs_pipe_info pipe_info;
  170. };
  171. /*
  172. * common
  173. */
  174. u16 usbhs_read(struct usbhs_priv *priv, u32 reg);
  175. void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
  176. void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
  177. int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev);
  178. /*
  179. * sysconfig
  180. */
  181. void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable);
  182. void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable);
  183. void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable);
  184. void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable);
  185. void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable);
  186. /*
  187. * frame
  188. */
  189. int usbhs_frame_get_num(struct usbhs_priv *priv);
  190. /*
  191. * data
  192. */
  193. struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev);
  194. #define usbhs_get_dparam(priv, param) (priv->dparam->param)
  195. #define usbhs_priv_to_pdev(priv) (priv->pdev)
  196. #define usbhs_priv_to_dev(priv) (&priv->pdev->dev)
  197. #define usbhs_priv_to_lock(priv) (&priv->lock)
  198. #endif /* RENESAS_USB_DRIVER_H */