static int cm36686_i2c_remove(struct i2c_client *client) { struct cm36686_data *cm36686 = i2c_get_clientdata(client); /* free irq */ if (cm36686->power_state & PROXIMITY_ENABLED) { disable_irq_wake(cm36686->irq); disable_irq(cm36686->irq); } free_irq(cm36686->irq, cm36686); gpio_free(cm36686->pdata->irq); /* device off */ if (cm36686->power_state & LIGHT_ENABLED) cm36686_light_disable(cm36686); if (cm36686->power_state & PROXIMITY_ENABLED) { cm36686_i2c_write_word(cm36686, REG_PS_CONF1, 0x0001); } /* destroy workqueue */ destroy_workqueue(cm36686->light_wq); destroy_workqueue(cm36686->prox_wq); /* sysfs destroy */ sensors_unregister(cm36686->light_dev, light_sensor_attrs); sensors_unregister(cm36686->proximity_dev, prox_sensor_attrs); sensors_remove_symlink(&cm36686->light_input_dev->dev.kobj, cm36686->light_input_dev->name); sensors_remove_symlink(&cm36686->proximity_input_dev->dev.kobj, cm36686->proximity_input_dev->name); /* input device destroy */ sysfs_remove_group(&cm36686->light_input_dev->dev.kobj, &light_attribute_group); input_unregister_device(cm36686->light_input_dev); sysfs_remove_group(&cm36686->proximity_input_dev->dev.kobj, &proximity_attribute_group); input_unregister_device(cm36686->proximity_input_dev); #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) cm36686_leden_gpio_onoff(cm36686, 0); gpio_free(cm36686->pdata->leden_gpio); #else prox_led_onoff(cm36686, 0); #endif /* lock destroy */ mutex_destroy(&cm36686->read_lock); mutex_destroy(&cm36686->power_lock); wake_lock_destroy(&cm36686->prx_wake_lock); kfree(cm36686); return 0; }
void remove_pressure_factorytest(struct ssp_data *data) { #if defined (LPS25H_REV) if(data->ap_rev >= LPS25H_REV) sensors_unregister(data->prs_device, pressure_attrs_lps25h); else sensors_unregister(data->prs_device, pressure_attrs); #else sensors_unregister(data->prs_device, pressure_attrs); #endif }
static void gp2a_shutdown(struct i2c_client *client) { struct gp2a_data *data = i2c_get_clientdata(client); pr_info("%s, is called\n", __func__); if (data->light_enabled) { cancel_delayed_work_sync(&data->light_work); lightsensor_onoff(0, data); input_report_rel(data->light_input_dev, REL_MISC, data->lux + 1); input_sync(data->light_input_dev); } if (data->prox_enabled) { disable_irq(data->irq); disable_irq_wake(data->irq); gp2a_prox_onoff(0, data); wake_unlock(&data->prx_wake_lock); } wake_lock_destroy(&data->prx_wake_lock); mutex_destroy(&data->light_mutex); mutex_destroy(&data->data_mutex); sensors_unregister(data->prox_sensor_device, prox_sensor_attrs); sensors_unregister(data->light_sensor_device, light_sensor_attrs); sysfs_remove_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); sensors_remove_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); input_unregister_device(data->prox_input_dev); input_free_device(data->prox_input_dev); gpio_free(data->gpio); sysfs_remove_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); sensors_remove_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); input_unregister_device(data->light_input_dev); input_free_device(data->light_input_dev); sensor_power_on_vdd(data, 0); kfree(data); bShutdown = true; }
static int __devexit cm3323_remove(struct i2c_client *client) { struct cm3323_p *data = i2c_get_clientdata(client); /* device off */ if (data->power_state & LIGHT_ENABLED) cm3323_light_disable(data); /* destroy workqueue */ destroy_workqueue(data->light_wq); /* lock destroy */ mutex_destroy(&data->read_lock); mutex_destroy(&data->power_lock); /* sysfs destroy */ sensors_unregister(data->light_dev, sensor_attrs); sensors_remove_symlink(&data->input->dev.kobj, data->input->name); /* input device destroy */ sysfs_remove_group(&data->input->dev.kobj, &light_attribute_group); input_unregister_device(data->input); kfree(data); return 0; }
static void uv_shutdown(struct platform_device *pdev) { struct uv_info *uv = dev_get_drvdata(&pdev->dev); pr_info("%s+\n", __func__); if (uv->onoff) { hrtimer_cancel(&uv->uv_timer); cancel_work_sync(&uv->work_uv); } destroy_workqueue(uv->uv_wq); #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&uv->early_suspend); #endif sensors_unregister(uv->uv_dev, uv_sensor_attrs); sysfs_remove_group(&uv->uv_input_dev->dev.kobj, &uv_attribute_group); input_unregister_device(uv->uv_input_dev); if (uv->onoff && uv->pdata->power_on) uv->pdata->power_on(false); if (uv->pdata->adc_ap_exit) uv->pdata->adc_ap_exit(uv->pdev_uv_adc); if (uv->pdev_uv_adc) platform_device_put(uv->pdev_uv_adc); mutex_destroy(&uv->read_lock); mutex_destroy(&uv->power_lock); kfree(uv); pr_info("%s-\n", __func__); }
static int __devexit bma280_remove(struct i2c_client *client) { struct bma280_p *data = (struct bma280_p *)i2c_get_clientdata(client); if (atomic_read(&data->enable) == ON) bma280_set_enable(data, OFF); atomic_set(&data->enable, OFF); cancel_delayed_work_sync(&data->irq_work); bma280_set_mode(data, BMA280_MODE_SUSPEND); sensors_unregister(data->factory_device, sensor_attrs); sensors_remove_symlink(&data->input->dev.kobj, data->input->name); sysfs_remove_group(&data->input->dev.kobj, &bma280_attribute_group); input_unregister_device(data->input); free_irq(data->irq1, data); wake_lock_destroy(&data->reactive_wake_lock); mutex_destroy(&data->mode_mutex); gpio_free(data->acc_int1); kfree(data); return 0; }
static int bh1721fvc_remove(struct i2c_client *client) { struct bh1721fvc_data *bh1721fvc = i2c_get_clientdata(client); sensors_unregister(bh1721fvc->light_sensor_device); sysfs_remove_group(&bh1721fvc->input_dev->dev.kobj, &bh1721fvc_attribute_group); input_unregister_device(bh1721fvc->input_dev); if (bh1721fvc_is_measuring(bh1721fvc)) bh1721fvc_disable(bh1721fvc); destroy_workqueue(bh1721fvc->wq); mutex_destroy(&bh1721fvc->lock); kfree(bh1721fvc); bh1721fvc_dbmsg("bh1721fvc_remove -\n"); return 0; }
void remove_temphumidity_factorytest(struct ssp_data *data) { if (data->comp_engine_ver != NULL) kfree(data->comp_engine_ver); if (data->comp_engine_ver2 != NULL) kfree(data->comp_engine_ver2); sensors_unregister(data->temphumidity_device, temphumidity_attrs); }
void remove_magnetic_sensor(struct ssp_data *data) { sensors_unregister(data->mag_device, mag_attrs); device_remove_file(&data->mag_input_dev->dev, &dev_attr_mag_poll_delay); sensors_remove_symlink(&data->mag_input_dev->dev.kobj, data->mag_input_dev->name); input_unregister_device(data->mag_input_dev); }
void KXSD9_sysfs_exit(struct sensors_dev *sdev) #endif { trace_in(); #ifdef CONFIG_MACH_OSCAR sensors_unregister(sdev); #endif trace_out(); }
void remove_temphumidity_factorytest(struct ssp_data *data) { if (data->comp_engine_ver != NULL) kfree(data->comp_engine_ver); if (data->comp_engine_ver2 != NULL) kfree(data->comp_engine_ver2); sensors_unregister(data->temphumidity_device, temphumidity_attrs); ssp_temphumidity_fops.unlocked_ioctl = NULL; misc_deregister(&data->shtc1_device); }
void remove_temphumidity_factorytest(struct ssp_data *data) { if (data->adc_client) s3c_adc_release(data->adc_client); if (data->pdev_pam_temp) platform_device_put(data->pdev_pam_temp); sensors_unregister(data->temphumidity_device, temphumidity_attrs); kfree(data->comp_engine_ver); ssp_temphumidity_fops.unlocked_ioctl = NULL; misc_deregister(&data->shtc1_device); }
void L_sysfs_exit(struct sensors_dev *sdev) #endif { trace_in(); #ifdef CONFIG_MACH_OSCAR struct device *dev = sdev->dev; sensors_unregister(sdev); #endif device_remove_file( dev, &dev_attr_L_adc_val ); device_remove_file( dev, &dev_attr_L_illum_lvl ); trace_out(); }
void P_sysfs_exit(struct sensors_dev *sdev) #endif { trace_in(); #ifdef CONFIG_MACH_OSCAR sensors_unregister(sdev); #else class_destroy(P_obj_state); device_remove_file( dev, &dev_attr_P_output ); device_remove_file( dev, &dev_attr_P_operation ); #endif trace_out(); }
static int __devexit ak09911c_remove(struct i2c_client *client) { struct ak09911c_p *data = (struct ak09911c_p *)i2c_get_clientdata(client); if (atomic_read(&data->enable) == 1) ak09911c_set_enable(data, 0); gpio_free(data->m_rst_n); mutex_destroy(&data->lock); sensors_unregister(data->factory_device, sensor_attrs); sensors_remove_symlink(&data->input->dev.kobj, data->input->name); sysfs_remove_group(&data->input->dev.kobj, &ak09911c_attribute_group); input_unregister_device(data->input); kfree(data); return 0; }
static int bma280_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = -ENODEV, i; struct bma280_p *data = NULL; pr_info("##########################################################\n"); pr_info("[SENSOR]: %s - Probe Start!\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("[SENSOR]: %s - i2c_check_functionality error\n", __func__); goto exit; } data = kzalloc(sizeof(struct bma280_p), GFP_KERNEL); if (data == NULL) { pr_err("[SENSOR]: %s - kzalloc error\n", __func__); ret = -ENOMEM; goto exit_kzalloc; } ret = bma280_parse_dt(data, client->dev.platform_data); if (ret < 0) { pr_err("[SENSOR]: %s - of_node error\n", __func__); ret = -ENODEV; goto exit_of_node; } ret = bma280_setup_pin(data); if (ret < 0) { pr_err("[SENSOR]: %s - could not setup pin\n", __func__); goto exit_setup_pin; } i2c_set_clientdata(client, data); data->client = client; mutex_init(&data->mode_mutex); wake_lock_init(&data->reactive_wake_lock, WAKE_LOCK_SUSPEND, "reactive_wake_lock"); /* read chip id */ for (i = 0; i < CHIP_ID_RETRIES; i++) { ret = i2c_smbus_read_word_data(client, BMA280_CHIP_ID_REG); if ((ret & 0x00ff) != BMA280_CHIP_ID) { pr_err("[SENSOR]: %s - chip id failed 0x%x\n", __func__, (unsigned int)ret & 0x00ff); } else { pr_info("[SENSOR]: %s - chip id success 0x%x\n", __func__, (unsigned int)ret & 0x00ff); break; } msleep(20); } if (i >= CHIP_ID_RETRIES) { ret = -ENODEV; goto exit_read_chipid; } /* input device init */ ret = bma280_input_init(data); if (ret < 0) goto exit_input_init; sensors_register(data->factory_device, data, sensor_attrs, MODULE_NAME); /* accel_timer settings. we poll for light values using a timer. */ hrtimer_init(&data->accel_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); data->poll_delay = ns_to_ktime(BMA280_DEFAULT_DELAY); data->accel_timer.function = bma280_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ data->accel_wq = create_singlethread_workqueue("accel_wq"); if (!data->accel_wq) { ret = -ENOMEM; pr_err("[SENSOR]: %s - could not create workqueue\n", __func__); goto exit_create_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&data->work, bma280_work_func); INIT_DELAYED_WORK(&data->irq_work, bma280_irq_work_func); data->irq1 = gpio_to_irq(data->acc_int1); ret = request_threaded_irq(data->irq1, NULL, bma280_irq_thread, IRQF_TRIGGER_RISING | IRQF_ONESHOT, "bma280_accel", data); if (ret < 0) { pr_err("[SENSOR]: %s - can't allocate irq.\n", __func__); goto exit_request_threaded_irq; } disable_irq(data->irq1); atomic_set(&data->enable, OFF); data->time_count = 0; data->irq_state = 0; data->recog_flag = OFF; bma280_set_bandwidth(data, BMA280_BW_125HZ); bma280_set_range(data, BMA280_RANGE_2G); bma280_set_mode(data, BMA280_MODE_SUSPEND); pr_info("[SENSOR]: %s - Probe done!(chip pos : %d)\n", __func__, data->chip_pos); return 0; exit_request_threaded_irq: exit_create_workqueue: sensors_unregister(data->factory_device, sensor_attrs); sensors_remove_symlink(&data->input->dev.kobj, data->input->name); sysfs_remove_group(&data->input->dev.kobj, &bma280_attribute_group); input_unregister_device(data->input); exit_input_init: exit_read_chipid: mutex_destroy(&data->mode_mutex); wake_lock_destroy(&data->reactive_wake_lock); gpio_free(data->acc_int1); exit_setup_pin: exit_of_node: kfree(data); exit_kzalloc: exit: pr_err("[SENSOR]: %s - Probe fail!\n", __func__); return ret; }
static void remove_mcu_factorytest(struct ssp_data *data) { sensors_unregister(data->mcu_device, mcu_attrs); }
void remove_grip_factorytest(struct ssp_data *data) { sensors_unregister(data->grip_device, grip_attrs); }
void remove_uv_factorytest(struct ssp_data *data) { sensors_unregister(data->uv_device, uv_attrs); }
void remove_prox_factorytest(struct ssp_data *data) { sensors_unregister(data->prox_device, prox_attrs); }
void remove_gesture_factorytest(struct ssp_data *data) { sensors_unregister(data->ges_device, gesture_attrs); }
void remove_accel_factorytest(struct ssp_data *data) { sensors_unregister(data->acc_device, acc_attrs); }
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct yas_state *st; struct iio_dev *indio_dev; int ret; pr_info("[SENSOR] %s is called!!\n", __func__); this_client = i2c; indio_dev = iio_allocate_device(sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; goto error_ret; } i2c_set_clientdata(i2c, indio_dev); indio_dev->name = id->name; indio_dev->dev.parent = &i2c->dev; indio_dev->info = &yas_info; indio_dev->channels = yas_channels; indio_dev->num_channels = ARRAY_SIZE(yas_channels); indio_dev->modes = INDIO_DIRECT_MODE; st = iio_priv(indio_dev); st->client = i2c; st->sampling_frequency = 20; st->mag.callback.device_open = yas_device_open; st->mag.callback.device_close = yas_device_close; st->mag.callback.device_read = yas_device_read; st->mag.callback.device_write = yas_device_write; st->mag.callback.usleep = yas_usleep; st->mag.callback.current_time = yas_current_time; INIT_DELAYED_WORK(&st->work, yas_work_func); mutex_init(&st->lock); #ifdef CONFIG_HAS_EARLYSUSPEND st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; st->sus.suspend = yas_early_suspend; st->sus.resume = yas_late_resume; register_early_suspend(&st->sus); #endif #ifdef CONFIG_SENSORS ret = sensors_register(st->yas_device, st, sensor_attrs, "magnetic_sensor"); if (ret) { pr_err("%s: cound not register gyro sensor device(%d).\n", __func__, ret); goto err_yas_sensor_register_failed; } #endif ret = yas_probe_buffer(indio_dev); if (ret) goto error_free_dev; ret = yas_probe_trigger(indio_dev); if (ret) goto error_remove_buffer; ret = iio_device_register(indio_dev); if (ret) goto error_remove_trigger; ret = yas_mag_driver_init(&st->mag); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.init(); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.set_enable(1); if (ret < 0) { ret = -EFAULT; goto error_driver_term; } pr_info("[SENSOR] %s is finished!!\n", __func__); return 0; error_driver_term: st->mag.term(); error_unregister_iio: iio_device_unregister(indio_dev); error_remove_trigger: yas_remove_trigger(indio_dev); error_remove_buffer: yas_remove_buffer(indio_dev); error_free_dev: #ifdef CONFIG_SENSORS sensors_unregister(st->yas_device, sensor_attrs); err_yas_sensor_register_failed: #endif #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&st->sus); #endif iio_free_device(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; return ret; }
static int gp2a_probe(struct i2c_client *client, const struct i2c_device_id *id) { int err = 0; struct gp2a_data *data; u8 value; pr_info("%s, is called\n", __func__); if (client == NULL) { pr_err("%s, client doesn't exist\n", __func__); err = -ENOMEM; return err; } data = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); if (!data) { pr_err("%s, kzalloc error\n", __func__); err = -ENOMEM; return err; } err = gp2a_parse_dt(data, &client->dev); if (err) { pr_err("%s, get gpio is failed\n", __func__); goto gp2a_parse_dt_err; } data->client = client; data->light_delay = MAX_DELAY; bShutdown = false; i2c_set_clientdata(client, data); sensor_power_on_vdd(data, 1); value = 0x00; err = gp2a_i2c_write(data, (u8) (COMMAND1), &value); if (err < 0) { pr_err("%s failed : threre is no such device.\n", __func__); goto i2c_fail_err; } data->light_input_dev = input_allocate_device(); if (!data->light_input_dev) { pr_err("%s input_allocate_device error\n", __func__); err = -ENOMEM; goto input_allocate_light_device_err; } data->light_input_dev->name = "light_sensor"; input_set_capability(data->light_input_dev, EV_REL, REL_MAX); input_set_capability(data->light_input_dev, EV_REL, REL_MISC); input_set_drvdata(data->light_input_dev, data); err = input_register_device(data->light_input_dev); if (err < 0) { pr_err("%s input_register_device light error\n", __func__); goto input_register_device_err; } err = sensors_create_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); if (err < 0) { pr_err("%s sensors_create_symlink light error\n", __func__); goto sensors_create_symlink_err; } err = sysfs_create_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); if (err) { pr_err("%s sysfs_create_group light error\n", __func__); goto sysfs_create_group_light_err; } err = gp2a_setup_irq(data); if (err) { pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } data->prox_input_dev = input_allocate_device(); if (!data->prox_input_dev) { pr_err("%s input_allocate_device error\n", __func__); err = -ENOMEM; goto input_allocate_prox_device_err; } data->prox_input_dev->name = "proximity_sensor"; input_set_capability(data->prox_input_dev, EV_ABS, ABS_DISTANCE); input_set_capability(data->prox_input_dev, EV_ABS, ABS_MAX); input_set_abs_params(data->prox_input_dev, ABS_DISTANCE, 0, 1, 0, 0); input_set_abs_params(data->prox_input_dev, ABS_MAX, 0, 1, 0, 0); input_set_drvdata(data->prox_input_dev, data); err = input_register_device(data->prox_input_dev); if (err < 0) { pr_err("%s input_register_device prox error\n", __func__); goto input_register_prox_device_err; } err = sensors_create_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); if (err < 0) { pr_err("%s sensors_create_symlink light error\n", __func__); goto sensors_create_symlink_light_err; } err = sysfs_create_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); if (err) { pr_err("%s sysfs_create_group prox error\n", __func__); goto sysfs_create_group_prox_err; } err = sensors_register(data->light_sensor_device, data, light_sensor_attrs, "light_sensor"); if (err) { pr_err("%s: cound not register prox sensor device(%d).\n", __func__, err); goto sensors_register_light_err; } err = sensors_register(data->prox_sensor_device, data, prox_sensor_attrs, "proximity_sensor"); if (err) { pr_err("%s: cound not register prox sensor device(%d).\n", __func__, err); goto sensors_register_prox_err; } mutex_init(&data->light_mutex); mutex_init(&data->data_mutex); INIT_DELAYED_WORK(&data->light_work, gp2a_work_func_light); wake_lock_init(&data->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); INIT_WORK(&data->proximity_work, gp2a_work_func_prox); INIT_DELAYED_WORK(&data->prox_avg_work, gp2a_work_avg_prox); goto done; mutex_destroy(&data->light_mutex); mutex_destroy(&data->data_mutex); sensors_unregister(data->prox_sensor_device, prox_sensor_attrs); sensors_register_prox_err: sensors_unregister(data->light_sensor_device, light_sensor_attrs); sensors_register_light_err: sysfs_remove_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); sysfs_create_group_prox_err: sensors_remove_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); sensors_create_symlink_err: input_unregister_device(data->prox_input_dev); input_register_prox_device_err: input_free_device(data->prox_input_dev); input_allocate_prox_device_err: gpio_free(data->gpio); err_setup_irq: sysfs_remove_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); sysfs_create_group_light_err: sensors_remove_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); sensors_create_symlink_light_err: input_unregister_device(data->light_input_dev); input_register_device_err: input_free_device(data->light_input_dev); input_allocate_light_device_err: i2c_fail_err: gp2a_parse_dt_err: sensor_power_on_vdd(data, 0); kfree(data); bShutdown = true; done: return err; }
void remove_light_factorytest(struct ssp_data *data) { sensors_unregister(data->light_device, light_attrs); }
static int gp2a_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = -ENODEV; struct input_dev *input_dev; struct gp2a_data *gp2a; struct gp2a_platform_data *pdata = client->dev.platform_data; pr_info("==============================\n"); pr_info("========= GP2A =======\n"); pr_info("==============================\n"); if (!pdata) { pr_err("%s: missing pdata!\n", __func__); return ret; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s: i2c functionality check failed!\n", __func__); return ret; } gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); if (!gp2a) { pr_err("%s: failed to alloc memory for module data\n", __func__); return -ENOMEM; } #if defined(CONFIG_OPTICAL_WAKE_ENABLE) if (system_rev >= 0x03) { pr_info("GP2A Reset GPIO = GPX0(1) (rev%02d)\n", system_rev); gp2a->enable_wakeup = true; } else { pr_info("GP2A Reset GPIO = GPL0(6) (rev%02d)\n", system_rev); gp2a->enable_wakeup = false; } #else gp2a->enable_wakeup = false; #endif gp2a->pdata = pdata; gp2a->i2c_client = client; i2c_set_clientdata(client, gp2a); /* wake lock init */ wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); mutex_init(&gp2a->power_mutex); mutex_init(&gp2a->adc_mutex); ret = gp2a_setup_irq(gp2a); if (ret) { pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } /* allocate proximity input_device */ input_dev = input_allocate_device(); if (!input_dev) { pr_err("%s: could not allocate input device\n", __func__); goto err_input_allocate_device_proximity; } gp2a->proximity_input_dev = input_dev; input_set_drvdata(input_dev, gp2a); input_dev->name = "proximity_sensor"; input_set_capability(input_dev, EV_ABS, ABS_DISTANCE); input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0); gp2a_dbgmsg("registering proximity input device\n"); ret = input_register_device(input_dev); if (ret < 0) { pr_err("%s: could not register input device\n", __func__); input_free_device(input_dev); goto err_input_register_device_proximity; } ret = sysfs_create_group(&input_dev->dev.kobj, &proximity_attribute_group); if (ret) { pr_err("%s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_proximity; } /* hrtimer settings. we poll for light values using a timer. */ hrtimer_init(&gp2a->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); gp2a->light_poll_delay = ns_to_ktime(LIGHT_TIMER_PERIOD_MS * NSEC_PER_MSEC); gp2a->timer.function = gp2a_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ gp2a->wq = create_singlethread_workqueue("gp2a_wq"); if (!gp2a->wq) { ret = -ENOMEM; pr_err("%s: could not create workqueue\n", __func__); goto err_create_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&gp2a->work_light, gp2a_work_func_light); #ifdef GP2A_MODE_B /* this is the thread function we run on the work queue */ INIT_WORK(&gp2a->work_proximity, gp2a_work_func_proximity); #endif /* allocate lightsensor-level input_device */ input_dev = input_allocate_device(); if (!input_dev) { pr_err("%s: could not allocate input device\n", __func__); ret = -ENOMEM; goto err_input_allocate_device_light; } input_set_drvdata(input_dev, gp2a); input_dev->name = "light_sensor"; input_set_capability(input_dev, EV_REL, REL_MISC); gp2a_dbgmsg("registering lightsensor-level input device\n"); ret = input_register_device(input_dev); if (ret < 0) { pr_err("%s: could not register input device\n", __func__); input_free_device(input_dev); goto err_input_register_device_light; } gp2a->light_input_dev = input_dev; ret = sysfs_create_group(&input_dev->dev.kobj, &light_attribute_group); if (ret) { pr_err("%s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_light; } /* alloc platform device for adc client */ pdev_gp2a_adc = platform_device_alloc("gp2a-adc", -1); if (!pdev_gp2a_adc) { pr_err("%s: could not allocation pdev_gp2a_adc.\n", __func__); ret = -ENOMEM; goto err_platform_allocate_device_adc; } /* Register adc client */ gp2a->padc = s3c_adc_register(pdev_gp2a_adc, NULL, NULL, 0); if (IS_ERR(gp2a->padc)) { dev_err(&pdev_gp2a_adc->dev, "cannot register adc\n"); ret = PTR_ERR(gp2a->padc); goto err_platform_register_device_adc; } /* set sysfs for light sensor */ ret = misc_register(&light_device); if (ret) pr_err(KERN_ERR "misc_register failed - light\n"); gp2a->lightsensor_class = class_create(THIS_MODULE, "lightsensor"); if (IS_ERR(gp2a->lightsensor_class)) pr_err("Failed to create class(lightsensor)!\n"); gp2a->switch_cmd_dev = device_create(gp2a->lightsensor_class, NULL, 0, NULL, "switch_cmd"); if (IS_ERR(gp2a->switch_cmd_dev)) pr_err("Failed to create device(switch_cmd_dev)!\n"); if (device_create_file(gp2a->switch_cmd_dev, &dev_attr_lightsensor_file_illuminance) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_illuminance.attr.name); dev_set_drvdata(gp2a->switch_cmd_dev, gp2a); /* new sysfs */ ret = sensors_register(gp2a->light_dev, gp2a, light_sensor_attrs, "light_sensor"); if (ret) { pr_err("%s: cound not register light sensor device(%d).\n", __func__, ret); goto out_light_sensor_register_failed; } ret = sensors_register(gp2a->proximity_dev, gp2a, proximity_sensor_attrs, "proximity_sensor"); if (ret) { pr_err("%s: cound not register proximity sensor device(%d).\n", __func__, ret); goto out_proximity_sensor_register_failed; } /* set initial proximity value as 1 */ gp2a->prox_value = 1; input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, 1); input_sync(gp2a->proximity_input_dev); goto done; /* error, unwind it all */ out_light_sensor_register_failed: sensors_unregister(gp2a->light_dev); out_proximity_sensor_register_failed: sensors_unregister(gp2a->proximity_dev); err_sysfs_create_group_light: input_unregister_device(gp2a->light_input_dev); err_input_register_device_light: err_input_allocate_device_light: destroy_workqueue(gp2a->wq); err_platform_allocate_device_adc: platform_device_unregister(pdev_gp2a_adc); err_platform_register_device_adc: s3c_adc_release(gp2a->padc); err_create_workqueue: sysfs_remove_group(&gp2a->proximity_input_dev->dev.kobj, &proximity_attribute_group); err_sysfs_create_group_proximity: input_unregister_device(gp2a->proximity_input_dev); err_input_register_device_proximity: err_input_allocate_device_proximity: free_irq(gp2a->irq, 0); gpio_free(gp2a->pdata->p_out); err_setup_irq: mutex_destroy(&gp2a->adc_mutex); mutex_destroy(&gp2a->power_mutex); wake_lock_destroy(&gp2a->prx_wake_lock); kfree(gp2a); done: return ret; }
void remove_gyro_factorytest(struct ssp_data *data) { sensors_unregister(data->devices[GYROSCOPE_SENSOR], gyro_attrs); }
void remove_accel_factorytest(struct ssp_data *data) { sensors_unregister(data->devices[ACCELEROMETER_SENSOR], acc_attrs); }
void remove_magnetic_factorytest(struct ssp_data *data) { sensors_unregister(data->mag_device, mag_attrs); }
static int cm36686_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = -ENODEV; struct cm36686_data *cm36686 = NULL; struct cm36686_platform_data *pdata = NULL; int err; pr_info("[SENSOR] %s: Probe Start!\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("[SENSOR] %s: i2c functionality check failed!\n", __func__); return ret; } cm36686 = kzalloc(sizeof(struct cm36686_data), GFP_KERNEL); if (!cm36686) { pr_err ("[SENSOR] %s: failed to alloc memory for RGB sensor module data\n", __func__); return -ENOMEM; } if(client->dev.of_node) { pdata = devm_kzalloc (&client->dev , sizeof(struct cm36686_platform_data ), GFP_KERNEL); if(!pdata) { dev_err(&client->dev, "Failed to allocate memory\n"); if(cm36686) kfree(cm36686); return -ENOMEM; } err = cm36686_parse_dt(&client->dev, pdata); if(err) goto err_devicetree; } else pdata = client->dev.platform_data; if (!pdata) { pr_err("%s: missing pdata!\n", __func__); if(cm36686) kfree(cm36686); return ret; } prox_regulator_onoff(&client->dev,1); cm36686->pdata = pdata; cm36686->i2c_client = client; i2c_set_clientdata(client, cm36686); mutex_init(&cm36686->power_lock); mutex_init(&cm36686->read_lock); /* wake lock init for proximity sensor */ wake_lock_init(&cm36686->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) /* setup leden_gpio */ ret = cm36686_setup_leden_gpio(cm36686); if (ret) { pr_err("%s: could not setup leden_gpio\n", __func__); goto err_setup_leden_gpio; } cm36686_leden_gpio_onoff(cm36686, 1); #else prox_led_onoff(cm36686, 1); #endif /* Check if the device is there or not. */ ret = cm36686_i2c_write_word(cm36686, REG_CS_CONF1, 0x0001); if (ret < 0) { pr_err("[SENSOR] %s: cm36686 is not connected.(%d)\n", __func__, ret); goto err_setup_reg; } /* setup initial registers */ ret = cm36686_setup_reg(cm36686); if (ret < 0) { pr_err("[SENSOR] %s: could not setup regs\n", __func__); goto err_setup_reg; } #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) cm36686_leden_gpio_onoff(cm36686, 0); #else prox_led_onoff(cm36686, 0); #endif /* allocate proximity input_device */ cm36686->proximity_input_dev = input_allocate_device(); if (!cm36686->proximity_input_dev) { pr_err("%s: could not allocate proximity input device\n", __func__); goto err_input_allocate_device_proximity; } input_set_drvdata(cm36686->proximity_input_dev, cm36686); cm36686->proximity_input_dev->name = "proximity_sensor"; input_set_capability(cm36686->proximity_input_dev, EV_ABS, ABS_DISTANCE); input_set_abs_params(cm36686->proximity_input_dev, ABS_DISTANCE, 0, 1, 0, 0); ret = input_register_device(cm36686->proximity_input_dev); if (ret < 0) { input_free_device(cm36686->proximity_input_dev); pr_err("[SENSOR] %s: could not register input device\n", __func__); goto err_input_register_device_proximity; } ret = sensors_create_symlink(&cm36686->proximity_input_dev->dev.kobj, cm36686->proximity_input_dev->name); if (ret < 0) { pr_err("[SENSOR] %s: create_symlink error\n", __func__); goto err_sensors_create_symlink_prox; } ret = sysfs_create_group(&cm36686->proximity_input_dev->dev.kobj, &proximity_attribute_group); if (ret) { pr_err("[SENSOR] %s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_proximity; } /* setup irq */ ret = cm36686_setup_irq(cm36686); if (ret) { pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } /* For factory test mode, we use timer to get average proximity data. */ /* prox_timer settings. we poll for light values using a timer. */ hrtimer_init(&cm36686->prox_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); cm36686->prox_poll_delay = ns_to_ktime(2000 * NSEC_PER_MSEC);/*2 sec*/ cm36686->prox_timer.function = cm36686_prox_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ cm36686->prox_wq = create_singlethread_workqueue("cm36686_prox_wq"); if (!cm36686->prox_wq) { ret = -ENOMEM; pr_err("[SENSOR] %s: could not create prox workqueue\n", __func__); goto err_create_prox_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&cm36686->work_prox, cm36686_work_func_prox); /* allocate lightsensor input_device */ cm36686->light_input_dev = input_allocate_device(); if (!cm36686->light_input_dev) { pr_err("%s: could not allocate light input device\n", __func__); goto err_input_allocate_device_light; } input_set_drvdata(cm36686->light_input_dev, cm36686); cm36686->light_input_dev->name = "light_sensor"; input_set_capability(cm36686->light_input_dev, EV_REL, REL_MISC); input_set_capability(cm36686->light_input_dev, EV_REL, REL_DIAL); input_set_capability(cm36686->light_input_dev, EV_REL, REL_WHEEL); ret = input_register_device(cm36686->light_input_dev); if (ret < 0) { input_free_device(cm36686->light_input_dev); pr_err("%s: could not register input device\n", __func__); goto err_input_register_device_light; } ret = sensors_create_symlink(&cm36686->light_input_dev->dev.kobj, cm36686->light_input_dev->name); if (ret < 0) { pr_err("[SENSOR] %s: create_symlink error\n", __func__); goto err_sensors_create_symlink_light; } ret = sysfs_create_group(&cm36686->light_input_dev->dev.kobj, &light_attribute_group); if (ret) { pr_err("[SENSOR] %s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_light; } /* light_timer settings. we poll for light values using a timer. */ hrtimer_init(&cm36686->light_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); cm36686->light_poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC); cm36686->light_timer.function = cm36686_light_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ cm36686->light_wq = create_singlethread_workqueue("cm36686_light_wq"); if (!cm36686->light_wq) { ret = -ENOMEM; pr_err("[SENSOR] %s: could not create light workqueue\n", __func__); goto err_create_light_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&cm36686->work_light, cm36686_work_func_light); /* set sysfs for proximity sensor */ ret = sensors_register(cm36686->proximity_dev, cm36686, prox_sensor_attrs, "proximity_sensor"); if (ret) { pr_err("[SENSOR] %s: cound not register\ proximity sensor device(%d).\n", __func__, ret); goto prox_sensor_register_failed; } /* set sysfs for light sensor */ ret = sensors_register(cm36686->light_dev, cm36686, light_sensor_attrs, "light_sensor"); if (ret) { pr_err("[SENSOR] %s: cound not register\ light sensor device(%d).\n", __func__, ret); goto light_sensor_register_failed; } pr_info("[SENSOR] %s is success.\n", __func__); goto done; err_devicetree: printk("\n error in device tree"); /* error, unwind it all */ light_sensor_register_failed: sensors_unregister(cm36686->proximity_dev, prox_sensor_attrs); prox_sensor_register_failed: destroy_workqueue(cm36686->light_wq); err_create_light_workqueue: sysfs_remove_group(&cm36686->light_input_dev->dev.kobj, &light_attribute_group); err_sysfs_create_group_light: sensors_remove_symlink(&cm36686->light_input_dev->dev.kobj, cm36686->light_input_dev->name); err_sensors_create_symlink_light: input_unregister_device(cm36686->light_input_dev); err_input_register_device_light: err_input_allocate_device_light: destroy_workqueue(cm36686->prox_wq); err_create_prox_workqueue: free_irq(cm36686->irq, cm36686); gpio_free(cm36686->pdata->irq); err_setup_irq: sysfs_remove_group(&cm36686->proximity_input_dev->dev.kobj, &proximity_attribute_group); err_sysfs_create_group_proximity: sensors_remove_symlink(&cm36686->proximity_input_dev->dev.kobj, cm36686->proximity_input_dev->name); err_sensors_create_symlink_prox: input_unregister_device(cm36686->proximity_input_dev); err_input_register_device_proximity: err_input_allocate_device_proximity: err_setup_reg: #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) cm36686_leden_gpio_onoff(cm36686, 0); gpio_free(cm36686->pdata->leden_gpio); err_setup_leden_gpio: #else prox_led_onoff(cm36686, 0); #endif wake_lock_destroy(&cm36686->prx_wake_lock); mutex_destroy(&cm36686->read_lock); mutex_destroy(&cm36686->power_lock); kfree(cm36686); prox_regulator_onoff(&client->dev,0); done: return ret; }