33 #include <linux/module.h>
39 #include <linux/slab.h>
44 #define PIN_CONFIG_MASK 0x03
45 #define PIN_CONFIG_IN_PULLUP 0x03
46 #define PIN_CONFIG_IN_WO_PULLUP 0x02
47 #define PIN_CONFIG_OUT 0x01
51 static int max7301_direction_input(
struct gpio_chip *
chip,
unsigned offset)
60 offset_bits = (offset & 3) << 1;
72 | (pin_config << offset_bits);
74 ret = ts->
write(ts->
dev, 0x08 + (offset >> 2), *config);
85 return ts->
write(ts->
dev, 0x20 + offset, 0x01);
88 return ts->
write(ts->
dev, 0x20 + offset, 0x00);
92 static int max7301_direction_output(
struct gpio_chip *
chip,
unsigned offset,
102 offset_bits = (offset & 3) << 1;
111 ret = __max7301_set(ts, offset, value);
114 ret = ts->
write(ts->
dev, 0x08 + (offset >> 2), *config);
121 static int max7301_get(
struct gpio_chip *chip,
unsigned offset)
131 config = (ts->
port_config[offset >> 2] >> ((offset & 3) << 1))
142 level = ts->
read(ts->
dev, 0x20 + offset) & 0x01;
149 static void max7301_set(
struct gpio_chip *chip,
unsigned offset,
int value)
158 __max7301_set(ts, offset, value);
170 if (!pdata || !pdata->
base) {
171 dev_err(dev,
"incorrect or missing platform data\n");
179 ts->
write(dev, 0x04, 0x01);
184 ts->
chip.direction_input = max7301_direction_input;
185 ts->
chip.get = max7301_get;
186 ts->
chip.direction_output = max7301_direction_output;
187 ts->
chip.set = max7301_set;
191 ts->
chip.can_sleep = 1;
199 for (i = 1; i < 8; i++) {
208 for (j = 0; j < 4; j++) {
209 int offset = (i - 1) * 4 + j;
210 ret = max7301_direction_input(&ts->
chip, offset);
240 ts->
write(dev, 0x04, 0x00);
247 dev_err(dev,
"Failed to remove GPIO controller: %d\n", ret);