[PATCH v2 5/9] reset: google: Add CPM reset driver

Philipp Zabel p.zabel at pengutronix.de
Wed Nov 25 00:48:04 PST 2026


On Di, 2026-11-24 at 16:03 -0800, Brian Norris wrote:
> Google Tensor SoCs (used on Pixel phones) manage many resources
> (including resets) using a Central Power Manager (CPM) co-processor. We
> communicate with CPM using mailboxes, abstracted in the
> devm_cpm_get_handle(), etc., API.
> 
> For posterity, I list a summary of changes made relative to the
> downstream Pixel driver:
> 
> * Switch to auxiliary bus, as a child of a CPM device
> 
> * Use devm more heavily
> 
> * Avoid representing each reset as its own Device Tree node.
> 
> Signed-off-by: Brian Norris <briannorris at chromium.org>
> ---
> 
> Changes in v2:
>  * Rename symbols from goog_cpm_rst_* to cpm_reset_*
>  * Moved shared protocol details to CPM driver
>  * Remove custom reset debugfs interface and .remove callback.
>  * Remove per-SoC table; we only need naive translation of firmware IDs
> 
>  drivers/reset/Kconfig            |   1 +
>  drivers/reset/Makefile           |   1 +
>  drivers/reset/google/Kconfig     |  11 +++
>  drivers/reset/google/Makefile    |   2 +
>  drivers/reset/google/reset-cpm.c | 154 +++++++++++++++++++++++++++++++
>  5 files changed, 169 insertions(+)
>  create mode 100644 drivers/reset/google/Kconfig
>  create mode 100644 drivers/reset/google/Makefile
>  create mode 100644 drivers/reset/google/reset-cpm.c
> 
> diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
> index 673bca1e594e..64c12b479b2c 100644
> --- a/drivers/reset/Kconfig
> +++ b/drivers/reset/Kconfig
> @@ -475,6 +475,7 @@ config RESET_ZYNQMP
>  	  This enables the reset controller driver for Xilinx ZynqMP SoCs.
>  
>  source "drivers/reset/amlogic/Kconfig"
> +source "drivers/reset/google/Kconfig"
>  source "drivers/reset/hisilicon/Kconfig"
>  source "drivers/reset/realtek/Kconfig"
>  source "drivers/reset/spacemit/Kconfig"
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 2fe527a7be8e..a151fe63905e 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>  obj-y += core.o
>  obj-y += amlogic/
> +obj-y += google/
>  obj-y += hisilicon/
>  obj-y += realtek/
>  obj-y += spacemit/
> diff --git a/drivers/reset/google/Kconfig b/drivers/reset/google/Kconfig
> new file mode 100644
> index 000000000000..38431b4f9001
> --- /dev/null
> +++ b/drivers/reset/google/Kconfig
> @@ -0,0 +1,11 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +config RESET_CPM
> +	tristate "Google CPM Reset Controller"
> +	depends on ARCH_GOOGLE || COMPILE_TEST
> +	depends on GOOGLE_CPM_MBA
> +	help
> +	  Driver support for reset controllers found on Google Tensor SoCs,
> +	  operating over the CPM mailbox interface. This allows peripheral
> +	  drivers to assert and deassert resets on LPCM hardware blocks.
> +
> +	  If unsure, say N.
> diff --git a/drivers/reset/google/Makefile b/drivers/reset/google/Makefile
> new file mode 100644
> index 000000000000..437c19459464
> --- /dev/null
> +++ b/drivers/reset/google/Makefile
> @@ -0,0 +1,2 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +obj-$(CONFIG_RESET_CPM) += reset-cpm.o
> diff --git a/drivers/reset/google/reset-cpm.c b/drivers/reset/google/reset-cpm.c
> new file mode 100644
> index 000000000000..ef0863f25cac
> --- /dev/null
> +++ b/drivers/reset/google/reset-cpm.c
> @@ -0,0 +1,154 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Device driver to control Google SoC LPCM resets via CPM.
> + * Copyright 2023-2026 Google LLC
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/container_of.h>
> +#include <linux/dev_printk.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/errno.h>
> +#include <linux/gfp_types.h>
> +#include <linux/limits.h>
> +#include <linux/mod_devicetable.h>

