ulpi.h 9.5 KB

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