18 #define pr_fmt(fmt) "%s: " fmt, __func__
20 #include <linux/bitmap.h>
21 #include <linux/bitops.h>
27 #include <linux/module.h>
82 #define GPIO_INTR_CFG_SU(gpio) (MSM_TLMM_BASE + 0x0400 + (0x04 * (gpio)))
83 #define GPIO_CONFIG(gpio) (MSM_TLMM_BASE + 0x1000 + (0x10 * (gpio)))
84 #define GPIO_IN_OUT(gpio) (MSM_TLMM_BASE + 0x1004 + (0x10 * (gpio)))
85 #define GPIO_INTR_CFG(gpio) (MSM_TLMM_BASE + 0x1008 + (0x10 * (gpio)))
86 #define GPIO_INTR_STATUS(gpio) (MSM_TLMM_BASE + 0x100c + (0x10 * (gpio)))
118 static inline void set_gpio_bits(
unsigned n,
void __iomem *
reg)
123 static inline void clear_gpio_bits(
unsigned n,
void __iomem *reg)
133 static void msm_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int val)
138 static int msm_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
140 unsigned long irq_flags;
144 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
148 static int msm_gpio_direction_output(
struct gpio_chip *chip,
152 unsigned long irq_flags;
155 msm_gpio_set(chip, offset, val);
157 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
171 static int msm_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
176 static inline int msm_irq_to_gpio(
struct gpio_chip *chip,
unsigned irq)
185 .direction_input = msm_gpio_direction_input,
186 .direction_output = msm_gpio_direction_output,
189 .to_irq = msm_gpio_to_irq,
215 static void msm_gpio_update_dual_edge_pos(
unsigned gpio)
217 int loop_limit = 100;
218 unsigned val, val2, intstat;
228 if (intstat || val == val2)
230 }
while (loop_limit-- > 0);
231 pr_err(
"dual-edge irq failed to stabilize, "
232 "interrupts dropped. %#08x != %#08x\n",
236 static void msm_gpio_irq_ack(
struct irq_data *
d)
238 int gpio = msm_irq_to_gpio(&msm_gpio.
gpio_chip, d->
irq);
241 if (
test_bit(gpio, msm_gpio.dual_edge_irqs))
242 msm_gpio_update_dual_edge_pos(gpio);
245 static void msm_gpio_irq_mask(
struct irq_data *d)
247 int gpio = msm_irq_to_gpio(&msm_gpio.
gpio_chip, d->
irq);
248 unsigned long irq_flags;
254 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
257 static void msm_gpio_irq_unmask(
struct irq_data *d)
259 int gpio = msm_irq_to_gpio(&msm_gpio.
gpio_chip, d->
irq);
260 unsigned long irq_flags;
266 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
269 static int msm_gpio_irq_set_type(
struct irq_data *d,
unsigned int flow_type)
271 int gpio = msm_irq_to_gpio(&msm_gpio.
gpio_chip, d->
irq);
272 unsigned long irq_flags;
282 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
283 __set_bit(gpio, msm_gpio.dual_edge_irqs);
299 if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
300 msm_gpio_update_dual_edge_pos(gpio);
302 spin_unlock_irqrestore(&tlmm_lock, irq_flags);
313 static void msm_summary_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
316 struct irq_chip *chip = irq_desc_get_chip(desc);
318 chained_irq_enter(chip, desc);
326 chained_irq_exit(chip, desc);
329 static int msm_gpio_irq_set_wake(
struct irq_data *d,
unsigned int on)
331 int gpio = msm_irq_to_gpio(&msm_gpio.
gpio_chip, d->
irq);
336 set_bit(gpio, msm_gpio.wake_irqs);
346 static struct irq_chip msm_gpio_irq_chip = {
348 .irq_mask = msm_gpio_irq_mask,
349 .irq_unmask = msm_gpio_irq_unmask,
350 .irq_ack = msm_gpio_irq_ack,
351 .irq_set_type = msm_gpio_irq_set_type,
352 .irq_set_wake = msm_gpio_irq_set_wake,
367 for (i = 0; i < msm_gpio.
gpio_chip.ngpio; ++
i) {
368 irq = msm_gpio_to_irq(&msm_gpio.
gpio_chip, i);
369 irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
375 msm_summary_irq_handler);
392 .probe = msm_gpio_probe,
405 static int __init msm_gpio_init(
void)
419 static void __exit msm_gpio_exit(
void)