drivers/gpio/gpio-lp87565.c

Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-lp87565.c

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-lp87565.c
Extension
.c
Size
4475 bytes
Lines
191
Domain
Driver Families
Bucket
drivers/gpio
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct lp87565_gpio {
	struct gpio_chip chip;
	struct regmap *map;
};

static int lp87565_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(chip);
	int ret, val;

	ret = regmap_read(gpio->map, LP87565_REG_GPIO_IN, &val);
	if (ret < 0)
		return ret;

	return !!(val & BIT(offset));
}

static int lp87565_gpio_set(struct gpio_chip *chip, unsigned int offset,
			    int value)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(chip);

	return regmap_update_bits(gpio->map, LP87565_REG_GPIO_OUT,
				  BIT(offset), value ? BIT(offset) : 0);
}

static int lp87565_gpio_get_direction(struct gpio_chip *chip,
				      unsigned int offset)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(chip);
	int ret, val;

	ret = regmap_read(gpio->map, LP87565_REG_GPIO_CONFIG, &val);
	if (ret < 0)
		return ret;

	if (val & BIT(offset))
		return GPIO_LINE_DIRECTION_OUT;

	return GPIO_LINE_DIRECTION_IN;
}

static int lp87565_gpio_direction_input(struct gpio_chip *chip,
					unsigned int offset)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(chip);

	return regmap_update_bits(gpio->map,
				  LP87565_REG_GPIO_CONFIG,
				  BIT(offset), 0);
}

static int lp87565_gpio_direction_output(struct gpio_chip *chip,
					 unsigned int offset, int value)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(chip);
	int ret;

	ret = lp87565_gpio_set(chip, offset, value);
	if (ret)
		return ret;

	return regmap_update_bits(gpio->map,
				  LP87565_REG_GPIO_CONFIG,
				  BIT(offset), BIT(offset));
}

static int lp87565_gpio_request(struct gpio_chip *gc, unsigned int offset)
{
	struct lp87565_gpio *gpio = gpiochip_get_data(gc);
	int ret;

	switch (offset) {
	case 0:
	case 1:
	case 2:
		/*
		 * MUX can program the pin to be in EN1/2/3 pin mode
		 * Or GPIO1/2/3 mode.
		 * Setup the GPIO*_SEL MUX to GPIO mode
		 */
		ret = regmap_update_bits(gpio->map,
					 LP87565_REG_PIN_FUNCTION,
					 BIT(offset), BIT(offset));
		if (ret)
			return ret;

		break;
	default:
		return -EINVAL;

Annotation

Implementation Notes