工作中有时需要创建proc文件来debug,这样的代码网上很多,我也参考了网上的代码,作了以下调整,记录下来以资后用。
static int proc_read(char *page, char **start, off_t off, int count, int *eof,
void *data) {
u8 value;
int len;
i2c_smbus_read_i2c_block_data(i2c_client, (u8)register_addr, 1, &value);
len = sprintf(page, "the value of register addr(0x%x) is 0x%x", register_addr, value);
printk("page is %s\n", page);
return len;
}
static int proc_write(struct file *file, const char *buffer, unsigned long count,
void *data) {
int tmp;
char type;
unsigned char value;
char *p = NULL;
p = strstr(buffer, "type=");
if (p)
{
type = p[5]