2019-05-31 16:09:32 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
/*
|
|
|
|
* TI/National Semiconductor LP3943 GPIO driver
|
|
|
|
*
|
|
|
|
* Copyright 2013 Texas Instruments
|
|
|
|
*
|
|
|
|
* Author: Milo Kim <milo.kim@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/err.h>
|
2018-04-13 20:37:12 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/mfd/lp3943.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
enum lp3943_gpios {
|
|
|
|
LP3943_GPIO1,
|
|
|
|
LP3943_GPIO2,
|
|
|
|
LP3943_GPIO3,
|
|
|
|
LP3943_GPIO4,
|
|
|
|
LP3943_GPIO5,
|
|
|
|
LP3943_GPIO6,
|
|
|
|
LP3943_GPIO7,
|
|
|
|
LP3943_GPIO8,
|
|
|
|
LP3943_GPIO9,
|
|
|
|
LP3943_GPIO10,
|
|
|
|
LP3943_GPIO11,
|
|
|
|
LP3943_GPIO12,
|
|
|
|
LP3943_GPIO13,
|
|
|
|
LP3943_GPIO14,
|
|
|
|
LP3943_GPIO15,
|
|
|
|
LP3943_GPIO16,
|
|
|
|
LP3943_MAX_GPIO,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lp3943_gpio {
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct lp3943 *lp3943;
|
|
|
|
u16 input_mask; /* 1 = GPIO is input direction, 0 = output */
|
|
|
|
};
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static int lp3943_gpio_request(struct gpio_chip *chip, unsigned int offset)
|
2016-03-09 23:00:27 +08:00
|
|
|
{
|
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
|
|
|
struct lp3943 *lp3943 = lp3943_gpio->lp3943;
|
|
|
|
|
|
|
|
/* Return an error if the pin is already assigned */
|
|
|
|
if (test_and_set_bit(offset, &lp3943->pin_used))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static void lp3943_gpio_free(struct gpio_chip *chip, unsigned int offset)
|
2016-03-09 23:00:27 +08:00
|
|
|
{
|
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
|
|
|
struct lp3943 *lp3943 = lp3943_gpio->lp3943;
|
|
|
|
|
|
|
|
clear_bit(offset, &lp3943->pin_used);
|
|
|
|
}
|
|
|
|
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
static int lp3943_gpio_set_mode(struct lp3943_gpio *lp3943_gpio, u8 offset,
|
|
|
|
u8 val)
|
|
|
|
{
|
|
|
|
struct lp3943 *lp3943 = lp3943_gpio->lp3943;
|
|
|
|
const struct lp3943_reg_cfg *mux = lp3943->mux_cfg;
|
|
|
|
|
|
|
|
return lp3943_update_bits(lp3943, mux[offset].reg, mux[offset].mask,
|
|
|
|
val << mux[offset].shift);
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static int lp3943_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
{
|
2015-12-07 16:10:13 +08:00
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
|
|
|
|
lp3943_gpio->input_mask |= BIT(offset);
|
|
|
|
|
|
|
|
return lp3943_gpio_set_mode(lp3943_gpio, offset, LP3943_GPIO_IN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lp3943_get_gpio_in_status(struct lp3943_gpio *lp3943_gpio,
|
2022-07-11 13:29:35 +08:00
|
|
|
struct gpio_chip *chip, unsigned int offset)
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
{
|
|
|
|
u8 addr, read;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case LP3943_GPIO1 ... LP3943_GPIO8:
|
|
|
|
addr = LP3943_REG_GPIO_A;
|
|
|
|
break;
|
|
|
|
case LP3943_GPIO9 ... LP3943_GPIO16:
|
|
|
|
addr = LP3943_REG_GPIO_B;
|
|
|
|
offset = offset - 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lp3943_read_byte(lp3943_gpio->lp3943, addr, &read);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return !!(read & BIT(offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lp3943_get_gpio_out_status(struct lp3943_gpio *lp3943_gpio,
|
2022-07-11 13:29:35 +08:00
|
|
|
struct gpio_chip *chip, unsigned int offset)
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
{
|
|
|
|
struct lp3943 *lp3943 = lp3943_gpio->lp3943;
|
|
|
|
const struct lp3943_reg_cfg *mux = lp3943->mux_cfg;
|
|
|
|
u8 read;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = lp3943_read_byte(lp3943, mux[offset].reg, &read);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
read = (read & mux[offset].mask) >> mux[offset].shift;
|
|
|
|
|
|
|
|
if (read == LP3943_GPIO_OUT_HIGH)
|
|
|
|
return 1;
|
|
|
|
else if (read == LP3943_GPIO_OUT_LOW)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static int lp3943_gpio_get(struct gpio_chip *chip, unsigned int offset)
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
{
|
2015-12-07 16:10:13 +08:00
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Limitation:
|
|
|
|
* LP3943 doesn't have the GPIO direction register. It provides
|
|
|
|
* only input and output status registers.
|
|
|
|
* So, direction info is required to handle the 'get' operation.
|
|
|
|
* This variable is updated whenever the direction is changed and
|
|
|
|
* it is used here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (lp3943_gpio->input_mask & BIT(offset))
|
|
|
|
return lp3943_get_gpio_in_status(lp3943_gpio, chip, offset);
|
|
|
|
else
|
|
|
|
return lp3943_get_gpio_out_status(lp3943_gpio, chip, offset);
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static void lp3943_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
{
|
2015-12-07 16:10:13 +08:00
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
u8 data;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
data = LP3943_GPIO_OUT_HIGH;
|
|
|
|
else
|
|
|
|
data = LP3943_GPIO_OUT_LOW;
|
|
|
|
|
|
|
|
lp3943_gpio_set_mode(lp3943_gpio, offset, data);
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:29:35 +08:00
|
|
|
static int lp3943_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
int value)
|
|
|
|
{
|
2015-12-07 16:10:13 +08:00
|
|
|
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
|
|
|
|
lp3943_gpio_set(chip, offset, value);
|
|
|
|
lp3943_gpio->input_mask &= ~BIT(offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gpio_chip lp3943_gpio_chip = {
|
|
|
|
.label = "lp3943",
|
|
|
|
.owner = THIS_MODULE,
|
2016-03-09 23:00:27 +08:00
|
|
|
.request = lp3943_gpio_request,
|
|
|
|
.free = lp3943_gpio_free,
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
.direction_input = lp3943_gpio_direction_input,
|
|
|
|
.get = lp3943_gpio_get,
|
|
|
|
.direction_output = lp3943_gpio_direction_output,
|
|
|
|
.set = lp3943_gpio_set,
|
|
|
|
.base = -1,
|
|
|
|
.ngpio = LP3943_MAX_GPIO,
|
|
|
|
.can_sleep = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int lp3943_gpio_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
struct lp3943_gpio *lp3943_gpio;
|
|
|
|
|
|
|
|
lp3943_gpio = devm_kzalloc(&pdev->dev, sizeof(*lp3943_gpio),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!lp3943_gpio)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
lp3943_gpio->lp3943 = lp3943;
|
|
|
|
lp3943_gpio->chip = lp3943_gpio_chip;
|
2015-11-04 16:56:26 +08:00
|
|
|
lp3943_gpio->chip.parent = &pdev->dev;
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, lp3943_gpio);
|
|
|
|
|
2016-02-22 20:13:28 +08:00
|
|
|
return devm_gpiochip_add_data(&pdev->dev, &lp3943_gpio->chip,
|
|
|
|
lp3943_gpio);
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id lp3943_gpio_of_match[] = {
|
|
|
|
{ .compatible = "ti,lp3943-gpio", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, lp3943_gpio_of_match);
|
|
|
|
|
|
|
|
static struct platform_driver lp3943_gpio_driver = {
|
|
|
|
.probe = lp3943_gpio_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "lp3943-gpio",
|
2014-01-07 14:27:18 +08:00
|
|
|
.of_match_table = lp3943_gpio_of_match,
|
gpio: add LP3943 I2C GPIO expander driver
This is one of LP3943 MFD driver.
LP3943 is configurable as a GPIO expander, up to 16 GPIOs.
* Application note: how to configure LP3943 as a GPIO expander
http://www.ti.com/lit/an/snva287a/snva287a.pdf
* Supported GPIO controller operations
request, free, direction_input, direction_output, get and set
* GPIO direction register not supported
LP3943 doesn't have the GPIO direction register. It only provides input and
output status registers.
So, private data for the direction should be handled manually.
This variable is updated whenever the direction is changed and
used in 'get' operation.
* Pin assignment
A driver data, 'pin_used' is checked when a GPIO is requested.
If the GPIO is already assigned, then returns as failure.
If the GPIO is available, 'pin_used' is set.
When the GPIO is not used anymore, then it is cleared.
It is defined as unsigned long type for atomic bit operation APIs,
but only LSB 16bits are used because LP3943 has 16 outputs.
Signed-off-by: Milo Kim <milo.kim@ti.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2013-12-06 10:18:42 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
module_platform_driver(lp3943_gpio_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("LP3943 GPIO driver");
|
|
|
|
MODULE_ALIAS("platform:lp3943-gpio");
|
|
|
|
MODULE_AUTHOR("Milo Kim");
|
|
|
|
MODULE_LICENSE("GPL");
|