diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-16 15:59:38 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-16 15:59:38 +0200 |
commit | 130395cf96bc2eff45e54eacd73cc251a30e92ea (patch) | |
tree | f51d99818c8c085d91ec3e2a313343fe1186317f /driver/main.c | |
parent | 3a0e12380b6316db215fd5c086fe6d8be108bd01 (diff) |
Diffstat (limited to 'driver/main.c')
-rw-r--r-- | driver/main.c | 19 |
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"); |