14 #include <linux/module.h>
26 #define DA9052_INPUT 1
27 #define DA9052_OUTPUT_OPENDRAIN 2
28 #define DA9052_OUTPUT_PUSHPULL 3
30 #define DA9052_SUPPLY_VDD_IO1 0
32 #define DA9052_DEBOUNCING_OFF 0
33 #define DA9052_DEBOUNCING_ON 1
35 #define DA9052_OUTPUT_LOWLEVEL 0
37 #define DA9052_ACTIVE_LOW 0
38 #define DA9052_ACTIVE_HIGH 1
40 #define DA9052_GPIO_MAX_PORTS_PER_REGISTER 8
41 #define DA9052_GPIO_SHIFT_COUNT(no) (no%8)
42 #define DA9052_GPIO_MASK_UPPER_NIBBLE 0xF0
43 #define DA9052_GPIO_MASK_LOWER_NIBBLE 0x0F
44 #define DA9052_GPIO_NIBBLE_SHIFT 4
45 #define DA9052_IRQ_GPI0 16
46 #define DA9052_GPIO_ODD_SHIFT 7
47 #define DA9052_GPIO_EVEN_SHIFT 3
54 static inline struct da9052_gpio *to_da9052_gpio(
struct gpio_chip *
chip)
59 static unsigned char da9052_gpio_port_odd(
unsigned offset)
64 static int da9052_gpio_get(
struct gpio_chip *
gc,
unsigned offset)
67 int da9052_port_direction = 0;
70 ret = da9052_reg_read(gpio->
da9052,
75 if (da9052_gpio_port_odd(offset)) {
77 da9052_port_direction >>= 4;
82 switch (da9052_port_direction) {
85 ret = da9052_reg_read(gpio->
da9052,
88 ret = da9052_reg_read(gpio->
da9052,
97 if (da9052_gpio_port_odd(offset))
106 static void da9052_gpio_set(
struct gpio_chip *gc,
unsigned offset,
int value)
111 if (da9052_gpio_port_odd(offset)) {
112 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
118 "Failed to updated gpio odd reg,%d",
121 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
127 "Failed to updated gpio even reg,%d",
132 static int da9052_gpio_direction_input(
struct gpio_chip *gc,
unsigned offset)
135 unsigned char register_value;
142 if (da9052_gpio_port_odd(offset))
143 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
149 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
157 static int da9052_gpio_direction_output(
struct gpio_chip *gc,
158 unsigned offset,
int value)
161 unsigned char register_value;
168 if (da9052_gpio_port_odd(offset))
169 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
175 ret = da9052_reg_update(gpio->
da9052, (offset >> 1) +
183 static int da9052_gpio_to_irq(
struct gpio_chip *gc,
u32 offset)
192 .label =
"da9052-gpio",
194 .get = da9052_gpio_get,
195 .set = da9052_gpio_set,
196 .direction_input = da9052_gpio_direction_input,
197 .direction_output = da9052_gpio_direction_output,
198 .to_irq = da9052_gpio_to_irq,
215 pdata = gpio->
da9052->dev->platform_data;
217 gpio->
gp = reference_gp;
223 dev_err(&pdev->
dev,
"Could not register gpiochip, %d\n", ret);
227 platform_set_drvdata(pdev, gpio);
234 struct da9052_gpio *gpio = platform_get_drvdata(pdev);
240 .probe = da9052_gpio_probe,
243 .name =
"da9052-gpio",