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/platform_device.h>
16 #include <linux/libata.h>
17 #include <linux/ahci_platform.h>
18 #include <linux/acpi.h>
19 #include <linux/pci_ids.h>
22 /* SGPIO Control Register definition
24 * Bit Type Description
25 * 31 RW OD7.2 (activity)
26 * 30 RW OD7.1 (locate)
28 * 28...8 RW OD6.2...OD0.0 (3bits per port, 1 bit per LED)
29 * 7 RO SGPIO feature flag
31 * 3:0 RO Number of ports (0 means no port supported)
33 #define ACTIVITY_BIT_POS(x) (8 + (3 * x))
34 #define LOCATE_BIT_POS(x) (ACTIVITY_BIT_POS(x) + 1)
35 #define FAULT_BIT_POS(x) (LOCATE_BIT_POS(x) + 1)
37 #define ACTIVITY_MASK 0x00010000
38 #define LOCATE_MASK 0x00080000
39 #define FAULT_MASK 0x00400000
41 #define DRV_NAME "ahci-seattle"
43 static ssize_t
seattle_transmit_led_message(struct ata_port
*ap
, u32 state
,
46 struct seattle_plat_data
{
47 void __iomem
*sgpio_ctrl
;
50 static struct ata_port_operations ahci_port_ops
= {
51 .inherits
= &ahci_ops
,
54 static const struct ata_port_info ahci_port_info
= {
55 .flags
= AHCI_FLAG_COMMON
,
57 .udma_mask
= ATA_UDMA6
,
58 .port_ops
= &ahci_port_ops
,
61 static struct ata_port_operations ahci_seattle_ops
= {
62 .inherits
= &ahci_ops
,
63 .transmit_led_message
= seattle_transmit_led_message
,
66 static const struct ata_port_info ahci_port_seattle_info
= {
67 .flags
= AHCI_FLAG_COMMON
| ATA_FLAG_EM
| ATA_FLAG_SW_ACTIVITY
,
68 .link_flags
= ATA_LFLAG_SW_ACTIVITY
,
70 .udma_mask
= ATA_UDMA6
,
71 .port_ops
= &ahci_seattle_ops
,
74 static const struct scsi_host_template ahci_platform_sht
= {
78 static ssize_t
seattle_transmit_led_message(struct ata_port
*ap
, u32 state
,
81 struct ahci_host_priv
*hpriv
= ap
->host
->private_data
;
82 struct ahci_port_priv
*pp
= ap
->private_data
;
83 struct seattle_plat_data
*plat_data
= hpriv
->plat_data
;
86 struct ahci_em_priv
*emp
;
89 /* get the slot number from the message */
90 pmp
= (state
& EM_MSG_LED_PMP_SLOT
) >> 8;
91 if (pmp
>= EM_MAX_SLOTS
)
93 emp
= &pp
->em_priv
[pmp
];
95 val
= ioread32(plat_data
->sgpio_ctrl
);
96 if (state
& ACTIVITY_MASK
)
97 val
|= 1 << ACTIVITY_BIT_POS((ap
->port_no
));
99 val
&= ~(1 << ACTIVITY_BIT_POS((ap
->port_no
)));
101 if (state
& LOCATE_MASK
)
102 val
|= 1 << LOCATE_BIT_POS((ap
->port_no
));
104 val
&= ~(1 << LOCATE_BIT_POS((ap
->port_no
)));
106 if (state
& FAULT_MASK
)
107 val
|= 1 << FAULT_BIT_POS((ap
->port_no
));
109 val
&= ~(1 << FAULT_BIT_POS((ap
->port_no
)));
111 iowrite32(val
, plat_data
->sgpio_ctrl
);
113 spin_lock_irqsave(ap
->lock
, flags
);
115 /* save off new led state for port/slot */
116 emp
->led_state
= state
;
118 spin_unlock_irqrestore(ap
->lock
, flags
);
123 static const struct ata_port_info
*ahci_seattle_get_port_info(
124 struct platform_device
*pdev
, struct ahci_host_priv
*hpriv
)
126 struct device
*dev
= &pdev
->dev
;
127 struct seattle_plat_data
*plat_data
;
130 plat_data
= devm_kzalloc(dev
, sizeof(*plat_data
), GFP_KERNEL
);
132 return &ahci_port_info
;
134 plat_data
->sgpio_ctrl
= devm_platform_ioremap_resource(pdev
, 1);
135 if (IS_ERR(plat_data
->sgpio_ctrl
))
136 return &ahci_port_info
;
138 val
= ioread32(plat_data
->sgpio_ctrl
);
141 return &ahci_port_info
;
144 hpriv
->em_buf_sz
= 4;
145 hpriv
->em_msg_type
= EM_MSG_TYPE_LED
;
146 hpriv
->plat_data
= plat_data
;
148 dev_info(dev
, "SGPIO LED control is enabled.\n");
149 return &ahci_port_seattle_info
;
152 static int ahci_seattle_probe(struct platform_device
*pdev
)
155 struct ahci_host_priv
*hpriv
;
157 hpriv
= ahci_platform_get_resources(pdev
, 0);
159 return PTR_ERR(hpriv
);
161 rc
= ahci_platform_enable_resources(hpriv
);
165 rc
= ahci_platform_init_host(pdev
, hpriv
,
166 ahci_seattle_get_port_info(pdev
, hpriv
),
169 goto disable_resources
;
173 ahci_platform_disable_resources(hpriv
);
177 static SIMPLE_DEV_PM_OPS(ahci_pm_ops
, ahci_platform_suspend
,
178 ahci_platform_resume
);
180 static const struct acpi_device_id ahci_acpi_match
[] = {
184 MODULE_DEVICE_TABLE(acpi
, ahci_acpi_match
);
186 static struct platform_driver ahci_seattle_driver
= {
187 .probe
= ahci_seattle_probe
,
188 .remove_new
= ata_platform_remove_one
,
191 .acpi_match_table
= ahci_acpi_match
,
195 module_platform_driver(ahci_seattle_driver
);
197 MODULE_DESCRIPTION("Seattle AHCI SATA platform driver");
198 MODULE_AUTHOR("Brijesh Singh <brijesh.singh@amd.com>");
199 MODULE_LICENSE("GPL");
200 MODULE_ALIAS("platform:" DRV_NAME
);