mt_musbphy.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * Copyright (c) 2018 MediaTek Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in
  11. * the documentation and/or other materials provided with the
  12. * distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  17. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  18. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  20. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  21. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  22. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  24. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #include <sys/types.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <debug.h>
  31. #include <reg.h>
  32. #include <platform/bitops.h>
  33. #include <platform/mt_reg_base.h>
  34. #include <platform/mt_typedefs.h>
  35. #include <dev/udc.h>
  36. /* common */
  37. #include <mt_musb.h>
  38. #if CFG_FPGA_PLATFORM
  39. /* for usb phy */
  40. #include <platform/mt_i2c.h>
  41. #endif
  42. #ifdef MACH_FPGA
  43. #define CFG_FPGA_PLATFORM (1)
  44. #else
  45. #define DBG_PHY_CALIBRATION 1
  46. #endif
  47. /* usb phy bring up */
  48. #if CFG_FPGA_PLATFORM
  49. #define USB_I2C_ID I2C3 /* 0 - 6 */
  50. #define PATH_NORMAL 0
  51. #define PATH_PMIC 1
  52. U32 usb_i2c_read8 (U8 addr, U8 *dataBuffer)
  53. {
  54. U32 ret_code = I2C_OK;
  55. // U8 write_data = addr;
  56. U16 len;
  57. static struct mt_i2c_t i2c;
  58. i2c.id = USB_I2C_ID;
  59. i2c.addr = 0x60; /* i2c API will shift-left this value to 0xc0 */
  60. i2c.mode = ST_MODE;
  61. i2c.speed = 100;
  62. i2c.dma_en = 0;
  63. len = 1;
  64. /* set register command */
  65. #if 0
  66. ret_code = i2c_write(&i2c, &write_data, len);
  67. if (ret_code != len)
  68. return ret_code;
  69. ret_code = i2c_read(&i2c, dataBuffer, len);
  70. #else
  71. ret_code = i2c_write_read(&i2c, dataBuffer, len, len);
  72. #endif
  73. return ret_code;
  74. }
  75. U32 usb_i2c_write8(U8 addr, U8 value)
  76. {
  77. U32 ret_code = I2C_OK;
  78. U8 write_data[2];
  79. U16 len;
  80. static struct mt_i2c_t i2c;
  81. write_data[0]= addr;
  82. write_data[1] = value;
  83. i2c.id = USB_I2C_ID;
  84. i2c.addr = 0x60; /* i2c API will shift-left this value to 0xc0 */
  85. i2c.mode = ST_MODE;
  86. i2c.speed = 100;
  87. i2c.dma_en = 0;
  88. len = 2;
  89. ret_code = i2c_write(&i2c, write_data, len);
  90. return ret_code;
  91. }
  92. #define USBPHY_I2C_READ8(addr, buffer) usb_i2c_read8(addr, buffer)
  93. #define USBPHY_I2C_WRITE8(addr, value) usb_i2c_write8(addr, value)
  94. #endif
  95. /* use mt_typedefs.h */
  96. #define USBPHY_READ8(offset) readb(USB20_PHY_BASE+offset)
  97. #define USBPHY_WRITE8(offset, value) writeb(value, USB20_PHY_BASE+offset)
  98. #define USBPHY_SET8(offset, mask) USBPHY_WRITE8(offset, (USBPHY_READ8(offset)) | (mask))
  99. #define USBPHY_CLR8(offset, mask) USBPHY_WRITE8(offset, (USBPHY_READ8(offset)) & (~mask))
  100. #define DRV_USB_Reg32(addr) (*(volatile u32 *)(addr))
  101. #define DRV_USB_WriteReg32(addr,data) ((*(volatile u32 *)(addr)) = (u32)data)
  102. #define USBPHYREAD32(offset) DRV_USB_Reg32(USB20_PHY_BASE+offset)
  103. #define USBPHYWRITE32(offset, value) DRV_USB_WriteReg32(USB20_PHY_BASE+offset, value)
  104. #define USB11PHY_READ8(offset) readb(USB11_PHY_BASE+offset)
  105. #define USB11PHY_WRITE8(offset, value) writeb(value, USB11_PHY_BASE+offset)
  106. #define USB11PHY_SET8(offset, mask) USB11PHY_WRITE8(offset, (USB11PHY_READ8(offset)) | (mask))
  107. #define USB11PHY_CLR8(offset, mask) USB11PHY_WRITE8(offset, (USB11PHY_READ8(offset)) & (~mask))
  108. #define USBPHY_SET32(offset, mask) USBPHYWRITE32(offset, USBPHYREAD32(offset) | mask)
  109. #define USBPHY_CLR32(offset, mask) USBPHYWRITE32(offset, USBPHYREAD32(offset) & ~mask)
  110. #if CFG_FPGA_PLATFORM
  111. void mt_usb_phy_poweron(void)
  112. {
  113. #define PHY_DRIVING 0x3
  114. #if defined(USB_PHY_DRIVING_TUNING)
  115. UINT8 usbreg8;
  116. unsigned int i;
  117. #endif
  118. /* force_suspendm = 0 */
  119. USBPHY_CLR8(0x6a, 0x04);
  120. USBPHY_I2C_WRITE8(0xff, 0x00);
  121. USBPHY_I2C_WRITE8(0x61, 0x04);
  122. USBPHY_I2C_WRITE8(0x68, 0x00);
  123. USBPHY_I2C_WRITE8(0x6a, 0x00);
  124. USBPHY_I2C_WRITE8(0x00, 0x6e);
  125. USBPHY_I2C_WRITE8(0x1b, 0x0c);
  126. USBPHY_I2C_WRITE8(0x08, 0x44);
  127. USBPHY_I2C_WRITE8(0x11, 0x55);
  128. USBPHY_I2C_WRITE8(0x1a, 0x68);
  129. #if defined(USB_PHY_DRIVING_TUNING)
  130. /* driving tuning */
  131. USBPHY_I2C_READ8(0xab, &usbreg8);
  132. usbreg8 &= ~0x3;
  133. usbreg8 |= PHY_DRIVING;
  134. USBPHY_I2C_WRITE8(0xab, usbreg8);
  135. for (i = 0; i < 16; i++) {
  136. USBPHY_I2C_READ8((0x92+i), &usbreg8);
  137. usbreg8 &= ~0x3;
  138. usbreg8 |= PHY_DRIVING;
  139. USBPHY_I2C_WRITE8((0x92+i), usbreg8);
  140. }
  141. USBPHY_I2C_READ8(0xbc, &usbreg8);
  142. usbreg8 &= ~0x3;
  143. usbreg8 |= PHY_DRIVING;
  144. USBPHY_I2C_WRITE8(0xbc, usbreg8);
  145. USBPHY_I2C_READ8(0xbe, &usbreg8);
  146. usbreg8 &= ~0x3;
  147. usbreg8 |= PHY_DRIVING;
  148. USBPHY_I2C_WRITE8(0xbe, usbreg8);
  149. USBPHY_I2C_READ8(0xbf, &usbreg8);
  150. usbreg8 &= ~0x3;
  151. usbreg8 |= PHY_DRIVING;
  152. USBPHY_I2C_WRITE8(0xbf, usbreg8);
  153. USBPHY_I2C_READ8(0xcd, &usbreg8);
  154. usbreg8 &= ~0x3;
  155. usbreg8 |= PHY_DRIVING;
  156. USBPHY_I2C_WRITE8(0xcd, usbreg8);
  157. USBPHY_I2C_READ8(0xf1, &usbreg8);
  158. usbreg8 &= ~0x3;
  159. usbreg8 |= PHY_DRIVING;
  160. USBPHY_I2C_WRITE8(0xf1, usbreg8);
  161. USBPHY_I2C_READ8(0xa7, &usbreg8);
  162. usbreg8 &= ~0x3;
  163. usbreg8 |= PHY_DRIVING;
  164. USBPHY_I2C_WRITE8(0xa7, usbreg8);
  165. USBPHY_I2C_READ8(0xa8, &usbreg8);
  166. usbreg8 &= ~0x3;
  167. usbreg8 |= PHY_DRIVING;
  168. USBPHY_I2C_WRITE8(0xa8, usbreg8);
  169. #endif
  170. udelay(800);
  171. }
  172. void mt_usb_phy_savecurrent (void)
  173. {
  174. /* no need */
  175. }
  176. void mt_usb_phy_recover (void)
  177. {
  178. /* no need */
  179. }
  180. void mt_usb11_phy_savecurrent(void)
  181. {
  182. /* no need */
  183. }
  184. void Charger_Detect_Init(void)
  185. {
  186. /* no need */
  187. }
  188. void Charger_Detect_Release(void)
  189. {
  190. /* no need */
  191. }
  192. #else
  193. void mt_usb_phy_poweron(void)
  194. {
  195. /*
  196. * force_uart_en 1'b0 0x68 26
  197. * RG_UART_EN 1'b0 0x6c 16
  198. * rg_usb20_gpio_ctl 1'b0 0x20 09
  199. * usb20_gpio_mode 1'b0 0x20 08
  200. * RG_USB20_BC11_SW_EN 1'b0 0x18 23
  201. * rg_usb20_dp_100k_mode 1'b1 0x20 18
  202. * USB20_DP_100K_EN 1'b0 0x20 16
  203. * RG_USB20_DM_100K_EN 1'b0 0x20 17
  204. * RG_USB20_OTG_VBUSCMP_EN 1'b1 0x18 20
  205. * force_suspendm 1'b0 0x68 18
  206. */
  207. /* force_uart_en, 1'b0 */
  208. USBPHY_CLR32(0x68, (0x1 << 26));
  209. /* RG_UART_EN, 1'b0 */
  210. USBPHY_CLR32(0x6c, (0x1 << 16));
  211. /* rg_usb20_gpio_ctl, 1'b0, usb20_gpio_mode, 1'b0 */
  212. USBPHY_CLR32(0x20, ((0x1 << 9) | (0x1 << 8)));
  213. /* RG_USB20_BC11_SW_EN, 1'b0 */
  214. USBPHY_CLR32(0x18, (0x1 << 23));
  215. /* rg_usb20_dp_100k_mode, 1'b1 */
  216. USBPHY_SET32(0x20, (0x1 << 18));
  217. /* USB20_DP_100K_EN 1'b0, RG_USB20_DM_100K_EN, 1'b0 */
  218. USBPHY_CLR32(0x20, ((0x1 << 16) | (0x1 << 17)));
  219. /* RG_USB20_OTG_VBUSCMP_EN, 1'b1 */
  220. USBPHY_SET32(0x18, (0x1 << 20));
  221. /* force_suspendm, 1'b0 */
  222. USBPHY_CLR32(0x68, (0x1 << 18));
  223. /* wait for 800 usec. */
  224. udelay(800);
  225. }
  226. void mt_usb_phy_savecurrent(void)
  227. {
  228. /*
  229. * force_uart_en 1'b0 0x68 26
  230. * RG_UART_EN 1'b0 0x6c 16
  231. * rg_usb20_gpio_ctl 1'b0 0x20 09
  232. * usb20_gpio_mode 1'b0 0x20 08
  233. * RG_USB20_BC11_SW_EN 1'b0 0x18 23
  234. * RG_USB20_OTG_VBUSCMP_EN 1'b0 0x18 20
  235. * RG_SUSPENDM 1'b1 0x68 03
  236. * force_suspendm 1'b1 0x68 18
  237. * RG_DPPULLDOWN 1'b1 0x68 06
  238. * RG_DMPULLDOWN 1'b1 0x68 07
  239. * RG_XCVRSEL[1:0] 2'b01 0x68 [04-05]
  240. * RG_TERMSEL 1'b1 0x68 02
  241. * RG_DATAIN[3:0] 4'b0000 0x68 [10-13]
  242. * force_dp_pulldown 1'b1 0x68 20
  243. * force_dm_pulldown 1'b1 0x68 21
  244. * force_xcversel 1'b1 0x68 19
  245. * force_termsel 1'b1 0x68 17
  246. * force_datain 1'b1 0x68 23
  247. * RG_SUSPENDM 1'b0 0x68 03
  248. */
  249. /* force_uart_en, 1'b0 */
  250. USBPHY_CLR32(0x68, (0x1 << 26));
  251. /* RG_UART_EN, 1'b0 */
  252. USBPHY_CLR32(0x6c, (0x1 << 16));
  253. /* rg_usb20_gpio_ctl, 1'b0, usb20_gpio_mode, 1'b0 */
  254. USBPHY_CLR32(0x20, (0x1 << 9));
  255. USBPHY_CLR32(0x20, (0x1 << 8));
  256. /* RG_USB20_BC11_SW_EN, 1'b0 */
  257. USBPHY_CLR32(0x18, (0x1 << 23));
  258. /* RG_USB20_OTG_VBUSCMP_EN, 1'b0 */
  259. USBPHY_CLR32(0x18, (0x1 << 20));
  260. /* RG_SUSPENDM, 1'b1 */
  261. USBPHY_SET32(0x68, (0x1 << 3));
  262. /* force_suspendm, 1'b1 */
  263. USBPHY_SET32(0x68, (0x1 << 18));
  264. /* RG_DPPULLDOWN, 1'b1, RG_DMPULLDOWN, 1'b1 */
  265. USBPHY_SET32(0x68, ((0x1 << 6) | (0x1 << 7)));
  266. /* RG_XCVRSEL[1:0], 2'b01. */
  267. USBPHY_CLR32(0x68, (0x3 << 4));
  268. USBPHY_SET32(0x68, (0x1 << 4));
  269. /* RG_TERMSEL, 1'b1 */
  270. USBPHY_SET32(0x68, (0x1 << 2));
  271. /* RG_DATAIN[3:0], 4'b0000 */
  272. USBPHY_CLR32(0x68, (0xF << 10));
  273. /* force_dp_pulldown, 1'b1, force_dm_pulldown, 1'b1,
  274. * force_xcversel, 1'b1, force_termsel, 1'b1, force_datain, 1'b1
  275. */
  276. USBPHY_SET32(0x68, ((0x1 << 20) | (0x1 << 21) | (0x1 << 19) | (0x1 << 17) | (0x1 << 23)));
  277. udelay(800);
  278. /* RG_SUSPENDM, 1'b0 */
  279. USBPHY_CLR32(0x68, (0x1 << 3));
  280. udelay(1);
  281. return;
  282. }
  283. void mt_usb_phy_recover(void)
  284. {
  285. /*
  286. * 04.force_uart_en 1'b0 0x68 26
  287. * 04.RG_UART_EN 1'b0 0x6C 16
  288. * 04.rg_usb20_gpio_ctl 1'b0 0x20 09
  289. * 04.usb20_gpio_mode 1'b0 0x20 08
  290. * 05.force_suspendm 1'b0 0x68 18
  291. * 06.RG_DPPULLDOWN 1'b0 0x68 06
  292. * 07.RG_DMPULLDOWN 1'b0 0x68 07
  293. * 08.RG_XCVRSEL[1:0] 2'b00 0x68 [04:05]
  294. * 09.RG_TERMSEL 1'b0 0x68 02
  295. * 10.RG_DATAIN[3:0] 4'b0000 0x68 [10:13]
  296. * 11.force_dp_pulldown 1'b0 0x68 20
  297. * 12.force_dm_pulldown 1'b0 0x68 21
  298. * 13.force_xcversel 1'b0 0x68 19
  299. * 14.force_termsel 1'b0 0x68 17
  300. * 15.force_datain 1'b0 0x68 23
  301. * 16.RG_USB20_BC11_SW_EN 1'b0 0x18 23
  302. * 17.RG_USB20_OTG_VBUSCMP_EN 1'b1 0x18 20
  303. */
  304. /* clean PUPD_BIST_EN */
  305. /* PUPD_BIST_EN = 1'b0 */
  306. /* PMIC will use it to detect charger type */
  307. /* NEED?? USBPHY_CLR8(0x1d, 0x10);*/
  308. USBPHY_CLR32(0x1c, (0x1 << 12));
  309. /* force_uart_en, 1'b0 */
  310. USBPHY_CLR32(0x68, (0x1 << 26));
  311. /* RG_UART_EN, 1'b0 */
  312. USBPHY_CLR32(0x6C, (0x1 << 16));
  313. /* rg_usb20_gpio_ctl, 1'b0, usb20_gpio_mode, 1'b0 */
  314. USBPHY_CLR32(0x20, (0x1 << 9));
  315. USBPHY_CLR32(0x20, (0x1 << 8));
  316. /* force_suspendm, 1'b0 */
  317. USBPHY_CLR32(0x68, (0x1 << 18));
  318. /* RG_DPPULLDOWN, 1'b0, RG_DMPULLDOWN, 1'b0 */
  319. USBPHY_CLR32(0x68, ((0x1 << 6) | (0x1 << 7)));
  320. /* RG_XCVRSEL[1:0], 2'b00. */
  321. USBPHY_CLR32(0x68, (0x3 << 4));
  322. /* RG_TERMSEL, 1'b0 */
  323. USBPHY_CLR32(0x68, (0x1 << 2));
  324. /* RG_DATAIN[3:0], 4'b0000 */
  325. USBPHY_CLR32(0x68, (0xF << 10));
  326. /* force_dp_pulldown, 1'b0, force_dm_pulldown, 1'b0,
  327. * force_xcversel, 1'b0, force_termsel, 1'b0, force_datain, 1'b0
  328. */
  329. USBPHY_CLR32(0x68, ((0x1 << 20) | (0x1 << 21) | (0x1 << 19) | (0x1 << 17) | (0x1 << 23)));
  330. /* RG_USB20_BC11_SW_EN, 1'b0 */
  331. USBPHY_CLR32(0x18, (0x1 << 23));
  332. /* RG_USB20_OTG_VBUSCMP_EN, 1'b1 */
  333. USBPHY_SET32(0x18, (0x1 << 20));
  334. /* wait 800 usec. */
  335. udelay(800);
  336. /* force enter device mode */
  337. USBPHY_CLR32(0x6C, (0x10<<0));
  338. USBPHY_SET32(0x6C, (0x2F<<0));
  339. USBPHY_SET32(0x6C, (0x3F<<8));
  340. }
  341. void mt_usb11_phy_savecurrent(void)
  342. {
  343. #if 0
  344. USB11PHY_SET8(0xca, 0x10);
  345. USB11PHY_SET8(0xcb, 0x3c);
  346. USB11PHY_CLR8(0xc1, 0x08);
  347. USB11PHY_CLR8(0xc7, 0x06);
  348. USB11PHY_SET8(0xc6, 0x06);
  349. #endif
  350. }
  351. void Charger_Detect_Init(void)
  352. {
  353. /* RG_USB20_BC11_SW_EN = 1'b1 */
  354. USBPHY_SET8(0x1a, 0x80);
  355. }
  356. void Charger_Detect_Release(void)
  357. {
  358. /* RG_USB20_BC11_SW_EN = 1'b0 */
  359. USBPHY_CLR8(0x1a, 0x80);
  360. }
  361. #endif
  362. /* usb phy bring up end */
  363. #if !CFG_FPGA_PLATFORM
  364. //ALPS00427972, implement the analog register formula
  365. void mt_usb_phy_calibraion (int case_set, int input_reg)
  366. {
  367. #if 0
  368. int temp_added=0;
  369. int temp_test=0;
  370. int temp_mask;
  371. #if DBG_PHY_CALIBRATION
  372. DBG_I("%s: case_set %d, input_reg = 0x%x \n", __func__, case_set, input_reg);
  373. #endif
  374. switch (case_set) {
  375. case 1:
  376. //case 1
  377. //If M_HW_RES3[15:13] !=0
  378. //RG_USB20_TERM_VREF_SEL[2:0] <= RG_USB20_TERM_VREF_SEL[2:0] + M_HW_RES3[15:13]
  379. temp_mask = 0x07;
  380. temp_test = USBPHY_READ8(0x05);
  381. #if DBG_PHY_CALIBRATION
  382. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  383. #endif
  384. temp_added = (USBPHY_READ8(0x05)& temp_mask) + input_reg;
  385. #if DBG_PHY_CALIBRATION
  386. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  387. #endif
  388. temp_added &= 0x07;
  389. #if DBG_PHY_CALIBRATION
  390. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  391. #endif
  392. USBPHY_CLR8(0x05, temp_mask);
  393. USBPHY_SET8(0x05, temp_added);
  394. temp_test = USBPHY_READ8(0x05);
  395. #if DBG_PHY_CALIBRATION
  396. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  397. #endif
  398. break;
  399. case 2:
  400. //case 2
  401. //If M_HW_RES3[12:10] !=0
  402. //RG_USB20_CLKREF_REF[2:0]<= RG_USB20_CLKREF_REF[2:0]+ M_HW_RES3[12:10]
  403. temp_mask = 0x07;
  404. temp_test = USBPHY_READ8(0x07);
  405. #if DBG_PHY_CALIBRATION
  406. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  407. #endif
  408. temp_added = (USBPHY_READ8(0x07)& temp_mask) + input_reg;
  409. #if DBG_PHY_CALIBRATION
  410. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  411. #endif
  412. temp_added &= 0x07;
  413. #if DBG_PHY_CALIBRATION
  414. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  415. #endif
  416. USBPHY_CLR8(0x07, temp_mask);
  417. USBPHY_SET8(0x07, temp_added);
  418. temp_test = USBPHY_READ8(0x07);
  419. #if DBG_PHY_CALIBRATION
  420. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  421. #endif
  422. break;
  423. case 3:
  424. //case 3
  425. //If M_HW_RES3[9:7] !=0
  426. //RG_USB20_VRT_VREF_SEL[2:0]<=RG_USB20_VRT_VREF_SEL[2:0]+ M_HW_RES3[9:7]
  427. temp_mask = 0x70;
  428. temp_test = USBPHY_READ8(0x05);
  429. #if DBG_PHY_CALIBRATION
  430. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  431. #endif
  432. temp_added = (USBPHY_READ8(0x05)& temp_mask) >> 4;
  433. #if DBG_PHY_CALIBRATION
  434. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  435. #endif
  436. temp_added += input_reg;
  437. #if DBG_PHY_CALIBRATION
  438. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  439. #endif
  440. temp_added &= 0x07;
  441. #if DBG_PHY_CALIBRATION
  442. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  443. #endif
  444. USBPHY_CLR8(0x05, temp_mask);
  445. USBPHY_SET8(0x05, temp_added<<4);
  446. temp_test = USBPHY_READ8(0x05);
  447. #if DBG_PHY_CALIBRATION
  448. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  449. #endif
  450. break;
  451. }
  452. #endif
  453. }
  454. //ALPS00427972, implement the analog register formula
  455. #endif