2 * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <linux/clk.h>
23 #include <linux/err.h>
24 #include <linux/device.h>
25 #include <linux/dma-mapping.h>
26 #include <asm/sizes.h>
28 #include "../hardware.h"
29 #include "devices-common.h"
31 #define imx_ahci_imx_data_entry_single(soc, _devid) \
34 .iobase = soc ## _SATA_BASE_ADDR, \
35 .irq = soc ## _INT_SATA, \
38 #ifdef CONFIG_SOC_IMX53
39 const struct imx_ahci_imx_data imx53_ahci_imx_data __initconst
=
40 imx_ahci_imx_data_entry_single(MX53
, "imx53-ahci");
45 HOST_CAP_SSS
= (1 << 27), /* Staggered Spin-up */
46 HOST_PORTS_IMPL
= 0x0c,
47 HOST_TIMER1MS
= 0xe0, /* Timer 1-ms */
50 static struct clk
*sata_clk
, *sata_ref_clk
;
52 /* AHCI module Initialization, if return 0, initialization is successful. */
53 static int imx_sata_init(struct device
*dev
, void __iomem
*addr
)
59 sata_clk
= clk_get(dev
, "ahci");
60 if (IS_ERR(sata_clk
)) {
61 dev_err(dev
, "no sata clock.\n");
62 return PTR_ERR(sata_clk
);
64 ret
= clk_prepare_enable(sata_clk
);
66 dev_err(dev
, "can't prepare/enable sata clock.\n");
70 /* Get the AHCI SATA PHY CLK */
71 sata_ref_clk
= clk_get(dev
, "ahci_phy");
72 if (IS_ERR(sata_ref_clk
)) {
73 dev_err(dev
, "no sata ref clock.\n");
74 ret
= PTR_ERR(sata_ref_clk
);
75 goto release_sata_clk
;
77 ret
= clk_prepare_enable(sata_ref_clk
);
79 dev_err(dev
, "can't prepare/enable sata ref clock.\n");
80 goto put_sata_ref_clk
;
83 /* Get the AHB clock rate, and configure the TIMER1MS reg later */
84 clk
= clk_get(dev
, "ahci_dma");
86 dev_err(dev
, "no dma clock.\n");
88 goto release_sata_ref_clk
;
90 tmpdata
= clk_get_rate(clk
) / 1000;
93 writel(tmpdata
, addr
+ HOST_TIMER1MS
);
95 tmpdata
= readl(addr
+ HOST_CAP
);
96 if (!(tmpdata
& HOST_CAP_SSS
)) {
97 tmpdata
|= HOST_CAP_SSS
;
98 writel(tmpdata
, addr
+ HOST_CAP
);
101 if (!(readl(addr
+ HOST_PORTS_IMPL
) & 0x1))
102 writel((readl(addr
+ HOST_PORTS_IMPL
) | 0x1),
103 addr
+ HOST_PORTS_IMPL
);
107 release_sata_ref_clk
:
108 clk_disable_unprepare(sata_ref_clk
);
110 clk_put(sata_ref_clk
);
112 clk_disable_unprepare(sata_clk
);
119 static void imx_sata_exit(struct device
*dev
)
121 clk_disable_unprepare(sata_ref_clk
);
122 clk_put(sata_ref_clk
);
124 clk_disable_unprepare(sata_clk
);
128 struct platform_device
*__init
imx_add_ahci_imx(
129 const struct imx_ahci_imx_data
*data
,
130 const struct ahci_platform_data
*pdata
)
132 struct resource res
[] = {
134 .start
= data
->iobase
,
135 .end
= data
->iobase
+ SZ_4K
- 1,
136 .flags
= IORESOURCE_MEM
,
140 .flags
= IORESOURCE_IRQ
,
144 return imx_add_platform_device_dmamask(data
->devid
, 0,
145 res
, ARRAY_SIZE(res
),
146 pdata
, sizeof(*pdata
), DMA_BIT_MASK(32));
149 struct platform_device
*__init
imx53_add_ahci_imx(void)
151 struct ahci_platform_data pdata
= {
152 .init
= imx_sata_init
,
153 .exit
= imx_sata_exit
,
156 return imx_add_ahci_imx(&imx53_ahci_imx_data
, &pdata
);