2 * DaVinci DA850 AHCI SATA platform driver
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/platform_device.h>
15 #include <linux/libata.h>
16 #include <linux/ahci_platform.h>
19 #define DRV_NAME "ahci_da850"
21 /* SATA PHY Control Register offset from AHCI base */
22 #define SATA_P0PHYCR_REG 0x178
24 #define SATA_PHY_MPY(x) ((x) << 0)
25 #define SATA_PHY_LOS(x) ((x) << 6)
26 #define SATA_PHY_RXCDR(x) ((x) << 10)
27 #define SATA_PHY_RXEQ(x) ((x) << 13)
28 #define SATA_PHY_TXSWING(x) ((x) << 19)
29 #define SATA_PHY_ENPLL(x) ((x) << 31)
32 * The multiplier needed for 1.5GHz PLL output.
34 * NOTE: This is currently hardcoded to be suitable for 100MHz crystal
35 * frequency (which is used by DA850 EVM board) and may need to be changed
36 * if you would like to use this driver on some other board.
38 #define DA850_SATA_CLK_MULTIPLIER 7
40 static void da850_sata_init(struct device *dev, void __iomem *pwrdn_reg,
41 void __iomem *ahci_base)
45 /* Enable SATA clock receiver */
46 val = readl(pwrdn_reg);
48 writel(val, pwrdn_reg);
50 val = SATA_PHY_MPY(DA850_SATA_CLK_MULTIPLIER + 1) | SATA_PHY_LOS(1) |
51 SATA_PHY_RXCDR(4) | SATA_PHY_RXEQ(1) | SATA_PHY_TXSWING(3) |
54 writel(val, ahci_base + SATA_P0PHYCR_REG);
57 static int ahci_da850_softreset(struct ata_link *link,
58 unsigned int *class, unsigned long deadline)
62 pmp = sata_srst_pmp(link);
65 * There's an issue with the SATA controller on da850 SoCs: if we
66 * enable Port Multiplier support, but the drive is connected directly
67 * to the board, it can't be detected. As a workaround: if PMP is
68 * enabled, we first call ahci_do_softreset() and pass it the result of
69 * sata_srst_pmp(). If this call fails, we retry with pmp = 0.
71 ret = ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
72 if (pmp && ret == -EBUSY)
73 return ahci_do_softreset(link, class, 0,
74 deadline, ahci_check_ready);
79 static struct ata_port_operations ahci_da850_port_ops = {
80 .inherits = &ahci_platform_ops,
81 .softreset = ahci_da850_softreset,
83 * No need to override .pmp_softreset - it's only used for actual
88 static const struct ata_port_info ahci_da850_port_info = {
89 .flags = AHCI_FLAG_COMMON,
91 .udma_mask = ATA_UDMA6,
92 .port_ops = &ahci_da850_port_ops,
95 static struct scsi_host_template ahci_platform_sht = {
99 static int ahci_da850_probe(struct platform_device *pdev)
101 struct device *dev = &pdev->dev;
102 struct ahci_host_priv *hpriv;
103 struct resource *res;
104 void __iomem *pwrdn_reg;
107 hpriv = ahci_platform_get_resources(pdev);
109 return PTR_ERR(hpriv);
111 rc = ahci_platform_enable_resources(hpriv);
115 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
117 goto disable_resources;
119 pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
121 goto disable_resources;
123 da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
125 rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
128 goto disable_resources;
132 ahci_platform_disable_resources(hpriv);
136 static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
137 ahci_platform_resume);
139 static struct platform_driver ahci_da850_driver = {
140 .probe = ahci_da850_probe,
141 .remove = ata_platform_remove_one,
144 .pm = &ahci_da850_pm_ops,
147 module_platform_driver(ahci_da850_driver);
149 MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
150 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
151 MODULE_LICENSE("GPL");