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.

Dependency Surface

Detected Declarations

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

Implementation Notes