Lines Matching refs:dev
48 #include <dev/iicbus/iicbus.h>
49 #include <dev/iicbus/iiconf.h>
51 #include <dev/gpio/gpiobusvar.h>
53 #include <dev/ofw/openfirm.h>
54 #include <dev/ofw/ofw_bus.h>
55 #include <dev/ofw/ofw_bus_subr.h>
63 device_t dev;
91 axp209_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size)
93 struct axp209_softc *sc = device_get_softc(dev);
106 return (iicbus_transfer(dev, msg, 2));
110 axp209_write(device_t dev, uint8_t reg, uint8_t data)
113 struct axp209_softc *sc = device_get_softc(dev);
124 return (iicbus_transfer(dev, &msg, 1));
130 device_t dev = arg1;
137 error = axp209_read(dev, AXP209_TEMPMON, data, 2);
146 error = axp209_read(dev, AXP209_ACIN_VOLTAGE, data, 2);
154 error = axp209_read(dev, AXP209_ACIN_CURRENT, data, 2);
162 error = axp209_read(dev, AXP209_VBUS_VOLTAGE, data, 2);
170 error = axp209_read(dev, AXP209_VBUS_CURRENT, data, 2);
178 error = axp209_read(dev, AXP209_BAT_VOLTAGE, data, 2);
186 error = axp209_read(dev, AXP209_BAT_CHARGE_CURRENT, data, 2);
194 error = axp209_read(dev, AXP209_BAT_DISCHARGE_CURRENT, data, 2);
211 device_t dev;
215 dev = (device_t)devp;
218 device_printf(dev, "Shutdown AXP209\n");
220 axp209_write(dev, AXP209_SHUTBAT, AXP209_SHUTBAT_SHUTDOWN);
231 axp209_read(sc->dev, AXP209_IRQ1_STATUS, ®, 1);
247 axp209_write(sc->dev, AXP209_IRQ1_STATUS, AXP209_IRQ_ACK);
250 axp209_read(sc->dev, AXP209_IRQ2_STATUS, ®, 1);
264 axp209_write(sc->dev, AXP209_IRQ2_STATUS, AXP209_IRQ_ACK);
267 axp209_read(sc->dev, AXP209_IRQ3_STATUS, ®, 1);
271 axp209_write(sc->dev, AXP209_IRQ3_STATUS, AXP209_IRQ_ACK);
274 axp209_read(sc->dev, AXP209_IRQ4_STATUS, ®, 1);
276 axp209_write(sc->dev, AXP209_IRQ4_STATUS, AXP209_IRQ_ACK);
279 axp209_read(sc->dev, AXP209_IRQ5_STATUS, ®, 1);
281 axp209_write(sc->dev, AXP209_IRQ5_STATUS, AXP209_IRQ_ACK);
286 axp209_gpio_get_bus(device_t dev)
290 sc = device_get_softc(dev);
296 axp209_gpio_pin_max(device_t dev, int *maxpin)
304 axp209_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
315 axp209_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
326 axp209_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
335 sc = device_get_softc(dev);
338 error = axp209_read(dev, axp209_pins[pin].ctrl_reg, &data, 1);
355 axp209_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
364 sc = device_get_softc(dev);
367 error = axp209_read(dev, axp209_pins[pin].ctrl_reg, &data, 1);
374 error = axp209_write(dev, axp209_pins[pin].ctrl_reg, data);
382 axp209_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
391 sc = device_get_softc(dev);
394 error = axp209_read(dev, axp209_pins[pin].ctrl_reg, &data, 1);
405 error = axp209_read(dev, AXP209_GPIO_STATUS, &data, 1);
420 axp209_gpio_pin_set(device_t dev, uint32_t pin, unsigned int val)
429 sc = device_get_softc(dev);
432 error = axp209_read(dev, axp209_pins[pin].ctrl_reg, &data, 1);
452 error = axp209_write(dev, axp209_pins[pin].ctrl_reg, data);
460 axp209_gpio_pin_toggle(device_t dev, uint32_t pin)
469 sc = device_get_softc(dev);
472 error = axp209_read(dev, axp209_pins[pin].ctrl_reg, &data, 1);
495 error = axp209_write(dev, axp209_pins[pin].ctrl_reg, data);
502 axp209_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent,
515 axp209_get_node(device_t dev, device_t bus)
517 return (ofw_bus_get_node(dev));
523 device_t dev;
529 dev = pdev;
531 sc = device_get_softc(dev);
532 sc->addr = iicbus_get_addr(dev);
533 sc->dev = dev;
541 axp209_read(dev, AXP209_PSR, &data, 1);
545 device_printf(dev, "AXP209 Powered by %s\n",
550 axp209_write(dev, AXP209_IRQ1_ENABLE,
557 axp209_write(dev, AXP209_IRQ2_ENABLE,
566 axp209_write(dev, AXP209_IRQ3_ENABLE,
568 axp209_write(dev, AXP209_IRQ4_ENABLE, AXP209_IRQ4_APS_LOW_2);
569 axp209_write(dev, AXP209_IRQ5_ENABLE, 0x0);
571 EVENTHANDLER_REGISTER(shutdown_final, axp209_shutdown, dev,
575 if (axp209_write(dev, AXP209_ADC_ENABLE1,
579 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
580 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
583 dev, AXP209_ACVOLT, axp209_sysctl, "I",
585 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
586 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
589 dev, AXP209_ACCURRENT, axp209_sysctl, "I",
591 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
592 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
595 dev, AXP209_VBUSVOLT, axp209_sysctl, "I",
597 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
598 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
601 dev, AXP209_VBUSCURRENT, axp209_sysctl, "I",
603 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
604 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
607 dev, AXP209_BATVOLT, axp209_sysctl, "I",
609 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
610 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
613 dev, AXP209_BATCHARGECURRENT, axp209_sysctl, "I",
615 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
616 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
619 dev, AXP209_BATDISCHARGECURRENT, axp209_sysctl, "I",
622 device_printf(dev, "Couldn't enable ADC sensors\n");
625 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
626 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
629 dev, AXP209_TEMP, axp209_sysctl, "IK", "Internal temperature");
631 if ((bus_setup_intr(dev, sc->res[0], INTR_TYPE_MISC | INTR_MPSAFE,
633 device_printf(dev, "unable to register interrupt handler\n");
639 axp209_probe(device_t dev)
642 if (!ofw_bus_status_okay(dev))
645 if (!ofw_bus_is_compatible(dev, "x-powers,axp209"))
648 device_set_desc(dev, "X-Powers AXP209 Power Management Unit");
654 axp209_attach(device_t dev)
658 sc = device_get_softc(dev);
659 mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
661 if (bus_alloc_resources(dev, axp_res_spec, sc->res) != 0) {
662 device_printf(dev, "can't allocate device resources\n");
667 sc->intr_hook.ich_arg = dev;
672 sc->gpiodev = gpiobus_attach_bus(dev);