drivers/regulator/max20086-regulator.c

Source file repositories/reference/linux-study-clean/drivers/regulator/max20086-regulator.c

File Facts

System
Linux kernel
Corpus path
drivers/regulator/max20086-regulator.c
Extension
.c
Size
8555 bytes
Lines
336
Domain
Driver Families
Bucket
drivers/regulator
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 max20086_chip_info {
	u8 id;
	unsigned int num_outputs;
};

struct max20086_regulator {
	struct device_node *of_node;
	struct regulator_init_data *init_data;
	const struct regulator_desc *desc;
	struct regulator_dev *rdev;
};

struct max20086 {
	struct device *dev;
	struct regmap *regmap;
	struct gpio_desc *ena_gpiod;

	const struct max20086_chip_info *info;

	struct max20086_regulator regulators[MAX20086_MAX_REGULATORS];
};

static const struct regulator_ops max20086_buck_ops = {
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.is_enabled = regulator_is_enabled_regmap,
};

#define MAX20086_REGULATOR_DESC(n)		\
{						\
	.name = "OUT"#n,			\
	.supply_name = "in",			\
	.id = (n) - 1,				\
	.ops = &max20086_buck_ops,		\
	.type = REGULATOR_VOLTAGE,		\
	.owner = THIS_MODULE,			\
	.enable_reg = MAX20086_REG_CONFIG,	\
	.enable_mask = 1 << ((n) - 1),		\
	.enable_val = 1 << ((n) - 1),		\
	.disable_val = 0,			\
}

static const char * const max20086_output_names[] = {
	"OUT1",
	"OUT2",
	"OUT3",
	"OUT4",
};

static const struct regulator_desc max20086_regulators[] = {
	MAX20086_REGULATOR_DESC(1),
	MAX20086_REGULATOR_DESC(2),
	MAX20086_REGULATOR_DESC(3),
	MAX20086_REGULATOR_DESC(4),
};

static int max20086_regulators_register(struct max20086 *chip)
{
	unsigned int i;

	for (i = 0; i < chip->info->num_outputs; i++) {
		struct max20086_regulator *reg = &chip->regulators[i];
		struct regulator_config config = { };
		struct regulator_dev *rdev;

		config.dev = chip->dev;
		config.init_data = reg->init_data;
		config.driver_data = chip;
		config.of_node = reg->of_node;
		config.regmap = chip->regmap;
		config.ena_gpiod = chip->ena_gpiod;

		rdev = devm_regulator_register(chip->dev, reg->desc, &config);
		if (IS_ERR(rdev)) {
			dev_err(chip->dev,
				"Failed to register regulator output %s\n",
				reg->desc->name);
			return PTR_ERR(rdev);
		}

		reg->rdev = rdev;
	}

	return 0;
}

static int max20086_parse_regulators_dt(struct max20086 *chip, bool *boot_on)
{
	struct of_regulator_match *matches;
	unsigned int i;

Annotation

Implementation Notes