drivers/regulator/spacemit-p1.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/spacemit-p1.c
Extension
.c
Size
4099 bytes
Lines
161
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
/*
 * Driver for regulators found in the SpacemiT P1 PMIC
 *
 * Copyright (C) 2025 by RISCstar Solutions Corporation.  All rights reserved.
 * Derived from code from SpacemiT.
 *	Copyright (c) 2023, SPACEMIT Co., Ltd
 */

#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/device.h>
#include <linux/linear_range.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>

#define MOD_NAME	"spacemit-p1-regulator"

enum p1_regulator_id {
	P1_BUCK1,
	P1_BUCK2,
	P1_BUCK3,
	P1_BUCK4,
	P1_BUCK5,
	P1_BUCK6,

	P1_ALDO1,
	P1_ALDO2,
	P1_ALDO3,
	P1_ALDO4,

	P1_DLDO1,
	P1_DLDO2,
	P1_DLDO3,
	P1_DLDO4,
	P1_DLDO5,
	P1_DLDO6,
	P1_DLDO7,
};

static const struct regulator_ops p1_regulator_ops = {
	.list_voltage		= regulator_list_voltage_linear_range,
	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
	.set_voltage_time_sel   = regulator_set_voltage_time_sel,
	.enable			= regulator_enable_regmap,
	.disable		= regulator_disable_regmap,
	.is_enabled		= regulator_is_enabled_regmap,
};

/* Selector value 255 can be used to disable the buck converter on sleep */
static const struct linear_range p1_buck_ranges[] = {
	REGULATOR_LINEAR_RANGE(500000, 0, 170, 5000),
	REGULATOR_LINEAR_RANGE(1375000, 171, 254, 25000),
};

/* Selector value 0 can be used for suspend */
static const struct linear_range p1_ldo_ranges[] = {
	REGULATOR_LINEAR_RANGE(500000, 11, 127, 25000),
};

/* These define the voltage selector field for buck and LDO regulators */
#define BUCK_MASK		GENMASK(7, 0)
#define LDO_MASK		GENMASK(6, 0)

#define P1_ID(_TYPE, _n)	P1_ ## _TYPE ## _n
#define P1_ENABLE_REG(_off, _n)	((_off) + 3 * ((_n) - 1))

#define P1_REG_DESC(_TYPE, _type, _n, _s, _off, _mask, _nv, _ranges)	\
	{								\
		.name			= #_type #_n,			\
		.supply_name		= _s,				\
		.of_match		= of_match_ptr(#_type #_n),	\
		.regulators_node	= of_match_ptr("regulators"),	\
		.id			= P1_ID(_TYPE, _n),		\
		.n_voltages		= _nv,				\
		.ops			= &p1_regulator_ops,		\
		.owner			= THIS_MODULE,			\
		.linear_ranges		= _ranges,			\
		.n_linear_ranges	= ARRAY_SIZE(_ranges),		\
		.vsel_reg		= P1_ENABLE_REG(_off, _n) + 1,	\
		.vsel_mask		= _mask,			\
		.enable_reg		= P1_ENABLE_REG(_off, _n),	\
		.enable_mask		= BIT(0),			\
	}

#define P1_BUCK_DESC(_n) \
	P1_REG_DESC(BUCK, buck, _n, "vin" #_n, 0x47, BUCK_MASK, 255, p1_buck_ranges)

Annotation

Implementation Notes