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

Commit 4a09066d authored by Jie Cheng's avatar Jie Cheng Committed by Gerrit - the friendly Code Review server
Browse files

sensors: Add the class device support for stk3x1x sensor



Add the sensor class device support for the stk3x1x 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: Id601679ec219ce541e8ee92837185461c9dc74bd
Signed-off-by: default avatarJie Cheng <rockiec@codeaurora.org>
parent a0773975
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <linux/input.h>
#include <linux/sensors.h>
#include <linux/workqueue.h>
#include <linux/irq.h>
#include <linux/delay.h>
@@ -181,6 +182,35 @@

#define STK_FIR_LEN 16
#define MAX_FIR_LEN 32

static struct sensors_classdev sensors_light_cdev = {
	.name = "stk3x1x-light",
	.vendor = "Sensortek",
	.version = 1,
	.handle = SENSORS_LIGHT_HANDLE,
	.type = SENSOR_TYPE_LIGHT,
	.max_range = "6500",
	.resolution = "0.0625",
	.sensor_power = "0.09",
	.min_delay = 0,
	.fifo_reserved_event_count = 0,
	.fifo_max_event_count = 0,
};

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

struct data_filter {
	u16 raw[MAX_FIR_LEN];
	int sum;
@@ -2368,6 +2398,14 @@ static int stk3x1x_probe(struct i2c_client *client,
	ps_data->stk_early_suspend.resume = stk3x1x_late_resume;
	register_early_suspend(&ps_data->stk_early_suspend);
#endif
	/* make sure everything is ok before registering the class device */
	err = sensors_classdev_register(&client->dev, &sensors_light_cdev);
	if (err)
		goto err_power_on;
	err = sensors_classdev_register(&client->dev, &sensors_proximity_cdev);
	if (err)
		goto err_class_sysfs;

	/* enable device power only when it is enabled */
	err = stk3x1x_power_ctl(ps_data, false);
	if (err)
@@ -2378,6 +2416,9 @@ static int stk3x1x_probe(struct i2c_client *client,

err_init_all_setting:
	stk3x1x_power_ctl(ps_data, false);
	sensors_classdev_unregister(&sensors_proximity_cdev);
err_class_sysfs:
	sensors_classdev_unregister(&sensors_light_cdev);
err_power_on:
	stk3x1x_power_init(ps_data, false);
err_power_init: