git: 01e3492337cb - main - icee: allow configuration via hints on FDT-based systems
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 13 Nov 2021 09:25:21 UTC
The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=01e3492337cb48484e03be38340cc67ac5e30a5b commit 01e3492337cb48484e03be38340cc67ac5e30a5b Author: Andriy Gapon <avg@FreeBSD.org> AuthorDate: 2021-11-04 11:56:22 +0000 Commit: Andriy Gapon <avg@FreeBSD.org> CommitDate: 2021-11-13 09:24:57 +0000 icee: allow configuration via hints on FDT-based systems On-board devices should be configured via the FDT and overlays. Hints are primarily useful for external and temporarily attached devices. Adding hints is much easier and faster than writing and compiling an overlay. MFC after: 2 weeks --- sys/dev/iicbus/icee.c | 64 +++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/sys/dev/iicbus/icee.c b/sys/dev/iicbus/icee.c index 19aff78bf45a..a658d73cb875 100644 --- a/sys/dev/iicbus/icee.c +++ b/sys/dev/iicbus/icee.c @@ -123,10 +123,10 @@ static struct cdevsw icee_cdevsw = .d_write = icee_write }; -#ifdef FDT static int icee_probe(device_t dev) { +#ifdef FDT struct eeprom_desc *d; if (!ofw_bus_status_okay(dev)) @@ -134,49 +134,42 @@ icee_probe(device_t dev) d = (struct eeprom_desc *) ofw_bus_search_compatible(dev, compat_data)->ocd_data; - if (d == NULL) - return (ENXIO); - - device_set_desc(dev, d->name); - return (BUS_PROBE_DEFAULT); -} - -static void -icee_init(struct icee_softc *sc) -{ - struct eeprom_desc *d; - - d = (struct eeprom_desc *) - ofw_bus_search_compatible(sc->dev, compat_data)->ocd_data; - if (d == NULL) - return; /* attach will see sc->size == 0 and return error */ - - sc->size = d->size; - sc->type = d->type; - sc->wr_sz = d->wr_sz; -} -#else /* !FDT */ -static int -icee_probe(device_t dev) -{ - + if (d != NULL) { + device_set_desc(dev, d->name); + return (BUS_PROBE_DEFAULT); + } +#endif device_set_desc(dev, "I2C EEPROM"); return (BUS_PROBE_NOWILDCARD); } -static void +static int icee_init(struct icee_softc *sc) { const char *dname; int dunit; +#ifdef FDT + struct eeprom_desc *d; + d = (struct eeprom_desc *) + ofw_bus_search_compatible(sc->dev, compat_data)->ocd_data; + if (d != NULL) { + sc->size = d->size; + sc->type = d->type; + sc->wr_sz = d->wr_sz; + return (0); + } +#endif dname = device_get_name(sc->dev); dunit = device_get_unit(sc->dev); - resource_int_value(dname, dunit, "size", &sc->size); - resource_int_value(dname, dunit, "type", &sc->type); - resource_int_value(dname, dunit, "wr_sz", &sc->wr_sz); + if (resource_int_value(dname, dunit, "type", &sc->type) != 0) + return (ENOENT); + if (resource_int_value(dname, dunit, "size", &sc->size) != 0) + return (ENOENT); + if (resource_int_value(dname, dunit, "wr_sz", &sc->wr_sz) != 0) + return (ENOENT); + return (0); } -#endif /* FDT */ static int icee_attach(device_t dev) @@ -187,13 +180,8 @@ icee_attach(device_t dev) sc->dev = dev; sc->addr = iicbus_get_addr(dev); - icee_init(sc); - if (sc->size == 0 || sc->type == 0 || sc->wr_sz == 0) { - device_printf(sc->dev, "Missing config data, " - "these cannot be zero: size %d type %d wr_sz %d\n", - sc->size, sc->type, sc->wr_sz); + if (icee_init(sc) != 0) return (EINVAL); - } if (bootverbose) device_printf(dev, "size: %d bytes, addressing: %d-bits\n", sc->size, sc->type);