drivers/gpio/gpio-waveshare-dsi.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-waveshare-dsi.c
Extension
.c
Size
5111 bytes
Lines
209
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 waveshare_gpio {
	struct mutex dir_lock;
	struct mutex pwr_lock;
	struct regmap *regmap;
	u16 poweron_state;

	struct gpio_chip gc;
};

static const struct regmap_config waveshare_gpio_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = REG_VERSION,
};

static int waveshare_gpio_get(struct waveshare_gpio *state, unsigned int offset)
{
	u16 pwr_state;

	guard(mutex)(&state->pwr_lock);
	pwr_state = state->poweron_state & BIT(offset);

	return !!pwr_state;
}

static int waveshare_gpio_set(struct waveshare_gpio *state, unsigned int offset, int value)
{
	u16 last_val;
	int err;

	guard(mutex)(&state->pwr_lock);

	last_val = state->poweron_state;
	if (value)
		last_val |= BIT(offset);
	else
		last_val &= ~BIT(offset);

	state->poweron_state = last_val;

	err = regmap_write(state->regmap, REG_TP, last_val >> 8);
	if (!err)
		err = regmap_write(state->regmap, REG_LCD, last_val & 0xff);

	return err;
}

static int waveshare_gpio_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
{
	return GPIO_LINE_DIRECTION_OUT;
}

static int waveshare_gpio_gpio_get(struct gpio_chip *gc, unsigned int offset)
{
	struct waveshare_gpio *state = gpiochip_get_data(gc);

	return waveshare_gpio_get(state, offset);
}

static int waveshare_gpio_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
{
	struct waveshare_gpio *state = gpiochip_get_data(gc);

	return waveshare_gpio_set(state, offset, value);
}

static int waveshare_gpio_update_status(struct backlight_device *bl)
{
	struct waveshare_gpio *state = bl_get_data(bl);
	int brightness = backlight_get_brightness(bl);

	waveshare_gpio_set(state, GPIO_BL_ENABLE, brightness);

	return regmap_write(state->regmap, REG_PWM, brightness);
}

static const struct backlight_ops waveshare_gpio_bl = {
	.update_status = waveshare_gpio_update_status,
};

static int waveshare_gpio_probe(struct i2c_client *i2c)
{
	struct backlight_properties props = {};
	struct waveshare_gpio *state;
	struct device *dev = &i2c->dev;
	struct backlight_device *bl;
	struct regmap *regmap;
	unsigned int data;
	int ret;

Annotation

Implementation Notes