#include "main.h" struct i2c_client * i2c_client; int lork_probe(struct i2c_client * client) { 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");