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;
}
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;
}
示例#4
0
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;
}
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);
}
int initialize_magnetic_sensor(struct ssp_data *data)
{
	int iRet;
	struct input_dev *input_dev;

	/* allocate input_device */
	input_dev = input_allocate_device();
	if (input_dev == NULL)
		return ERROR;

	input_dev->name = MODULE_NAME;
	input_set_capability(input_dev, EV_REL, REL_RX);
	input_set_capability(input_dev, EV_REL, REL_RY);
	input_set_capability(input_dev, EV_REL, REL_RZ);
	input_set_drvdata(input_dev, data);

	/* register input_device */
	iRet = input_register_device(input_dev);
	if (iRet < 0) {
		input_free_device(input_dev);		
		return ERROR;
	}

	iRet = sensors_create_symlink(&input_dev->dev.kobj, input_dev->name);
	if (iRet < 0)
		goto err_creat_symlink;

	iRet = device_create_file(&input_dev->dev, &dev_attr_mag_poll_delay);
	if (iRet < 0)
		goto err_creat_file;

	iRet = sensors_register(data->mag_device, data, mag_attrs, MODULE_NAME);
	if (iRet < 0)
		goto err_sensor_register;

	data->mag_input_dev = input_dev;

	return SUCCESS;

err_sensor_register:
	device_remove_file(&input_dev->dev, &dev_attr_mag_poll_delay);
err_creat_file:
	sensors_remove_symlink(&input_dev->dev.kobj, input_dev->name);
err_creat_symlink:
	input_unregister_device(input_dev);

	pr_err("[SSP]: %s - fail!\n", __func__);
	return ERROR;
}
static int cm3323_input_init(struct cm3323_p *data)
{
	int ret = 0;
	struct input_dev *dev;

	/* allocate lightsensor input_device */
	dev = input_allocate_device();
	if (!dev)
		return -ENOMEM;

	dev->name = MODULE_NAME;
	dev->id.bustype = BUS_I2C;

	input_set_capability(dev, EV_REL, REL_RED);
	input_set_capability(dev, EV_REL, REL_GREEN);
	input_set_capability(dev, EV_REL, REL_BLUE);
	input_set_capability(dev, EV_REL, REL_WHITE);
	input_set_drvdata(dev, data);

	ret = input_register_device(dev);
	if (ret < 0) {
		input_free_device(data->input);
		return ret;
	}

	ret = sensors_create_symlink(&dev->dev.kobj, dev->name);
	if (ret < 0) {
		input_unregister_device(dev);
		return ret;
	}

	ret = sysfs_create_group(&dev->dev.kobj, &light_attribute_group);
	if (ret < 0) {
		sensors_remove_symlink(&data->input->dev.kobj,
			data->input->name);
		input_unregister_device(dev);
		return ret;
	}

	data->input = dev;
	return 0;
}
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;
}
示例#9
0
static int ak09911c_input_init(struct ak09911c_p *data)
{
	int ret = 0;
	struct input_dev *dev;

	dev = input_allocate_device();
	if (!dev)
		return -ENOMEM;

	dev->name = MODULE_NAME;
	dev->id.bustype = BUS_I2C;

	input_set_capability(dev, EV_REL, REL_X);
	input_set_capability(dev, EV_REL, REL_Y);
	input_set_capability(dev, EV_REL, REL_Z);
	input_set_drvdata(dev, data);

	ret = input_register_device(dev);
	if (ret < 0) {
		input_free_device(dev);
		return ret;
	}

	ret = sensors_create_symlink(&dev->dev.kobj, dev->name);
	if (ret < 0) {
		input_unregister_device(dev);
		return ret;
	}

	/* sysfs node creation */
	ret = sysfs_create_group(&dev->dev.kobj, &ak09911c_attribute_group);
	if (ret < 0) {
		sensors_remove_symlink(&data->input->dev.kobj,
			data->input->name);
		input_unregister_device(dev);
		return ret;
	}

	data->input = dev;
	return 0;
}
示例#10
0
static int ak09911c_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	int ret = -ENODEV;
	struct ak09911c_p *data = NULL;
	struct ak09911c_platform_data *pdata;

	pr_info("%s Probe Start!\n", __func__);
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s i2c_check_functionality error\n", __func__);
		goto exit;
	}

	ak09911c_regulator_onoff(&client->dev, 1);

	data = kzalloc(sizeof(struct ak09911c_p), GFP_KERNEL);
	if (data == NULL) {
		pr_err("%s kzalloc error\n", __func__);
		ret = -ENOMEM;
		goto exit_kzalloc;
	}
	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
			sizeof(struct ak09911c_platform_data), GFP_KERNEL);
		if (!pdata) {
			dev_err(&client->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}
		ret = ak09911c_parse_dt(&client->dev, pdata);
		if (ret < 0) {
			pr_err("%s of_node error\n", __func__);
			ret = -ENODEV;
			goto exit_of_node;
		}

	} else
		pdata = client->dev.platform_data;

	if (!pdata) {
		ret = -EINVAL;
		goto exit_pdata;
	}

	data->pdata = pdata;
	ret = ak09911c_setup_pin(pdata);
	if (ret) {
		pr_err("%s could not setup pin\n", __func__);
		goto exit_setup_pin;
	}

	/* ak09911c chip reset */
	ak09911c_reset(data);

	i2c_set_clientdata(client, data);
	data->client = client;

	ret = ak09911c_check_device(data);
	if (ret < 0)
		goto exit_set_mode_check_device;

	/* input device init */
	ret = ak09911c_input_init(data);
	if (ret < 0)
		goto exit_input_init;

	ret = sensors_register(data->factory_device, data, sensor_attrs,
		MODULE_NAME);
	if (ret) {
		pr_err("%s: failed to sensors_register (%d)\n", __func__, ret);
		goto exit_register_failed;
	}

	/* workqueue init */
	INIT_DELAYED_WORK(&data->work, ak09911c_work_func);
	mutex_init(&data->lock);

	atomic_set(&data->delay, AK09911C_DEFAULT_DELAY);
	atomic_set(&data->enable, 0);

	ak09911c_read_fuserom(data);

	pr_info("%s Probe done!(chip pos : %d)\n", __func__, pdata->chip_pos);

	return 0;

