linux驱动结构之kobject及相关结构

 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,
 &reg_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);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值