11 #include <linux/kernel.h>
12 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
66 static inline void ack_irqs(
struct egpio_info *ei)
69 pr_debug(
"EGPIO ack - write %x to base+%x\n",
82 struct egpio_info *ei = irq_data_get_irq_chip_data(data);
89 struct egpio_info *ei = irq_data_get_irq_chip_data(data);
94 static struct irq_chip egpio_muxed_chip = {
97 .irq_mask = egpio_mask,
98 .irq_unmask = egpio_unmask,
101 static void egpio_handler(
unsigned int irq,
struct irq_desc *
desc)
103 struct egpio_info *ei = irq_desc_get_handler_data(desc);
107 unsigned long readval = egpio_readw(ei, ei->
ack_register);
108 pr_debug(
"IRQ reg: %x\n", (
unsigned int)readval);
141 return 1 << (bit & ((1 << ei->
reg_shift)-1));
148 static int egpio_get(
struct gpio_chip *
chip,
unsigned offset)
156 pr_debug(
"egpio_get_value(%d)\n", chip->base + offset);
160 bit = egpio_bit(ei, offset);
161 reg = egpio->
reg_start + egpio_pos(ei, offset);
163 value = egpio_readw(ei, reg);
169 static int egpio_direction_input(
struct gpio_chip *
chip,
unsigned offset)
182 static void egpio_set(
struct gpio_chip *
chip,
unsigned offset,
int value)
192 pr_debug(
"egpio_set(%s, %d(%d), %d)\n",
193 chip->label, offset, offset+chip->base, value);
197 bit = egpio_bit(ei, offset);
198 pos = egpio_pos(ei, offset);
202 pr_debug(
"egpio %s: reg %d = 0x%04x\n", value ?
"set" :
"clear",
211 spin_unlock_irqrestore(&ei->
lock, flag);
214 static int egpio_direction_output(
struct gpio_chip *chip,
215 unsigned offset,
int value)
221 egpio_set(chip, offset, value);
228 static void egpio_write_cache(
struct egpio_info *ei)
234 for (i = 0; i < ei->
nchips; i++) {
235 egpio = &(ei->
chip[
i]);
239 for (shift = 0; shift < egpio->
chip.ngpio;
242 int reg = egpio->
reg_start + egpio_pos(ei, shift);
247 pr_debug(
"EGPIO: setting %x to %x, was %x\n", reg,
249 egpio_readw(ei, reg));
267 struct gpio_chip *
chip;
268 unsigned int irq, irq_end;
306 platform_set_drvdata(pdev, ei);
314 for (i = 0; i < ei->
nchips; i++) {
315 ei->
chip[
i].reg_start = pdata->
chip[
i].reg_start;
316 ei->
chip[
i].cached_values = pdata->
chip[
i].initial_values;
317 ei->
chip[
i].is_out = pdata->
chip[
i].direction;
319 chip = &(ei->
chip[
i].chip);
320 chip->label =
"htc-egpio";
321 chip->dev = &pdev->
dev;
323 chip->get = egpio_get;
324 chip->set = egpio_set;
325 chip->direction_input = egpio_direction_input;
326 chip->direction_output = egpio_direction_output;
327 chip->base = pdata->
chip[
i].gpio_base;
328 chip->ngpio = pdata->
chip[
i].num_gpios;
334 egpio_write_cache(ei);
346 for (irq = ei->
irq_start; irq < irq_end; irq++) {
347 irq_set_chip_and_handler(irq, &egpio_muxed_chip,
354 irq_set_chained_handler(ei->
chained_irq, egpio_handler);
370 struct egpio_info *ei = platform_get_drvdata(pdev);
371 unsigned int irq, irq_end;
375 for (irq = ei->
irq_start; irq < irq_end; irq++) {
376 irq_set_chip_and_handler(irq,
NULL,
NULL);
392 struct egpio_info *ei = platform_get_drvdata(pdev);
401 struct egpio_info *ei = platform_get_drvdata(pdev);
408 egpio_write_cache(ei);
412 #define egpio_suspend NULL
413 #define egpio_resume NULL
426 static int __init egpio_init(
void)
431 static void __exit egpio_exit(
void)