exit_register_failed:
	sysfs_remove_group(&data->input->dev.kobj, &ak09911c_attribute_group);
	sensors_remove_symlink(&data->input->dev.kobj, data->input->name);
	input_unregister_device(data->input);
exit_input_init:
exit_set_mode_check_device:
	gpio_free(data->pdata->m_rst_n);
exit_setup_pin:
exit_pdata:
exit_of_node:
	kfree(data);
exit_kzalloc:
	ak09911c_regulator_onoff(&client->dev, 0);
exit:
	pr_err("%s Probe fail!\n", __func__);
	return ret;
}
static int bma254_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	int ret = 0;
	struct bma254_data *bma254;
	struct input_dev *dev;
#ifdef CONFIG_BMA254_SMART_ALERT
	int err = 0;
	struct bma254_platform_data *pdata;
#endif

	pr_info("%s, is called\n", __func__);

	if (client == NULL) {
		pr_err("%s, client doesn't exist\n", __func__);
		ret = -ENOMEM;
		return ret;
	}
#ifdef CONFIG_SENSORS_POWERCONTROL
	ret = bma254_regulator_onoff(&client->dev, true);
	if (ret) {
		pr_err("%s, Power Up Failed\n", __func__);
		return ret;
	}
#endif
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s,client not i2c capable\n", __func__);
		return -ENOMEM;
	}

	ret = i2c_smbus_read_word_data(client, BMA254_CHIP_ID);
	if ((ret & 0x00ff) != 0xfa) {
		pr_err("%s,i2c failed(%x)\n", __func__, ret & 0x00ff);
		ret = -ENOMEM;
		return ret;
	} else {
		pr_err("%s,chip id %x\n", __func__, ret & 0x00ff);
	}

	bma254 = kzalloc(sizeof(struct bma254_data), GFP_KERNEL);
	if (!bma254) {
		pr_err("%s, kzalloc error\n", __func__);
		ret = -ENOMEM;
		return ret;
	}

