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

Commit 7eb5bed5 authored by Jie Cheng's avatar Jie Cheng
Browse files

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: default avatarJie Cheng <rockiec@codeaurora.org>
parent bfd7e850
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -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 @@ static int mma8x5x_probe(struct i2c_client *client,
		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: