-
Notifications
You must be signed in to change notification settings - Fork 197
/
ldt_plat_drv.c
130 lines (109 loc) · 2.66 KB
/
ldt_plat_drv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* LDT - Linux Driver Template
*
* Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
*
* Dual BSD/GPL License
*
* platform_driver template driver
* Power Management (dev_pm_ops)
* Device Tree (of_device_id)
*
*/
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/mod_devicetable.h>
#include <linux/of_irq.h>
#include "tracing.h"
static int irq;
static int port;
static int port_size;
static int ldt_plat_probe(struct platform_device *pdev)
{
char *data = NULL;
struct resource *r;
struct device *dev = &pdev->dev;
_entry:
dev_dbg(dev, "probe\n");
data = pdev->dev.platform_data;
irq = platform_get_irq(pdev, 0);
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
pr_debug("pdev->dev.of_node = %p\n", pdev->dev.of_node);
#ifdef CONFIG_OF_DEVICE
if (pdev->dev.of_node) {
const __be32 *p;
int property;
of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
p = of_get_property(pdev->dev.of_node, "property", NULL);
if (p)
property = be32_to_cpu(*p);
(void)property;
}
#endif
/*
sample code for drvdata usage:
struct ldt_data *drvdata = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, drvdata);
*/
(void)data;
data = dev_get_platdata(&pdev->dev);
pr_debug("%p %s\n", data, data);
(void)r;
r = platform_get_resource(pdev, IORESOURCE_IO, 0);
port = r->start;
port_size = resource_size(r);
/*
devm_kzalloc
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
r = devm_request_and_ioremap(&pdev->dev, res);
*/
return 0;
}
static int ldt_plat_remove(struct platform_device *pdev)
{
_entry:
return 0;
}
/*
* template for OF FDT ID
* (Open Firmware Flat Device Tree)
*/
static const struct of_device_id ldt_of_match[] = {
{.compatible = "linux-driver-template"},
{},
};
MODULE_DEVICE_TABLE(of, ldt_of_match);
#ifdef CONFIG_PM
static int ldt_suspend(struct device *dev)
{
return 0;
}
static int ldt_resume(struct device *dev)
{
return 0;
}
static const struct dev_pm_ops ldt_pm = {
.suspend = ldt_suspend,
.resume = ldt_resume,
};
#define ldt_pm_ops (&ldt_pm)
#else
#define ldt_pm_ops NULL
#endif
static struct platform_driver ldt_plat_driver = {
.driver = {
.name = "ldt_device_name",
.owner = THIS_MODULE,
.pm = ldt_pm_ops,
.of_match_table = of_match_ptr(ldt_of_match),
},
.probe = ldt_plat_probe,
.remove = ldt_plat_remove,
};
module_platform_driver(ldt_plat_driver);
MODULE_DESCRIPTION("LDT - Linux Driver Template: platform_driver template");
MODULE_AUTHOR("Constantine Shulyupin <[email protected]>");
MODULE_LICENSE("Dual BSD/GPL");