All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Neil Armstrong <narmstrong@baylibre.com>
Cc: linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/6] nvmem: add support for the Khadas MCU Programmable User Memory
Date: Wed, 13 May 2020 11:34:13 +0100	[thread overview]
Message-ID: <09026bde-0ae7-b1a4-835f-bf2481199398@linaro.org> (raw)
In-Reply-To: <20200512132613.31507-5-narmstrong@baylibre.com>



On 12/05/2020 14:26, Neil Armstrong wrote:
> The new Khadas VIM2, VIM3 and Edge boards embeds an on-board microcontroller
> offering a 56bytes User Programmable NVMEM array.
> 
> This array needs a password to be writable, thus a password sysfs file
> has been added on the device node to unlock the NVMEM.

Is this one time programmable? Or does it need to be unlocked for every 
read/write?

How can you make sure that the memory is unlocked before making attempt 
to read/write?

> 
> The default 6bytes password id: "Khadas"
> 
> This implements the user NVMEM devices as cell of the Khadas MCU MFD driver.
> 
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>   drivers/nvmem/Kconfig               |   8 ++
>   drivers/nvmem/Makefile              |   2 +
>   drivers/nvmem/khadas-mcu-user-mem.c | 128 ++++++++++++++++++++++++++++
>   3 files changed, 138 insertions(+)
>   create mode 100644 drivers/nvmem/khadas-mcu-user-mem.c
> 
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d7b7f6d688e7..92cd4f6aa931 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -67,6 +67,14 @@ config JZ4780_EFUSE
>   	  To compile this driver as a module, choose M here: the module
>   	  will be called nvmem_jz4780_efuse.
>   
> +config NVMEM_KHADAS_MCU_USER_MEM
> +	tristate "Khadas MCU User programmable memory support"
> +	depends on MFD_KHADAS_MCU
> +	depends on REGMAP
> +	help
> +	  This is a driver for the MCU User programmable memory
> +	  available on the Khadas VIM and Edge boards.
> +
>   config NVMEM_LPC18XX_EEPROM
>   	tristate "NXP LPC18XX EEPROM Memory Support"
>   	depends on ARCH_LPC18XX || COMPILE_TEST
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index a7c377218341..0516a309542d 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -17,6 +17,8 @@ obj-$(CONFIG_NVMEM_IMX_OCOTP_SCU)	+= nvmem-imx-ocotp-scu.o
>   nvmem-imx-ocotp-scu-y		:= imx-ocotp-scu.o
>   obj-$(CONFIG_JZ4780_EFUSE)		+= nvmem_jz4780_efuse.o
>   nvmem_jz4780_efuse-y		:= jz4780-efuse.o
> +obj-$(CONFIG_NVMEM_KHADAS_MCU_USER_MEM)	+= nvmem-khadas-mcu-user-mem.o
> +nvmem-khadas-mcu-user-mem-y	:= khadas-mcu-user-mem.o
>   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
> diff --git a/drivers/nvmem/khadas-mcu-user-mem.c b/drivers/nvmem/khadas-mcu-user-mem.c
> new file mode 100644
> index 000000000000..a1d5ae9a030c
> --- /dev/null
> +++ b/drivers/nvmem/khadas-mcu-user-mem.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for Khadas MCU User programmable Memory
> + *
> + * Copyright (C) 2020 BayLibre SAS
> + * Author(s): Neil Armstrong <narmstrong@baylibre.com>
> + */
> +
> +#include <linux/clk.h>

Why do we need this header?

> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/mfd/khadas-mcu.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +static int khadas_mcu_user_mem_read(void *context, unsigned int offset,
> +			    void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_read(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static int khadas_mcu_user_mem_write(void *context, unsigned int offset,
> +			     void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_write(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static ssize_t password_store(struct device *dev, struct device_attribute *attr,
> +			     const char *buf, size_t count)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(dev);
> +	int i, ret;
> +
> +	if (count < 6)
> +		return -EINVAL;

Possibly this magic 6 value needs proper define. An additional check 
here for > 6 would be better as well.

> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 1);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0 ; i < 6 ; ++i) {
> +		ret = regmap_write(khadas_mcu->map,
> +				   KHADAS_MCU_CHECK_USER_PASSWD_REG,
> +				   buf[i]);
> +		if (ret)
> +			goto out;
> +	}
> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +	if (ret)
> +		return ret;
> +
> +	return count;
> +out:
> +	regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +
> +	return ret;
> +}
> +
> +static DEVICE_ATTR_WO(password);
> +
> +static struct attribute *khadas_mcu_user_mem_sysfs_attributes[] = {
> +	&dev_attr_password.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group khadas_mcu_user_mem_sysfs_attr_group = {
> +	.attrs = khadas_mcu_user_mem_sysfs_attributes,
> +};
> +
> +static int khadas_mcu_user_mem_probe(struct platform_device *pdev)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(pdev->dev.parent);

You could probably get away with dependency of this structure and the 
header itself by directly getting hold of regmap from parent device.


> +	struct device *dev = &pdev->dev;
> +	struct nvmem_device *nvmem;
> +	struct nvmem_config *econfig;
> +
> +	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
> +	if (!econfig)
> +		return -ENOMEM;
> +
> +	econfig->dev = pdev->dev.parent;
> +	econfig->name = dev_name(pdev->dev.parent);
> +	econfig->stride = 1;
> +	econfig->word_size = 1;
> +	econfig->reg_read = khadas_mcu_user_mem_read;
> +	econfig->reg_write = khadas_mcu_user_mem_write;
> +	econfig->size = 56;
define 56 to make it more readable!

> +	econfig->priv = khadas_mcu;
> +
> +	platform_set_drvdata(pdev, khadas_mcu);
> +
> +	nvmem = devm_nvmem_register(&pdev->dev, econfig);
> +	if (IS_ERR(nvmem))
> +		return PTR_ERR(nvmem);
> +
> +	return sysfs_create_group(&pdev->dev.kobj,
> +				  &khadas_mcu_user_mem_sysfs_attr_group);
> +}
> +
> +static const struct platform_device_id khadas_mcu_user_mem_id_table[] = {
> +	{ .name = "khadas-mcu-user-mem", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(platform, khadas_mcu_user_mem_id_table);
> +
> +static struct platform_driver khadas_mcu_user_mem_driver = {
> +	.probe = khadas_mcu_user_mem_probe,
> +	.driver = {
> +		.name = "khadas-mcu-user-mem",
> +	},
> +	.id_table = khadas_mcu_user_mem_id_table,
> +};
> +
> +module_platform_driver(khadas_mcu_user_mem_driver);
> +
> +MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
> +MODULE_DESCRIPTION("Khadas MCU User MEM driver");
> +MODULE_LICENSE("GPL v2");
> 

WARNING: multiple messages have this Message-ID (diff)
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Neil Armstrong <narmstrong@baylibre.com>
Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 4/6] nvmem: add support for the Khadas MCU Programmable User Memory
Date: Wed, 13 May 2020 11:34:13 +0100	[thread overview]
Message-ID: <09026bde-0ae7-b1a4-835f-bf2481199398@linaro.org> (raw)
In-Reply-To: <20200512132613.31507-5-narmstrong@baylibre.com>



On 12/05/2020 14:26, Neil Armstrong wrote:
> The new Khadas VIM2, VIM3 and Edge boards embeds an on-board microcontroller
> offering a 56bytes User Programmable NVMEM array.
> 
> This array needs a password to be writable, thus a password sysfs file
> has been added on the device node to unlock the NVMEM.

Is this one time programmable? Or does it need to be unlocked for every 
read/write?

How can you make sure that the memory is unlocked before making attempt 
to read/write?

> 
> The default 6bytes password id: "Khadas"
> 
> This implements the user NVMEM devices as cell of the Khadas MCU MFD driver.
> 
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>   drivers/nvmem/Kconfig               |   8 ++
>   drivers/nvmem/Makefile              |   2 +
>   drivers/nvmem/khadas-mcu-user-mem.c | 128 ++++++++++++++++++++++++++++
>   3 files changed, 138 insertions(+)
>   create mode 100644 drivers/nvmem/khadas-mcu-user-mem.c
> 
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d7b7f6d688e7..92cd4f6aa931 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -67,6 +67,14 @@ config JZ4780_EFUSE
>   	  To compile this driver as a module, choose M here: the module
>   	  will be called nvmem_jz4780_efuse.
>   
> +config NVMEM_KHADAS_MCU_USER_MEM
> +	tristate "Khadas MCU User programmable memory support"
> +	depends on MFD_KHADAS_MCU
> +	depends on REGMAP
> +	help
> +	  This is a driver for the MCU User programmable memory
> +	  available on the Khadas VIM and Edge boards.
> +
>   config NVMEM_LPC18XX_EEPROM
>   	tristate "NXP LPC18XX EEPROM Memory Support"
>   	depends on ARCH_LPC18XX || COMPILE_TEST
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index a7c377218341..0516a309542d 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -17,6 +17,8 @@ obj-$(CONFIG_NVMEM_IMX_OCOTP_SCU)	+= nvmem-imx-ocotp-scu.o
>   nvmem-imx-ocotp-scu-y		:= imx-ocotp-scu.o
>   obj-$(CONFIG_JZ4780_EFUSE)		+= nvmem_jz4780_efuse.o
>   nvmem_jz4780_efuse-y		:= jz4780-efuse.o
> +obj-$(CONFIG_NVMEM_KHADAS_MCU_USER_MEM)	+= nvmem-khadas-mcu-user-mem.o
> +nvmem-khadas-mcu-user-mem-y	:= khadas-mcu-user-mem.o
>   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
> diff --git a/drivers/nvmem/khadas-mcu-user-mem.c b/drivers/nvmem/khadas-mcu-user-mem.c
> new file mode 100644
> index 000000000000..a1d5ae9a030c
> --- /dev/null
> +++ b/drivers/nvmem/khadas-mcu-user-mem.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for Khadas MCU User programmable Memory
> + *
> + * Copyright (C) 2020 BayLibre SAS
> + * Author(s): Neil Armstrong <narmstrong@baylibre.com>
> + */
> +
> +#include <linux/clk.h>

Why do we need this header?

> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/mfd/khadas-mcu.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +static int khadas_mcu_user_mem_read(void *context, unsigned int offset,
> +			    void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_read(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static int khadas_mcu_user_mem_write(void *context, unsigned int offset,
> +			     void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_write(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static ssize_t password_store(struct device *dev, struct device_attribute *attr,
> +			     const char *buf, size_t count)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(dev);
> +	int i, ret;
> +
> +	if (count < 6)
> +		return -EINVAL;

Possibly this magic 6 value needs proper define. An additional check 
here for > 6 would be better as well.

> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 1);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0 ; i < 6 ; ++i) {
> +		ret = regmap_write(khadas_mcu->map,
> +				   KHADAS_MCU_CHECK_USER_PASSWD_REG,
> +				   buf[i]);
> +		if (ret)
> +			goto out;
> +	}
> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +	if (ret)
> +		return ret;
> +
> +	return count;
> +out:
> +	regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +
> +	return ret;
> +}
> +
> +static DEVICE_ATTR_WO(password);
> +
> +static struct attribute *khadas_mcu_user_mem_sysfs_attributes[] = {
> +	&dev_attr_password.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group khadas_mcu_user_mem_sysfs_attr_group = {
> +	.attrs = khadas_mcu_user_mem_sysfs_attributes,
> +};
> +
> +static int khadas_mcu_user_mem_probe(struct platform_device *pdev)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(pdev->dev.parent);

You could probably get away with dependency of this structure and the 
header itself by directly getting hold of regmap from parent device.


> +	struct device *dev = &pdev->dev;
> +	struct nvmem_device *nvmem;
> +	struct nvmem_config *econfig;
> +
> +	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
> +	if (!econfig)
> +		return -ENOMEM;
> +
> +	econfig->dev = pdev->dev.parent;
> +	econfig->name = dev_name(pdev->dev.parent);
> +	econfig->stride = 1;
> +	econfig->word_size = 1;
> +	econfig->reg_read = khadas_mcu_user_mem_read;
> +	econfig->reg_write = khadas_mcu_user_mem_write;
> +	econfig->size = 56;
define 56 to make it more readable!

> +	econfig->priv = khadas_mcu;
> +
> +	platform_set_drvdata(pdev, khadas_mcu);
> +
> +	nvmem = devm_nvmem_register(&pdev->dev, econfig);
> +	if (IS_ERR(nvmem))
> +		return PTR_ERR(nvmem);
> +
> +	return sysfs_create_group(&pdev->dev.kobj,
> +				  &khadas_mcu_user_mem_sysfs_attr_group);
> +}
> +
> +static const struct platform_device_id khadas_mcu_user_mem_id_table[] = {
> +	{ .name = "khadas-mcu-user-mem", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(platform, khadas_mcu_user_mem_id_table);
> +
> +static struct platform_driver khadas_mcu_user_mem_driver = {
> +	.probe = khadas_mcu_user_mem_probe,
> +	.driver = {
> +		.name = "khadas-mcu-user-mem",
> +	},
> +	.id_table = khadas_mcu_user_mem_id_table,
> +};
> +
> +module_platform_driver(khadas_mcu_user_mem_driver);
> +
> +MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
> +MODULE_DESCRIPTION("Khadas MCU User MEM driver");
> +MODULE_LICENSE("GPL v2");
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Neil Armstrong <narmstrong@baylibre.com>
Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 4/6] nvmem: add support for the Khadas MCU Programmable User Memory
Date: Wed, 13 May 2020 11:34:13 +0100	[thread overview]
Message-ID: <09026bde-0ae7-b1a4-835f-bf2481199398@linaro.org> (raw)
In-Reply-To: <20200512132613.31507-5-narmstrong@baylibre.com>



On 12/05/2020 14:26, Neil Armstrong wrote:
> The new Khadas VIM2, VIM3 and Edge boards embeds an on-board microcontroller
> offering a 56bytes User Programmable NVMEM array.
> 
> This array needs a password to be writable, thus a password sysfs file
> has been added on the device node to unlock the NVMEM.

Is this one time programmable? Or does it need to be unlocked for every 
read/write?

How can you make sure that the memory is unlocked before making attempt 
to read/write?

> 
> The default 6bytes password id: "Khadas"
> 
> This implements the user NVMEM devices as cell of the Khadas MCU MFD driver.
> 
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>   drivers/nvmem/Kconfig               |   8 ++
>   drivers/nvmem/Makefile              |   2 +
>   drivers/nvmem/khadas-mcu-user-mem.c | 128 ++++++++++++++++++++++++++++
>   3 files changed, 138 insertions(+)
>   create mode 100644 drivers/nvmem/khadas-mcu-user-mem.c
> 
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d7b7f6d688e7..92cd4f6aa931 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -67,6 +67,14 @@ config JZ4780_EFUSE
>   	  To compile this driver as a module, choose M here: the module
>   	  will be called nvmem_jz4780_efuse.
>   
> +config NVMEM_KHADAS_MCU_USER_MEM
> +	tristate "Khadas MCU User programmable memory support"
> +	depends on MFD_KHADAS_MCU
> +	depends on REGMAP
> +	help
> +	  This is a driver for the MCU User programmable memory
> +	  available on the Khadas VIM and Edge boards.
> +
>   config NVMEM_LPC18XX_EEPROM
>   	tristate "NXP LPC18XX EEPROM Memory Support"
>   	depends on ARCH_LPC18XX || COMPILE_TEST
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index a7c377218341..0516a309542d 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -17,6 +17,8 @@ obj-$(CONFIG_NVMEM_IMX_OCOTP_SCU)	+= nvmem-imx-ocotp-scu.o
>   nvmem-imx-ocotp-scu-y		:= imx-ocotp-scu.o
>   obj-$(CONFIG_JZ4780_EFUSE)		+= nvmem_jz4780_efuse.o
>   nvmem_jz4780_efuse-y		:= jz4780-efuse.o
> +obj-$(CONFIG_NVMEM_KHADAS_MCU_USER_MEM)	+= nvmem-khadas-mcu-user-mem.o
> +nvmem-khadas-mcu-user-mem-y	:= khadas-mcu-user-mem.o
>   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
> diff --git a/drivers/nvmem/khadas-mcu-user-mem.c b/drivers/nvmem/khadas-mcu-user-mem.c
> new file mode 100644
> index 000000000000..a1d5ae9a030c
> --- /dev/null
> +++ b/drivers/nvmem/khadas-mcu-user-mem.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for Khadas MCU User programmable Memory
> + *
> + * Copyright (C) 2020 BayLibre SAS
> + * Author(s): Neil Armstrong <narmstrong@baylibre.com>
> + */
> +
> +#include <linux/clk.h>

Why do we need this header?

> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/mfd/khadas-mcu.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +
> +static int khadas_mcu_user_mem_read(void *context, unsigned int offset,
> +			    void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_read(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static int khadas_mcu_user_mem_write(void *context, unsigned int offset,
> +			     void *val, size_t bytes)
> +{
> +	struct khadas_mcu *khadas_mcu = context;
> +
> +	return regmap_bulk_write(khadas_mcu->map,
> +				KHADAS_MCU_USER_DATA_0_REG + offset,
> +				val, bytes);
> +}
> +
> +static ssize_t password_store(struct device *dev, struct device_attribute *attr,
> +			     const char *buf, size_t count)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(dev);
> +	int i, ret;
> +
> +	if (count < 6)
> +		return -EINVAL;

Possibly this magic 6 value needs proper define. An additional check 
here for > 6 would be better as well.

> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 1);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0 ; i < 6 ; ++i) {
> +		ret = regmap_write(khadas_mcu->map,
> +				   KHADAS_MCU_CHECK_USER_PASSWD_REG,
> +				   buf[i]);
> +		if (ret)
> +			goto out;
> +	}
> +
> +	ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +	if (ret)
> +		return ret;
> +
> +	return count;
> +out:
> +	regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0);
> +
> +	return ret;
> +}
> +
> +static DEVICE_ATTR_WO(password);
> +
> +static struct attribute *khadas_mcu_user_mem_sysfs_attributes[] = {
> +	&dev_attr_password.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group khadas_mcu_user_mem_sysfs_attr_group = {
> +	.attrs = khadas_mcu_user_mem_sysfs_attributes,
> +};
> +
> +static int khadas_mcu_user_mem_probe(struct platform_device *pdev)
> +{
> +	struct khadas_mcu *khadas_mcu = dev_get_drvdata(pdev->dev.parent);

You could probably get away with dependency of this structure and the 
header itself by directly getting hold of regmap from parent device.


> +	struct device *dev = &pdev->dev;
> +	struct nvmem_device *nvmem;
> +	struct nvmem_config *econfig;
> +
> +	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
> +	if (!econfig)
> +		return -ENOMEM;
> +
> +	econfig->dev = pdev->dev.parent;
> +	econfig->name = dev_name(pdev->dev.parent);
> +	econfig->stride = 1;
> +	econfig->word_size = 1;
> +	econfig->reg_read = khadas_mcu_user_mem_read;
> +	econfig->reg_write = khadas_mcu_user_mem_write;
> +	econfig->size = 56;
define 56 to make it more readable!

> +	econfig->priv = khadas_mcu;
> +
> +	platform_set_drvdata(pdev, khadas_mcu);
> +
> +	nvmem = devm_nvmem_register(&pdev->dev, econfig);
> +	if (IS_ERR(nvmem))
> +		return PTR_ERR(nvmem);
> +
> +	return sysfs_create_group(&pdev->dev.kobj,
> +				  &khadas_mcu_user_mem_sysfs_attr_group);
> +}
> +
> +static const struct platform_device_id khadas_mcu_user_mem_id_table[] = {
> +	{ .name = "khadas-mcu-user-mem", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(platform, khadas_mcu_user_mem_id_table);
> +
> +static struct platform_driver khadas_mcu_user_mem_driver = {
> +	.probe = khadas_mcu_user_mem_probe,
> +	.driver = {
> +		.name = "khadas-mcu-user-mem",
> +	},
> +	.id_table = khadas_mcu_user_mem_id_table,
> +};
> +
> +module_platform_driver(khadas_mcu_user_mem_driver);
> +
> +MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
> +MODULE_DESCRIPTION("Khadas MCU User MEM driver");
> +MODULE_LICENSE("GPL v2");
> 

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2020-05-13 10:34 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 13:26 [PATCH v2 0/6] mfd: Add support for Khadas Microcontroller Neil Armstrong
2020-05-12 13:26 ` Neil Armstrong
2020-05-12 13:26 ` Neil Armstrong
2020-05-12 13:26 ` [PATCH v2 1/6] dt-bindings: mfd: add Khadas Microcontroller bindings Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-15  6:42   ` Amit Kucheria
2020-05-15  6:42     ` Amit Kucheria
2020-05-15  6:42     ` Amit Kucheria
2020-05-12 13:26 ` [PATCH v2 2/6] mfd: add support for the Khadas System control Microcontroller Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-20  9:01   ` Lee Jones
2020-05-20  9:01     ` Lee Jones
2020-05-20  9:01     ` Lee Jones
2020-06-02  8:26     ` Neil Armstrong
2020-06-02  8:26       ` Neil Armstrong
2020-06-02  8:26       ` Neil Armstrong
2020-06-02  8:33       ` Lee Jones
2020-06-02  8:33         ` Lee Jones
2020-06-02  8:33         ` Lee Jones
2020-05-12 13:26 ` [PATCH v2 3/6] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-15  6:41   ` Amit Kucheria
2020-05-15  6:41     ` Amit Kucheria
2020-05-15  6:41     ` Amit Kucheria
2020-05-15  8:05     ` Neil Armstrong
2020-05-15  8:05       ` Neil Armstrong
2020-05-15  8:05       ` Neil Armstrong
2020-06-02  8:26     ` Neil Armstrong
2020-06-02  8:26       ` Neil Armstrong
2020-06-02  8:26       ` Neil Armstrong
2020-05-12 13:26 ` [PATCH v2 4/6] nvmem: add support for the Khadas MCU Programmable User Memory Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-13 10:34   ` Srinivas Kandagatla [this message]
2020-05-13 10:34     ` Srinivas Kandagatla
2020-05-13 10:34     ` Srinivas Kandagatla
2020-05-13 12:33     ` Neil Armstrong
2020-05-13 12:33       ` Neil Armstrong
2020-05-13 12:33       ` Neil Armstrong
2020-05-15 10:55       ` Srinivas Kandagatla
2020-05-15 10:55         ` Srinivas Kandagatla
2020-05-15 10:55         ` Srinivas Kandagatla
2020-06-02  8:29         ` Neil Armstrong
2020-06-02  8:29           ` Neil Armstrong
2020-06-02  8:29           ` Neil Armstrong
2020-05-12 13:26 ` [PATCH v2 5/6] MAINTAINERS: add myself as maintainer for Khadas MCU drivers Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26 ` [PATCH v2 6/6] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong
2020-05-12 13:26   ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09026bde-0ae7-b1a4-835f-bf2481199398@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=narmstrong@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.