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.
- 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/bits.hlinux/gpio/consumer.hlinux/i2c.hlinux/kernel.hlinux/mod_devicetable.hlinux/property.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
function Copyrightfunction rt5739_get_modefunction rt5739_set_suspend_voltagefunction rt5739_set_suspend_enablefunction rt5739_set_suspend_disablefunction rt5739_set_suspend_modefunction rt5739_of_map_modefunction rt5739_init_regulator_descfunction rt5739_volatile_regfunction rt5739_probe
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
- Immediate include surface: `linux/bits.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/property.h`, `linux/regmap.h`, `linux/regulator/driver.h`.
- Detected declarations: `function Copyright`, `function rt5739_get_mode`, `function rt5739_set_suspend_voltage`, `function rt5739_set_suspend_enable`, `function rt5739_set_suspend_disable`, `function rt5739_set_suspend_mode`, `function rt5739_of_map_mode`, `function rt5739_init_regulator_desc`, `function rt5739_volatile_reg`, `function rt5739_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.