diff options
Diffstat (limited to 'drivers/ata/sata_highbank.c')
-rw-r--r-- | drivers/ata/sata_highbank.c | 161 |
1 files changed, 155 insertions, 6 deletions
diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c index c846fd3c5c09..d047d92a456f 100644 --- a/drivers/ata/sata_highbank.c +++ b/drivers/ata/sata_highbank.c | |||
@@ -33,6 +33,9 @@ | |||
33 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
34 | #include <linux/delay.h> | 34 | #include <linux/delay.h> |
35 | #include <linux/export.h> | 35 | #include <linux/export.h> |
36 | #include <linux/gpio.h> | ||
37 | #include <linux/of_gpio.h> | ||
38 | |||
36 | #include "ahci.h" | 39 | #include "ahci.h" |
37 | 40 | ||
38 | #define CPHY_MAP(dev, addr) ((((dev) & 0x1f) << 7) | (((addr) >> 9) & 0x7f)) | 41 | #define CPHY_MAP(dev, addr) ((((dev) & 0x1f) << 7) | (((addr) >> 9) & 0x7f)) |
@@ -66,6 +69,146 @@ struct phy_lane_info { | |||
66 | }; | 69 | }; |
67 | static struct phy_lane_info port_data[CPHY_PORT_COUNT]; | 70 | static struct phy_lane_info port_data[CPHY_PORT_COUNT]; |
68 | 71 | ||
72 | static DEFINE_SPINLOCK(sgpio_lock); | ||
73 | #define SCLOCK 0 | ||
74 | #define SLOAD 1 | ||
75 | #define SDATA 2 | ||
76 | #define SGPIO_PINS 3 | ||
77 | #define SGPIO_PORTS 8 | ||
78 | |||
79 | /* can be cast as an ahci_host_priv for compatibility with most functions */ | ||
80 | struct ecx_plat_data { | ||
81 | u32 n_ports; | ||
82 | unsigned sgpio_gpio[SGPIO_PINS]; | ||
83 | u32 sgpio_pattern; | ||
84 | u32 port_to_sgpio[SGPIO_PORTS]; | ||
85 | }; | ||
86 | |||
87 | #define SGPIO_SIGNALS 3 | ||
88 | #define ECX_ACTIVITY_BITS 0x300000 | ||
89 | #define ECX_ACTIVITY_SHIFT 2 | ||
90 | #define ECX_LOCATE_BITS 0x80000 | ||
91 | #define ECX_LOCATE_SHIFT 1 | ||
92 | #define ECX_FAULT_BITS 0x400000 | ||
93 | #define ECX_FAULT_SHIFT 0 | ||
94 | static inline int sgpio_bit_shift(struct ecx_plat_data *pdata, u32 port, | ||
95 | u32 shift) | ||
96 | { | ||
97 | return 1 << (3 * pdata->port_to_sgpio[port] + shift); | ||
98 | } | ||
99 | |||
100 | static void ecx_parse_sgpio(struct ecx_plat_data *pdata, u32 port, u32 state) | ||
101 | { | ||
102 | if (state & ECX_ACTIVITY_BITS) | ||
103 | pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port, | ||
104 | ECX_ACTIVITY_SHIFT); | ||
105 | else | ||
106 | pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port, | ||
107 | ECX_ACTIVITY_SHIFT); | ||
108 | if (state & ECX_LOCATE_BITS) | ||
109 | pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port, | ||
110 | ECX_LOCATE_SHIFT); | ||
111 | else | ||
112 | pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port, | ||
113 | ECX_LOCATE_SHIFT); | ||
114 | if (state & ECX_FAULT_BITS) | ||
115 | pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port, | ||
116 | ECX_FAULT_SHIFT); | ||
117 | else | ||
118 | pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port, | ||
119 | ECX_FAULT_SHIFT); | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Tell the LED controller that the signal has changed by raising the clock | ||
124 | * line for 50 uS and then lowering it for 50 uS. | ||
125 | */ | ||
126 | static void ecx_led_cycle_clock(struct ecx_plat_data *pdata) | ||
127 | { | ||
128 | gpio_set_value(pdata->sgpio_gpio[SCLOCK], 1); | ||
129 | udelay(50); | ||
130 | gpio_set_value(pdata->sgpio_gpio[SCLOCK], 0); | ||
131 | udelay(50); | ||
132 | } | ||
133 | |||
134 | static ssize_t ecx_transmit_led_message(struct ata_port *ap, u32 state, | ||
135 | ssize_t size) | ||
136 | { | ||
137 | struct ahci_host_priv *hpriv = ap->host->private_data; | ||
138 | struct ecx_plat_data *pdata = (struct ecx_plat_data *) hpriv->plat_data; | ||
139 | struct ahci_port_priv *pp = ap->private_data; | ||
140 | unsigned long flags; | ||
141 | int pmp, i; | ||
142 | struct ahci_em_priv *emp; | ||
143 | u32 sgpio_out; | ||
144 | |||
145 | /* get the slot number from the message */ | ||
146 | pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8; | ||
147 | if (pmp < EM_MAX_SLOTS) | ||
148 | emp = &pp->em_priv[pmp]; | ||
149 | else | ||
150 | return -EINVAL; | ||
151 | |||
152 | if (!(hpriv->em_msg_type & EM_MSG_TYPE_LED)) | ||
153 | return size; | ||
154 | |||
155 | spin_lock_irqsave(&sgpio_lock, flags); | ||
156 | ecx_parse_sgpio(pdata, ap->port_no, state); | ||
157 | sgpio_out = pdata->sgpio_pattern; | ||
158 | gpio_set_value(pdata->sgpio_gpio[SLOAD], 1); | ||
159 | ecx_led_cycle_clock(pdata); | ||
160 | gpio_set_value(pdata->sgpio_gpio[SLOAD], 0); | ||
161 | /* | ||
162 | * bit-bang out the SGPIO pattern, by consuming a bit and then | ||
163 | * clocking it out. | ||
164 | */ | ||
165 | for (i = 0; i < (SGPIO_SIGNALS * pdata->n_ports); i++) { | ||
166 | gpio_set_value(pdata->sgpio_gpio[SDATA], sgpio_out & 1); | ||
167 | sgpio_out >>= 1; | ||
168 | ecx_led_cycle_clock(pdata); | ||
169 | } | ||
170 | |||
171 | /* save off new led state for port/slot */ | ||
172 | emp->led_state = state; | ||
173 | |||
174 | spin_unlock_irqrestore(&sgpio_lock, flags); | ||
175 | return size; | ||
176 | } | ||
177 | |||
178 | static void highbank_set_em_messages(struct device *dev, | ||
179 | struct ahci_host_priv *hpriv, | ||
180 | struct ata_port_info *pi) | ||
181 | { | ||
182 | struct device_node *np = dev->of_node; | ||
183 | struct ecx_plat_data *pdata = hpriv->plat_data; | ||
184 | int i; | ||
185 | int err; | ||
186 | |||
187 | for (i = 0; i < SGPIO_PINS; i++) { | ||
188 | err = of_get_named_gpio(np, "calxeda,sgpio-gpio", i); | ||
189 | if (IS_ERR_VALUE(err)) | ||
190 | return; | ||
191 | |||
192 | pdata->sgpio_gpio[i] = err; | ||
193 | err = gpio_request(pdata->sgpio_gpio[i], "CX SGPIO"); | ||
194 | if (err) { | ||
195 | pr_err("sata_highbank gpio_request %d failed: %d\n", | ||
196 | i, err); | ||
197 | return; | ||
198 | } | ||
199 | gpio_direction_output(pdata->sgpio_gpio[i], 1); | ||
200 | } | ||
201 | of_property_read_u32_array(np, "calxeda,led-order", | ||
202 | pdata->port_to_sgpio, | ||
203 | pdata->n_ports); | ||
204 | |||
205 | /* store em_loc */ | ||
206 | hpriv->em_loc = 0; | ||
207 | hpriv->em_buf_sz = 4; | ||
208 | hpriv->em_msg_type = EM_MSG_TYPE_LED; | ||
209 | pi->flags |= ATA_FLAG_EM | ATA_FLAG_SW_ACTIVITY; | ||
210 | } | ||
211 | |||
69 | static u32 __combo_phy_reg_read(u8 sata_port, u32 addr) | 212 | static u32 __combo_phy_reg_read(u8 sata_port, u32 addr) |
70 | { | 213 | { |
71 | u32 data; | 214 | u32 data; |
@@ -257,6 +400,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class, | |||
257 | static struct ata_port_operations ahci_highbank_ops = { | 400 | static struct ata_port_operations ahci_highbank_ops = { |
258 | .inherits = &ahci_ops, | 401 | .inherits = &ahci_ops, |
259 | .hardreset = ahci_highbank_hardreset, | 402 | .hardreset = ahci_highbank_hardreset, |
403 | .transmit_led_message = ecx_transmit_led_message, | ||
260 | }; | 404 | }; |
261 | 405 | ||
262 | static const struct ata_port_info ahci_highbank_port_info = { | 406 | static const struct ata_port_info ahci_highbank_port_info = { |
@@ -280,12 +424,13 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
280 | { | 424 | { |
281 | struct device *dev = &pdev->dev; | 425 | struct device *dev = &pdev->dev; |
282 | struct ahci_host_priv *hpriv; | 426 | struct ahci_host_priv *hpriv; |
427 | struct ecx_plat_data *pdata; | ||
283 | struct ata_host *host; | 428 | struct ata_host *host; |
284 | struct resource *mem; | 429 | struct resource *mem; |
285 | int irq; | 430 | int irq; |
286 | int n_ports; | ||
287 | int i; | 431 | int i; |
288 | int rc; | 432 | int rc; |
433 | u32 n_ports; | ||
289 | struct ata_port_info pi = ahci_highbank_port_info; | 434 | struct ata_port_info pi = ahci_highbank_port_info; |
290 | const struct ata_port_info *ppi[] = { &pi, NULL }; | 435 | const struct ata_port_info *ppi[] = { &pi, NULL }; |
291 | 436 | ||
@@ -306,6 +451,11 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
306 | dev_err(dev, "can't alloc ahci_host_priv\n"); | 451 | dev_err(dev, "can't alloc ahci_host_priv\n"); |
307 | return -ENOMEM; | 452 | return -ENOMEM; |
308 | } | 453 | } |
454 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
455 | if (!pdata) { | ||
456 | dev_err(dev, "can't alloc ecx_plat_data\n"); | ||
457 | return -ENOMEM; | ||
458 | } | ||
309 | 459 | ||
310 | hpriv->flags |= (unsigned long)pi.private_data; | 460 | hpriv->flags |= (unsigned long)pi.private_data; |
311 | 461 | ||
@@ -329,8 +479,6 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
329 | if (hpriv->cap & HOST_CAP_PMP) | 479 | if (hpriv->cap & HOST_CAP_PMP) |
330 | pi.flags |= ATA_FLAG_PMP; | 480 | pi.flags |= ATA_FLAG_PMP; |
331 | 481 | ||
332 | ahci_set_em_messages(hpriv, &pi); | ||
333 | |||
334 | /* CAP.NP sometimes indicate the index of the last enabled | 482 | /* CAP.NP sometimes indicate the index of the last enabled |
335 | * port, at other times, that of the last possible port, so | 483 | * port, at other times, that of the last possible port, so |
336 | * determining the maximum port number requires looking at | 484 | * determining the maximum port number requires looking at |
@@ -338,6 +486,10 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
338 | */ | 486 | */ |
339 | n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); | 487 | n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); |
340 | 488 | ||
489 | pdata->n_ports = n_ports; | ||
490 | hpriv->plat_data = pdata; | ||
491 | highbank_set_em_messages(dev, hpriv, &pi); | ||
492 | |||
341 | host = ata_host_alloc_pinfo(dev, ppi, n_ports); | 493 | host = ata_host_alloc_pinfo(dev, ppi, n_ports); |
342 | if (!host) { | 494 | if (!host) { |
343 | rc = -ENOMEM; | 495 | rc = -ENOMEM; |
@@ -349,9 +501,6 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
349 | if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) | 501 | if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) |
350 | host->flags |= ATA_HOST_PARALLEL_SCAN; | 502 | host->flags |= ATA_HOST_PARALLEL_SCAN; |
351 | 503 | ||
352 | if (pi.flags & ATA_FLAG_EM) | ||
353 | ahci_reset_em(host); | ||
354 | |||
355 | for (i = 0; i < host->n_ports; i++) { | 504 | for (i = 0; i < host->n_ports; i++) { |
356 | struct ata_port *ap = host->ports[i]; | 505 | struct ata_port *ap = host->ports[i]; |
357 | 506 | ||