Commit fe91c24a authored by Hector Martin's avatar Hector Martin Committed by Greg Kroah-Hartman
Browse files

nvmem: Add apple-spmi-nvmem driver



Add a driver for a series of SPMI-attached PMICs present on Apple devices

Reviewed-by: default avatarNeal Gompa <neal@gompa.dev>
Reviewed-by: default avatarAlyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: default avatarHector Martin <marcan@marcan.st>
Co-developed-by: default avatarSasha Finkelstein <fnkl.kernel@gmail.com>
Signed-off-by: default avatarSasha Finkelstein <fnkl.kernel@gmail.com>
Signed-off-by: default avatarSrinivas Kandagatla <srini@kernel.org>
Link: https://lore.kernel.org/r/20250509122452.11827-4-srini@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 48332454
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2298,6 +2298,7 @@ F: drivers/iommu/io-pgtable-dart.c
F:	drivers/irqchip/irq-apple-aic.c
F:	drivers/nvme/host/apple.c
F:	drivers/nvmem/apple-efuses.c
F:	drivers/nvmem/apple-spmi-nvmem.c
F:	drivers/pinctrl/pinctrl-apple-gpio.c
F:	drivers/pwm/pwm-apple.c
F:	drivers/soc/apple/*
+13 −0
Original line number Diff line number Diff line
@@ -40,6 +40,19 @@ config NVMEM_APPLE_EFUSES
	  This driver can also be built as a module. If so, the module will
	  be called nvmem-apple-efuses.

config NVMEM_APPLE_SPMI
	tristate "Apple SPMI NVMEM"
	depends on ARCH_APPLE || COMPILE_TEST
	depends on SPMI
	select REGMAP_SPMI
	help
	  Say y here to build a driver to expose NVMEM cells for a set of power
	  and RTC-related settings on a SPMI-attached PMIC present on Apple
	  devices, such as Apple Silicon Macs.

	  This driver can also be built as a module. If so, the module
	  will be called apple-nvmem-spmi.

config NVMEM_BCM_OCOTP
	tristate "Broadcom On-Chip OTP Controller support"
	depends on ARCH_BCM_IPROC || COMPILE_TEST
+2 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ obj-y += layouts/
# Devices
obj-$(CONFIG_NVMEM_APPLE_EFUSES)	+= nvmem-apple-efuses.o
nvmem-apple-efuses-y 			:= apple-efuses.o
obj-$(CONFIG_NVMEM_APPLE_SPMI)		+= apple_nvmem_spmi.o
apple_nvmem_spmi-y			:= apple-spmi-nvmem.o
obj-$(CONFIG_NVMEM_BCM_OCOTP)		+= nvmem-bcm-ocotp.o
nvmem-bcm-ocotp-y			:= bcm-ocotp.o
obj-$(CONFIG_NVMEM_BRCM_NVRAM)		+= nvmem_brcm_nvram.o
+62 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/*
 * Apple SPMI NVMEM driver
 *
 * Copyright The Asahi Linux Contributors
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/nvmem-provider.h>
#include <linux/of.h>
#include <linux/spmi.h>
#include <linux/regmap.h>

static const struct regmap_config apple_spmi_regmap_config = {
	.reg_bits	= 16,
	.val_bits	= 8,
	.max_register	= 0xffff,
};

static int apple_spmi_nvmem_probe(struct spmi_device *sdev)
{
	struct regmap *regmap;
	struct nvmem_config nvmem_cfg = {
		.dev = &sdev->dev,
		.name = "spmi_nvmem",
		.id = NVMEM_DEVID_AUTO,
		.word_size = 1,
		.stride = 1,
		.size = 0xffff,
		.reg_read = (void *)regmap_bulk_read,
		.reg_write = (void *)regmap_bulk_write,
	};

	regmap = devm_regmap_init_spmi_ext(sdev, &apple_spmi_regmap_config);
	if (IS_ERR(regmap))
		return PTR_ERR(regmap);

	nvmem_cfg.priv = regmap;

	return PTR_ERR_OR_ZERO(devm_nvmem_register(&sdev->dev, &nvmem_cfg));
}

static const struct of_device_id apple_spmi_nvmem_id_table[] = {
	{ .compatible = "apple,spmi-nvmem" },
	{ },
};
MODULE_DEVICE_TABLE(of, apple_spmi_nvmem_id_table);

static struct spmi_driver apple_spmi_nvmem_driver = {
	.probe = apple_spmi_nvmem_probe,
	.driver = {
		.name = "apple-spmi-nvmem",
		.of_match_table	= apple_spmi_nvmem_id_table,
	},
};

module_spmi_driver(apple_spmi_nvmem_driver);

MODULE_LICENSE("Dual MIT/GPL");
MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");
MODULE_DESCRIPTION("Apple SPMI NVMEM driver");