static void n900audjck_attach(device_t parent, device_t self, void *aux) { struct n900audjck_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; int caps; sc->sc_dev = self; sc->sc_gpio = ga->ga_gpio; /* map pins */ sc->sc_map.pm_map = sc->sc_map_pins; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { aprint_error(": couldn't map the pins\n"); return; } /* configure the input pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, N900AUDJCK_PIN_INPUT); if (!(caps & GPIO_PIN_INPUT)) { aprint_error(": pin is unable to read input\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, N900AUDJCK_PIN_INPUT, GPIO_PIN_INPUT); sc->sc_intr = intr_establish(N900AUDJCK_GPIO_BASE + ga->ga_offset, IPL_VM, IST_EDGE_BOTH, n900audjck_intr, sc); if (sc->sc_intr == NULL) { aprint_error(": couldn't establish interrupt\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } aprint_normal(": N900 audio jack\n"); aprint_naive(": N900 audio jack\n"); if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); } sysmon_task_queue_init(); sc->sc_smpsw.smpsw_name = device_xname(self); sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_HOTKEY; sc->sc_state = PSWITCH_EVENT_RELEASED; sysmon_pswitch_register(&sc->sc_smpsw); /* report an event immediately if an audio jack is inserted */ n900audjck_refresh(sc); }
void gpiopwm_attach(device_t parent, device_t self, void *aux) { struct gpiopwm_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; const struct sysctlnode *node; sc->sc_dev = self; /* Map pin */ sc->sc_gpio = ga->ga_gpio; sc->sc_map.pm_map = sc->_map; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { aprint_error(": can't map pin\n"); return; } aprint_normal(" [%d]", sc->sc_map.pm_map[0]); pmf_device_register(self, NULL, NULL); callout_init(&sc->sc_pulse, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_pulse, gpiopwm_pulse, sc); sysctl_createv(&sc->sc_log, 0, NULL, &node, 0, CTLTYPE_NODE, device_xname(sc->sc_dev), SYSCTL_DESCR("GPIO software PWM"), NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); if (node == NULL) { printf(": can't create sysctl node\n"); return; } sysctl_createv(&sc->sc_log, 0, &node, NULL, CTLFLAG_READWRITE, CTLTYPE_INT, "on", SYSCTL_DESCR("PWM 'on' period in ticks"), gpiopwm_set_on, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL); sysctl_createv(&sc->sc_log, 0, &node, NULL, CTLFLAG_READWRITE, CTLTYPE_INT, "off", SYSCTL_DESCR("PWM 'off' period in ticks"), gpiopwm_set_off, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL); aprint_normal("\n"); return; }
void gpioiic_attach(device_t parent, device_t self, void *aux) { struct gpioiic_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; struct i2cbus_attach_args iba; int caps; /* Map pins */ sc->sc_gpio = ga->ga_gpio; sc->sc_map.pm_map = sc->_map; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { aprint_error(": can't map pins\n"); return; } if (ga->ga_flags & GPIOIIC_PIN_REVERSE) { sc->sc_pin_sda = GPIOIIC_PIN_SCL; sc->sc_pin_scl = GPIOIIC_PIN_SDA; } else { sc->sc_pin_sda = GPIOIIC_PIN_SDA; sc->sc_pin_scl = GPIOIIC_PIN_SCL; } /* Configure SDA pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, sc->sc_pin_sda); if (!(caps & GPIO_PIN_OUTPUT)) { aprint_error(": SDA pin is unable to drive output\n"); goto fail; } if (!(caps & GPIO_PIN_INPUT)) { aprint_error(": SDA pin is unable to read input\n"); goto fail; } aprint_normal(": SDA[%d]", sc->sc_map.pm_map[sc->sc_pin_sda]); sc->sc_sda = GPIO_PIN_OUTPUT; if (caps & GPIO_PIN_OPENDRAIN) { aprint_normal(" open-drain"); sc->sc_sda |= GPIO_PIN_OPENDRAIN; } else if ((caps & GPIO_PIN_PUSHPULL) && (caps & GPIO_PIN_TRISTATE)) { aprint_normal(" push-pull tri-state"); sc->sc_sda |= GPIO_PIN_PUSHPULL; } if (caps & GPIO_PIN_PULLUP) { aprint_normal(" pull-up"); sc->sc_sda |= GPIO_PIN_PULLUP; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, sc->sc_pin_sda, sc->sc_sda); /* Configure SCL pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, sc->sc_pin_scl); if (!(caps & GPIO_PIN_OUTPUT)) { aprint_error(": SCL pin is unable to drive output\n"); goto fail; } aprint_normal(", SCL[%d]", sc->sc_map.pm_map[sc->sc_pin_scl]); sc->sc_scl = GPIO_PIN_OUTPUT; if (caps & GPIO_PIN_OPENDRAIN) { aprint_normal(" open-drain"); sc->sc_scl |= GPIO_PIN_OPENDRAIN; if (caps & GPIO_PIN_PULLUP) { aprint_normal(" pull-up"); sc->sc_scl |= GPIO_PIN_PULLUP; } } else if (caps & GPIO_PIN_PUSHPULL) { aprint_normal(" push-pull"); sc->sc_scl |= GPIO_PIN_PUSHPULL; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, sc->sc_pin_scl, sc->sc_scl); aprint_normal("\n"); /* Attach I2C bus */ rw_init(&sc->sc_i2c_lock); sc->sc_i2c_tag.ic_cookie = sc; sc->sc_i2c_tag.ic_acquire_bus = gpioiic_i2c_acquire_bus; sc->sc_i2c_tag.ic_release_bus = gpioiic_i2c_release_bus; sc->sc_i2c_tag.ic_send_start = gpioiic_i2c_send_start; sc->sc_i2c_tag.ic_send_stop = gpioiic_i2c_send_stop; sc->sc_i2c_tag.ic_initiate_xfer = gpioiic_i2c_initiate_xfer; sc->sc_i2c_tag.ic_read_byte = gpioiic_i2c_read_byte; sc->sc_i2c_tag.ic_write_byte = gpioiic_i2c_write_byte; sc->sc_i2c_tag.ic_exec = NULL; memset(&iba, 0, sizeof(iba)); iba.iba_type = I2C_TYPE_SMBUS; iba.iba_tag = &sc->sc_i2c_tag; sc->sc_i2c_dev = config_found(self, &iba, iicbus_print); if (!pmf_device_register(self, NULL, NULL)) aprint_error("%s: could not establish power handler\n", device_xname(self)); return; fail: gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); }
void gpioow_attach(struct device *parent, struct device *self, void *aux) { struct gpioow_softc *sc = (struct gpioow_softc *)self; struct gpio_attach_args *ga = aux; struct onewirebus_attach_args oba; int caps; /* Check that we have enough pins */ if (gpio_npins(ga->ga_mask) != GPIOOW_NPINS) { printf(": invalid pin mask\n"); return; } /* Map pins */ sc->sc_gpio = ga->ga_gpio; sc->sc_map.pm_map = sc->__map; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { printf(": can't map pins\n"); return; } /* Configure data pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, GPIOOW_PIN_DATA); if (!(caps & GPIO_PIN_OUTPUT)) { printf(": data pin is unable to drive output\n"); goto fail; } if (!(caps & GPIO_PIN_INPUT)) { printf(": data pin is unable to read input\n"); goto fail; } printf(": DATA[%d]", sc->sc_map.pm_map[GPIOOW_PIN_DATA]); sc->sc_data = GPIO_PIN_OUTPUT; if (caps & GPIO_PIN_OPENDRAIN) { printf(" open-drain"); sc->sc_data |= GPIO_PIN_OPENDRAIN; } else if ((caps & GPIO_PIN_PUSHPULL) && (caps & GPIO_PIN_TRISTATE)) { printf(" push-pull tri-state"); sc->sc_data |= GPIO_PIN_PUSHPULL; } if (caps & GPIO_PIN_PULLUP) { printf(" pull-up"); sc->sc_data |= GPIO_PIN_PULLUP; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, GPIOOW_PIN_DATA, sc->sc_data); printf("\n"); /* Attach 1-Wire bus */ sc->sc_ow_bus.bus_cookie = sc; sc->sc_ow_bus.bus_reset = gpioow_ow_reset; sc->sc_ow_bus.bus_bit = gpioow_ow_bit; bzero(&oba, sizeof(oba)); oba.oba_bus = &sc->sc_ow_bus; sc->sc_ow_dev = config_found(self, &oba, onewirebus_print); return; fail: gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); }
static void mousebtn_attach(device_t parent, device_t self, void *aux) { struct mousebtn_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; int caps; struct wsmousedev_attach_args a; sc->sc_dev = self; sc->sc_gpio = ga->ga_gpio; /* map pins */ sc->sc_map.pm_map = sc->sc_map_pins; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { aprint_error(": couldn't map the pins\n"); return; } /* configure left pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_LEFT); if (!(caps & GPIO_PIN_INPUT)) { aprint_error(": pin is unable to read input\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_LEFT, GPIO_PIN_INPUT); /* configure right pin */ caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_RIGHT); if (!(caps & GPIO_PIN_INPUT)) { aprint_error(": pin is unable to read input\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_RIGHT, GPIO_PIN_INPUT); /* interrupt settings */ sc->sc_intr[0] = intr_establish(GPIO1_BASE + ga->ga_offset, IPL_VM, IST_EDGE_BOTH, mousebtn_intr, sc); if (sc->sc_intr[0] == NULL) { aprint_error(": couldn't establish interrupt\n"); return; } sc->sc_intr[1] = intr_establish(GPIO1_BASE + ga->ga_offset + 1, IPL_VM, IST_EDGE_BOTH, mousebtn_intr, sc); if (sc->sc_intr[1] == NULL) { aprint_error(": couldn't establish interrupt\n"); intr_disestablish(sc->sc_intr[0]); return; } aprint_normal(": NetWalker mouse button\n"); aprint_naive(": NetWalker mouse button\n"); mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); callout_init(&sc->sc_c, 0); a.accessops = &mousebtn_accessops; a.accesscookie = sc; sc->sc_buttons = 0; sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint); }