diff options
author | Max Krummenacher <max.krummenacher@toradex.com> | 2018-09-13 14:08:13 +0200 |
---|---|---|
committer | Max Krummenacher <max.krummenacher@toradex.com> | 2018-11-08 11:31:52 +0100 |
commit | a7d303d7d63d444ed012200e98e6575814439101 (patch) | |
tree | aa84725eab2dc479796b674dc79fd6ef51fd0d4d | |
parent | f8df25d5785377f11fe8a757346ba8241847fb8d (diff) |
gpio-fxl6408.c: add of properties to set inital direction and state
inital_io_dir: a 1 at a bit positions sets the corresponding pin as output.
inital_output: a 1 sets a gpio which is set to output with inital_io_dir to 1.
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
-rw-r--r-- | drivers/gpio/gpio-fxl6408.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/drivers/gpio/gpio-fxl6408.c b/drivers/gpio/gpio-fxl6408.c index e68c8a49f868..22d193c4d9d5 100644 --- a/drivers/gpio/gpio-fxl6408.c +++ b/drivers/gpio/gpio-fxl6408.c @@ -154,6 +154,7 @@ static int fxl6408_probe(struct i2c_client *client, struct device *dev = &client->dev; struct fxl6408_chip *chip; struct gpio_chip *gc; + unsigned int val; int ret; u8 device_id; @@ -182,8 +183,21 @@ static int fxl6408_probe(struct i2c_client *client, chip->client = client; mutex_init(&chip->i2c_lock); - chip->reg_io_dir = i2c_smbus_read_byte_data(client, FXL6408_IO_DIR); - chip->reg_output = i2c_smbus_read_byte_data(client, FXL6408_OUTPUT); + + /* if configured, set initial output state and direction, + * otherwise read them from the chip */ + if (of_property_read_u32(dev->of_node, "inital_io_dir", &val)) { + chip->reg_io_dir = i2c_smbus_read_byte_data(client, FXL6408_IO_DIR); + } else { + chip->reg_io_dir = val & 0xff; + i2c_smbus_write_byte_data(client, FXL6408_IO_DIR, chip->reg_io_dir); + } + if (of_property_read_u32(dev->of_node, "inital_output", &val)) { + chip->reg_output = i2c_smbus_read_byte_data(client, FXL6408_OUTPUT); + } else { + chip->reg_output = val & 0xff; + i2c_smbus_write_byte_data(client, FXL6408_OUTPUT, chip->reg_output); + } gc = &chip->gpio_chip; gc->direction_input = fxl6408_gpio_direction_input; |