1 .\" Copyright (c) 2018 Emmanuel Vadot <manu@freebsd.org>
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
12 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
13 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
16 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 .Nm nvmem_get_cell_len ,
31 .Nm nvmem_read_cell_by_name ,
32 .Nm nvmem_read_cell_by_idx ,
33 .Nm nvmem_write_cell_by_name ,
34 .Nm nvmem_write_cell_by_idx ,
36 .Cd "options EXT_RESOURCES"
39 .In sys/extres/nvmem/nvmem.h
41 .Fn nvmem_get_cell_len "phandle_t node" "const char *name"
43 .Fn nvmem_read_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
45 .Fn nvmem_read_cell_by_idx "phandle_t node" "int idx" "void *cell" "size_t buflen"
47 .Fn nvmem_write_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
49 .Fn nvmem_write_cell_by_idx "phandle_t node" "int idx" "void *cell" "size_t buflen"
51 On some embedded boards, the manufacturer stored some data on a NVMEM
52 (Non-Volatile Memory), this is generally stored in some eeprom or fuses.
56 API consist of helpers functions for consumer and device methods for
59 .Bl -tag -width indent
60 .It Fn nvmem_get_cell_len "phandle_t node" "const char *name"
61 Get the size of the cell base on the reg property on the node.
62 Return the size or ENOENT if the cell name wasn't found
63 .It Fn nvmem_read_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
64 Get the cell content based on the name.
65 Return 0 on sucess or ENOENT if the cell doesn't exists, ENXIO if no provider device was found,
66 EINVAL if the size isn't correct.
67 .It Fn nvmem_read_cell_by_idx "phandle_t node" "int idx" "void *cell" "size_t buflen"
68 Get the cell content based on the id.
69 Return 0 on sucess or ENOENT if the cell doesn't exists, ENXIO if no provider device was found,
70 EINVAL if the size isn't correct.
71 .It Fn nvmem_write_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
72 Write the cell content based on the name.
73 Return 0 on sucess or ENOENT if the cell doesn't exists, ENXIO if no provider device was found,
74 EINVAL if the size isn't correct.
75 .It Fn nvmem_write_cell_by_idx "phandle_t node" "int idx" "void *cell" "size_t buflen"
76 Write the cell content based on the id.
77 Return 0 on sucess or ENOENT if the cell doesn't exists, ENXIO if no provider device was found,
78 EINVAL if the size isn't correct.
81 .Bl -tag -width indent
82 .It Fn nvmem_read "device_t dev" "uint32_t offset" "uint32_t size" "uint8_t *buffer"
83 Provider device method to read a cell content.
84 .It Fn nvmem_write "device_t dev" "uint32_t offset" "uint32_t size" "uint8_t *buffer"
85 Provider device method to write a cell content.
91 eeprom: eeprom@20000 {
100 nvmem-cells = <&board_id>
101 nvmem-cell-names = "boardid";
105 The device driver for eeprom@20000 needs to expose itself as a provider
107 #include "nvmem_if.h"
110 foo_nvmem_read(device_t dev, uint32_t offset, uint32_t size, uint8_t *buffer)
116 foo_attach(device_t dev)
120 node = ofw_bus_get_node(dev);
122 /* Registering the device so the consumers can find us */
123 OF_device_register_xref(OF_xref_from_node(node), dev);
128 static device_method_t foo_methods[] = {
131 /* nvmem interface */
132 DEVMETHOD(nvmem_read, foo_nvmem_read),
134 /* Terminate method list */
139 The consumer device driver for device@30000 can now read the nvmem data
142 bar_attach(device_t dev)
148 node = ofw_bus_get_node(dev);
149 nvmem_read_cell_by_name(node, "boardid", (void *)&boardid, sizeof(boardid));
154 The nvmem related function first appear in
156 The nvmem interface and manual page was written by
157 .An Emmanuel Vadot Aq Mt manu@FreeBSD.org .