Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c911a981 authored by Jie Cheng's avatar Jie Cheng
Browse files

sensors: Add the class device support for cm36283 sensor



Add the sensor class device support for the cm36283 light and
proximity sensor. By using the class device, the driver will
create the subfolder in the "/sys/class/sensors/". The userspace
app could detect the sensors by searching this folder.

Change-Id: I4d96ed54ee647069a5f1cf592c4aea1d8636a0f5
Signed-off-by: default avatarJie Cheng <rockiec@codeaurora.org>
parent bfd7e850
Loading
Loading
Loading
Loading
+40 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/sensors.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -61,6 +62,35 @@
#define CM36283_PS_MAX_POLL_DELAY	1000
#define CM36283_PS_DEFAULT_POLL_DELAY	100

static struct sensors_classdev sensors_light_cdev = {
	.name = "cm36283-light",
	.vendor = "Capella",
	.version = 1,
	.handle = SENSORS_LIGHT_HANDLE,
	.type = SENSOR_TYPE_LIGHT,
	.max_range = "6553",
	.resolution = "0.0125",
	.sensor_power = "0.15",
	.min_delay = 0,
	.fifo_reserved_event_count = 0,
	.fifo_max_event_count = 0,
};

static struct sensors_classdev sensors_proximity_cdev = {
	.name = "cm36283-proximity",
	.vendor = "Capella",
	.version = 1,
	.handle = SENSORS_PROXIMITY_HANDLE,
	.type = SENSOR_TYPE_PROXIMITY,
	.max_range = "5.0",
	.resolution = "5.0",
	.sensor_power = "0.18",
	.min_delay = 0,
	.fifo_reserved_event_count = 0,
	.fifo_max_event_count = 0,
};


static const int als_range[] = {
	[CM36283_ALS_IT0] = 6554,
	[CM36283_ALS_IT1] = 3277,
@@ -1688,13 +1718,22 @@ static int cm36283_probe(struct i2c_client *client,
	if (ret)
		goto err_create_ps_device_file;

	ret = sensors_classdev_register(&client->dev, &sensors_light_cdev);
	if (ret)
		goto err_create_ps_device_file;

	ret = sensors_classdev_register(&client->dev, &sensors_proximity_cdev);
	if (ret)
		goto err_create_class_sysfs;

	mutex_init(&wq_lock);
	INIT_DELAYED_WORK(&lpi->ldwork, lsensor_delay_work_handler);
	INIT_DELAYED_WORK(&lpi->pdwork, psensor_delay_work_handler);
	dev_dbg(&lpi->i2c_client->dev, "%s: Probe success!\n", __func__);

	return ret;

err_create_class_sysfs:
	sensors_classdev_unregister(&sensors_light_cdev);
err_create_ps_device_file:
	device_unregister(lpi->ps_dev);
err_create_ps_device: