drivers/regulator/pf0900-regulator.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/pf0900-regulator.c
Extension
.c
Size
29861 bytes
Lines
976
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 pf0900_regulator_desc {
	struct regulator_desc desc;
	unsigned int suspend_enable_mask;
	unsigned int suspend_voltage_reg;
	unsigned int suspend_voltage_cache;
};

struct pf0900_drvdata {
	const struct pf0900_regulator_desc *desc;
	unsigned int rcnt;
};

struct pf0900 {
	struct device *dev;
	struct regmap *regmap;
	const struct pf0900_drvdata *drvdata;
	struct regulator_dev *rdevs[PF0900_REGULATOR_CNT];
	int irq;
	unsigned short addr;
	bool crc_en;
};

enum pf0900_regulator_type {
	PF0900_SW = 0,
	PF0900_LDO,
};

#define PF0900_REGU_IRQ(_reg, _type, _event)	\
	{					\
		.reg = _reg,			\
		.type = _type,			\
		.event = _event,		\
	}

struct pf0900_regulator_irq {
	unsigned int  reg;
	unsigned int  type;
	unsigned int  event;
};

static const struct regmap_range pf0900_range = {
	.range_min = PF0900_REG_DEV_ID,
	.range_max = PF0900_REG_SYS_DIAG,
};

static const struct regmap_access_table pf0900_volatile_regs = {
	.yes_ranges = &pf0900_range,
	.n_yes_ranges = 1,
};

static const struct regmap_config pf0900_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.volatile_table = &pf0900_volatile_regs,
	.max_register = PF0900_MAX_REGISTER - 1,
	.cache_type = REGCACHE_MAPLE,
};

static uint8_t crc8_j1850(unsigned short addr, unsigned int reg,
			  unsigned int val)
{
	uint8_t crcBuf[3];
	uint8_t t_crc;
	uint8_t i, j;

	crcBuf[0] = addr;
	crcBuf[1] = reg;
	crcBuf[2] = val;
	t_crc = 0xFF;

	/*
	 * The CRC calculation is based on the standard CRC-8-SAE as
	 * defined in the SAE-J1850 specification with the following
	 * characteristics.
	 * Polynomial = 0x1D
	 * Initial Value = 0xFF
	 * The CRC byte is calculated by shifting 24-bit data through
	 * the CRC polynomial.The 24-bits package is built as follows:
	 * DEVICE_ADDR[b8] + REGISTER_ADDR [b8] +DATA[b8]
	 * The DEVICE_ADDR is calculated as the 7-bit slave address
	 * shifted left one space plus the corresponding read/write bit.
	 * (7Bit Address [b7] << 1 ) + R/W = DEVICE_ADDR[b8]
	 */
	for (i = 0; i < sizeof(crcBuf); i++) {
		t_crc ^= crcBuf[i];
		for (j = 0; j < 8; j++) {
			if ((t_crc & 0x80) != 0) {
				t_crc <<= 1;
				t_crc ^= 0x1D;
			} else {

Annotation

Implementation Notes