blob: f268f3393ab5193520e55862c268ddf77d676b79 [file] [log] [blame]
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -07001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#include <linux/bitmap.h>
14#include <linux/bitops.h>
15#include <linux/gpio.h>
16#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/io.h>
20#include <linux/module.h>
21#include <linux/spinlock.h>
22#include <linux/syscore_ops.h>
23#include <linux/irqdomain.h>
24#include <linux/of.h>
25#include <linux/err.h>
26
27#include <asm/mach/irq.h>
28
29#include <mach/msm_iomap.h>
30#include <mach/gpiomux.h>
31#include <mach/mpm.h>
32#include "gpio-msm-common.h"
33
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053034#ifdef CONFIG_GPIO_MSM_V3
35enum msm_tlmm_register {
36 SDC4_HDRV_PULL_CTL = 0x0, /* NOT USED */
37 SDC3_HDRV_PULL_CTL = 0x0, /* NOT USED */
38 SDC2_HDRV_PULL_CTL = 0x2048,
39 SDC1_HDRV_PULL_CTL = 0x2044,
40};
41#else
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070042enum msm_tlmm_register {
43 SDC4_HDRV_PULL_CTL = 0x20a0,
44 SDC3_HDRV_PULL_CTL = 0x20a4,
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053045 SDC2_HDRV_PULL_CTL = 0x0, /* NOT USED */
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070046 SDC1_HDRV_PULL_CTL = 0x20a0,
47};
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053048#endif
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070049
50struct tlmm_field_cfg {
51 enum msm_tlmm_register reg;
52 u8 off;
53};
54
55static const struct tlmm_field_cfg tlmm_hdrv_cfgs[] = {
56 {SDC4_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC4_CLK */
57 {SDC4_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC4_CMD */
58 {SDC4_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC4_DATA */
59 {SDC3_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC3_CLK */
60 {SDC3_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC3_CMD */
61 {SDC3_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC3_DATA */
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053062 {SDC2_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC2_CLK */
63 {SDC2_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC2_CMD */
64 {SDC2_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC2_DATA */
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070065 {SDC1_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC1_CLK */
66 {SDC1_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC1_CMD */
67 {SDC1_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC1_DATA */
68};
69
70static const struct tlmm_field_cfg tlmm_pull_cfgs[] = {
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053071 {SDC4_HDRV_PULL_CTL, 14}, /* TLMM_PULL_SDC4_CLK */
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070072 {SDC4_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC4_CMD */
73 {SDC4_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC4_DATA */
74 {SDC3_HDRV_PULL_CTL, 14}, /* TLMM_PULL_SDC3_CLK */
75 {SDC3_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC3_CMD */
76 {SDC3_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC3_DATA */
Sujit Reddy Thumma39306c22012-06-26 15:39:26 +053077 {SDC2_HDRV_PULL_CTL, 14}, /* TLMM_PULL_SDC2_CLK */
78 {SDC2_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC2_CMD */
79 {SDC2_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC2_DATA */
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -070080 {SDC1_HDRV_PULL_CTL, 13}, /* TLMM_PULL_SDC1_CLK */
81 {SDC1_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC1_CMD */
82 {SDC1_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC1_DATA */
83};
84
85/*
86 * Supported arch specific irq extension.
87 * Default make them NULL.
88 */
89struct irq_chip msm_gpio_irq_extn = {
90 .irq_eoi = NULL,
91 .irq_mask = NULL,
92 .irq_unmask = NULL,
93 .irq_retrigger = NULL,
94 .irq_set_type = NULL,
95 .irq_set_wake = NULL,
96 .irq_disable = NULL,
97};
98
99/**
100 * struct msm_gpio_dev: the MSM8660 SoC GPIO device structure
101 *
102 * @enabled_irqs: a bitmap used to optimize the summary-irq handler. By
103 * keeping track of which gpios are unmasked as irq sources, we avoid
104 * having to do __raw_readl calls on hundreds of iomapped registers each time
105 * the summary interrupt fires in order to locate the active interrupts.
106 *
107 * @wake_irqs: a bitmap for tracking which interrupt lines are enabled
108 * as wakeup sources. When the device is suspended, interrupts which are
109 * not wakeup sources are disabled.
110 *
111 * @dual_edge_irqs: a bitmap used to track which irqs are configured
112 * as dual-edge, as this is not supported by the hardware and requires
113 * some special handling in the driver.
114 */
115struct msm_gpio_dev {
116 struct gpio_chip gpio_chip;
117 DECLARE_BITMAP(enabled_irqs, NR_MSM_GPIOS);
118 DECLARE_BITMAP(wake_irqs, NR_MSM_GPIOS);
119 DECLARE_BITMAP(dual_edge_irqs, NR_MSM_GPIOS);
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700120 struct irq_domain *domain;
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700121};
122
123static DEFINE_SPINLOCK(tlmm_lock);
124
125static inline struct msm_gpio_dev *to_msm_gpio_dev(struct gpio_chip *chip)
126{
127 return container_of(chip, struct msm_gpio_dev, gpio_chip);
128}
129
130static int msm_gpio_get(struct gpio_chip *chip, unsigned offset)
131{
132 int rc;
133 rc = __msm_gpio_get_inout(offset);
134 mb();
135 return rc;
136}
137
138static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
139{
140 __msm_gpio_set_inout(offset, val);
141 mb();
142}
143
144static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
145{
146 unsigned long irq_flags;
147
148 spin_lock_irqsave(&tlmm_lock, irq_flags);
149 __msm_gpio_set_config_direction(offset, 1, 0);
150 mb();
151 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
152 return 0;
153}
154
155static int msm_gpio_direction_output(struct gpio_chip *chip,
156 unsigned offset,
157 int val)
158{
159 unsigned long irq_flags;
160
161 spin_lock_irqsave(&tlmm_lock, irq_flags);
162 __msm_gpio_set_config_direction(offset, 0, val);
163 mb();
164 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
165 return 0;
166}
167
168#ifdef CONFIG_OF
169static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
170{
171 struct msm_gpio_dev *g_dev = to_msm_gpio_dev(chip);
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700172 struct irq_domain *domain = g_dev->domain;
173 return irq_linear_revmap(domain, offset - chip->base);
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700174}
175
176static inline int msm_irq_to_gpio(struct gpio_chip *chip, unsigned irq)
177{
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700178 struct irq_data *irq_data = irq_get_irq_data(irq);
179 return irq_data->hwirq;
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700180}
181#else
182static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
183{
184 return MSM_GPIO_TO_INT(offset - chip->base);
185}
186
187static inline int msm_irq_to_gpio(struct gpio_chip *chip, unsigned irq)
188{
189 return irq - MSM_GPIO_TO_INT(chip->base);
190}
191#endif
192
193static int msm_gpio_request(struct gpio_chip *chip, unsigned offset)
194{
195 return msm_gpiomux_get(chip->base + offset);
196}
197
198static void msm_gpio_free(struct gpio_chip *chip, unsigned offset)
199{
200 msm_gpiomux_put(chip->base + offset);
201}
202
203static struct msm_gpio_dev msm_gpio = {
204 .gpio_chip = {
205 .label = "msmgpio",
206 .base = 0,
207 .ngpio = NR_MSM_GPIOS,
208 .direction_input = msm_gpio_direction_input,
209 .direction_output = msm_gpio_direction_output,
210 .get = msm_gpio_get,
211 .set = msm_gpio_set,
212 .to_irq = msm_gpio_to_irq,
213 .request = msm_gpio_request,
214 .free = msm_gpio_free,
215 },
216};
217
218static void switch_mpm_config(struct irq_data *d, unsigned val)
219{
220 /* switch the configuration in the mpm as well */
221 if (!msm_gpio_irq_extn.irq_set_type)
222 return;
223
224 if (val)
225 msm_gpio_irq_extn.irq_set_type(d, IRQF_TRIGGER_FALLING);
226 else
227 msm_gpio_irq_extn.irq_set_type(d, IRQF_TRIGGER_RISING);
228}
229
230/* For dual-edge interrupts in software, since the hardware has no
231 * such support:
232 *
233 * At appropriate moments, this function may be called to flip the polarity
234 * settings of both-edge irq lines to try and catch the next edge.
235 *
236 * The attempt is considered successful if:
237 * - the status bit goes high, indicating that an edge was caught, or
238 * - the input value of the gpio doesn't change during the attempt.
239 * If the value changes twice during the process, that would cause the first
240 * test to fail but would force the second, as two opposite
241 * transitions would cause a detection no matter the polarity setting.
242 *
243 * The do-loop tries to sledge-hammer closed the timing hole between
244 * the initial value-read and the polarity-write - if the line value changes
245 * during that window, an interrupt is lost, the new polarity setting is
246 * incorrect, and the first success test will fail, causing a retry.
247 *
248 * Algorithm comes from Google's msmgpio driver, see mach-msm/gpio.c.
249 */
250static void msm_gpio_update_dual_edge_pos(struct irq_data *d, unsigned gpio)
251{
252 int loop_limit = 100;
253 unsigned val, val2, intstat;
254
255 do {
256 val = __msm_gpio_get_inout(gpio);
257 __msm_gpio_set_polarity(gpio, val);
258 val2 = __msm_gpio_get_inout(gpio);
259 intstat = __msm_gpio_get_intr_status(gpio);
260 if (intstat || val == val2) {
261 switch_mpm_config(d, val);
262 return;
263 }
264 } while (loop_limit-- > 0);
265 pr_err("%s: dual-edge irq failed to stabilize, %#08x != %#08x\n",
266 __func__, val, val2);
267}
268
269static void msm_gpio_irq_ack(struct irq_data *d)
270{
271 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
272
273 __msm_gpio_set_intr_status(gpio);
274 if (test_bit(gpio, msm_gpio.dual_edge_irqs))
275 msm_gpio_update_dual_edge_pos(d, gpio);
276 mb();
277}
278
279static void msm_gpio_irq_mask(struct irq_data *d)
280{
281 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
282 unsigned long irq_flags;
283
284 spin_lock_irqsave(&tlmm_lock, irq_flags);
285 __msm_gpio_set_intr_cfg_enable(gpio, 0);
286 __clear_bit(gpio, msm_gpio.enabled_irqs);
287 mb();
288 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
289
290 if (msm_gpio_irq_extn.irq_mask)
291 msm_gpio_irq_extn.irq_mask(d);
292
293}
294
295static void msm_gpio_irq_unmask(struct irq_data *d)
296{
297 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
298 unsigned long irq_flags;
299
300 spin_lock_irqsave(&tlmm_lock, irq_flags);
301 __set_bit(gpio, msm_gpio.enabled_irqs);
302 __msm_gpio_set_intr_cfg_enable(gpio, 1);
303 mb();
304 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
305
306 if (msm_gpio_irq_extn.irq_mask)
307 msm_gpio_irq_extn.irq_unmask(d);
308}
309
310static void msm_gpio_irq_disable(struct irq_data *d)
311{
312 if (msm_gpio_irq_extn.irq_disable)
313 msm_gpio_irq_extn.irq_disable(d);
314}
315
316static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type)
317{
318 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
319 unsigned long irq_flags;
320
321 spin_lock_irqsave(&tlmm_lock, irq_flags);
322
323 if (flow_type & IRQ_TYPE_EDGE_BOTH) {
324 __irq_set_handler_locked(d->irq, handle_edge_irq);
325 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
326 __set_bit(gpio, msm_gpio.dual_edge_irqs);
327 else
328 __clear_bit(gpio, msm_gpio.dual_edge_irqs);
329 } else {
330 __irq_set_handler_locked(d->irq, handle_level_irq);
331 __clear_bit(gpio, msm_gpio.dual_edge_irqs);
332 }
333
334 __msm_gpio_set_intr_cfg_type(gpio, flow_type);
335
336 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
337 msm_gpio_update_dual_edge_pos(d, gpio);
338
339 mb();
340 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
341
342 if (msm_gpio_irq_extn.irq_set_type)
343 msm_gpio_irq_extn.irq_set_type(d, flow_type);
344
345 return 0;
346}
347
348/*
349 * When the summary IRQ is raised, any number of GPIO lines may be high.
350 * It is the job of the summary handler to find all those GPIO lines
351 * which have been set as summary IRQ lines and which are triggered,
352 * and to call their interrupt handlers.
353 */
354static irqreturn_t msm_summary_irq_handler(int irq, void *data)
355{
356 unsigned long i;
357 struct irq_desc *desc = irq_to_desc(irq);
358 struct irq_chip *chip = irq_desc_get_chip(desc);
359
360 chained_irq_enter(chip, desc);
361
362 for (i = find_first_bit(msm_gpio.enabled_irqs, NR_MSM_GPIOS);
363 i < NR_MSM_GPIOS;
364 i = find_next_bit(msm_gpio.enabled_irqs, NR_MSM_GPIOS, i + 1)) {
365 if (__msm_gpio_get_intr_status(i))
366 generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip,
367 i));
368 }
369
370 chained_irq_exit(chip, desc);
371 return IRQ_HANDLED;
372}
373
374static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
375{
376 int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, d->irq);
377
378 if (on) {
379 if (bitmap_empty(msm_gpio.wake_irqs, NR_MSM_GPIOS))
380 irq_set_irq_wake(TLMM_MSM_SUMMARY_IRQ, 1);
381 set_bit(gpio, msm_gpio.wake_irqs);
382 } else {
383 clear_bit(gpio, msm_gpio.wake_irqs);
384 if (bitmap_empty(msm_gpio.wake_irqs, NR_MSM_GPIOS))
385 irq_set_irq_wake(TLMM_MSM_SUMMARY_IRQ, 0);
386 }
387
388 if (msm_gpio_irq_extn.irq_set_wake)
389 msm_gpio_irq_extn.irq_set_wake(d, on);
390
391 return 0;
392}
393
394static struct irq_chip msm_gpio_irq_chip = {
395 .name = "msmgpio",
396 .irq_mask = msm_gpio_irq_mask,
397 .irq_unmask = msm_gpio_irq_unmask,
398 .irq_ack = msm_gpio_irq_ack,
399 .irq_set_type = msm_gpio_irq_set_type,
400 .irq_set_wake = msm_gpio_irq_set_wake,
401 .irq_disable = msm_gpio_irq_disable,
402};
403
404/*
405 * This lock class tells lockdep that GPIO irqs are in a different
406 * category than their parent, so it won't report false recursion.
407 */
408static struct lock_class_key msm_gpio_lock_class;
409
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700410/* TODO: This should be a real platform_driver */
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700411static int __devinit msm_gpio_probe(void)
412{
413 int i, irq, ret;
414
415 spin_lock_init(&tlmm_lock);
416 bitmap_zero(msm_gpio.enabled_irqs, NR_MSM_GPIOS);
417 bitmap_zero(msm_gpio.wake_irqs, NR_MSM_GPIOS);
418 bitmap_zero(msm_gpio.dual_edge_irqs, NR_MSM_GPIOS);
419 ret = gpiochip_add(&msm_gpio.gpio_chip);
420 if (ret < 0)
421 return ret;
422
423 for (i = 0; i < msm_gpio.gpio_chip.ngpio; ++i) {
424 irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i);
425 irq_set_lockdep_class(irq, &msm_gpio_lock_class);
426 irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
427 handle_level_irq);
428 set_irq_flags(irq, IRQF_VALID);
429 }
430
431 ret = request_irq(TLMM_MSM_SUMMARY_IRQ, msm_summary_irq_handler,
432 IRQF_TRIGGER_HIGH, "msmgpio", NULL);
433 if (ret) {
434 pr_err("Request_irq failed for TLMM_MSM_SUMMARY_IRQ - %d\n",
435 ret);
436 return ret;
437 }
438 return 0;
439}
440
441static int __devexit msm_gpio_remove(void)
442{
443 int ret = gpiochip_remove(&msm_gpio.gpio_chip);
444
445 if (ret < 0)
446 return ret;
447
448 irq_set_handler(TLMM_MSM_SUMMARY_IRQ, NULL);
449
450 return 0;
451}
452
453#ifdef CONFIG_PM
454static int msm_gpio_suspend(void)
455{
456 unsigned long irq_flags;
457 unsigned long i;
458
459 spin_lock_irqsave(&tlmm_lock, irq_flags);
460 for_each_set_bit(i, msm_gpio.enabled_irqs, NR_MSM_GPIOS)
461 __msm_gpio_set_intr_cfg_enable(i, 0);
462
463 for_each_set_bit(i, msm_gpio.wake_irqs, NR_MSM_GPIOS)
464 __msm_gpio_set_intr_cfg_enable(i, 1);
465 mb();
466 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
467 return 0;
468}
469
470void msm_gpio_show_resume_irq(void)
471{
472 unsigned long irq_flags;
473 int i, irq, intstat;
474
475 if (!msm_show_resume_irq_mask)
476 return;
477
478 spin_lock_irqsave(&tlmm_lock, irq_flags);
479 for_each_set_bit(i, msm_gpio.wake_irqs, NR_MSM_GPIOS) {
480 intstat = __msm_gpio_get_intr_status(i);
481 if (intstat) {
482 irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i);
483 pr_warning("%s: %d triggered\n",
484 __func__, irq);
485 }
486 }
487 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
488}
489
490static void msm_gpio_resume(void)
491{
492 unsigned long irq_flags;
493 unsigned long i;
494
495 msm_gpio_show_resume_irq();
496
497 spin_lock_irqsave(&tlmm_lock, irq_flags);
498 for_each_set_bit(i, msm_gpio.wake_irqs, NR_MSM_GPIOS)
499 __msm_gpio_set_intr_cfg_enable(i, 0);
500
501 for_each_set_bit(i, msm_gpio.enabled_irqs, NR_MSM_GPIOS)
502 __msm_gpio_set_intr_cfg_enable(i, 1);
503 mb();
504 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
505}
506#else
507#define msm_gpio_suspend NULL
508#define msm_gpio_resume NULL
509#endif
510
511static struct syscore_ops msm_gpio_syscore_ops = {
512 .suspend = msm_gpio_suspend,
513 .resume = msm_gpio_resume,
514};
515
516static int __init msm_gpio_init(void)
517{
518 msm_gpio_probe();
519 register_syscore_ops(&msm_gpio_syscore_ops);
520 return 0;
521}
522
523static void __exit msm_gpio_exit(void)
524{
525 unregister_syscore_ops(&msm_gpio_syscore_ops);
526 msm_gpio_remove();
527}
528
529postcore_initcall(msm_gpio_init);
530module_exit(msm_gpio_exit);
531
532static void msm_tlmm_set_field(const struct tlmm_field_cfg *configs,
533 unsigned id, unsigned width, unsigned val)
534{
535 unsigned long irqflags;
536 u32 mask = (1 << width) - 1;
537 u32 __iomem *reg = MSM_TLMM_BASE + configs[id].reg;
538 u32 reg_val;
539
540 spin_lock_irqsave(&tlmm_lock, irqflags);
541 reg_val = __raw_readl(reg);
542 reg_val &= ~(mask << configs[id].off);
543 reg_val |= (val & mask) << configs[id].off;
544 __raw_writel(reg_val, reg);
545 mb();
546 spin_unlock_irqrestore(&tlmm_lock, irqflags);
547}
548
549void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt, int drv_str)
550{
551 msm_tlmm_set_field(tlmm_hdrv_cfgs, tgt, 3, drv_str);
552}
553EXPORT_SYMBOL(msm_tlmm_set_hdrive);
554
555void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull)
556{
557 msm_tlmm_set_field(tlmm_pull_cfgs, tgt, 2, pull);
558}
559EXPORT_SYMBOL(msm_tlmm_set_pull);
560
561int gpio_tlmm_config(unsigned config, unsigned disable)
562{
563 unsigned gpio = GPIO_PIN(config);
564
565 if (gpio > NR_MSM_GPIOS)
566 return -EINVAL;
567
568 __gpio_tlmm_config(config);
569 mb();
570
571 return 0;
572}
573EXPORT_SYMBOL(gpio_tlmm_config);
574
575int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq,
576 unsigned int input_polarity)
577{
578 unsigned long irq_flags;
579
580 if (gpio >= NR_MSM_GPIOS || irq >= NR_TLMM_MSM_DIR_CONN_IRQ)
581 return -EINVAL;
582
583 spin_lock_irqsave(&tlmm_lock, irq_flags);
584 __msm_gpio_install_direct_irq(gpio, irq, input_polarity);
585 mb();
586 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
587
588 return 0;
589}
590EXPORT_SYMBOL(msm_gpio_install_direct_irq);
591
592#ifdef CONFIG_OF
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700593static int msm_gpio_irq_domain_xlate(struct irq_domain *d,
594 struct device_node *controller,
595 const u32 *intspec,
596 unsigned int intsize,
597 unsigned long *out_hwirq,
598 unsigned int *out_type)
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700599{
600 if (d->of_node != controller)
601 return -EINVAL;
602 if (intsize != 2)
603 return -EINVAL;
604
605 /* hwirq value */
606 *out_hwirq = intspec[0];
607
608 /* irq flags */
609 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
610 return 0;
611}
612
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700613/*
614 * TODO: this really should be doing all the things that msm_gpio_probe() does,
615 * but since the msm_gpio_probe is called unconditionally for DT and non-DT
616 * configs, we can't duplicate it here. This should be fixed.
617 */
618int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq,
619 irq_hw_number_t hwirq)
620{
621 return 0;
622}
623
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700624static struct irq_domain_ops msm_gpio_irq_domain_ops = {
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700625 .xlate = msm_gpio_irq_domain_xlate,
626 .map = msm_gpio_irq_domain_map,
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700627};
628
629int __init msm_gpio_of_init(struct device_node *node,
630 struct device_node *parent)
631{
Michael Bohanbb6b30f2012-06-01 13:33:51 -0700632 msm_gpio.domain = irq_domain_add_linear(node, NR_MSM_GPIOS,
633 &msm_gpio_irq_domain_ops, &msm_gpio);
634 if (!msm_gpio.domain) {
635 WARN(1, "Cannot allocate irq_domain\n");
636 return -ENOMEM;
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700637 }
638
Sathish Ambleyd2ad0fa2012-03-23 11:23:47 -0700639 return 0;
640}
641#endif
642
643MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>");
644MODULE_DESCRIPTION("Driver for Qualcomm MSM TLMMv2 SoC GPIOs");
645MODULE_LICENSE("GPL v2");
646MODULE_ALIAS("sysdev:msmgpio");