#ifdef CONFIG_BMA254_SMART_ALERT
	if(client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
			sizeof(struct bma254_platform_data), GFP_KERNEL);
		if (!pdata) {
			dev_err(&client->dev, "Failed to allocate memory \n");
			kfree(bma254);

			return -ENOMEM;
		}
	}else{
		pr_err("%s,this_node is empty\n", __func__);
		kfree(bma254);
		return -ENODEV;
	}

	bma254->pdata = pdata;
#endif
	ret = bma254_parse_dt(bma254, &client->dev);
	if (ret) {
		pr_err("%s, get gpio is failed\n", __func__);
		goto parse_dt_err;
	}

	i2c_set_clientdata(client, bma254);
	bma254->client = client;

	bma254_activate(bma254, false);

	dev = input_allocate_device();
	if (!dev){
		goto input_allocate_device_err;
	}
	dev->name = "accelerometer";
	dev->id.bustype = BUS_I2C;
#if !defined(CONFIG_MACH_VICTORLTE) && !defined(CONFIG_MACH_VICTOR3GDSDTV_LTN)
	dev->dev.parent = &client->dev;
#endif
#ifdef REPORT_ABS
	input_set_capability(dev, EV_ABS, ABS_MISC);
	input_set_abs_params(dev, ABS_X, ABSMIN, ABSMAX, 0, 0);
	input_set_abs_params(dev, ABS_Y, ABSMIN, ABSMAX, 0, 0);
	input_set_abs_params(dev, ABS_Z, ABSMIN, ABSMAX, 0, 0);
#else
	input_set_capability(dev, EV_REL, REL_X);
	input_set_capability(dev, EV_REL, REL_Y);
	input_set_capability(dev, EV_REL, REL_Z);
#endif
	input_set_drvdata(dev, bma254);

	ret = input_register_device(dev);
	if (ret < 0) {
		pr_err("%s,sysfs_create_group failed\n", __func__);
		goto input_register_device_err;
	}
	bma254->input = dev;

#ifdef CONFIG_BMA254_SMART_ALERT
	pr_info("%s:  HW_rev success %d\n", __func__, system_rev);
	INIT_WORK(&bma254->alert_work, bma254_work_func_alert);
	wake_lock_init(&bma254->reactive_wake_lock, WAKE_LOCK_SUSPEND,
		"reactive_wake_lock");
	err = bma254_setup_irq(bma254);
	if (err) {
		bma254->pin_check_fail = true;
		pr_err("%s: could not setup irq\n", __func__);
		goto err_setup_irq;
	}
	mutex_init(&bma254->data_mutex);
#endif

	ret = sensors_create_symlink(&dev->dev.kobj, dev->name);
	if (ret < 0) {
		input_unregister_device(dev);
		return ret;
	}
	ret = sysfs_create_group(&bma254->input->dev.kobj,
			&bma254_attribute_group);
	if (ret < 0) {
		pr_err("%s,sysfs_create_group failed\n", __func__);
		sensors_remove_symlink(&bma254->input->dev.kobj,
			bma254->input->name);
		goto sysfs_create_group_err;
	}

	INIT_DELAYED_WORK(&bma254->work, bma254_work_func);
	bma254->delay = MAX_DELAY;
	bma254->enable = 0;

	ret = sensors_register(bma254->dev, bma254,
		bma254_attrs, "accelerometer_sensor");
	if (ret < 0) {
		pr_info("%s: could not sensors_register\n", __func__);
		goto sensors_register_err;
	}

#ifdef CONFIG_SENSORS_POWERCONTROL
	bma254_regulator_onoff(&client->dev, false);
