static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) { struct iforce *iforce; int err; iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL); if (!iforce) return -ENOMEM; iforce->bus = IFORCE_232; iforce->serio = serio; serio_set_drvdata(serio, iforce); err = serio_open(serio, drv); if (err) { serio_set_drvdata(serio, NULL); kfree(iforce); return err; } err = iforce_init_device(iforce); if (err) { serio_close(serio); serio_set_drvdata(serio, NULL); kfree(iforce); return -ENODEV; } return 0; }
static int dock_keyboard_serio_connect(struct serio *serio, struct serio_driver *drv) { int ret; struct dock_keyboard_data *data; pr_debug("kbd: serio_connect\n"); data = sec_dock_kbd_driver.private_data; data->serio = serio; serio_set_drvdata(serio, data); ret = serio_open(serio, drv); if (unlikely(ret)) { pr_err("kbd: failed to open serio!\n"); goto err_open_serio; } if (unlikely(!sec_dock_kbd_driver.private_data)) { pr_err("kbd: failed to get platform device data!\n"); ret = -ENODEV; goto err_plat_dev; } return 0; err_plat_dev: err_open_serio: serio_set_drvdata(serio, NULL); return ret; }
static void tickHandler(int userVal, xPL_ObjectPtr obj) { static Bool firstTime = TRUE; /* Process clock tick update checking */ if(firstTime){ firstTime = FALSE; xPL_clearMessageNamedValues(xplEventTriggerMessage); xPL_addMessageNamedValue(xplEventTriggerMessage, "event", "ready"); xPL_sendMessage(xplEventTriggerMessage); } if(serialRetryTimer){ /* If this is non-zero, we lost the serial connection, wait retry time and try again */ serialRetryTimer--; if(!serialRetryTimer){ if(!(serioStuff = serio_open(comPort, COM_BAUD_RATE))){ debug(DEBUG_UNEXPECTED,"Serial reconnect failed, trying later..."); serialRetryTimer = SERIAL_RETRY_TIME; return; } else{ debug(DEBUG_EXPECTED,"Serial reconnect successful"); if(!xPL_addIODevice(serioHandler, 1234, serio_fd(serioStuff), TRUE, FALSE, FALSE)) fatal("Could not register serial I/O fd with xPL"); } } } }
static int vsxxxaa_connect (struct serio *serio, struct serio_driver *drv) { struct vsxxxaa *mouse; struct input_dev *input_dev; int err = -ENOMEM; mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL); input_dev = input_allocate_device (); if (!mouse || !input_dev) goto fail1; mouse->dev = input_dev; mouse->serio = serio; strlcat (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", sizeof (mouse->name)); snprintf (mouse->phys, sizeof (mouse->phys), "%s/input0", serio->phys); input_dev->name = mouse->name; input_dev->phys = mouse->phys; input_dev->id.bustype = BUS_RS232; input_dev->dev.parent = &serio->dev; set_bit (EV_KEY, input_dev->evbit); /* We have buttons */ set_bit (EV_REL, input_dev->evbit); set_bit (EV_ABS, input_dev->evbit); set_bit (BTN_LEFT, input_dev->keybit); /* We have 3 buttons */ set_bit (BTN_MIDDLE, input_dev->keybit); set_bit (BTN_RIGHT, input_dev->keybit); set_bit (BTN_TOUCH, input_dev->keybit); /* ...and Tablet */ set_bit (REL_X, input_dev->relbit); set_bit (REL_Y, input_dev->relbit); input_set_abs_params (input_dev, ABS_X, 0, 1023, 0, 0); input_set_abs_params (input_dev, ABS_Y, 0, 1023, 0, 0); serio_set_drvdata (serio, mouse); err = serio_open (serio, drv); if (err) goto fail2; /* * Request selftest. Standard packet format and differential * mode will be requested after the device ID'ed successfully. */ serio->write (serio, 'T'); /* Test */ err = input_register_device (input_dev); if (err) goto fail3; return 0; fail3: serio_close (serio); fail2: serio_set_drvdata (serio, NULL); fail1: input_free_device (input_dev); kfree (mouse); return err; }
/*----------------------------------------------------------------------- Given a baud rate and port number, configure the serial system. Multiple calls with the same args are allowed, and are harmless. portname = "com1", "com2", etc. baud = 19200, 38400, 57600? -----------------------------------------------------------------------*/ ser_result_t ser_config(ser_t *ser, long baud, const char * szPort) { serio_res_t err; err = serio_open(&ser->serio, baud, szPort); if (err == serio_RES_OK) return ser_RES_OK; DPRINT(("ser_config: error in serio_open %d\n", err)); return CONVERT_ERR(err); }
static int skbd_connect(struct serio *serio, struct serio_driver *drv) { struct skbd *skbd; struct input_dev *input_dev; int err = -ENOMEM; int i; skbd = kzalloc(sizeof(struct skbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!skbd || !input_dev) goto fail1; skbd->serio = serio; skbd->dev = input_dev; snprintf(skbd->phys, sizeof(skbd->phys), "%s/input0", serio->phys); memcpy(skbd->keycode, skbd_keycode, sizeof(skbd->keycode)); input_dev->name = "Stowaway Keyboard"; input_dev->phys = skbd->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_STOWAWAY; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); input_dev->keycode = skbd->keycode; input_dev->keycodesize = sizeof(unsigned char); input_dev->keycodemax = ARRAY_SIZE(skbd_keycode); for (i = 0; i < ARRAY_SIZE(skbd_keycode); i++) set_bit(skbd_keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); serio_set_drvdata(serio, skbd); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(skbd->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(skbd); return err; }
static int tsc_connect(struct serio *serio, struct serio_driver *drv) { struct tsc_ser *ptsc; struct input_dev *input_dev; int error; ptsc = kzalloc(sizeof(struct tsc_ser), GFP_KERNEL); input_dev = input_allocate_device(); if (!ptsc || !input_dev) { error = -ENOMEM; goto fail1; } ptsc->serio = serio; ptsc->dev = input_dev; snprintf(ptsc->phys, sizeof(ptsc->phys), "%s/input0", serio->phys); input_dev->name = "TSC-10/25/40 Serial TouchScreen"; input_dev->phys = ptsc->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_TSC40; input_dev->id.product = 40; input_dev->id.version = 0x0001; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); __set_bit(BTN_TOUCH, input_dev->keybit); input_set_abs_params(ptsc->dev, ABS_X, 0, 0x3ff, 0, 0); input_set_abs_params(ptsc->dev, ABS_Y, 0, 0x3ff, 0, 0); input_set_abs_params(ptsc->dev, ABS_PRESSURE, 0, 0, 0, 0); serio_set_drvdata(serio, ptsc); error = serio_open(serio, drv); if (error) goto fail2; error = input_register_device(ptsc->dev); if (error) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(ptsc); return error; }
static int sec_keyboard_connect(struct serio *serio, struct serio_driver *drv) { struct sec_keyboard_drvdata *data = container_of(drv, struct sec_keyboard_drvdata, serio_driver); printk(KERN_DEBUG "[Keyboard] %s", __func__); data->serio = serio; serio_set_drvdata(serio, data); if (serio_open(serio, drv)) printk(KERN_ERR "[Keyboard] failed to open serial port\n"); else data->tx_ready = true; return 0; }
static int rain_connect(struct serio *serio, struct serio_driver *drv) { u32 caps = CEC_CAP_DEFAULTS | CEC_CAP_PHYS_ADDR | CEC_CAP_MONITOR_ALL; struct rain *rain; int err = -ENOMEM; struct cec_log_addrs log_addrs = {}; u16 pa = CEC_PHYS_ADDR_INVALID; rain = kzalloc(sizeof(*rain), GFP_KERNEL); if (!rain) return -ENOMEM; rain->serio = serio; rain->adap = cec_allocate_adapter(&rain_cec_adap_ops, rain, dev_name(&serio->dev), caps, 1); err = PTR_ERR_OR_ZERO(rain->adap); if (err < 0) goto free_device; rain->dev = &serio->dev; serio_set_drvdata(serio, rain); INIT_WORK(&rain->work, rain_irq_work_handler); mutex_init(&rain->write_lock); spin_lock_init(&rain->buf_lock); err = serio_open(serio, drv); if (err) goto delete_adap; err = rain_setup(rain, serio, &log_addrs, &pa); if (err) goto close_serio; err = cec_register_adapter(rain->adap, &serio->dev); if (err < 0) goto close_serio; rain->dev = &rain->adap->devnode.dev; return 0; close_serio: serio_close(serio); delete_adap: cec_delete_adapter(rain->adap); serio_set_drvdata(serio, NULL); free_device: kfree(rain); return err; }
static int hampshire_connect(struct serio *serio, struct serio_driver *drv) { struct hampshire *phampshire; struct input_dev *input_dev; int err; phampshire = kzalloc(sizeof(struct hampshire), GFP_KERNEL); input_dev = input_allocate_device(); if (!phampshire || !input_dev) { err = -ENOMEM; goto fail1; } phampshire->serio = serio; phampshire->dev = input_dev; snprintf(phampshire->phys, sizeof(phampshire->phys), "%s/input0", serio->phys); input_dev->name = "Hampshire Serial TouchScreen"; input_dev->phys = phampshire->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_HAMPSHIRE; input_dev->id.product = 0; input_dev->id.version = 0x0001; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(phampshire->dev, ABS_X, HAMPSHIRE_MIN_XC, HAMPSHIRE_MAX_XC, 0, 0); input_set_abs_params(phampshire->dev, ABS_Y, HAMPSHIRE_MIN_YC, HAMPSHIRE_MAX_YC, 0, 0); serio_set_drvdata(serio, phampshire); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(phampshire->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(phampshire); return err; }
/* * fujitsu_connect() is the routine that is called when someone adds a * new serio device that supports the Fujitsu protocol and registers it * as input device. */ static int fujitsu_connect(struct serio *serio, struct serio_driver *drv) { struct fujitsu *fujitsu; struct input_dev *input_dev; int err; fujitsu = kzalloc(sizeof(struct fujitsu), GFP_KERNEL); input_dev = input_allocate_device(); if (!fujitsu || !input_dev) { err = -ENOMEM; goto fail1; } fujitsu->serio = serio; fujitsu->dev = input_dev; snprintf(fujitsu->phys, sizeof(fujitsu->phys), "%s/input0", serio->phys); input_dev->name = "Fujitsu Serial Touchscreen"; input_dev->phys = fujitsu->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_FUJITSU; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(input_dev, ABS_X, 0, 4096, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, 4096, 0, 0); serio_set_drvdata(serio, fujitsu); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(fujitsu->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(fujitsu); return err; }
static int touchit213_connect(struct serio *serio, struct serio_driver *drv) { struct touchit213 *touchit213; struct input_dev *input_dev; int err; touchit213 = kzalloc(sizeof(struct touchit213), GFP_KERNEL); input_dev = input_allocate_device(); if (!touchit213 || !input_dev) { err = -ENOMEM; goto fail1; } touchit213->serio = serio; touchit213->dev = input_dev; snprintf(touchit213->phys, sizeof(touchit213->phys), "%s/input0", serio->phys); input_dev->name = "Sahara Touch-iT213 Serial TouchScreen"; input_dev->phys = touchit213->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_TOUCHIT213; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(touchit213->dev, ABS_X, T213_MIN_XC, T213_MAX_XC, 0, 0); input_set_abs_params(touchit213->dev, ABS_Y, T213_MIN_YC, T213_MAX_YC, 0, 0); serio_set_drvdata(serio, touchit213); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(touchit213->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(touchit213); return err; }
static int magellan_connect(struct serio *serio, struct serio_driver *drv) { struct magellan *magellan; struct input_dev *input_dev; int err = -ENOMEM; int i; magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL); input_dev = input_allocate_device(); if (!magellan || !input_dev) goto fail1; magellan->dev = input_dev; snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys); input_dev->name = "LogiCad3D Magellan / SpaceMouse"; input_dev->phys = magellan->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_MAGELLAN; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); for (i = 0; i < 9; i++) set_bit(magellan_buttons[i], input_dev->keybit); for (i = 0; i < 6; i++) input_set_abs_params(input_dev, magellan_axes[i], -360, 360, 0, 0); serio_set_drvdata(serio, magellan); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(magellan->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(magellan); return err; }
static int pm_connect(struct serio *serio, struct serio_driver *drv) { struct pm *pm; struct input_dev *input_dev; int err; pm = kzalloc(sizeof(struct pm), GFP_KERNEL); input_dev = input_allocate_device(); if (!pm || !input_dev) { err = -ENOMEM; goto fail1; } pm->serio = serio; pm->dev = input_dev; snprintf(pm->phys, sizeof(pm->phys), "%s/input0", serio->phys); input_dev->name = "Penmount Serial TouchScreen"; input_dev->phys = pm->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_PENMOUNT; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(pm->dev, ABS_X, 0, 0x3ff, 0, 0); input_set_abs_params(pm->dev, ABS_Y, 0, 0x3ff, 0, 0); serio_set_drvdata(serio, pm); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(pm->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(pm); return err; }
static int mtouch_connect(struct serio *serio, struct serio_driver *drv) { struct mtouch *mtouch; struct input_dev *input_dev; int err; mtouch = kzalloc(sizeof(struct mtouch), GFP_KERNEL); input_dev = input_allocate_device(); if (!mtouch || !input_dev) { err = -ENOMEM; goto fail1; } mtouch->serio = serio; mtouch->dev = input_dev; snprintf(mtouch->phys, sizeof(mtouch->phys), "%s/input0", serio->phys); input_dev->name = "MicroTouch Serial TouchScreen"; input_dev->phys = mtouch->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_MICROTOUCH; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(mtouch->dev, ABS_X, MTOUCH_MIN_XC, MTOUCH_MAX_XC, 0, 0); input_set_abs_params(mtouch->dev, ABS_Y, MTOUCH_MIN_YC, MTOUCH_MAX_YC, 0, 0); serio_set_drvdata(serio, mtouch); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(mtouch->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(mtouch); return err; }
static int gunze_connect(struct serio *serio, struct serio_driver *drv) { struct gunze *gunze; struct input_dev *input_dev; int err; gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL); input_dev = input_allocate_device(); if (!gunze || !input_dev) { err = -ENOMEM; goto fail1; } gunze->serio = serio; gunze->dev = input_dev; snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys); input_dev->name = "Gunze AHL-51S TouchScreen"; input_dev->phys = gunze->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_GUNZE; input_dev->id.product = 0x0051; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0); input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0); serio_set_drvdata(serio, gunze); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(gunze->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(gunze); return err; }
static int elo_connect(struct serio *serio, struct serio_driver *drv) { struct elo *elo; struct input_dev *input_dev; int err; elo = kzalloc(sizeof(struct elo), GFP_KERNEL); input_dev = input_allocate_device(); if (!elo || !input_dev) { err = -ENOMEM; goto fail1; } elo->serio = serio; elo->id = serio->id.id; elo->dev = input_dev; elo->expected_packet = ELO10_TOUCH_PACKET; mutex_init(&elo->cmd_mutex); init_completion(&elo->cmd_done); snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys); input_dev->name = "Elo Serial TouchScreen"; input_dev->phys = elo->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_ELO; input_dev->id.product = elo->id; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); serio_set_drvdata(serio, elo); err = serio_open(serio, drv); if (err) goto fail2; switch (elo->id) { case 0: /* 10-byte protocol */ if (elo_setup_10(elo)) goto fail3; break; case 1: /* 6-byte protocol */ input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0); case 2: /* 4-byte protocol */ input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0); input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0); break; case 3: /* 3-byte protocol */ input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0); break; } err = input_register_device(elo->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(elo); return err; }
static int hil_dev_connect(struct serio *serio, struct serio_driver *drv) { struct hil_dev *dev; struct input_dev *input_dev; uint8_t did, *idd; int error; dev = kzalloc(sizeof(*dev), GFP_KERNEL); input_dev = input_allocate_device(); if (!dev || !input_dev) { error = -ENOMEM; goto bail0; } dev->serio = serio; dev->dev = input_dev; error = serio_open(serio, drv); if (error) goto bail0; serio_set_drvdata(serio, dev); /* Get device info. MLC driver supplies devid/status/etc. */ init_completion(&dev->cmd_done); serio_write(serio, 0); serio_write(serio, 0); serio_write(serio, HIL_PKT_CMD >> 8); serio_write(serio, HIL_CMD_IDD); error = wait_for_completion_killable(&dev->cmd_done); if (error) goto bail1; init_completion(&dev->cmd_done); serio_write(serio, 0); serio_write(serio, 0); serio_write(serio, HIL_PKT_CMD >> 8); serio_write(serio, HIL_CMD_RSC); error = wait_for_completion_killable(&dev->cmd_done); if (error) goto bail1; init_completion(&dev->cmd_done); serio_write(serio, 0); serio_write(serio, 0); serio_write(serio, HIL_PKT_CMD >> 8); serio_write(serio, HIL_CMD_RNM); error = wait_for_completion_killable(&dev->cmd_done); if (error) goto bail1; init_completion(&dev->cmd_done); serio_write(serio, 0); serio_write(serio, 0); serio_write(serio, HIL_PKT_CMD >> 8); serio_write(serio, HIL_CMD_EXD); error = wait_for_completion_killable(&dev->cmd_done); if (error) goto bail1; did = dev->idd[0]; idd = dev->idd + 1; switch (did & HIL_IDD_DID_TYPE_MASK) { case HIL_IDD_DID_TYPE_KB_INTEGRAL: case HIL_IDD_DID_TYPE_KB_ITF: case HIL_IDD_DID_TYPE_KB_RSVD: case HIL_IDD_DID_TYPE_CHAR: if (HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) { printk(KERN_INFO PREFIX "combo devices are not supported.\n"); goto bail1; } dev->is_pointer = false; hil_dev_keyboard_setup(dev); break; case HIL_IDD_DID_TYPE_REL: case HIL_IDD_DID_TYPE_ABS: dev->is_pointer = true; hil_dev_pointer_setup(dev); break; default: goto bail1; } input_dev->id.bustype = BUS_HIL; input_dev->id.vendor = PCI_VENDOR_ID_HP; input_dev->id.product = 0x0001; /* TODO: get from kbd->rsc */ input_dev->id.version = 0x0100; /* TODO: get from kbd->rsc */ input_dev->dev.parent = &serio->dev; if (!dev->is_pointer) { serio_write(serio, 0); serio_write(serio, 0); serio_write(serio, HIL_PKT_CMD >> 8); /* Enable Keyswitch Autorepeat 1 */ serio_write(serio, HIL_CMD_EK1); /* No need to wait for completion */ }
/* * h3600ts_connect() is the routine that is called when someone adds a * new serio device that supports H3600 protocol and registers it as * an input device. */ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv) { struct h3600_dev *ts; struct input_dev *input_dev; int err; ts = kzalloc(sizeof(struct h3600_dev), GFP_KERNEL); input_dev = input_allocate_device(); if (!ts || !input_dev) { err = -ENOMEM; goto fail1; } ts->serio = serio; ts->dev = input_dev; snprintf(ts->phys, sizeof(ts->phys), "%s/input0", serio->phys); input_dev->name = "H3600 TouchScreen"; input_dev->phys = ts->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_H3600; input_dev->id.product = 0x0666; /* FIXME !!! We can ask the hardware */ input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_set_drvdata(input_dev, ts); input_dev->event = h3600ts_event; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_LED) | BIT_MASK(EV_PWR); input_dev->ledbit[0] = BIT_MASK(LED_SLEEP); input_set_abs_params(input_dev, ABS_X, 60, 985, 0, 0); input_set_abs_params(input_dev, ABS_Y, 35, 1024, 0, 0); set_bit(KEY_RECORD, input_dev->keybit); set_bit(KEY_Q, input_dev->keybit); set_bit(KEY_PROG1, input_dev->keybit); set_bit(KEY_PROG2, input_dev->keybit); set_bit(KEY_PROG3, input_dev->keybit); set_bit(KEY_UP, input_dev->keybit); set_bit(KEY_RIGHT, input_dev->keybit); set_bit(KEY_LEFT, input_dev->keybit); set_bit(KEY_DOWN, input_dev->keybit); set_bit(KEY_ENTER, input_dev->keybit); set_bit(KEY_SUSPEND, input_dev->keybit); set_bit(BTN_TOUCH, input_dev->keybit); /* Device specific stuff */ set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE); if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler, IRQF_SHARED | IRQF_DISABLED, "h3600_action", &ts->dev)) { printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); err = -EBUSY; goto fail2; } if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, IRQF_SHARED | IRQF_DISABLED, "h3600_suspend", &ts->dev)) { printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n"); err = -EBUSY; goto fail3; } serio_set_drvdata(serio, ts); err = serio_open(serio, drv); if (err) return err; //h3600_flite_control(1, 25); /* default brightness */ input_register_device(ts->dev); return 0; fail3: free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev); fail2: free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev); fail1: serio_set_drvdata(serio, NULL); input_free_device(input_dev); kfree(ts); return err; }
static int spaceball_connect(struct serio *serio, struct serio_driver *drv) { struct spaceball *spaceball; struct input_dev *input_dev; int err = -ENOMEM; int i, id; if ((id = serio->id.id) > SPACEBALL_MAX_ID) return -ENODEV; spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL); input_dev = input_allocate_device(); if (!spaceball || !input_dev) goto fail1; spaceball->dev = input_dev; snprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys); input_dev->name = spaceball_names[id]; input_dev->phys = spaceball->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_SPACEBALL; input_dev->id.product = id; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); switch (id) { case SPACEBALL_4000FLX: case SPACEBALL_4000FLX_L: input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_9); input_dev->keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); default: input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); case SPACEBALL_3003C: input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); } for (i = 0; i < 3; i++) { input_set_abs_params(input_dev, ABS_X + i, -8000, 8000, 8, 40); input_set_abs_params(input_dev, ABS_RX + i, -1600, 1600, 2, 8); } serio_set_drvdata(serio, spaceball); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(spaceball->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(spaceball); return err; }
static int sunkbd_connect(struct serio *serio, struct serio_driver *drv) { struct sunkbd *sunkbd; struct input_dev *input_dev; int err = -ENOMEM; int i; sunkbd = kzalloc(sizeof(struct sunkbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!sunkbd || !input_dev) goto fail1; sunkbd->serio = serio; sunkbd->dev = input_dev; init_waitqueue_head(&sunkbd->wait); INIT_WORK(&sunkbd->tq, sunkbd_reinit); snprintf(sunkbd->phys, sizeof(sunkbd->phys), "%s/input0", serio->phys); serio_set_drvdata(serio, sunkbd); err = serio_open(serio, drv); if (err) goto fail2; if (sunkbd_initialize(sunkbd) < 0) { err = -ENODEV; goto fail3; } snprintf(sunkbd->name, sizeof(sunkbd->name), "Sun Type %d keyboard", sunkbd->type); memcpy(sunkbd->keycode, sunkbd_keycode, sizeof(sunkbd->keycode)); input_dev->name = sunkbd->name; input_dev->phys = sunkbd->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_SUNKBD; input_dev->id.product = sunkbd->type; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_set_drvdata(input_dev, sunkbd); input_dev->event = sunkbd_event; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_LED) | BIT_MASK(EV_SND) | BIT_MASK(EV_REP); input_dev->ledbit[0] = BIT_MASK(LED_CAPSL) | BIT_MASK(LED_COMPOSE) | BIT_MASK(LED_SCROLLL) | BIT_MASK(LED_NUML); input_dev->sndbit[0] = BIT_MASK(SND_CLICK) | BIT_MASK(SND_BELL); input_dev->keycode = sunkbd->keycode; input_dev->keycodesize = sizeof(unsigned char); input_dev->keycodemax = ARRAY_SIZE(sunkbd_keycode); for (i = 0; i < 128; i++) set_bit(sunkbd->keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); sunkbd_enable(sunkbd, 1); err = input_register_device(sunkbd->dev); if (err) goto fail4; return 0; fail4: sunkbd_enable(sunkbd, 0); fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(sunkbd); return err; }
static int pm_connect(struct serio *serio, struct serio_driver *drv) { struct pm *pm; struct input_dev *input_dev; int max_x, max_y; int err; pm = kzalloc(sizeof(struct pm), GFP_KERNEL); input_dev = input_allocate_device(); if (!pm || !input_dev) { err = -ENOMEM; goto fail1; } pm->serio = serio; pm->dev = input_dev; snprintf(pm->phys, sizeof(pm->phys), "%s/input0", serio->phys); pm->maxcontacts = 1; input_dev->name = "PenMount Serial TouchScreen"; input_dev->phys = pm->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_PENMOUNT; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); switch (serio->id.id) { default: case 0: pm->packetsize = 5; pm->parse_packet = pm_parse_9000; input_dev->id.product = 0x9000; max_x = max_y = 0x3ff; break; case 1: pm->packetsize = 6; pm->parse_packet = pm_parse_6000; input_dev->id.product = 0x6000; max_x = max_y = 0x3ff; break; case 2: pm->packetsize = 6; pm->parse_packet = pm_parse_3000; input_dev->id.product = 0x3000; max_x = max_y = 0x7ff; pm->maxcontacts = PM_3000_MTSLOT; break; case 3: pm->packetsize = 6; pm->parse_packet = pm_parse_6250; input_dev->id.product = 0x6250; max_x = max_y = 0x3ff; pm->maxcontacts = PM_6250_MTSLOT; break; } input_set_abs_params(pm->dev, ABS_X, 0, max_x, 0, 0); input_set_abs_params(pm->dev, ABS_Y, 0, max_y, 0, 0); if (pm->maxcontacts > 1) { input_mt_init_slots(pm->dev, pm->maxcontacts); input_set_abs_params(pm->dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); input_set_abs_params(pm->dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0); } serio_set_drvdata(serio, pm); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(pm->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(pm); return err; }
int main(int argc, char *argv[]) { char optchar; int longindex, i,res, crcerr; u8 writecmd; u32 bufbytepos; u8 *buffer,*lastrow; u16 wordaddr; u16 rowsexceptlast, toprow; u16 crc16; u16 load_size, load_size_bytes, load_address; u16 bootloader_size; u32 max_app_size; u32 bytes_received, bytes_sent; ihx_t *ihx; response_t *r; config_area_t *cf; serioStuff *s; dictionary *dict = NULL; static char exten[20]; char *q; /* Die if packet structures screwed up */ assert(sizeof(packet_t) == PACKET_SIZE); progname = argv[0]; // Argument pre scan for config file name change first while((optchar=getopt_long(argc, argv, SHORT_OPTIONS, long_options, &longindex)) != EOF) { //Handle each argument. switch(optchar) { // Was it a long option? case 0: // Hrmm, something we don't know about? fatal("Unhandled long getopt option '%s'", long_options[longindex].name); // If it was an error, exit right here. case '?': exit(1); // Was it a config file name? case 'z': memset(config_file, 0, MAX_PATH); strncpy(config_file, optarg, MAX_PATH); flags.configfileoverride = 1; break; default: // Don't care about the rest of the args right now break; } } optind = 1; // Reset option index for second scan later if((dict = iniparser_load(config_file))){ char *s; s = iniparser_getstring(dict, "general:file", NULL); if(s) strncpy(file, s, MAX_PATH - 1); s = iniparser_getstring(dict, "general:port", NULL); if(s) strncpy(port, s, MAX_PATH - 1); s = iniparser_getstring(dict, "general:han-host",NULL); if(s) strncpy(host, s, MAX_PATH - 1); s = iniparser_getstring(dict, "general:han-service",NULL); if(s) strncpy(service, s, MAX_PATH - 1); s = iniparser_getstring(dict, "general:product-id", NULL); if(s){ if(sscanf(s, "%X", &i) != 1) fatal("In pcl.conf, product ID needs to be a hexadecimal value"); productid = (u16) i; } iniparser_freedict(dict); } else if(flags.configfileoverride){ fatal("Cannot open config file: %s\n", config_file); } /* Parse the arguments. */ while((optchar=getopt_long(argc, argv, SHORT_OPTIONS, long_options, &longindex)) != EOF) { /* Handle each argument. */ switch(optchar) { /* Was it a long option? */ case 0: /* Hrmm, something we don't know about? */ fatal("Unhandled long getopt option '%s'", long_options[longindex].name); /* If it was an error, exit right here. */ case '?': exit(1); /* Was it han node address request? */ case 'a': if(sscanf(optarg, "%hx", &hannodeaddr) != 1) fatal("Invalid node address"); if(hannodeaddr > 32) fatal("Node address out of range"); flags.hanmode = 1; break; /* Was it a check app request? */ case 'c': flags.checkapp = 1; break; /* Was it a debug level set? */ case 'd': /* Save the value. */ debuglvl=strtol(optarg, NULL, 10); if((debuglvl < 0 || debuglvl > DEBUG_MAX)) { fatal("Invalid debug level"); } break; case 'e': flags.eeprom = 1; break; /* Was it a file request? */ case 'f': memset(file, 0, MAX_PATH); strncpy(file, optarg, MAX_PATH); break; /* Was it a help request? */ case 'h': show_help(); exit(0); case 'i': flags.interrogateonly = 1; break; case 'o': if(sscanf(optarg, "%X", &i) != 1) fatal("Product ID needs hexadecimal value"); productid = (u16) i; break; /* Was it a port request? */ case 'p': memset(port, 0, MAX_PATH); strncpy(port, optarg, MAX_PATH); break; /* Was it a reset request */ case 'r': flags.reset = 1; break; /* Was it a verbose request? */ case 'v': flags.verbose = 1; break; case 'V': printf("PCL version %s\n", PCL_VERSION); exit(0); /* Was it Execute App ? */ case 'x': flags.execute = 1; break; case 'z': /* handled previously */ break; /* It was something weird.. */ default: panic("Unhandled getopt return value %c", optchar); } } /* If there were any extra arguments, we should complain. */ if(optind < argc) { fatal("Extra argument on commandline, '%s'", argv[optind]); } if(flags.eeprom && (flags.execute | flags.checkapp)) fatal("-e is not valid with -x or -c"); if(!(flags.interrogateonly | flags.execute | flags.checkapp | flags.eeprom)) fatal("What do you want me to do, anyhow? Must specify -e, -c, -i, or -x"); r = (response_t *) ((flags.hanmode) ? packet.han.payload : packet.pbl.payload); cf = (config_area_t *) r->config; // Send a query packet packet_init(); if(flags.hanmode){ // If HAN address specified res = hanclient_connect_setup("","", service, host); if(!res){ // if connect setup OK printf("Test for hand running\n"); client_command.request = HAN_CCMD_DAEMON_INFO; res = hanclient_send_command_return_res(&client_command); printf("Hand %s running\n", (res) ? "is not" : "is"); if(!res){ // If hand is loaded, send boot loader entry command debug(DEBUG_EXPECTED,"Hand version: %s", client_command.cmd.info.version); // Check for structure size match between us and han daemon if(client_command.cmd.info.cmdpktsize != sizeof(struct han_packet)){ debug(DEBUG_UNEXPECTED, "Hand command structure incompatible"); fatal(not_comp); } if(client_command.cmd.info.rawsize != sizeof(struct han_raw)){ debug(DEBUG_UNEXPECTED, "Hand raw command structure incompatible"); fatal(not_comp); } flags.handisrunning = 1; // Set flag indicating comm is going to go through hand memset(&client_command,0,sizeof(Client_Command)); // Send boot loader entry command client_command.request = HAN_CCMD_SENDPKT; client_command.cmd.pkt.nodecommand = HAN_CMD_GEBL; client_command.cmd.pkt.numnodeparams = 2; client_command.cmd.pkt.nodeparams[0] = 0x55; client_command.cmd.pkt.nodeparams[1] = 0xAA; client_command.cmd.pkt.nodeaddress = hannodeaddr; printf("Sending boot loader entry request\n"); res = hanclient_send_command_return_res(&client_command); res = res | client_command.commstatus; printf("Boot loader %s entered via HAN command\n", (res) ? "not" : "was"); if(!res){ printf("Waiting for boot loader to initialize..."); fflush(stdout); usleep(3000000); // Wait for boot loader to activate printf("OK\n"); } } } // Set up packet parameters for addressable mode packet.han.param = 0x55AA; // Not required by protocol packet.han.pkttype = HDC; packet.han.addr = (u8) hannodeaddr; packet_size = sizeof(packet_t); } else{ // Non-addressable operating mode packet.pbl.param = 0x55AA; // Not required by protocol packet_size = sizeof(packet_t_pbl); } if(!flags.handisrunning){ // If not going through hand if(!port[0]) fatal("Missing port (-p) option on command line or config file"); if(!(s = serio_open(port, (flags.hanmode) ? 9600 : 57600))) fatal("Can't open serial port %s\n", port); serio_flush_input(s); packet_finalize(); debug(DEBUG_ACTION, "Transmit Packet CRC: 0x%04X", (flags.hanmode) ? packet.han.crc16 : packet.pbl.crc16); if((bytes_sent = packet_tx(s, packet.buffer, packet_size, 5000000)) < 0) fatal("Packet write error"); debug(DEBUG_ACTION, "Bytes Sent: %d", bytes_sent); if(bytes_sent != packet_size) fatal("Packet write incomplete"); packet_init(); // Just to be sure we get something // Wait for response bytes_received = packet_rx(s, packet.buffer, packet_size, 5000000); debug(DEBUG_ACTION, "Bytes Received: %d", bytes_received); if(bytes_received < 0) fatal("Packet read error"); if((bytes_received != packet_size)) // Must see a packet, not just an ACK fatal("Packet read incomplete, received %d bytes", bytes_received); if(packet_check()) fatal("Packet CRC error"); } else{ // Send packets through hand */ debug(DEBUG_ACTION,"Sending packets through hand"); packet_finalize(); debug(DEBUG_ACTION, "Transmit Packet CRC: 0x%04X", (flags.hanmode) ? packet.han.crc16 : packet.pbl.crc16); for(i = 0; i < PACKET_RETRIES; i++){ client_command.cmd.raw.txlen = packet_format(client_command.cmd.raw.txbuffer, &packet.han, packet_size); client_command.cmd.raw.rxexpectlen = 255; client_command.cmd.raw.txtimeout = 100000; client_command.cmd.raw.rxtimeout = 500000; client_command.request = HAN_CCMD_RAW_PACKET; res = hanclient_send_command_return_res(&client_command); if((!res) && (client_command.cmd.raw.rxexpectlen)) bytes_received = packet_unformat(packet.buffer, client_command.cmd.raw.rxbuffer, 255); else bytes_received = 0; if(bytes_received) crcerr = packet_check(); else crcerr = 0; if((bytes_received == packet_size) && (!crcerr)) // Must see a packet with a good CRC, not just an ACK break; debug(DEBUG_UNEXPECTED,"Query packet receive error, try = %d", i); debug(DEBUG_UNEXPECTED,"bytes_received = %d crcerr = %d", bytes_received, crcerr); } if(i == PACKET_RETRIES) fatal("Too many packet retries!"); } if(flags.verbose || flags.interrogateonly){ printf("Loader Size in Words: 0x%04X\n", r->lsize); printf("App. Size In Words : 0x%04X\n", r->appsize); printf("Product ID : 0x%04X\n", r->prodid); printf("Boot Program Version: 0x%02X\n", r->bootvers); printf("Protocol Number : 0x%02X\n", r->proto); printf("Device User 1 : 0x%04X\n", cf->user1); printf("Device User 2 : 0x%04X\n", cf->user2); printf("Device User 3 : 0x%04X\n", cf->user3); printf("Device User 4 : 0x%04X\n", cf->user4); printf("Device ID : 0x%04X\n", cf->deviceid); printf("Device Config 1 : 0x%04X\n", cf->config1); printf("Device Config 2 : 0x%04X\n", cf->config2); } if((flags.execute) && (!file[0])){ /* Special case for execute without load */ printf("Check App: "); if(send_command(s, BC_CHECK_APP, 0, NULL)){ printf("FAILED\n"); exit(1); } else printf("PASSED\n"); printf("Executing App... "); if(send_command(s, BC_EXEC_APP, 0, NULL)){ printf("FAILED\n"); exit(1); } printf("\n"); exit(0); } if(flags.interrogateonly) /* If interrogate only, exit now */ exit(0); if(r->prodid != productid) fatal("Wrong product ID: specified: %04X, device reports: %04X", productid, r->prodid); if(r->bootvers > BOOT_VERSION_SUPPORTED) fatal("Do not know how to deal with bootversion %d\n", r->bootvers); if(r->proto) fatal("Does not support protocol version %d\n", r->proto); max_app_size = r->appsize; bootloader_size = r->lsize; if(!file[0]) fatal("Missing file (-f) option on command line"); // Allocate buffer if(!(buffer = malloc(max_app_size << 1))) fatal("No memory for buffer"); if(!flags.eeprom){ /* Fill buffer with erase pattern */ for(i = 0 ; i < max_app_size << 1; i++) buffer[i] = (i & 1) ? 0x3F : 0xFF; } /* Locate the extension if it exists */ for(i = strlen(file), q = NULL; i >= 0 ; i--){ if(file[i] == '/'){ break; } if(file[i] == '.'){ q = file + i + 1; break; } } if(q) strncpy(exten, q, 18); if(!strcmp(exten, "hex")){ /* Hex files */ if(!(ihx = ihx_read( file, buffer, max_app_size << 1))) fatal("Could not open and/or read hex file"); load_address = ihx->load_address >> 1; load_size = ihx->size >> 1; load_size_bytes = ihx->size; ihx_free(ihx); } else if(!strcmp(exten, "bin")){
/* * lkkbd_connect() probes for a LK keyboard and fills the necessary structures. */ static int lkkbd_connect (struct serio *serio, struct serio_driver *drv) { struct lkkbd *lk; struct input_dev *input_dev; int i; int err; lk = kzalloc (sizeof (struct lkkbd), GFP_KERNEL); input_dev = input_allocate_device (); if (!lk || !input_dev) { err = -ENOMEM; goto fail1; } lk->serio = serio; lk->dev = input_dev; INIT_WORK (&lk->tq, lkkbd_reinit); lk->bell_volume = bell_volume; lk->keyclick_volume = keyclick_volume; lk->ctrlclick_volume = ctrlclick_volume; memcpy (lk->keycode, lkkbd_keycode, sizeof (lk_keycode_t) * LK_NUM_KEYCODES); strlcpy (lk->name, "DEC LK keyboard", sizeof(lk->name)); snprintf (lk->phys, sizeof(lk->phys), "%s/input0", serio->phys); input_dev->name = lk->name; input_dev->phys = lk->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_LKKBD; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->event = lkkbd_event; input_set_drvdata (input_dev, lk); set_bit (EV_KEY, input_dev->evbit); set_bit (EV_LED, input_dev->evbit); set_bit (EV_SND, input_dev->evbit); set_bit (EV_REP, input_dev->evbit); set_bit (LED_CAPSL, input_dev->ledbit); set_bit (LED_SLEEP, input_dev->ledbit); set_bit (LED_COMPOSE, input_dev->ledbit); set_bit (LED_SCROLLL, input_dev->ledbit); set_bit (SND_BELL, input_dev->sndbit); set_bit (SND_CLICK, input_dev->sndbit); input_dev->keycode = lk->keycode; input_dev->keycodesize = sizeof (lk_keycode_t); input_dev->keycodemax = LK_NUM_KEYCODES; for (i = 0; i < LK_NUM_KEYCODES; i++) set_bit (lk->keycode[i], input_dev->keybit); serio_set_drvdata (serio, lk); err = serio_open (serio, drv); if (err) goto fail2; err = input_register_device (lk->dev); if (err) goto fail3; lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET); return 0; fail3: serio_close (serio); fail2: serio_set_drvdata (serio, NULL); fail1: input_free_device (input_dev); kfree (lk); return err; }
int main(int argc, char *argv[]) { int longindex; int optchar; String p; KeyEntryPtr_t e; zoneMapPtr_t zm; /* Set the program name */ progName=argv[0]; /* Parse the arguments. */ while((optchar=getopt_long(argc, argv, SHORT_OPTIONS, longOptions, &longindex)) != EOF) { /* Handle each argument. */ switch(optchar) { /* Was it a long option? */ case 0: /* Hrmm, something we don't know about? */ fatal("Unhandled long getopt option '%s'", longOptions[longindex].name); /* If it was an error, exit right here. */ case '?': exit(1); /* Was it a config file path ? */ case 'c': confreadStringCopy(configFile, optarg, WS_SIZE - 1); debug(DEBUG_ACTION,"New config file path is: %s", configFile); break; /* Was it a debug level set? */ case 'd': /* Save the value. */ debugLvl=atoi(optarg); if(debugLvl < 0 || debugLvl > DEBUG_MAX) { fatal("Invalid debug level"); } break; /* Was it a pid file switch? */ case 'f': confreadStringCopy(pidFile, optarg, WS_SIZE - 1); debug(DEBUG_ACTION,"New pid file path is: %s", pidFile); configOverride |= CO_PID_FILE; break; /* Was it a help request? */ case 'h': showHelp(); exit(0); /* Specify interface to broadcast on */ case 'i': confreadStringCopy(interface, optarg, WS_SIZE -1); xPL_setBroadcastInterface(interface); configOverride |= CO_INTERFACE; break; case 'u': /* Override debug path*/ confreadStringCopy(debugFile, optarg, WS_SIZE - 1); debug(DEBUG_ACTION,"New debug path is: %s", debugFile); configOverride |= CO_DEBUG_FILE; break; /* Was it a no-backgrounding request? */ case 'n': /* Mark that we shouldn't background. */ noBackground = TRUE; break; case 'p': /* Override com port*/ confreadStringCopy(comPort, optarg, WS_SIZE - 1); debug(DEBUG_ACTION,"New com port is: %s", comPort); configOverride |= CO_COM_PORT; break; /* Was it an instance ID ? */ case 's': confreadStringCopy(instanceID, optarg, WS_SIZE); debug(DEBUG_ACTION,"New instance ID is: %s", instanceID); configOverride |= CO_INSTANCE_ID; break; /* Was it a version request? */ case 'v': printf("Version: %s\n", VERSION); exit(0); /* It was something weird.. */ default: fatal("Unhandled getopt return value %d", optchar); } } /* If there were any extra arguments, we should complain. */ if(optind < argc) { fatal("Extra argument on commandline, '%s'", argv[optind]); } /* Load the config file */ if(!(configEntry =confreadScan(configFile, NULL))) exit(1); /* Parse the general section */ /* Com port */ if(!(configOverride & CO_COM_PORT)){ if((p = confreadValueBySectKey(configEntry, "general", "com-port"))){ confreadStringCopy(comPort, p, WS_SIZE); } } /* Debug file */ if(!(configOverride & CO_DEBUG_FILE)){ if((p = confreadValueBySectKey(configEntry, "general", "debug-file"))){ confreadStringCopy(debugFile, p, WS_SIZE); } } /* PID file */ if(!(configOverride & CO_PID_FILE)){ if((p = confreadValueBySectKey(configEntry, "general", "pid-file"))){ confreadStringCopy(pidFile, p, WS_SIZE); } } /* Instance ID */ if(!(configOverride & CO_INSTANCE_ID)){ if((p = confreadValueBySectKey(configEntry, "general", "instance-id"))){ confreadStringCopy(instanceID, p, WS_SIZE); } } /* Interface */ if(!(configOverride & CO_INTERFACE)){ if((p = confreadValueBySectKey(configEntry, "general", "interface"))){ confreadStringCopy(interface, p, WS_SIZE); } } /* Build Zone Map */ if(!(e = confreadGetFirstKeyBySection(configEntry, "zone-map"))) fatal("A valid zone-map section and at least one entry must be defined in the config file"); for(; e; e = confreadGetNextKey(e)){ String plist[3]; const String key = confreadGetKey(e); const String value = confreadGetValue(e); /* Allocate a zone struct */ if(!(zm = mallocz(sizeof(zoneMap_t)))) MALLOC_ERROR; /* Get the zone number */ if(!str2uns(key, &zm->zone_num, 1, 99)) syntax_error(e, configFile,"invalid zone number"); /* Get the parameters */ if(3 != splitString(value, plist, ',', 3)) syntax_error(e, configFile, "3 parameters required"); if(!(zm->zone_name = strdup(plist[0]))) MALLOC_ERROR; if(!(zm->zone_type = strdup(plist[1]))) MALLOC_ERROR; if(!(zm->alarm_type = strdup(plist[2]))) MALLOC_ERROR; /* Hash the zone name */ zm->zone_name_hash = confreadHash(zm->zone_name); /* Free the split string */ free(plist[0]); /* Insert the entry into the zone list */ if(!zoneMapHead) zoneMapHead = zoneMapTail = zm; else{ zm->prev = zoneMapTail; zoneMapTail->next = zm; zoneMapTail = zm; } zoneCount++; } /* EXP zone mapping */ for(e = confreadGetFirstKeyBySection(configEntry, "exp-map"); e; e = confreadGetNextKey(e)){ expMapPtr_t emp; const String keyString = confreadGetKey(e); const String zone = confreadGetValue(e); String plist[3]; unsigned expaddr, expchannel; /* Check the key and zone strings */ if(!(keyString) || (!zone)) syntax_error(e, configFile, "key or zone missing"); /* Split the address and channel */ plist[0] = NULL; if(2 != splitString(keyString, plist, ',', 2)) syntax_error(e, configFile, "left hand side needs 2 numbers separated by a comma"); /* Convert and check address */ if(!str2uns(plist[0], &expaddr, 1, 99)) syntax_error(e, configFile,"address is limited from 1 - 99"); /* Convert and check channel */ if(!str2uns(plist[1], &expchannel, 1, 99)) syntax_error(e, configFile,"channel is limited from 1 - 99"); /* debug(DEBUG_ACTION, "Address: %u, channel: %u, zone: %s", expaddr, expchannel, zone); */ /* Look up zone to ensure it is defined */ if(!(zm = zoneLookup(zone))) syntax_error(e, configFile, "Zone must be defined in zone-map section"); /* Get memory for entry */ if(!(emp = mallocz(sizeof(expMap_t)))) MALLOC_ERROR; /* Initialize entry */ emp->zone_entry = zm; emp->addr = expaddr; emp->channel = expchannel; if(!(emp->zone = strdup(zone))) MALLOC_ERROR; /* Insert into list */ if(!expMapHead){ expMapHead = expMapTail = emp; } else{ expMapTail->next = emp; emp->prev = expMapTail; expMapTail = emp; } /* Free parameter string */ if(plist[0]) free(plist[0]); } /* Turn on library debugging for level 5 */ if(debugLvl >= 5) xPL_setDebugging(TRUE); /* Make sure we are not already running (.pid file check). */ if(pid_read(pidFile) != -1) { fatal("%s is already running", progName); } /* Check to see the serial device exists before we fork */ if(!serio_check_node(comPort)) fatal("Serial device %s does not exist or its permissions are not allowing it to be used.", comPort); /* Fork into the background. */ if(!noBackground) { int retval; debug(DEBUG_STATUS, "Forking into background"); /* * If debugging is enabled, and we are daemonized, redirect the debug output to a log file if * the path to the logfile is defined */ if((debugLvl) && (debugFile[0])) notify_logpath(debugFile); /* Fork and exit the parent */ if((retval = fork())){ if(retval > 0) exit(0); /* Exit parent */ else fatal_with_reason(errno, "parent fork"); } /* * The child creates a new session leader * This divorces us from the controlling TTY */ if(setsid() == -1) fatal_with_reason(errno, "creating session leader with setsid"); /* * Fork and exit the session leader, this prohibits * reattachment of a controlling TTY. */ if((retval = fork())){ if(retval > 0) exit(0); /* exit session leader */ else fatal_with_reason(errno, "session leader fork"); } /* * Change to the root of all file systems to * prevent mount/unmount problems. */ if(chdir("/")) fatal_with_reason(errno, "chdir to /"); /* set the desired umask bits */ umask(022); /* Close STDIN, STDOUT, and STDERR */ close(0); close(1); close(2); } /* Start xPL up */ if (!xPL_initialize(xPL_getParsedConnectionType())) { fatal("Unable to start xPL lib"); } /* Initialize xplrcs service */ /* Create a service and set our application version */ xplService = xPL_createService("hwstar", "xplademco", instanceID); xPL_setServiceVersion(xplService, VERSION); /* * Create a status message object */ xplStatusMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_STATUS); /* * Create trigger message objects */ /* security.gateway */ if(!(xplEventTriggerMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_TRIGGER))) fatal("Could not initialize security.gateway trigger"); xPL_setSchema(xplEventTriggerMessage, "security", "gateway"); /* security.zone */ if(!(xplZoneTriggerMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_TRIGGER))) fatal("Could not initialize security.zone trigger"); xPL_setSchema(xplZoneTriggerMessage, "security", "zone"); /* Install signal traps for proper shutdown */ signal(SIGTERM, shutdownHandler); signal(SIGINT, shutdownHandler); /* Initialize the COM port */ if(!(serioStuff = serio_open(comPort, COM_BAUD_RATE))) fatal("Could not open com port: %s", comPort); /* Flush any partial commands */ serio_printf(serioStuff, "\r"); usleep(100000); serio_flush_input(serioStuff); /* Ask xPL to monitor our serial device */ if(xPL_addIODevice(serioHandler, 1234, serio_fd(serioStuff), TRUE, FALSE, FALSE) == FALSE) fatal("Could not register serial I/O fd with xPL"); /* Add 1 second tick service */ xPL_addTimeoutHandler(tickHandler, 1, NULL); /* And a listener for all xPL messages */ xPL_addMessageListener(xPLListener, NULL); /* Enable the service */ xPL_setServiceEnabled(xplService, TRUE); /* Update pid file */ if(pid_write(pidFile, getpid()) != 0) { debug(DEBUG_UNEXPECTED, "Could not write pid file '%s'.", pidFile); } /** Main Loop **/ for (;;) { /* Let XPL run forever */ xPL_processMessages(-1); } exit(1); }
static int taos_connect(struct serio *serio, struct serio_driver *drv) { struct taos_data *taos; struct i2c_adapter *adapter; char *name; int err; taos = kzalloc(sizeof(struct taos_data), GFP_KERNEL); if (!taos) { err = -ENOMEM; goto exit; } taos->state = TAOS_STATE_INIT; serio_set_drvdata(serio, taos); err = serio_open(serio, drv); if (err) goto exit_kfree; adapter = &taos->adapter; adapter->owner = THIS_MODULE; adapter->algo = &taos_algorithm; adapter->algo_data = serio; adapter->dev.parent = &serio->dev; /* Reset the TAOS evaluation module to identify it */ serio_write(serio, TAOS_CMD_RESET); wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, msecs_to_jiffies(2000)); if (taos->state != TAOS_STATE_IDLE) { err = -ENODEV; dev_dbg(&serio->dev, "TAOS EVM reset failed (state=%d, " "pos=%d)\n", taos->state, taos->pos); goto exit_close; } name = taos_adapter_name(taos->buffer); if (!name) { err = -ENODEV; dev_err(&serio->dev, "TAOS EVM identification failed\n"); goto exit_close; } strlcpy(adapter->name, name, sizeof(adapter->name)); err = i2c_add_adapter(adapter); if (err) goto exit_close; dev_dbg(&serio->dev, "Connected to TAOS EVM\n"); taos->client = taos_instantiate_device(adapter); return 0; exit_close: serio_close(serio); exit_kfree: serio_set_drvdata(serio, NULL); kfree(taos); exit: return err; }