http://blog.csdn.net/wucongdonglai/article/details/6134653
http://blog.csdn.net/z2007b/article/details/6388753
http://bbs.chinaunix.net/thread-2004737-1-1.html
http://hi.baidu.com/serial_story/blog/item/65dd870e2e4fe5eb37d122f6.html
static struct kobj_attribute reg_attri =
__ATTR(testreg, (S_IRUGO|S_IWUGO), reg_id_show, reg_id_stroe);
/*
* Create a group of attributes so that we can create and destroy them all
* at once.
*/
static struct attribute *attrs[] = {
&product_attri.attr,
&vendor_attri.attr,
®_attri.attr,
NULL, /* need to NULL terminate the list of attributes */
};
/*
* An unnamed attribute group will put all of the attributes directly in
* the kobject directory. If we specify a name, a subdirectory will be
* created for the attributes with the directory being the name of the
* attribute group.
*/
static struct attribute_group test_attr_group = {
.attrs = attrs,
};
static int test_plat_probe(struct platform_device *pdev)
{
int retval;
struct test_plat_data *pdata = pdev->dev.platform_data;
test_product_id = pdata->product_id;
test_vendor_id = pdata->vendor_id;
printk("product_id: %s \n vendor_id: %s \n ",test_product_id,test_vendor_id);
test_plat_kobj = kobject_create_and_add("test_plat", kernel_kobj);
if (!test_plat_kobj)
{
printk("failed to create test_plat_kobj");
return -ENOMEM;
}
/* Create the files associated with this kobject */
retval = sysfs_create_group(test_plat_kobj, &test_attr_group);
if (retval)
{
printk("failed to create example group");
kobject_put(test_plat_kobj);
}
return retval;
}
static int test_plat_remove(struct platform_device *pdev)
{
kobject_put(test_plat_kobj);
return 0;
}
static struct platform_driver test_plat_driver = {
.probe = test_plat_probe,
.remove = test_plat_remove,
.driver = {
.name = "testplat",
.owner = THIS_MODULE,
},
};
static int __init test_drv_init(void)
{
return platform_driver_register(&test_plat_driver);
}
static void __exit test_drv_exit(void)
{
platform_driver_unregister(&test_plat_driver);
}