source: src/linux/universal/linux-4.9/drivers/ata/ahci_da850.c @ 31859

Last change on this file since 31859 was 31859, checked in by brainslayer, 3 months ago

kernel update

File size: 4.0 KB
Line 
1/*
2 * DaVinci DA850 AHCI SATA platform driver
3 *
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)
7 * any later version.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/pm.h>
13#include <linux/device.h>
14#include <linux/platform_device.h>
15#include <linux/libata.h>
16#include <linux/ahci_platform.h>
17#include "ahci.h"
18
19#define DRV_NAME "ahci_da850"
20
21/* SATA PHY Control Register offset from AHCI base */
22#define SATA_P0PHYCR_REG        0x178
23
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)
30
31/*
32 * The multiplier needed for 1.5GHz PLL output.
33 *
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.
37 */
38#define DA850_SATA_CLK_MULTIPLIER       7
39
40static void da850_sata_init(struct device *dev, void __iomem *pwrdn_reg,
41                            void __iomem *ahci_base)
42{
43        unsigned int val;
44
45        /* Enable SATA clock receiver */
46        val = readl(pwrdn_reg);
47        val &= ~BIT(0);
48        writel(val, pwrdn_reg);
49
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) |
52              SATA_PHY_ENPLL(1);
53
54        writel(val, ahci_base + SATA_P0PHYCR_REG);
55}
56
57static int ahci_da850_softreset(struct ata_link *link,
58                                unsigned int *class, unsigned long deadline)
59{
60        int pmp, ret;
61
62        pmp = sata_srst_pmp(link);
63
64        /*
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.
70         */
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);
75
76        return ret;
77}
78
79static struct ata_port_operations ahci_da850_port_ops = {
80        .inherits = &ahci_platform_ops,
81        .softreset = ahci_da850_softreset,
82        /*
83         * No need to override .pmp_softreset - it's only used for actual
84         * PMP-enabled ports.
85         */
86};
87
88static const struct ata_port_info ahci_da850_port_info = {
89        .flags          = AHCI_FLAG_COMMON,
90        .pio_mask       = ATA_PIO4,
91        .udma_mask      = ATA_UDMA6,
92        .port_ops       = &ahci_da850_port_ops,
93};
94
95static struct scsi_host_template ahci_platform_sht = {
96        AHCI_SHT(DRV_NAME),
97};
98
99static int ahci_da850_probe(struct platform_device *pdev)
100{
101        struct device *dev = &pdev->dev;
102        struct ahci_host_priv *hpriv;
103        struct resource *res;
104        void __iomem *pwrdn_reg;
105        int rc;
106
107        hpriv = ahci_platform_get_resources(pdev);
108        if (IS_ERR(hpriv))
109                return PTR_ERR(hpriv);
110
111        rc = ahci_platform_enable_resources(hpriv);
112        if (rc)
113                return rc;
114
115        res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
116        if (!res)
117                goto disable_resources;
118
119        pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
120        if (!pwrdn_reg)
121                goto disable_resources;
122
123        da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
124
125        rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
126                                     &ahci_platform_sht);
127        if (rc)
128                goto disable_resources;
129
130        return 0;
131disable_resources:
132        ahci_platform_disable_resources(hpriv);
133        return rc;
134}
135
136static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
137                         ahci_platform_resume);
138
139static struct platform_driver ahci_da850_driver = {
140        .probe = ahci_da850_probe,
141        .remove = ata_platform_remove_one,
142        .driver = {
143                .name = DRV_NAME,
144                .pm = &ahci_da850_pm_ops,
145        },
146};
147module_platform_driver(ahci_da850_driver);
148
149MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
150MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
151MODULE_LICENSE("GPL");
Note: See TracBrowser for help on using the repository browser.