aboutsummaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
Diffstat (limited to 'driver')
-rw-r--r--driver/main.c19
-rw-r--r--driver/main.h9
2 files changed, 27 insertions, 1 deletions
diff --git a/driver/main.c b/driver/main.c
index 498bb0f..0790a17 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -1,14 +1,31 @@
#include "main.h"
+struct i2c_client * i2c_client;
+
int lork_probe(struct i2c_client * client) {
- printk(KERN_INFO "%s()\n", __PRETTY_FUNCTION__);
+ int err = driver_create_file(&lork_driver.driver, &drv_attr);
+ if (err) return -EINVAL;
+
+ i2c_client = client; // this is a garbage solution
+ printk(KERN_INFO "%s(i2c addr %02x)\n", __PRETTY_FUNCTION__, client->addr);
+
return 0;
}
void lork_remove(struct i2c_client * client) {
+ driver_remove_file(&lork_driver.driver, &drv_attr);
+
+ printk(KERN_INFO "%s()\n", __PRETTY_FUNCTION__);
return;
}
+ssize_t drv_attr_show(struct device_driver* drv, char* buf) {
+ char recv[3];
+ int ret = i2c_master_recv(i2c_client, recv, sizeof(recv));
+ if (ret < 0) return 0; // error
+ return sprintf(buf, "%.*s\n", ret, recv);
+}
+
module_i2c_driver(lork_driver);
MODULE_LICENSE("Dual MIT/GPL");
diff --git a/driver/main.h b/driver/main.h
index 059f277..bdc4e5d 100644
--- a/driver/main.h
+++ b/driver/main.h
@@ -28,3 +28,12 @@ struct i2c_driver lork_driver = {
.id_table = lork_ids,
};
+ssize_t drv_attr_show(struct device_driver*, char*);
+static const struct driver_attribute drv_attr = {
+ .attr = {
+ .name = "foo", // -> /sys/bus/i2c/drivers/lork/foo
+ .mode = 0444,
+ },
+ .show = drv_attr_show,
+};
+