summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-pca9570.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-pca9570.c')
-rw-r--r--drivers/gpio/gpio-pca9570.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c
index cb2b2f735c15..c5a1287079a0 100644
--- a/drivers/gpio/gpio-pca9570.c
+++ b/drivers/gpio/gpio-pca9570.c
@@ -15,14 +15,28 @@
#include <linux/mutex.h>
#include <linux/property.h>
+#define SLG7XL45106_GPO_REG 0xDB
+
+/**
+ * struct pca9570_chip_data - GPIO platformdata
+ * @ngpio: no of gpios
+ * @command: Command to be sent
+ */
+struct pca9570_chip_data {
+ u16 ngpio;
+ u32 command;
+};
+
/**
* struct pca9570 - GPIO driver data
* @chip: GPIO controller chip
+ * @chip_data: GPIO controller platform data
* @lock: Protects write sequences
* @out: Buffer for device register
*/
struct pca9570 {
struct gpio_chip chip;
+ const struct pca9570_chip_data *chip_data;
struct mutex lock;
u8 out;
};
@@ -32,7 +46,11 @@ static int pca9570_read(struct pca9570 *gpio, u8 *value)
struct i2c_client *client = to_i2c_client(gpio->chip.parent);
int ret;
- ret = i2c_smbus_read_byte(client);
+ if (gpio->chip_data->command != 0)
+ ret = i2c_smbus_read_byte_data(client, gpio->chip_data->command);
+ else
+ ret = i2c_smbus_read_byte(client);
+
if (ret < 0)
return ret;
@@ -44,6 +62,9 @@ static int pca9570_write(struct pca9570 *gpio, u8 value)
{
struct i2c_client *client = to_i2c_client(gpio->chip.parent);
+ if (gpio->chip_data->command != 0)
+ return i2c_smbus_write_byte_data(client, gpio->chip_data->command, value);
+
return i2c_smbus_write_byte(client, value);
}
@@ -67,7 +88,7 @@ static int pca9570_get(struct gpio_chip *chip, unsigned offset)
return !!(buffer & BIT(offset));
}
-static void pca9570_set(struct gpio_chip *chip, unsigned offset, int value)
+static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
{
struct pca9570 *gpio = gpiochip_get_data(chip);
u8 buffer;
@@ -89,6 +110,7 @@ static void pca9570_set(struct gpio_chip *chip, unsigned offset, int value)
out:
mutex_unlock(&gpio->lock);
+ return ret;
}
static int pca9570_probe(struct i2c_client *client)
@@ -106,7 +128,8 @@ static int pca9570_probe(struct i2c_client *client)
gpio->chip.get = pca9570_get;
gpio->chip.set = pca9570_set;
gpio->chip.base = -1;
- gpio->chip.ngpio = (uintptr_t)device_get_match_data(&client->dev);
+ gpio->chip_data = device_get_match_data(&client->dev);
+ gpio->chip.ngpio = gpio->chip_data->ngpio;
gpio->chip.can_sleep = true;
mutex_init(&gpio->lock);
@@ -119,14 +142,31 @@ static int pca9570_probe(struct i2c_client *client)
return devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio);
}
+static const struct pca9570_chip_data pca9570_gpio = {
+ .ngpio = 4,
+};
+
+static const struct pca9570_chip_data pca9571_gpio = {
+ .ngpio = 8,
+};
+
+static const struct pca9570_chip_data slg7xl45106_gpio = {
+ .ngpio = 8,
+ .command = SLG7XL45106_GPO_REG,
+};
+
static const struct i2c_device_id pca9570_id_table[] = {
- { "pca9570", 4 },
+ { "pca9570", (kernel_ulong_t)&pca9570_gpio},
+ { "pca9571", (kernel_ulong_t)&pca9571_gpio },
+ { "slg7xl45106", (kernel_ulong_t)&slg7xl45106_gpio },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(i2c, pca9570_id_table);
static const struct of_device_id pca9570_of_match_table[] = {
- { .compatible = "nxp,pca9570", .data = (void *)4 },
+ { .compatible = "dlg,slg7xl45106", .data = &slg7xl45106_gpio},
+ { .compatible = "nxp,pca9570", .data = &pca9570_gpio },
+ { .compatible = "nxp,pca9571", .data = &pca9571_gpio },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, pca9570_of_match_table);
@@ -136,7 +176,7 @@ static struct i2c_driver pca9570_driver = {
.name = "pca9570",
.of_match_table = pca9570_of_match_table,
},
- .probe_new = pca9570_probe,
+ .probe = pca9570_probe,
.id_table = pca9570_id_table,
};
module_i2c_driver(pca9570_driver);