drivers/regulator/rt4803.c
Source file repositories/reference/linux-study-clean/drivers/regulator/rt4803.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/rt4803.c- Extension
.c- Size
- 5496 bytes
- Lines
- 217
- 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/i2c.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
function Copyrightfunction rt4803_get_modefunction rt4803_get_error_flagsfunction rt4803_set_suspend_voltagefunction rt4803_of_map_modefunction rt4803_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2023 Richtek Technology Corp.
*
* Author: ChiYuan Huang <cy_huang@richtek.com>
*/
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/of_regulator.h>
#define RT4803_AUTO_MODE 1
#define RT4803_FPWM_MODE 2
#define RT4803_REG_CONFIG 0x01
#define RT4803_REG_VSELL 0x02
#define RT4803_REG_VSELH 0x03
#define RT4803_REG_ILIM 0x04
#define RT4803_REG_STAT 0x05
#define RT4803_MODE_MASK GENMASK(1, 0)
#define RT4803_VSEL_MASK GENMASK(4, 0)
#define RT4803_ILIM_MASK GENMASK(3, 0)
#define RT4803_TSD_MASK BIT(7)
#define RT4803_HOTDIE_MASK BIT(6)
#define RT4803_FAULT_MASK BIT(1)
#define RT4803_PGOOD_MASK BIT(0)
#define RT4803_VOUT_MINUV 2850000
#define RT4803_VOUT_STEPUV 50000
#define RT4803_VOUT_NUM 32
static int rt4803_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int modeval;
switch (mode) {
case REGULATOR_MODE_NORMAL:
modeval = RT4803_AUTO_MODE;
break;
case REGULATOR_MODE_FAST:
modeval = RT4803_FPWM_MODE;
break;
default:
return -EINVAL;
}
modeval <<= ffs(RT4803_MODE_MASK) - 1;
return regmap_update_bits(regmap, RT4803_REG_CONFIG, RT4803_MODE_MASK, modeval);
}
static unsigned int rt4803_get_mode(struct regulator_dev *rdev)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int modeval;
int ret;
ret = regmap_read(regmap, RT4803_REG_CONFIG, &modeval);
if (ret)
return REGULATOR_MODE_INVALID;
modeval >>= ffs(RT4803_MODE_MASK) - 1;
switch (modeval) {
case RT4803_AUTO_MODE:
return REGULATOR_MODE_NORMAL;
case RT4803_FPWM_MODE:
return REGULATOR_MODE_FAST;
default:
return REGULATOR_MODE_INVALID;
}
}
static int rt4803_get_error_flags(struct regulator_dev *rdev, unsigned int *flags)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int state, events = 0;
int ret;
ret = regmap_read(regmap, RT4803_REG_STAT, &state);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `function Copyright`, `function rt4803_get_mode`, `function rt4803_get_error_flags`, `function rt4803_set_suspend_voltage`, `function rt4803_of_map_mode`, `function rt4803_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.