9 #define AHCI_PHYCS0R 0x00c0
10 #define AHCI_PHYCS1R 0x00c4
11 #define AHCI_PHYCS2R 0x00c8
12 #define AHCI_RWCR 0x00fc
14 /* This magic PHY initialisation was taken from the Allwinner releases
15 * and Linux driver, but is completely undocumented.
17 static int sunxi_ahci_phy_init(u8 *reg_base)
22 writel(0, reg_base + AHCI_RWCR);
25 setbits_le32(reg_base + AHCI_PHYCS1R, 0x1 << 19);
26 clrsetbits_le32(reg_base + AHCI_PHYCS0R,
28 (0x5 << 24) | (0x1 << 23) | (0x1 << 18));
29 clrsetbits_le32(reg_base + AHCI_PHYCS1R,
30 (0x3 << 16) | (0x1f << 8) | (0x3 << 6),
31 (0x2 << 16) | (0x6 << 8) | (0x2 << 6));
32 setbits_le32(reg_base + AHCI_PHYCS1R, (0x1 << 28) | (0x1 << 15));
33 clrbits_le32(reg_base + AHCI_PHYCS1R, (0x1 << 19));
34 clrsetbits_le32(reg_base + AHCI_PHYCS0R, (0x7 << 20), (0x3 << 20));
35 clrsetbits_le32(reg_base + AHCI_PHYCS2R, (0x1f << 5), (0x19 << 5));
38 setbits_le32(reg_base + AHCI_PHYCS0R, (0x1 << 19));
40 timeout = 250; /* Power up takes approx 50 us */
42 reg_val = readl(reg_base + AHCI_PHYCS0R) & (0x7 << 28);
43 if (reg_val == (0x2 << 28))
46 printf("AHCI PHY power up failed.\n");
52 setbits_le32(reg_base + AHCI_PHYCS2R, (0x1 << 24));
54 timeout = 100; /* Calibration takes approx 10 us */
56 reg_val = readl(reg_base + AHCI_PHYCS2R) & (0x1 << 24);
60 printf("AHCI PHY calibration failed.\n");
68 writel(0x7, reg_base + AHCI_RWCR);
73 #ifndef CONFIG_DM_SCSI
76 if (sunxi_ahci_phy_init((u8 *)SUNXI_SATA_BASE) < 0)
79 ahci_init((void __iomem *)SUNXI_SATA_BASE);
82 static int sunxi_sata_probe(struct udevice *dev)
88 base = dev_read_addr(dev);
89 if (base == FDT_ADDR_T_NONE) {
90 debug("%s: Failed to find address (err=%d\n)", __func__, ret);
94 ret = sunxi_ahci_phy_init(reg);
96 debug("%s: Failed to init phy (err=%d\n)", __func__, ret);
99 ret = ahci_probe_scsi(dev, base);
101 debug("%s: Failed to probe (err=%d\n)", __func__, ret);
108 static int sunxi_sata_bind(struct udevice *dev)
110 struct udevice *scsi_dev;
113 ret = ahci_bind_scsi(dev, &scsi_dev);
115 debug("%s: Failed to bind (err=%d\n)", __func__, ret);
122 static const struct udevice_id sunxi_ahci_ids[] = {
123 { .compatible = "allwinner,sun4i-a10-ahci" },
127 U_BOOT_DRIVER(ahci_sunxi_drv) = {
128 .name = "ahci_sunxi",
130 .of_match = sunxi_ahci_ids,
131 .bind = sunxi_sata_bind,
132 .probe = sunxi_sata_probe,