drivers/regulator/rt5739.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/rt5739.c
Extension
.c
Size
8471 bytes
Lines
323
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

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Device driver for RT5739 regulator
 *
 * Copyright (C) 2023 Richtek Technology Corp.
 *
 * Author: ChiYuan Huang <cy_huang@richtek.com>
 */

#include <linux/bits.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/of_regulator.h>

#define RT5739_AUTO_MODE	0
#define RT5739_FPWM_MODE	1

#define RT5739_REG_NSEL0	0x00
#define RT5739_REG_NSEL1	0x01
#define RT5739_REG_CNTL1	0x02
#define RT5739_REG_ID1		0x03
#define RT5739_REG_ID2		0x04
#define RT5739_REG_MON		0x05
#define RT5739_REG_CNTL2	0x06
#define RT5739_REG_CNTL4	0x08

#define RT5739_VSEL_MASK	GENMASK(7, 0)
#define RT5739_MODEVSEL1_MASK	BIT(1)
#define RT5739_MODEVSEL0_MASK	BIT(0)
#define RT5739_VID_MASK		GENMASK(7, 5)
#define RT5739_DID_MASK		GENMASK(3, 0)
#define RT5739_ACTD_MASK	BIT(7)
#define RT5739_ENVSEL1_MASK	BIT(1)
#define RT5739_ENVSEL0_MASK	BIT(0)

#define RT5733_CHIPDIE_ID	0x1
#define RT5733_VOLT_MINUV	270000
#define RT5733_VOLT_MAXUV	1401250
#define RT5733_VOLT_STPUV	6250
#define RT5733_N_VOLTS		182

#define RT5739_VOLT_MINUV	300000
#define RT5739_VOLT_MAXUV	1300000
#define RT5739_VOLT_STPUV	5000
#define RT5739_N_VOLTS		201
#define RT5739_I2CRDY_TIMEUS	1000

static int rt5739_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
	const struct regulator_desc *desc = rdev->desc;
	struct regmap *regmap = rdev_get_regmap(rdev);
	unsigned int mask, val;

	if (desc->vsel_reg == RT5739_REG_NSEL0)
		mask = RT5739_MODEVSEL0_MASK;
	else
		mask = RT5739_MODEVSEL1_MASK;

	switch (mode) {
	case REGULATOR_MODE_FAST:
		val = mask;
		break;
	case REGULATOR_MODE_NORMAL:
		val = 0;
		break;
	default:
		return -EINVAL;
	}

	return regmap_update_bits(regmap, RT5739_REG_CNTL1, mask, val);
}

static unsigned int rt5739_get_mode(struct regulator_dev *rdev)
{
	const struct regulator_desc *desc = rdev->desc;
	struct regmap *regmap = rdev_get_regmap(rdev);
	unsigned int mask, val;
	int ret;

	if (desc->vsel_reg == RT5739_REG_NSEL0)
		mask = RT5739_MODEVSEL0_MASK;
	else
		mask = RT5739_MODEVSEL1_MASK;

	ret = regmap_read(regmap, RT5739_REG_CNTL1, &val);

Annotation

Implementation Notes