mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
gpio-exar/8250-exar: Make set of exported GPIOs configurable
On the SIMATIC, IOT2040 only a single pin is exportable as GPIO, the rest is required to operate the UART. To allow modeling this case, expand the platform device data structure to specify a (consecutive) pin subset for exporting by the gpio-exar driver. Signed-off-by: Jan Kiszka <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
This commit is contained in:
parent
277036f05b
commit
380b1e2f3a
2 changed files with 45 additions and 26 deletions
|
|
@ -31,6 +31,7 @@ struct exar_gpio_chip {
|
|||
int index;
|
||||
void __iomem *regs;
|
||||
char name[20];
|
||||
unsigned int first_pin;
|
||||
};
|
||||
|
||||
static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
|
||||
|
|
@ -51,11 +52,12 @@ static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
|
|||
static int exar_set_direction(struct gpio_chip *chip, int direction,
|
||||
unsigned int offset)
|
||||
{
|
||||
unsigned int bank = offset / 8;
|
||||
unsigned int addr;
|
||||
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
|
||||
unsigned int addr = (offset + exar_gpio->first_pin) / 8 ?
|
||||
EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
|
||||
unsigned int bit = (offset + exar_gpio->first_pin) % 8;
|
||||
|
||||
addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
|
||||
exar_update(chip, addr, direction, offset % 8);
|
||||
exar_update(chip, addr, direction, bit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -73,36 +75,33 @@ static int exar_get(struct gpio_chip *chip, unsigned int reg)
|
|||
|
||||
static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
|
||||
{
|
||||
unsigned int bank = offset / 8;
|
||||
unsigned int addr;
|
||||
int val;
|
||||
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
|
||||
unsigned int addr = (offset + exar_gpio->first_pin) / 8 ?
|
||||
EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
|
||||
unsigned int bit = (offset + exar_gpio->first_pin) % 8;
|
||||
|
||||
addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
|
||||
val = exar_get(chip, addr) & BIT(offset % 8);
|
||||
|
||||
return !!val;
|
||||
return !!(exar_get(chip, addr) & BIT(bit));
|
||||
}
|
||||
|
||||
static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
|
||||
{
|
||||
unsigned int bank = offset / 8;
|
||||
unsigned int addr;
|
||||
int val;
|
||||
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
|
||||
unsigned int addr = (offset + exar_gpio->first_pin) / 8 ?
|
||||
EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
|
||||
unsigned int bit = (offset + exar_gpio->first_pin) % 8;
|
||||
|
||||
addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
|
||||
val = exar_get(chip, addr) & BIT(offset % 8);
|
||||
|
||||
return !!val;
|
||||
return !!(exar_get(chip, addr) & BIT(bit));
|
||||
}
|
||||
|
||||
static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
|
||||
int value)
|
||||
{
|
||||
unsigned int bank = offset / 8;
|
||||
unsigned int addr;
|
||||
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
|
||||
unsigned int addr = (offset + exar_gpio->first_pin) / 8 ?
|
||||
EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
|
||||
unsigned int bit = (offset + exar_gpio->first_pin) % 8;
|
||||
|
||||
addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
|
||||
exar_update(chip, addr, value, offset % 8);
|
||||
exar_update(chip, addr, value, bit);
|
||||
}
|
||||
|
||||
static int exar_direction_output(struct gpio_chip *chip, unsigned int offset,
|
||||
|
|
@ -121,6 +120,7 @@ static int gpio_exar_probe(struct platform_device *pdev)
|
|||
{
|
||||
struct pci_dev *pcidev = to_pci_dev(pdev->dev.parent);
|
||||
struct exar_gpio_chip *exar_gpio;
|
||||
u32 first_pin, ngpios;
|
||||
void __iomem *p;
|
||||
int index, ret;
|
||||
|
||||
|
|
@ -132,6 +132,15 @@ static int gpio_exar_probe(struct platform_device *pdev)
|
|||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = device_property_read_u32(&pdev->dev, "linux,first-pin",
|
||||
&first_pin);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = device_property_read_u32(&pdev->dev, "ngpios", &ngpios);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
exar_gpio = devm_kzalloc(&pdev->dev, sizeof(*exar_gpio), GFP_KERNEL);
|
||||
if (!exar_gpio)
|
||||
return -ENOMEM;
|
||||
|
|
@ -149,9 +158,10 @@ static int gpio_exar_probe(struct platform_device *pdev)
|
|||
exar_gpio->gpio_chip.get = exar_get_value;
|
||||
exar_gpio->gpio_chip.set = exar_set_value;
|
||||
exar_gpio->gpio_chip.base = -1;
|
||||
exar_gpio->gpio_chip.ngpio = 16;
|
||||
exar_gpio->gpio_chip.ngpio = ngpios;
|
||||
exar_gpio->regs = p;
|
||||
exar_gpio->index = index;
|
||||
exar_gpio->first_pin = first_pin;
|
||||
|
||||
ret = devm_gpiochip_add_data(&pdev->dev,
|
||||
&exar_gpio->gpio_chip, exar_gpio);
|
||||
|
|
|
|||
Loading…
Reference in a new issue