#endif
	pr_info("[SENSOR]: %s - Probe done!(chip pos : %d)\n",
		__func__, bma254->position);

	return 0;

sensors_register_err:
	sysfs_remove_group(&bma254->input->dev.kobj,
			&bma254_attribute_group);
	sensors_remove_symlink(&bma254->input->dev.kobj, bma254->input->name);
sysfs_create_group_err:
	input_unregister_device(bma254->input);
#ifdef CONFIG_BMA254_SMART_ALERT
err_setup_irq:
	wake_lock_destroy(&bma254->reactive_wake_lock);
#endif
input_register_device_err:
	input_free_device(dev);
input_allocate_device_err:
parse_dt_err:
	kfree(bma254);
	pr_err("[SENSOR]: %s - Probe fail!\n", __func__);
#ifdef CONFIG_SENSORS_POWERCONTROL
	bma254_regulator_onoff(&client->dev, false);
#endif
	return ret;
}
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;
}
static int cm3323_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	int ret = -ENODEV;
	struct cm3323_p *data = NULL;

	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 cm3323_p), GFP_KERNEL);
	if (data == NULL) {
		pr_err("[SENSOR]: %s - kzalloc error\n", __func__);
		ret = -ENOMEM;
		goto exit_kzalloc;
	}

	data->i2c_client = client;
	i2c_set_clientdata(client, data);

	mutex_init(&data->power_lock);
	mutex_init(&data->read_lock);

	/* Check if the device is there or not. */
	ret = cm3323_setup_reg(data);
	if (ret < 0) {
		pr_err("[SENSOR]: %s - could not setup regs\n", __func__);
		goto exit_setup_reg;
	}

	/* input device init */
	ret = cm3323_input_init(data);
	if (ret < 0)
		goto exit_input_init;

	/* light_timer settings. we poll for light values using a timer. */
	hrtimer_init(&data->light_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	data->poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC);
	data->light_timer.function = cm3323_light_timer_func;
	data->time_count = 0;

	/* the timer just fires off a work queue request.  we need a thread
	   to read the i2c (can be slow and blocking). */
	data->light_wq = create_singlethread_workqueue("cm3323_light_wq");
	if (!data->light_wq) {
		ret = -ENOMEM;
		pr_err("[SENSOR]: %s - could not create light workqueue\n",
			__func__);
		goto exit_create_light_workqueue;
	}

	/* this is the thread function we run on the work queue */
	INIT_WORK(&data->work_light, cm3323_work_func_light);

	/* set sysfs for light sensor */
	sensors_register(data->light_dev, data, sensor_attrs, MODULE_NAME);
	pr_info("[SENSOR]: %s - Probe done!\n", __func__);

	return 0;

exit_create_light_workqueue:
	sysfs_remove_group(&data->input->dev.kobj, &light_attribute_group);
	sensors_remove_symlink(&data->input->dev.kobj, data->input->name);
	input_unregister_device(data->input);
exit_input_init:
exit_setup_reg:
	mutex_destroy(&data->read_lock);
	mutex_destroy(&data->power_lock);
	kfree(data);
