BigW Consortium Gitlab

Commit 258f589f by Forest Godfrey

Add basic structure of evdev to send messages.

parent 90f2e9ac
...@@ -24,6 +24,7 @@ typedef struct arduino_i2c_driver_data_s { ...@@ -24,6 +24,7 @@ typedef struct arduino_i2c_driver_data_s {
struct list_head driver_list; struct list_head driver_list;
struct work_struct intr_upper_work; struct work_struct intr_upper_work;
struct i2c_client *client; struct i2c_client *client;
struct input_dev *indev;
int irq_num; int irq_num;
int irq_pin; int irq_pin;
int irq_count; int irq_count;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/list.h> #include <linux/list.h>
...@@ -58,6 +59,11 @@ ai2c_intr(struct work_struct *work) { ...@@ -58,6 +59,11 @@ ai2c_intr(struct work_struct *work) {
dev_info(&drv_info->client->dev, "ai2c_intr: entered\n"); dev_info(&drv_info->client->dev, "ai2c_intr: entered\n");
i2c_smbus_write_byte_data(drv_info->client, 50, 48); i2c_smbus_write_byte_data(drv_info->client, 50, 48);
input_report_key(drv_info->indev, BTN_0, 1);
input_sync(drv_info->indev);
input_report_key(drv_info->indev, BTN_0, 0);
input_sync(drv_info->indev);
return; return;
} }
...@@ -118,10 +124,34 @@ ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { ...@@ -118,10 +124,34 @@ ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {
flags |= IRQF_TRIGGER_FALLING; flags |= IRQF_TRIGGER_FALLING;
ret = request_irq(drv_info->irq_num, ai2c_intr_lower, flags, "ai2c_keyboard", drv_info); ret = request_irq(drv_info->irq_num, ai2c_intr_lower, flags, "ai2c_keyboard", drv_info);
if (ret < 0) { if (ret < 0) {
dev_err(&client->dev, "ai2c: request_irq failed: error %d\n", ret); dev_err(&client->dev, "ai2c: request_irq failed: error %d", ret);
goto out_cleanup; goto out_cleanup;
} }
drv_info->indev = devm_input_allocate_device(&client->dev);
if (!drv_info->indev) {
ret = -ENOMEM;
dev_err(&client->dev, "ai2c: unable to allocate input device");
goto out_cleanirq;
}
drv_info->indev->name = "arduino_i2c";
drv_info->indev->phys = "arduino_i2c/input0";
drv_info->indev->dev.parent = &client->dev;
drv_info->indev->id.bustype = BUS_I2C;
drv_info->indev->id.vendor = 0x4242;
drv_info->indev->id.product = 0x4242;
drv_info->indev->id.version = 0x0001;
drv_info->indev->keycodesize = sizeof(unsigned short);
drv_info->indev->keycodemax = BTN_0 + 1;
drv_info->indev->evbit[0] = BIT_MASK(EV_KEY);
drv_info->indev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
ret = input_register_device(drv_info->indev);
if (ret) {
dev_err(&client->dev, "ai2c: unable to register input device: %d", ret);
goto out_cleanindev;
}
irq_set_irq_type(drv_info->irq_num, IRQ_TYPE_EDGE_FALLING); irq_set_irq_type(drv_info->irq_num, IRQ_TYPE_EDGE_FALLING);
drv_info->client = client; drv_info->client = client;
...@@ -136,6 +166,10 @@ ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { ...@@ -136,6 +166,10 @@ ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {
return 0; return 0;
out_cleanindev:
input_free_device(drv_info->indev);
out_cleanirq:
free_irq(drv_info->irq_num, drv_info);
out_cleanup: out_cleanup:
gpio_free(drv_info->irq_num); gpio_free(drv_info->irq_num);
out_dealloc: out_dealloc:
...@@ -157,6 +191,8 @@ ai2c_remove(struct i2c_client *client) { ...@@ -157,6 +191,8 @@ ai2c_remove(struct i2c_client *client) {
dev_set_drvdata(&drv_info->client->dev, NULL); dev_set_drvdata(&drv_info->client->dev, NULL);
input_unregister_device(drv_info->indev);
mutex_lock(&driver_list_lock); mutex_lock(&driver_list_lock);
list_del(&drv_info->driver_list); list_del(&drv_info->driver_list);
mutex_unlock(&driver_list_lock); mutex_unlock(&driver_list_lock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment