23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
33 #define MSIC_GPIO_IRQ_OFFSET 0x100
35 #define MSIC_GPIO_DIR_IN 0
36 #define MSIC_GPIO_DIR_OUT BIT(5)
37 #define MSIC_GPIO_TRIG_FALL BIT(1)
38 #define MSIC_GPIO_TRIG_RISE BIT(2)
41 #define MSIC_GPIO_DIR_MASK BIT(5)
42 #define MSIC_GPIO_DRV_MASK BIT(4)
43 #define MSIC_GPIO_REN_MASK BIT(3)
44 #define MSIC_GPIO_RVAL_MASK (BIT(2) | BIT(1))
45 #define MSIC_GPIO_DOUT_MASK BIT(0)
48 #define MSIC_GPIO_GLBYP_MASK BIT(5)
49 #define MSIC_GPIO_DBNC_MASK (BIT(4) | BIT(3))
50 #define MSIC_GPIO_INTCNT_MASK (BIT(2) | BIT(1))
51 #define MSIC_GPIO_DIN_MASK BIT(0)
53 #define MSIC_NUM_GPIO 24
75 static int msic_gpio_to_ireg(
unsigned offset)
90 static int msic_gpio_to_oreg(
unsigned offset)
105 static int msic_gpio_direction_input(
struct gpio_chip *
chip,
unsigned offset)
109 reg = msic_gpio_to_oreg(offset);
116 static int msic_gpio_direction_output(
struct gpio_chip *chip,
117 unsigned offset,
int value)
125 reg = msic_gpio_to_oreg(offset);
132 static int msic_gpio_get(
struct gpio_chip *chip,
unsigned offset)
138 reg = msic_gpio_to_ireg(offset);
149 static void msic_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
153 reg = msic_gpio_to_oreg(offset);
167 struct msic_gpio *mg = irq_data_get_irq_chip_data(data);
170 if (gpio >= mg->
chip.ngpio)
180 static int msic_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
186 static void msic_bus_lock(
struct irq_data *data)
188 struct msic_gpio *mg = irq_data_get_irq_chip_data(data);
192 static void msic_bus_sync_unlock(
struct irq_data *data)
194 struct msic_gpio *mg = irq_data_get_irq_chip_data(data);
205 reg = msic_gpio_to_ireg(offset);
222 static void msic_irq_unmask(
struct irq_data *data) { }
224 static void msic_irq_mask(
struct irq_data *data) { }
226 static struct irq_chip msic_irqchip = {
228 .irq_mask = msic_irq_mask,
229 .irq_unmask = msic_irq_unmask,
230 .irq_set_type = msic_irq_type,
231 .irq_bus_lock = msic_bus_lock,
232 .irq_bus_sync_unlock = msic_bus_sync_unlock,
235 static void msic_gpio_irq_handler(
unsigned irq,
struct irq_desc *
desc)
237 struct irq_data *data = irq_desc_get_irq_data(desc);
238 struct msic_gpio *mg = irq_data_get_irq_handler_data(data);
239 struct irq_chip *chip = irq_data_get_irq_chip(data);
244 unsigned long pending = 0;
274 dev_err(dev,
"incorrect or missing platform data\n");
287 mg->
chip.label =
"msic_gpio";
288 mg->
chip.direction_input = msic_gpio_direction_input;
289 mg->
chip.direction_output = msic_gpio_direction_output;
290 mg->
chip.get = msic_gpio_get;
291 mg->
chip.set = msic_gpio_set;
292 mg->
chip.to_irq = msic_gpio_to_irq;
295 mg->
chip.can_sleep = 1;
302 dev_err(dev,
"Adding MSIC gpio chip failed\n");
306 for (i = 0; i < mg->
chip.ngpio; i++) {
313 irq_set_chained_handler(mg->
irq, msic_gpio_irq_handler);
327 .probe = platform_msic_gpio_probe,
330 static int __init platform_msic_gpio_init(
void)