2 * Copyright (C) 2012 STMicroelectronics Limited
4 * Authors: Francesco Virlinzi <francesco.virlinzi@st.com>
5 * Alexandre Torgue <alexandre.torgue@st.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/export.h>
15 #include <linux/platform_device.h>
16 #include <linux/clk.h>
18 #include <linux/ahci_platform.h>
19 #include <linux/libata.h>
20 #include <linux/reset.h>
22 #include <linux/dma-mapping.h>
26 #define DRV_NAME "st_ahci"
28 #define ST_AHCI_OOBR 0xbc
29 #define ST_AHCI_OOBR_WE BIT(31)
30 #define ST_AHCI_OOBR_CWMIN_SHIFT 24
31 #define ST_AHCI_OOBR_CWMAX_SHIFT 16
32 #define ST_AHCI_OOBR_CIMIN_SHIFT 8
33 #define ST_AHCI_OOBR_CIMAX_SHIFT 0
35 struct st_ahci_drv_data
{
36 struct platform_device
*ahci
;
37 struct reset_control
*pwr
;
38 struct reset_control
*sw_rst
;
39 struct reset_control
*pwr_rst
;
40 struct ahci_host_priv
*hpriv
;
43 static void st_ahci_configure_oob(void __iomem
*mmio
)
45 unsigned long old_val
, new_val
;
47 new_val
= (0x02 << ST_AHCI_OOBR_CWMIN_SHIFT
) |
48 (0x04 << ST_AHCI_OOBR_CWMAX_SHIFT
) |
49 (0x08 << ST_AHCI_OOBR_CIMIN_SHIFT
) |
50 (0x0C << ST_AHCI_OOBR_CIMAX_SHIFT
);
52 old_val
= readl(mmio
+ ST_AHCI_OOBR
);
53 writel(old_val
| ST_AHCI_OOBR_WE
, mmio
+ ST_AHCI_OOBR
);
54 writel(new_val
| ST_AHCI_OOBR_WE
, mmio
+ ST_AHCI_OOBR
);
55 writel(new_val
, mmio
+ ST_AHCI_OOBR
);
58 static int st_ahci_deassert_resets(struct device
*dev
)
60 struct st_ahci_drv_data
*drv_data
= dev_get_drvdata(dev
);
64 err
= reset_control_deassert(drv_data
->pwr
);
66 dev_err(dev
, "unable to bring out of pwrdwn\n");
71 st_ahci_configure_oob(drv_data
->hpriv
->mmio
);
73 if (drv_data
->sw_rst
) {
74 err
= reset_control_deassert(drv_data
->sw_rst
);
76 dev_err(dev
, "unable to bring out of sw-rst\n");
81 if (drv_data
->pwr_rst
) {
82 err
= reset_control_deassert(drv_data
->pwr_rst
);
84 dev_err(dev
, "unable to bring out of pwr-rst\n");
92 static void st_ahci_host_stop(struct ata_host
*host
)
94 struct ahci_host_priv
*hpriv
= host
->private_data
;
95 struct device
*dev
= host
->dev
;
96 struct st_ahci_drv_data
*drv_data
= dev_get_drvdata(dev
);
100 err
= reset_control_assert(drv_data
->pwr
);
102 dev_err(dev
, "unable to pwrdwn\n");
105 ahci_platform_disable_resources(hpriv
);
108 static int st_ahci_probe_resets(struct platform_device
*pdev
)
110 struct st_ahci_drv_data
*drv_data
= platform_get_drvdata(pdev
);
112 drv_data
->pwr
= devm_reset_control_get(&pdev
->dev
, "pwr-dwn");
113 if (IS_ERR(drv_data
->pwr
)) {
114 dev_info(&pdev
->dev
, "power reset control not defined\n");
115 drv_data
->pwr
= NULL
;
118 drv_data
->sw_rst
= devm_reset_control_get(&pdev
->dev
, "sw-rst");
119 if (IS_ERR(drv_data
->sw_rst
)) {
120 dev_info(&pdev
->dev
, "soft reset control not defined\n");
121 drv_data
->sw_rst
= NULL
;
124 drv_data
->pwr_rst
= devm_reset_control_get(&pdev
->dev
, "pwr-rst");
125 if (IS_ERR(drv_data
->pwr_rst
)) {
126 dev_dbg(&pdev
->dev
, "power soft reset control not defined\n");
127 drv_data
->pwr_rst
= NULL
;
130 return st_ahci_deassert_resets(&pdev
->dev
);
133 static struct ata_port_operations st_ahci_port_ops
= {
134 .inherits
= &ahci_platform_ops
,
135 .host_stop
= st_ahci_host_stop
,
138 static const struct ata_port_info st_ahci_port_info
= {
139 .flags
= AHCI_FLAG_COMMON
,
140 .pio_mask
= ATA_PIO4
,
141 .udma_mask
= ATA_UDMA6
,
142 .port_ops
= &st_ahci_port_ops
,
145 static struct scsi_host_template ahci_platform_sht
= {
149 static int st_ahci_probe(struct platform_device
*pdev
)
151 struct st_ahci_drv_data
*drv_data
;
152 struct ahci_host_priv
*hpriv
;
155 drv_data
= devm_kzalloc(&pdev
->dev
, sizeof(*drv_data
), GFP_KERNEL
);
159 platform_set_drvdata(pdev
, drv_data
);
161 hpriv
= ahci_platform_get_resources(pdev
);
163 return PTR_ERR(hpriv
);
165 drv_data
->hpriv
= hpriv
;
167 err
= st_ahci_probe_resets(pdev
);
171 err
= ahci_platform_enable_resources(hpriv
);
175 err
= ahci_platform_init_host(pdev
, hpriv
, &st_ahci_port_info
,
178 ahci_platform_disable_resources(hpriv
);
185 #ifdef CONFIG_PM_SLEEP
186 static int st_ahci_suspend(struct device
*dev
)
188 struct st_ahci_drv_data
*drv_data
= dev_get_drvdata(dev
);
189 struct ahci_host_priv
*hpriv
= drv_data
->hpriv
;
192 err
= ahci_platform_suspend_host(dev
);
197 err
= reset_control_assert(drv_data
->pwr
);
199 dev_err(dev
, "unable to pwrdwn");
204 ahci_platform_disable_resources(hpriv
);
209 static int st_ahci_resume(struct device
*dev
)
211 struct st_ahci_drv_data
*drv_data
= dev_get_drvdata(dev
);
212 struct ahci_host_priv
*hpriv
= drv_data
->hpriv
;
215 err
= ahci_platform_enable_resources(hpriv
);
219 err
= st_ahci_deassert_resets(dev
);
221 ahci_platform_disable_resources(hpriv
);
225 return ahci_platform_resume_host(dev
);
229 static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops
, st_ahci_suspend
, st_ahci_resume
);
231 static const struct of_device_id st_ahci_match
[] = {
232 { .compatible
= "st,ahci", },
235 MODULE_DEVICE_TABLE(of
, st_ahci_match
);
237 static struct platform_driver st_ahci_driver
= {
240 .pm
= &st_ahci_pm_ops
,
241 .of_match_table
= of_match_ptr(st_ahci_match
),
243 .probe
= st_ahci_probe
,
244 .remove
= ata_platform_remove_one
,
246 module_platform_driver(st_ahci_driver
);
248 MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>");
249 MODULE_AUTHOR("Francesco Virlinzi <francesco.virlinzi@st.com>");
250 MODULE_DESCRIPTION("STMicroelectronics SATA AHCI Driver");
251 MODULE_LICENSE("GPL v2");