static int __devinit rb532_button_probe(struct platform_device *pdev) { struct input_polled_dev *poll_dev; int error; poll_dev = input_allocate_polled_device(); if (!poll_dev) return -ENOMEM; poll_dev->poll = rb532_button_poll; poll_dev->poll_interval = RB532_BTN_RATE; poll_dev->input->name = "rb532 button"; poll_dev->input->phys = "rb532/button0"; poll_dev->input->id.bustype = BUS_HOST; poll_dev->input->dev.parent = &pdev->dev; dev_set_drvdata(&pdev->dev, poll_dev); input_set_capability(poll_dev->input, EV_KEY, RB532_BTN_KSYM); error = input_register_polled_device(poll_dev); if (error) { input_free_polled_device(poll_dev); return error; } return 0; }
/* Module stuff */ static int __init light_sensor_init(void) { struct input_dev *idev; int ret; ret = platform_driver_register(&light_sensor_driver); if (ret) goto out; pdev = platform_device_register_simple("light_sensor", -1, NULL, 0); if (IS_ERR(pdev)) { ret = PTR_ERR(pdev); goto out_driver; } ret = sysfs_create_group(&pdev->dev.kobj, &light_sensor_attribute_group); if (ret) goto out_device; light_sensor_idev = input_allocate_polled_device(); if (!light_sensor_idev) { ret = -ENOMEM; goto out_group; } light_sensor_idev->poll = light_sensor_dev_poll; light_sensor_idev->poll_interval = POLL_INTERVAL; /* initialize the input class */ idev = light_sensor_idev->input; idev->name = "light_sensor"; idev->phys = "light_sensor/input0"; idev->id.bustype = BUS_ISA; idev->dev.parent = &pdev->dev; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, 0, LUX_LEVEL, 0, 1); ret = input_register_polled_device(light_sensor_idev); if (ret) goto out_idev; printk(KERN_INFO "light_sensor: driver successfully loaded.\n"); return 0; out_idev: input_free_polled_device(light_sensor_idev); out_group: sysfs_remove_group(&pdev->dev.kobj, &light_sensor_attribute_group); out_device: platform_device_unregister(pdev); out_driver: platform_driver_unregister(&light_sensor_driver); out: printk(KERN_WARNING "light_sensor: driver init failed (ret=%d)!\n", ret); return ret; }
int lis3lv02d_joystick_enable(void) { struct input_dev *input_dev; int err; int max_val, fuzz, flat; int btns[] = {BTN_X, BTN_Y, BTN_Z}; if (lis3_dev.idev) return -EINVAL; lis3_dev.idev = input_allocate_polled_device(); if (!lis3_dev.idev) return -ENOMEM; lis3_dev.idev->poll = lis3lv02d_joystick_poll; lis3_dev.idev->open = lis3lv02d_joystick_open; lis3_dev.idev->close = lis3lv02d_joystick_close; lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN; lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX; input_dev = lis3_dev.idev->input; input_dev->name = "ST LIS3LV02DL Accelerometer"; input_dev->phys = DRIVER_NAME "/input0"; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0; input_dev->dev.parent = &lis3_dev.pdev->dev; set_bit(EV_ABS, input_dev->evbit); max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; if (lis3_dev.whoami == WAI_12B) { fuzz = LIS3_DEFAULT_FUZZ_12B; flat = LIS3_DEFAULT_FLAT_12B; } else { fuzz = LIS3_DEFAULT_FUZZ_8B; flat = LIS3_DEFAULT_FLAT_8B; } fuzz = (fuzz * lis3_dev.scale) / LIS3_ACCURACY; flat = (flat * lis3_dev.scale) / LIS3_ACCURACY; input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns); lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns); lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns); err = input_register_polled_device(lis3_dev.idev); if (err) { input_free_polled_device(lis3_dev.idev); lis3_dev.idev = NULL; } return err; }
static int pega_accel_init(struct asus_laptop *asus) { int err; struct input_polled_dev *ipd; if (!asus->is_pega_lucid) return -ENODEV; if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) || acpi_check_handle(asus->handle, METHOD_XLRY, NULL) || acpi_check_handle(asus->handle, METHOD_XLRZ, NULL)) return -ENODEV; ipd = input_allocate_polled_device(); if (!ipd) return -ENOMEM; ipd->poll = pega_accel_poll; ipd->poll_interval = 125; ipd->poll_interval_min = 50; ipd->poll_interval_max = 2000; ipd->input->name = PEGA_ACCEL_DESC; ipd->input->phys = PEGA_ACCEL_NAME "/input0"; ipd->input->dev.parent = &asus->platform_device->dev; ipd->input->id.bustype = BUS_HOST; set_bit(EV_ABS, ipd->input->evbit); input_set_abs_params(ipd->input, ABS_X, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); input_set_abs_params(ipd->input, ABS_Y, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); input_set_abs_params(ipd->input, ABS_Z, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); err = input_register_polled_device(ipd); if (err) goto exit; asus->pega_accel_poll = ipd; return 0; exit: input_free_polled_device(ipd); return err; }
static int ams_input_enable(void) { struct input_dev *input; s8 x, y, z; int error; ams_sensors(&x, &y, &z); ams_info.xcalib = x; ams_info.ycalib = y; ams_info.zcalib = z; ams_info.idev = input_allocate_polled_device(); if (!ams_info.idev) return -ENOMEM; ams_info.idev->poll = ams_idev_poll; ams_info.idev->poll_interval = 25; input = ams_info.idev->input; input->name = "Apple Motion Sensor"; input->id.bustype = ams_info.bustype; input->id.vendor = 0; input->dev.parent = &ams_info.of_dev->dev; input_set_abs_params(input, ABS_X, -50, 50, 3, 0); input_set_abs_params(input, ABS_Y, -50, 50, 3, 0); input_set_abs_params(input, ABS_Z, -50, 50, 3, 0); set_bit(EV_ABS, input->evbit); set_bit(EV_KEY, input->evbit); set_bit(BTN_TOUCH, input->keybit); error = input_register_polled_device(ams_info.idev); if (error) { input_free_polled_device(ams_info.idev); ams_info.idev = NULL; return error; } joystick = 1; return 0; }
static int __init peaq_wmi_init(void) { if (!wmi_has_guid(PEAQ_DOLBY_BUTTON_GUID)) return -ENODEV; peaq_poll_dev = input_allocate_polled_device(); if (!peaq_poll_dev) return -ENOMEM; peaq_poll_dev->poll = peaq_wmi_poll; peaq_poll_dev->poll_interval = PEAQ_POLL_INTERVAL_MS; peaq_poll_dev->poll_interval_max = PEAQ_POLL_MAX_MS; peaq_poll_dev->input->name = "PEAQ WMI hotkeys"; peaq_poll_dev->input->phys = "wmi/input0"; peaq_poll_dev->input->id.bustype = BUS_HOST; input_set_capability(peaq_poll_dev->input, EV_KEY, KEY_SOUND); return input_register_polled_device(peaq_poll_dev); }
int lis3lv02d_joystick_enable(void) { struct input_dev *input_dev; int err; int max_val, fuzz, flat; if (lis3_dev.idev) return -EINVAL; lis3_dev.idev = input_allocate_polled_device(); if (!lis3_dev.idev) return -ENOMEM; lis3_dev.idev->poll = lis3lv02d_joystick_poll; lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; input_dev = lis3_dev.idev->input; input_dev->name = "ST LIS3LV02DL Accelerometer"; input_dev->phys = DRIVER_NAME "/input0"; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0; input_dev->dev.parent = &lis3_dev.pdev->dev; set_bit(EV_ABS, input_dev->evbit); max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_ACCURACY; flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_ACCURACY; input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); err = input_register_polled_device(lis3_dev.idev); if (err) { input_free_polled_device(lis3_dev.idev); lis3_dev.idev = NULL; } return err; }
int lis3lv02d_joystick_enable(void) { struct input_dev *input_dev; int err; if (lis3_dev.idev) return -EINVAL; lis3_dev.idev = input_allocate_polled_device(); if (!lis3_dev.idev) return -ENOMEM; lis3_dev.idev->poll = lis3lv02d_joystick_poll; lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; input_dev = lis3_dev.idev->input; lis3lv02d_calibrate_joystick(); input_dev->name = "ST LIS3LV02DL Accelerometer"; input_dev->phys = DRIVER_NAME "/input0"; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0; input_dev->dev.parent = &lis3_dev.pdev->dev; set_bit(EV_ABS, input_dev->evbit); input_set_abs_params(input_dev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); input_set_abs_params(input_dev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); input_set_abs_params(input_dev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); err = input_register_polled_device(lis3_dev.idev); if (err) { input_free_polled_device(lis3_dev.idev); lis3_dev.idev = NULL; } return err; }
/** * devm_input_allocate_polled_device - allocate managed polled device * @dev: device owning the polled device being created * * Returns prepared &struct input_polled_dev or %NULL. * * Managed polled input devices do not need to be explicitly unregistered * or freed as it will be done automatically when owner device unbinds * from * its driver (or binding fails). Once such managed polled device * is allocated, it is ready to be set up and registered in the same * fashion as regular polled input devices (using * input_register_polled_device() function). * * If you want to manually unregister and free such managed polled devices, * it can be still done by calling input_unregister_polled_device() and * input_free_polled_device(), although it is rarely needed. * * NOTE: the owner device is set up as parent of input device and users * should not override it. */ struct input_polled_dev *devm_input_allocate_polled_device(struct device *dev) { struct input_polled_dev *polldev; struct input_polled_devres *devres; devres = devres_alloc(devm_input_polldev_release, sizeof(*devres), GFP_KERNEL); if (!devres) return NULL; polldev = input_allocate_polled_device(); if (!polldev) { devres_free(devres); return NULL; } polldev->input->dev.parent = dev; polldev->devres_managed = true; devres->polldev = polldev; devres_add(dev, devres); return polldev; }
static int __devinit mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id) { int result; struct input_dev *idev; struct i2c_adapter *adapter; printk(KERN_INFO "mma7660 probe\n"); mma7660_i2c_client = client; adapter = to_i2c_adapter(client->dev.parent); result = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA); assert(result); /* Initialize the MMA7660 chip */ result = mma7660_init_client(client); assert(result==0); hwmon_dev = hwmon_device_register(&client->dev); assert(!(IS_ERR(hwmon_dev))); dev_info(&client->dev, "build time %s %s\n", __DATE__, __TIME__); /*input poll device register */ mma7660_idev = input_allocate_polled_device(); if (!mma7660_idev) { dev_err(&client->dev, "alloc poll device failed!\n"); result = -ENOMEM; return result; } mma7660_idev->poll = mma7660_dev_poll; mma7660_idev->poll_interval = POLL_INTERVAL; mma7660_idev->poll_interval_max = POLL_INTERVAL_MAX; idev = mma7660_idev->input; idev->name = MMA7660_DRV_NAME; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -512, 512, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -512, 512, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -512, 512, INPUT_FUZZ, INPUT_FLAT); result = input_register_polled_device(mma7660_idev); if (result) { dev_err(&client->dev, "register poll device failed!\n"); return result; } result = sysfs_create_group(&mma7660_idev->input->dev.kobj, &mma7660_attribute_group); //result = device_create_file(&mma7660_idev->input->dev, &dev_attr_enable); //result = device_create_file(&mma7660_idev->input->dev, &dev_attr_value); if(result) { dev_err(&client->dev, "create sys failed\n"); } #ifdef CONFIG_HAS_EARLYSUSPEND mma7660_data.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; mma7660_data.early_suspend.suspend = mma7660_early_suspend; mma7660_data.early_suspend.resume = mma7660_late_resume; register_early_suspend(&mma7660_data.early_suspend); mma7660_data.suspend_indator = 0; #endif return result; }
static int stmp3xxx_rotdec_probe(struct platform_device *pdev) { int rc = 0; /* save original state of HW_TIMROT_ROTCTRL */ rotctrl = HW_TIMROT_ROTCTRL_RD(); if (!(rotctrl & BM_TIMROT_ROTCTRL_ROTARY_PRESENT)) { dev_info(&pdev->dev, "No rotary decoder present\n"); rc = -ENODEV; goto err_rotdec_present; } else { /* I had to add some extra line breaks in here * to avoid lines >80 chars wide */ HW_TIMROT_ROTCTRL_WR( //BF_TIMROT_ROTCTRL_DIVIDER(0x0) | /* 32kHz divider - 1 */ BF_TIMROT_ROTCTRL_DIVIDER(0x0F) | /* 32/(15+1) = 2kHz sampling */ BF_TIMROT_ROTCTRL_OVERSAMPLE( BV_TIMROT_ROTCTRL_OVERSAMPLE__2X) | BF_TIMROT_ROTCTRL_SELECT_B( BV_TIMROT_ROTCTRL_SELECT_B__ROTARYB) | BF_TIMROT_ROTCTRL_SELECT_A( BV_TIMROT_ROTCTRL_SELECT_A__ROTARYA) ); HW_TIMROT_ROTCTRL_CLR( BM_TIMROT_ROTCTRL_POLARITY_B | BM_TIMROT_ROTCTRL_POLARITY_A ); if (!absolute) HW_TIMROT_ROTCTRL_SET(BM_TIMROT_ROTCTRL_RELATIVE); else HW_TIMROT_ROTCTRL_CLR(BM_TIMROT_ROTCTRL_RELATIVE); rc = rotdec_pinmux_request(); if (rc) { dev_err(&pdev->dev, "Pin request failed (err=%d)\n", rc); goto err_pinmux; } /* set up input_polled_dev */ rotdec = input_allocate_polled_device(); if (!rotdec) { dev_err(&pdev->dev, "Unable to allocate polled device\n"); rc = -ENOMEM; goto err_alloc_polldev; } rotdec->flush = stmp3xxx_rotdec_flush; rotdec->poll = stmp3xxx_rotdec_poll; rotdec->poll_interval = poll_interval; /* msec */ rotdec->input->name = "stmp3xxx-rotdec"; if (!absolute) input_set_capability(rotdec->input, EV_REL, REL_WHEEL); else { input_set_capability(rotdec->input, EV_ABS, ABS_WHEEL); input_set_abs_params(rotdec->input, ABS_WHEEL, -32768, 32767, 0, 0); } rc = input_register_polled_device(rotdec); if (rc) { dev_err(&pdev->dev, "Unable to register rotary decoder (err=%d)\n", rc); goto err_reg_polldev; } previous_state = (HW_TIMROT_ROTCTRL_RD()&BM_TIMROT_ROTCTRL_STATE)>>BP_TIMROT_ROTCTRL_STATE; } return 0; err_reg_polldev: input_free_polled_device(rotdec); err_alloc_polldev: rotdec_pinmux_free(); err_pinmux: /* restore original register state */ HW_TIMROT_ROTCTRL_WR(rotctrl); err_rotdec_present: return rc; }
/******************************************************************************* ** Implement For Scalar Platform Driver ** ** ********************************************************************************/ static int __devinit scalarpolicy_probe(struct platform_device *pdev) { int ret; int i; printk ("ScalarPolicy_init -- scalarpolicy_probe\n"); misc_scalar_dev.parent = &pdev->dev; ret = misc_register(&misc_scalar_dev); if (0 != ret) { printk ("ScalarPolicy_init -- misc_register fail\n"); return -EIO; } ScalarPolicy_dev = input_allocate_polled_device(); if (NULL == ScalarPolicy_dev) { printk ("ScalarPolicy_init -- allocdev fail\n"); return -ENOMEM; } //bob+[ spi = kzalloc(sizeof(struct sclar_pm_info), GFP_KERNEL); if (!spi) return -ENOMEM; wake_lock_init(&spi->wake_lock, WAKE_LOCK_SUSPEND, "scalar_policy"); //bob+] ScalarPolicy_dev->poll = ScalarPolicy_poll; ScalarPolicy_dev->poll_interval = INP_KEYCODE_INTERVAL; ScalarPolicy_dev->input->evbit[0] = BIT_MASK(EV_KEY);// | BIT_MASK(EV_REP); ScalarPolicy_dev->input->name = "ScalarPolicy"; ScalarPolicy_dev->input->phys = "Scalar/input0"; ScalarPolicy_dev->input->id.bustype = BUS_HOST; ScalarPolicy_dev->input->id.vendor = 0xBABE; ScalarPolicy_dev->input->id.product = 0xBEEF; ScalarPolicy_dev->input->id.version = 0xDEDA; ScalarPolicy_dev->input->keycode = keycode; ScalarPolicy_dev->input->keycodesize = sizeof(unsigned char); ScalarPolicy_dev->input->keycodemax = sizeof(keycode); for (i = 0; i < sizeof(keycode); i++) { set_bit(keycode[i], ScalarPolicy_dev->input->keybit); } //printk ("ScalarPolicy_init -- input_register_polled_device\n"); ret = input_register_polled_device(ScalarPolicy_dev); if (0 != ret) { printk ("ScalarPolicy_init -- input_register_device fail\n"); wake_lock_destroy(&spi->wake_lock); //bob+ return -EIO; } wake_lock(&spi->wake_lock); //bob+ return 0; }
static int __devinit mag3110_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter; struct input_dev *idev; struct mag3110_data *data; int ret = 0; adapter = to_i2c_adapter(client->dev.parent); if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; dev_info(&client->dev, "check mag3110 chip ID\n"); ret = mag3110_read_reg(client, MAG3110_WHO_AM_I); if (MAG3110_ID != ret) { dev_err(&client->dev, "read chip ID 0x%x is not equal to 0x%x!\n", ret, MAG3110_ID); return -EINVAL; } data = kzalloc(sizeof(struct mag3110_data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; i2c_set_clientdata(client, data); /* Init queue */ init_waitqueue_head(&data->waitq); data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { dev_err(&client->dev, "hwmon register failed!\n"); ret = PTR_ERR(data->hwmon_dev); goto error_rm_dev_sysfs; } /*input poll device register */ data->poll_dev = input_allocate_polled_device(); if (!data->poll_dev) { dev_err(&client->dev, "alloc poll device failed!\n"); ret = -ENOMEM; goto error_rm_hwmon_dev; } data->poll_dev->poll = mag3110_dev_poll; data->poll_dev->poll_interval = POLL_INTERVAL; data->poll_dev->poll_interval_max = POLL_INTERVAL_MAX; idev = data->poll_dev->input; idev->name = MAG3110_DRV_NAME; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -15000, 15000, 0, 0); input_set_abs_params(idev, ABS_Y, -15000, 15000, 0, 0); input_set_abs_params(idev, ABS_Z, -15000, 15000, 0, 0); ret = input_register_polled_device(data->poll_dev); if (ret) { dev_err(&client->dev, "register poll device failed!\n"); goto error_free_poll_dev; } /*create device group in sysfs as user interface */ ret = sysfs_create_group(&idev->dev.kobj, &mag3110_attr_group); if (ret) { dev_err(&client->dev, "create device file failed!\n"); ret = -EINVAL; goto error_rm_poll_dev; } /* set irq type to edge rising */ #if MAG3110_IRQ_USED ret = request_irq(client->irq, mag3110_irq_handler, IRQF_TRIGGER_RISING, client->dev.driver->name, idev); if (ret < 0) { dev_err(&client->dev, "failed to register irq %d!\n", client->irq); goto error_rm_dev_sysfs; } #endif /* Initialize mag3110 chip */ mag3110_init_client(client); mag3110_pdata = data; mag3110_pdata->active = MAG_STANDBY; mag3110_pdata->position = *(int *)client->dev.platform_data; dev_info(&client->dev, "mag3110 is probed\n"); return 0; error_rm_dev_sysfs: sysfs_remove_group(&client->dev.kobj, &mag3110_attr_group); error_rm_poll_dev: input_unregister_polled_device(data->poll_dev); error_free_poll_dev: input_free_polled_device(data->poll_dev); error_rm_hwmon_dev: hwmon_device_unregister(data->hwmon_dev); kfree(data); mag3110_pdata = NULL; return ret; }
static int __devinit mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id) { //printk(KERN_INFO "Linda mma7660_probe start ! 111111111111111111111111111111111\n"); int result; //struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct input_dev *idev; struct i2c_adapter *adapter; mma7660_i2c_client = client; adapter = to_i2c_adapter(client->dev.parent); result = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA); assert(result); /* Initialize the MMA7660 chip */ result = mma7660_init_client(client); //printk(KERN_INFO "Linda mma7660_init_client ! 111111111111111111111111111111111\n"); assert(result==0); result = sysfs_create_group(&client->dev.kobj, &mma7660_group); assert(result==0); hwmon_dev = hwmon_device_register(&client->dev); assert(!(IS_ERR(hwmon_dev))); dev_info(&client->dev, "build time %s %s\n", __DATE__, __TIME__); //printk(KERN_INFO "Linda test 111111111111111111111111111111111\n"); /*input poll device register */ mma7660_idev = input_allocate_polled_device(); if (!mma7660_idev) { dev_err(&client->dev, "alloc poll device failed!\n"); result = -ENOMEM; return result; } mma7660_idev->poll = mma7660_dev_poll; mma7660_idev->poll_interval = POLL_INTERVAL; mma7660_idev->poll_interval_max = POLL_INTERVAL_MAX; idev = mma7660_idev->input; idev->name = MMA7660_DRV_NAME; idev->id.bustype = BUS_I2C; idev->dev.parent = &client->dev; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -512, 512, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -512, 512, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -512, 512, INPUT_FUZZ, INPUT_FLAT); result = input_register_polled_device(mma7660_idev); if (result) { dev_err(&client->dev, "register poll device failed!\n"); return result; } ////////////////////////////// //a7660_enter_suspend(); ////////////////////////////// //Encryp_main(); //////////////////////// return result; }
static int mma8451_probe(struct i2c_client *client, const struct i2c_device_id *id) { int result; struct input_dev *idev; struct i2c_adapter *adapter; u32 pos; struct device_node *of_node = client->dev.of_node; struct regulator *vdd, *vdd_io; mma8451_i2c_client = client; vdd = devm_regulator_get(&client->dev, "vdd"); if (!IS_ERR(vdd)) { result = regulator_enable(vdd); if (result) { dev_err(&client->dev, "vdd set voltage error\n"); return result; } } vdd_io = devm_regulator_get(&client->dev, "vddio"); if (!IS_ERR(vdd_io)) { result = regulator_enable(vdd_io); if (result) { dev_err(&client->dev, "vddio set voltage error\n"); return result; } } adapter = to_i2c_adapter(client->dev.parent); result = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA); if (!result) goto err_out; client_id = i2c_smbus_read_byte_data(client, MMA8451_WHO_AM_I); if (client_id != MMA8451_ID && client_id != MMA8452_ID && client_id != MMA8453_ID && client_id != FXOS8700_ID) { dev_err(&client->dev, "read chip ID 0x%x is not equal to 0x%x,0x%x,0x%x!\n", result, MMA8451_ID, MMA8452_ID, FXOS8700_ID); result = -EINVAL; goto err_out; } /* Initialize the MMA8451 chip */ result = mma8451_change_mode(client, senstive_mode); if (result) { dev_err(&client->dev, "error when init mma8451 chip:(%d)\n", result); goto err_out; } hwmon_dev = hwmon_device_register(&client->dev); if (!hwmon_dev) { result = -ENOMEM; dev_err(&client->dev, "error when register hwmon device\n"); goto err_out; } /* create a polled input device for accelerometer */ mma8451_idev = input_allocate_polled_device(); if (!mma8451_idev) { result = -ENOMEM; dev_err(&client->dev, "alloc poll device failed!\n"); goto err_register_polled_device; } mma8451_idev->poll = mma8451_dev_poll; mma8451_idev->poll_interval = POLL_INTERVAL; mma8451_idev->poll_interval_min = POLL_INTERVAL_MIN; mma8451_idev->poll_interval_max = POLL_INTERVAL_MAX; idev = mma8451_idev->input; if (client_id == FXOS8700_ID) idev->name = "mma845x_a"; else idev->name = "mma845x"; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); result = input_register_polled_device(mma8451_idev); if (result) { dev_err(&client->dev, "register poll device failed!\n"); goto err_register_polled_device; } result = sysfs_create_group(&idev->dev.kobj, &mma8451_attr_group); if (result) { dev_err(&client->dev, "create device file failed!\n"); result = -EINVAL; goto err_register_polled_device; } /* create a polled input device for magnetometer */ if (client_id == FXOS8700_ID) { fxos8700_m_idev = input_allocate_polled_device(); if (!fxos8700_m_idev) { result = -ENOMEM; dev_err(&client->dev, "alloc poll device failed!\n"); goto err_alloc_poll_device; } fxos8700_m_idev->poll = mma8451_dev_poll; fxos8700_m_idev->poll_interval = POLL_INTERVAL; fxos8700_m_idev->poll_interval_min = POLL_INTERVAL_MIN; fxos8700_m_idev->poll_interval_max = POLL_INTERVAL_MAX; idev = fxos8700_m_idev->input; idev->name = "fxos8700_m"; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); result = input_register_polled_device(fxos8700_m_idev); if (result) { dev_err(&client->dev, "register poll device failed!\n"); goto err_register_polled_device1; } result = sysfs_create_group(&idev->dev.kobj, &mma8451_attr_group); if (result) { dev_err(&client->dev, "create device file failed!\n"); result = -EINVAL; goto err_create_sysfs1; } } result = of_property_read_u32(of_node, "position", &pos); if (result) pos = DEFAULT_POSITION; mma_status.position = (int)pos; return 0; err_create_sysfs1: input_unregister_polled_device(fxos8700_m_idev); err_register_polled_device1: input_free_polled_device(fxos8700_m_idev); err_register_polled_device: input_free_polled_device(mma8451_idev); err_alloc_poll_device: hwmon_device_unregister(&client->dev); err_out: return result; }
static int mag3110_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter; struct input_dev *idev; struct mag3110_data *data; int ret = 0; struct regulator *vdd, *vdd_io; u32 pos = 0; struct device_node *of_node = client->dev.of_node; #if MAG3110_IRQ_USED struct irq_data *irq_data = irq_get_irq_data(client->irq); u32 irq_flag; bool shared_irq = of_property_read_bool(of_node, "shared-interrupt"); #endif vdd = NULL; vdd_io = NULL; vdd = devm_regulator_get(&client->dev, "vdd"); if (!IS_ERR(vdd)) { ret = regulator_enable(vdd); if (ret) { dev_err(&client->dev, "vdd set voltage error\n"); return ret; } } vdd_io = devm_regulator_get(&client->dev, "vddio"); if (!IS_ERR(vdd_io)) { ret = regulator_enable(vdd_io); if (ret) { dev_err(&client->dev, "vddio set voltage error\n"); return ret; } } adapter = to_i2c_adapter(client->dev.parent); if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; dev_info(&client->dev, "check mag3110 chip ID\n"); ret = mag3110_read_reg(client, MAG3110_WHO_AM_I); if (MAG3110_ID != ret) { dev_err(&client->dev, "read chip ID 0x%x is not equal to 0x%x!\n", ret, MAG3110_ID); return -EINVAL; } data = kzalloc(sizeof(struct mag3110_data), GFP_KERNEL); if (!data) return -ENOMEM; data->client = client; i2c_set_clientdata(client, data); /* Init queue */ init_waitqueue_head(&data->waitq); data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { dev_err(&client->dev, "hwmon register failed!\n"); ret = PTR_ERR(data->hwmon_dev); goto error_rm_dev_sysfs; } /*input poll device register */ data->poll_dev = input_allocate_polled_device(); if (!data->poll_dev) { dev_err(&client->dev, "alloc poll device failed!\n"); ret = -ENOMEM; goto error_rm_hwmon_dev; } data->poll_dev->poll = mag3110_dev_poll; data->poll_dev->poll_interval = POLL_INTERVAL; data->poll_dev->poll_interval_max = POLL_INTERVAL_MAX; idev = data->poll_dev->input; idev->name = MAG3110_DRV_NAME; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -15000, 15000, 0, 0); input_set_abs_params(idev, ABS_Y, -15000, 15000, 0, 0); input_set_abs_params(idev, ABS_Z, -15000, 15000, 0, 0); ret = input_register_polled_device(data->poll_dev); if (ret) { dev_err(&client->dev, "register poll device failed!\n"); goto error_free_poll_dev; } /*create device group in sysfs as user interface */ ret = sysfs_create_group(&idev->dev.kobj, &mag3110_attr_group); if (ret) { dev_err(&client->dev, "create device file failed!\n"); ret = -EINVAL; goto error_rm_poll_dev; } #if MAG3110_IRQ_USED irq_flag = irqd_get_trigger_type(irq_data); irq_flag |= IRQF_ONESHOT; if (shared_irq) irq_flag |= IRQF_SHARED; ret = request_threaded_irq(client->irq, NULL, mag3110_irq_handler, irq_flag, client->dev.driver->name, idev); if (ret < 0) { dev_err(&client->dev, "failed to register irq %d!\n", client->irq); goto error_rm_dev_sysfs; } #endif /* Initialize mag3110 chip */ mag3110_init_client(client); mag3110_pdata = data; mag3110_pdata->active = MAG_STANDBY; ret = of_property_read_u32(of_node, "position", &pos); if (ret) pos = DEFAULT_POSITION; mag3110_pdata->position = (int)pos; dev_info(&client->dev, "mag3110 is probed\n"); return 0; error_rm_dev_sysfs: sysfs_remove_group(&client->dev.kobj, &mag3110_attr_group); error_rm_poll_dev: input_unregister_polled_device(data->poll_dev); error_free_poll_dev: input_free_polled_device(data->poll_dev); error_rm_hwmon_dev: hwmon_device_unregister(data->hwmon_dev); kfree(data); mag3110_pdata = NULL; return ret; }
static int __devinit mc32x0_probe(struct i2c_client *client, const struct i2c_device_id *id) { int result; struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct input_dev *idev; #if DEBUG printk("probing mc32x0 \n"); #endif mutex_init(&sensor_lock); result = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE|I2C_FUNC_SMBUS_BYTE_DATA); assert(result); /* Initialize the MC32X0 chip */ result = mc32x0_init_client(client); assert(result==0); result = sysfs_create_group(&client->dev.kobj, &mc32x0_group); assert(result==0); hwmon_dev = hwmon_device_register(&client->dev); assert(!(IS_ERR(hwmon_dev))); dev_info(&client->dev, "build time %s %s\n", __DATE__, __TIME__); /*input poll device register */ mc32x0_idev = input_allocate_polled_device(); if (!mc32x0_idev) { dev_err(&client->dev, "alloc poll device failed!\n"); result = -ENOMEM; return result; } mc32x0_idev->poll = mc32x0_dev_poll; mc32x0_idev->poll_interval = poll_interval = DEFAULT_POLL_INTERVAL; idev = mc32x0_idev->input; idev->name = MC32X0_DRV_NAME; idev->id.bustype = BUS_I2C; idev->dev.parent = &client->dev; idev->evbit[0] = BIT_MASK(EV_ABS); //change the param by simon.wang,2012-04-09 //to enhance the sensititity input_set_abs_params(idev, ABS_X, -MAX_ABS_X, MAX_ABS_X, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -MAX_ABS_Y, MAX_ABS_Y, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -MAX_ABS_Z, MAX_ABS_Z, INPUT_FUZZ, INPUT_FLAT); //input_set_abs_params(idev, ABS_THROTTLE, -MAX_ABS_THROTTLE, MAX_ABS_THROTTLE, INPUT_FUZZ, INPUT_FLAT);//if necessary? #if DEBUG printk("***** Sensor MC32X0 param: max_abs_x = %d,max_abs_y = %d,max_abs_z = %d \ INPUT_FUZZ = %d,INPUT_FLAT = %d\n",MAX_ABS_X,MAX_ABS_Y,MAX_ABS_Y,INPUT_FUZZ,INPUT_FLAT); #endif result = input_register_polled_device(mc32x0_idev); result = sysfs_create_group(&mc32x0_idev->input->dev.kobj, &mc32x0_attribute_group); assert(result==0); if (result) { dev_err(&client->dev, "register poll device failed!\n"); return result; } return result; }
static int __init alps_init(void) { struct input_dev *idev; int ret; flgM = 0; flgA = 0; probeA = PROBE_FAIL; probeM = PROBE_FAIL; ret = platform_driver_register(&alps_driver); if (ret) goto out_region; pr_info("alps-init: platform_driver_register\n"); mutex_init(&alps_lock); pdev = platform_device_register_simple("alps", -1, NULL, 0); if (IS_ERR(pdev)) { ret = PTR_ERR(pdev); goto out_driver; } pr_info("alps-init: platform_device_register_simple\n"); ret = sysfs_create_group(&pdev->dev.kobj, &alps_attribute_group); if (ret) goto out_device; pr_info("alps-init: sysfs_create_group\n"); alps_idev = input_allocate_polled_device(); if (!alps_idev) { ret = -ENOMEM; goto out_group; } pr_info("alps-init: input_allocate_polled_device\n"); alps_idev->poll = alps_poll; alps_idev->poll_interval = ALPS_POLL_INTERVAL; /* initialize the input class */ idev = alps_idev->input; idev->name = "alps"; idev->phys = "alps/input0"; idev->id.bustype = BUS_HOST; idev->dev.parent = &pdev->dev; idev->evbit[0] = BIT_MASK(EV_ABS); #if defined(CONFIG_SENSORS_BMA222E) || defined(CONFIG_SENSORS_BMA222) || defined(CONFIG_SENSORS_K2DH) input_set_abs_params(idev, EVENT_TYPE_ACCEL_X, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_ACCEL_Y, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_ACCEL_Z, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); #endif #if defined(CONFIG_SENSORS_HSCDTD006A) || defined(CONFIG_SENSORS_HSCDTD008A) input_set_abs_params(idev, EVENT_TYPE_MAGV_X, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Y, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Z, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); #endif ret = input_register_polled_device(alps_idev); if (ret) goto out_idev; pr_info("alps-init: input_register_polled_device\n"); ret = misc_register(&alps_device); if (ret) { pr_info("alps-init: alps_io_device register failed\n"); goto exit_misc_device_register_failed; } pr_info("alps-init: misc_register\n"); return 0; exit_misc_device_register_failed: out_idev: input_free_polled_device(alps_idev); pr_info("alps-init: input_free_polled_device\n"); out_group: sysfs_remove_group(&pdev->dev.kobj, &alps_attribute_group); pr_info("alps-init: sysfs_remove_group\n"); out_device: platform_device_unregister(pdev); pr_info("alps-init: platform_device_unregister\n"); out_driver: platform_driver_unregister(&alps_driver); pr_info("alps-init: platform_driver_unregister\n"); mutex_destroy(&alps_lock); out_region: return ret; }
/** * Probe implementation * Inits the character device and completes the I2C driver initialization * @return 0 in success, or negative error code */ static int accel_probe(struct i2c_client *client, const struct i2c_device_id *id) { int err=-ENOMEM; struct input_dev *idev; struct input_polled_dev *ipdev; struct platform_device *pdev; if (!i2c_check_functionality (client->adapter, I2C_FUNC_I2C)) { fprintk ("I2C function is not supported"); return -ENOTSUPP; } memset (&accel_info, 0, sizeof (accel_data_t)); accel_info.magic = ACCEL_MAGIC; accel_info.irq1 = accel_info.irq2 = -1; mutex_init (&accel_info.mlock); mutex_init (&pl); atomic_set (&accel_info.data_ready_enabled, 0); accel_info.i2c = client; i2c_set_clientdata (client, &accel_info); if (accel_i2c_who_am_i () != ACCEL_I_AM_THE_ONE) { fprintk ("I2C device with address 0x%x is not LIS331DLH", client->addr); err = -ENODEV; goto exit; }else { vprintk ("I2C device with address 0x%x is LIS331DLH accelerometer", client->addr); } INIT_WORK (&accel_info.wq1, accel_irq_bottom_half); #ifdef ACCEL_DATA_READY_IRQ INIT_WORK (&accel_info.wq2, accel_irq_data_ready_bottom_half); #endif // sema_init (&accel_info.sema1, 1); // sema_init (&accel_info.sema2, 1); pdev = (struct platform_device *)client->dev.platform_data; /* * IRQ field contain information about swapped axes */ accel_param_swapped = pdev->id; fprintk ("swapped axes parameter 0x%02x", accel_param_swapped); if (pdev && pdev->num_resources && ! strcmp(pdev->name, "stmicro")) { struct resource *resource; vprintk ("platform data for '%s', num_resources %d", pdev->name, pdev->num_resources); resource = platform_get_resource (pdev, IORESOURCE_IRQ, 0); if (resource) { accel_gpio_one = resource->start; accel_gpio_two = resource->end; accel_irq_config_edge (&accel_info.irq1, accel_gpio_one, ACCEL_IRQ_INT1, (void *)&accel_info.irq1_cnt, accel_irq_handler); #ifdef ACCEL_DATA_READY_IRQ accel_irq_config_high (&accel_info.irq2, accel_gpio_two, ACCEL_IRQ_INT2, (void *)&accel_info.irq2_cnt, accel_irq_data_ready_handler); #endif } else { fprintk ("unable to obtain GPIO information; no IRQ support"); } } else { fprintk ("platform data has no resources declared; no IRQ support"); } if (accel_param_input) { /* take care of input device here */ ipdev = input_allocate_polled_device (); if (! ipdev) { fprintk ("failed to allocate input device structure"); err = -ENOMEM; goto exit_irqs; } ipdev->poll_interval = (int)-1; ipdev->poll = accel_poll_data_ready; idev = ipdev->input; idev->name = "accelerometer"; idev->id.bustype = BUS_I2C; idev->id.vendor = 0; idev->id.product = ACCEL_I_AM_THE_ONE; accel_info.idev = idev; accel_info.ipdev = ipdev; set_bit (EV_ABS, idev->evbit); set_bit (EV_SW, idev->evbit); set_bit (6, idev->swbit); input_report_switch (idev, 6, TOGGLE_OFF); accel_input_params (idev, ABS_X, 3, ACCEL_2G_MAX); accel_input_params (idev, ABS_RX, 3, ACCEL_2G_MAX); accel_input_params (idev, ABS_TILT_X, 2, ACCEL_2G_MAX); if ((err = input_register_polled_device (ipdev))) { fprintk ("failed to register input device"); goto exit_input; } } fprintk ("registered input device accelerometer\n"); atomic_set (&accel_info.mode, 0); atomic_set (&accel_info.odr, 0); atomic_set (&accel_info.g_range, 1); // 4G accel_i2c_set_config (0, 0, 0, -1); /* create misc device and /dev/accelerometer file */ if (misc_register (&accel_misc_driver)) { fprintk("can't register misc. device"); goto exit_input; } fprintk ("registered misc device\n"); /* Turn power on if forced to do so */ if (accel_param_power) { /*enable all axises */ accel_i2c_enable_axis (AXIS_XYZ); /* aplly power settings */ accel_i2c_set_power_mode (accel_param_power); } /* Register sysfs hooks */ if ((err = sysfs_create_group (&client->dev.kobj, &accel_defattr_group))) { fprintk ("failed to create a sysfs group"); goto exit_input; } fprintk ("created sysfs group\n"); #ifdef CONFIG_HAS_EARLYSUSPEND accel_info.early_suspend.suspend = accel_early_suspend; accel_info.early_suspend.resume = accel_early_resume; register_early_suspend (&(accel_info.early_suspend)); #endif printk (KERN_INFO "%s: driver probed successfully\n", __func__); return SUCCESS; exit_input: if (accel_info.ipdev) { input_free_polled_device (accel_info.ipdev); accel_info.ipdev = NULL; } exit_irqs: if (accel_info.irq1 > 0) { gpio_free (accel_gpio_one); free_irq (accel_info.irq1, (void *)&accel_info.irq1_cnt); } #ifdef ACCEL_DATA_READY_IRQ if (accel_info.irq2 > 0) { gpio_free (accel_gpio_two); free_irq (accel_info.irq2, (void *)&accel_info.irq2_cnt); } #endif exit: return err; }
static int __init alps_init(void) { int ret; alps_info("is called\n"); ret = platform_driver_register(&alps_driver); if (ret) goto out_region; alps_dbgmsg("platform_driver_register\n"); pdev = platform_device_register_simple("alps_compass", -1, NULL, 0); if (IS_ERR(pdev)) { ret = PTR_ERR(pdev); goto out_driver; } alps_dbgmsg("platform_device_register_simple\n"); alps_idev = input_allocate_polled_device(); if (!alps_idev) { ret = -ENOMEM; goto out_device; } alps_dbgmsg("input_allocate_polled_device\n"); alps_idev->poll = alps_poll; alps_idev->poll_interval = ALPS_POLL_INTERVAL; /* initialize the input class */ idev = alps_idev->input; idev->name = "magnetic_sensor"; //idev->phys = "alps_compass/input0"; idev->id.bustype = BUS_I2C; //idev->dev.parent = &pdev->dev; //idev->evbit[0] = BIT_MASK(EV_ABS); set_bit(EV_REL, idev->evbit); input_set_capability(idev, EV_REL, REL_X); input_set_capability(idev, EV_REL, REL_Y); input_set_capability(idev, EV_REL, REL_Z); #if 0//defined(MAG_15BIT) input_set_abs_params(idev, EVENT_TYPE_MAGV_X, -16384, 16383, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Y, -16384, 16383, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Z, -16384, 16383, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); //#elif defined(MAG_13BIT) input_set_abs_params(idev, EVENT_TYPE_MAGV_X, -4096, 4095, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Y, -4096, 4095, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Z, -4096, 4095, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); #endif ret = input_register_polled_device(alps_idev); if (ret) goto out_alc_poll; alps_dbgmsg("input_register_polled_device\n"); ret = misc_register(&alps_device); if (ret) { alps_info("alps_io_device register failed\n"); goto out_reg_poll; } alps_dbgmsg("misc_register\n"); ret = sysfs_create_group(&idev->dev.kobj, &magnetic_attribute_group); #if defined(CONFIG_SENSOR_USE_SYMLINK) ret = sensors_initialize_symlink(alps_idev->input); if (ret < 0) { pr_err("%s: apls_sensors_initialize_symlink error(%d).\n", __func__, ret); goto out_reg_poll; } #endif #ifdef CONFIG_HAS_EARLYSUSPEND register_early_suspend(&alps_early_suspend_handler); alps_dbgmsg("register_early_suspend\n"); #endif mutex_lock(&alps_lock); flg_suspend = 0; mutex_unlock(&alps_lock); return 0; out_reg_poll: input_unregister_polled_device(alps_idev); alps_info("input_unregister_polled_device\n"); out_alc_poll: input_free_polled_device(alps_idev); alps_info("input_free_polled_device\n"); out_device: platform_device_unregister(pdev); alps_info("platform_device_unregister\n"); out_driver: platform_driver_unregister(&alps_driver); alps_info("platform_driver_unregister\n"); out_region: return ret; }
static int __init alps_init(void) { struct input_dev *idev; int ret; printk(KERN_INFO "[ALPS] alps_init\n"); flgM = 0; flgA = 0; ret = platform_driver_register(&alps_driver); if (ret) goto out_region; printk(KERN_INFO "[ALPS] platform_driver_register\n"); pdev = platform_device_register_simple("alps", -1, NULL, 0); if (IS_ERR(pdev)) { ret = PTR_ERR(pdev); goto out_driver; } printk(KERN_INFO "[ALPS] platform_device_register_simple\n"); ret = sysfs_create_group(&pdev->dev.kobj, &alps_attribute_group); if (ret) goto out_device; printk(KERN_INFO "[ALPS] sysfs_create_group\n"); alps_idev = input_allocate_polled_device(); if (!alps_idev) { ret = -ENOMEM; goto out_group; } printk(KERN_INFO "[ALPS] input_allocate_polled_device\n"); alps_idev->poll = alps_poll; alps_idev->poll_interval = ALPS_POLL_INTERVAL; /* initialize the input class */ idev = alps_idev->input; idev->name = "magnetic_sensor"; idev->phys = "alps/input2"; idev->id.bustype = BUS_HOST; idev->dev.parent = &pdev->dev; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, EVENT_TYPE_ACCEL_X, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_ACCEL_Y, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_ACCEL_Z, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_X, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Y, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); input_set_abs_params(idev, EVENT_TYPE_MAGV_Z, -4096, 4096, ALPS_INPUT_FUZZ, ALPS_INPUT_FLAT); ret = input_register_polled_device(alps_idev); if (ret) goto out_idev; printk(KERN_INFO "[ALPS] input_register_polled_device\n"); ret = misc_register(&alps_device); if (ret) { printk(KERN_ERR "[ALPS] alps_io_device register failed\n"); goto exit_misc_device_register_failed; } printk(KERN_INFO "[ALPS] misc_register\n"); return 0; exit_misc_device_register_failed: out_idev: input_free_polled_device(alps_idev); printk(KERN_ERR "[ALPS] input_free_polled_device\n"); out_group: sysfs_remove_group(&pdev->dev.kobj, &alps_attribute_group); printk(KERN_ERR "[ALPS] sysfs_remove_group\n"); out_device: platform_device_unregister(pdev); printk(KERN_ERR "[ALPS] platform_device_unregister\n"); out_driver: platform_driver_unregister(&alps_driver); printk(KERN_ERR "[ALPS] platform_driver_unregister\n"); out_region: return ret; }
static int __devinit mma8452_probe(struct i2c_client *client, const struct i2c_device_id *id) { int result, client_id; struct input_dev *idev; struct i2c_adapter *adapter; struct mma8452_data *mma; const struct mma8452_platform_data *pdata = client->dev.platform_data; if (!pdata) { dev_err(&client->dev, "platform data for layout is NULL; exiting\n"); return -EINVAL; } /* Allocate memory for driver data */ mma = kzalloc(sizeof(struct mma8452_data), GFP_KERNEL); if (!mma) { printk(KERN_ERR "mma8452_probe: memory allocation failed.\n"); return -ENOMEM; } mma8452_i2c_client = client; printk(SENSOR_TAG "come into %s\n",__FUNCTION__); adapter = to_i2c_adapter(client->dev.parent); result = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA); if (!result) goto err_out; else printk(SENSOR_TAG "i2c_check_functionality() was called success\n"); client_id = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I); if (client_id != MMA8452_ID && client_id != MMA8452_ID) { dev_err(&client->dev, "read chip ID 0x%x is not equal to 0x%x or 0x%x!\n", result, MMA8452_ID, MMA8452_ID); printk(SENSOR_TAG "I2C read error\n"); result = -EINVAL; goto err_out; }else{ printk(SENSOR_TAG "read chip ID is :0x%x\n",client_id); } /* Initialize the MMA8452 chip */ result = mma8452_change_mode(client, senstive_mode); if (result) { dev_err(&client->dev, "error when init mma8452 chip:(%d)\n", result); goto err_out; } hwmon_dev = hwmon_device_register(&client->dev); if (!hwmon_dev) { result = -ENOMEM; dev_err(&client->dev, "error when register hwmon device\n"); goto err_out; } mma8452_idev = input_allocate_polled_device(); if (!mma8452_idev) { result = -ENOMEM; dev_err(&client->dev, "alloc poll device failed!\n"); goto err_alloc_poll_device; } mma8452_idev->poll = mma8452_dev_poll; mma8452_idev->poll_interval = POLL_INTERVAL; mma8452_idev->poll_interval_min = POLL_INTERVAL_MIN; mma8452_idev->poll_interval_max = POLL_INTERVAL_MAX; idev = mma8452_idev->input; if (client_id == MMA8452_ID) idev->name = "mma8452"; else idev->name = "mma8452"; idev->id.bustype = BUS_I2C; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); input_set_abs_params(idev, ABS_Z, -8192, 8191, INPUT_FUZZ, INPUT_FLAT); result = input_register_polled_device(mma8452_idev); if (result) { dev_err(&client->dev, "register poll device failed!\n"); goto err_register_polled_device; } mma->mma_early_suspend.suspend = mma8452_early_suspend; mma->mma_early_suspend.resume = mma8452_early_resume; register_early_suspend(&mma->mma_early_suspend); result = sysfs_create_group(&idev->dev.kobj, &mma8452_attr_group); if (result) { dev_err(&client->dev, "create device file failed!\n"); result = -EINVAL; goto err_register_polled_device; } mma_status.position = (*pdata).axis_map_cordination; return 0; err_register_polled_device: input_free_polled_device(mma8452_idev); err_alloc_poll_device: hwmon_device_unregister(&client->dev); err_out: return result; }
static int __init hdaps_init(void) { struct input_dev *idev; int ret; if (!dmi_check_system(hdaps_whitelist)) { printk(KERN_WARNING "hdaps: supported laptop not found!\n"); ret = -ENODEV; goto out; } if (!request_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS, "hdaps")) { ret = -ENXIO; goto out; } ret = platform_driver_register(&hdaps_driver); if (ret) goto out_region; pdev = platform_device_register_simple("hdaps", -1, NULL, 0); if (IS_ERR(pdev)) { ret = PTR_ERR(pdev); goto out_driver; } ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group); if (ret) goto out_device; hdaps_idev = input_allocate_polled_device(); if (!hdaps_idev) { ret = -ENOMEM; goto out_group; } hdaps_idev->poll = hdaps_mousedev_poll; hdaps_idev->poll_interval = HDAPS_POLL_INTERVAL; hdaps_calibrate(); idev = hdaps_idev->input; idev->name = "hdaps"; idev->phys = "isa1600/input0"; idev->id.bustype = BUS_ISA; idev->dev.parent = &pdev->dev; idev->evbit[0] = BIT_MASK(EV_ABS); input_set_abs_params(idev, ABS_X, -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); input_set_abs_params(idev, ABS_Y, -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); ret = input_register_polled_device(hdaps_idev); if (ret) goto out_idev; printk(KERN_INFO "hdaps: driver successfully loaded.\n"); return 0; out_idev: input_free_polled_device(hdaps_idev); out_group: sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); out_device: platform_device_unregister(pdev); out_driver: platform_driver_unregister(&hdaps_driver); out_region: release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS); out: printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret); return ret; }