32#include "opt_platform.h"
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/sysctl.h>
41#include <machine/bus.h>
47#include <dev/ofw/ofw_bus.h>
48#include <dev/ofw/ofw_bus_subr.h>
54#define CTRL_CH_SELECT_MASK 0x03
55#define CTRL_AUTOINC_EN 0x04
56#define CTRL_CH_CONFIG_MASK 0x30
57#define CTRL_CH_CONFIG_4_SINGLE 0x00
58#define CTRL_CH_CONFIG_3_DIFF 0x10
59#define CTRL_CH_CONFIG_2_SINGLE_1_DIFF 0x20
60#define CTRL_CH_CONFIG_2_DIFF 0x30
61#define CTRL_OUTPUT_EN 0x40
73 {
"nxp,pcf8591",
true },
87 sc = device_get_softc(
dev);
106 sc = device_get_softc(
dev);
124 sc = device_get_softc(
dev);
127 sc->
sc_cfg &= ~CTRL_CH_SELECT_MASK;
145 int error, channel,
val;
151 if (req->oldptr != NULL) {
160 error = sysctl_handle_int(oidp, &
val, 0, req);
169 struct sysctl_ctx_list *ctx;
170 struct sysctl_oid *tree_node;
171 struct sysctl_oid_list *tree;
172 struct sysctl_oid *inputs_node;
173 struct sysctl_oid_list *inputs;
190 ctx = device_get_sysctl_ctx(
dev);
191 tree_node = device_get_sysctl_tree(
dev);
192 tree = SYSCTL_CHILDREN(tree_node);
194 inputs_node = SYSCTL_ADD_NODE(ctx, tree, OID_AUTO,
"inputs",
195 CTLTYPE_NODE, NULL,
"Input channels");
196 inputs = SYSCTL_CHILDREN(inputs_node);
200 snprintf(
buf,
sizeof(
buf),
"%d", i);
201 SYSCTL_ADD_PROC(ctx, inputs, OID_AUTO,
buf,
202 CTLTYPE_INT | CTLFLAG_RD,
dev, i,
204 "(relative to Vref)");
212 if (!ofw_bus_status_okay(
dev))
215 device_set_desc(
dev,
"PCF8591 8-bit ADC / DAC");
218 return (BUS_PROBE_GENERIC);
220 return (BUS_PROBE_NOWILDCARD);
228 sc = device_get_softc(
dev);
static ds13_compat_data compat_data[]
#define IICBUS_FDT_PNP_INFO(t)
int iicbus_transfer_excl(device_t dev, struct iic_msg *msgs, uint32_t nmsgs, int how)
static device_method_t pcf8591_methods[]
static int pcf8591_detach(device_t dev)
static devclass_t pcf8591_devclass
static void pcf8591_start(void *arg)
static int pcf8591_get_reading(device_t dev, uint8_t *reading)
static int pcf8591_probe(device_t dev)
static int pcf8591_channel_sysctl(SYSCTL_HANDLER_ARGS)
static int pcf8591_select_channel(device_t dev, int channel)
static driver_t pcf8591_driver
DRIVER_MODULE(pcf8591, iicbus, pcf8591_driver, pcf8591_devclass, 0, 0)
MODULE_VERSION(pcf8591, 1)
static int pcf8591_attach(device_t dev)
MODULE_DEPEND(pcf8591, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
static int pcf8591_set_config(device_t dev)