diff options
author | Mark Langsdorf <mark.langsdorf@calxeda.com> | 2013-06-06 08:52:41 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-06-06 17:05:24 -0400 |
commit | d50b110f14ad07066f9ad6e7f32e2b1a595b92f9 (patch) | |
tree | dc54f400aa524bad55254989464f3cd2ee3b7a95 /drivers/ata/sata_highbank.c | |
parent | 439d7a358f93a52458527329939be9f97db1242a (diff) |
sata highbank: add bit-banged SGPIO driver support
Highbank supports SGPIO by bit-banging out the SGPIO signals over
three GPIO pins defined in the DTB. Add support for this SGPIO
functionality.
Signed-off-by: Mark Langsdorf <mark.langsdorf@calxeda.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
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 b20aa96b958d..8de8ac80335b 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; |
@@ -241,6 +384,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class, | |||
241 | static struct ata_port_operations ahci_highbank_ops = { | 384 | static struct ata_port_operations ahci_highbank_ops = { |
242 | .inherits = &ahci_ops, | 385 | .inherits = &ahci_ops, |
243 | .hardreset = ahci_highbank_hardreset, | 386 | .hardreset = ahci_highbank_hardreset, |
387 | .transmit_led_message = ecx_transmit_led_message, | ||
244 | }; | 388 | }; |
245 | 389 | ||
246 | static const struct ata_port_info ahci_highbank_port_info = { | 390 | static const struct ata_port_info ahci_highbank_port_info = { |
@@ -264,12 +408,13 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
264 | { | 408 | { |
265 | struct device *dev = &pdev->dev; | 409 | struct device *dev = &pdev->dev; |
266 | struct ahci_host_priv *hpriv; | 410 | struct ahci_host_priv *hpriv; |
411 | struct ecx_plat_data *pdata; | ||
267 | struct ata_host *host; | 412 | struct ata_host *host; |
268 | struct resource *mem; | 413 | struct resource *mem; |
269 | int irq; | 414 | int irq; |
270 | int n_ports; | ||
271 | int i; | 415 | int i; |
272 | int rc; | 416 | int rc; |
417 | u32 n_ports; | ||
273 | struct ata_port_info pi = ahci_highbank_port_info; | 418 | struct ata_port_info pi = ahci_highbank_port_info; |
274 | const struct ata_port_info *ppi[] = { &pi, NULL }; | 419 | const struct ata_port_info *ppi[] = { &pi, NULL }; |
275 | 420 | ||
@@ -290,6 +435,11 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
290 | dev_err(dev, "can't alloc ahci_host_priv\n"); | 435 | dev_err(dev, "can't alloc ahci_host_priv\n"); |
291 | return -ENOMEM; | 436 | return -ENOMEM; |
292 | } | 437 | } |
438 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
439 | if (!pdata) { | ||
440 | dev_err(dev, "can't alloc ecx_plat_data\n"); | ||
441 | return -ENOMEM; | ||
442 | } | ||
293 | 443 | ||
294 | hpriv->flags |= (unsigned long)pi.private_data; | 444 | hpriv->flags |= (unsigned long)pi.private_data; |
295 | 445 | ||
@@ -313,8 +463,6 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
313 | if (hpriv->cap & HOST_CAP_PMP) | 463 | if (hpriv->cap & HOST_CAP_PMP) |
314 | pi.flags |= ATA_FLAG_PMP; | 464 | pi.flags |= ATA_FLAG_PMP; |
315 | 465 | ||
316 | ahci_set_em_messages(hpriv, &pi); | ||
317 | |||
318 | /* CAP.NP sometimes indicate the index of the last enabled | 466 | /* CAP.NP sometimes indicate the index of the last enabled |
319 | * port, at other times, that of the last possible port, so | 467 | * port, at other times, that of the last possible port, so |
320 | * determining the maximum port number requires looking at | 468 | * determining the maximum port number requires looking at |
@@ -322,6 +470,10 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
322 | */ | 470 | */ |
323 | n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); | 471 | n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); |
324 | 472 | ||
473 | pdata->n_ports = n_ports; | ||
474 | hpriv->plat_data = pdata; | ||
475 | highbank_set_em_messages(dev, hpriv, &pi); | ||
476 | |||
325 | host = ata_host_alloc_pinfo(dev, ppi, n_ports); | 477 | host = ata_host_alloc_pinfo(dev, ppi, n_ports); |
326 | if (!host) { | 478 | if (!host) { |
327 | rc = -ENOMEM; | 479 | rc = -ENOMEM; |
@@ -333,9 +485,6 @@ static int ahci_highbank_probe(struct platform_device *pdev) | |||
333 | if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) | 485 | if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) |
334 | host->flags |= ATA_HOST_PARALLEL_SCAN; | 486 | host->flags |= ATA_HOST_PARALLEL_SCAN; |
335 | 487 | ||
336 | if (pi.flags & ATA_FLAG_EM) | ||
337 | ahci_reset_em(host); | ||
338 | |||
339 | for (i = 0; i < host->n_ports; i++) { | 488 | for (i = 0; i < host->n_ports; i++) { |
340 | struct ata_port *ap = host->ports[i]; | 489 | struct ata_port *ap = host->ports[i]; |
341 | 490 | ||