15 #include <linux/kernel.h>
17 #include <linux/types.h>
23 #include <linux/slab.h>
40 static u8 u8_pin2mask(
unsigned int pin)
42 return 1 << (8 - 1 -
pin);
45 static int u8_gpio_get(
struct gpio_chip *
gc,
unsigned int gpio)
47 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
49 return in_8(mm_gc->regs) & u8_pin2mask(gpio);
52 static void u8_gpio_set(
struct gpio_chip *
gc,
unsigned int gpio,
int val)
54 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
61 u8_gc->
data |= u8_pin2mask(gpio);
63 u8_gc->
data &= ~u8_pin2mask(gpio);
67 spin_unlock_irqrestore(&u8_gc->
lock, flags);
70 static int u8_gpio_dir_in(
struct gpio_chip *gc,
unsigned int gpio)
75 static int u8_gpio_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
77 u8_gpio_set(gc, gpio, val);
81 static void u8_gpio_save_regs(
struct of_mm_gpio_chip *mm_gc)
92 struct of_mm_gpio_chip *mm_gc;
101 mm_gc = &u8_gc->
mm_gc;
104 mm_gc->save_regs = u8_gpio_save_regs;
106 gc->direction_input = u8_gpio_dir_in;
107 gc->direction_output = u8_gpio_dir_out;
108 gc->get = u8_gpio_get;
109 gc->set = u8_gpio_set;
124 for_each_compatible_node(np,
NULL, compatible) {
132 switch (resource_size(&r)) {
134 ret = u8_simple_gpiochip_add(np);
149 pr_err(
"%s: registration failed, status %d\n",