drivers/regulator/tps6524x-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/tps6524x-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/tps6524x-regulator.c- Extension
.c- Size
- 15006 bytes
- Lines
- 640
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/module.hlinux/err.hlinux/errno.hlinux/slab.hlinux/spi/spi.hlinux/regulator/driver.hlinux/regulator/machine.h
Detected Declarations
struct fieldstruct supply_infostruct tps6524xfunction __read_regfunction read_regfunction __write_regfunction __rmw_regfunction rmw_protectfunction read_fieldfunction write_fieldfunction set_voltage_selfunction get_voltage_selfunction set_current_limitfunction get_current_limitfunction enable_supplyfunction disable_supplyfunction is_supply_enabledfunction pmic_probe
Annotated Snippet
struct field {
int reg;
int shift;
int mask;
};
struct supply_info {
const char *name;
int n_voltages;
const unsigned int *voltages;
int n_ilimsels;
const unsigned int *ilimsels;
struct field enable, voltage, ilimsel;
};
struct tps6524x {
struct device *dev;
struct spi_device *spi;
struct mutex lock;
struct regulator_desc desc[N_REGULATORS];
};
static int __read_reg(struct tps6524x *hw, int reg)
{
int error = 0;
u16 cmd = CMD_READ(reg), in;
u8 status;
struct spi_message m;
struct spi_transfer t[3];
spi_message_init(&m);
memset(t, 0, sizeof(t));
t[0].tx_buf = &cmd;
t[0].len = 2;
t[0].bits_per_word = 12;
spi_message_add_tail(&t[0], &m);
t[1].rx_buf = ∈
t[1].len = 2;
t[1].bits_per_word = 16;
spi_message_add_tail(&t[1], &m);
t[2].rx_buf = &status;
t[2].len = 1;
t[2].bits_per_word = 4;
spi_message_add_tail(&t[2], &m);
error = spi_sync(hw->spi, &m);
if (error < 0)
return error;
dev_dbg(hw->dev, "read reg %d, data %x, status %x\n",
reg, in, status);
if (!(status & STAT_CLK) || (status & STAT_WRITE))
return -EIO;
if (status & STAT_INVALID)
return -EINVAL;
return in;
}
static int read_reg(struct tps6524x *hw, int reg)
{
int ret;
mutex_lock(&hw->lock);
ret = __read_reg(hw, reg);
mutex_unlock(&hw->lock);
return ret;
}
static int __write_reg(struct tps6524x *hw, int reg, int val)
{
int error = 0;
u16 cmd = CMD_WRITE(reg), out = val;
u8 status;
struct spi_message m;
struct spi_transfer t[3];
spi_message_init(&m);
memset(t, 0, sizeof(t));
t[0].tx_buf = &cmd;
t[0].len = 2;
t[0].bits_per_word = 12;
spi_message_add_tail(&t[0], &m);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/err.h`, `linux/errno.h`, `linux/slab.h`, `linux/spi/spi.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`.
- Detected declarations: `struct field`, `struct supply_info`, `struct tps6524x`, `function __read_reg`, `function read_reg`, `function __write_reg`, `function __rmw_reg`, `function rmw_protect`, `function read_field`, `function write_field`.
- Atlas domain: Driver Families / drivers/regulator.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.