Lines Matching +full:chan +full:- +full:name

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
72 * On config write, the operational-state bit starts a measurement, on read it
79 * The default values for config items that are not per-channel. Mostly, this
90 * Per-channel defaults. The chip only has one control register, and we load
91 * per-channel values into it every time we make a measurement on that channel.
93 * values we maintain on a per-channel basis.
99 * Full-scale ranges for each available amplifier setting, in microvolts. The
100 * ADS1x13 chips are fixed-range, the other chips contain a programmable gain
111 #define ADS101x_RANGEDIV ((1 << 15) - 15)
112 #define ADS111x_RANGEDIV ((1 << 15) - 1)
119 u_int gainidx; /* Amplifier (full-scale range) config index */
127 const char *name; member
174 slaveaddr = iicbus_get_addr(sc->dev); in ads111x_write_2()
184 return (iicbus_transfer_excl(sc->dev, msgs, nitems(msgs), IIC_WAIT)); in ads111x_write_2()
193 err = iic2errno(iicdev_readfrom(sc->dev, reg, data, 2, IIC_WAIT)); in ads111x_read_2()
203 struct ads111x_channel *chan; in ads111x_sample_voltage() local
207 chan = &sc->channels[channum]; in ads111x_sample_voltage()
209 /* Ask the chip to do a one-shot measurement of the given channel. */ in ads111x_sample_voltage()
210 cfgword = sc->cfgword | in ads111x_sample_voltage()
213 (chan->gainidx << ADS111x_CONF_GAIN_SHIFT) | in ads111x_sample_voltage()
214 (chan->rateidx << ADS111x_CONF_RATE_SHIFT); in ads111x_sample_voltage()
223 rate = sc->chipinfo->ratetab[chan->rateidx]; in ads111x_sample_voltage()
224 waitns = (1000000000 + rate - 1) / rate; in ads111x_sample_voltage()
233 * as the system clock, so we have to double-check that the measurement in ads111x_sample_voltage()
237 * Unlike most i2c slaves, this device does not auto-increment the in ads111x_sample_voltage()
241 for (retries = 5; ; --retries) { in ads111x_sample_voltage()
254 fsrange = sc->chipinfo->rangetab[chan->gainidx]; in ads111x_sample_voltage()
255 *voltage = (int)((convword * fsrange ) / sc->chipinfo->rangediv); in ads111x_sample_voltage()
264 int chan, err, gainidx; in ads111x_sysctl_gainidx() local
267 chan = arg2; in ads111x_sysctl_gainidx()
269 gainidx = sc->channels[chan].gainidx; in ads111x_sysctl_gainidx()
271 if (err != 0 || req->newptr == NULL) in ads111x_sysctl_gainidx()
275 sx_xlock(&sc->lock); in ads111x_sysctl_gainidx()
276 sc->channels[chan].gainidx = gainidx; in ads111x_sysctl_gainidx()
277 sx_xunlock(&sc->lock); in ads111x_sysctl_gainidx()
286 int chan, err, rateidx; in ads111x_sysctl_rateidx() local
289 chan = arg2; in ads111x_sysctl_rateidx()
291 rateidx = sc->channels[chan].rateidx; in ads111x_sysctl_rateidx()
293 if (err != 0 || req->newptr == NULL) in ads111x_sysctl_rateidx()
297 sx_xlock(&sc->lock); in ads111x_sysctl_rateidx()
298 sc->channels[chan].rateidx = rateidx; in ads111x_sysctl_rateidx()
299 sx_xunlock(&sc->lock); in ads111x_sysctl_rateidx()
308 int chan, err, voltage; in ads111x_sysctl_voltage() local
311 chan = arg2; in ads111x_sysctl_voltage()
313 if (req->oldptr != NULL) { in ads111x_sysctl_voltage()
314 sx_xlock(&sc->lock); in ads111x_sysctl_voltage()
315 err = ads111x_sample_voltage(sc, chan, &voltage); in ads111x_sysctl_voltage()
316 sx_xunlock(&sc->lock); in ads111x_sysctl_voltage()
318 device_printf(sc->dev, in ads111x_sysctl_voltage()
334 config = sc->cfgword & ADS111x_CONF_USERMASK; in ads111x_sysctl_config()
336 if (err != 0 || req->newptr == NULL) in ads111x_sysctl_config()
338 sx_xlock(&sc->lock); in ads111x_sysctl_config()
339 sc->cfgword = config & ADS111x_CONF_USERMASK; in ads111x_sysctl_config()
340 err = ads111x_write_2(sc, ADS111x_CONF, sc->cfgword); in ads111x_sysctl_config()
341 sx_xunlock(&sc->lock); in ads111x_sysctl_config()
355 if (err != 0 || req->newptr == NULL) in ads111x_sysctl_lothresh()
357 sx_xlock(&sc->lock); in ads111x_sysctl_lothresh()
359 sx_xunlock(&sc->lock); in ads111x_sysctl_lothresh()
374 if (err != 0 || req->newptr == NULL) in ads111x_sysctl_hithresh()
376 sx_xlock(&sc->lock); in ads111x_sysctl_hithresh()
378 sx_xunlock(&sc->lock); in ads111x_sysctl_hithresh()
384 ads111x_setup_channel(struct ads111x_softc *sc, int chan, int gainidx, int rateidx) in ads111x_setup_channel() argument
391 c = &sc->channels[chan]; in ads111x_setup_channel()
392 c->gainidx = gainidx; in ads111x_setup_channel()
393 c->rateidx = rateidx; in ads111x_setup_channel()
401 if (c->configured) in ads111x_setup_channel()
404 ctx = device_get_sysctl_ctx(sc->dev); in ads111x_setup_channel()
405 devtree = device_get_sysctl_tree(sc->dev); in ads111x_setup_channel()
406 snprintf(chanstr, sizeof(chanstr), "%d", chan); in ads111x_setup_channel()
411 sc, chan, ads111x_sysctl_gainidx, "I", in ads111x_setup_channel()
412 "programmable gain amp setting, 0-7"); in ads111x_setup_channel()
415 sc, chan, ads111x_sysctl_rateidx, "I", "sample rate setting, 0-7"); in ads111x_setup_channel()
419 chan, ads111x_sysctl_voltage, "I", "sampled voltage in microvolts"); in ads111x_setup_channel()
421 c->configured = true; in ads111x_setup_channel()
427 const char *name; in ads111x_add_channels() local
428 uint32_t chan, gainidx, num_added, rateidx, unit; in ads111x_add_channels() local
436 node = ofw_bus_get_node(sc->dev); in ads111x_add_channels()
438 if (OF_getencprop(child, "reg", &chan, sizeof(chan)) == -1) in ads111x_add_channels()
440 if (chan >= ADS111x_MAX_CHANNELS) in ads111x_add_channels()
446 ads111x_setup_channel(sc, chan, gainidx, rateidx); in ads111x_add_channels()
454 name = device_get_name(sc->dev); in ads111x_add_channels()
455 unit = device_get_unit(sc->dev); in ads111x_add_channels()
456 for (chan = 0; chan < sc->chipinfo->numchan; ++chan) { in ads111x_add_channels()
461 snprintf(resname, sizeof(resname), "%d.gain_index", chan); in ads111x_add_channels()
462 if (resource_int_value(name, unit, resname, &gainidx) == 0) in ads111x_add_channels()
464 snprintf(resname, sizeof(resname), "%d.rate_index", chan); in ads111x_add_channels()
465 if (resource_int_value(name, unit, resname, &rateidx) == 0) in ads111x_add_channels()
468 ads111x_setup_channel(sc, chan, gainidx, rateidx); in ads111x_add_channels()
481 for (chan = 0; chan < sc->chipinfo->numchan; ++chan) { in ads111x_add_channels()
484 ads111x_setup_channel(sc, chan, gainidx, rateidx); in ads111x_add_channels()
498 ofw_bus_search_compatible(dev, compat_data)->ocd_data; in ads111x_find_chipinfo()
511 if (strcasecmp(chiptype, info->name) == 0) in ads111x_find_chipinfo()
525 device_set_desc(dev, info->name); in ads111x_probe()
545 sc->dev = dev; in ads111x_attach()
546 sc->addr = iicbus_get_addr(dev); in ads111x_attach()
547 sc->cfgword = ADS111x_CONF_DEFAULT; in ads111x_attach()
549 sc->chipinfo = ads111x_find_chipinfo(sc->dev); in ads111x_attach()
550 if (sc->chipinfo == NULL) { in ads111x_attach()
557 if ((err = ads111x_write_2(sc, ADS111x_CONF, sc->cfgword)) != 0) { in ads111x_attach()
578 sx_init(&sc->lock, "ads111x"); in ads111x_attach()
590 sx_destroy(&sc->lock); in ads111x_detach()