aboutsummaryrefslogtreecommitdiff
path: root/driver/main.c
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 /driver/main.c
parent3a0e12380b6316db215fd5c086fe6d8be108bd01 (diff)
i2c driver recv working :tada:HEADmaster
Diffstat (limited to 'driver/main.c')
-rw-r--r--driver/main.c19
1 files changed, 18 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");