drivers/regulator/tps6287x-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/tps6287x-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/tps6287x-regulator.c- Extension
.c- Size
- 6774 bytes
- Lines
- 255
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/regmap.hlinux/regulator/of_regulator.hlinux/regulator/machine.hlinux/regulator/driver.hlinux/bitfield.hlinux/linear_range.h
Detected Declarations
struct tps6287x_reg_datafunction Copyrightfunction tps6287x_best_rangefunction tps6287x_set_modefunction tps6287x_get_modefunction tps6287x_of_map_modefunction tps6287x_map_voltagefunction tps6287x_i2c_probe
Annotated Snippet
struct tps6287x_reg_data {
int range;
};
static int tps6287x_best_range(struct regulator_config *config, const struct regulator_desc *desc)
{
const struct linear_range *r;
int i;
if (!config->init_data->constraints.apply_uV)
return -1;
for (i = 0; i < desc->n_linear_ranges; i++) {
r = &desc->linear_ranges[i];
if (r->min <= config->init_data->constraints.min_uV &&
config->init_data->constraints.max_uV <= linear_range_get_max_value(r))
return i;
}
return -1;
}
static int tps6287x_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
unsigned int val;
switch (mode) {
case REGULATOR_MODE_NORMAL:
val = 0;
break;
case REGULATOR_MODE_FAST:
val = TPS6287X_CTRL1_FPWMEN;
break;
default:
return -EINVAL;
}
return regmap_update_bits(rdev->regmap, TPS6287X_CTRL1,
TPS6287X_CTRL1_FPWMEN, val);
}
static unsigned int tps6287x_get_mode(struct regulator_dev *rdev)
{
unsigned int val;
int ret;
ret = regmap_read(rdev->regmap, TPS6287X_CTRL1, &val);
if (ret < 0)
return 0;
return (val & TPS6287X_CTRL1_FPWMEN) ? REGULATOR_MODE_FAST :
REGULATOR_MODE_NORMAL;
}
static unsigned int tps6287x_of_map_mode(unsigned int mode)
{
switch (mode) {
case REGULATOR_MODE_NORMAL:
case REGULATOR_MODE_FAST:
return mode;
default:
return REGULATOR_MODE_INVALID;
}
}
static int tps6287x_map_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
{
struct tps6287x_reg_data *data = (struct tps6287x_reg_data *)rdev->reg_data;
struct linear_range selected_range;
int selector, voltage;
if (!data || data->range == -1)
return regulator_map_voltage_pickable_linear_range(rdev, min_uV, max_uV);
selected_range = rdev->desc->linear_ranges[data->range];
selector = DIV_ROUND_UP(min_uV - selected_range.min, selected_range.step);
if (selector < selected_range.min_sel || selector > selected_range.max_sel)
return -EINVAL;
selector |= tps6287x_voltage_range_prefix[data->range];
voltage = rdev->desc->ops->list_voltage(rdev, selector);
if (voltage < min_uV || voltage > max_uV)
return -EINVAL;
return selector;
}
static const struct regulator_ops tps6287x_regulator_ops = {
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.set_mode = tps6287x_set_mode,
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/regmap.h`, `linux/regulator/of_regulator.h`, `linux/regulator/machine.h`, `linux/regulator/driver.h`.
- Detected declarations: `struct tps6287x_reg_data`, `function Copyright`, `function tps6287x_best_range`, `function tps6287x_set_mode`, `function tps6287x_get_mode`, `function tps6287x_of_map_mode`, `function tps6287x_map_voltage`, `function tps6287x_i2c_probe`.
- Atlas domain: Driver Families / drivers/regulator.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.