drivers/gpio/gpio-max77759.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpio/gpio-max77759.c
Extension
.c
Size
14243 bytes
Lines
525
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 max77759_gpio_chip {
	struct regmap *map;
	struct max77759 *max77759;
	struct gpio_chip gc;
	struct mutex maxq_lock; /* protect MaxQ r/m/w operations */

	struct mutex irq_lock; /* protect irq bus */
	int irq_mask;
	int irq_mask_changed;
	int irq_trig;
	int irq_trig_changed;
};

#define MAX77759_GPIOx_TRIGGER(offs, val) (((val) & 1) << (offs))
#define MAX77759_GPIOx_TRIGGER_MASK(offs) MAX77759_GPIOx_TRIGGER(offs, ~0)
enum max77759_trigger_gpio_type {
	MAX77759_GPIO_TRIGGER_RISING = 0,
	MAX77759_GPIO_TRIGGER_FALLING = 1
};

#define MAX77759_GPIOx_DIR(offs, dir) (((dir) & 1) << (2 + (3 * (offs))))
#define MAX77759_GPIOx_DIR_MASK(offs) MAX77759_GPIOx_DIR(offs, ~0)
enum max77759_control_gpio_dir {
	MAX77759_GPIO_DIR_IN = 0,
	MAX77759_GPIO_DIR_OUT = 1
};

#define MAX77759_GPIOx_OUTVAL(offs, val) (((val) & 1) << (3 + (3 * (offs))))
#define MAX77759_GPIOx_OUTVAL_MASK(offs) MAX77759_GPIOx_OUTVAL(offs, ~0)

#define MAX77759_GPIOx_INVAL_MASK(offs) (BIT(4) << (3 * (offs)))

static int max77759_gpio_maxq_gpio_trigger_read(struct max77759_gpio_chip *chip)
{
	DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length, 1);
	DEFINE_FLEX(struct max77759_maxq_response, rsp, rsp, length, 2);
	int ret;

	cmd->cmd[0] = MAX77759_MAXQ_OPCODE_GPIO_TRIGGER_READ;

	ret = max77759_maxq_command(chip->max77759, cmd, rsp);
	if (ret < 0)
		return ret;

	return rsp->rsp[1];
}

static int max77759_gpio_maxq_gpio_trigger_write(struct max77759_gpio_chip *chip,
						 u8 trigger)
{
	DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length, 2);

	cmd->cmd[0] = MAX77759_MAXQ_OPCODE_GPIO_TRIGGER_WRITE;
	cmd->cmd[1] = trigger;

	return max77759_maxq_command(chip->max77759, cmd, NULL);
}

static int max77759_gpio_maxq_gpio_control_read(struct max77759_gpio_chip *chip)
{
	DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length, 1);
	DEFINE_FLEX(struct max77759_maxq_response, rsp, rsp, length, 2);
	int ret;

	cmd->cmd[0] = MAX77759_MAXQ_OPCODE_GPIO_CONTROL_READ;

	ret = max77759_maxq_command(chip->max77759, cmd, rsp);
	if (ret < 0)
		return ret;

	return rsp->rsp[1];
}

static int max77759_gpio_maxq_gpio_control_write(struct max77759_gpio_chip *chip,
						 u8 ctrl)
{
	DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length, 2);

	cmd->cmd[0] = MAX77759_MAXQ_OPCODE_GPIO_CONTROL_WRITE;
	cmd->cmd[1] = ctrl;

	return max77759_maxq_command(chip->max77759, cmd, NULL);
}

static int
max77759_gpio_direction_from_control(int ctrl, unsigned int offset)
{
	enum max77759_control_gpio_dir dir;

	dir = !!(ctrl & MAX77759_GPIOx_DIR_MASK(offset));

Annotation

Implementation Notes