static int __devinit adp5520_keys_probe(struct platform_device *pdev) { struct adp5520_keys_platform_data *pdata = pdev->dev.platform_data; struct input_dev *input; struct adp5520_keys *dev; int ret, i; unsigned char en_mask, ctl_mask = 0; if (pdev->id != ID_ADP5520) { dev_err(&pdev->dev, "only ADP5520 supports Keypad\n"); return -EINVAL; } if (pdata == NULL) { dev_err(&pdev->dev, "missing platform data\n"); return -EINVAL; } if (!(pdata->rows_en_mask && pdata->cols_en_mask)) return -EINVAL; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; } input = input_allocate_device(); if (!input) { ret = -ENOMEM; goto err; } dev->master = pdev->dev.parent; dev->input = input; input->name = pdev->name; input->phys = "adp5520-keys/input0"; input->dev.parent = &pdev->dev; input_set_drvdata(input, dev); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x5520; input->id.version = 0x0001; input->keycodesize = sizeof(dev->keycode[0]); input->keycodemax = pdata->keymapsize; input->keycode = dev->keycode; memcpy(dev->keycode, pdata->keymap, pdata->keymapsize * input->keycodesize); __set_bit(EV_KEY, input->evbit); if (pdata->repeat) __set_bit(EV_REP, input->evbit); for (i = 0; i < input->keycodemax; i++) __set_bit(dev->keycode[i], input->keybit); __clear_bit(KEY_RESERVED, input->keybit); ret = input_register_device(input); if (ret) { dev_err(&pdev->dev, "unable to register input device\n"); goto err; } en_mask = pdata->rows_en_mask | pdata->cols_en_mask; ret = adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_1, en_mask); if (en_mask & ADP5520_COL_C3) ctl_mask |= ADP5520_C3_MODE; if (en_mask & ADP5520_ROW_R3) ctl_mask |= ADP5520_R3_MODE; if (ctl_mask) ret |= adp5520_set_bits(dev->master, ADP5520_LED_CONTROL, ctl_mask); ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP, pdata->rows_en_mask); if (ret) { dev_err(&pdev->dev, "failed to write\n"); ret = -EIO; goto err1; } dev->notifier.notifier_call = adp5520_keys_notifier; ret = adp5520_register_notifier(dev->master, &dev->notifier, ADP5520_KP_IEN | ADP5520_KR_IEN); if (ret) { dev_err(&pdev->dev, "failed to register notifier\n"); goto err1; } platform_set_drvdata(pdev, dev); return 0; err1: input_unregister_device(input); input = NULL; err: input_free_device(input); kfree(dev); return ret; }
static int imx_keypad_probe(struct platform_device *pdev) { const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data; struct imx_keypad *keypad; struct input_dev *input_dev; struct resource *res; int irq, error, i, row, col; if (!keymap_data && !pdev->dev.of_node) { dev_err(&pdev->dev, "no keymap defined\n"); return -EINVAL; } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "no irq defined in platform data\n"); return -EINVAL; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "no I/O memory defined in platform data\n"); return -EINVAL; } input_dev = devm_input_allocate_device(&pdev->dev); if (!input_dev) { dev_err(&pdev->dev, "failed to allocate the input device\n"); return -ENOMEM; } keypad = devm_kzalloc(&pdev->dev, sizeof(struct imx_keypad), GFP_KERNEL); if (!keypad) { dev_err(&pdev->dev, "not enough memory for driver data\n"); return -ENOMEM; } keypad->input_dev = input_dev; keypad->irq = irq; keypad->stable_count = 0; setup_timer(&keypad->check_matrix_timer, imx_keypad_check_for_events, (unsigned long) keypad); keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(keypad->mmio_base)) return PTR_ERR(keypad->mmio_base); keypad->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(keypad->clk)) { dev_err(&pdev->dev, "failed to get keypad clock\n"); return PTR_ERR(keypad->clk); } /* Init the Input device */ input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; input_dev->dev.parent = &pdev->dev; input_dev->open = imx_keypad_open; input_dev->close = imx_keypad_close; error = matrix_keypad_build_keymap(keymap_data, NULL, MAX_MATRIX_KEY_ROWS, MAX_MATRIX_KEY_COLS, keypad->keycodes, input_dev); if (error) { dev_err(&pdev->dev, "failed to build keymap\n"); return error; } /* Search for rows and cols enabled */ for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) { for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) { i = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT); if (keypad->keycodes[i] != KEY_RESERVED) { keypad->rows_en_mask |= 1 << row; keypad->cols_en_mask |= 1 << col; } } } dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_set_drvdata(input_dev, keypad); /* Ensure that the keypad will stay dormant until opened */ clk_prepare_enable(keypad->clk); imx_keypad_inhibit(keypad); clk_disable_unprepare(keypad->clk); error = devm_request_irq(&pdev->dev, irq, imx_keypad_irq_handler, 0, pdev->name, keypad); if (error) { dev_err(&pdev->dev, "failed to request IRQ\n"); return error; } /* Register the input device */ error = input_register_device(input_dev); if (error) { dev_err(&pdev->dev, "failed to register input device\n"); return error; } platform_set_drvdata(pdev, keypad); device_init_wakeup(&pdev->dev, 1); return 0; }
static int pxa930_rotary_probe(struct platform_device *pdev) { struct pxa930_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev); struct pxa930_rotary *r; struct input_dev *input_dev; struct resource *res; int irq; int err; irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "no irq for rotary controller\n"); return -ENXIO; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "no I/O memory defined\n"); return -ENXIO; } if (!pdata) { dev_err(&pdev->dev, "no platform data defined\n"); return -EINVAL; } r = kzalloc(sizeof(struct pxa930_rotary), GFP_KERNEL); if (!r) return -ENOMEM; r->mmio_base = ioremap_nocache(res->start, resource_size(res)); if (r->mmio_base == NULL) { dev_err(&pdev->dev, "failed to remap IO memory\n"); err = -ENXIO; goto failed_free; } r->pdata = pdata; platform_set_drvdata(pdev, r); /* allocate and register the input device */ input_dev = input_allocate_device(); if (!input_dev) { dev_err(&pdev->dev, "failed to allocate input device\n"); err = -ENOMEM; goto failed_free_io; } input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; input_dev->open = pxa930_rotary_open; input_dev->close = pxa930_rotary_close; input_dev->dev.parent = &pdev->dev; if (pdata->up_key && pdata->down_key) { __set_bit(pdata->up_key, input_dev->keybit); __set_bit(pdata->down_key, input_dev->keybit); __set_bit(EV_KEY, input_dev->evbit); } else { __set_bit(pdata->rel_code, input_dev->relbit); __set_bit(EV_REL, input_dev->evbit); } r->input_dev = input_dev; input_set_drvdata(input_dev, r); err = request_irq(irq, rotary_irq, 0, "enhanced rotary", r); if (err) { dev_err(&pdev->dev, "failed to request IRQ\n"); goto failed_free_input; } err = input_register_device(input_dev); if (err) { dev_err(&pdev->dev, "failed to register input device\n"); goto failed_free_irq; } return 0; failed_free_irq: free_irq(irq, r); failed_free_input: input_free_device(input_dev); failed_free_io: iounmap(r->mmio_base); failed_free: kfree(r); return err; }
static int sirfsoc_pwrc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct sirfsoc_pwrc_drvdata *pwrcdrv; int irq; int error; pwrcdrv = devm_kzalloc(&pdev->dev, sizeof(struct sirfsoc_pwrc_drvdata), GFP_KERNEL); if (!pwrcdrv) { dev_info(&pdev->dev, "Not enough memory for the device data\n"); return -ENOMEM; } /* * We can't use of_iomap because pwrc is not mapped in memory, * the so-called base address is only offset in rtciobrg */ error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base); if (error) { dev_err(&pdev->dev, "unable to find base address of pwrc node in dtb\n"); return error; } pwrcdrv->input = devm_input_allocate_device(&pdev->dev); if (!pwrcdrv->input) return -ENOMEM; pwrcdrv->input->name = "sirfsoc pwrckey"; pwrcdrv->input->phys = "pwrc/input0"; pwrcdrv->input->evbit[0] = BIT_MASK(EV_KEY); input_set_capability(pwrcdrv->input, EV_KEY, KEY_POWER); INIT_DELAYED_WORK(&pwrcdrv->work, sirfsoc_pwrc_report_event); pwrcdrv->input->open = sirfsoc_pwrc_open; pwrcdrv->input->close = sirfsoc_pwrc_close; input_set_drvdata(pwrcdrv->input, pwrcdrv); /* Make sure the device is quiesced */ sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false); irq = platform_get_irq(pdev, 0); error = devm_request_irq(&pdev->dev, irq, sirfsoc_pwrc_isr, 0, "sirfsoc_pwrc_int", pwrcdrv); if (error) { dev_err(&pdev->dev, "unable to claim irq %d, error: %d\n", irq, error); return error; } error = input_register_device(pwrcdrv->input); if (error) { dev_err(&pdev->dev, "unable to register input device, error: %d\n", error); return error; } dev_set_drvdata(&pdev->dev, pwrcdrv); device_init_wakeup(&pdev->dev, 1); return 0; }
static int __devinit bh1721fvc_probe(struct i2c_client *client, const struct i2c_device_id *id) { int err = 0; struct bh1721fvc_data *bh1721fvc; struct input_dev *input_dev; struct bh1721fvc_platform_data *pdata = client->dev.platform_data; struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); printk(KERN_INFO "%s: start!\n", __func__); if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) return -EIO; bh1721fvc = kzalloc(sizeof(*bh1721fvc), GFP_KERNEL); if (!bh1721fvc) { pr_err("%s, failed to alloc memory for module data\n", __func__); return -ENOMEM; } #if defined(CONFIG_MACH_SAMSUNG_P5) bh1721fvc->output = pdata->output; #endif bh1721fvc->reset = pdata->reset; if (!bh1721fvc->reset) { pr_err("%s: reset callback is null\n", __func__); err = -EIO; goto err_reset_null; } err = bh1721fvc->reset(); if (err) { pr_err("%s: Failed to reset\n", __func__); goto err_reset_failed; } bh1721fvc->client = client; i2c_set_clientdata(client, bh1721fvc); mutex_init(&bh1721fvc->lock); bh1721fvc->state = POWER_DOWN; bh1721fvc->measure_mode = AUTO_MEASURE; err = bh1721fvc_test_luxvalue(bh1721fvc); if (err < 0) { pr_err("%s: No search bh1721fvc lightsensor!\n", __func__); goto err_test_lightsensor; } else printk(KERN_INFO "Lux : %d\n", err); hrtimer_init(&bh1721fvc->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); bh1721fvc->light_poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC); bh1721fvc->timer.function = bh1721fvc_timer_func; bh1721fvc->wq = alloc_workqueue("bh1721fvc_wq", WQ_UNBOUND | WQ_RESCUER, 1); if (!bh1721fvc->wq) { err = -ENOMEM; pr_err("%s: could not create workqueue\n", __func__); goto err_create_workqueue; } INIT_WORK(&bh1721fvc->work_light, bh1721fvc_work_func_light); input_dev = input_allocate_device(); if (!input_dev) { pr_err("%s: could not allocate input device\n", __func__); err = -ENOMEM; goto err_input_allocate_device_light; } input_set_drvdata(input_dev, bh1721fvc); input_dev->name = "light_sensor"; input_set_capability(input_dev, EV_REL, REL_MISC); bh1721fvc_dbmsg("registering lightsensor-level input device\n"); err = input_register_device(input_dev); if (err < 0) { pr_err("%s: could not register input device\n", __func__); input_free_device(input_dev); goto err_input_register_device_light; } bh1721fvc->input_dev = input_dev; err = sysfs_create_group(&input_dev->dev.kobj, &bh1721fvc_attribute_group); if (err) { pr_err("%s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_light; } bh1721fvc->factory_class = class_create(THIS_MODULE, "lightsensor"); if (IS_ERR(bh1721fvc->factory_class)) { pr_err("Failed to create class(lightsensor)!\n"); err = PTR_ERR(bh1721fvc->factory_class); goto err_factory_sysfs_create; } bh1721fvc->factory_dev = device_create(bh1721fvc->factory_class, NULL, 0, bh1721fvc, "switch_cmd"); if (IS_ERR(bh1721fvc->factory_dev)) { pr_err("Failed to create device(switch_cmd_dev)!\n"); err = PTR_ERR(bh1721fvc->factory_dev); goto err_factory_device_create; } err = device_create_file(bh1721fvc->factory_dev, &dev_attr_lightsensor_file_cmd); if (err < 0) { pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_cmd.attr.name); goto err_file_cmd_attr_create; } err = device_create_file(bh1721fvc->factory_dev, &dev_attr_lightsensor_file_illuminance); if (err < 0) { pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_illuminance.attr.name); goto err_illuminance_attr_create; } err = device_create_file(bh1721fvc->factory_dev, &dev_attr_sensor_info); if (err < 0) { pr_err("Failed to create device file(%s)!\n", dev_attr_sensor_info.attr.name); goto err_sensor_info_attr_create; } printk(KERN_INFO "%s: success!\n", __func__); goto done; err_sensor_info_attr_create: device_remove_file(bh1721fvc->factory_dev, &dev_attr_lightsensor_file_illuminance); err_illuminance_attr_create: device_remove_file(bh1721fvc->factory_dev, &dev_attr_lightsensor_file_cmd); err_file_cmd_attr_create: device_destroy(bh1721fvc->factory_class, 0); err_factory_device_create: class_destroy(bh1721fvc->factory_class); err_factory_sysfs_create: sysfs_remove_group(&bh1721fvc->input_dev->dev.kobj, &bh1721fvc_attribute_group); err_sysfs_create_group_light: input_unregister_device(bh1721fvc->input_dev); err_input_register_device_light: err_input_allocate_device_light: destroy_workqueue(bh1721fvc->wq); err_create_workqueue: err_test_lightsensor: mutex_destroy(&bh1721fvc->lock); err_reset_failed: err_reset_null: kfree(bh1721fvc); done: printk(KERN_INFO "%s: fail!\n", __func__); return err; }
static int __devinit msm_ts_probe(struct platform_device *pdev) { struct msm_ts_platform_data *pdata = pdev->dev.platform_data; struct msm_ts *ts; struct resource *tssc_res; struct resource *irq1_res; struct resource *irq2_res; int err = 0; int i; struct marimba_tsadc_client *ts_client; printk("%s\n", __func__); tssc_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tssc"); irq1_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tssc1"); irq2_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tssc2"); if (!tssc_res || !irq1_res || !irq2_res) { pr_err("%s: required resources not defined\n", __func__); return -ENODEV; } if (pdata == NULL) { pr_err("%s: missing platform_data\n", __func__); return -ENODEV; } ts = kzalloc(sizeof(struct msm_ts), GFP_KERNEL); if (ts == NULL) { pr_err("%s: No memory for struct msm_ts\n", __func__); return -ENOMEM; } ts->pdata = pdata; ts->dev = &pdev->dev; ts->sample_irq = irq1_res->start; ts->pen_up_irq = irq2_res->start; ts->tssc_base = ioremap(tssc_res->start, resource_size(tssc_res)); if (ts->tssc_base == NULL) { pr_err("%s: Can't ioremap region (0x%08x - 0x%08x)\n", __func__, (uint32_t)tssc_res->start, (uint32_t)tssc_res->end); err = -ENOMEM; goto err_ioremap_tssc; } ts_client = marimba_tsadc_register(pdev, 1); if (IS_ERR(ts_client)) { pr_err("%s: Unable to register with TSADC\n", __func__); err = -ENOMEM; goto err_tsadc_register; } ts->ts_client = ts_client; err = marimba_tsadc_start(ts_client); if (err) { pr_err("%s: Unable to start TSADC\n", __func__); err = -EINVAL; goto err_start_tsadc; } ts->input_dev = input_allocate_device(); if (ts->input_dev == NULL) { pr_err("failed to allocate touchscreen input device\n"); err = -ENOMEM; goto err_alloc_input_dev; } ts->input_dev->name = "msm-touchscreen"; ts->input_dev->dev.parent = &pdev->dev; input_set_drvdata(ts->input_dev, ts); input_set_capability(ts->input_dev, EV_KEY, BTN_TOUCH); set_bit(EV_ABS, ts->input_dev->evbit); input_set_abs_params(ts->input_dev, ABS_X, pdata->min_x, pdata->max_x, 0, 0); input_set_abs_params(ts->input_dev, ABS_Y, pdata->min_y, pdata->max_y, 0, 0); input_set_abs_params(ts->input_dev, ABS_PRESSURE, pdata->min_press, pdata->max_press, 0, 0); for (i = 0; pdata->vkeys_x && (i < pdata->vkeys_x->num_keys); ++i) input_set_capability(ts->input_dev, EV_KEY, pdata->vkeys_x->keys[i].key); for (i = 0; pdata->vkeys_y && (i < pdata->vkeys_y->num_keys); ++i) input_set_capability(ts->input_dev, EV_KEY, pdata->vkeys_y->keys[i].key); err = input_register_device(ts->input_dev); if (err != 0) { pr_err("%s: failed to register input device\n", __func__); goto err_input_dev_reg; } msm_ts_hw_init(ts); err = request_irq(ts->sample_irq, msm_ts_irq, (irq1_res->flags & ~IORESOURCE_IRQ) | IRQF_DISABLED, "msm_touchscreen", ts); if (err != 0) { pr_err("%s: Cannot register irq1 (%d)\n", __func__, err); goto err_request_irq1; } err = request_irq(ts->pen_up_irq, msm_ts_irq, (irq2_res->flags & ~IORESOURCE_IRQ) | IRQF_DISABLED, "msm_touchscreen", ts); if (err != 0) { pr_err("%s: Cannot register irq2 (%d)\n", __func__, err); goto err_request_irq2; } platform_set_drvdata(pdev, ts); #ifdef CONFIG_HAS_EARLYSUSPEND ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + TSSC_SUSPEND_LEVEL; ts->early_suspend.suspend = msm_ts_early_suspend; ts->early_suspend.resume = msm_ts_late_resume; register_early_suspend(&ts->early_suspend); #endif device_init_wakeup(&pdev->dev, pdata->can_wakeup); pr_info("%s: tssc_base=%p irq1=%d irq2=%d\n", __func__, ts->tssc_base, (int)ts->sample_irq, (int)ts->pen_up_irq); dump_tssc_regs(ts); return 0; err_request_irq2: free_irq(ts->sample_irq, ts); err_request_irq1: /* disable the tssc */ tssc_writel(ts, TSSC_CTL_ENABLE, TSSC_CTL); err_input_dev_reg: input_set_drvdata(ts->input_dev, NULL); input_free_device(ts->input_dev); err_alloc_input_dev: err_start_tsadc: marimba_tsadc_unregister(ts->ts_client); err_tsadc_register: iounmap(ts->tssc_base); err_ioremap_tssc: kfree(ts); return err; }
static int __devinit gpio_keys_probe(struct platform_device *pdev) { struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; struct gpio_keys_drvdata *ddata; struct device *dev = &pdev->dev; struct input_dev *input; int i, error; int wakeup = 0; gpiokey_workqueue = create_singlethread_workqueue("GpioKey_workqueue"); if ( !gpiokey_workqueue ){ dev_err(dev, "failed to allocate GpioKey_workqueue\n"); return -ENOMEM; } ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + pdata->nbuttons * sizeof(struct gpio_button_data), GFP_KERNEL); input = input_allocate_device(); if (!ddata || !input) { dev_err(dev, "failed to allocate state\n"); error = -ENOMEM; goto fail1; } ddata->input = input; ddata->n_buttons = pdata->nbuttons; ddata->enable = pdata->enable; ddata->disable = pdata->disable; mutex_init(&ddata->disable_lock); platform_set_drvdata(pdev, ddata); input_set_drvdata(input, ddata); input->name = pdev->name; input->phys = "gpio-keys/input0"; input->dev.parent = &pdev->dev; input->open = gpio_keys_open; input->close = gpio_keys_close; input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = 0x0100; /* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit); for (i = 0; i < pdata->nbuttons; i++) { struct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_button_data *bdata = &ddata->data[i]; unsigned int type = button->type ?: EV_KEY; bdata->input = input; bdata->button = button; error = gpio_keys_setup_key(pdev, bdata, button); if (error) goto fail2; if (button->wakeup) wakeup = 1; input_set_capability(input, type, button->code); } error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group); if (error) { dev_err(dev, "Unable to export keys/switches, error: %d\n", error); goto fail2; } error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", error); goto fail3; } /* get current state of buttons */ for (i = 0; i < pdata->nbuttons; i++) gpio_keys_report_event(&ddata->data[i]); input_sync(input); device_init_wakeup(&pdev->dev, wakeup); return 0; fail3: sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); fail2: while (--i >= 0) { free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]); if (ddata->data[i].timer_debounce) del_timer_sync(&ddata->data[i].timer); cancel_work_sync(&ddata->data[i].work); gpio_free(pdata->buttons[i].gpio); } platform_set_drvdata(pdev, NULL); fail1: input_free_device(input); kfree(ddata); return error; }
static int __devinit gpio_keys_probe(struct platform_device *pdev) { const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; struct gpio_keys_drvdata *ddata; struct gpio_keys_button *button = NULL; struct gpio_button_data *bdata = NULL ; struct device *dev = &pdev->dev; struct gpio_keys_platform_data alt_pdata; struct input_dev *input; int i, error; int wakeup = 0; #ifdef CONFIG_SENSORS_HALL int ret; struct device *sec_key; #endif if (!pdata) { error = gpio_keys_get_devtree_pdata(dev, &alt_pdata); if (error) return error; pdata = &alt_pdata; } ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + pdata->nbuttons * sizeof(struct gpio_button_data), GFP_KERNEL); input = input_allocate_device(); if (!ddata || !input) { dev_err(dev, "failed to allocate state\n"); error = -ENOMEM; goto fail1; } ddata->input = input; ddata->n_buttons = pdata->nbuttons; ddata->enable = pdata->enable; ddata->disable = pdata->disable; #ifdef CONFIG_SENSORS_HALL ddata->gpio_flip_cover = pdata->gpio_flip_cover; ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover); #endif mutex_init(&ddata->disable_lock); platform_set_drvdata(pdev, ddata); input_set_drvdata(input, ddata); input->name = pdata->name ? : pdev->name; input->phys = "gpio-keys/input0"; input->dev.parent = &pdev->dev; #ifdef CONFIG_SENSORS_HALL input->evbit[0] |= BIT_MASK(EV_SW); input_set_capability(input, EV_SW, SW_FLIP); #endif input->open = gpio_keys_open; input->close = gpio_keys_close; input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = 0x0100; /* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit); for (i = 0; i < pdata->nbuttons; i++) { button = &pdata->buttons[i]; bdata = &ddata->data[i]; error = gpio_keys_setup_key(pdev, input, bdata, button); if (error) goto fail2; if (button->wakeup) wakeup = 1; } error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group); if (error) { dev_err(dev, "Unable to export keys/switches, error: %d\n", error); goto fail2; } error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", error); goto fail3; } /* get current state of buttons that are connected to GPIOs */ for (i = 0; i < pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; if (gpio_is_valid(bdata->button->gpio)) gpio_keys_gpio_report_event(bdata); } input_sync(input); #ifdef CONFIG_SENSORS_HALL sec_key = device_create(sec_class, NULL, 0, NULL, "sec_key"); if (IS_ERR(sec_key)) pr_err("Failed to create device(sec_key)!\n"); ret = device_create_file(sec_key, &dev_attr_hall_detect); if (ret < 0) { pr_err("Failed to create device file(%s)!, error: %d\n", dev_attr_hall_detect.attr.name, ret); } ret = device_create_file(sec_key, &dev_attr_sec_key_pressed); if (ret) { pr_err("Failed to create device file in sysfs entries(%s)!\n", dev_attr_sec_key_pressed.attr.name); } ret = device_create_file(sec_key, &dev_attr_wakeup_keys); if (ret < 0) { pr_err("Failed to create device file(%s), error: %d\n", dev_attr_wakeup_keys.attr.name, ret); } dev_set_drvdata(sec_key, ddata); #endif device_init_wakeup(&pdev->dev, wakeup); return 0; fail3: sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); fail2: while (--i >= 0) gpio_remove_key(&ddata->data[i]); platform_set_drvdata(pdev, NULL); fail1: input_free_device(input); kfree(ddata); /* If we have no platform_data, we allocated buttons dynamically. */ if (!pdev->dev.platform_data) kfree(pdata->buttons); return error; }
static int gpio_event_probe(struct platform_device *pdev) { int err; struct gpio_event *ip; struct gpio_event_platform_data *event_info; int dev_count = 1; int i; int registered = 0; event_info = pdev->dev.platform_data; if (event_info == NULL) { pr_err("gpio_event_probe: No pdata\n"); return -ENODEV; } if ((!event_info->name && !event_info->names[0]) || !event_info->info || !event_info->info_count) { pr_err("gpio_event_probe: Incomplete pdata\n"); return -ENODEV; } if (!event_info->name) while (event_info->names[dev_count]) dev_count++; ip = kzalloc(sizeof(*ip) + sizeof(ip->state[0]) * event_info->info_count + sizeof(*ip->input_devs) + sizeof(ip->input_devs->dev[0]) * dev_count, GFP_KERNEL); if (ip == NULL) { err = -ENOMEM; pr_err("gpio_event_probe: Failed to allocate private data\n"); goto err_kp_alloc_failed; } ip->input_devs = (void*)&ip->state[event_info->info_count]; platform_set_drvdata(pdev, ip); for (i = 0; i < dev_count; i++) { struct input_dev *input_dev = input_allocate_device(); if (input_dev == NULL) { err = -ENOMEM; pr_err("gpio_event_probe: " "Failed to allocate input device\n"); goto err_input_dev_alloc_failed; } input_set_drvdata(input_dev, ip); input_dev->name = event_info->name ? event_info->name : event_info->names[i]; input_dev->event = gpio_input_event; ip->input_devs->dev[i] = input_dev; } ip->input_devs->count = dev_count; ip->info = event_info; if (event_info->power) { #ifdef CONFIG_HAS_EARLYSUSPEND ip->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; ip->early_suspend.suspend = gpio_event_suspend; ip->early_suspend.resume = gpio_event_resume; register_early_suspend(&ip->early_suspend); #endif ip->info->power(ip->info, 1); } err = gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_INIT); if (err) goto err_call_all_func_failed; for (i = 0; i < dev_count; i++) { err = input_register_device(ip->input_devs->dev[i]); if (err) { pr_err("gpio_event_probe: Unable to register %s " "input device\n", ip->input_devs->dev[i]->name); goto err_input_register_device_failed; } registered++; } return 0; err_input_register_device_failed: gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_UNINIT); err_call_all_func_failed: if (event_info->power) { #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&ip->early_suspend); #endif ip->info->power(ip->info, 0); } for (i = 0; i < registered; i++) input_unregister_device(ip->input_devs->dev[i]); for (i = dev_count - 1; i >= registered; i--) { input_free_device(ip->input_devs->dev[i]); err_input_dev_alloc_failed: ; } kfree(ip); err_kp_alloc_failed: return err; }
static int __devinit pcap_ts_probe(struct platform_device *pdev) { struct input_dev *input_dev; struct pcap_ts *pcap_ts; int err = -ENOMEM; pcap_ts = kzalloc(sizeof(*pcap_ts), GFP_KERNEL); if (!pcap_ts) return err; pcap_ts->pcap = dev_get_drvdata(pdev->dev.parent); platform_set_drvdata(pdev, pcap_ts); input_dev = input_allocate_device(); if (!input_dev) goto fail; INIT_DELAYED_WORK(&pcap_ts->work, pcap_ts_work); pcap_ts->read_state = PCAP_ADC_TS_M_NONTS; pcap_set_ts_bits(pcap_ts->pcap, pcap_ts->read_state << PCAP_ADC_TS_M_SHIFT); pcap_ts->input = input_dev; input_set_drvdata(input_dev, pcap_ts); input_dev->name = "pcap-touchscreen"; input_dev->phys = "pcap_ts/input0"; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0x0001; input_dev->id.product = 0x0002; input_dev->id.version = 0x0100; input_dev->dev.parent = &pdev->dev; input_dev->open = pcap_ts_open; input_dev->close = pcap_ts_close; 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, X_AXIS_MIN, X_AXIS_MAX, 0, 0); input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0); input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0); err = input_register_device(pcap_ts->input); if (err) goto fail_allocate; err = request_irq(pcap_to_irq(pcap_ts->pcap, PCAP_IRQ_TS), pcap_ts_event_touch, 0, "Touch Screen", pcap_ts); if (err) goto fail_register; return 0; fail_register: input_unregister_device(input_dev); goto fail; fail_allocate: input_free_device(input_dev); fail: kfree(pcap_ts); return err; }
static int __devinit hs_probe(struct platform_device *pdev) { int rc = 0; struct input_dev *ipdev; hs = kzalloc(sizeof(struct msm_handset), GFP_KERNEL); if (!hs) return -ENOMEM; /* LGE_UPDATE_S myunghee.kim 2011.12.09 */ /* WiredAccessoryObserver.java check h2w device not h2w_headset for headset detecdtion */ /* so we modified board-u0-sound.c & this file */ /* modify here because of OS Upgrade */ /* original code : hs->sdev.name = "h2w"; */ hs->sdev.name = "h2w_handset"; /* LGE_UPDATE_E */ hs->sdev.print_name = msm_headset_print_name; rc = switch_dev_register(&hs->sdev); if (rc) goto err_switch_dev_register; ipdev = input_allocate_device(); if (!ipdev) { rc = -ENOMEM; goto err_alloc_input_dev; } input_set_drvdata(ipdev, hs); hs->ipdev = ipdev; if (pdev->dev.platform_data) hs->hs_pdata = pdev->dev.platform_data; if (hs->hs_pdata->hs_name) ipdev->name = hs->hs_pdata->hs_name; else ipdev->name = DRIVER_NAME; ipdev->id.vendor = 0x0001; ipdev->id.product = 1; ipdev->id.version = 1; input_set_capability(ipdev, EV_KEY, KEY_MEDIA); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEUP); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEDOWN); input_set_capability(ipdev, EV_SW, SW_HEADPHONE_INSERT); input_set_capability(ipdev, EV_SW, SW_MICROPHONE_INSERT); input_set_capability(ipdev, EV_KEY, KEY_POWER); input_set_capability(ipdev, EV_KEY, KEY_END); rc = input_register_device(ipdev); if (rc) { dev_err(&ipdev->dev, "hs_probe: input_register_device rc=%d\n", rc); goto err_reg_input_dev; } platform_set_drvdata(pdev, hs); rc = hs_rpc_init(); if (rc) { dev_err(&ipdev->dev, "rpc init failure\n"); goto err_hs_rpc_init; } return 0; err_hs_rpc_init: input_unregister_device(ipdev); ipdev = NULL; err_reg_input_dev: input_free_device(ipdev); err_alloc_input_dev: switch_dev_unregister(&hs->sdev); err_switch_dev_register: kfree(hs); return rc; }
static int tc3589x_keypad_probe(struct platform_device *pdev) { struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); struct tc_keypad *keypad; struct input_dev *input; const struct tc3589x_keypad_platform_data *plat; int error, irq; plat = tc3589x_keypad_of_probe(&pdev->dev); if (IS_ERR(plat)) { dev_err(&pdev->dev, "invalid keypad platform data\n"); return PTR_ERR(plat); } irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; keypad = devm_kzalloc(&pdev->dev, sizeof(struct tc_keypad), GFP_KERNEL); if (!keypad) return -ENOMEM; input = devm_input_allocate_device(&pdev->dev); if (!input) { dev_err(&pdev->dev, "failed to allocate input device\n"); return -ENOMEM; } keypad->board = plat; keypad->input = input; keypad->tc3589x = tc3589x; input->id.bustype = BUS_I2C; input->name = pdev->name; input->dev.parent = &pdev->dev; input->open = tc3589x_keypad_open; input->close = tc3589x_keypad_close; error = matrix_keypad_build_keymap(plat->keymap_data, NULL, TC3589x_MAX_KPROW, TC3589x_MAX_KPCOL, NULL, input); if (error) { dev_err(&pdev->dev, "Failed to build keymap\n"); return error; } keypad->keymap = input->keycode; input_set_capability(input, EV_MSC, MSC_SCAN); if (!plat->no_autorepeat) __set_bit(EV_REP, input->evbit); input_set_drvdata(input, keypad); tc3589x_keypad_disable(keypad); error = devm_request_threaded_irq(&pdev->dev, irq, NULL, tc3589x_keypad_irq, plat->irqtype | IRQF_ONESHOT, "tc3589x-keypad", keypad); if (error) { dev_err(&pdev->dev, "Could not allocate irq %d,error %d\n", irq, error); return error; } error = input_register_device(input); if (error) { dev_err(&pdev->dev, "Could not register input device\n"); return error; } /* let platform decide if keypad is a wakeup source or not */ device_init_wakeup(&pdev->dev, plat->enable_wakeup); device_set_wakeup_capable(&pdev->dev, plat->enable_wakeup); platform_set_drvdata(pdev, keypad); return 0; }
static int sun4i_ts_probe(struct platform_device *pdev) { struct sun4i_ts_data *ts; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct device *hwmon; int error; bool ts_attached; ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL); if (!ts) return -ENOMEM; ts->dev = dev; ts->ignore_fifo_data = true; ts->temp_data = -1; ts_attached = of_property_read_bool(np, "allwinner,ts-attached"); if (ts_attached) { ts->input = devm_input_allocate_device(dev); if (!ts->input) return -ENOMEM; ts->input->name = pdev->name; ts->input->phys = "sun4i_ts/input0"; ts->input->open = sun4i_ts_open; ts->input->close = sun4i_ts_close; ts->input->id.bustype = BUS_HOST; ts->input->id.vendor = 0x0001; ts->input->id.product = 0x0001; ts->input->id.version = 0x0100; ts->input->evbit[0] = BIT(EV_SYN) | BIT(EV_KEY) | BIT(EV_ABS); __set_bit(BTN_TOUCH, ts->input->keybit); input_set_abs_params(ts->input, ABS_X, 0, 4095, 0, 0); input_set_abs_params(ts->input, ABS_Y, 0, 4095, 0, 0); input_set_drvdata(ts->input, ts); } ts->base = devm_ioremap_resource(dev, platform_get_resource(pdev, IORESOURCE_MEM, 0)); if (IS_ERR(ts->base)) return PTR_ERR(ts->base); ts->irq = platform_get_irq(pdev, 0); error = devm_request_irq(dev, ts->irq, sun4i_ts_irq, 0, "sun4i-ts", ts); if (error) return error; /* * Select HOSC clk, clkin = clk / 6, adc samplefreq = clkin / 8192, * t_acq = clkin / (16 * 64) */ writel(ADC_CLK_SEL(0) | ADC_CLK_DIV(2) | FS_DIV(7) | T_ACQ(63), ts->base + TP_CTRL0); /* * sensitive_adjust = 15 : max, which is not all that sensitive, * tp_mode = 0 : only x and y coordinates, as we don't use dual touch */ writel(TP_SENSITIVE_ADJUST(15) | TP_MODE_SELECT(0), ts->base + TP_CTRL2); /* Enable median filter, type 1 : 5/3 */ writel(FILTER_EN(1) | FILTER_TYPE(1), ts->base + TP_CTRL3); /* Enable temperature measurement, period 1953 (2 seconds) */ writel(TEMP_ENABLE(1) | TEMP_PERIOD(1953), ts->base + TP_TPR); /* * Set stylus up debounce to aprox 10 ms, enable debounce, and * finally enable tp mode. */ writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1), ts->base + TP_CTRL1); hwmon = devm_hwmon_device_register_with_groups(ts->dev, "sun4i_ts", ts, sun4i_ts_groups); if (IS_ERR(hwmon)) return PTR_ERR(hwmon); writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC); if (ts_attached) { error = input_register_device(ts->input); if (error) { writel(0, ts->base + TP_INT_FIFOC); return error; } } platform_set_drvdata(pdev, ts); return 0; }
static int simple_remote_probe(struct platform_device *pdev) { int ret = 0; int size; void *v; struct simple_remote_driver *jack; dev_info(&pdev->dev, "**** Registering (headset) driver\n"); jack = kzalloc(sizeof(struct simple_remote_driver), GFP_KERNEL); if (!jack) return -ENOMEM; mutex_init(&jack->simple_remote_mutex); if (!pdev->dev.platform_data) goto err_switch_dev_register; size = sizeof(*jack->interface) / sizeof(void *); v = (void *)pdev->dev.platform_data; for (; size > 0; size--) if (v++ == NULL) goto err_switch_dev_register; jack->interface = pdev->dev.platform_data; jack->dev = &pdev->dev; jack->plug_det_timer.function = simple_remote_plug_detect_tmr_func; jack->plug_det_timer.data = (unsigned long)jack; init_timer(&jack->plug_det_timer); /* Set flags */ jack->current_accessory_state = NO_DEVICE; jack->pressed_button = 0xFF; /* Initialize work queue for Simple Remote Driver */ INIT_WORK(&jack->plug_det_work, simple_remote_plug_det_work); INIT_WORK(&jack->btn_det_work, simple_remote_btn_det_work); /* device name */ jack->swdev.name = "h2w"; /* print function name */ jack->swdev.print_name = simple_remote_print_name; ret = switch_dev_register(&jack->swdev); if (ret < 0) { dev_err(jack->dev, "switch_dev_register failed\n"); goto err_switch_dev_register; } ret = create_sysfs_interfaces(&pdev->dev); if (ret) { dev_err(jack->dev, "create_sysfs_interfaces for input failed\n"); goto err_switch_dev_register; } if (initialize_hardware(jack)) dev_err(jack->dev, "Failed to set default values in HW " "components."); /* Create input device for normal key events. */ jack->indev = input_allocate_device(); if (!jack->indev) { ret = -ENOMEM; dev_err(jack->dev, "Failed to allocate input device\n"); goto err_allocate_input_dev; } jack->indev->name = SIMPLE_REMOTE_NAME; jack->indev->evbit[0] = BIT_MASK(EV_KEY); jack->indev->keybit[BIT_WORD(KEY_MEDIA)] |= BIT_MASK(KEY_MEDIA); jack->indev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | BIT_MASK(BTN_1) | BIT_MASK(BTN_2); jack->indev->open = simple_remote_open; jack->indev->close = simple_remote_close; input_set_drvdata(jack->indev, jack); platform_set_drvdata(pdev, jack); ret = input_register_device(jack->indev); if (ret) { dev_err(jack->dev, "input_register_device for input device " "failed\n"); input_free_device(jack->indev); goto err_register_input_dev; } /* Create input device for application key events. */ jack->indev_appkey = input_allocate_device(); if (!jack->indev_appkey) { ret = -ENOMEM; dev_err(jack->dev, "Failed to allocate application key input " "device\n"); goto err_allocate_input_appkey_dev; } jack->indev_appkey->name = SIMPLE_REMOTE_APPKEY_NAME; jack->indev_appkey->evbit[0] = BIT_MASK(EV_KEY); jack->indev_appkey->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(SIMPLE_REMOTE_APPKEY); jack->indev_appkey->open = simple_remote_open; jack->indev_appkey->close = simple_remote_close; input_set_drvdata(jack->indev_appkey, jack); ret = input_register_device(jack->indev_appkey); if (ret) { dev_err(jack->dev, "input_register_device for application key " "input device failed\n"); goto err_register_input_appkey_dev; } dev_info(jack->dev, "***** Successfully registered\n"); atomic_set(&jack->initialized, 1); return ret; err_register_input_appkey_dev: input_free_device(jack->indev_appkey); err_allocate_input_appkey_dev: input_unregister_device(jack->indev); err_register_input_dev: err_allocate_input_dev: err_switch_dev_register: dev_err(&pdev->dev, "***** Failed to initialize\n"); kzfree(jack); return ret; }
static int pwm_beeper_probe(struct platform_device *pdev) { unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev); struct pwm_beeper *beeper; int error; beeper = kzalloc(sizeof(*beeper), GFP_KERNEL); if (!beeper) return -ENOMEM; beeper->pwm = pwm_get(&pdev->dev, NULL); if (IS_ERR(beeper->pwm)) { dev_dbg(&pdev->dev, "unable to request PWM, trying legacy API\n"); beeper->pwm = pwm_request(pwm_id, "pwm beeper"); } if (IS_ERR(beeper->pwm)) { error = PTR_ERR(beeper->pwm); dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error); goto err_free; } beeper->input = input_allocate_device(); if (!beeper->input) { dev_err(&pdev->dev, "Failed to allocate input device\n"); error = -ENOMEM; goto err_pwm_free; } beeper->input->dev.parent = &pdev->dev; beeper->input->name = "pwm-beeper"; beeper->input->phys = "pwm/input0"; beeper->input->id.bustype = BUS_HOST; beeper->input->id.vendor = 0x001f; beeper->input->id.product = 0x0001; beeper->input->id.version = 0x0100; beeper->input->evbit[0] = BIT(EV_SND); beeper->input->sndbit[0] = BIT(SND_TONE) | BIT(SND_BELL); beeper->input->event = pwm_beeper_event; input_set_drvdata(beeper->input, beeper); error = input_register_device(beeper->input); if (error) { dev_err(&pdev->dev, "Failed to register input device: %d\n", error); goto err_input_free; } platform_set_drvdata(pdev, beeper); return 0; err_input_free: input_free_device(beeper->input); err_pwm_free: pwm_free(beeper->pwm); err_free: kfree(beeper); return error; }
static int __devinit mcs5000_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mcs5000_ts_data *data; struct input_dev *input_dev; int ret; if (!client->dev.platform_data) return -EINVAL; data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL); input_dev = input_allocate_device(); if (!data || !input_dev) { dev_err(&client->dev, "Failed to allocate memory\n"); ret = -ENOMEM; goto err_free_mem; } data->client = client; data->input_dev = input_dev; data->platform_data = client->dev.platform_data; input_dev->name = "MELPAS MCS-5000 Touchscreen"; input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; __set_bit(EV_ABS, input_dev->evbit); __set_bit(EV_KEY, input_dev->evbit); __set_bit(BTN_TOUCH, input_dev->keybit); input_set_abs_params(input_dev, ABS_X, 0, MCS5000_MAX_XC, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0); input_set_drvdata(input_dev, data); if (data->platform_data->cfg_pin) data->platform_data->cfg_pin(); ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data); if (ret < 0) { dev_err(&client->dev, "Failed to register interrupt\n"); goto err_free_mem; } ret = input_register_device(data->input_dev); if (ret < 0) goto err_free_irq; mcs5000_ts_phys_init(data); i2c_set_clientdata(client, data); return 0; err_free_irq: free_irq(client->irq, data); err_free_mem: input_free_device(input_dev); kfree(data); return ret; }
static int pixcir_i2c_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { const struct pixcir_ts_platform_data *pdata = dev_get_platdata(&client->dev); struct device *dev = &client->dev; struct device_node *np = dev->of_node; struct pixcir_i2c_ts_data *tsdata; struct input_dev *input; int error; if (np && !pdata) { pdata = pixcir_parse_dt(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } if (!pdata) { dev_err(&client->dev, "platform data not defined\n"); return -EINVAL; } if (!gpio_is_valid(pdata->gpio_attb)) { dev_err(dev, "Invalid gpio_attb in pdata\n"); return -EINVAL; } if (!pdata->chip.max_fingers) { dev_err(dev, "Invalid max_fingers in pdata\n"); return -EINVAL; } tsdata = devm_kzalloc(dev, sizeof(*tsdata), GFP_KERNEL); if (!tsdata) return -ENOMEM; input = devm_input_allocate_device(dev); if (!input) { dev_err(dev, "Failed to allocate input device\n"); return -ENOMEM; } tsdata->client = client; tsdata->input = input; tsdata->pdata = pdata; input->name = client->name; input->id.bustype = BUS_I2C; input->open = pixcir_input_open; input->close = pixcir_input_close; input->dev.parent = &client->dev; __set_bit(EV_KEY, input->evbit); __set_bit(EV_ABS, input->evbit); __set_bit(BTN_TOUCH, input->keybit); input_set_abs_params(input, ABS_X, 0, pdata->x_max, 0, 0); input_set_abs_params(input, ABS_Y, 0, pdata->y_max, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0); tsdata->max_fingers = tsdata->pdata->chip.max_fingers; if (tsdata->max_fingers > PIXCIR_MAX_SLOTS) { tsdata->max_fingers = PIXCIR_MAX_SLOTS; dev_info(dev, "Limiting maximum fingers to %d\n", tsdata->max_fingers); } error = input_mt_init_slots(input, tsdata->max_fingers, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); if (error) { dev_err(dev, "Error initializing Multi-Touch slots\n"); return error; } input_set_drvdata(input, tsdata); error = devm_gpio_request_one(dev, pdata->gpio_attb, GPIOF_DIR_IN, "pixcir_i2c_attb"); if (error) { dev_err(dev, "Failed to request ATTB gpio\n"); return error; } error = devm_request_threaded_irq(dev, client->irq, NULL, pixcir_ts_isr, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->name, tsdata); if (error) { dev_err(dev, "failed to request irq %d\n", client->irq); return error; } /* Always be in IDLE mode to save power, device supports auto wake */ error = pixcir_set_power_mode(tsdata, PIXCIR_POWER_IDLE); if (error) { dev_err(dev, "Failed to set IDLE mode\n"); return error; } /* Stop device till opened */ error = pixcir_stop(tsdata); if (error) return error; error = input_register_device(input); if (error) return error; i2c_set_clientdata(client, tsdata); device_init_wakeup(&client->dev, 1); return 0; }
int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, struct regmap *regmap, int (*tsc200x_cmd)(struct device *dev, u8 cmd)) { struct tsc200x *ts; struct input_dev *input_dev; u32 x_plate_ohm; u32 esd_timeout; int error; if (irq <= 0) { dev_err(dev, "no irq\n"); return -ENODEV; } if (IS_ERR(regmap)) return PTR_ERR(regmap); if (!tsc200x_cmd) { dev_err(dev, "no cmd function\n"); return -ENODEV; } ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); if (!ts) return -ENOMEM; input_dev = devm_input_allocate_device(dev); if (!input_dev) return -ENOMEM; ts->irq = irq; ts->dev = dev; ts->idev = input_dev; ts->regmap = regmap; ts->tsc200x_cmd = tsc200x_cmd; error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm); ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; error = device_property_read_u32(dev, "ti,esd-recovery-timeout-ms", &esd_timeout); ts->esd_timeout = error ? 0 : esd_timeout; ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(ts->reset_gpio)) { error = PTR_ERR(ts->reset_gpio); dev_err(dev, "error acquiring reset gpio: %d\n", error); return error; } ts->vio = devm_regulator_get(dev, "vio"); if (IS_ERR(ts->vio)) { error = PTR_ERR(ts->vio); dev_err(dev, "error acquiring vio regulator: %d", error); return error; } mutex_init(&ts->mutex); spin_lock_init(&ts->lock); timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0); INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); snprintf(ts->phys, sizeof(ts->phys), "%s/input-ts", dev_name(dev)); if (tsc_id->product == 2004) { input_dev->name = "TSC200X touchscreen"; } else { input_dev->name = devm_kasprintf(dev, GFP_KERNEL, "TSC%04d touchscreen", tsc_id->product); if (!input_dev->name) return -ENOMEM; } input_dev->phys = ts->phys; input_dev->id = *tsc_id; input_dev->open = tsc200x_open; input_dev->close = tsc200x_close; input_set_drvdata(input_dev, ts); __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); input_set_capability(input_dev, EV_KEY, BTN_TOUCH); input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, TSC200X_DEF_X_FUZZ, 0); input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, TSC200X_DEF_Y_FUZZ, 0); input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, TSC200X_DEF_P_FUZZ, 0); touchscreen_parse_properties(input_dev, false, NULL); /* Ensure the touchscreen is off */ tsc200x_stop_scan(ts); error = devm_request_threaded_irq(dev, irq, NULL, tsc200x_irq_thread, IRQF_TRIGGER_RISING | IRQF_ONESHOT, "tsc200x", ts); if (error) { dev_err(dev, "Failed to request irq, err: %d\n", error); return error; } error = regulator_enable(ts->vio); if (error) return error; dev_set_drvdata(dev, ts); error = sysfs_create_group(&dev->kobj, &tsc200x_attr_group); if (error) { dev_err(dev, "Failed to create sysfs attributes, err: %d\n", error); goto disable_regulator; } error = input_register_device(ts->idev); if (error) { dev_err(dev, "Failed to register input device, err: %d\n", error); goto err_remove_sysfs; } irq_set_irq_wake(irq, 1); return 0; err_remove_sysfs: sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); disable_regulator: regulator_disable(ts->vio); return error; }
int ssp_sensorhub_initialize(struct ssp_data *ssp_data) { struct ssp_sensorhub_data *hub_data; int ret; /* allocate memory for sensorhub data */ hub_data = kzalloc(sizeof(*hub_data), GFP_KERNEL); if (!hub_data) { sensorhub_err("allocate memory for sensorhub data err"); ret = -ENOMEM; goto exit; } hub_data->ssp_data = ssp_data; ssp_data->hub_data = hub_data; /* init wakelock, list, waitqueue, completion and spinlock */ wake_lock_init(&hub_data->sensorhub_wake_lock, WAKE_LOCK_SUSPEND, "ssp_sensorhub_wake_lock"); init_waitqueue_head(&hub_data->sensorhub_wq); init_completion(&hub_data->read_done); init_completion(&hub_data->big_read_done); init_completion(&hub_data->big_write_done); spin_lock_init(&hub_data->sensorhub_lock); /* allocate sensorhub input device */ hub_data->sensorhub_input_dev = input_allocate_device(); if (!hub_data->sensorhub_input_dev) { sensorhub_err("allocate sensorhub input device err"); ret = -ENOMEM; goto err_input_allocate_device_sensorhub; } /* set sensorhub input device */ input_set_drvdata(hub_data->sensorhub_input_dev, hub_data); hub_data->sensorhub_input_dev->name = "ssp_context"; input_set_capability(hub_data->sensorhub_input_dev, EV_REL, DATA); input_set_capability(hub_data->sensorhub_input_dev, EV_REL, BIG_DATA); input_set_capability(hub_data->sensorhub_input_dev, EV_REL, NOTICE); /* register sensorhub input device */ ret = input_register_device(hub_data->sensorhub_input_dev); if (ret < 0) { sensorhub_err("register sensorhub input device err(%d)", ret); input_free_device(hub_data->sensorhub_input_dev); goto err_input_register_device_sensorhub; } /* register sensorhub misc device */ hub_data->sensorhub_device.minor = MISC_DYNAMIC_MINOR; hub_data->sensorhub_device.name = "ssp_sensorhub"; hub_data->sensorhub_device.fops = &ssp_sensorhub_fops; ret = misc_register(&hub_data->sensorhub_device); if (ret < 0) { sensorhub_err("register sensorhub misc device err(%d)", ret); goto err_misc_register; } /* allocate fifo */ ret = kfifo_alloc(&hub_data->fifo, sizeof(void *) * LIST_SIZE, GFP_KERNEL); if (ret) { sensorhub_err("kfifo allocate err(%d)", ret); goto err_kfifo_alloc; } /* create and run sensorhub thread */ hub_data->sensorhub_task = kthread_run(ssp_sensorhub_thread, (void *)hub_data, "ssp_sensorhub_thread"); if (IS_ERR(hub_data->sensorhub_task)) { ret = PTR_ERR(hub_data->sensorhub_task); goto err_kthread_run; } return 0; err_kthread_run: kfifo_free(&hub_data->fifo); err_kfifo_alloc: misc_deregister(&hub_data->sensorhub_device); err_misc_register: input_unregister_device(hub_data->sensorhub_input_dev); err_input_register_device_sensorhub: err_input_allocate_device_sensorhub: complete_all(&hub_data->big_write_done); complete_all(&hub_data->big_read_done); complete_all(&hub_data->read_done); wake_lock_destroy(&hub_data->sensorhub_wake_lock); kfree(hub_data); exit: return ret; }
static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(intf); struct usb_xpad *xpad; struct input_dev *input_dev; struct usb_endpoint_descriptor *ep_irq_in; int i, error; for (i = 0; xpad_device[i].idVendor; i++) { if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) break; } xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL); input_dev = input_allocate_device(); if (!xpad || !input_dev) { error = -ENOMEM; goto fail1; } xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, GFP_KERNEL, &xpad->idata_dma); if (!xpad->idata) { error = -ENOMEM; goto fail1; } xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); if (!xpad->irq_in) { error = -ENOMEM; goto fail2; } xpad->udev = udev; xpad->mapping = xpad_device[i].mapping; xpad->xtype = xpad_device[i].xtype; if (xpad->xtype == XTYPE_UNKNOWN) { if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) xpad->xtype = XTYPE_XBOX360W; else xpad->xtype = XTYPE_XBOX360; } else xpad->xtype = XTYPE_XBOX; if (dpad_to_buttons) xpad->mapping |= MAP_DPAD_TO_BUTTONS; if (triggers_to_buttons) xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; if (sticks_to_null) xpad->mapping |= MAP_STICKS_TO_NULL; } xpad->dev = input_dev; usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); input_dev->name = xpad_device[i].name; input_dev->phys = xpad->phys; usb_to_input_id(udev, &input_dev->id); input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, xpad); input_dev->open = xpad_open; input_dev->close = xpad_close; input_dev->evbit[0] = BIT_MASK(EV_KEY); if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { input_dev->evbit[0] |= BIT_MASK(EV_ABS); /* set up axes */ for (i = 0; xpad_abs[i] >= 0; i++) xpad_set_up_abs(input_dev, xpad_abs[i]); } /* set up standard buttons */ for (i = 0; xpad_common_btn[i] >= 0; i++) __set_bit(xpad_common_btn[i], input_dev->keybit); /* set up model-specific ones */ if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) { for (i = 0; xpad360_btn[i] >= 0; i++) __set_bit(xpad360_btn[i], input_dev->keybit); } else { for (i = 0; xpad_btn[i] >= 0; i++) __set_bit(xpad_btn[i], input_dev->keybit); } if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { for (i = 0; xpad_btn_pad[i] >= 0; i++) __set_bit(xpad_btn_pad[i], input_dev->keybit); } else { for (i = 0; xpad_abs_pad[i] >= 0; i++) xpad_set_up_abs(input_dev, xpad_abs_pad[i]); } if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { for (i = 0; xpad_btn_triggers[i] >= 0; i++) __set_bit(xpad_btn_triggers[i], input_dev->keybit); } else { for (i = 0; xpad_abs_triggers[i] >= 0; i++) xpad_set_up_abs(input_dev, xpad_abs_triggers[i]); } error = xpad_init_output(intf, xpad); if (error) goto fail3; error = xpad_init_ff(xpad); if (error) goto fail4; error = xpad_led_probe(xpad); if (error) goto fail5; ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; usb_fill_int_urb(xpad->irq_in, udev, usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), xpad->idata, XPAD_PKT_LEN, xpad_irq_in, xpad, ep_irq_in->bInterval); xpad->irq_in->transfer_dma = xpad->idata_dma; xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; INIT_WORK(&xpad->submit_urb, xpad_do_submit_urb); error = input_register_device(xpad->dev); if (error) goto fail6; usb_set_intfdata(intf, xpad); xpad->interface_number = intf->cur_altsetting->desc.bInterfaceNumber; /* * Submit the int URB immediately rather than waiting for open * because we get status messages from the device whether * or not any controllers are attached. In fact, it's * exactly the message that a controller has arrived that * we're waiting for. */ if (xpad->xtype == XTYPE_XBOX360W) { xpad->irq_in->dev = xpad->udev; error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); if (error) goto fail7; } return 0; fail7: input_unregister_device(input_dev); input_dev = NULL; fail6: xpad_led_disconnect(xpad); fail5: if (input_dev) input_ff_destroy(input_dev); fail4: xpad_deinit_output(xpad); fail3: cancel_work_sync(&xpad->submit_urb); usb_free_urb(xpad->irq_in); fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); fail1: input_free_device(input_dev); kfree(xpad); return error; }
static int wacom_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct wacom_g5_platform_data *pdata = client->dev.platform_data; struct wacom_i2c *wac_i2c; struct input_dev *input; int ret = 0; if (pdata == NULL) { printk(KERN_ERR "%s: no pdata\n", __func__); ret = -ENODEV; goto err_i2c_fail; } /*Check I2C functionality */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { printk(KERN_ERR "[E-PEN] No I2C functionality found\n"); ret = -ENODEV; goto err_i2c_fail; } /*Obtain kernel memory space for wacom i2c */ wac_i2c = kzalloc(sizeof(struct wacom_i2c), GFP_KERNEL); if (NULL == wac_i2c) { printk(KERN_ERR "[E-PEN] failed to allocate wac_i2c.\n"); ret = -ENOMEM; goto err_freemem; } input = input_allocate_device(); if (NULL == input) { printk(KERN_ERR "[E-PEN] failed to allocate input device.\n"); ret = -ENOMEM; goto err_input_allocate_device; } else wacom_i2c_set_input_values(client, wac_i2c, input); wac_i2c->wac_feature = &wacom_feature_EMR; wac_i2c->wac_pdata = pdata; wac_i2c->input_dev = input; wac_i2c->client = client; wac_i2c->irq = client->irq; #ifdef WACOM_PDCT_WORK_AROUND wac_i2c->irq_pdct = gpio_to_irq(pdata->gpio_pendct); #endif /*Change below if irq is needed */ wac_i2c->irq_flag = 1; /*Register callbacks */ wac_i2c->callbacks.check_prox = wacom_check_emr_prox; if (wac_i2c->wac_pdata->register_cb) wac_i2c->wac_pdata->register_cb(&wac_i2c->callbacks); /* Firmware Feature */ wacom_i2c_init_firm_data(); #if defined(CONFIG_MACH_Q1_BD) /* Change Origin offset by rev */ if (system_rev < 6) { origin_offset[0] = origin_offset_48[0]; origin_offset[1] = origin_offset_48[1]; } /* Reset IC */ wacom_i2c_reset_hw(wac_i2c->wac_pdata); #endif #if defined(CONFIG_MACH_Q1_BD) || defined(CONFIG_MACH_P4NOTE) wac_i2c->wac_pdata->resume_platform_hw(); msleep(200); #endif ret = wacom_i2c_query(wac_i2c); if (ret < 0) epen_reset_result = false; else epen_reset_result = true; INIT_WORK(&wac_i2c->update_work, update_work_func); #if defined(CONFIG_MACH_P4NOTE) if (pdata->xy_switch) { input_set_abs_params(input, ABS_X, WACOM_POSY_OFFSET, wac_i2c->wac_feature->y_max, 4, 0); input_set_abs_params(input, ABS_Y, WACOM_POSX_OFFSET, wac_i2c->wac_feature->x_max, 4, 0); } else { input_set_abs_params(input, ABS_X, WACOM_POSX_OFFSET, wac_i2c->wac_feature->x_max, 4, 0); input_set_abs_params(input, ABS_Y, WACOM_POSY_OFFSET, wac_i2c->wac_feature->y_max, 4, 0); } input_set_abs_params(input, ABS_PRESSURE, 0, wac_i2c->wac_feature->pressure_max, 0, 0); #else input_set_abs_params(wac_i2c->input_dev, ABS_X, pdata->min_x, pdata->max_x, 4, 0); input_set_abs_params(wac_i2c->input_dev, ABS_Y, pdata->min_y, pdata->max_y, 4, 0); input_set_abs_params(wac_i2c->input_dev, ABS_PRESSURE, pdata->min_pressure, pdata->max_pressure, 0, 0); #endif input_set_drvdata(input, wac_i2c); /*Before registering input device, data in each input_dev must be set */ ret = input_register_device(input); if (ret) { pr_err("[E-PEN] failed to register input device.\n"); goto err_register_device; } /*Change below if irq is needed */ wac_i2c->irq_flag = 1; /*Set client data */ i2c_set_clientdata(client, wac_i2c); /*Initializing for semaphor */ mutex_init(&wac_i2c->lock); wake_lock_init(&wac_i2c->wakelock, WAKE_LOCK_SUSPEND, "wacom"); INIT_DELAYED_WORK(&wac_i2c->resume_work, wacom_i2c_resume_work); #if defined(WACOM_IRQ_WORK_AROUND) INIT_DELAYED_WORK(&wac_i2c->pendct_dwork, wacom_i2c_pendct_work); #endif /*Request IRQ */ if (wac_i2c->irq_flag) { ret = request_threaded_irq(wac_i2c->irq, NULL, wacom_interrupt, IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_ONESHOT, wac_i2c->name, wac_i2c); if (ret < 0) { printk(KERN_ERR "[E-PEN]: failed to request irq(%d) - %d\n", wac_i2c->irq, ret); goto err_request_irq; } #if defined(WACOM_PDCT_WORK_AROUND) ret = request_threaded_irq(wac_i2c->irq_pdct, NULL, wacom_interrupt_pdct, IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, wac_i2c->name, wac_i2c); if (ret < 0) { printk(KERN_ERR "[E-PEN]: failed to request irq(%d) - %d\n", wac_i2c->irq_pdct, ret); goto err_request_irq; } #endif } #ifdef CONFIG_HAS_EARLYSUSPEND wac_i2c->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; wac_i2c->early_suspend.suspend = wacom_i2c_early_suspend; wac_i2c->early_suspend.resume = wacom_i2c_late_resume; register_early_suspend(&wac_i2c->early_suspend); #endif wac_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_epen"); if (IS_ERR(wac_i2c->dev)) printk(KERN_ERR "Failed to create device(wac_i2c->dev)!\n"); else { dev_set_drvdata(wac_i2c->dev, wac_i2c); ret = sysfs_create_group(&wac_i2c->dev->kobj, &epen_attr_group); if (ret) { printk(KERN_ERR "[E-PEN]: failed to create sysfs group\n"); goto err_sysfs_create_group; } } /* firmware info */ printk(KERN_NOTICE "[E-PEN] wacom fw ver : 0x%x, new fw ver : 0x%x\n", wac_i2c->wac_feature->fw_version, Firmware_version_of_file); #ifdef CONFIG_SEC_TOUCHSCREEN_DVFS_LOCK INIT_DELAYED_WORK(&wac_i2c->dvfs_work, free_dvfs_lock); if (exynos_cpufreq_get_level(500000, &wac_i2c->cpufreq_level)) printk(KERN_ERR "[E-PEN] exynos_cpufreq_get_level Error\n"); #ifdef SEC_BUS_LOCK wac_i2c->dvfs_lock_status = false; #if defined(CONFIG_MACH_P4NOTE) wac_i2c->bus_dev = dev_get("exynos-busfreq"); #endif /* CONFIG_MACH_P4NOTE */ #endif /* SEC_BUS_LOCK */ #endif /* CONFIG_SEC_TOUCHSCREEN_DVFS_LOCK */ return 0; err_sysfs_create_group: free_irq(wac_i2c->irq, wac_i2c); #ifdef WACOM_PDCT_WORK_AROUND free_irq(wac_i2c->irq_pdct, wac_i2c); #endif err_request_irq: err_register_device: input_unregister_device(input); input = NULL; err_input_allocate_device: input_free_device(input); err_freemem: kfree(wac_i2c); err_i2c_fail: return ret; }
static int __devinit gpio_keys_probe(struct platform_device *pdev) { const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; struct gpio_keys_drvdata *ddata; struct device *dev = &pdev->dev; struct gpio_keys_platform_data alt_pdata; struct input_dev *input; int i, error; int wakeup = 0; if (!pdata) { error = gpio_keys_get_devtree_pdata(dev, &alt_pdata); if (error) return error; pdata = &alt_pdata; } ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + pdata->nbuttons * sizeof(struct gpio_button_data), GFP_KERNEL); input = input_allocate_device(); if (!ddata || !input) { dev_err(dev, "failed to allocate state\n"); error = -ENOMEM; goto fail1; } ddata->input = input; ddata->n_buttons = pdata->nbuttons; ddata->enable = pdata->enable; ddata->disable = pdata->disable; #ifdef CONFIG_SENSORS_HALL ddata->gpio_flip_cover = pdata->gpio_flip_cover; ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);; wake_lock_init(&ddata->flip_wake_lock, WAKE_LOCK_SUSPEND, "flip wake lock"); #endif mutex_init(&ddata->disable_lock); platform_set_drvdata(pdev, ddata); input_set_drvdata(input, ddata); input->name = pdata->name ? : pdev->name; input->phys = "gpio-keys/input0"; input->dev.parent = &pdev->dev; #ifdef CONFIG_SENSORS_HALL input->evbit[0] |= BIT_MASK(EV_SW); input_set_capability(input, EV_SW, SW_FLIP); #endif input->open = gpio_keys_open; input->close = gpio_keys_close; input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = 0x0100; /* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit); for (i = 0; i < pdata->nbuttons; i++) { struct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_button_data *bdata = &ddata->data[i]; error = gpio_keys_setup_key(pdev, input, bdata, button); if (error) goto fail2; if (button->wakeup) wakeup = 1; #ifdef KEY_BOOSTER if (button->code == KEY_HOMEPAGE) { error = gpio_key_init_dvfs(bdata); if (error < 0) { dev_err(dev, "Fail get dvfs level for touch booster\n"); goto fail2; } } #endif } error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group); if (error) { dev_err(dev, "Unable to export keys/switches, error: %d\n", error); goto fail2; } ddata->sec_key = device_create(sec_class, NULL, 0, ddata, "sec_key"); if (IS_ERR(ddata->sec_key)) dev_err(dev, "Failed to create sec_key device\n"); error = sysfs_create_group(&ddata->sec_key->kobj, &sec_key_attr_group); if (error) { dev_err(dev, "Failed to create the test sysfs: %d\n", error); goto fail2; } #ifdef CONFIG_SENSORS_HALL init_hall_ic_irq(input); #endif error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", error); goto fail3; } /* get current state of buttons */ for (i = 0; i < pdata->nbuttons; i++) gpio_keys_report_event(&ddata->data[i]); input_sync(input); #ifdef CONFIG_FAST_BOOT /*Fake power off*/ input_set_capability(input, EV_KEY, KEY_FAKE_PWR); setup_timer(&fake_timer, gpio_keys_fake_off_check, (unsigned long)input); wake_lock_init(&fake_lock, WAKE_LOCK_SUSPEND, "fake_lock"); #endif device_init_wakeup(&pdev->dev, wakeup); #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP) #if defined(CONFIG_N1A) || defined(CONFIG_N2A) if(set_auto_power_on_off_powerkey_val) { init_timer(&poweroff_keypad_timer); poweroff_keypad_timer.function = poweroff_keypad_timer_handler; poweroff_keypad_timer.data = (unsigned long)&ddata->data[0]; if(lpcharge) poweroff_keypad_timer.expires = jiffies + 20*HZ; else poweroff_keypad_timer.expires = jiffies + 40*HZ; add_timer(&poweroff_keypad_timer); printk("AUTO_POWER_ON_OFF_FLAG Test Start !!!\n"); } #endif #endif return 0; fail3: sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); sysfs_remove_group(&ddata->sec_key->kobj, &sec_key_attr_group); fail2: while (--i >= 0) gpio_remove_key(&ddata->data[i]); platform_set_drvdata(pdev, NULL); #ifdef CONFIG_SENSORS_HALL wake_lock_destroy(&ddata->flip_wake_lock); #endif fail1: input_free_device(input); kfree(ddata); /* If we have no platform_data, we allocated buttons dynamically. */ if (!pdev->dev.platform_data) kfree(pdata->buttons); return error; }
/* * keypad controller should be initialized in the following sequence * only, otherwise it might get into FSM stuck state. * * - Initialize keypad control parameters, like no. of rows, columns, * timing values etc., * - configure rows and column gpios pull up/down. * - set irq edge type. * - enable the keypad controller. */ static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev) { const struct pm8xxx_keypad_platform_data *pdata = dev_get_platdata(&pdev->dev); const struct matrix_keymap_data *keymap_data; struct pmic8xxx_kp *kp; int rc; u8 ctrl_val; struct pm_gpio kypd_drv = { .direction = PM_GPIO_DIR_OUT, .output_buffer = PM_GPIO_OUT_BUF_OPEN_DRAIN, .output_value = 0, .pull = PM_GPIO_PULL_NO, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_LOW, .function = PM_GPIO_FUNC_1, .inv_int_pol = 1, }; struct pm_gpio kypd_sns = { .direction = PM_GPIO_DIR_IN, .pull = PM_GPIO_PULL_UP_31P5, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_NO, .function = PM_GPIO_FUNC_NORMAL, .inv_int_pol = 1, }; if (!pdata || !pdata->num_cols || !pdata->num_rows || pdata->num_cols > PM8XXX_MAX_COLS || pdata->num_rows > PM8XXX_MAX_ROWS || pdata->num_cols < PM8XXX_MIN_COLS) { dev_err(&pdev->dev, "invalid platform data\n"); return -EINVAL; } if (!pdata->scan_delay_ms || pdata->scan_delay_ms > MAX_SCAN_DELAY || pdata->scan_delay_ms < MIN_SCAN_DELAY || !is_power_of_2(pdata->scan_delay_ms)) { dev_err(&pdev->dev, "invalid keypad scan time supplied\n"); return -EINVAL; } if (!pdata->row_hold_ns || pdata->row_hold_ns > MAX_ROW_HOLD_DELAY || pdata->row_hold_ns < MIN_ROW_HOLD_DELAY || ((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) { dev_err(&pdev->dev, "invalid keypad row hold time supplied\n"); return -EINVAL; } if (!pdata->debounce_ms || ((pdata->debounce_ms % 5) != 0) || pdata->debounce_ms > MAX_DEBOUNCE_TIME || pdata->debounce_ms < MIN_DEBOUNCE_TIME) { dev_err(&pdev->dev, "invalid debounce time supplied\n"); return -EINVAL; } keymap_data = pdata->keymap_data; if (!keymap_data) { dev_err(&pdev->dev, "no keymap data supplied\n"); return -EINVAL; } kp = kzalloc(sizeof(*kp), GFP_KERNEL); if (!kp) return -ENOMEM; platform_set_drvdata(pdev, kp); kp->pdata = pdata; kp->dev = &pdev->dev; kp->input = input_allocate_device(); if (!kp->input) { dev_err(&pdev->dev, "unable to allocate input device\n"); rc = -ENOMEM; goto err_alloc_device; } kp->key_sense_irq = platform_get_irq(pdev, 0); if (kp->key_sense_irq < 0) { dev_err(&pdev->dev, "unable to get keypad sense irq\n"); rc = -ENXIO; goto err_get_irq; } kp->key_stuck_irq = platform_get_irq(pdev, 1); if (kp->key_stuck_irq < 0) { dev_err(&pdev->dev, "unable to get keypad stuck irq\n"); rc = -ENXIO; goto err_get_irq; } kp->input->name = pdata->input_name ? : "PMIC8XXX keypad"; kp->input->phys = pdata->input_phys_device ? : "pmic8xxx_keypad/input0"; kp->input->dev.parent = &pdev->dev; kp->input->id.bustype = BUS_I2C; kp->input->id.version = 0x0001; kp->input->id.product = 0x0001; kp->input->id.vendor = 0x0001; kp->input->evbit[0] = BIT_MASK(EV_KEY); if (pdata->rep) __set_bit(EV_REP, kp->input->evbit); kp->input->keycode = kp->keycodes; kp->input->keycodemax = PM8XXX_MATRIX_MAX_SIZE; kp->input->keycodesize = sizeof(kp->keycodes); kp->input->open = pmic8xxx_kp_open; kp->input->close = pmic8xxx_kp_close; matrix_keypad_build_keymap(keymap_data, PM8XXX_ROW_SHIFT, kp->input->keycode, kp->input->keybit); input_set_capability(kp->input, EV_MSC, MSC_SCAN); input_set_drvdata(kp->input, kp); /* initialize keypad state */ memset(kp->keystate, 0xff, sizeof(kp->keystate)); memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate)); rc = pmic8xxx_kpd_init(kp); if (rc < 0) { dev_err(&pdev->dev, "unable to initialize keypad controller\n"); goto err_get_irq; } rc = pmic8xxx_kp_config_gpio(pdata->cols_gpio_start, pdata->num_cols, kp, &kypd_sns); if (rc < 0) { dev_err(&pdev->dev, "unable to configure keypad sense lines\n"); goto err_gpio_config; } rc = pmic8xxx_kp_config_gpio(pdata->rows_gpio_start, pdata->num_rows, kp, &kypd_drv); if (rc < 0) { dev_err(&pdev->dev, "unable to configure keypad drive lines\n"); goto err_gpio_config; } rc = request_any_context_irq(kp->key_sense_irq, pmic8xxx_kp_irq, IRQF_TRIGGER_RISING, "pmic-keypad", kp); if (rc < 0) { dev_err(&pdev->dev, "failed to request keypad sense irq\n"); goto err_get_irq; } rc = request_any_context_irq(kp->key_stuck_irq, pmic8xxx_kp_stuck_irq, IRQF_TRIGGER_RISING, "pmic-keypad-stuck", kp); if (rc < 0) { dev_err(&pdev->dev, "failed to request keypad stuck irq\n"); goto err_req_stuck_irq; } rc = pmic8xxx_kp_read_u8(kp, &ctrl_val, KEYP_CTRL); if (rc < 0) { dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n"); goto err_pmic_reg_read; } kp->ctrl_reg = ctrl_val; rc = input_register_device(kp->input); if (rc < 0) { dev_err(&pdev->dev, "unable to register keypad input device\n"); goto err_pmic_reg_read; } device_init_wakeup(&pdev->dev, pdata->wakeup); return 0; err_pmic_reg_read: free_irq(kp->key_stuck_irq, kp); err_req_stuck_irq: free_irq(kp->key_sense_irq, kp); err_gpio_config: err_get_irq: input_free_device(kp->input); err_alloc_device: platform_set_drvdata(pdev, NULL); kfree(kp); return rc; } static int __devexit pmic8xxx_kp_remove(struct platform_device *pdev) { struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); device_init_wakeup(&pdev->dev, 0); free_irq(kp->key_stuck_irq, kp); free_irq(kp->key_sense_irq, kp); input_unregister_device(kp->input); kfree(kp); platform_set_drvdata(pdev, NULL); return 0; } #ifdef CONFIG_PM_SLEEP static int pmic8xxx_kp_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); struct input_dev *input_dev = kp->input; if (device_may_wakeup(dev)) { enable_irq_wake(kp->key_sense_irq); } else { mutex_lock(&input_dev->mutex); if (input_dev->users) pmic8xxx_kp_disable(kp); mutex_unlock(&input_dev->mutex); } return 0; } static int pmic8xxx_kp_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); struct input_dev *input_dev = kp->input; if (device_may_wakeup(dev)) { disable_irq_wake(kp->key_sense_irq); pmic8xxx_kp_enable(kp); } else { mutex_lock(&input_dev->mutex); if (input_dev->users) pmic8xxx_kp_enable(kp); mutex_unlock(&input_dev->mutex); } return 0; } #endif static SIMPLE_DEV_PM_OPS(pm8xxx_kp_pm_ops, pmic8xxx_kp_suspend, pmic8xxx_kp_resume); static struct platform_driver pmic8xxx_kp_driver = { .probe = pmic8xxx_kp_probe, .remove = __devexit_p(pmic8xxx_kp_remove), .driver = { .name = PM8XXX_KEYPAD_DEV_NAME, .owner = THIS_MODULE, .pm = &pm8xxx_kp_pm_ops, }, }; static int __init pmic8xxx_kp_init(void) { return platform_driver_register(&pmic8xxx_kp_driver); } module_init(pmic8xxx_kp_init); static void __exit pmic8xxx_kp_exit(void) { platform_driver_unregister(&pmic8xxx_kp_driver); } module_exit(pmic8xxx_kp_exit); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("PMIC8XXX keypad driver"); MODULE_VERSION("1.0"); MODULE_ALIAS("platform:pmic8xxx_keypad"); MODULE_AUTHOR("Trilok Soni <*****@*****.**>");
static int __devinit hs_probe(struct platform_device *pdev) { int rc = 0; struct input_dev *ipdev; hs = kzalloc(sizeof(struct msm_handset), GFP_KERNEL); if (!hs) return -ENOMEM; #ifndef CONFIG_LGE_HEADSET hs->sdev.name = "h2w"; hs->sdev.print_name = msm_headset_print_name; rc = switch_dev_register(&hs->sdev); if (rc) goto err_switch_dev_register; #endif ipdev = input_allocate_device(); if (!ipdev) { rc = -ENOMEM; goto err_alloc_input_dev; } input_set_drvdata(ipdev, hs); hs->ipdev = ipdev; if (pdev->dev.platform_data) hs->hs_pdata = pdev->dev.platform_data; if (hs->hs_pdata->hs_name) ipdev->name = hs->hs_pdata->hs_name; else ipdev->name = DRIVER_NAME; ipdev->id.vendor = 0x0001; ipdev->id.product = 1; ipdev->id.version = 1; input_set_capability(ipdev, EV_KEY, KEY_MEDIA); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEUP); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEDOWN); input_set_capability(ipdev, EV_SW, SW_HEADPHONE_INSERT); input_set_capability(ipdev, EV_KEY, KEY_POWER); input_set_capability(ipdev, EV_KEY, KEY_END); rc = input_register_device(ipdev); if (rc) { dev_err(&ipdev->dev, "hs_probe: input_register_device rc=%d\n", rc); goto err_reg_input_dev; } platform_set_drvdata(pdev, hs); rc = hs_rpc_init(); if (rc) { dev_err(&ipdev->dev, "rpc init failure\n"); goto err_hs_rpc_init; } return 0; err_hs_rpc_init: input_unregister_device(ipdev); ipdev = NULL; err_reg_input_dev: input_free_device(ipdev); err_alloc_input_dev: #ifndef CONFIG_LGE_HEADSET switch_dev_unregister(&hs->sdev); err_switch_dev_register: #endif kfree(hs); return rc; }
static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *dev = interface_to_usbdev(intf); struct usb_host_interface *interface; struct usb_endpoint_descriptor *endpoint; struct usb_mouse *mouse; struct input_dev *input_dev; int pipe, maxp; int error = -ENOMEM; interface = intf->cur_altsetting; if (interface->desc.bNumEndpoints != 1) return -ENODEV; endpoint = &interface->endpoint[0].desc; if (!usb_endpoint_is_int_in(endpoint)) return -ENODEV; pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL); input_dev = input_allocate_device(); if (!mouse || !input_dev) goto fail1; mouse->data = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &mouse->data_dma); if (!mouse->data) goto fail1; mouse->irq = usb_alloc_urb(0, GFP_KERNEL); if (!mouse->irq) goto fail2; mouse->usbdev = dev; mouse->dev = input_dev; if (dev->manufacturer) strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name)); if (dev->product) { if (dev->manufacturer) strlcat(mouse->name, " ", sizeof(mouse->name)); strlcat(mouse->name, dev->product, sizeof(mouse->name)); } if (!strlen(mouse->name)) snprintf(mouse->name, sizeof(mouse->name), "USB HIDBP Mouse %04x:%04x", le16_to_cpu(dev->descriptor.idVendor), le16_to_cpu(dev->descriptor.idProduct)); usb_make_path(dev, mouse->phys, sizeof(mouse->phys)); strlcat(mouse->phys, "/input0", sizeof(mouse->phys)); input_dev->name = mouse->name; input_dev->phys = mouse->phys; usb_to_input_id(dev, &input_dev->id); input_dev->dev.parent = &intf->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA); input_dev->relbit[0] |= BIT_MASK(REL_WHEEL); input_set_drvdata(input_dev, mouse); input_dev->open = usb_mouse_open; input_dev->close = usb_mouse_close; usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, (maxp > 8 ? 8 : maxp), usb_mouse_irq, mouse, endpoint->bInterval); mouse->irq->transfer_dma = mouse->data_dma; mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; error = input_register_device(mouse->dev); if (error) goto fail3; usb_set_intfdata(intf, mouse); return 0; fail3: usb_free_urb(mouse->irq); fail2: usb_free_coherent(dev, 8, mouse->data, mouse->data_dma); fail1: input_free_device(input_dev); kfree(mouse); return error; }
static int sensor_probe(struct platform_device *pdev) { struct sensor_data *sensordata = NULL; struct input_dev *inputdev = NULL; int input_registered = 0, sysfs_created = 0; int rt; dbg_func_in(); sensordata = kzalloc(sizeof(struct sensor_data), GFP_KERNEL); if (!sensordata) { rt = -ENOMEM; goto err; } atomic_set(&sensordata->enable, 0); atomic_set(&sensordata->delay, SENSOR_DEFAULT_DELAY); inputdev = input_allocate_device(); if (!inputdev) { rt = -ENOMEM; printk(KERN_ERR "sensor_probe: Failed to allocate input_data device\n"); goto err; } inputdev->name = SENSOR_INPUTDEV_NAME; input_set_capability(inputdev, EV_ABS, ABS_MISC); input_set_abs_params(inputdev, ABS_X, SENSOR_MIN_ABS, SENSOR_MAX_ABS, 0, 0); input_set_abs_params(inputdev, ABS_Y, SENSOR_MIN_ABS, SENSOR_MAX_ABS, 0, 0); input_set_abs_params(inputdev, ABS_Z, SENSOR_MIN_ABS, SENSOR_MAX_ABS, 0, 0); rt = input_register_device(inputdev); if (rt) { printk(KERN_ERR "sensor_probe: Unable to register input_data device: %s\n", inputdev->name); goto err; } input_set_drvdata(inputdev, sensordata); input_registered = 1; rt = sysfs_create_group(&inputdev->dev.kobj, &sensor_attribute_group); if (rt) { printk(KERN_ERR "sensor_probe: sysfs_create_group failed[%s]\n", inputdev->name); goto err; } sysfs_created = 1; mutex_init(&sensordata->enable_mutex); mutex_init(&sensordata->data_mutex); INIT_DELAYED_WORK(&sensordata->work, sensor_work_func); //L3G4200D_init(); input_pdev = inputdev; dbg_func_out(); return 0; err: if (sensordata != NULL) { if (inputdev != NULL) { if (sysfs_created) { sysfs_remove_group(&inputdev->dev.kobj, &sensor_attribute_group); } if (input_registered) { input_unregister_device(inputdev); } else { input_free_device(inputdev); } inputdev = NULL; } kfree(sensordata); } dbg_func_out(); return rt; }
// Pantech Earjack Probe Function static int __devinit pantech_earjack_probe(struct platform_device *pdev) { int rc = 0; int err = 0; struct input_dev *ipdev; dbg_func_in(); irq_state = 0; // Alloc Devices earjack = kzalloc(sizeof(struct pantech_earjack), GFP_KERNEL); if (!earjack) return -ENOMEM; earjack->sdev.name = "h2w"; earjack->sdev.print_name = msm_headset_print_name; rc = switch_dev_register(&earjack->sdev); if (rc) goto err_switch_dev_register; ipdev = input_allocate_device(); if (!ipdev) { rc = -ENOMEM; goto err_alloc_input_dev; } input_set_drvdata(ipdev, earjack); // Init Status Flags earjack->ipdev = ipdev; earjack->car_kit = 0; earjack->type=EARJACK_STATE_OFF; earjack->remotekey_pressed = 0; earjack->remotekey_index = 0; // Initialize Work Queue INIT_DELAYED_WORK(&earjack_work,earjack_detect_func); // INIT WORK INIT_DELAYED_WORK(&remotekey_work,remotekey_detect_func); // Get Power Source #if defined(CONFIG_MIC_BIAS_1_8V) err = 0; #else hs_jack_l8 = regulator_get(NULL, "8058_l8"); regulator_set_voltage(hs_jack_l8,2700000,2700000); dbg("regulator_enable hs_jack_l8 value => %d\n",err); #endif // Initialize Wakelocks wake_lock_init(&earjack_wake_lock, WAKE_LOCK_SUSPEND, "earjack_wake_lock_init"); wake_lock_init(&remotekey_wake_lock, WAKE_LOCK_SUSPEND, "remotekey_wake_lock_init"); // Setup GPIO's gpio_request(EARJACK_DET, "earjack_det"); gpio_request(REMOTEKEY_DET, "remotekey_det"); gpio_tlmm_config(GPIO_CFG(EARJACK_DET, 0, GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE); rc = request_irq(gpio_to_irq(EARJACK_DET), Earjack_Det_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "earjack_det-irq", earjack); // Warning: REMOTEKEY_DET using default gpio config. //gpio_tlmm_config(GPIO_CFG(REMOTEKEY_DET, 0, GPIO_CFG_INPUT,GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE); irq_set_irq_wake(gpio_to_irq(EARJACK_DET), 1); irq_set_irq_wake(gpio_to_irq(REMOTEKEY_DET), 1); // Init Input Device //pz1946 merge for wired long key #ifdef CONFIG_MACH_MSM8X60_PRESTO ipdev->name = DRIVER_NAME; ipdev->id.vendor = 0; ipdev->id.product = 0; ipdev->id.version = 0; #else ipdev->id.vendor = 0x0001; ipdev->id.product = 1; ipdev->id.version = 1; #endif input_set_capability(ipdev, EV_KEY, KEY_MEDIA); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEUP); input_set_capability(ipdev, EV_KEY, KEY_VOLUMEDOWN); input_set_capability(ipdev, EV_KEY, KEY_POWER); input_set_capability(ipdev, EV_KEY, KEY_END); input_set_capability(ipdev, EV_SW, SW_HEADPHONE_INSERT); input_set_capability(ipdev, EV_SW, SW_MICROPHONE_INSERT); rc = input_register_device(ipdev); if (rc) { dev_err(&ipdev->dev, "hs_probe: input_register_device rc=%d\n", rc); goto err_reg_input_dev; } platform_set_drvdata(pdev, earjack); rc = sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp); if (rc) { dev_err(&ipdev->dev, "hs_probe: sysfs_create_group rc=%d\n", rc); goto err_earjack_init; } // Scehdule earjack_detect_func for initial detect disable_irq_detect(); //disable_irq_nosync(gpio_to_irq(EARJACK_DET)); wake_lock(&earjack_wake_lock); disable_irq_nosync(gpio_to_irq(REMOTEKEY_DET)); schedule_delayed_work(&earjack_work,10); // after 100ms dbg_func_out(); return 0; err_earjack_init: err_reg_input_dev: input_unregister_device(ipdev); ipdev = NULL; err_alloc_input_dev: input_free_device(ipdev); err_switch_dev_register: kfree(earjack); return 0; }
static int __devinit locomokbd_probe(struct locomo_dev *dev) { struct locomokbd *locomokbd; struct input_dev *input_dev; int i, err; locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!locomokbd || !input_dev) { err = -ENOMEM; goto err_free_mem; } /* */ if (!request_mem_region((unsigned long) dev->mapbase, dev->length, LOCOMO_DRIVER_NAME(dev))) { err = -EBUSY; printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); goto err_free_mem; } locomo_set_drvdata(dev, locomokbd); locomokbd->base = (unsigned long) dev->mapbase; spin_lock_init(&locomokbd->lock); init_timer(&locomokbd->timer); locomokbd->timer.function = locomokbd_timer_callback; locomokbd->timer.data = (unsigned long) locomokbd; locomokbd->suspend_jiffies = jiffies; locomokbd->input = input_dev; strcpy(locomokbd->phys, "locomokbd/input0"); input_dev->name = "LoCoMo keyboard"; input_dev->phys = locomokbd->phys; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0x0001; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->open = locomokbd_open; input_dev->close = locomokbd_close; input_dev->dev.parent = &dev->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_PWR); input_dev->keycode = locomokbd->keycode; input_dev->keycodesize = sizeof(locomokbd_keycode[0]); input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode); input_set_drvdata(input_dev, locomokbd); memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); for (i = 0; i < LOCOMOKBD_NUMKEYS; i++) set_bit(locomokbd->keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); /* */ err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); if (err) { printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); goto err_release_region; } err = input_register_device(locomokbd->input); if (err) goto err_free_irq; return 0; err_free_irq: free_irq(dev->irq[0], locomokbd); err_release_region: release_mem_region((unsigned long) dev->mapbase, dev->length); locomo_set_drvdata(dev, NULL); err_free_mem: input_free_device(input_dev); kfree(locomokbd); return err; }
static int pixcir_i2c_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pixcir_i2c_ts_data *tsdata; struct input_dev *input; int error = 0; unsigned char Wrbuf; error = touch_reset(); if (error) goto fail; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "i2c check functionality failed\n"); return -ENODEV; } tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL); if (!tsdata) { dev_err(&client->dev, "failed to allocate driver data!\n"); error = -ENOMEM; goto fail1; } dev_set_drvdata(&client->dev, tsdata); input = input_allocate_device(); if (!input) { dev_err(&client->dev, "failed to allocate input device!\n"); error = -ENOMEM; goto fail2; } set_bit(EV_SYN, input->evbit); set_bit(EV_KEY, input->evbit); set_bit(EV_ABS, input->evbit); set_bit(BTN_TOUCH, input->keybit); set_bit(BTN_2, input->keybit); input_set_abs_params(input, ABS_X, TOUCHSCREEN_MINX, TOUCHSCREEN_MAXX, 0, 0); input_set_abs_params(input, ABS_Y, TOUCHSCREEN_MINY, TOUCHSCREEN_MAXY, 0, 0); input_set_abs_params(input, ABS_HAT0X, TOUCHSCREEN_MINX, TOUCHSCREEN_MAXX, 0, 0); input_set_abs_params(input, ABS_HAT0Y, TOUCHSCREEN_MINY, TOUCHSCREEN_MAXY, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_X, TOUCHSCREEN_MINX, TOUCHSCREEN_MAXX, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, TOUCHSCREEN_MINY, TOUCHSCREEN_MAXY, 0, 0); input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 25, 0, 0); input->name = client->name; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; input->open = pixcir_ts_open; input->close = pixcir_ts_close; input_set_drvdata(input, tsdata); tsdata->client = client; tsdata->input = input; INIT_WORK(&tsdata->work.work, pixcir_ts_poscheck); tsdata->irq = client->irq; error = input_register_device(input); if (error) { dev_err(&client->dev, "Could not register input device\n"); goto fail2; } error = gpio_request(TOUCH_INT_PIN, "GPX3"); if (error) { dev_err(&client->dev, "gpio_request failed\n"); error = -ENODEV; goto fail3; } else { s3c_gpio_cfgpin(TOUCH_INT_PIN, S3C_GPIO_SFN(0x0F)); s3c_gpio_setpull(TOUCH_INT_PIN, S3C_GPIO_PULL_UP); } #if defined(Unidisplay_9_7inch) || defined(Unidisplay_7inch) \ || defined(Unidisplay_7inch) Wrbuf = 0xcc; if (i2c_master_send(tsdata->client, &Wrbuf, 1) != 1) { dev_err(&client->dev, "i2c transfer failed\n"); error = -ENODEV; goto fail3; } #endif pixcir_wq = create_singlethread_workqueue("pixcir_wq"); if (!pixcir_wq) { error = -ENOMEM; goto fail3; } #ifdef NAS_7inch error = request_irq(tsdata->irq, pixcir_ts_isr, IRQF_DISABLED | IRQF_TRIGGER_FALLING, client->name, tsdata); #elif defined Unidisplay_7inch error = request_irq(tsdata->irq, pixcir_ts_isr, IRQF_SAMPLE_RANDOM , client->name, tsdata); #endif if (error) { dev_err(&client->dev, "Failed to request irq %d\n", \ tsdata->irq); goto fail3; } if (!error) { device_init_wakeup(&client->dev, 1); dev_info(&tsdata->client->dev, "probed successfully!\n"); return 0; } fail3: input_unregister_device(input); input = NULL; fail2: kfree(tsdata); fail1: dev_set_drvdata(&client->dev, NULL); fail: return error; }
static int __devinit adp5588_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adp5588_kpad *kpad; const struct adp5588_kpad_platform_data *pdata = client->dev.platform_data; struct input_dev *input; unsigned int revid; int ret, i; int error; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); return -EIO; } if (!pdata) { dev_err(&client->dev, "no platform data?\n"); return -EINVAL; } if (!pdata->rows || !pdata->cols || !pdata->keymap) { dev_err(&client->dev, "no rows, cols or keymap from pdata\n"); return -EINVAL; } if (pdata->keymapsize != ADP5588_KEYMAPSIZE) { dev_err(&client->dev, "invalid keymapsize\n"); return -EINVAL; } if (!pdata->gpimap && pdata->gpimapsize) { dev_err(&client->dev, "invalid gpimap from pdata\n"); return -EINVAL; } if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) { dev_err(&client->dev, "invalid gpimapsize\n"); return -EINVAL; } for (i = 0; i < pdata->gpimapsize; i++) { unsigned short pin = pdata->gpimap[i].pin; if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) { dev_err(&client->dev, "invalid gpi pin data\n"); return -EINVAL; } if (pin <= GPI_PIN_ROW_END) { if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) { dev_err(&client->dev, "invalid gpi row data\n"); return -EINVAL; } } else { if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) { dev_err(&client->dev, "invalid gpi col data\n"); return -EINVAL; } } } if (!client->irq) { dev_err(&client->dev, "no IRQ?\n"); return -EINVAL; } kpad = kzalloc(sizeof(*kpad), GFP_KERNEL); input = input_allocate_device(); if (!kpad || !input) { error = -ENOMEM; goto err_free_mem; } kpad->client = client; kpad->input = input; INIT_DELAYED_WORK(&kpad->work, adp5588_work); ret = adp5588_read(client, DEV_ID); if (ret < 0) { error = ret; goto err_free_mem; } revid = (u8) ret & ADP5588_DEVICE_ID_MASK; if (WA_DELAYED_READOUT_REVID(revid)) kpad->delay = msecs_to_jiffies(30); input->name = client->name; input->phys = "adp5588-keys/input0"; input->dev.parent = &client->dev; input_set_drvdata(input, kpad); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = revid; input->keycodesize = sizeof(kpad->keycode[0]); input->keycodemax = pdata->keymapsize; input->keycode = kpad->keycode; memcpy(kpad->keycode, pdata->keymap, pdata->keymapsize * input->keycodesize); kpad->gpimap = pdata->gpimap; kpad->gpimapsize = pdata->gpimapsize; /* setup input device */ __set_bit(EV_KEY, input->evbit); if (pdata->repeat) __set_bit(EV_REP, input->evbit); for (i = 0; i < input->keycodemax; i++) __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit); __clear_bit(KEY_RESERVED, input->keybit); if (kpad->gpimapsize) __set_bit(EV_SW, input->evbit); for (i = 0; i < kpad->gpimapsize; i++) __set_bit(kpad->gpimap[i].sw_evt, input->swbit); error = input_register_device(input); if (error) { dev_err(&client->dev, "unable to register input device\n"); goto err_free_mem; } error = request_irq(client->irq, adp5588_irq, IRQF_TRIGGER_FALLING | IRQF_DISABLED, client->dev.driver->name, kpad); if (error) { dev_err(&client->dev, "irq %d busy?\n", client->irq); goto err_unreg_dev; } error = adp5588_setup(client); if (error) goto err_free_irq; if (kpad->gpimapsize) adp5588_report_switch_state(kpad); error = adp5588_gpio_add(kpad); if (error) goto err_free_irq; device_init_wakeup(&client->dev, 1); i2c_set_clientdata(client, kpad); dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); return 0; err_free_irq: free_irq(client->irq, kpad); err_unreg_dev: input_unregister_device(input); input = NULL; err_free_mem: input_free_device(input); kfree(kpad); return error; }