mt_musbphy.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <sys/types.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <debug.h>
  27. #include <reg.h>
  28. #include <platform/bitops.h>
  29. #include <platform/mt_reg_base.h>
  30. #include <platform/mt_typedefs.h>
  31. #include <dev/udc.h>
  32. /* common */
  33. #include <mt_musb.h>
  34. #if CFG_FPGA_PLATFORM
  35. /* for usb phy */
  36. #include <platform/mt_i2c.h>
  37. #endif
  38. #ifdef MACH_FPGA
  39. #define CFG_FPGA_PLATFORM (1)
  40. #else
  41. #define DBG_PHY_CALIBRATION 1
  42. #endif
  43. /* usb phy bring up */
  44. #if CFG_FPGA_PLATFORM
  45. #define USB_I2C_ID I2C3 /* 0 - 6 */
  46. #define PATH_NORMAL 0
  47. #define PATH_PMIC 1
  48. U32 usb_i2c_read8 (U8 addr, U8 *dataBuffer)
  49. {
  50. U32 ret_code = I2C_OK;
  51. // U8 write_data = addr;
  52. U16 len;
  53. static struct mt_i2c_t i2c;
  54. i2c.id = USB_I2C_ID;
  55. i2c.addr = 0x60; /* i2c API will shift-left this value to 0xc0 */
  56. i2c.mode = ST_MODE;
  57. i2c.speed = 100;
  58. i2c.dma_en = 0;
  59. len = 1;
  60. /* set register command */
  61. #if 0
  62. ret_code = i2c_write(&i2c, &write_data, len);
  63. if (ret_code != len)
  64. return ret_code;
  65. ret_code = i2c_read(&i2c, dataBuffer, len);
  66. #else
  67. ret_code = i2c_write_read(&i2c, dataBuffer, len, len);
  68. #endif
  69. return ret_code;
  70. }
  71. U32 usb_i2c_write8(U8 addr, U8 value)
  72. {
  73. U32 ret_code = I2C_OK;
  74. U8 write_data[2];
  75. U16 len;
  76. static struct mt_i2c_t i2c;
  77. write_data[0]= addr;
  78. write_data[1] = value;
  79. i2c.id = USB_I2C_ID;
  80. i2c.addr = 0x60; /* i2c API will shift-left this value to 0xc0 */
  81. i2c.mode = ST_MODE;
  82. i2c.speed = 100;
  83. i2c.dma_en = 0;
  84. len = 2;
  85. ret_code = i2c_write(&i2c, write_data, len);
  86. return ret_code;
  87. }
  88. #define USBPHY_I2C_READ8(addr, buffer) usb_i2c_read8(addr, buffer)
  89. #define USBPHY_I2C_WRITE8(addr, value) usb_i2c_write8(addr, value)
  90. #endif
  91. /* use mt_typedefs.h */
  92. #define USBPHY_READ8(offset) readb(USB20_PHY_BASE+offset)
  93. #define USBPHY_WRITE8(offset, value) writeb(value, USB20_PHY_BASE+offset)
  94. #define USBPHY_SET8(offset, mask) USBPHY_WRITE8(offset, (USBPHY_READ8(offset)) | (mask))
  95. #define USBPHY_CLR8(offset, mask) USBPHY_WRITE8(offset, (USBPHY_READ8(offset)) & (~mask))
  96. #define DRV_USB_Reg32(addr) (*(volatile u32 *)(addr))
  97. #define DRV_USB_WriteReg32(addr,data) ((*(volatile u32 *)(addr)) = (u32)data)
  98. #define USBPHYREAD32(offset) DRV_USB_Reg32(USB20_PHY_BASE+offset)
  99. #define USBPHYWRITE32(offset, value) DRV_USB_WriteReg32(USB20_PHY_BASE+offset, value)
  100. #define USB11PHY_READ8(offset) readb(USB11_PHY_BASE+offset)
  101. #define USB11PHY_WRITE8(offset, value) writeb(value, USB11_PHY_BASE+offset)
  102. #define USB11PHY_SET8(offset, mask) USB11PHY_WRITE8(offset, (USB11PHY_READ8(offset)) | (mask))
  103. #define USB11PHY_CLR8(offset, mask) USB11PHY_WRITE8(offset, (USB11PHY_READ8(offset)) & (~mask))
  104. #define USBPHY_SET32(offset, mask) USBPHYWRITE32(offset, USBPHYREAD32(offset) | mask)
  105. #define USBPHY_CLR32(offset, mask) USBPHYWRITE32(offset, USBPHYREAD32(offset) & ~mask)
  106. #if CFG_FPGA_PLATFORM
  107. void mt_usb_phy_poweron(void)
  108. {
  109. #define PHY_DRIVING 0x3
  110. #if defined(USB_PHY_DRIVING_TUNING)
  111. UINT8 usbreg8;
  112. unsigned int i;
  113. #endif
  114. /* force_suspendm = 0 */
  115. USBPHY_CLR8(0x6a, 0x04);
  116. USBPHY_I2C_WRITE8(0xff, 0x00);
  117. USBPHY_I2C_WRITE8(0x61, 0x04);
  118. USBPHY_I2C_WRITE8(0x68, 0x00);
  119. USBPHY_I2C_WRITE8(0x6a, 0x00);
  120. USBPHY_I2C_WRITE8(0x00, 0x6e);
  121. USBPHY_I2C_WRITE8(0x1b, 0x0c);
  122. USBPHY_I2C_WRITE8(0x08, 0x44);
  123. USBPHY_I2C_WRITE8(0x11, 0x55);
  124. USBPHY_I2C_WRITE8(0x1a, 0x68);
  125. #if defined(USB_PHY_DRIVING_TUNING)
  126. /* driving tuning */
  127. USBPHY_I2C_READ8(0xab, &usbreg8);
  128. usbreg8 &= ~0x3;
  129. usbreg8 |= PHY_DRIVING;
  130. USBPHY_I2C_WRITE8(0xab, usbreg8);
  131. for (i = 0; i < 16; i++) {
  132. USBPHY_I2C_READ8((0x92+i), &usbreg8);
  133. usbreg8 &= ~0x3;
  134. usbreg8 |= PHY_DRIVING;
  135. USBPHY_I2C_WRITE8((0x92+i), usbreg8);
  136. }
  137. USBPHY_I2C_READ8(0xbc, &usbreg8);
  138. usbreg8 &= ~0x3;
  139. usbreg8 |= PHY_DRIVING;
  140. USBPHY_I2C_WRITE8(0xbc, usbreg8);
  141. USBPHY_I2C_READ8(0xbe, &usbreg8);
  142. usbreg8 &= ~0x3;
  143. usbreg8 |= PHY_DRIVING;
  144. USBPHY_I2C_WRITE8(0xbe, usbreg8);
  145. USBPHY_I2C_READ8(0xbf, &usbreg8);
  146. usbreg8 &= ~0x3;
  147. usbreg8 |= PHY_DRIVING;
  148. USBPHY_I2C_WRITE8(0xbf, usbreg8);
  149. USBPHY_I2C_READ8(0xcd, &usbreg8);
  150. usbreg8 &= ~0x3;
  151. usbreg8 |= PHY_DRIVING;
  152. USBPHY_I2C_WRITE8(0xcd, usbreg8);
  153. USBPHY_I2C_READ8(0xf1, &usbreg8);
  154. usbreg8 &= ~0x3;
  155. usbreg8 |= PHY_DRIVING;
  156. USBPHY_I2C_WRITE8(0xf1, usbreg8);
  157. USBPHY_I2C_READ8(0xa7, &usbreg8);
  158. usbreg8 &= ~0x3;
  159. usbreg8 |= PHY_DRIVING;
  160. USBPHY_I2C_WRITE8(0xa7, usbreg8);
  161. USBPHY_I2C_READ8(0xa8, &usbreg8);
  162. usbreg8 &= ~0x3;
  163. usbreg8 |= PHY_DRIVING;
  164. USBPHY_I2C_WRITE8(0xa8, usbreg8);
  165. #endif
  166. udelay(800);
  167. }
  168. void mt_usb_phy_savecurrent (void)
  169. {
  170. /* no need */
  171. }
  172. void mt_usb_phy_recover (void)
  173. {
  174. /* no need */
  175. }
  176. void mt_usb11_phy_savecurrent(void)
  177. {
  178. /* no need */
  179. }
  180. void Charger_Detect_Init(void)
  181. {
  182. /* no need */
  183. }
  184. void Charger_Detect_Release(void)
  185. {
  186. /* no need */
  187. }
  188. #else
  189. void mt_usb_phy_poweron(void)
  190. {
  191. /*
  192. * force_uart_en 1'b0 0x68 26
  193. * RG_UART_EN 1'b0 0x6c 16
  194. * rg_usb20_gpio_ctl 1'b0 0x20 09
  195. * usb20_gpio_mode 1'b0 0x20 08
  196. * RG_USB20_BC11_SW_EN 1'b0 0x18 23
  197. * rg_usb20_dp_100k_mode 1'b1 0x20 18
  198. * USB20_DP_100K_EN 1'b0 0x20 16
  199. * RG_USB20_DM_100K_EN 1'b0 0x20 17
  200. * RG_USB20_OTG_VBUSCMP_EN 1'b1 0x18 20
  201. * force_suspendm 1'b0 0x68 18
  202. */
  203. /* force_uart_en, 1'b0 */
  204. USBPHY_CLR32(0x68, (0x1 << 26));
  205. /* RG_UART_EN, 1'b0 */
  206. USBPHY_CLR32(0x6c, (0x1 << 16));
  207. /* rg_usb20_gpio_ctl, 1'b0, usb20_gpio_mode, 1'b0 */
  208. USBPHY_CLR32(0x20, ((0x1 << 9) | (0x1 << 8)));
  209. /* RG_USB20_BC11_SW_EN, 1'b0 */
  210. USBPHY_CLR32(0x18, (0x1 << 23));
  211. /* rg_usb20_dp_100k_mode, 1'b1 */
  212. USBPHY_SET32(0x20, (0x1 << 18));
  213. /* USB20_DP_100K_EN 1'b0, RG_USB20_DM_100K_EN, 1'b0 */
  214. USBPHY_CLR32(0x20, ((0x1 << 16) | (0x1 << 17)));
  215. /* RG_USB20_OTG_VBUSCMP_EN, 1'b1 */
  216. USBPHY_SET32(0x18, (0x1 << 20));
  217. /* force_suspendm, 1'b0 */
  218. USBPHY_CLR32(0x68, (0x1 << 18));
  219. /* RG_USB20_PHY_REV[7:0] = 8'b01000000 */
  220. USBPHY_CLR32(0x18, (0xFF << 24));
  221. USBPHY_SET32(0x18, (0x40 << 24));
  222. /* wait for 800 usec. */
  223. udelay(800);
  224. return;
  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. /* RG_USB20_PHY_REV[7:0] = 8'b01000000 */
  335. USBPHY_CLR32(0x18, (0xFF << 24));
  336. USBPHY_SET32(0x18, (0x40 << 24));
  337. /* wait 800 usec. */
  338. udelay(800);
  339. /* force enter device mode */
  340. USBPHY_CLR32(0x6C, (0x10<<0));
  341. USBPHY_SET32(0x6C, (0x2F<<0));
  342. USBPHY_SET32(0x6C, (0x3F<<8));
  343. }
  344. void mt_usb11_phy_savecurrent(void)
  345. {
  346. #if 0
  347. USB11PHY_SET8(0xca, 0x10);
  348. USB11PHY_SET8(0xcb, 0x3c);
  349. USB11PHY_CLR8(0xc1, 0x08);
  350. USB11PHY_CLR8(0xc7, 0x06);
  351. USB11PHY_SET8(0xc6, 0x06);
  352. #endif
  353. }
  354. void Charger_Detect_Init(void)
  355. {
  356. /* RG_USB20_BC11_SW_EN = 1'b1 */
  357. USBPHY_SET8(0x1a, 0x80);
  358. }
  359. void Charger_Detect_Release(void)
  360. {
  361. /* RG_USB20_BC11_SW_EN = 1'b0 */
  362. USBPHY_CLR8(0x1a, 0x80);
  363. }
  364. #endif
  365. /* usb phy bring up end */
  366. #if !CFG_FPGA_PLATFORM
  367. //ALPS00427972, implement the analog register formula
  368. void mt_usb_phy_calibraion (int case_set, int input_reg)
  369. {
  370. #if 0
  371. int temp_added=0;
  372. int temp_test=0;
  373. int temp_mask;
  374. #if DBG_PHY_CALIBRATION
  375. DBG_I("%s: case_set %d, input_reg = 0x%x \n", __func__, case_set, input_reg);
  376. #endif
  377. switch (case_set) {
  378. case 1:
  379. //case 1
  380. //If M_HW_RES3[15:13] !=0
  381. //RG_USB20_TERM_VREF_SEL[2:0] <= RG_USB20_TERM_VREF_SEL[2:0] + M_HW_RES3[15:13]
  382. temp_mask = 0x07;
  383. temp_test = USBPHY_READ8(0x05);
  384. #if DBG_PHY_CALIBRATION
  385. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  386. #endif
  387. temp_added = (USBPHY_READ8(0x05)& temp_mask) + input_reg;
  388. #if DBG_PHY_CALIBRATION
  389. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  390. #endif
  391. temp_added &= 0x07;
  392. #if DBG_PHY_CALIBRATION
  393. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  394. #endif
  395. USBPHY_CLR8(0x05, temp_mask);
  396. USBPHY_SET8(0x05, temp_added);
  397. temp_test = USBPHY_READ8(0x05);
  398. #if DBG_PHY_CALIBRATION
  399. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  400. #endif
  401. break;
  402. case 2:
  403. //case 2
  404. //If M_HW_RES3[12:10] !=0
  405. //RG_USB20_CLKREF_REF[2:0]<= RG_USB20_CLKREF_REF[2:0]+ M_HW_RES3[12:10]
  406. temp_mask = 0x07;
  407. temp_test = USBPHY_READ8(0x07);
  408. #if DBG_PHY_CALIBRATION
  409. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  410. #endif
  411. temp_added = (USBPHY_READ8(0x07)& temp_mask) + input_reg;
  412. #if DBG_PHY_CALIBRATION
  413. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  414. #endif
  415. temp_added &= 0x07;
  416. #if DBG_PHY_CALIBRATION
  417. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  418. #endif
  419. USBPHY_CLR8(0x07, temp_mask);
  420. USBPHY_SET8(0x07, temp_added);
  421. temp_test = USBPHY_READ8(0x07);
  422. #if DBG_PHY_CALIBRATION
  423. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  424. #endif
  425. break;
  426. case 3:
  427. //case 3
  428. //If M_HW_RES3[9:7] !=0
  429. //RG_USB20_VRT_VREF_SEL[2:0]<=RG_USB20_VRT_VREF_SEL[2:0]+ M_HW_RES3[9:7]
  430. temp_mask = 0x70;
  431. temp_test = USBPHY_READ8(0x05);
  432. #if DBG_PHY_CALIBRATION
  433. DBG_I("%s: temp_test = 0x%x \n", __func__, temp_test);
  434. #endif
  435. temp_added = (USBPHY_READ8(0x05)& temp_mask) >> 4;
  436. #if DBG_PHY_CALIBRATION
  437. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  438. #endif
  439. temp_added += input_reg;
  440. #if DBG_PHY_CALIBRATION
  441. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  442. #endif
  443. temp_added &= 0x07;
  444. #if DBG_PHY_CALIBRATION
  445. DBG_I("%s: temp_added = 0x%x \n", __func__, temp_added);
  446. #endif
  447. USBPHY_CLR8(0x05, temp_mask);
  448. USBPHY_SET8(0x05, temp_added<<4);
  449. temp_test = USBPHY_READ8(0x05);
  450. #if DBG_PHY_CALIBRATION
  451. DBG_I("%s: final temp_test = 0x%x \n", __func__, temp_test);
  452. #endif
  453. break;
  454. }
  455. #endif
  456. }
  457. //ALPS00427972, implement the analog register formula
  458. #endif