BigW Consortium Gitlab

Commit 39e41950 by Forest Godfrey

Add basic device interaction to get revision and firmware version.

parent 14d9b079
../arduino_sketch/ai2c_interface.h
\ No newline at end of file
......@@ -39,6 +39,7 @@
*/
#include "ai2c.h"
#include "ai2c_platform_data.h"
#include "ai2c_interface.h"
#define IRQ_GPIO_PIN 9
#define GPIO_IRQ_NAME "ai2c_keyboard_irq"
......@@ -51,6 +52,42 @@ static LIST_HEAD(driver_list);
static DEFINE_MUTEX(driver_list_lock);
static void
device_write_register(struct i2c_client *client, uint8_t raddr, uint8_t value) {
uint8_t tmp[2];
tmp[0] = raddr;
tmp[1] = value;
i2c_master_send(client, tmp, 2);
}
#if 0
static uint8_t
device_read_byte(struct i2c_client *client) {
uint8_t tmp;
i2c_master_recv(client, &tmp, 1);
return tmp;
}
static uint16_t
device_read_word(struct i2c_client *client) {
uint16_t tmp;
i2c_master_recv(client, (unsigned char *)&tmp, 1);
return tmp;
}
#endif
static void
device_read_register(struct i2c_client *client, void *buffer, uint8_t raddr, uint8_t len) {
device_write_register(client, AI2C_REGISTER_READ_ADDR, raddr);
device_write_register(client, AI2C_REGISTER_READ_BYTES, len);
i2c_master_recv(client, (unsigned char *)buffer, len);
}
static void
ai2c_intr(struct work_struct *work) {
arduino_i2c_driver_data_t *drv_info = container_of(
work, arduino_i2c_driver_data_t, intr_upper_work);
......@@ -81,8 +118,12 @@ ai2c_intr_lower(int irq, void *data) {
static int
ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {
int i;
int ret = 0;
int flags = 0;
uint16_t dev_id;
uint8_t dev_rev;
char dev_build_str[AI2C_VER_STR_LEN];
const arduino_i2c_keyboard_platform_data_t *pdata =
dev_get_platdata(&client->dev);
arduino_i2c_driver_data_t *drv_info = NULL;
......@@ -94,6 +135,19 @@ ai2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {
goto out;
}
/*
* Get/validate/print device information
*/
device_read_register(client, &dev_id, AI2C_REGISTER_ID_LOW, 2);
device_read_register(client, &dev_rev, AI2C_REGISTER_REG_REV, 1);
for (i = 0; i < AI2C_VER_STR_LEN; i++) {
device_read_register(client, &(dev_build_str[i]), AI2C_REGISTER_VERS_STR + i, 1);
}
dev_build_str[sizeof(dev_build_str) - 1] = '\0';
dev_info(&client->dev, "Device ID: 0x%04x\nDevice Revision: 0x%02x\nDevice Firmware Build: \"%s\"\n",
dev_id, dev_rev, dev_build_str);
drv_info = (arduino_i2c_driver_data_t *)kmalloc(sizeof(arduino_i2c_driver_data_t), GFP_KERNEL);
if (!drv_info) {
dev_err(&client->dev, "Unable to allocate driver memory");
......
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