1, create a device node in the/sys/class/directory, such as creating a CLASS_TEST_USB device node
[CPP]View Plaincopy
- Static struct CALSS *test_class;
- Test_class = Class_creat (This_module,"Class_test_usb");
2, create another device node in the CLASS_TEST_USB directory android0, as follows
[CPP]View Plaincopy
- struct device *dev;
- dev = device_creat (Test_calss,null,mkdev (0,0), NULL,"android0");
- if (Is_err (dev))
- return Ptr_err (dev);
3, create several other device nodes in the/sys/class/class_test_usb/android0/directory enable state, etc.
[CPP]View Plaincopy
- Static struct device_attribute* test_attributes[]={
- &dev_attr_state,
- &dev_attr_enable,
- Null
- }
- Static Device_attr (Enable,s_irugo | S_iwusr,enable_show,enable_store);
- struct Device_attribute * * attrs=test_attributes;
- struct Device_attribute *attr;
- int err;
- while ((attr=*attrs++))
- {
- Err=device_creat_file (DEV,ATTR);
- if (err)
- {
- Device_destory (TEST_CLASS,DEV->DEVT);
- return err;
- }
- }
[Linux Driver] device driver model related (ii)--Common API