Source
x
static int lp3943_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
/*
* TI/National Semiconductor LP3943 GPIO driver
*
* Copyright 2013 Texas Instruments
*
* Author: Milo Kim <milo.kim@ti.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2.
*/
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 */
};
static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset)
{
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;
}
static void lp3943_gpio_free(struct gpio_chip *chip, unsigned offset)
{
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
struct lp3943 *lp3943 = lp3943_gpio->lp3943;
clear_bit(offset, &lp3943->pin_used);
}
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);
}
static int lp3943_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{
struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
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,
struct gpio_chip *chip, unsigned offset)
{
u8 addr, read;
int err;