drivers/platform/cznic/turris-omnia-mcu-gpio.c

Source file repositories/reference/linux-study-clean/drivers/platform/cznic/turris-omnia-mcu-gpio.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/cznic/turris-omnia-mcu-gpio.c
Extension
.c
Size
31425 bytes
Lines
1124
Domain
Driver Families
Bucket
drivers/platform
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 omnia_gpio {
	u8 cmd;
	u8 ctl_cmd;
	u8 bit;
	u8 ctl_bit;
	u8 int_bit;
	u16 feat;
	u16 feat_mask;
};

#define OMNIA_GPIO_INVALID_INT_BIT	0xff

#define _DEF_GPIO(_cmd, _ctl_cmd, _bit, _ctl_bit, _int_bit, _feat, _feat_mask) \
	{								\
		.cmd = _cmd,						\
		.ctl_cmd = _ctl_cmd,					\
		.bit = _bit,						\
		.ctl_bit = _ctl_bit,					\
		.int_bit = (_int_bit) < 0 ? OMNIA_GPIO_INVALID_INT_BIT	\
					  : (_int_bit),			\
		.feat = _feat,						\
		.feat_mask = _feat_mask,				\
	}

#define _DEF_GPIO_STS(_name) \
	_DEF_GPIO(OMNIA_CMD_GET_STATUS_WORD, 0, __bf_shf(OMNIA_STS_ ## _name), \
		  0, __bf_shf(OMNIA_INT_ ## _name), 0, 0)

#define _DEF_GPIO_CTL(_name) \
	_DEF_GPIO(OMNIA_CMD_GET_STATUS_WORD, OMNIA_CMD_GENERAL_CONTROL, \
		  __bf_shf(OMNIA_STS_ ## _name), __bf_shf(OMNIA_CTL_ ## _name), \
		  -1, 0, 0)

#define _DEF_GPIO_EXT_STS(_name, _feat) \
	_DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
		  __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
		  __bf_shf(OMNIA_INT_ ## _name), \
		  OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS, \
		  OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS)

#define _DEF_GPIO_EXT_STS_LED(_name, _ledext) \
	_DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
		  __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
		  __bf_shf(OMNIA_INT_ ## _name), \
		  OMNIA_FEAT_LED_STATE_ ## _ledext, \
		  OMNIA_FEAT_LED_STATE_EXT_MASK)

#define _DEF_GPIO_EXT_STS_LEDALL(_name) \
	_DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
		  __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
		  __bf_shf(OMNIA_INT_ ## _name), \
		  OMNIA_FEAT_LED_STATE_EXT_MASK, 0)

#define _DEF_GPIO_EXT_CTL(_name, _feat) \
	_DEF_GPIO(OMNIA_CMD_GET_EXT_CONTROL_STATUS, OMNIA_CMD_EXT_CONTROL, \
		  __bf_shf(OMNIA_EXT_CTL_ ## _name), \
		  __bf_shf(OMNIA_EXT_CTL_ ## _name), -1, \
		  OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS, \
		  OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS)

#define _DEF_INT(_name) \
	_DEF_GPIO(0, 0, 0, 0, __bf_shf(OMNIA_INT_ ## _name), 0, 0)

static inline bool is_int_bit_valid(const struct omnia_gpio *gpio)
{
	return gpio->int_bit != OMNIA_GPIO_INVALID_INT_BIT;
}

static const struct omnia_gpio omnia_gpios[64] = {
	/* GPIOs with value read from the 16-bit wide status */
	[4]  = _DEF_GPIO_STS(CARD_DET),
	[5]  = _DEF_GPIO_STS(MSATA_IND),
	[6]  = _DEF_GPIO_STS(USB30_OVC),
	[7]  = _DEF_GPIO_STS(USB31_OVC),
	[8]  = _DEF_GPIO_CTL(USB30_PWRON),
	[9]  = _DEF_GPIO_CTL(USB31_PWRON),

	/* brightness changed interrupt, no GPIO */
	[11] = _DEF_INT(BRIGHTNESS_CHANGED),

	[12] = _DEF_GPIO_STS(BUTTON_PRESSED),

	/* TRNG interrupt, no GPIO */
	[13] = _DEF_INT(TRNG),

	/* MESSAGE_SIGNED interrupt, no GPIO */
	[14] = _DEF_INT(MESSAGE_SIGNED),

	/* GPIOs with value read from the 32-bit wide extended status */
	[16] = _DEF_GPIO_EXT_STS(SFP_nDET, PERIPH_MCU),

Annotation

Implementation Notes