2021-07-22 11:25:32 +08:00
|
|
|
/*
|
|
|
|
* devicemodel.c
|
|
|
|
*/
|
2021-07-22 06:35:24 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
struct devicemodel_data {
|
|
|
|
char *greeting;
|
2021-07-22 06:58:13 +08:00
|
|
|
int number;
|
2021-07-22 06:35:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int devicemodel_probe(struct platform_device *dev)
|
|
|
|
{
|
2021-07-22 06:58:13 +08:00
|
|
|
struct devicemodel_data *pd =
|
|
|
|
(struct devicemodel_data *) (dev->dev.platform_data);
|
2021-07-22 06:35:24 +08:00
|
|
|
|
|
|
|
pr_info("devicemodel probe\n");
|
|
|
|
pr_info("devicemodel greeting: %s; %d\n", pd->greeting, pd->number);
|
|
|
|
|
|
|
|
/* Your device initialisation code */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int devicemodel_remove(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
pr_info("devicemodel example removed\n");
|
|
|
|
|
|
|
|
/* Your device removal code */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int devicemodel_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
pr_info("devicemodel example suspend\n");
|
|
|
|
|
|
|
|
/* Your device suspend code */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int devicemodel_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
pr_info("devicemodel example resume\n");
|
|
|
|
|
|
|
|
/* Your device resume code */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:58:13 +08:00
|
|
|
static const struct dev_pm_ops devicemodel_pm_ops = {
|
2021-07-22 06:35:24 +08:00
|
|
|
.suspend = devicemodel_suspend,
|
|
|
|
.resume = devicemodel_resume,
|
|
|
|
.poweroff = devicemodel_suspend,
|
|
|
|
.freeze = devicemodel_suspend,
|
|
|
|
.thaw = devicemodel_resume,
|
2021-07-26 02:10:34 +08:00
|
|
|
.restore = devicemodel_resume,
|
|
|
|
};
|
2021-07-22 06:35:24 +08:00
|
|
|
|
|
|
|
static struct platform_driver devicemodel_driver = {
|
2021-07-22 06:58:13 +08:00
|
|
|
.driver =
|
|
|
|
{
|
|
|
|
.name = "devicemodel_example",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.pm = &devicemodel_pm_ops,
|
|
|
|
},
|
|
|
|
.probe = devicemodel_probe,
|
|
|
|
.remove = devicemodel_remove,
|
2021-07-22 06:35:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int devicemodel_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_info("devicemodel init\n");
|
|
|
|
|
|
|
|
ret = platform_driver_register(&devicemodel_driver);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
pr_err("Unable to register driver\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void devicemodel_exit(void)
|
|
|
|
{
|
|
|
|
pr_info("devicemodel exit\n");
|
|
|
|
platform_driver_unregister(&devicemodel_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Linux Device Model example");
|
|
|
|
|
|
|
|
module_init(devicemodel_init);
|
|
|
|
module_exit(devicemodel_exit);
|