Let's look at the relevant parts of the code for our simple sysfs interfacing driver and try things out, step by step:
- Set up the device attribute structure (via the DEVICE_ATTR_RW macro; see the preceding section for more information) and create our first sysfs (pseudo) file:
// ch2/sysfs_simple_intf/sysfs_simple_intf.c
#define SYSFS_FILE1 llkdsysfs_debug_level
// [... <we show the actual read/write callback functions just a bit further down> ...]
static DEVICE_ATTR_RW(SYSFS_FILE1);
int __init sysfs_simple_intf_init(void)
{
[...]
/* << 0. The platform device is created via the platform_device_register_simple() API; code already shown above ... >> */
// 1. Create our first sysfile file : llkdsysfs_debug_level
/* The device_create_file() API creates a sysfs attribute file for
* given device (1st parameter); the second parameter is the pointer
* to it's struct device_attribute structure dev_attr_<name...