/* ARGSUSED */ static int tsalarm_open(dev_t *devp, int flag, int otyp, cred_t *credp) { int inst = getminor(*devp); return (getsoftc(inst) == NULL ? ENXIO : 0); }
/* ARGSUSED */ static int tsalarm_close(dev_t dev, int flag, int otyp, cred_t *credp) { int inst = getminor(dev); return (getsoftc(inst) == NULL ? ENXIO : 0); }
int msopen(dev_t dev, int flags, int mode, struct lwp *l) { struct ms_softc *sc; struct ms_port *ms; int unit, port; unit = MS_UNIT(dev); sc = (struct ms_softc *)getsoftc(ms_cd, unit); if (sc == NULL) return(EXDEV); port = MS_PORT(dev); ms = &sc->sc_ports[port]; if (ms->ms_events.ev_io) return(EBUSY); #if NWSMOUSE > 0 /* don't allow opening when sending events to wsmouse */ if (ms->ms_wsenabled) return EBUSY; #endif /* initialize potgo bits for mouse mode */ custom.potgo = custom.potgor | (0xf00 << (port * 4)); ms->ms_events.ev_io = l->l_proc; ev_init(&ms->ms_events); /* may cause sleep */ ms_enable(ms); return(0); }
static int tsalarm_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) { int inst; struct tsalarm_softc *softc; switch (cmd) { case DDI_DETACH: inst = ddi_get_instance(dip); if ((softc = getsoftc(inst)) == NULL) return (DDI_FAILURE); /* * Free the soft state and remove minor node added earlier. */ ddi_remove_minor_node(dip, NULL); mutex_destroy(&softc->mutex); ddi_soft_state_free(statep, inst); return (DDI_SUCCESS); case DDI_SUSPEND: return (DDI_SUCCESS); default: return (DDI_FAILURE); } }
/* ARGSUSED */ static int tsalarm_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) { int inst = getminor((dev_t)arg); int retval = DDI_SUCCESS; struct tsalarm_softc *softc; switch (cmd) { case DDI_INFO_DEVT2DEVINFO: if ((softc = getsoftc(inst)) == NULL) { *result = (void *)NULL; retval = DDI_FAILURE; } else { *result = (void *)softc->dip; } break; case DDI_INFO_DEVT2INSTANCE: *result = (void *)(uintptr_t)inst; break; default: retval = DDI_FAILURE; } return (retval); }
static int gpio_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) { int instance; struct gpio_softc *softc; switch (cmd) { case DDI_DETACH: instance = ddi_get_instance(dip); DBG(dip, "detach: instance is %d", instance, 0, 0, 0, 0); if ((softc = getsoftc(instance)) == NULL) return (ENXIO); mutex_destroy(&softc->gp_mutex); ddi_regs_map_free(&softc->gp_handle); ddi_soft_state_free(statep, instance); ddi_remove_minor_node(dip, NULL); return (DDI_SUCCESS); case DDI_SUSPEND: /* Nothing to do in the suspend case. */ return (DDI_SUCCESS); default: return (DDI_FAILURE); } }
/* ARGSUSED */ static int gpio_close(dev_t dev, int flag, int otyp, cred_t *credp) { int instance = getminor(dev); DBG(NULL, "close: instance is %d", instance, 0, 0, 0, 0); return (getsoftc(instance) == NULL ? ENXIO : 0); }
/* ARGSUSED */ static int gpio_open(dev_t *devp, int flag, int otyp, cred_t *credp) { int instance = getminor(*devp); DBG(NULL, "open: instance is %d", instance, 0, 0, 0, 0); return (getsoftc(instance) == NULL ? ENXIO : 0); }
static int tsalarm_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) { int inst; struct tsalarm_softc *softc = NULL; switch (cmd) { case DDI_ATTACH: inst = ddi_get_instance(dip); /* * Allocate a soft state structure for this instance. */ if (ddi_soft_state_zalloc(statep, inst) != DDI_SUCCESS) goto attach_failed; softc = getsoftc(inst); softc->dip = dip; mutex_init(&softc->mutex, NULL, MUTEX_DRIVER, NULL); /* * Create minor node. The minor device number, inst, has no * meaning. The model number above, which will be added to * the device's softc, is used to direct peculiar behavior. */ if (ddi_create_minor_node(dip, "lom", S_IFCHR, 0, DDI_PSEUDO, NULL) == DDI_FAILURE) goto attach_failed; ddi_report_dev(dip); return (DDI_SUCCESS); case DDI_RESUME: return (DDI_SUCCESS); default: return (DDI_FAILURE); } attach_failed: /* Free soft state, if allocated. remove minor node if added earlier */ if (softc) { mutex_destroy(&softc->mutex); ddi_soft_state_free(statep, inst); } ddi_remove_minor_node(dip, NULL); return (DDI_FAILURE); }
/* ARGSUSED */ static int tsalarm_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp) { int inst = getminor(dev); struct tsalarm_softc *softc; int retval = 0; ts_aldata_t ts_alinfo; int alarm_type, alarm_state = 0; if ((softc = getsoftc(inst)) == NULL) return (ENXIO); mutex_enter(&softc->mutex); switch (cmd) { case LOMIOCALSTATE: case LOMIOCALSTATE_OLD: { if (ddi_copyin((caddr_t)arg, (caddr_t)&ts_alinfo, sizeof (ts_aldata_t), mode) != 0) { retval = EFAULT; goto end; } alarm_type = ts_alinfo.alarm_no; if ((alarm_type < ALARM_CRITICAL) || (alarm_type > ALARM_USER)) { retval = EINVAL; goto end; } retval = rmclomv_alarm_get(alarm_type, &alarm_state); if (retval != 0) goto end; if ((alarm_state != 0) && (alarm_state != 1)) { retval = EIO; goto end; } ts_alinfo.alarm_state = alarm_state; if (ddi_copyout((caddr_t)&ts_alinfo, (caddr_t)arg, sizeof (ts_aldata_t), mode) != 0) { retval = EFAULT; goto end; } } break; case LOMIOCALCTL: case LOMIOCALCTL_OLD: { if (ddi_copyin((caddr_t)arg, (caddr_t)&ts_alinfo, sizeof (ts_aldata_t), mode) != 0) { retval = EFAULT; goto end; } alarm_type = ts_alinfo.alarm_no; alarm_state = ts_alinfo.alarm_state; if ((alarm_type < ALARM_CRITICAL) || (alarm_type > ALARM_USER)) { retval = EINVAL; goto end; } if ((alarm_state < ALARM_OFF) || (alarm_state > ALARM_ON)) { retval = EINVAL; goto end; } retval = rmclomv_alarm_set(alarm_type, alarm_state); } break; default: retval = EINVAL; break; } end: mutex_exit(&softc->mutex); return (retval); }
/* ARGSUSED */ static int gpio_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp) { int instance = getminor(dev); struct gpio_softc *softc = getsoftc(instance); gpio_87317_op_t info; uint8_t byte; DBG(softc->gp_dip, "ioctl: instance is %d", instance, 0, 0, 0, 0); if (softc == NULL) return (ENXIO); /* Copy the command from user space. */ if (ddi_copyin((caddr_t)arg, (caddr_t)&info, sizeof (gpio_87317_op_t), mode) != 0) return (EFAULT); /* Check the command arguments. We only support port 1 in bank 0. */ if ((info.gpio_bank != 0) || (info.gpio_offset != GPIO_87317_PORT1_DATA)) { return (EINVAL); } /* Grap the instance's mutex to insure exclusive access. */ mutex_enter(&softc->gp_mutex); /* Get the contents of the GPIO register we're suppose to modify. */ byte = ddi_get8(softc->gp_handle, &softc->gp_regs[info.gpio_offset]); switch (cmd) { case GPIO_CMD_SET_BITS: DBG(softc->gp_dip, "ioctl: SET_BITS, byte is %x", byte, 0, 0, 0, 0); byte |= info.gpio_data; ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset], byte); byte = ddi_get8(softc->gp_handle, &softc->gp_regs[info.gpio_offset]); DBG(softc->gp_dip, "ioctl: SET_BITS, byte is %x", byte, 0, 0, 0, 0); break; case GPIO_CMD_CLR_BITS: DBG(softc->gp_dip, "ioctl: CLR_BITS, byte is %x", byte, 0, 0, 0, 0); byte &= ~info.gpio_data; ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset], byte); byte = ddi_get8(softc->gp_handle, &softc->gp_regs[info.gpio_offset]); DBG(softc->gp_dip, "ioctl: CLR_BITS, byte is %x", byte, 0, 0, 0, 0); break; case GPIO_CMD_GET: DBG(softc->gp_dip, "ioctl: GPIO_CMD_GET", 0, 0, 0, 0, 0); info.gpio_data = byte; if (ddi_copyout((caddr_t)&info, (caddr_t)arg, sizeof (gpio_87317_op_t), mode) != 0) { mutex_exit(&softc->gp_mutex); return (EFAULT); } break; case GPIO_CMD_SET: DBG(softc->gp_dip, "ioctl: GPIO_CMD_SET", 0, 0, 0, 0, 0); ddi_put8(softc->gp_handle, &softc->gp_regs[info.gpio_offset], info.gpio_data); break; default: mutex_exit(&softc->gp_mutex); return (EINVAL); } mutex_exit(&softc->gp_mutex); return (0); }
static int gpio_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) { int instance; struct gpio_softc *softc = NULL; ddi_device_acc_attr_t dev_attr; switch (cmd) { case DDI_ATTACH: /* Allocate and get the soft state structure for this instance. */ instance = ddi_get_instance(dip); DBG(dip, "attach: instance is %d", instance, 0, 0, 0, 0); if (ddi_soft_state_zalloc(statep, instance) != DDI_SUCCESS) goto attach_failed; softc = getsoftc(instance); softc->gp_dip = dip; softc->gp_state = 0; mutex_init(&softc->gp_mutex, NULL, MUTEX_DRIVER, NULL); /* Map in the gpio device registers. */ dev_attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; dev_attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; dev_attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; if (ddi_regs_map_setup(dip, 0, (caddr_t *)&softc->gp_regs, 0, 0, &dev_attr, &softc->gp_handle) != DDI_SUCCESS) goto attach_failed; DBG(dip, "attach: regs=0x%p", (uintptr_t)softc->gp_regs, 0, 0, 0, 0); DBG(dip, "attach: port 1 data is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[0]), 0, 0, 0, 0); DBG(dip, "attach: port 1 direction is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[1]), 0, 0, 0, 0); DBG(dip, "attach: port 1 output type is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[2]), 0, 0, 0, 0); DBG(dip, "attach: port 1 pull up control type is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[3]), 0, 0, 0, 0); DBG(dip, "attach: port 2 data is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[4]), 0, 0, 0, 0); DBG(dip, "attach: port 2 direction is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[5]), 0, 0, 0, 0); DBG(dip, "attach: port 2 output type is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[6]), 0, 0, 0, 0); DBG(dip, "attach: port 2 pull up control type is %x", (uintptr_t)ddi_get8(softc->gp_handle, &softc->gp_regs[7]), 0, 0, 0, 0); /* Create device minor nodes. */ if (ddi_create_minor_node(dip, "gpio", S_IFCHR, instance, NULL, NULL) == DDI_FAILURE) { ddi_regs_map_free(&softc->gp_handle); goto attach_failed; } ddi_report_dev(dip); return (DDI_SUCCESS); case DDI_RESUME: /* Nothing to do for a resume. */ return (DDI_SUCCESS); default: return (DDI_FAILURE); } attach_failed: if (softc) { mutex_destroy(&softc->gp_mutex); if (softc->gp_handle) ddi_regs_map_free(&softc->gp_handle); ddi_soft_state_free(statep, instance); ddi_remove_minor_node(dip, NULL); } return (DDI_FAILURE); }