ulpi.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Generic ULPI interface.
  3. *
  4. * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
  5. * Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
  6. *
  7. * Authors: Jana Rapava <fermata7@gmail.com>
  8. * Igor Grinberg <grinberg@compulab.co.il>
  9. *
  10. * Register offsets taken from:
  11. * linux/include/linux/usb/ulpi.h
  12. *
  13. * Original Copyrights follow:
  14. * Copyright (C) 2010 Nokia Corporation
  15. *
  16. * This software is distributed under the terms of the GNU General
  17. * Public License ("GPL") as published by the Free Software Foundation,
  18. * version 2 of that License.
  19. */
  20. #ifndef __USB_ULPI_H__
  21. #define __USB_ULPI_H__
  22. #define ULPI_ERROR (1 << 8) /* overflow from any register value */
  23. #ifndef CONFIG_USB_ULPI_TIMEOUT
  24. #define CONFIG_USB_ULPI_TIMEOUT 1000 /* timeout in us */
  25. #endif
  26. /*
  27. * Initialize the ULPI transciever and check the interface integrity.
  28. * @ulpi_viewport - the address of the ULPI viewport register.
  29. *
  30. * returns 0 on success, ULPI_ERROR on failure.
  31. */
  32. int ulpi_init(u32 ulpi_viewport);
  33. /*
  34. * Select transceiver speed.
  35. * @speed - ULPI_FC_HIGH_SPEED, ULPI_FC_FULL_SPEED (default),
  36. * ULPI_FC_LOW_SPEED, ULPI_FC_FS4LS
  37. * returns 0 on success, ULPI_ERROR on failure.
  38. */
  39. int ulpi_select_transceiver(u32 ulpi_viewport, unsigned speed);
  40. /*
  41. * Enable/disable VBUS.
  42. * @ext_power - external VBUS supply is used (default is false)
  43. * @ext_indicator - external VBUS over-current indicator is used
  44. *
  45. * returns 0 on success, ULPI_ERROR on failure.
  46. */
  47. int ulpi_enable_vbus(u32 ulpi_viewport, int on, int ext_power, int ext_ind);
  48. /*
  49. * Enable/disable pull-down resistors on D+ and D- USB lines.
  50. *
  51. * returns 0 on success, ULPI_ERROR on failure.
  52. */
  53. int ulpi_set_pd(u32 ulpi_viewport, int enable);
  54. /*
  55. * Select OpMode.
  56. * @opmode - ULPI_FC_OPMODE_NORMAL (default), ULPI_FC_OPMODE_NONDRIVING,
  57. * ULPI_FC_OPMODE_DISABLE_NRZI, ULPI_FC_OPMODE_NOSYNC_NOEOP
  58. *
  59. * returns 0 on success, ULPI_ERROR on failure.
  60. */
  61. int ulpi_opmode_sel(u32 ulpi_viewport, unsigned opmode);
  62. /*
  63. * Switch to Serial Mode.
  64. * @smode - ULPI_IFACE_6_PIN_SERIAL_MODE or ULPI_IFACE_3_PIN_SERIAL_MODE
  65. *
  66. * returns 0 on success, ULPI_ERROR on failure.
  67. *
  68. * Notes:
  69. * Switches immediately to Serial Mode.
  70. * To return from Serial Mode, STP line needs to be asserted.
  71. */
  72. int ulpi_serial_mode_enable(u32 ulpi_viewport, unsigned smode);
  73. /*
  74. * Put PHY into low power mode.
  75. *
  76. * returns 0 on success, ULPI_ERROR on failure.
  77. *
  78. * Notes:
  79. * STP line must be driven low to keep the PHY in suspend.
  80. * To resume the PHY, STP line needs to be asserted.
  81. */
  82. int ulpi_suspend(u32 ulpi_viewport);
  83. /*
  84. * Reset the transceiver. ULPI interface and registers are not affected.
  85. *
  86. * returns 0 on success, ULPI_ERROR on failure.
  87. */
  88. int ulpi_reset(u32 ulpi_viewport);
  89. /* ULPI access methods below must be implemented for each ULPI viewport. */
  90. /*
  91. * Write to the ULPI PHY register via the viewport.
  92. * @reg - the ULPI register (one of the fields in struct ulpi_regs).
  93. * @value - the value - only 8 lower bits are used, others ignored.
  94. *
  95. * returns 0 on success, ULPI_ERROR on failure.
  96. */
  97. u32 ulpi_write(u32 ulpi_viewport, u8 *reg, u32 value);
  98. /*
  99. * Read the ULPI PHY register content via the viewport.
  100. * @reg - the ULPI register (one of the fields in struct ulpi_regs).
  101. *
  102. * returns register content on success, ULPI_ERROR on failure.
  103. */
  104. u32 ulpi_read(u32 ulpi_viewport, u8 *reg);
  105. /*
  106. * Wait for the reset to complete.
  107. * The Link must not attempt to access the PHY until the reset has
  108. * completed and DIR line is de-asserted.
  109. */
  110. int ulpi_reset_wait(u32 ulpi_viewport);
  111. /* Access Extended Register Set (indicator) */
  112. #define ACCESS_EXT_REGS_OFFSET 0x2f /* read-write */
  113. /* Vendor-specific */
  114. #define VENDOR_SPEC_OFFSET 0x30
  115. /*
  116. * Extended Register Set
  117. *
  118. * Addresses 0x00-0x3F map directly to Immediate Register Set.
  119. * Addresses 0x40-0x7F are reserved.
  120. * Addresses 0x80-0xff are vendor-specific.
  121. */
  122. #define EXT_VENDOR_SPEC_OFFSET 0x80
  123. /* ULPI registers, bits and offsets definitions */
  124. struct ulpi_regs {
  125. /* Vendor ID and Product ID: 0x00 - 0x03 Read-only */
  126. u8 vendor_id_low;
  127. u8 vendor_id_high;
  128. u8 product_id_low;
  129. u8 product_id_high;
  130. /* Function Control: 0x04 - 0x06 Read */
  131. u8 function_ctrl; /* 0x04 Write */
  132. u8 function_ctrl_set; /* 0x05 Set */
  133. u8 function_ctrl_clear; /* 0x06 Clear */
  134. /* Interface Control: 0x07 - 0x09 Read */
  135. u8 iface_ctrl; /* 0x07 Write */
  136. u8 iface_ctrl_set; /* 0x08 Set */
  137. u8 iface_ctrl_clear; /* 0x09 Clear */
  138. /* OTG Control: 0x0A - 0x0C Read */
  139. u8 otg_ctrl; /* 0x0A Write */
  140. u8 otg_ctrl_set; /* 0x0B Set */
  141. u8 otg_ctrl_clear; /* 0x0C Clear */
  142. /* USB Interrupt Enable Rising: 0x0D - 0x0F Read */
  143. u8 usb_ie_rising; /* 0x0D Write */
  144. u8 usb_ie_rising_set; /* 0x0E Set */
  145. u8 usb_ie_rising_clear; /* 0x0F Clear */
  146. /* USB Interrupt Enable Falling: 0x10 - 0x12 Read */
  147. u8 usb_ie_falling; /* 0x10 Write */
  148. u8 usb_ie_falling_set; /* 0x11 Set */
  149. u8 usb_ie_falling_clear; /* 0x12 Clear */
  150. /* USB Interrupt Status: 0x13 Read-only */
  151. u8 usb_int_status;
  152. /* USB Interrupt Latch: 0x14 Read-only with auto-clear */
  153. u8 usb_int_latch;
  154. /* Debug: 0x15 Read-only */
  155. u8 debug;
  156. /* Scratch Register: 0x16 - 0x18 Read */
  157. u8 scratch; /* 0x16 Write */
  158. u8 scratch_set; /* 0x17 Set */
  159. u8 scratch_clear; /* 0x18 Clear */
  160. /*
  161. * Optional Carkit registers:
  162. * Carkit Control: 0x19 - 0x1B Read
  163. */
  164. u8 carkit_ctrl; /* 0x19 Write */
  165. u8 carkit_ctrl_set; /* 0x1A Set */
  166. u8 carkit_ctrl_clear; /* 0x1B Clear */
  167. /* Carkit Interrupt Delay: 0x1C Read, Write */
  168. u8 carkit_int_delay;
  169. /* Carkit Interrupt Enable: 0x1D - 0x1F Read */
  170. u8 carkit_ie; /* 0x1D Write */
  171. u8 carkit_ie_set; /* 0x1E Set */
  172. u8 carkit_ie_clear; /* 0x1F Clear */
  173. /* Carkit Interrupt Status: 0x20 Read-only */
  174. u8 carkit_int_status;
  175. /* Carkit Interrupt Latch: 0x21 Read-only with auto-clear */
  176. u8 carkit_int_latch;
  177. /* Carkit Pulse Control: 0x22 - 0x24 Read */
  178. u8 carkit_pulse_ctrl; /* 0x22 Write */
  179. u8 carkit_pulse_ctrl_set; /* 0x23 Set */
  180. u8 carkit_pulse_ctrl_clear; /* 0x24 Clear */
  181. /*
  182. * Other optional registers:
  183. * Transmit Positive Width: 0x25 Read, Write
  184. */
  185. u8 transmit_pos_width;
  186. /* Transmit Negative Width: 0x26 Read, Write */
  187. u8 transmit_neg_width;
  188. /* Receive Polarity Recovery: 0x27 Read, Write */
  189. u8 recv_pol_recovery;
  190. /*
  191. * Addresses 0x28 - 0x2E are reserved, so we use offsets
  192. * for immediate registers with higher addresses
  193. */
  194. };
  195. /*
  196. * Register Bits
  197. */
  198. /* Function Control */
  199. #define ULPI_FC_XCVRSEL_MASK (3 << 0)
  200. #define ULPI_FC_HIGH_SPEED (0 << 0)
  201. #define ULPI_FC_FULL_SPEED (1 << 0)
  202. #define ULPI_FC_LOW_SPEED (2 << 0)
  203. #define ULPI_FC_FS4LS (3 << 0)
  204. #define ULPI_FC_TERMSELECT (1 << 2)
  205. #define ULPI_FC_OPMODE_MASK (3 << 3)
  206. #define ULPI_FC_OPMODE_NORMAL (0 << 3)
  207. #define ULPI_FC_OPMODE_NONDRIVING (1 << 3)
  208. #define ULPI_FC_OPMODE_DISABLE_NRZI (2 << 3)
  209. #define ULPI_FC_OPMODE_NOSYNC_NOEOP (3 << 3)
  210. #define ULPI_FC_RESET (1 << 5)
  211. #define ULPI_FC_SUSPENDM (1 << 6)
  212. /* Interface Control */
  213. #define ULPI_IFACE_6_PIN_SERIAL_MODE (1 << 0)
  214. #define ULPI_IFACE_3_PIN_SERIAL_MODE (1 << 1)
  215. #define ULPI_IFACE_CARKITMODE (1 << 2)
  216. #define ULPI_IFACE_CLOCKSUSPENDM (1 << 3)
  217. #define ULPI_IFACE_AUTORESUME (1 << 4)
  218. #define ULPI_IFACE_EXTVBUS_COMPLEMENT (1 << 5)
  219. #define ULPI_IFACE_PASSTHRU (1 << 6)
  220. #define ULPI_IFACE_PROTECT_IFC_DISABLE (1 << 7)
  221. /* OTG Control */
  222. #define ULPI_OTG_ID_PULLUP (1 << 0)
  223. #define ULPI_OTG_DP_PULLDOWN (1 << 1)
  224. #define ULPI_OTG_DM_PULLDOWN (1 << 2)
  225. #define ULPI_OTG_DISCHRGVBUS (1 << 3)
  226. #define ULPI_OTG_CHRGVBUS (1 << 4)
  227. #define ULPI_OTG_DRVVBUS (1 << 5)
  228. #define ULPI_OTG_DRVVBUS_EXT (1 << 6)
  229. #define ULPI_OTG_EXTVBUSIND (1 << 7)
  230. /*
  231. * USB Interrupt Enable Rising,
  232. * USB Interrupt Enable Falling,
  233. * USB Interrupt Status and
  234. * USB Interrupt Latch
  235. */
  236. #define ULPI_INT_HOST_DISCONNECT (1 << 0)
  237. #define ULPI_INT_VBUS_VALID (1 << 1)
  238. #define ULPI_INT_SESS_VALID (1 << 2)
  239. #define ULPI_INT_SESS_END (1 << 3)
  240. #define ULPI_INT_IDGRD (1 << 4)
  241. /* Debug */
  242. #define ULPI_DEBUG_LINESTATE0 (1 << 0)
  243. #define ULPI_DEBUG_LINESTATE1 (1 << 1)
  244. /* Carkit Control */
  245. #define ULPI_CARKIT_CTRL_CARKITPWR (1 << 0)
  246. #define ULPI_CARKIT_CTRL_IDGNDDRV (1 << 1)
  247. #define ULPI_CARKIT_CTRL_TXDEN (1 << 2)
  248. #define ULPI_CARKIT_CTRL_RXDEN (1 << 3)
  249. #define ULPI_CARKIT_CTRL_SPKLEFTEN (1 << 4)
  250. #define ULPI_CARKIT_CTRL_SPKRIGHTEN (1 << 5)
  251. #define ULPI_CARKIT_CTRL_MICEN (1 << 6)
  252. /* Carkit Interrupt Enable */
  253. #define ULPI_CARKIT_INT_EN_IDFLOAT_RISE (1 << 0)
  254. #define ULPI_CARKIT_INT_EN_IDFLOAT_FALL (1 << 1)
  255. #define ULPI_CARKIT_INT_EN_CARINTDET (1 << 2)
  256. #define ULPI_CARKIT_INT_EN_DP_RISE (1 << 3)
  257. #define ULPI_CARKIT_INT_EN_DP_FALL (1 << 4)
  258. /* Carkit Interrupt Status and Latch */
  259. #define ULPI_CARKIT_INT_IDFLOAT (1 << 0)
  260. #define ULPI_CARKIT_INT_CARINTDET (1 << 1)
  261. #define ULPI_CARKIT_INT_DP (1 << 2)
  262. /* Carkit Pulse Control*/
  263. #define ULPI_CARKIT_PLS_CTRL_TXPLSEN (1 << 0)
  264. #define ULPI_CARKIT_PLS_CTRL_RXPLSEN (1 << 1)
  265. #define ULPI_CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2)
  266. #define ULPI_CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3)
  267. #endif /* __USB_ULPI_H__ */