_dinsdale

imx6_ahci.c.rhaley.diff

Jul 20th, 2017
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.50 KB | None | 0 0
  1. --- /usr/home/russellh/FreeBSD/rh-armv6/src/sys/arm/freescale/imx/imx6_ahci.c 2017-07-20 13:41:58.469329000 -0700
  2. +++ /usr/home/russellh/FreeBSD/rh-armv6/patches/in/imx6_ahci.c 2017-07-19 20:12:00.974999000 -0700
  3. @@ -45,44 +45,42 @@ __FBSDID("$FreeBSD$");
  4. #include <arm/freescale/imx/imx_ccmvar.h>
  5. #include <arm/freescale/imx/imx6_ccmvar.h>
  6.  
  7. -#define SATA_P0PHYCR 0x00000178
  8. -#define SATA_P0PHYCR_CR_READ (1 << 19)
  9. -#define SATA_P0PHYCR_CR_WRITE (1 << 18)
  10. -#define SATA_P0PHYCR_CR_CAP_DATA (1 << 17)
  11. -#define SATA_P0PHYCR_CR_CAP_ADDR (1 << 16)
  12. -#define SATA_P0PHYCR_CR_DATA_IN(v) ((v) & 0xffff)
  13. -#define SATA_P0PHYSR 0x0000017c
  14. -#define SATA_P0PHYSR_CR_ACK (1 << 18)
  15. -#define SATA_P0PHYSR_CR_DATA_OUT(v) ((v) & 0xffff)
  16. +#define SATA_P0PHYCR 0x00000178
  17. +#define SATA_P0PHYCR_CR_READ (1 << 19)
  18. +#define SATA_P0PHYCR_CR_WRITE (1 << 18)
  19. +#define SATA_P0PHYCR_CR_CAP_DATA (1 << 17)
  20. +#define SATA_P0PHYCR_CR_CAP_ADDR (1 << 16)
  21. +#define SATA_P0PHYCR_CR_DATA_IN(v) ((v) & 0xffff)
  22. +#define SATA_P0PHYSR 0x0000017c
  23. +#define SATA_P0PHYSR_CR_ACK (1 << 18)
  24. +#define SATA_P0PHYSR_CR_DATA_OUT(v) ((v) & 0xffff)
  25.  
  26. -#define SATA_TIMER1MS 0x000000e0
  27. +#define SATA_TIMER1MS 0x000000e0
  28.  
  29. /* phy registers */
  30. -#define SATA_PHY_CLOCK_RESET 0x7f3f
  31. -#define SATA_PHY_CLOCK_RESET_RST (1 << 0)
  32. +#define SATA_PHY_CLOCK_RESET 0x7f3f
  33. +#define SATA_PHY_CLOCK_RESET_RST (1 << 0)
  34.  
  35. -#define SATA_PHY_LANE0_OUT_STAT 0x2003
  36. -#define SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE (1 << 1)
  37. +#define SATA_PHY_LANE0_OUT_STAT 0x2003
  38. +#define SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE (1 << 1)
  39.  
  40. -//imx6_ahci_phy_ctrl(struct ahci_controller* sc, uint32_t bitmask, int on)
  41. static int
  42. -imx6_ahci_phy_ctrl(struct ahci_controller* sc, uint32_t bitmask, bool on)
  43. +imx6_ahci_phy_ctrl(struct ahci_controller* sc, uint32_t bitmask, int on)
  44. {
  45. uint32_t v;
  46. int timeout;
  47.  
  48. v = ATA_INL(sc->r_mem, SATA_P0PHYCR);
  49. - if (on) {
  50. + if(on) {
  51. v |= bitmask;
  52. } else {
  53. v &= ~bitmask;
  54. }
  55. ATA_OUTL(sc->r_mem, SATA_P0PHYCR, v);
  56.  
  57. - for (timeout = 5000; timeout > 0; --timeout) {
  58. + for(timeout = 5000; timeout > 0; --timeout) {
  59. v = ATA_INL(sc->r_mem, SATA_P0PHYSR);
  60. - //if (!!(v & SATA_P0PHYSR_CR_ACK) == !!on) {
  61. - if ((v & SATA_P0PHYSR_CR_ACK) == on) {
  62. + if(!!(v & SATA_P0PHYSR_CR_ACK) == !!on) {
  63. break;
  64. }
  65. DELAY(100);
  66. @@ -99,19 +97,23 @@ static int
  67. imx6_ahci_phy_addr(struct ahci_controller* sc, uint32_t addr)
  68. {
  69. int error;
  70. -
  71. DELAY(100);
  72. +
  73. ATA_OUTL(sc->r_mem, SATA_P0PHYCR, addr);
  74.  
  75. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, true);
  76. - if (error != 0) {
  77. - device_printf(sc->dev, "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=1\n", __FUNCTION__);
  78. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, 1);
  79. + if(error != 0) {
  80. + if(bootverbose) {
  81. + device_printf(sc->dev, "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=1\n", __FUNCTION__);
  82. + }
  83. return error;
  84. }
  85.  
  86. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, false);
  87. - if (error != 0) {
  88. - device_printf(sc->dev, "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=0\n", __FUNCTION__);
  89. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, 0);
  90. + if(error != 0) {
  91. + if(bootverbose) {
  92. + device_printf(sc->dev, "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=0\n", __FUNCTION__);
  93. + }
  94. return error;
  95. }
  96.  
  97. @@ -125,39 +127,43 @@ imx6_ahci_phy_write(struct ahci_controller* sc, uint32
  98. int error;
  99.  
  100. error = imx6_ahci_phy_addr(sc, addr);
  101. - if (error != 0) {
  102. - device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", __FUNCTION__);
  103. + if(error != 0) {
  104. + if(bootverbose) { device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", __FUNCTION__); }
  105. return error;
  106. }
  107.  
  108. ATA_OUTL(sc->r_mem, SATA_P0PHYCR, data);
  109.  
  110. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, true);
  111. - if (error != 0) {
  112. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_CAP_DATA=1\n", __FUNCTION__);
  113. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, 1);
  114. + if(error != 0) {
  115. + if(bootverbose) {
  116. + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_CAP_DATA=1\n", __FUNCTION__);
  117. + }
  118. return error;
  119. }
  120. - if (imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, false) != 0) {
  121. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_CAP_DATA=0\n", __FUNCTION__);
  122. + if(imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, 0) != 0) {
  123. + if(bootverbose) {
  124. + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_CAP_DATA=0\n", __FUNCTION__);
  125. + }
  126. return error;
  127. }
  128.  
  129. - if ((addr == SATA_PHY_CLOCK_RESET) && data) {
  130. + if((addr == SATA_PHY_CLOCK_RESET) && data) {
  131. /* we can't check ACK after RESET */
  132. ATA_OUTL(sc->r_mem, SATA_P0PHYCR,
  133. SATA_P0PHYCR_CR_DATA_IN(data) | SATA_P0PHYCR_CR_WRITE);
  134. return 0;
  135. }
  136.  
  137. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, true);
  138. - if (error != 0) {
  139. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=1\n", __FUNCTION__);
  140. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, 1);
  141. + if(error != 0) {
  142. + if(bootverbose) { device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=1\n", __FUNCTION__); }
  143. return error;
  144. }
  145.  
  146. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, false);
  147. - if (error != 0) {
  148. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=0\n", __FUNCTION__);
  149. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, 0);
  150. + if(error != 0) {
  151. + if(bootverbose) { device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=0\n", __FUNCTION__); }
  152. return error;
  153. }
  154.  
  155. @@ -171,22 +177,22 @@ imx6_ahci_phy_read(struct ahci_controller* sc, uint32_
  156. uint32_t v;
  157.  
  158. error = imx6_ahci_phy_addr(sc, addr);
  159. - if (error != 0) {
  160. - device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", __FUNCTION__);
  161. + if(error != 0) {
  162. + if(bootverbose) { device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", __FUNCTION__); }
  163. return error;
  164. }
  165.  
  166. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, true);
  167. - if (error != 0) {
  168. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=1\n", __FUNCTION__);
  169. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, 1);
  170. + if(error != 0) {
  171. + if(bootverbose) { device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=1\n", __FUNCTION__); }
  172. return error;
  173. }
  174.  
  175. v = ATA_INL(sc->r_mem, SATA_P0PHYSR);
  176.  
  177. - error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, false);
  178. - if (error != 0) {
  179. - device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=0\n", __FUNCTION__);
  180. + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, 0);
  181. + if(error != 0) {
  182. + if(bootverbose) { device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=0\n", __FUNCTION__); }
  183. return error;
  184. }
  185.  
  186. @@ -196,11 +202,9 @@ imx6_ahci_phy_read(struct ahci_controller* sc, uint32_
  187. static int
  188. imx6_ahci_probe(device_t dev)
  189. {
  190. - if (!ofw_bus_status_okay(dev))
  191. + if(!ofw_bus_is_compatible(dev, "fsl,imx6q-ahci")) {
  192. return (ENXIO);
  193. - if (!ofw_bus_is_compatible(dev, "fsl,imx6q-ahci"))
  194. - return (ENXIO);
  195. -
  196. + }
  197. device_set_desc(dev, "i.MX6 Integrated AHCI controller");
  198.  
  199. return (BUS_PROBE_DEFAULT);
  200. @@ -211,16 +215,17 @@ imx6_ahci_attach(device_t dev)
  201. {
  202. struct ahci_controller* ctlr;
  203. uint32_t v;
  204. - int error, pllstat, timeout;
  205. + int timeout;
  206. + int pllstat;
  207. + int error;
  208.  
  209. - printf("Got to russells code.");
  210. /*
  211. * Init the device PHY
  212. */
  213. ctlr = device_get_softc(dev);
  214.  
  215. error = imx6_ccm_sataphy_enable();
  216. - if (error != 0) {
  217. + if(error != 0) {
  218. device_printf(dev, "time out resetting AHCI PHY\n");
  219. return error;
  220. }
  221. @@ -231,56 +236,54 @@ imx6_ahci_attach(device_t dev)
  222. ctlr->subdeviceid = 0;
  223. ctlr->numirqs = 1;
  224. ctlr->r_rid = 0;
  225. -
  226. - if ((ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
  227. - &ctlr->r_rid, RF_ACTIVE)) == NULL)
  228. + if(!(ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
  229. + &ctlr->r_rid, RF_ACTIVE))) {
  230. return (ENXIO);
  231. + }
  232.  
  233. - v = imx_iomux_gpr_get(13);
  234. -
  235. - v &= ~(IOMUX_GPR13_SATA_PHY_8(7) |
  236. + v = imx_iomux_gpr_get(IOMUX_GPR13);
  237. + v &= ~(IOMUX_GPR13_SATA_PHY_8(7) |
  238. IOMUX_GPR13_SATA_PHY_7(0x1f) |
  239. - IOMUX_GPR13_SATA_PHY_6(7) |
  240. - IOMUX_GPR13_SATA_SPEED(1) |
  241. - IOMUX_GPR13_SATA_PHY_5(1) |
  242. - IOMUX_GPR13_SATA_PHY_4(7) |
  243. - IOMUX_GPR13_SATA_PHY_3(0xf) |
  244. + IOMUX_GPR13_SATA_PHY_6(7) |
  245. + IOMUX_GPR13_SATA_SPEED(1) |
  246. + IOMUX_GPR13_SATA_PHY_5(1) |
  247. + IOMUX_GPR13_SATA_PHY_4(7) |
  248. + IOMUX_GPR13_SATA_PHY_3(0xf) |
  249. IOMUX_GPR13_SATA_PHY_2(0x1f) |
  250. - IOMUX_GPR13_SATA_PHY_1(1) |
  251. + IOMUX_GPR13_SATA_PHY_1(1) |
  252. IOMUX_GPR13_SATA_PHY_0(1));
  253. /* setting */
  254. - v |= IOMUX_GPR13_SATA_PHY_8(5) | /* Rx 3.0db */
  255. - IOMUX_GPR13_SATA_PHY_7(0x12) | /* Rx SATA2m */
  256. - IOMUX_GPR13_SATA_PHY_6(3) | /* Rx DPLL mode */
  257. - IOMUX_GPR13_SATA_SPEED(1) | /* 3.0GHz */
  258. - IOMUX_GPR13_SATA_PHY_5(0) | /* SpreadSpectram */
  259. - IOMUX_GPR13_SATA_PHY_4(4) | /* Tx Attenuation 9/16 */
  260. - IOMUX_GPR13_SATA_PHY_3(0) | /* Tx Boost 0db */
  261. - IOMUX_GPR13_SATA_PHY_2(0x11) | /* Tx Level 1.104V */
  262. + v |= IOMUX_GPR13_SATA_PHY_8(5) | /* Rx 3.0db */
  263. + IOMUX_GPR13_SATA_PHY_7(0x12) | /* Rx SATA2m */
  264. + IOMUX_GPR13_SATA_PHY_6(3) | /* Rx DPLL mode */
  265. + IOMUX_GPR13_SATA_SPEED(1) | /* 3.0GHz */
  266. + IOMUX_GPR13_SATA_PHY_5(0) | /* SpreadSpectram */
  267. + IOMUX_GPR13_SATA_PHY_4(4) | /* Tx Attenuation 9/16 */
  268. + IOMUX_GPR13_SATA_PHY_3(0) | /* Tx Boost 0db */
  269. + IOMUX_GPR13_SATA_PHY_2(0x11) | /* Tx Level 1.104V */
  270. IOMUX_GPR13_SATA_PHY_1(1); /* PLL clock enable */
  271. -
  272. - imx_iomux_gpr_set(13, v);
  273. + imx_iomux_gpr_set(IOMUX_GPR13, v);
  274.  
  275. /* phy reset */
  276. error = imx6_ahci_phy_write(ctlr, SATA_PHY_CLOCK_RESET,
  277. SATA_PHY_CLOCK_RESET_RST);
  278. - if (error != 0) {
  279. + if(error != 0) {
  280. device_printf(dev, "cannot reset PHY\n");
  281. goto fail;
  282. }
  283.  
  284. - for (timeout = 50; timeout > 0; --timeout) {
  285. + for(timeout = 50; timeout > 0; --timeout) {
  286. DELAY(100);
  287. pllstat = imx6_ahci_phy_read(ctlr, SATA_PHY_LANE0_OUT_STAT);
  288. - if (pllstat < 0) {
  289. + if(pllstat < 0) {
  290. device_printf(dev, "cannot read LANE0 status\n");
  291. break;
  292. }
  293. - if (pllstat & SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE)
  294. + if(pllstat & SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE) {
  295. break;
  296. + }
  297. }
  298. -
  299. - if (timeout <= 0) {
  300. + if(timeout <= 0) {
  301. device_printf(dev, "time out reading LANE0 status\n");
  302. error = ETIMEDOUT;
  303. goto fail;
Advertisement
Add Comment
Please, Sign In to add comment