Message ID | 20250415-spmi-nvmem-v1-2-22067be253cf@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Generic SPMI NVMEM cell driver | expand |
On Tue, Apr 15, 2025 at 5:52 PM Sasha Finkelstein via B4 Relay <devnull+fnkl.kernel.gmail.com@kernel.org> wrote: > > From: Hector Martin <marcan@marcan.st> > > This driver exposes a SPMI device as an NVMEM device. > It is intended to be used with e.g. PMUs/PMICs that are used to > hold power management configuration, such as used on Apple Silicon > Macs. > > Signed-off-by: Hector Martin <marcan@marcan.st> > Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> > --- > MAINTAINERS | 1 + > drivers/nvmem/Kconfig | 14 +++++++++++ > drivers/nvmem/Makefile | 2 ++ > drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 79 insertions(+) > This driver code looks reasonable to me. Reviewed-by: Neal Gompa <neal@gompa.dev>
This should have a Co-developed-by tag in addition to the two sign-offs, given you've made significant changes. > This driver exposes a SPMI device as an NVMEM device. > It is intended to be used with e.g. PMUs/PMICs that are used to > hold power management configuration, such as used on Apple Silicon > Macs. > > Signed-off-by: Hector Martin <marcan@marcan.st> > Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> > --- > MAINTAINERS | 1 + > drivers/nvmem/Kconfig | 14 +++++++++++ > drivers/nvmem/Makefile | 2 ++ > drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 79 insertions(+) > > diff --git a/MAINTAINERS b/MAINTAINERS > index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -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/spmi-nvmem.c > F: drivers/pinctrl/pinctrl-apple-gpio.c > F: drivers/pwm/pwm-apple.c > F: drivers/soc/apple/* > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig > index 8671b7c974b933e147154bb40b5d41b5730518d2..9ec907d8aa6ef7df0ea45cc35e92d8239d2705ee 100644 > --- a/drivers/nvmem/Kconfig > +++ b/drivers/nvmem/Kconfig > @@ -310,6 +310,20 @@ config NVMEM_SNVS_LPGPR > This driver can also be built as a module. If so, the module > will be called nvmem-snvs-lpgpr. > > +config NVMEM_SPMI > + tristate "Generic SPMI NVMEM" > + default ARCH_APPLE > + depends on SPMI > + select REGMAP_SPMI > + help > + Say y here to build a generic driver to expose a SPMI device > + as a NVMEM provider. This can be used for PMIC/PMU devices which > + are used to store power and RTC-related settings on certain > + platforms, such as Apple Silicon Macs. > + > + This driver can also be built as a module. If so, the module > + will be called nvmem-spmi. > + > config NVMEM_SPMI_SDAM > tristate "SPMI SDAM Support" > depends on SPMI > diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile > index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..b639f4284184db026bb27b11e04d54b8f7ff166f 100644 > --- a/drivers/nvmem/Makefile > +++ b/drivers/nvmem/Makefile > @@ -64,6 +64,8 @@ obj-$(CONFIG_NVMEM_SC27XX_EFUSE) += nvmem-sc27xx-efuse.o > nvmem-sc27xx-efuse-y := sc27xx-efuse.o > obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o > nvmem_snvs_lpgpr-y := snvs_lpgpr.o > +obj-$(CONFIG_NVMEM_SPMI) += nvmem_spmi.o > +nvmem_spmi-y := spmi-nvmem.o > obj-$(CONFIG_NVMEM_SPMI_SDAM) += nvmem_qcom-spmi-sdam.o > nvmem_qcom-spmi-sdam-y += qcom-spmi-sdam.o > obj-$(CONFIG_NVMEM_SPRD_EFUSE) += nvmem_sprd_efuse.o > diff --git a/drivers/nvmem/spmi-nvmem.c b/drivers/nvmem/spmi-nvmem.c > new file mode 100644 > index 0000000000000000000000000000000000000000..fff6162cb22dd7ab45883f004f5b63ebae014698 > --- /dev/null > +++ b/drivers/nvmem/spmi-nvmem.c > @@ -0,0 +1,62 @@ > +// SPDX-License-Identifier: GPL-2.0-only OR MIT > +/* > + * Generic 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 spmi_regmap_config = { > + .reg_bits = 16, > + .val_bits = 8, > + .max_register = 0xffff, > +}; > + > +static int 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, &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 spmi_nvmem_id_table[] = { > + { .compatible = "spmi-nvmem" }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, spmi_nvmem_id_table); > + > +static struct spmi_driver spmi_nvmem_driver = { > + .probe = spmi_nvmem_probe, > + .driver = { > + .name = "spmi-nvmem", > + .of_match_table = spmi_nvmem_id_table, > + }, > +}; > + > +module_spmi_driver(spmi_nvmem_driver); > + > +MODULE_LICENSE("Dual MIT/GPL"); > +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>"); > +MODULE_DESCRIPTION("SPMI NVMEM driver"); > > -- > 2.49.0 > >
On 15/04/2025 22:52, Sasha Finkelstein via B4 Relay wrote: > From: Hector Martin <marcan@marcan.st> > > This driver exposes a SPMI device as an NVMEM device. > It is intended to be used with e.g. PMUs/PMICs that are used to > hold power management configuration, such as used on Apple Silicon > Macs. > > Signed-off-by: Hector Martin <marcan@marcan.st> > Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> > --- > MAINTAINERS | 1 + > drivers/nvmem/Kconfig | 14 +++++++++++ > drivers/nvmem/Makefile | 2 ++ > drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 79 insertions(+) > > diff --git a/MAINTAINERS b/MAINTAINERS > index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -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/spmi-nvmem.c > F: drivers/pinctrl/pinctrl-apple-gpio.c > F: drivers/pwm/pwm-apple.c > F: drivers/soc/apple/* > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig > index 8671b7c974b933e147154bb40b5d41b5730518d2..9ec907d8aa6ef7df0ea45cc35e92d8239d2705ee 100644 > --- a/drivers/nvmem/Kconfig > +++ b/drivers/nvmem/Kconfig > @@ -310,6 +310,20 @@ config NVMEM_SNVS_LPGPR > This driver can also be built as a module. If so, the module > will be called nvmem-snvs-lpgpr. > > +config NVMEM_SPMI > + tristate "Generic SPMI NVMEM" > + default ARCH_APPLE Why default is set to ARCH_APPLE? This will endup with y in arm64 defconfig, means increasing the size of kernel. should it be: depends on ARCH_APPLE || COMPILE_TEST --srini > + depends on SPMI > + select REGMAP_SPMI > + help > + Say y here to build a generic driver to expose a SPMI device > + as a NVMEM provider. This can be used for PMIC/PMU devices which > + are used to store power and RTC-related settings on certain > + platforms, such as Apple Silicon Macs. > + > + This driver can also be built as a module. If so, the module > + will be called nvmem-spmi. > + > config NVMEM_SPMI_SDAM > tristate "SPMI SDAM Support" > depends on SPMI > diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile > index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..b639f4284184db026bb27b11e04d54b8f7ff166f 100644 > --- a/drivers/nvmem/Makefile > +++ b/drivers/nvmem/Makefile > @@ -64,6 +64,8 @@ obj-$(CONFIG_NVMEM_SC27XX_EFUSE) += nvmem-sc27xx-efuse.o > nvmem-sc27xx-efuse-y := sc27xx-efuse.o > obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o > nvmem_snvs_lpgpr-y := snvs_lpgpr.o > +obj-$(CONFIG_NVMEM_SPMI) += nvmem_spmi.o > +nvmem_spmi-y := spmi-nvmem.o > obj-$(CONFIG_NVMEM_SPMI_SDAM) += nvmem_qcom-spmi-sdam.o > nvmem_qcom-spmi-sdam-y += qcom-spmi-sdam.o > obj-$(CONFIG_NVMEM_SPRD_EFUSE) += nvmem_sprd_efuse.o > diff --git a/drivers/nvmem/spmi-nvmem.c b/drivers/nvmem/spmi-nvmem.c > new file mode 100644 > index 0000000000000000000000000000000000000000..fff6162cb22dd7ab45883f004f5b63ebae014698 > --- /dev/null > +++ b/drivers/nvmem/spmi-nvmem.c > @@ -0,0 +1,62 @@ > +// SPDX-License-Identifier: GPL-2.0-only OR MIT > +/* > + * Generic 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 spmi_regmap_config = { > + .reg_bits = 16, > + .val_bits = 8, > + .max_register = 0xffff, > +}; > + > +static int 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, &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 spmi_nvmem_id_table[] = { > + { .compatible = "spmi-nvmem" }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, spmi_nvmem_id_table); > + > +static struct spmi_driver spmi_nvmem_driver = { > + .probe = spmi_nvmem_probe, > + .driver = { > + .name = "spmi-nvmem", > + .of_match_table = spmi_nvmem_id_table, > + }, > +}; > + > +module_spmi_driver(spmi_nvmem_driver); > + > +MODULE_LICENSE("Dual MIT/GPL"); > +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>"); > +MODULE_DESCRIPTION("SPMI NVMEM driver"); >
> > +config NVMEM_SPMI > > + tristate "Generic SPMI NVMEM" > > + default ARCH_APPLE > Why default is set to ARCH_APPLE? > > This will endup with y in arm64 defconfig, means increasing the size of > kernel. I mean, eventually I think we /do/ want M1 properly supported in the arm64 defconfig, no? I'm not sure what the criteria is for any other driver to be defconfig or not, though.
On Thu, Apr 17, 2025 at 09:49:28AM -0400, Alyssa Rosenzweig wrote: > > > +config NVMEM_SPMI > > > + tristate "Generic SPMI NVMEM" > > > + default ARCH_APPLE > > Why default is set to ARCH_APPLE? > > > > This will endup with y in arm64 defconfig, means increasing the size of > > kernel. > > I mean, eventually I think we /do/ want M1 properly supported in the > arm64 defconfig, no? I'm not sure what the criteria is for any other > driver to be defconfig or not, though. cat arch/arm64/configs/defconfig | grep APPLE CONFIG_ARCH_APPLE=y Criteria for other drivers default should be not selected, and should be module if they are part of defconfig, rather than inbuilt. Not sure how most of the ARCH_APPLE drivers ended up using default ARCH_APPLE. --srini
> > > > +config NVMEM_SPMI > > > > + tristate "Generic SPMI NVMEM" > > > > + default ARCH_APPLE > > > Why default is set to ARCH_APPLE? > > > > > > This will endup with y in arm64 defconfig, means increasing the size of > > > kernel. > > > > I mean, eventually I think we /do/ want M1 properly supported in the > > arm64 defconfig, no? I'm not sure what the criteria is for any other > > driver to be defconfig or not, though. > cat arch/arm64/configs/defconfig | grep APPLE > CONFIG_ARCH_APPLE=y > > Criteria for other drivers default should be not selected, > and should be module if they are part of defconfig, rather than > inbuilt. Not sure how most of the ARCH_APPLE drivers ended up using > default ARCH_APPLE. Oh, I see what you mean, module vs in-built. Understood now, thanks for explaining :)
On Thu, 17 Apr 2025 at 15:34, Srinivas Kandagatla <srini@kernel.org> wrote: > should it be: > > depends on ARCH_APPLE || COMPILE_TEST No, this is not a driver for an apple-specific hw, but a generic thing for re-exporting a set of spmi registers as nvmem cells.
On Thu, Apr 17, 2025 at 02:34:37PM +0100, Srinivas Kandagatla wrote: > > > On 15/04/2025 22:52, Sasha Finkelstein via B4 Relay wrote: > > From: Hector Martin <marcan@marcan.st> > > > > This driver exposes a SPMI device as an NVMEM device. > > It is intended to be used with e.g. PMUs/PMICs that are used to > > hold power management configuration, such as used on Apple Silicon > > Macs. > > > > Signed-off-by: Hector Martin <marcan@marcan.st> > > Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> > > --- > > MAINTAINERS | 1 + > > drivers/nvmem/Kconfig | 14 +++++++++++ > > drivers/nvmem/Makefile | 2 ++ > > drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ > > 4 files changed, 79 insertions(+) > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -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/spmi-nvmem.c > > F: drivers/pinctrl/pinctrl-apple-gpio.c > > F: drivers/pwm/pwm-apple.c > > F: drivers/soc/apple/* > > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig > > index 8671b7c974b933e147154bb40b5d41b5730518d2..9ec907d8aa6ef7df0ea45cc35e92d8239d2705ee 100644 > > --- a/drivers/nvmem/Kconfig > > +++ b/drivers/nvmem/Kconfig > > @@ -310,6 +310,20 @@ config NVMEM_SNVS_LPGPR > > This driver can also be built as a module. If so, the module > > will be called nvmem-snvs-lpgpr. > > > > +config NVMEM_SPMI > > + tristate "Generic SPMI NVMEM" > > + default ARCH_APPLE > Why default is set to ARCH_APPLE? > > This will endup with y in arm64 defconfig, means increasing the size of > kernel. > > should it be: > > depends on ARCH_APPLE || COMPILE_TEST I don't think it should depend on ARCH_APPLE. There is nothing ARCH_APPLE specific in the driver or dt-bindings even apple platforms are currently only user. `default m if ARCH_APPLE` might an alternative but in this specific case the driver which will uses the nvmem cells should just select it. So I would remove the default. Janne
On Thu, Apr 17, 2025 at 04:30:53PM +0200, Janne Grunau wrote: > On Thu, Apr 17, 2025 at 02:34:37PM +0100, Srinivas Kandagatla wrote: > > > > > > On 15/04/2025 22:52, Sasha Finkelstein via B4 Relay wrote: > > > From: Hector Martin <marcan@marcan.st> > > > > > > This driver exposes a SPMI device as an NVMEM device. > > > It is intended to be used with e.g. PMUs/PMICs that are used to > > > hold power management configuration, such as used on Apple Silicon > > > Macs. > > > > > > Signed-off-by: Hector Martin <marcan@marcan.st> > > > Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com> > > > --- > > > MAINTAINERS | 1 + > > > drivers/nvmem/Kconfig | 14 +++++++++++ > > > drivers/nvmem/Makefile | 2 ++ > > > drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ > > > 4 files changed, 79 insertions(+) > > > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > > index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644 > > > --- a/MAINTAINERS > > > +++ b/MAINTAINERS > > > @@ -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/spmi-nvmem.c > > > F: drivers/pinctrl/pinctrl-apple-gpio.c > > > F: drivers/pwm/pwm-apple.c > > > F: drivers/soc/apple/* > > > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig > > > index 8671b7c974b933e147154bb40b5d41b5730518d2..9ec907d8aa6ef7df0ea45cc35e92d8239d2705ee 100644 > > > --- a/drivers/nvmem/Kconfig > > > +++ b/drivers/nvmem/Kconfig > > > @@ -310,6 +310,20 @@ config NVMEM_SNVS_LPGPR > > > This driver can also be built as a module. If so, the module > > > will be called nvmem-snvs-lpgpr. > > > > > > +config NVMEM_SPMI > > > + tristate "Generic SPMI NVMEM" > > > + default ARCH_APPLE > > Why default is set to ARCH_APPLE? > > > > This will endup with y in arm64 defconfig, means increasing the size of > > kernel. > > > > should it be: > > > > depends on ARCH_APPLE || COMPILE_TEST > > I don't think it should depend on ARCH_APPLE. There is nothing > ARCH_APPLE specific in the driver or dt-bindings even apple platforms > are currently only user. irrespective of this is generic or not none of the drivers should have default set to y. > > `default m if ARCH_APPLE` might an alternative but in this specific case > the driver which will uses the nvmem cells should just select it. So I > would remove the default. remove the default, and let it be selected in defconfig as m as required, like any other drivers. --srini > > Janne
diff --git a/MAINTAINERS b/MAINTAINERS index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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/spmi-nvmem.c F: drivers/pinctrl/pinctrl-apple-gpio.c F: drivers/pwm/pwm-apple.c F: drivers/soc/apple/* diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 8671b7c974b933e147154bb40b5d41b5730518d2..9ec907d8aa6ef7df0ea45cc35e92d8239d2705ee 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -310,6 +310,20 @@ config NVMEM_SNVS_LPGPR This driver can also be built as a module. If so, the module will be called nvmem-snvs-lpgpr. +config NVMEM_SPMI + tristate "Generic SPMI NVMEM" + default ARCH_APPLE + depends on SPMI + select REGMAP_SPMI + help + Say y here to build a generic driver to expose a SPMI device + as a NVMEM provider. This can be used for PMIC/PMU devices which + are used to store power and RTC-related settings on certain + platforms, such as Apple Silicon Macs. + + This driver can also be built as a module. If so, the module + will be called nvmem-spmi. + config NVMEM_SPMI_SDAM tristate "SPMI SDAM Support" depends on SPMI diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..b639f4284184db026bb27b11e04d54b8f7ff166f 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -64,6 +64,8 @@ obj-$(CONFIG_NVMEM_SC27XX_EFUSE) += nvmem-sc27xx-efuse.o nvmem-sc27xx-efuse-y := sc27xx-efuse.o obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o nvmem_snvs_lpgpr-y := snvs_lpgpr.o +obj-$(CONFIG_NVMEM_SPMI) += nvmem_spmi.o +nvmem_spmi-y := spmi-nvmem.o obj-$(CONFIG_NVMEM_SPMI_SDAM) += nvmem_qcom-spmi-sdam.o nvmem_qcom-spmi-sdam-y += qcom-spmi-sdam.o obj-$(CONFIG_NVMEM_SPRD_EFUSE) += nvmem_sprd_efuse.o diff --git a/drivers/nvmem/spmi-nvmem.c b/drivers/nvmem/spmi-nvmem.c new file mode 100644 index 0000000000000000000000000000000000000000..fff6162cb22dd7ab45883f004f5b63ebae014698 --- /dev/null +++ b/drivers/nvmem/spmi-nvmem.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Generic 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 spmi_regmap_config = { + .reg_bits = 16, + .val_bits = 8, + .max_register = 0xffff, +}; + +static int 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, &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 spmi_nvmem_id_table[] = { + { .compatible = "spmi-nvmem" }, + { }, +}; +MODULE_DEVICE_TABLE(of, spmi_nvmem_id_table); + +static struct spmi_driver spmi_nvmem_driver = { + .probe = spmi_nvmem_probe, + .driver = { + .name = "spmi-nvmem", + .of_match_table = spmi_nvmem_id_table, + }, +}; + +module_spmi_driver(spmi_nvmem_driver); + +MODULE_LICENSE("Dual MIT/GPL"); +MODULE_AUTHOR("Hector Martin <marcan@marcan.st>"); +MODULE_DESCRIPTION("SPMI NVMEM driver");