mbox series

[00/14] Add support for NVMEM API

Message ID 20220207234212.685316-1-sean.anderson@seco.com
Headers show
Series Add support for NVMEM API | expand

Message

Sean Anderson Feb. 7, 2022, 11:41 p.m. UTC
This adds support for the nvmem-cells properties cropping up in manyb
device trees. This is an easy way to load configuration, version
information, or calibration data from a non-volatile memory source. For
more information, refer to patch 6 ("misc: Add support for nvmem
cells").

Should this be implemented on top of/as part of syscon/regmap? In Linux,
all nvmem devices must also implement regmap support, making nvmem a
subset of regmap drivers. There are certainly similarities, but I don't
know if we want to make this depend on regmap.

For the moment I have only added some integration tests using the
ethernet addresses. This hits the main code paths (looking up nvmem
cells) but doesn't test writing. I can add a few stand-alone tests if
desired.

The patches are structured in the following manner:
1-5:   These are general cleanups, and may be applied independently of
       the rest of the series.
6-10:  Add NVMEM support
11-14: Support reading ethernet addresses using the NVMEM API and add
       some tests.


Sean Anderson (14):
  sandbox: net: Remove fake-host-hwaddr
  sandbox: Remove eth2addr from environment
  test: eth: Add test for ethernet addresses
  sandbox: Move some mac addresses to device tree
  misc: i2c_eeprom: Make i2c_eeprom_write use a const buf
  misc: Add support for nvmem cells
  sandbox: Enable NVMEM
  rtc: Implement nvmem interface
  misc: i2c_eeprom: Implement nvmem interface
  misc: Implement nvmem interface
  net: Add support for reading mac addresses from nvmem cells
  test: Load mac address with i2c eeprom
  test: Load mac address using RTC
  test: Load mac address using misc device

 MAINTAINERS                        |   7 ++
 arch/sandbox/dts/sandbox.dts       |   1 -
 arch/sandbox/dts/sandbox64.dts     |   1 -
 arch/sandbox/dts/test.dts          |  29 ++++-
 board/sandbox/sandbox.env          |   4 -
 configs/sandbox64_defconfig        |   1 +
 configs/sandbox_defconfig          |   1 +
 configs/sandbox_flattree_defconfig |   1 +
 configs/sandbox_noinst_defconfig   |   1 +
 configs/sandbox_spl_defconfig      |   1 +
 doc/api/index.rst                  |   1 +
 doc/api/nvmem.rst                  |   7 ++
 drivers/misc/Kconfig               |  16 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/i2c_eeprom.c          |  22 +++-
 drivers/misc/i2c_eeprom_emul.c     |   4 +
 drivers/misc/misc-uclass.c         |  31 +++++
 drivers/misc/misc_sandbox.c        |   3 +
 drivers/misc/nvmem.c               | 109 +++++++++++++++++
 drivers/net/sandbox.c              |  10 +-
 drivers/rtc/i2c_rtc_emul.c         |  10 ++
 drivers/rtc/rtc-uclass.c           |  19 +++
 include/i2c_eeprom.h               |   3 +-
 include/nvmem.h                    | 185 +++++++++++++++++++++++++++++
 net/eth-uclass.c                   |  13 +-
 test/dm/eth.c                      |  28 +++++
 26 files changed, 484 insertions(+), 25 deletions(-)
 create mode 100644 doc/api/nvmem.rst
 create mode 100644 drivers/misc/nvmem.c
 create mode 100644 include/nvmem.h

Comments

Michael Walle Feb. 8, 2022, 3 p.m. UTC | #1
Hi Sean,

> Should this be implemented on top of/as part of syscon/regmap? In Linux,
> all nvmem devices must also implement regmap support, making nvmem a
> subset of regmap drivers. There are certainly similarities, but I don't
> know if we want to make this depend on regmap.

What do you mean by that? I assume with "nvmem devices" you mean the
nvmem providers. I've implemented the nvmem provider for MTD OTP devices
in linux and there is no regmap support.

-michael
Sean Anderson Feb. 8, 2022, 4:02 p.m. UTC | #2
Hi Michael,

On 2/8/22 10:00 AM, Michael Walle wrote:
> Hi Sean,
> 
>> Should this be implemented on top of/as part of syscon/regmap? In Linux,
>> all nvmem devices must also implement regmap support, making nvmem a
>> subset of regmap drivers. There are certainly similarities, but I don't
>> know if we want to make this depend on regmap.
> 
> What do you mean by that? I assume with "nvmem devices" you mean the
> nvmem providers. I've implemented the nvmem provider for MTD OTP devices
> in linux and there is no regmap support.

According to [1],

> [The NVMEM] framework is based on regmap, so that most of the
> abstraction available in regmap can be reused, across multiple types
> of buses.

and

> It is mandatory that the NVMEM provider has a regmap associated with
> its struct device. Failure to do would return error code from
> nvmem_register().

which seems to imply that NVMEM devices should also be regmaps.

--Sean

[1] https://www.kernel.org/doc/html/latest/driver-api/nvmem.html
Michael Walle Feb. 8, 2022, 4:05 p.m. UTC | #3
Hi Sean,

Am 2022-02-08 17:02, schrieb Sean Anderson:
>>> Should this be implemented on top of/as part of syscon/regmap? In 
>>> Linux,
>>> all nvmem devices must also implement regmap support, making nvmem a
>>> subset of regmap drivers. There are certainly similarities, but I 
>>> don't
>>> know if we want to make this depend on regmap.
>> 
>> What do you mean by that? I assume with "nvmem devices" you mean the
>> nvmem providers. I've implemented the nvmem provider for MTD OTP 
>> devices
>> in linux and there is no regmap support.
> 
> According to [1],
> 
>> [The NVMEM] framework is based on regmap, so that most of the
>> abstraction available in regmap can be reused, across multiple types
>> of buses.
> 
> and
> 
>> It is mandatory that the NVMEM provider has a regmap associated with
>> its struct device. Failure to do would return error code from
>> nvmem_register().
> 
> which seems to imply that NVMEM devices should also be regmaps.

Ahh I see. That seems to be outdated, see commit
795ddd18d38f9762fbfefceab9aa16caef0cf431 ("nvmem: core: remove
regmap dependency").

-michael