sensors: Add the class device support for mma8x5x sensor
Add the sensor class device support for the mma8x5x accelerometer
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: I6b96c43fa6da78d84a950f67843c62a41e03aa99
Signed-off-by: Jie Cheng <rockiec@codeaurora.org>
diff --git a/drivers/input/misc/mma8x5x.c b/drivers/input/misc/mma8x5x.c
index 91aa928..d5053eb 100644
--- a/drivers/input/misc/mma8x5x.c
+++ b/drivers/input/misc/mma8x5x.c
@@ -27,6 +27,7 @@
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input-polldev.h>
+#include <linux/sensors.h>
#include <linux/regulator/consumer.h>
#include <linux/of_gpio.h>
@@ -55,6 +56,20 @@
#define MMA_SHUTTEDDOWN (1 << 31)
#define MMA_STATE_MASK (~MMA_SHUTTEDDOWN)
+static struct sensors_classdev sensors_cdev = {
+ .name = "mma8x5x-accel",
+ .vendor = "Freescale",
+ .version = 1,
+ .handle = SENSORS_ACCELERATION_HANDLE,
+ .type = SENSOR_TYPE_ACCELEROMETER,
+ .max_range = "19.6",
+ .resolution = "0.01",
+ .sensor_power = "0.2",
+ .min_delay = 2000,
+ .fifo_reserved_event_count = 0,
+ .fifo_max_event_count = 0,
+};
+
struct sensor_regulator {
struct regulator *vreg;
const char *name;
@@ -644,11 +659,19 @@
result = -EINVAL;
goto err_create_sysfs;
}
+ result = sensors_classdev_register(&client->dev, &sensors_cdev);
+ if (result) {
+ dev_err(&client->dev, "create class device file failed!\n");
+ result = -EINVAL;
+ goto err_create_class_sysfs;
+ }
dev_info(&client->dev,
"%s:mma8x5x device driver probe successfully, position =%d\n",
__func__, pdata->position);
return 0;
+err_create_class_sysfs:
+ sysfs_remove_group(&idev->dev.kobj, &mma8x5x_attr_group);
err_create_sysfs:
input_unregister_polled_device(pdata->poll_dev);
err_register_polled_device: