linuxe kernel platform_set_drvdata 和 platform_get_drvdata的使用说明

#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for pr_info() */
#include <linux/module.h> /* Needed by all modules */
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/timer.h>
#include <linux/bug.h>
#include <linux/i2c.h>
#include <linux/slab.h>

#define  TRUE(condition)  BUG_ON(!(condition))

/**
 *
 *
 my_platform_device003 {
 status = "okay";
 compatible ="my_platform_device_003";
 interrupt-parent = <&gpio1>;
 interrupts = <7 2>;
 };


 https://stackoverflow.com/questions/12256986/what-is-the-difference-between-devm-kzalloc-and-kzalloc-in-linux-driver-prog

 */

struct data {
	char name[48];
	int timeout;
};

int myprobe(struct platform_device *pdev) {
	struct data *priv;
	char *tmp="wsxedc";
	priv = devm_kzalloc(&pdev->dev, sizeof(*priv),
	GFP_KERNEL);
	memcpy(priv->name,tmp,strlen(tmp));
	priv->timeout = 14000 ;
//	strlcpy(priv->name, "Au1xxx PSC I2C 147258", sizeof(priv->name));
	pr_info("myplatformdriver myprobe  start \n");
	platform_set_drvdata(pdev, priv);
	pr_info("myplatformdriver myprobe end  \n");
	return 0;
}

int myremove(struct platform_device *pdev) {
	struct data *a = platform_get_drvdata(pdev);
	pr_info("myplatformdriver myremove  start  \n");
	pr_info("a->name = %s\n", a->name);
	pr_info("a->timeout = %d\n", a->timeout);
	pr_info("myplatformdriver myremove  end \n");
	return 0;
}

int mysuspend(struct device *pdev, pm_message_t state) {
	pr_err("myplatformdriver mysuspend \n");
	return 0;
}

int myresume(struct device *pdev) {
	pr_info("myplatformdriver myresume \n");
	return 0;
}

struct of_device_id my_of_match_table =
		{ .compatible = "my_platform_device_003", };

struct platform_driver my_platform_driver = { .driver = { .of_match_table =
		&my_of_match_table, .name = "my-platform-driver", .owner = THIS_MODULE,
		.suspend = mysuspend, .resume = myresume, }, .probe = myprobe, .remove =
		myremove, };

module_platform_driver(my_platform_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值