Please include the specific <linux/device-id/*.h> that is needed
instead of all of <linux/mod_devicetable.h>.

> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/reset-controller.h>
> +#include <linux/types.h>
> +#include <soc/google/google-cpm-mba.h>
> +
> +#define ASSERT_OP_ID			0
> +#define DEASSERT_OP_ID			1
> +
> +#define CPM_RST_LPCM_ID_MASK		GENMASK(31, 16)
> +#define CPM_RST_ID_MASK			GENMASK(15, 0)

Why are these fields 16 bits wide when one line below it says:

> +/* Object fields are 8 bits */
> +#define CPM_RST_ID_MAX			U8_MAX
> +
> +static inline unsigned long to_rstc_idx(u32 lpcm_id, u32 rst_id)
> +{
> +	return FIELD_PREP(CPM_RST_LPCM_ID_MASK, lpcm_id) |
> +	       FIELD_PREP(CPM_RST_ID_MASK, rst_id);
> +}
> +
> +static inline u32 lpcm_from_idx(unsigned long idx)
> +{
> +	return FIELD_GET(CPM_RST_LPCM_ID_MASK, idx);
> +}
> +
> +static inline u32 rst_from_idx(unsigned long idx)
> +{
> +	return FIELD_GET(CPM_RST_ID_MASK, idx);
> +}
> +
> +struct cpm_reset_provider {
> +	struct reset_controller_dev rcdev;
> +	struct cpm_handle *cpm;
> +};
> +
> +static inline struct cpm_reset_provider *to_provider(struct reset_controller_dev *rcdev)
> +{
> +	return container_of(rcdev, struct cpm_reset_provider, rcdev);
> +}
> +
> +static int cpm_reset_send_lpcm(struct reset_controller_dev *rcdev,
> +			       unsigned long idx, u8 opcode)
> +{
> +	struct cpm_reset_provider *provider = to_provider(rcdev);
> +	const struct cpm_lpcm_message msg = {
> +		.cmd = LPCM_CMD_SET_RST,
> +		.opcode = opcode,
> +		.lpcm_id = lpcm_from_idx(idx),
> +		.obj_id = rst_from_idx(idx),
> +	};
> +
> +	return cpm_send_lpcm_message(provider->cpm, &msg);
> +}
> +
> +static int cpm_reset_assert(struct reset_controller_dev *rcdev,
> +			    unsigned long idx)
> +{
> +	return cpm_reset_send_lpcm(rcdev, idx, ASSERT_OP_ID);
> +}
> +
> +static int cpm_reset_deassert(struct reset_controller_dev *rcdev,
> +			      unsigned long idx)
> +{
> +	return cpm_reset_send_lpcm(rcdev, idx, DEASSERT_OP_ID);
> +}
> +
> +static const struct reset_control_ops cpm_reset_ops = {
> +	.assert = cpm_reset_assert,
> +	.deassert = cpm_reset_deassert,
> +};
> +
> +static int cpm_reset_of_xlate(struct reset_controller_dev *rcdev,
> +			      const struct of_phandle_args *reset_spec)
> +{
> +	u32 lpcm_id, rst_id;
> +
> +	if (reset_spec->args_count != 2)
> +		return -EINVAL;
> +
> +	lpcm_id = reset_spec->args[0];
> +	rst_id = reset_spec->args[1];
> +
> +	if (lpcm_id > CPM_RST_ID_MAX)

This looks a bit weird.

Maybe add a CPM_LPCM_ID_MAX, directly use U8_MAX here, or rename the
constant to not include RST_ID?

> +		return -EINVAL;
> +	if (rst_id > CPM_RST_ID_MAX)
> +		return -EINVAL;
> +
> +	return to_rstc_idx(lpcm_id, rst_id);
> +}
> +
> +static int cpm_reset_probe(struct auxiliary_device *auxdev,
> +			   const struct auxiliary_device_id *id)
> +{
> +	struct device *dev = &auxdev->dev;
> +	struct cpm_reset_provider *provider;
> +	int ret;
> +
> +	provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL);

devm_kzalloc_obj()

> +	if (!provider)
> +		return -ENOMEM;
> +
> +	provider->cpm = devm_cpm_get_handle(dev);
> +	if (IS_ERR(provider->cpm))
> +		return dev_err_probe(dev, PTR_ERR(provider->cpm),
> +				     "Failed to get CPM handle\n");
> +
> +	provider->rcdev.dev = dev;
> +	provider->rcdev.owner = THIS_MODULE;
> +	provider->rcdev.of_node = dev->of_node;
> +	provider->rcdev.ops = &cpm_reset_ops;
> +	provider->rcdev.of_reset_n_cells = 2;
> +	provider->rcdev.of_xlate = cpm_reset_of_xlate;
> +
> +	ret = devm_reset_controller_register(dev, &provider->rcdev);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to register reset controller: %d\n", ret);

dev_err_probe()


regards
Philipp



More information about the linux-arm-kernel mailing list