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

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

sensors: Add the class device support for bmp18x sensor



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

Change-Id: Id947e8b7dd101d15bc7ffcbe5a01fa9c6cf28efe
Signed-off-by: default avatarJie Cheng <rockiec@codeaurora.org>
parent bfd7e850
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/input.h>
#include <linux/sensors.h>
#include <linux/workqueue.h>
#include <linux/workqueue.h>
#include <linux/module.h>
#include <linux/module.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_HAS_EARLYSUSPEND
@@ -103,6 +104,20 @@ struct bmp18x_data {
	u32					enable;
	u32					enable;
};
};


static struct sensors_classdev sensors_cdev = {
	.name = "bmp18x-pressure",
	.vendor = "Bosch",
	.version = 1,
	.handle = SENSORS_PRESSURE_HANDLE,
	.type = SENSOR_TYPE_PRESSURE,
	.max_range = "1100.0",
	.resolution = "0.01",
	.sensor_power = "0.67",
	.min_delay = 20000,
	.fifo_reserved_event_count = 0,
	.fifo_max_event_count = 0,
};

#ifdef CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_HAS_EARLYSUSPEND
static void bmp18x_early_suspend(struct early_suspend *h);
static void bmp18x_early_suspend(struct early_suspend *h);
static void bmp18x_late_resume(struct early_suspend *h);
static void bmp18x_late_resume(struct early_suspend *h);
@@ -612,6 +627,13 @@ int bmp18x_probe(struct device *dev, struct bmp18x_data_bus *data_bus)
	err = sysfs_create_group(&data->input->dev.kobj, &bmp18x_attr_group);
	err = sysfs_create_group(&data->input->dev.kobj, &bmp18x_attr_group);
	if (err)
	if (err)
		goto error_sysfs;
		goto error_sysfs;

	err = sensors_classdev_register(&data->input->dev, &sensors_cdev);
	if (err) {
		pr_err("class device create failed: %d\n", err);
		goto error_class_sysfs;
	}

	/* workqueue init */
	/* workqueue init */
	INIT_DELAYED_WORK(&data->work, bmp18x_work_func);
	INIT_DELAYED_WORK(&data->work, bmp18x_work_func);
	data->delay  = BMP_DELAY_DEFAULT;
	data->delay  = BMP_DELAY_DEFAULT;
@@ -627,6 +649,8 @@ int bmp18x_probe(struct device *dev, struct bmp18x_data_bus *data_bus)
	dev_info(dev, "Succesfully initialized bmp18x!\n");
	dev_info(dev, "Succesfully initialized bmp18x!\n");
	return 0;
	return 0;


error_class_sysfs:
	sysfs_remove_group(&data->input->dev.kobj, &bmp18x_attr_group);
error_sysfs:
error_sysfs:
	bmp18x_input_delete(data);
	bmp18x_input_delete(data);
exit_free:
exit_free: