drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c

Source file repositories/reference/linux-study-clean/drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c

File Facts

System
Linux kernel
Corpus path
drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c
Extension
.c
Size
18258 bytes
Lines
738
Domain
Driver Families
Bucket
drivers/pinctrl
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 mpfs_pinctrl_mux_config {
	u8 pin;
	u8 function;
};

struct mpfs_pinctrl {
	struct pinctrl_dev *pctrl;
	struct device *dev;
	struct regmap *regmap;
	struct regmap *sysreg_regmap;
	struct mutex mutex;
	struct pinctrl_desc desc;
};

struct mpfs_pinctrl_drive_strength {
	u8 ma;
	u8 val;
};

struct mpfs_pinctrl_bank_voltage {
	u32 uv;
	u8 val;
};

static struct mpfs_pinctrl_drive_strength mpfs_pinctrl_drive_strengths[8] = {
	{ .ma = 2, .val = 2 },
	{ .ma = 4, .val = 3 },
	{ .ma = 6, .val = 4 },
	{ .ma = 8, .val = 5 },
	{ .ma = 10, .val = 6 },
	{ .ma = 12, .val = 7 },
	{ .ma = 16, .val = 10 },
	{ .ma = 20, .val = 12 },
};
static struct mpfs_pinctrl_bank_voltage mpfs_pinctrl_bank_voltages[8] = {
	{ .uv = 1200000, .val = 0 },
	{ .uv = 1500000, .val = 2 },
	{ .uv = 1800000, .val = 4 },
	{ .uv = 2500000, .val = 6 },
	{ .uv = 3300000, .val = 8 },
	{ .uv = 0, .val = 0x3f }, // pin unused
};

static int mpfs_pinctrl_get_drive_strength_ma(u32 drive_strength)
{
	size_t num = ARRAY_SIZE(mpfs_pinctrl_drive_strengths);

	for (int i = 0; i < num; i++)
		if (drive_strength == mpfs_pinctrl_drive_strengths[i].val)
			return mpfs_pinctrl_drive_strengths[i].ma;

	return -EINVAL;
}

static int mpfs_pinctrl_get_drive_strength_val(u32 drive_strength_ma)
{
	size_t num = ARRAY_SIZE(mpfs_pinctrl_drive_strengths);

	if (!drive_strength_ma)
		return -EINVAL;

	for (int i = 0; i < num; i++)
		if (drive_strength_ma <= mpfs_pinctrl_drive_strengths[i].ma)
			return mpfs_pinctrl_drive_strengths[i].val;

	return mpfs_pinctrl_drive_strengths[num - 1].val;
}

static int mpfs_pinctrl_get_bank_voltage_uv(u32 bank_voltage)
{
	size_t num = ARRAY_SIZE(mpfs_pinctrl_bank_voltages);

	for (int i = 0; i < num; i++)
		if (bank_voltage == mpfs_pinctrl_bank_voltages[i].val)
			return mpfs_pinctrl_bank_voltages[i].uv;

	return -EINVAL;
}

static int mpfs_pinctrl_get_bank_voltage_val(u32 bank_voltage_uv)
{
	size_t num = ARRAY_SIZE(mpfs_pinctrl_bank_voltages);

	for (int i = 0; i < num; i++)
		if (bank_voltage_uv <= mpfs_pinctrl_bank_voltages[i].uv)
			return mpfs_pinctrl_bank_voltages[i].val;

	return -EINVAL;
}

Annotation

Implementation Notes