aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-16 15:59:38 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-16 15:59:38 +0200
commit130395cf96bc2eff45e54eacd73cc251a30e92ea (patch)
treef51d99818c8c085d91ec3e2a313343fe1186317f
parent3a0e12380b6316db215fd5c086fe6d8be108bd01 (diff)
i2c driver recv working :tada:HEADmaster
-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,
+};
+