diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-01-21 00:21:56 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-01-21 00:21:56 +0000 |
commit | f1e2f79a9e206ff0466db02c5c02080477efc59f (patch) | |
tree | 4b0086d6799771af4663addf36960f54a9441325 | |
parent | 1d550900bcb34eeef5b656bc353d7759d4e39130 (diff) |
Add the beginnings of an nvmem "framework".
ok patrick@
-rw-r--r-- | sys/dev/ofw/ofw_misc.c | 32 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_misc.h | 16 |
2 files changed, 46 insertions, 2 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c index dd98ee8c4af..7856088933f 100644 --- a/sys/dev/ofw/ofw_misc.c +++ b/sys/dev/ofw/ofw_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.c,v 1.10 2019/09/30 20:40:54 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.c,v 1.11 2020/01/21 00:21:55 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -337,3 +337,33 @@ pwm_set_state(uint32_t *cells, struct pwm_state *ps) return ENXIO; } + +/* + * Non-volatile memory support. + */ + +LIST_HEAD(, nvmem_device) nvmem_devices = + LIST_HEAD_INITIALIZER(nvmem_devices); + +void +nvmem_register(struct nvmem_device *nd) +{ + nd->nd_phandle = OF_getpropint(nd->nd_node, "phandle", 0); + if (nd->nd_phandle == 0) + return; + + LIST_INSERT_HEAD(&nvmem_devices, nd, nd_list); +} + +int +nvmem_read(uint32_t phandle, bus_addr_t addr, void *data, bus_size_t size) +{ + struct nvmem_device *nd; + + LIST_FOREACH(nd, &nvmem_devices, nd_list) { + if (nd->nd_phandle == phandle) + return nd->nd_read(nd->nd_cookie, addr, data, size); + } + + return ENXIO; +} diff --git a/sys/dev/ofw/ofw_misc.h b/sys/dev/ofw/ofw_misc.h index 3c3f75307a7..d286ea1fecf 100644 --- a/sys/dev/ofw/ofw_misc.h +++ b/sys/dev/ofw/ofw_misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.h,v 1.7 2019/09/30 20:40:54 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.h,v 1.8 2020/01/21 00:21:55 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -114,4 +114,18 @@ int pwm_init_state(uint32_t *cells, struct pwm_state *ps); int pwm_get_state(uint32_t *cells, struct pwm_state *ps); int pwm_set_state(uint32_t *cells, struct pwm_state *ps); +/* Non-volatile memory support */ + +struct nvmem_device { + int nd_node; + void *nd_cookie; + int (*nd_read)(void *, bus_addr_t, void *, bus_size_t); + + LIST_ENTRY(nvmem_device) nd_list; + uint32_t nd_phandle; +}; + +void nvmem_register(struct nvmem_device *); +int nvmem_read(uint32_t, bus_addr_t, void *, bus_size_t); + #endif /* _DEV_OFW_MISC_H_ */ |