drivers/power/supply/rt9467-charger.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/rt9467-charger.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/rt9467-charger.c
Extension
.c
Size
34162 bytes
Lines
1258
Domain
Driver Families
Bucket
drivers/power
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 rt9467_chg_data {
	struct device *dev;
	struct regmap *regmap;
	struct regmap_field *rm_field[F_MAX_FIELDS];
	struct regmap_irq_chip_data *irq_chip_data;
	struct power_supply *psy;
	struct mutex adc_lock;
	struct mutex attach_lock;
	struct mutex ichg_ieoc_lock;
	struct regulator_dev *rdev;
	struct completion aicl_done;
	enum power_supply_usb_type psy_usb_type;
	unsigned int old_stat;
	unsigned int vid;
	int ichg_ua;
	int ieoc_ua;
};

static int rt9467_otg_of_parse_cb(struct device_node *of,
				  const struct regulator_desc *desc,
				  struct regulator_config *cfg)
{
	struct rt9467_chg_data *data = cfg->driver_data;

	cfg->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(of),
						"enable", 0, GPIOD_OUT_LOW |
						GPIOD_FLAGS_BIT_NONEXCLUSIVE,
						desc->name);
	if (IS_ERR(cfg->ena_gpiod)) {
		cfg->ena_gpiod = NULL;
		return 0;
	}

	return regmap_field_write(data->rm_field[F_OTG_PIN_EN], 1);
}

static const struct regulator_ops rt9467_otg_regulator_ops = {
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.is_enabled = regulator_is_enabled_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_current_limit = regulator_set_current_limit_regmap,
	.get_current_limit = regulator_get_current_limit_regmap,
};

static const u32 rt9467_otg_microamp[] = {
	500000, 700000, 1100000, 1300000, 1800000, 2100000, 2400000, 3000000
};

static const struct regulator_desc rt9467_otg_desc = {
	.name = "rt9476-usb-otg-vbus",
	.of_match = "usb-otg-vbus-regulator",
	.of_parse_cb = rt9467_otg_of_parse_cb,
	.type = REGULATOR_VOLTAGE,
	.owner = THIS_MODULE,
	.min_uV = RT9467_OTG_MIN_uV,
	.uV_step = RT9467_OTG_STEP_uV,
	.n_voltages = RT9467_NUM_VOTG,
	.curr_table = rt9467_otg_microamp,
	.n_current_limits = ARRAY_SIZE(rt9467_otg_microamp),
	.csel_reg = RT9467_REG_CHG_CTRL10,
	.csel_mask = RT9467_MASK_OTG_CSEL,
	.vsel_reg = RT9467_REG_CHG_CTRL5,
	.vsel_mask = RT9467_MASK_OTG_VSEL,
	.enable_reg = RT9467_REG_CHG_CTRL1,
	.enable_mask = RT9467_MASK_OTG_EN,
	.ops = &rt9467_otg_regulator_ops,
};

static int rt9467_register_otg_regulator(struct rt9467_chg_data *data)
{
	struct regulator_config cfg = {
		.dev = data->dev,
		.regmap = data->regmap,
		.driver_data = data,
	};

	data->rdev = devm_regulator_register(data->dev, &rt9467_otg_desc, &cfg);
	return PTR_ERR_OR_ZERO(data->rdev);
}

static int rt9467_get_value_from_ranges(struct rt9467_chg_data *data,
					enum rt9467_fields field,
					enum rt9467_ranges rsel,
					int *value)
{
	const struct linear_range *range = rt9467_ranges + rsel;
	unsigned int sel;

Annotation

Implementation Notes