6b13f685e
김민수
BSP 최초 추가
|
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* rfkill-regulator.c - Regulator consumer driver for rfkill
*
* Copyright (C) 2009 Guiming Zhuo <gmzhuo@gmail.com>
* Copyright (C) 2011 Antonio Ospite <ospite@studenti.unina.it>
*
* Implementation inspired by leds-regulator driver.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/module.h>
#include <linux/err.h>
#include <linux/of_irq.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/rfkill.h>
#include <linux/rfkill-regulator.h>
struct rfkill_regulator_data {
struct rfkill *rf_kill;
bool reg_enabled;
struct regulator *vcc;
};
static int rfkill_regulator_set_block(void *data, bool blocked)
{
struct rfkill_regulator_data *rfkill_data = data;
int ret = 0;
pr_debug("%s: blocked: %d
", __func__, blocked);
if (blocked) {
if (rfkill_data->reg_enabled) {
regulator_disable(rfkill_data->vcc);
rfkill_data->reg_enabled = false;
}
} else {
if (!rfkill_data->reg_enabled) {
ret = regulator_enable(rfkill_data->vcc);
if (!ret)
rfkill_data->reg_enabled = true;
}
}
pr_debug("%s: regulator_is_enabled after set_block: %d
", __func__,
regulator_is_enabled(rfkill_data->vcc));
return ret;
}
static struct rfkill_ops rfkill_regulator_ops = {
.set_block = rfkill_regulator_set_block,
};
static struct rfkill_regulator_platform_data *rfkill_regulator_get_pdata_from_of(struct device *dev)
{
struct rfkill_regulator_platform_data *pdata;
struct device_node *np = dev->of_node;
if (!np) {
np = of_find_matching_node(NULL, dev->driver->of_match_table);
if (!np) {
dev_notice(dev, "device tree node not available
");
return ERR_PTR(-ENODEV);
}
}
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
dev_err(dev, "can't allocate platform data
");
return ERR_PTR(-ENODEV);
}
of_property_read_u32(np, "type", &pdata->type);
of_property_read_string(np, "name", &pdata->name);
return pdata;
}
static int rfkill_regulator_probe(struct platform_device *pdev)
{
struct rfkill_regulator_platform_data *pdata = pdev->dev.platform_data;
struct rfkill_regulator_platform_data *p = NULL;
struct rfkill_regulator_data *rfkill_data;
struct regulator *vcc;
struct rfkill *rf_kill;
int ret = 0;
if (pdata == NULL) {
p = pdata = rfkill_regulator_get_pdata_from_of(&pdev->dev);
if (IS_ERR(p)) {
dev_err(&pdev->dev, "no platform data
");
return PTR_ERR(p);
}
}
if (pdata->name == NULL || pdata->type == 0) {
dev_err(&pdev->dev, "invalid name or type in platform data
");
ret = -EINVAL;
goto out;
}
vcc = regulator_get_exclusive(&pdev->dev, "vrfkill");
if (IS_ERR(vcc)) {
dev_err(&pdev->dev, "Cannot get vcc for %s
", pdata->name);
ret = PTR_ERR(vcc);
goto out;
}
rfkill_data = kzalloc(sizeof(*rfkill_data), GFP_KERNEL);
if (rfkill_data == NULL) {
ret = -ENOMEM;
goto err_data_alloc;
}
rf_kill = rfkill_alloc(pdata->name, &pdev->dev,
pdata->type,
&rfkill_regulator_ops, rfkill_data);
if (rf_kill == NULL) {
ret = -ENOMEM;
goto err_rfkill_alloc;
}
if (regulator_is_enabled(vcc)) {
dev_dbg(&pdev->dev, "Regulator already enabled
");
rfkill_data->reg_enabled = true;
}
rfkill_data->vcc = vcc;
rfkill_data->rf_kill = rf_kill;
ret = rfkill_register(rf_kill);
if (ret) {
dev_err(&pdev->dev, "Cannot register rfkill device
");
goto err_rfkill_register;
}
platform_set_drvdata(pdev, rfkill_data);
dev_info(&pdev->dev, "%s initialized
", pdata->name);
kfree(p);
return 0;
err_rfkill_register:
rfkill_destroy(rf_kill);
err_rfkill_alloc:
kfree(rfkill_data);
err_data_alloc:
regulator_put(vcc);
out:
kfree(p);
return ret;
}
static int rfkill_regulator_remove(struct platform_device *pdev)
{
struct rfkill_regulator_data *rfkill_data = platform_get_drvdata(pdev);
struct rfkill *rf_kill = rfkill_data->rf_kill;
rfkill_unregister(rf_kill);
rfkill_destroy(rf_kill);
regulator_put(rfkill_data->vcc);
kfree(rfkill_data);
return 0;
}
static const struct of_device_id rfkill_regulator_of_match_table[] = {
{ .compatible = "net,rfkill-reg" },
{ }
};
MODULE_DEVICE_TABLE(of, rfkill_regulator_of_match_table);
static struct platform_driver rfkill_regulator_driver = {
.probe = rfkill_regulator_probe,
.remove = rfkill_regulator_remove,
.driver = {
.name = "rfkill-regulator",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(rfkill_regulator_of_match_table),
},
};
module_platform_driver(rfkill_regulator_driver);
MODULE_AUTHOR("Guiming Zhuo <gmzhuo@gmail.com>");
MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
MODULE_DESCRIPTION("Regulator consumer driver for rfkill");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:rfkill-regulator");
|