Skip to content
This repository
Newer
Older
100644 127 lines (106 sloc) 2.73 kb
e9983bbf »
2012-09-15 +platform_device and small updates
1 /*
2 * LDT - Linux Driver Template
9bef4ebb »
2012-09-26 +checkpatch
3 *
e9983bbf »
2012-09-15 +platform_device and small updates
4 * Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
5 *
6 * Dual BSD/GPL License
7 *
8 * platform_driver template driver
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
9 * Power Management (dev_pm_ops)
10 * Device Tree (of_device_id)
e9983bbf »
2012-09-15 +platform_device and small updates
11 *
12 */
13
14 #include <linux/module.h>
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
15 #include <linux/of.h>
e9983bbf »
2012-09-15 +platform_device and small updates
16 #include <linux/platform_device.h>
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
17 #include <linux/of_platform.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/of_irq.h>
2f323352 »
2012-10-14 tracing.h instead of ctracer.h
20 #include "tracing.h"
e9983bbf »
2012-09-15 +platform_device and small updates
21
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
22 static int irq;
23 static int port;
24 static int port_size;
25
76366fc5 »
2012-09-24 minor
26 static __devinit int ldt_plat_probe(struct platform_device *pdev)
e9983bbf »
2012-09-15 +platform_device and small updates
27 {
28 char *data = NULL;
29 struct resource *r;
c74ec321 »
2012-12-11 updates
30 struct device *dev = &pdev->dev;
31
e9983bbf »
2012-09-15 +platform_device and small updates
32 _entry:
c74ec321 »
2012-12-11 updates
33 dev_dbg(dev, "probe\n");
34 data = pdev->dev.platform_data;
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
35 irq = platform_get_irq(pdev, 0);
e9983bbf »
2012-09-15 +platform_device and small updates
36 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
c74ec321 »
2012-12-11 updates
37 pr_debug("pdev->dev.of_node = %p\n", pdev->dev.of_node);
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
38 #ifdef CONFIG_OF_DEVICE
39 if (pdev->dev.of_node) {
7f4c97ea »
2012-12-10 checkpatch and cgcc fixes
40 const __be32 *p;
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
41 int property;
42 of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
43 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
44 p = of_get_property(pdev->dev.of_node, "property", NULL);
45 if (p)
46 property = be32_to_cpu(*p);
47 }
48 #endif
15b26033 »
2012-12-10 +misc_drv.c fixes, +pr_fmt, removed timer
49 /*
50 sample code for drvdata usage:
51 struct ldt_data *drvdata = platform_get_drvdata(pdev);
52 platform_set_drvdata(pdev, drvdata);
53 */
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
54
55 data = dev_get_platdata(&pdev->dev);
56 pr_debug("%p %s\n", data, data);
57 r = platform_get_resource(pdev, IORESOURCE_IO, 0);
58 port = r->start;
59 port_size = resource_size(r);
c74ec321 »
2012-12-11 updates
60 /*
61 devm_kzalloc
62
63 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
64 r = devm_request_and_ioremap(&pdev->dev, res);
65
66 */
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
67
e9983bbf »
2012-09-15 +platform_device and small updates
68 return 0;
69 }
70
76366fc5 »
2012-09-24 minor
71 static int __devexit ldt_plat_remove(struct platform_device *pdev)
e9983bbf »
2012-09-15 +platform_device and small updates
72 {
73 _entry:
74 return 0;
75 }
76
77 /*
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
78 * template for OF FDT ID
79 * (Open Firmware Flat Device Tree)
e9983bbf »
2012-09-15 +platform_device and small updates
80 */
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
81
82 static const struct of_device_id ldt_of_match[] = {
83 {.compatible = "linux-driver-template",},
84 {},
85 };
86
87 MODULE_DEVICE_TABLE(of, ldt_of_match);
88
89 #ifdef CONFIG_PM
90
91 static int ldt_suspend(struct device *dev)
e9983bbf »
2012-09-15 +platform_device and small updates
92 {
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
93 return 0;
e9983bbf »
2012-09-15 +platform_device and small updates
94 }
95
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
96 static int ldt_resume(struct device *dev)
e9983bbf »
2012-09-15 +platform_device and small updates
97 {
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
98 return 0;
e9983bbf »
2012-09-15 +platform_device and small updates
99 }
100
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
101 static const struct dev_pm_ops ldt_pm = {
102 .suspend = ldt_suspend,
103 .resume = ldt_resume,
104 };
105
106 #define ldt_pm_ops (&ldt_pm)
107 #else
108 #define ldt_pm_ops NULL
e9983bbf »
2012-09-15 +platform_device and small updates
109 #endif
110
7c7c6c60 »
2012-12-06 ldt.c simplified: removed work, ioctl
111 static struct platform_driver ldt_plat_driver = {
112 .driver = {
113 .name = "ldt_device_name",
114 .owner = THIS_MODULE,
115 .pm = ldt_pm_ops,
116 .of_match_table = of_match_ptr(ldt_of_match),
117 },
118 .probe = ldt_plat_probe,
119 .remove = __devexit_p(ldt_plat_remove),
120
121 };
122
123 module_platform_driver(ldt_plat_driver);
124
e9983bbf »
2012-09-15 +platform_device and small updates
125 MODULE_DESCRIPTION("LDT - Linux Driver Template: platform_driver template");
126 MODULE_AUTHOR("Constantine Shulyupin <const@makelinux.net>");
127 MODULE_LICENSE("Dual BSD/GPL");
Something went wrong with that request. Please try again.