10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
14 #include <linux/i2c.h>
21 #define DRV_NAME "adp5588-gpio"
28 #define WA_DELAYED_READOUT_REVID(rev) ((rev) < 4)
66 static int adp5588_gpio_get_value(
struct gpio_chip *
chip,
unsigned off)
71 return !!(adp5588_gpio_read(dev->
client,
75 static void adp5588_gpio_set_value(
struct gpio_chip *chip,
76 unsigned off,
int val)
96 static int adp5588_gpio_direction_input(
struct gpio_chip *chip,
unsigned off)
113 static int adp5588_gpio_direction_output(
struct gpio_chip *chip,
114 unsigned off,
int val)
141 #ifdef CONFIG_GPIO_ADP5588_IRQ
142 static int adp5588_gpio_to_irq(
struct gpio_chip *chip,
unsigned off)
149 static void adp5588_irq_bus_lock(
struct irq_data *
d)
151 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
164 static void adp5588_irq_bus_sync_unlock(
struct irq_data *
d)
166 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
179 static void adp5588_irq_mask(
struct irq_data *d)
181 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
187 static void adp5588_irq_unmask(
struct irq_data *d)
189 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
195 static int adp5588_irq_set_type(
struct irq_data *d,
unsigned int type)
197 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
217 adp5588_gpio_direction_input(&dev->
gpio_chip, gpio);
224 static struct irq_chip adp5588_irq_chip = {
226 .irq_mask = adp5588_irq_mask,
227 .irq_unmask = adp5588_irq_unmask,
228 .irq_bus_lock = adp5588_irq_bus_lock,
229 .irq_bus_sync_unlock = adp5588_irq_bus_sync_unlock,
230 .irq_set_type = adp5588_irq_set_type,
233 static int adp5588_gpio_read_intstat(
struct i2c_client *client,
u8 *
buf)
238 dev_err(&client->
dev,
"Read INT_STAT Error\n");
260 if (pending & (1 << bit)) {
263 pending &= ~(1 <<
bit);
284 adp5588_gpio_write(client,
INT_STAT, -1);
285 adp5588_gpio_read_intstat(client, dev->
irq_stat);
290 for (gpio = 0; gpio < dev->
gpio_chip.ngpio; gpio++) {
293 irq_set_chip_and_handler(irq, &adp5588_irq_chip,
295 irq_set_nested_thread(irq, 1);
303 irq_set_noprobe(irq);
311 dev_name(&client->
dev), dev);
313 dev_err(&client->
dev,
"failed to request irq %d\n",
318 dev->
gpio_chip.to_irq = adp5588_gpio_to_irq;
319 adp5588_gpio_write(client,
CFG,
329 static void adp5588_irq_teardown(
struct adp5588_gpio *dev)
339 dev_warn(&client->
dev,
"interrupt support not compiled in\n");
344 static void adp5588_irq_teardown(
struct adp5588_gpio *dev)
354 struct gpio_chip *
gc;
358 dev_err(&client->
dev,
"missing platform data\n");
362 if (!i2c_check_functionality(client->
adapter,
364 dev_err(&client->
dev,
"SMBUS Byte Data not Supported\n");
370 dev_err(&client->
dev,
"failed to alloc memory\n");
377 gc->direction_input = adp5588_gpio_direction_input;
378 gc->direction_output = adp5588_gpio_direction_output;
379 gc->get = adp5588_gpio_get_value;
380 gc->set = adp5588_gpio_set_value;
385 gc->label = client->
name;
399 ret |= adp5588_gpio_write(client,
KP_GPIO1 + i, 0);
400 ret |= adp5588_gpio_write(client,
GPIO_PULL1 + i,
409 dev_warn(&client->
dev,
"GPIO int not supported\n");
411 ret = adp5588_irq_setup(dev);
425 ret = pdata->
setup(client, gc->base, gc->ngpio, pdata->
context);
430 i2c_set_clientdata(client, dev);
435 adp5588_irq_teardown(dev);
452 dev_err(&client->
dev,
"teardown failed %d\n", ret);
462 dev_err(&client->
dev,
"gpiochip_remove failed %d\n", ret);
477 static struct i2c_driver adp5588_gpio_driver = {
481 .probe = adp5588_gpio_probe,
483 .id_table = adp5588_gpio_id,