|
@@ -27,6 +27,8 @@ static unsigned int invert;
|
|
module_param(invert, bool, S_IWUSR | S_IRUGO);
|
|
module_param(invert, bool, S_IWUSR | S_IRUGO);
|
|
MODULE_PARM_DESC(invert, "Invert input data on X and Y axis");
|
|
MODULE_PARM_DESC(invert, "Invert input data on X and Y axis");
|
|
|
|
|
|
|
|
+static DEFINE_MUTEX(ams_input_mutex);
|
|
|
|
+
|
|
static void ams_idev_poll(struct input_polled_dev *dev)
|
|
static void ams_idev_poll(struct input_polled_dev *dev)
|
|
{
|
|
{
|
|
struct input_dev *idev = dev->input;
|
|
struct input_dev *idev = dev->input;
|
|
@@ -50,13 +52,11 @@ static void ams_idev_poll(struct input_polled_dev *dev)
|
|
}
|
|
}
|
|
|
|
|
|
/* Call with ams_info.lock held! */
|
|
/* Call with ams_info.lock held! */
|
|
-static void ams_input_enable(void)
|
|
|
|
|
|
+static int ams_input_enable(void)
|
|
{
|
|
{
|
|
struct input_dev *input;
|
|
struct input_dev *input;
|
|
s8 x, y, z;
|
|
s8 x, y, z;
|
|
-
|
|
|
|
- if (ams_info.idev)
|
|
|
|
- return;
|
|
|
|
|
|
+ int error;
|
|
|
|
|
|
ams_sensors(&x, &y, &z);
|
|
ams_sensors(&x, &y, &z);
|
|
ams_info.xcalib = x;
|
|
ams_info.xcalib = x;
|
|
@@ -65,7 +65,7 @@ static void ams_input_enable(void)
|
|
|
|
|
|
ams_info.idev = input_allocate_polled_device();
|
|
ams_info.idev = input_allocate_polled_device();
|
|
if (!ams_info.idev)
|
|
if (!ams_info.idev)
|
|
- return;
|
|
|
|
|
|
+ return -ENOMEM;
|
|
|
|
|
|
ams_info.idev->poll = ams_idev_poll;
|
|
ams_info.idev->poll = ams_idev_poll;
|
|
ams_info.idev->poll_interval = 25;
|
|
ams_info.idev->poll_interval = 25;
|
|
@@ -84,14 +84,18 @@ static void ams_input_enable(void)
|
|
set_bit(EV_KEY, input->evbit);
|
|
set_bit(EV_KEY, input->evbit);
|
|
set_bit(BTN_TOUCH, input->keybit);
|
|
set_bit(BTN_TOUCH, input->keybit);
|
|
|
|
|
|
- if (input_register_polled_device(ams_info.idev)) {
|
|
|
|
|
|
+ error = input_register_polled_device(ams_info.idev);
|
|
|
|
+ if (error) {
|
|
input_free_polled_device(ams_info.idev);
|
|
input_free_polled_device(ams_info.idev);
|
|
ams_info.idev = NULL;
|
|
ams_info.idev = NULL;
|
|
- return;
|
|
|
|
|
|
+ return error;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ joystick = 1;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-/* Call with ams_info.lock held! */
|
|
|
|
static void ams_input_disable(void)
|
|
static void ams_input_disable(void)
|
|
{
|
|
{
|
|
if (ams_info.idev) {
|
|
if (ams_info.idev) {
|
|
@@ -99,6 +103,8 @@ static void ams_input_disable(void)
|
|
input_free_polled_device(ams_info.idev);
|
|
input_free_polled_device(ams_info.idev);
|
|
ams_info.idev = NULL;
|
|
ams_info.idev = NULL;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ joystick = 0;
|
|
}
|
|
}
|
|
|
|
|
|
static ssize_t ams_input_show_joystick(struct device *dev,
|
|
static ssize_t ams_input_show_joystick(struct device *dev,
|
|
@@ -110,39 +116,42 @@ static ssize_t ams_input_show_joystick(struct device *dev,
|
|
static ssize_t ams_input_store_joystick(struct device *dev,
|
|
static ssize_t ams_input_store_joystick(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
{
|
|
{
|
|
- if (sscanf(buf, "%d\n", &joystick) != 1)
|
|
|
|
|
|
+ unsigned long enable;
|
|
|
|
+ int error = 0;
|
|
|
|
+
|
|
|
|
+ if (strict_strtoul(buf, 0, &enable) || enable > 1)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- mutex_lock(&ams_info.lock);
|
|
|
|
|
|
+ mutex_lock(&ams_input_mutex);
|
|
|
|
|
|
- if (joystick)
|
|
|
|
- ams_input_enable();
|
|
|
|
- else
|
|
|
|
- ams_input_disable();
|
|
|
|
|
|
+ if (enable != joystick) {
|
|
|
|
+ if (enable)
|
|
|
|
+ error = ams_input_enable();
|
|
|
|
+ else
|
|
|
|
+ ams_input_disable();
|
|
|
|
+ }
|
|
|
|
|
|
- mutex_unlock(&ams_info.lock);
|
|
|
|
|
|
+ mutex_unlock(&ams_input_mutex);
|
|
|
|
|
|
- return count;
|
|
|
|
|
|
+ return error ? error : count;
|
|
}
|
|
}
|
|
|
|
|
|
static DEVICE_ATTR(joystick, S_IRUGO | S_IWUSR,
|
|
static DEVICE_ATTR(joystick, S_IRUGO | S_IWUSR,
|
|
ams_input_show_joystick, ams_input_store_joystick);
|
|
ams_input_show_joystick, ams_input_store_joystick);
|
|
|
|
|
|
-/* Call with ams_info.lock held! */
|
|
|
|
int ams_input_init(void)
|
|
int ams_input_init(void)
|
|
{
|
|
{
|
|
- int result;
|
|
|
|
-
|
|
|
|
- result = device_create_file(&ams_info.of_dev->dev, &dev_attr_joystick);
|
|
|
|
-
|
|
|
|
- if (!result && joystick)
|
|
|
|
|
|
+ if (joystick)
|
|
ams_input_enable();
|
|
ams_input_enable();
|
|
- return result;
|
|
|
|
|
|
+
|
|
|
|
+ return device_create_file(&ams_info.of_dev->dev, &dev_attr_joystick);
|
|
}
|
|
}
|
|
|
|
|
|
-/* Call with ams_info.lock held! */
|
|
|
|
void ams_input_exit(void)
|
|
void ams_input_exit(void)
|
|
{
|
|
{
|
|
- ams_input_disable();
|
|
|
|
device_remove_file(&ams_info.of_dev->dev, &dev_attr_joystick);
|
|
device_remove_file(&ams_info.of_dev->dev, &dev_attr_joystick);
|
|
|
|
+
|
|
|
|
+ mutex_lock(&ams_input_mutex);
|
|
|
|
+ ams_input_disable();
|
|
|
|
+ mutex_unlock(&ams_input_mutex);
|
|
}
|
|
}
|