[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aBEtzh8w5PZKSntr@srini-hackbase>
Date: Tue, 29 Apr 2025 20:51:42 +0100
From: Srinivas Kandagatla <srini@...nel.org>
To: André Draszik <andre.draszik@...aro.org>
Cc: Lee Jones <lee@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <brgl@...ev.pl>, Kees Cook <kees@...nel.org>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Peter Griffin <peter.griffin@...aro.org>,
Tudor Ambarus <tudor.ambarus@...aro.org>,
Will McVicker <willmcvicker@...gle.com>, kernel-team@...roid.com,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
linux-gpio@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH v8 6/6] nvmem: max77759: add Maxim MAX77759 NVMEM driver
On Tue, Apr 29, 2025 at 09:21:42AM +0100, André Draszik wrote:
> The Maxim MAX77759 is a companion PMIC for USB Type-C applications and
> includes Battery Charger, Fuel Gauge, temperature sensors, USB Type-C
> Port Controller (TCPC), NVMEM, and a GPIO expander.
>
> This driver exposes the non volatile memory using the platform device
> registered by the core MFD driver.
>
> Signed-off-by: André Draszik <andre.draszik@...aro.org>
> ---
> v8:
> * replace MODULE_ALIAS() with .id_table (Krzysztof)
> * drop previous tags
>
> v5:
> * follow API updates of max77759 core driver
>
> v2:
> * align sentinel in max77759_nvmem_of_id[] with other max77759 drivers
> (Christophe)
> ---
> MAINTAINERS | 1 +
> drivers/nvmem/Kconfig | 12 +++
> drivers/nvmem/Makefile | 2 +
> drivers/nvmem/max77759-nvmem.c | 162 +++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 177 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0db5e1fe64930e85265913e6a7dd2669c645cf42..b821502afc48f95d48fb8c6ac6941d1dd8e63582 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -14670,6 +14670,7 @@ S: Maintained
> F: Documentation/devicetree/bindings/*/maxim,max77759*.yaml
> F: drivers/gpio/gpio-max77759.c
> F: drivers/mfd/max77759.c
> +F: drivers/nvmem/max77759-nvmem.c
> F: include/linux/mfd/max77759.h
>
> MAXIM MAX77802 PMIC REGULATOR DEVICE DRIVER
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index 8671b7c974b933e147154bb40b5d41b5730518d2..3de07ef524906ad24a89e58abdfe93529a83c80f 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -154,6 +154,18 @@ config NVMEM_LPC18XX_OTP
> To compile this driver as a module, choose M here: the module
> will be called nvmem_lpc18xx_otp.
>
> +config NVMEM_MAX77759
> + tristate "Maxim Integrated MAX77759 NVMEM Support"
> + depends on MFD_MAX77759
> + default MFD_MAX77759
> + help
> + Say Y here to include support for the user-accessible storage found
> + in Maxim Integrated MAX77759 PMICs. This IC provides space for 30
> + bytes of storage.
> +
> + This driver can also be built as a module. If so, the module
> + will be called nvmem-max77759.
> +
> config NVMEM_MESON_EFUSE
> tristate "Amlogic Meson GX eFuse Support"
> depends on (ARCH_MESON || COMPILE_TEST) && MESON_SM
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..a9d03cfbbd27e68d40f8c330e72e20378b12a481 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -34,6 +34,8 @@ obj-$(CONFIG_NVMEM_LPC18XX_EEPROM) += nvmem_lpc18xx_eeprom.o
> nvmem_lpc18xx_eeprom-y := lpc18xx_eeprom.o
> obj-$(CONFIG_NVMEM_LPC18XX_OTP) += nvmem_lpc18xx_otp.o
> nvmem_lpc18xx_otp-y := lpc18xx_otp.o
> +obj-$(CONFIG_NVMEM_MAX77759) += nvmem-max77759.o
> +nvmem-max77759-y := max77759-nvmem.o
> obj-$(CONFIG_NVMEM_MESON_EFUSE) += nvmem_meson_efuse.o
> nvmem_meson_efuse-y := meson-efuse.o
> obj-$(CONFIG_NVMEM_MESON_MX_EFUSE) += nvmem_meson_mx_efuse.o
> diff --git a/drivers/nvmem/max77759-nvmem.c b/drivers/nvmem/max77759-nvmem.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..df7d1998fa2f116450d2fd50eba70d9b61a24574
> --- /dev/null
> +++ b/drivers/nvmem/max77759-nvmem.c
> @@ -0,0 +1,162 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +//
> +// Copyright 2020 Google Inc
> +// Copyright 2025 Linaro Ltd.
> +//
> +// NVMEM driver for Maxim MAX77759
> +
> +#include <linux/dev_printk.h>
> +#include <linux/device.h>
> +#include <linux/device/driver.h>
> +#include <linux/err.h>
> +#include <linux/mfd/max77759.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/overflow.h>
> +#include <linux/platform_device.h>
> +#include <linux/string.h>
> +
> +#define MAX77759_NVMEM_OPCODE_HEADER_LEN 3
> +/*
> + * NVMEM commands have a three byte header (which becomes part of the command),
> + * so we need to subtract that.
> + */
> +#define MAX77759_NVMEM_SIZE (MAX77759_MAXQ_OPCODE_MAXLENGTH \
> + - MAX77759_NVMEM_OPCODE_HEADER_LEN)
> +
> +struct max77759_nvmem {
> + struct device *dev;
> + struct max77759 *max77759;
> +};
> +
> +static bool max77759_nvmem_is_valid(unsigned int offset, size_t bytes)
> +{
> + return (offset + bytes - 1 <= MAX77759_NVMEM_SIZE);
> +}
Do you really need this check?
nvmem core should take care of this boundary checks.
> +
> +static int max77759_nvmem_reg_read(void *priv, unsigned int offset,
> + void *val, size_t bytes)
> +{
> + struct max77759_nvmem *nvmem = priv;
> + DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length,
> + MAX77759_NVMEM_OPCODE_HEADER_LEN);
> + DEFINE_FLEX(struct max77759_maxq_response, rsp, rsp, length,
> + MAX77759_MAXQ_OPCODE_MAXLENGTH);
> + int ret;
> +
> + if (!max77759_nvmem_is_valid(offset, bytes)) {
> + dev_err(nvmem->dev, "outside NVMEM area: %u / %zu\n",
> + offset, bytes);
> + return -EINVAL;
> + }
> +
Powered by blists - more mailing lists