-/* $OpenBSD: ofw_misc.c,v 1.37 2022/11/07 19:07:31 patrick Exp $ */
+/* $OpenBSD: ofw_misc.c,v 1.38 2022/12/17 11:54:32 kettenis Exp $ */
/*
* Copyright (c) 2017-2021 Mark Kettenis
*
{
struct nvmem_device *nd;
struct nvmem_cell *nc;
+ uint8_t *p = data;
+ bus_addr_t addr;
uint32_t phandle, *phandles;
uint32_t offset, bitlen;
int id, len, first;
return EACCES;
first = 1;
- offset = nc->nc_offset;
+ addr = nc->nc_addr + (nc->nc_offset / 8);
+ offset = nc->nc_offset % 8;
bitlen = nc->nc_bitlen;
while (bitlen > 0 && size > 0) {
- uint8_t *p = data;
uint8_t mask, tmp;
int error;
- error = nd->nd_read(nd->nd_cookie, nc->nc_addr, &tmp, 1);
+ error = nd->nd_read(nd->nd_cookie, addr++, &tmp, 1);
if (error)
return error;
if (!first) {
*p++ |= (tmp << (8 - offset)) & (mask << (8 - offset));
bitlen -= MIN(offset, bitlen);
+ mask >>= offset;
size--;
}
if (bitlen > 0 && size > 0) {
- *p = (tmp >> offset) & (mask >> offset);
+ *p = (tmp >> offset) & mask;
bitlen -= MIN(8 - offset, bitlen);
}
{
struct nvmem_device *nd;
struct nvmem_cell *nc;
+ const uint8_t *p = data;
+ bus_addr_t addr;
uint32_t phandle, *phandles;
uint32_t offset, bitlen;
int id, len, first;
return EACCES;
first = 1;
- offset = nc->nc_offset;
+ addr = nc->nc_addr + (nc->nc_offset / 8);
+ offset = nc->nc_offset % 8;
bitlen = nc->nc_bitlen;
while (bitlen > 0 && size > 0) {
- const uint8_t *p = data;
uint8_t mask, tmp;
int error;
- error = nd->nd_read(nd->nd_cookie, nc->nc_addr, &tmp, 1);
+ error = nd->nd_read(nd->nd_cookie, addr, &tmp, 1);
if (error)
return error;
bitlen -= MIN(offset, bitlen);
}
- error = nd->nd_write(nd->nd_cookie, nc->nc_addr, &tmp, 1);
+ error = nd->nd_write(nd->nd_cookie, addr++, &tmp, 1);
if (error)
return error;