1 // SPDX-License-Identifier: GPL-2.0-only
3 * AMD Seattle AHCI SATA driver
5 * Copyright (c) 2015, Advanced Micro Devices
6 * Author: Brijesh Singh <brijesh.singh@amd.com>
8 * based on the AHCI SATA platform driver by Jeff Garzik and Anton Vorontsov
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/of_device.h>
16 #include <linux/platform_device.h>
17 #include <linux/libata.h>
18 #include <linux/ahci_platform.h>
19 #include <linux/acpi.h>
20 #include <linux/pci_ids.h>
23 /* SGPIO Control Register definition
25 * Bit Type Description
26 * 31 RW OD7.2 (activity)
27 * 30 RW OD7.1 (locate)
29 * 28...8 RW OD6.2...OD0.0 (3bits per port, 1 bit per LED)
30 * 7 RO SGPIO feature flag
32 * 3:0 RO Number of ports (0 means no port supported)
34 #define ACTIVITY_BIT_POS(x) (8 + (3 * x))
35 #define LOCATE_BIT_POS(x) (ACTIVITY_BIT_POS(x) + 1)
36 #define FAULT_BIT_POS(x) (LOCATE_BIT_POS(x) + 1)
38 #define ACTIVITY_MASK 0x00010000
39 #define LOCATE_MASK 0x00080000
40 #define FAULT_MASK 0x00400000
42 #define DRV_NAME "ahci-seattle"
44 static ssize_t seattle_transmit_led_message(struct ata_port *ap, u32 state,
47 struct seattle_plat_data {
48 void __iomem *sgpio_ctrl;
51 static struct ata_port_operations ahci_port_ops = {
52 .inherits = &ahci_ops,
55 static const struct ata_port_info ahci_port_info = {
56 .flags = AHCI_FLAG_COMMON,
58 .udma_mask = ATA_UDMA6,
59 .port_ops = &ahci_port_ops,
62 static struct ata_port_operations ahci_seattle_ops = {
63 .inherits = &ahci_ops,
64 .transmit_led_message = seattle_transmit_led_message,
67 static const struct ata_port_info ahci_port_seattle_info = {
68 .flags = AHCI_FLAG_COMMON | ATA_FLAG_EM | ATA_FLAG_SW_ACTIVITY,
69 .link_flags = ATA_LFLAG_SW_ACTIVITY,
71 .udma_mask = ATA_UDMA6,
72 .port_ops = &ahci_seattle_ops,
75 static struct scsi_host_template ahci_platform_sht = {
79 static ssize_t seattle_transmit_led_message(struct ata_port *ap, u32 state,
82 struct ahci_host_priv *hpriv = ap->host->private_data;
83 struct ahci_port_priv *pp = ap->private_data;
84 struct seattle_plat_data *plat_data = hpriv->plat_data;
87 struct ahci_em_priv *emp;
90 /* get the slot number from the message */
91 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
92 if (pmp >= EM_MAX_SLOTS)
94 emp = &pp->em_priv[pmp];
96 val = ioread32(plat_data->sgpio_ctrl);
97 if (state & ACTIVITY_MASK)
98 val |= 1 << ACTIVITY_BIT_POS((ap->port_no));
100 val &= ~(1 << ACTIVITY_BIT_POS((ap->port_no)));
102 if (state & LOCATE_MASK)
103 val |= 1 << LOCATE_BIT_POS((ap->port_no));
105 val &= ~(1 << LOCATE_BIT_POS((ap->port_no)));
107 if (state & FAULT_MASK)
108 val |= 1 << FAULT_BIT_POS((ap->port_no));
110 val &= ~(1 << FAULT_BIT_POS((ap->port_no)));
112 iowrite32(val, plat_data->sgpio_ctrl);
114 spin_lock_irqsave(ap->lock, flags);
116 /* save off new led state for port/slot */
117 emp->led_state = state;
119 spin_unlock_irqrestore(ap->lock, flags);
124 static const struct ata_port_info *ahci_seattle_get_port_info(
125 struct platform_device *pdev, struct ahci_host_priv *hpriv)
127 struct device *dev = &pdev->dev;
128 struct seattle_plat_data *plat_data;
131 plat_data = devm_kzalloc(dev, sizeof(*plat_data), GFP_KERNEL);
133 return &ahci_port_info;
135 plat_data->sgpio_ctrl = devm_ioremap_resource(dev,
136 platform_get_resource(pdev, IORESOURCE_MEM, 1));
137 if (IS_ERR(plat_data->sgpio_ctrl))
138 return &ahci_port_info;
140 val = ioread32(plat_data->sgpio_ctrl);
143 return &ahci_port_info;
146 hpriv->em_buf_sz = 4;
147 hpriv->em_msg_type = EM_MSG_TYPE_LED;
148 hpriv->plat_data = plat_data;
150 dev_info(dev, "SGPIO LED control is enabled.\n");
151 return &ahci_port_seattle_info;
154 static int ahci_seattle_probe(struct platform_device *pdev)
157 struct ahci_host_priv *hpriv;
159 hpriv = ahci_platform_get_resources(pdev, 0);
161 return PTR_ERR(hpriv);
163 rc = ahci_platform_enable_resources(hpriv);
167 rc = ahci_platform_init_host(pdev, hpriv,
168 ahci_seattle_get_port_info(pdev, hpriv),
171 goto disable_resources;
175 ahci_platform_disable_resources(hpriv);
179 static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
180 ahci_platform_resume);
182 static const struct acpi_device_id ahci_acpi_match[] = {
186 MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
188 static struct platform_driver ahci_seattle_driver = {
189 .probe = ahci_seattle_probe,
190 .remove = ata_platform_remove_one,
193 .acpi_match_table = ahci_acpi_match,
197 module_platform_driver(ahci_seattle_driver);
199 MODULE_DESCRIPTION("Seattle AHCI SATA platform driver");
200 MODULE_AUTHOR("Brijesh Singh <brijesh.singh@amd.com>");
201 MODULE_LICENSE("GPL");
202 MODULE_ALIAS("platform:" DRV_NAME);