From 7bf52f65662887ec3e81a0b3c44ca1f99c8b0e6a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 10 Feb 2018 10:43:01 +0000 Subject: [PATCH] Reintroduce devicemodel example It was getting snaggled by gitignore --- .gitignore | 3 +- 4.14.8/examples/Makefile | 1 + 4.14.8/examples/devicemodel.c | 96 +++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 4.14.8/examples/devicemodel.c diff --git a/.gitignore b/.gitignore index a647297..3f736e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ *.ko *cmd *.swp -*mod* -*.symvers \ No newline at end of file +*.symvers diff --git a/4.14.8/examples/Makefile b/4.14.8/examples/Makefile index d566579..fff6966 100644 --- a/4.14.8/examples/Makefile +++ b/4.14.8/examples/Makefile @@ -22,6 +22,7 @@ obj-m += cryptosha256.o obj-m += cryptoapi.o obj-m += completions.o obj-m += example_tasklet.o +obj-m += devicemodel.o obj-m += example_spinlock.o obj-m += example_rwlock.o obj-m += example_atomic.o diff --git a/4.14.8/examples/devicemodel.c b/4.14.8/examples/devicemodel.c new file mode 100644 index 0000000..d6e937e --- /dev/null +++ b/4.14.8/examples/devicemodel.c @@ -0,0 +1,96 @@ +#include +#include +#include + +struct devicemodel_data { + char *greeting; + int number; +}; + +static int devicemodel_probe(struct platform_device *dev) +{ + struct devicemodel_data *pd = (struct devicemodel_data *)(dev->dev.platform_data); + + 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; +} + +static const struct dev_pm_ops devicemodel_pm_ops = +{ + .suspend = devicemodel_suspend, + .resume = devicemodel_resume, + .poweroff = devicemodel_suspend, + .freeze = devicemodel_suspend, + .thaw = devicemodel_resume, + .restore = devicemodel_resume +}; + +static struct platform_driver devicemodel_driver = { + .driver = { + .name = "devicemodel_example", + .owner = THIS_MODULE, + .pm = &devicemodel_pm_ops, + }, + .probe = devicemodel_probe, + .remove = devicemodel_remove, +}; + +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_AUTHOR("Bob Mottram"); +MODULE_DESCRIPTION("Linux Device Model example"); + +module_init(devicemodel_init); +module_exit(devicemodel_exit);