exit_kzalloc:
exit:
	pr_err("[SENSOR]: %s - Probe fail!\n", __func__);
	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;
}
static int gp2a_i2c_probe(struct i2c_client *client,
			  const struct i2c_device_id *id)
{
	int ret = 0;
	struct input_dev *input_dev;
	struct gp2a_data *gp2a;
	struct gp2a_platform_data *pdata = client->dev.platform_data;

	pr_info("%s, start\n", __func__);

	ret = gp2a_regulator_onoff(&client->dev, true);
	if (ret) {
		pr_err("%s, Power Up Failed\n", __func__);
		return ret;
	}

	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
		sizeof(struct gp2a_platform_data), GFP_KERNEL);
		if (!pdata) {
			pr_err("%s,Failed to allocate memory\n", __func__);
			return -ENOMEM;
		}
		ret = gp2a_parse_dt(&client->dev, pdata);
		if (ret < 0)
			return ret;
		ret = gp2a_request_gpio(pdata);
		if (ret < 0)
			return ret;
	}

	if (!pdata) {
		pr_err("%s,missing pdata\n", __func__);
		return -ENOMEM;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s,i2c functionality failed\n", __func__);
		return -ENOMEM;
	}

	gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
	if (!gp2a) {
		pr_err("%s,failed memory alloc\n",
		       __func__);
		return -ENOMEM;
	}

	gp2a->pdata = pdata;
	gp2a->i2c_client = client;
	i2c_set_clientdata(client, gp2a);

	wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND,
		       "prx_wake_lock");
	mutex_init(&gp2a->power_lock);

	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->input = input_dev;
	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);
	input_set_drvdata(input_dev, gp2a);

	ret = input_register_device(input_dev);
	if (ret < 0) {
		pr_err("%s,could not register input device\n",
			__func__);
		goto err_input_register_device_proximity;
	}
	ret = sensors_create_symlink(&input_dev->dev.kobj, input_dev->name);
	if (ret < 0) {
		pr_err("%s,create sysfs symlink error\n", __func__);
		goto err_sysfs_create_symlink_proximity;
	}

	ret = sysfs_create_group(&input_dev->dev.kobj,
		&proximity_attribute_group);
	if (ret) {
		pr_err("%s,create sysfs group error\n", __func__);
		goto err_sysfs_create_group_proximity;
	}

	INIT_WORK(&gp2a->work_prox, gp2a_prox_work_func);

	gp2a_leda_onoff(gp2a, 1);

	ret = gp2a_setup_irq(gp2a);

	if (ret) {
		pr_err("%s,could not setup irq\n", __func__);
		goto err_setup_irq;
	}

	gp2a_leda_onoff(gp2a, 0);

	ret = sensors_register(gp2a->dev, gp2a,
		proxi_attrs, "proximity_sensor");
	if (ret < 0) {
		pr_info("%s,could not sensors_register\n", __func__);
		goto exit_gp2a_sensors_register;
	}

	pr_info("%s done\n", __func__);

	goto done;

exit_gp2a_sensors_register:
	free_irq(gp2a->irq, gp2a);
	gpio_free(gp2a->pdata->p_out);
err_setup_irq:
	gp2a_leda_onoff(gp2a, 0);
	sysfs_remove_group(&gp2a->input->dev.kobj, &proximity_attribute_group);
err_sysfs_create_group_proximity:
	sensors_remove_symlink(&gp2a->input->dev.kobj, gp2a->input->name);
err_sysfs_create_symlink_proximity:
	input_unregister_device(gp2a->input);
err_input_register_device_proximity:
	input_free_device(input_dev);
err_input_allocate_device_proximity:
	mutex_destroy(&gp2a->power_lock);
	wake_lock_destroy(&gp2a->prx_wake_lock);
	kfree(gp2a);
done:
	gp2a_regulator_onoff(&client->dev, false);
	return ret;
}
示例#16
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 int mlx90615_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	int ret = -ENODEV;
	struct mlx90615_data *mlx90615 = NULL;

	pr_info("[BODYTEMP] %s is called.\n", __func__);

	/* Check i2c functionality */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("[BODYTEMP] %s: i2c functionality check failed!\n",
			__func__);
		return ret;
	}

	mlx90615 = kzalloc(sizeof(struct mlx90615_data), GFP_KERNEL);
	if (!mlx90615) {
		pr_err("[BODYTEMP] %s: failed to alloc memory mlx90615_data\n",
			__func__);
		return -ENOMEM;
	}

	if (client-> dev.of_node)
		pr_info("[BODYTEMP] %s : of node\n", __func__);
	else {
		pr_err("[BODYTEMP] %s : no of node\n", __func__);
		goto err_setup_reg;
	}

	ret = mlx90615_parse_dt(&client->dev, mlx90615);

	if (ret) {
		pr_err("[BODYTEMP] %s : parse dt error\n", __func__);
		//goto err_parse_dt;
	}

	mlx90615->i2c_client = client;
	mlx90615->always_on = 0;

	i2c_set_clientdata(client, mlx90615);

	mutex_init(&mlx90615->power_lock);
	mutex_init(&mlx90615->read_lock);
