blob: 58f8fd7bb8b8b67893383afa497300840fdb4d4a [file] [log] [blame]
Thomas Gleixner3e0a4e82019-05-23 11:14:55 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Brian Norris766a2d92015-05-12 16:28:21 -07002/*
3 * Broadcom SATA3 AHCI Controller Driver
4 *
5 * Copyright © 2009-2015 Broadcom Corporation
Brian Norris766a2d92015-05-12 16:28:21 -07006 */
7
8#include <linux/ahci_platform.h>
9#include <linux/compiler.h>
10#include <linux/device.h>
11#include <linux/init.h>
12#include <linux/interrupt.h>
13#include <linux/io.h>
14#include <linux/kernel.h>
15#include <linux/libata.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/platform_device.h>
Florian Fainelli2b2c47d2018-10-01 10:33:00 -070019#include <linux/reset.h>
Brian Norris766a2d92015-05-12 16:28:21 -070020#include <linux/string.h>
21
22#include "ahci.h"
23
24#define DRV_NAME "brcm-ahci"
25
26#define SATA_TOP_CTRL_VERSION 0x0
27#define SATA_TOP_CTRL_BUS_CTRL 0x4
28 #define MMIO_ENDIAN_SHIFT 0 /* CPU->AHCI */
29 #define DMADESC_ENDIAN_SHIFT 2 /* AHCI->DDR */
30 #define DMADATA_ENDIAN_SHIFT 4 /* AHCI->DDR */
31 #define PIODATA_ENDIAN_SHIFT 6
32 #define ENDIAN_SWAP_NONE 0
33 #define ENDIAN_SWAP_FULL 2
Brian Norris766a2d92015-05-12 16:28:21 -070034#define SATA_TOP_CTRL_TP_CTRL 0x8
35#define SATA_TOP_CTRL_PHY_CTRL 0xc
36 #define SATA_TOP_CTRL_PHY_CTRL_1 0x0
37 #define SATA_TOP_CTRL_1_PHY_DEFAULT_POWER_STATE BIT(14)
38 #define SATA_TOP_CTRL_PHY_CTRL_2 0x4
39 #define SATA_TOP_CTRL_2_SW_RST_MDIOREG BIT(0)
40 #define SATA_TOP_CTRL_2_SW_RST_OOB BIT(1)
41 #define SATA_TOP_CTRL_2_SW_RST_RX BIT(2)
42 #define SATA_TOP_CTRL_2_SW_RST_TX BIT(3)
43 #define SATA_TOP_CTRL_2_PHY_GLOBAL_RESET BIT(14)
44 #define SATA_TOP_CTRL_PHY_OFFS 0x8
45 #define SATA_TOP_MAX_PHYS 2
Brian Norris766a2d92015-05-12 16:28:21 -070046
Danesh Petigara6863caa2016-01-07 16:03:30 -080047#define SATA_FIRST_PORT_CTRL 0x700
48#define SATA_NEXT_PORT_CTRL_OFFSET 0x80
49#define SATA_PORT_PCTRL6(reg_base) (reg_base + 0x18)
50
Brian Norris766a2d92015-05-12 16:28:21 -070051/* On big-endian MIPS, buses are reversed to big endian, so switch them back */
52#if defined(CONFIG_MIPS) && defined(__BIG_ENDIAN)
53#define DATA_ENDIAN 2 /* AHCI->DDR inbound accesses */
54#define MMIO_ENDIAN 2 /* CPU->AHCI outbound accesses */
55#else
56#define DATA_ENDIAN 0
57#define MMIO_ENDIAN 0
58#endif
59
60#define BUS_CTRL_ENDIAN_CONF \
61 ((DATA_ENDIAN << DMADATA_ENDIAN_SHIFT) | \
62 (DATA_ENDIAN << DMADESC_ENDIAN_SHIFT) | \
63 (MMIO_ENDIAN << MMIO_ENDIAN_SHIFT))
64
Florian Fainelli36fffd62017-12-22 11:43:08 -080065#define BUS_CTRL_ENDIAN_NSP_CONF \
66 (0x02 << DMADATA_ENDIAN_SHIFT | 0x02 << DMADESC_ENDIAN_SHIFT)
67
68#define BUS_CTRL_ENDIAN_CONF_MASK \
69 (0x3 << MMIO_ENDIAN_SHIFT | 0x3 << DMADESC_ENDIAN_SHIFT | \
70 0x3 << DMADATA_ENDIAN_SHIFT | 0x3 << PIODATA_ENDIAN_SHIFT)
71
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -040072enum brcm_ahci_version {
73 BRCM_SATA_BCM7425 = 1,
74 BRCM_SATA_BCM7445,
75 BRCM_SATA_NSP,
76};
77
Jaedon Shin7de32442015-11-26 11:56:30 +090078enum brcm_ahci_quirks {
Florian Fainelli1a3d78c2019-12-10 10:53:46 -080079 BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE = BIT(0),
Jaedon Shin7de32442015-11-26 11:56:30 +090080};
81
Brian Norris766a2d92015-05-12 16:28:21 -070082struct brcm_ahci_priv {
83 struct device *dev;
84 void __iomem *top_ctrl;
85 u32 port_mask;
Jaedon Shin7de32442015-11-26 11:56:30 +090086 u32 quirks;
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -040087 enum brcm_ahci_version version;
Florian Fainelli2b2c47d2018-10-01 10:33:00 -070088 struct reset_control *rcdev;
Brian Norris766a2d92015-05-12 16:28:21 -070089};
90
Brian Norris766a2d92015-05-12 16:28:21 -070091static inline u32 brcm_sata_readreg(void __iomem *addr)
92{
93 /*
94 * MIPS endianness is configured by boot strap, which also reverses all
95 * bus endianness (i.e., big-endian CPU + big endian bus ==> native
96 * endian I/O).
97 *
98 * Other architectures (e.g., ARM) either do not support big endian, or
99 * else leave I/O in little endian mode.
100 */
Axel Linf9114d32015-08-06 12:28:18 +0800101 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
Brian Norris766a2d92015-05-12 16:28:21 -0700102 return __raw_readl(addr);
103 else
104 return readl_relaxed(addr);
105}
106
107static inline void brcm_sata_writereg(u32 val, void __iomem *addr)
108{
109 /* See brcm_sata_readreg() comments */
Axel Linf9114d32015-08-06 12:28:18 +0800110 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
Brian Norris766a2d92015-05-12 16:28:21 -0700111 __raw_writel(val, addr);
112 else
113 writel_relaxed(val, addr);
114}
115
Danesh Petigara6863caa2016-01-07 16:03:30 -0800116static void brcm_sata_alpm_init(struct ahci_host_priv *hpriv)
117{
118 struct brcm_ahci_priv *priv = hpriv->plat_data;
Doug Bergerda8fa9c2017-06-21 16:20:14 -0700119 u32 port_ctrl, host_caps;
Danesh Petigara6863caa2016-01-07 16:03:30 -0800120 int i;
121
122 /* Enable support for ALPM */
Danesh Petigara6863caa2016-01-07 16:03:30 -0800123 host_caps = readl(hpriv->mmio + HOST_CAP);
Doug Bergerda8fa9c2017-06-21 16:20:14 -0700124 if (!(host_caps & HOST_CAP_ALPM))
125 hpriv->flags |= AHCI_HFLAG_YES_ALPM;
Danesh Petigara6863caa2016-01-07 16:03:30 -0800126
127 /*
128 * Adjust timeout to allow PLL sufficient time to lock while waking
129 * up from slumber mode.
130 */
131 for (i = 0, port_ctrl = SATA_FIRST_PORT_CTRL;
132 i < SATA_TOP_MAX_PHYS;
133 i++, port_ctrl += SATA_NEXT_PORT_CTRL_OFFSET) {
134 if (priv->port_mask & BIT(i))
135 writel(0xff1003fc,
136 hpriv->mmio + SATA_PORT_PCTRL6(port_ctrl));
137 }
138}
139
Brian Norris766a2d92015-05-12 16:28:21 -0700140static void brcm_sata_phy_enable(struct brcm_ahci_priv *priv, int port)
141{
142 void __iomem *phyctrl = priv->top_ctrl + SATA_TOP_CTRL_PHY_CTRL +
143 (port * SATA_TOP_CTRL_PHY_OFFS);
144 void __iomem *p;
145 u32 reg;
146
Jaedon Shinb46f79b2015-11-26 11:56:31 +0900147 if (priv->quirks & BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE)
148 return;
149
Brian Norris766a2d92015-05-12 16:28:21 -0700150 /* clear PHY_DEFAULT_POWER_STATE */
151 p = phyctrl + SATA_TOP_CTRL_PHY_CTRL_1;
152 reg = brcm_sata_readreg(p);
153 reg &= ~SATA_TOP_CTRL_1_PHY_DEFAULT_POWER_STATE;
154 brcm_sata_writereg(reg, p);
155
156 /* reset the PHY digital logic */
157 p = phyctrl + SATA_TOP_CTRL_PHY_CTRL_2;
158 reg = brcm_sata_readreg(p);
159 reg &= ~(SATA_TOP_CTRL_2_SW_RST_MDIOREG | SATA_TOP_CTRL_2_SW_RST_OOB |
160 SATA_TOP_CTRL_2_SW_RST_RX);
161 reg |= SATA_TOP_CTRL_2_SW_RST_TX;
162 brcm_sata_writereg(reg, p);
163 reg = brcm_sata_readreg(p);
164 reg |= SATA_TOP_CTRL_2_PHY_GLOBAL_RESET;
165 brcm_sata_writereg(reg, p);
166 reg = brcm_sata_readreg(p);
167 reg &= ~SATA_TOP_CTRL_2_PHY_GLOBAL_RESET;
168 brcm_sata_writereg(reg, p);
169 (void)brcm_sata_readreg(p);
170}
171
172static void brcm_sata_phy_disable(struct brcm_ahci_priv *priv, int port)
173{
174 void __iomem *phyctrl = priv->top_ctrl + SATA_TOP_CTRL_PHY_CTRL +
175 (port * SATA_TOP_CTRL_PHY_OFFS);
176 void __iomem *p;
177 u32 reg;
178
Jaedon Shinb46f79b2015-11-26 11:56:31 +0900179 if (priv->quirks & BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE)
180 return;
181
Brian Norris766a2d92015-05-12 16:28:21 -0700182 /* power-off the PHY digital logic */
183 p = phyctrl + SATA_TOP_CTRL_PHY_CTRL_2;
184 reg = brcm_sata_readreg(p);
185 reg |= (SATA_TOP_CTRL_2_SW_RST_MDIOREG | SATA_TOP_CTRL_2_SW_RST_OOB |
186 SATA_TOP_CTRL_2_SW_RST_RX | SATA_TOP_CTRL_2_SW_RST_TX |
187 SATA_TOP_CTRL_2_PHY_GLOBAL_RESET);
188 brcm_sata_writereg(reg, p);
189
190 /* set PHY_DEFAULT_POWER_STATE */
191 p = phyctrl + SATA_TOP_CTRL_PHY_CTRL_1;
192 reg = brcm_sata_readreg(p);
193 reg |= SATA_TOP_CTRL_1_PHY_DEFAULT_POWER_STATE;
194 brcm_sata_writereg(reg, p);
195}
196
197static void brcm_sata_phys_enable(struct brcm_ahci_priv *priv)
198{
199 int i;
200
201 for (i = 0; i < SATA_TOP_MAX_PHYS; i++)
202 if (priv->port_mask & BIT(i))
203 brcm_sata_phy_enable(priv, i);
204}
205
206static void brcm_sata_phys_disable(struct brcm_ahci_priv *priv)
207{
208 int i;
209
210 for (i = 0; i < SATA_TOP_MAX_PHYS; i++)
211 if (priv->port_mask & BIT(i))
212 brcm_sata_phy_disable(priv, i);
213}
214
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800215static u32 brcm_ahci_get_portmask(struct ahci_host_priv *hpriv,
Brian Norris766a2d92015-05-12 16:28:21 -0700216 struct brcm_ahci_priv *priv)
217{
Brian Norris766a2d92015-05-12 16:28:21 -0700218 u32 impl;
219
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800220 impl = readl(hpriv->mmio + HOST_PORTS_IMPL);
Brian Norris766a2d92015-05-12 16:28:21 -0700221
222 if (fls(impl) > SATA_TOP_MAX_PHYS)
223 dev_warn(priv->dev, "warning: more ports than PHYs (%#x)\n",
224 impl);
225 else if (!impl)
226 dev_info(priv->dev, "no ports found\n");
227
Brian Norris766a2d92015-05-12 16:28:21 -0700228 return impl;
229}
230
231static void brcm_sata_init(struct brcm_ahci_priv *priv)
232{
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400233 void __iomem *ctrl = priv->top_ctrl + SATA_TOP_CTRL_BUS_CTRL;
Florian Fainelli36fffd62017-12-22 11:43:08 -0800234 u32 data;
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400235
Brian Norris766a2d92015-05-12 16:28:21 -0700236 /* Configure endianness */
Florian Fainelli36fffd62017-12-22 11:43:08 -0800237 data = brcm_sata_readreg(ctrl);
238 data &= ~BUS_CTRL_ENDIAN_CONF_MASK;
239 if (priv->version == BRCM_SATA_NSP)
240 data |= BUS_CTRL_ENDIAN_NSP_CONF;
241 else
242 data |= BUS_CTRL_ENDIAN_CONF;
243 brcm_sata_writereg(data, ctrl);
Brian Norris766a2d92015-05-12 16:28:21 -0700244}
245
Florian Fainellieb733902018-01-11 17:31:08 -0800246static unsigned int brcm_ahci_read_id(struct ata_device *dev,
247 struct ata_taskfile *tf, u16 *id)
248{
249 struct ata_port *ap = dev->link->ap;
250 struct ata_host *host = ap->host;
251 struct ahci_host_priv *hpriv = host->private_data;
252 struct brcm_ahci_priv *priv = hpriv->plat_data;
253 void __iomem *mmio = hpriv->mmio;
254 unsigned int err_mask;
255 unsigned long flags;
256 int i, rc;
257 u32 ctl;
258
259 /* Try to read the device ID and, if this fails, proceed with the
260 * recovery sequence below
261 */
262 err_mask = ata_do_dev_read_id(dev, tf, id);
263 if (likely(!err_mask))
264 return err_mask;
265
266 /* Disable host interrupts */
267 spin_lock_irqsave(&host->lock, flags);
268 ctl = readl(mmio + HOST_CTL);
269 ctl &= ~HOST_IRQ_EN;
270 writel(ctl, mmio + HOST_CTL);
271 readl(mmio + HOST_CTL); /* flush */
272 spin_unlock_irqrestore(&host->lock, flags);
273
274 /* Perform the SATA PHY reset sequence */
275 brcm_sata_phy_disable(priv, ap->port_no);
276
277 /* Bring the PHY back on */
278 brcm_sata_phy_enable(priv, ap->port_no);
279
280 /* Re-initialize and calibrate the PHY */
281 for (i = 0; i < hpriv->nports; i++) {
282 rc = phy_init(hpriv->phys[i]);
283 if (rc)
284 goto disable_phys;
285
286 rc = phy_calibrate(hpriv->phys[i]);
287 if (rc) {
288 phy_exit(hpriv->phys[i]);
289 goto disable_phys;
290 }
291 }
292
293 /* Re-enable host interrupts */
294 spin_lock_irqsave(&host->lock, flags);
295 ctl = readl(mmio + HOST_CTL);
296 ctl |= HOST_IRQ_EN;
297 writel(ctl, mmio + HOST_CTL);
298 readl(mmio + HOST_CTL); /* flush */
299 spin_unlock_irqrestore(&host->lock, flags);
300
301 return ata_do_dev_read_id(dev, tf, id);
302
303disable_phys:
304 while (--i >= 0) {
305 phy_power_off(hpriv->phys[i]);
306 phy_exit(hpriv->phys[i]);
307 }
308
309 return AC_ERR_OTHER;
310}
311
312static void brcm_ahci_host_stop(struct ata_host *host)
313{
314 struct ahci_host_priv *hpriv = host->private_data;
315
316 ahci_platform_disable_resources(hpriv);
317}
318
319static struct ata_port_operations ahci_brcm_platform_ops = {
320 .inherits = &ahci_ops,
321 .host_stop = brcm_ahci_host_stop,
322 .read_id = brcm_ahci_read_id,
323};
324
325static const struct ata_port_info ahci_brcm_port_info = {
326 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM,
327 .link_flags = ATA_LFLAG_NO_DB_DELAY,
328 .pio_mask = ATA_PIO4,
329 .udma_mask = ATA_UDMA6,
330 .port_ops = &ahci_brcm_platform_ops,
331};
332
Florian Fainelli8b34fe52015-07-14 13:03:33 -0700333#ifdef CONFIG_PM_SLEEP
Brian Norris766a2d92015-05-12 16:28:21 -0700334static int brcm_ahci_suspend(struct device *dev)
335{
336 struct ata_host *host = dev_get_drvdata(dev);
337 struct ahci_host_priv *hpriv = host->private_data;
338 struct brcm_ahci_priv *priv = hpriv->plat_data;
Brian Norris766a2d92015-05-12 16:28:21 -0700339
Brian Norris766a2d92015-05-12 16:28:21 -0700340 brcm_sata_phys_disable(priv);
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800341
342 return ahci_platform_suspend(dev);
Brian Norris766a2d92015-05-12 16:28:21 -0700343}
344
345static int brcm_ahci_resume(struct device *dev)
346{
347 struct ata_host *host = dev_get_drvdata(dev);
348 struct ahci_host_priv *hpriv = host->private_data;
349 struct brcm_ahci_priv *priv = hpriv->plat_data;
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800350 int ret;
351
352 /* Make sure clocks are turned on before re-configuration */
353 ret = ahci_platform_enable_clks(hpriv);
354 if (ret)
355 return ret;
Brian Norris766a2d92015-05-12 16:28:21 -0700356
357 brcm_sata_init(priv);
358 brcm_sata_phys_enable(priv);
Danesh Petigara6863caa2016-01-07 16:03:30 -0800359 brcm_sata_alpm_init(hpriv);
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800360
361 /* Since we had to enable clocks earlier on, we cannot use
362 * ahci_platform_resume() as-is since a second call to
363 * ahci_platform_enable_resources() would bump up the resources
364 * (regulators, clocks, PHYs) count artificially so we copy the part
365 * after ahci_platform_enable_resources().
366 */
367 ret = ahci_platform_enable_phys(hpriv);
368 if (ret)
369 goto out_disable_phys;
370
371 ret = ahci_platform_resume_host(dev);
372 if (ret)
373 goto out_disable_platform_phys;
374
375 /* We resumed so update PM runtime state */
376 pm_runtime_disable(dev);
377 pm_runtime_set_active(dev);
378 pm_runtime_enable(dev);
379
380 return 0;
381
382out_disable_platform_phys:
383 ahci_platform_disable_phys(hpriv);
384out_disable_phys:
385 brcm_sata_phys_disable(priv);
386 ahci_platform_disable_clks(hpriv);
387 return ret;
Brian Norris766a2d92015-05-12 16:28:21 -0700388}
Florian Fainelli8b34fe52015-07-14 13:03:33 -0700389#endif
Brian Norris766a2d92015-05-12 16:28:21 -0700390
391static struct scsi_host_template ahci_platform_sht = {
392 AHCI_SHT(DRV_NAME),
393};
394
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400395static const struct of_device_id ahci_of_match[] = {
396 {.compatible = "brcm,bcm7425-ahci", .data = (void *)BRCM_SATA_BCM7425},
397 {.compatible = "brcm,bcm7445-ahci", .data = (void *)BRCM_SATA_BCM7445},
Florian Fainellifb8506f2018-10-01 10:33:01 -0700398 {.compatible = "brcm,bcm63138-ahci", .data = (void *)BRCM_SATA_BCM7445},
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400399 {.compatible = "brcm,bcm-nsp-ahci", .data = (void *)BRCM_SATA_NSP},
400 {},
401};
402MODULE_DEVICE_TABLE(of, ahci_of_match);
403
Brian Norris766a2d92015-05-12 16:28:21 -0700404static int brcm_ahci_probe(struct platform_device *pdev)
405{
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400406 const struct of_device_id *of_id;
Brian Norris766a2d92015-05-12 16:28:21 -0700407 struct device *dev = &pdev->dev;
408 struct brcm_ahci_priv *priv;
409 struct ahci_host_priv *hpriv;
410 struct resource *res;
411 int ret;
412
413 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
414 if (!priv)
415 return -ENOMEM;
Yendapally Reddy Dhananjaya Reddy3ee2e6d2016-06-16 09:53:33 -0400416
417 of_id = of_match_node(ahci_of_match, pdev->dev.of_node);
418 if (!of_id)
419 return -ENODEV;
420
421 priv->version = (enum brcm_ahci_version)of_id->data;
Brian Norris766a2d92015-05-12 16:28:21 -0700422 priv->dev = dev;
423
424 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "top-ctrl");
425 priv->top_ctrl = devm_ioremap_resource(dev, res);
426 if (IS_ERR(priv->top_ctrl))
427 return PTR_ERR(priv->top_ctrl);
428
Florian Fainelli2b2c47d2018-10-01 10:33:00 -0700429 /* Reset is optional depending on platform */
430 priv->rcdev = devm_reset_control_get(&pdev->dev, "ahci");
431 if (!IS_ERR_OR_NULL(priv->rcdev))
432 reset_control_deassert(priv->rcdev);
433
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800434 hpriv = ahci_platform_get_resources(pdev, 0);
435 if (IS_ERR(hpriv)) {
436 ret = PTR_ERR(hpriv);
437 goto out_reset;
438 }
439
Florian Fainelli1a3d78c2019-12-10 10:53:46 -0800440 hpriv->plat_data = priv;
441 hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP | AHCI_HFLAG_NO_WRITE_TO_RO;
442
443 switch (priv->version) {
444 case BRCM_SATA_BCM7425:
445 hpriv->flags |= AHCI_HFLAG_DELAY_ENGINE;
446 /* fall through */
447 case BRCM_SATA_NSP:
448 hpriv->flags |= AHCI_HFLAG_NO_NCQ;
449 priv->quirks |= BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE;
450 break;
451 default:
452 break;
453 }
454
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800455 ret = ahci_platform_enable_clks(hpriv);
456 if (ret)
457 goto out_reset;
458
459 /* Must be first so as to configure endianness including that
460 * of the standard AHCI register space.
461 */
Brian Norris766a2d92015-05-12 16:28:21 -0700462 brcm_sata_init(priv);
463
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800464 /* Initializes priv->port_mask which is used below */
465 priv->port_mask = brcm_ahci_get_portmask(hpriv, priv);
466 if (!priv->port_mask) {
467 ret = -ENODEV;
468 goto out_disable_clks;
469 }
Brian Norris766a2d92015-05-12 16:28:21 -0700470
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800471 /* Must be done before ahci_platform_enable_phys() */
Brian Norris766a2d92015-05-12 16:28:21 -0700472 brcm_sata_phys_enable(priv);
473
Danesh Petigara6863caa2016-01-07 16:03:30 -0800474 brcm_sata_alpm_init(hpriv);
475
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800476 ret = ahci_platform_enable_phys(hpriv);
477 if (ret)
478 goto out_disable_phys;
479
Brian Norris766a2d92015-05-12 16:28:21 -0700480 ret = ahci_platform_init_host(pdev, hpriv, &ahci_brcm_port_info,
481 &ahci_platform_sht);
482 if (ret)
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800483 goto out_disable_platform_phys;
Brian Norris766a2d92015-05-12 16:28:21 -0700484
485 dev_info(dev, "Broadcom AHCI SATA3 registered\n");
486
487 return 0;
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800488
489out_disable_platform_phys:
490 ahci_platform_disable_phys(hpriv);
491out_disable_phys:
492 brcm_sata_phys_disable(priv);
493out_disable_clks:
494 ahci_platform_disable_clks(hpriv);
495out_reset:
496 if (!IS_ERR_OR_NULL(priv->rcdev))
497 reset_control_assert(priv->rcdev);
498 return ret;
Brian Norris766a2d92015-05-12 16:28:21 -0700499}
500
501static int brcm_ahci_remove(struct platform_device *pdev)
502{
503 struct ata_host *host = dev_get_drvdata(&pdev->dev);
504 struct ahci_host_priv *hpriv = host->private_data;
505 struct brcm_ahci_priv *priv = hpriv->plat_data;
506 int ret;
507
Florian Fainellic0cdf2a2019-12-10 10:53:45 -0800508 brcm_sata_phys_disable(priv);
509
Brian Norris766a2d92015-05-12 16:28:21 -0700510 ret = ata_platform_remove_one(pdev);
511 if (ret)
512 return ret;
513
Brian Norris766a2d92015-05-12 16:28:21 -0700514 return 0;
515}
516
Brian Norris766a2d92015-05-12 16:28:21 -0700517static SIMPLE_DEV_PM_OPS(ahci_brcm_pm_ops, brcm_ahci_suspend, brcm_ahci_resume);
518
519static struct platform_driver brcm_ahci_driver = {
520 .probe = brcm_ahci_probe,
521 .remove = brcm_ahci_remove,
522 .driver = {
523 .name = DRV_NAME,
524 .of_match_table = ahci_of_match,
525 .pm = &ahci_brcm_pm_ops,
526 },
527};
528module_platform_driver(brcm_ahci_driver);
529
530MODULE_DESCRIPTION("Broadcom SATA3 AHCI Controller Driver");
531MODULE_AUTHOR("Brian Norris");
532MODULE_LICENSE("GPL");
533MODULE_ALIAS("platform:sata-brcmstb");