I hijacked the matrix-keypad platform device driver and was attempting to add a sysfs attribute so I could read the status of the button presses. I was able to get the new entry to show up in my file system, but when I attempt to read it (cat
) nothing is shown on the console. I added a prink()
into my show function and I can see it being executed and the buf
being filled correctly with my value, but nothing on the UI.
/* Here's my show function, I can see the printk so I know it's getting called and the return value (ret) is 3 and the buffer has "10" in it, so the scnprintf call works too. */staticssize_t btn_output(struct device *dev,char*buf){staticint count =0;ssize_t ret = scnprintf(buf, PAGE_SIZE,"%d\n",10);if(count ==0){ printk("called btn_output: ret (%d) size (%d) buf: %s\n", ret, sw1, buf); count++;}return ret;}/* Here's where I set the button device to the show function btn_output */static DEVICE_ATTR(button, S_IRUSR, btn_output, NULL);/* Here's where I added the new attribute for the device*/staticint __devinit matrix_keypad_probe(struct platform_device *pdev){/* ...bunch of probe-y code here ...*/ device_create_file(&pdev->dev,&dev_attr_button);
So that's all the code I added (besides a device_remove_file
call in the exit routine), I can find my new entry:
root@am335x-evm:/sys/devices/platform/matrix-keypad# ls
button driver input modalias power subsystem uevent
root@am335x-evm:/sys/devices/platform/matrix-keypad# cat button
[ 319.582672] called btn_output: ret (3) size (0) buf: 10
[ 319.582672]
root@am335x-evm:/sys/devices/platform/matrix-keypad# cat button
root@am335x-evm:/sys/devices/platform/matrix-keypad#
And when I cat
the file I see the printk
message, but the buffer value "10"
is not displayed as I expected it would be.
What am I missing here?