#if 0
	/* Check if the device is there or not. */
	ret = i2c_master_send(mlx90615->i2c_client,
				CMD_READ_ID_REG, MLX90615_CMD_LENGTH);
	if (ret < 0) {
		pr_err("[BODYTEMP] %s: failed i2c_master_send (err = %d)\n",
			__func__, ret);
		/* goto err_i2c_master_send;*/
	}
#endif
	/* allocate mlx90615 input_device */
	mlx90615->input = input_allocate_device();
	if (!mlx90615->input) {
		pr_err("[BODYTEMP] %s: could not allocate input device\n",
			__func__);
		goto err_input_allocate_device;
	}

	mlx90615->input->name = "bodytemp_sensor";
	input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_AMBIENT_TEMP);
	input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_OBJECT_TEMP);
	input_set_drvdata(mlx90615->input, mlx90615);

	ret = input_register_device(mlx90615->input);
	if (ret < 0) {
		input_free_device(mlx90615->input);
		pr_err("[BODYTEMP] %s: could not register input device\n",
			__func__);
		goto err_input_register_device;
	}

	ret = sensors_create_symlink(&mlx90615->input->dev.kobj,
					mlx90615->input->name);
	if (ret < 0) {
		input_unregister_device(mlx90615->input);
		goto err_sysfs_create_symlink;
	}

	ret = sysfs_create_group(&mlx90615->input->dev.kobj,
				&mlx90615_attribute_group);
	if (ret) {
		pr_err("[BODYTEMP] %s: could not create sysfs group\n",
			__func__);
		goto err_sysfs_create_group;
	}
	ret = sensors_register(mlx90615->mlx90615_dev,
			mlx90615, bodytemp_sensor_attrs, "bodytemp_sensor");
	if (ret) {
		pr_err("[BODYTEMP] %s: cound not register sensor device(%d).\n",
			__func__, ret);
		goto err_sysfs_create_symlink;
	}
	/* Timer settings. We poll for mlx90615 values using a timer. */
	hrtimer_init(&mlx90615->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	mlx90615->poll_delay = ns_to_ktime(DEFAULT_DELAY * NSEC_PER_MSEC);
	mlx90615->timer.function = timer_func;

	/* Timer just fires off a work queue request.  We need a thread
	   to read the i2c (can be slow and blocking). */
	mlx90615->mlx90615_wq =
		create_singlethread_workqueue("mlx90615_bidytemp_wq");
	if (!mlx90615->mlx90615_wq) {
		ret = -ENOMEM;
		pr_err("[BODYTEMP] %s: could not create mlx90615 workqueue\n", __func__);
		goto err_create_workqueue;
	}

	/* This is the thread function we run on the work queue */
	INIT_WORK(&mlx90615->work_mlx90615, mlx90615_work_func);

	pr_info("[BODYTEMP] %s is success.\n", __func__);

	goto done;


err_create_workqueue:
	sysfs_remove_group(&mlx90615->input->dev.kobj,
				&mlx90615_attribute_group);
	/* sensors_classdev_unregister(mlx90615->mlx90615_dev);*/
	destroy_workqueue(mlx90615->mlx90615_wq);
err_sysfs_create_group:
	input_unregister_device(mlx90615->input);
err_sysfs_create_symlink:
	sensors_remove_symlink(&mlx90615->input->dev.kobj,
			mlx90615->input->name);
err_input_register_device:
err_input_allocate_device:
	mutex_destroy(&mlx90615->read_lock);
	mutex_destroy(&mlx90615->power_lock);
err_setup_reg:
//err_parse_dt:
	kfree(mlx90615);
done:
	return ret;
}