xref: /freebsd/sys/dev/nvmem/nvmem_if.m (revision e51b3d8e53cee7d6a36e34e1cd4d588593d71b40)
1*e51b3d8eSEmmanuel Vadot#-
2*e51b3d8eSEmmanuel Vadot# Copyright (c) 2018 Emmanuel Vadot <manu@FreeBSD.org>
3*e51b3d8eSEmmanuel Vadot#
4*e51b3d8eSEmmanuel Vadot# Redistribution and use in source and binary forms, with or without
5*e51b3d8eSEmmanuel Vadot# modification, are permitted provided that the following conditions
6*e51b3d8eSEmmanuel Vadot# are met:
7*e51b3d8eSEmmanuel Vadot# 1. Redistributions of source code must retain the above copyright
8*e51b3d8eSEmmanuel Vadot#    notice, this list of conditions and the following disclaimer.
9*e51b3d8eSEmmanuel Vadot# 2. Redistributions in binary form must reproduce the above copyright
10*e51b3d8eSEmmanuel Vadot#    notice, this list of conditions and the following disclaimer in the
11*e51b3d8eSEmmanuel Vadot#    documentation and/or other materials provided with the distribution.
12*e51b3d8eSEmmanuel Vadot#
13*e51b3d8eSEmmanuel Vadot# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*e51b3d8eSEmmanuel Vadot# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*e51b3d8eSEmmanuel Vadot# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*e51b3d8eSEmmanuel Vadot# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*e51b3d8eSEmmanuel Vadot# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*e51b3d8eSEmmanuel Vadot# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*e51b3d8eSEmmanuel Vadot# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*e51b3d8eSEmmanuel Vadot# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*e51b3d8eSEmmanuel Vadot# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*e51b3d8eSEmmanuel Vadot# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*e51b3d8eSEmmanuel Vadot# SUCH DAMAGE.
24*e51b3d8eSEmmanuel Vadot#
25*e51b3d8eSEmmanuel Vadot#
26*e51b3d8eSEmmanuel Vadot
27*e51b3d8eSEmmanuel VadotINTERFACE nvmem;
28*e51b3d8eSEmmanuel Vadot
29*e51b3d8eSEmmanuel Vadot#
30*e51b3d8eSEmmanuel Vadot# Default implementations of some methods.
31*e51b3d8eSEmmanuel Vadot#
32*e51b3d8eSEmmanuel VadotCODE {
33*e51b3d8eSEmmanuel Vadot	static int
34*e51b3d8eSEmmanuel Vadot	null_nvmem_read(device_t dev __unused, uint32_t offset __unused, uint32_t size __unused, uint8_t *buffer __unused)
35*e51b3d8eSEmmanuel Vadot	{
36*e51b3d8eSEmmanuel Vadot
37*e51b3d8eSEmmanuel Vadot		return (ENXIO);
38*e51b3d8eSEmmanuel Vadot	}
39*e51b3d8eSEmmanuel Vadot
40*e51b3d8eSEmmanuel Vadot	static int
41*e51b3d8eSEmmanuel Vadot	null_nvmem_write(device_t dev __unused, uint32_t offset __unused, uint32_t size __unused, uint8_t *buffer __unused)
42*e51b3d8eSEmmanuel Vadot	{
43*e51b3d8eSEmmanuel Vadot
44*e51b3d8eSEmmanuel Vadot		return (ENXIO);
45*e51b3d8eSEmmanuel Vadot	}
46*e51b3d8eSEmmanuel Vadot};
47*e51b3d8eSEmmanuel Vadot
48*e51b3d8eSEmmanuel Vadot#
49*e51b3d8eSEmmanuel Vadot# Read
50*e51b3d8eSEmmanuel Vadot#
51*e51b3d8eSEmmanuel VadotMETHOD int read {
52*e51b3d8eSEmmanuel Vadot	device_t dev;
53*e51b3d8eSEmmanuel Vadot	uint32_t offset;
54*e51b3d8eSEmmanuel Vadot	uint32_t size;
55*e51b3d8eSEmmanuel Vadot	uint8_t *buffer;
56*e51b3d8eSEmmanuel Vadot} DEFAULT null_nvmem_read;
57*e51b3d8eSEmmanuel Vadot
58*e51b3d8eSEmmanuel Vadot#
59*e51b3d8eSEmmanuel Vadot# Write
60*e51b3d8eSEmmanuel Vadot#
61*e51b3d8eSEmmanuel VadotMETHOD int write {
62*e51b3d8eSEmmanuel Vadot	device_t dev;
63*e51b3d8eSEmmanuel Vadot	uint32_t offset;
64*e51b3d8eSEmmanuel Vadot	uint32_t size;
65*e51b3d8eSEmmanuel Vadot	uint8_t *buffer;
66*e51b3d8eSEmmanuel Vadot} DEFAULT null_nvmem_write;
67