-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaml_fe.c
259 lines (205 loc) · 6.1 KB
/
aml_fe.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CONFIG_ARM64
#include <mach/am_regs.h>
#else
#include <linux/reset.h>
#endif
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/firmware.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/version.h>
#include <linux/amlogic/aml_gpio_consumer.h>
#include <linux/platform_device.h>
#include "aml_fe.h"
#include "avl6862.h"
#include "r848a.h"
#include "aml_dvb.h"
#undef pr_err
#define pr_dbg(fmt, args...) \
do {\
if (debug_fe)\
printk("DVB FE: " fmt, ##args);\
} while (0)
#define pr_err(fmt, args...) printk("DVB FE: " fmt, ## args)
#define pr_inf(fmt, args...) printk("DVB FE: " fmt, ## args)
MODULE_PARM_DESC(debug_fe, "\n\t\t Enable frontend debug information");
static int debug_fe;
module_param(debug_fe, int, 0644);
MODULE_PARM_DESC(frontend_power, "\n\t\t Power GPIO of frontend");
static int frontend_power = -1;
module_param(frontend_power, int, 0644);
MODULE_PARM_DESC(frontend_reset, "\n\t\t Reset GPIO of frontend");
static int frontend_reset = -1;
module_param(frontend_reset, int, 0644);
static struct aml_fe avl6862_fe[FE_DEV_COUNT];
static char *device_name = "avl6862";
#if 1
static struct r848_config r848_config = {
.i2c_address = 0x7A,
};
#endif
static struct avl6862_config avl6862_config = {
.demod_address = 0x14,
.tuner_address = 0x7A,
};
int avl6862_Reset(void)
{
pr_dbg("avl6862_Reset!\n");
gpio_request(frontend_reset,device_name);
gpio_direction_output(frontend_reset, 0);
msleep(600);
gpio_request(frontend_reset,device_name);
gpio_direction_output(frontend_reset, 1);
msleep(200);
return 0;
}
int avl6862_gpio(void)
{
pr_dbg("avl6862_gpio!\n");
gpio_request(frontend_power,device_name);
gpio_direction_output(frontend_power, 1);
return 0;
}
static int avl6862_fe_init(struct aml_dvb *advb, struct platform_device *pdev, struct aml_fe *fe, int id)
{
struct dvb_frontend_ops *ops;
int ret, i2c_adap_id = 1;
struct i2c_adapter *i2c_handle;
#ifdef CONFIG_ARM64
struct gpio_desc *desc;
int gpio_reset, gpio_power;
#endif
pr_inf("Init AVL6862 frontend %d\n", id);
#ifdef CONFIG_OF
if (of_property_read_u32(pdev->dev.of_node, "dtv_demod0_i2c_adap_id", &i2c_adap_id)) {
ret = -ENOMEM;
goto err_resource;
}
pr_dbg("i2c_adap_id=%d\n", &i2c_adap_id);
desc = of_get_named_gpiod_flags(pdev->dev.of_node, "dtv_demod0_reset_gpio-gpios", 0, NULL);
gpio_reset = desc_to_gpio(desc);
pr_dbg("gpio_reset=%d\n", gpio_reset);
desc = of_get_named_gpiod_flags(pdev->dev.of_node, "dtv_demod0_power_gpio-gpios", 0, NULL);
gpio_power = desc_to_gpio(desc);
pr_dbg("gpio_power=%d\n", gpio_power);
#endif /*CONFIG_OF*/
frontend_reset = gpio_reset;
frontend_power = gpio_power;
i2c_handle = i2c_get_adapter(i2c_adap_id);
if (!i2c_handle) {
pr_err("Cannot get i2c adapter for id:%d! \n", i2c_adap_id);
ret = -ENOMEM;
goto err_resource;
}
avl6862_Reset();
avl6862_gpio();
fe->fe = dvb_attach(avl6862_attach, &avl6862_config, i2c_handle);
if (!fe->fe) {
pr_err("avl6862_attach attach failed!!!\n");
ret = -ENOMEM;
goto err_resource;
}
if (dvb_attach(r848x_attach, fe->fe, &r848_config, i2c_handle) == NULL) {
dvb_frontend_detach(fe->fe);
fe->fe = NULL;
pr_err("r848_attach attach failed!!!\n");
ret = -ENOMEM;
goto err_resource;
}
pr_inf("AVL6862 and R848 attached!\n");
if ((ret=dvb_register_frontend(&advb->dvb_adapter, fe->fe))) {
pr_err("Frontend avl6862 registration failed!!!\n");
ops = &fe->fe->ops;
if (ops->release != NULL)
ops->release(fe->fe);
fe->fe = NULL;
ret = -ENOMEM;
goto err_resource;
}
pr_inf("Frontend AVL6862 registred!\n");
return 0;
err_resource:
return ret;
}
static int avl6862_fe_probe(struct platform_device *pdev)
{
int ret = 0;
struct aml_dvb *dvb = aml_get_dvb_device();
if(avl6862_fe_init(dvb, pdev, &avl6862_fe[0], 0)<0)
return -ENXIO;
platform_set_drvdata(pdev, &avl6862_fe[0]);
return ret;
}
static void avl6862_fe_release(struct aml_dvb *advb, struct aml_fe *fe)
{
if(fe && fe->fe) {
dvb_unregister_frontend(fe->fe);
dvb_frontend_detach(fe->fe);
}
}
static int avl6862_fe_remove(struct platform_device *pdev)
{
struct aml_fe *drv_data = platform_get_drvdata(pdev);
struct aml_dvb *dvb = aml_get_dvb_device();
platform_set_drvdata(pdev, NULL);
avl6862_fe_release(dvb, drv_data);
return 0;
}
static int avl6862_fe_resume(struct platform_device *pdev)
{
pr_dbg("avl6862_fe_resume \n");
return 0;
}
static int avl6862_fe_suspend(struct platform_device *pdev, pm_message_t state)
{
pr_dbg("avl6862_fe_suspend \n");
return 0;
}
#ifdef CONFIG_OF
static const struct of_device_id aml_fe_dt_match[]={
{
.compatible = "amlogic,dvbfe",
},
{},
};
#endif /*CONFIG_OF*/
static struct platform_driver aml_fe_driver = {
.probe = avl6862_fe_probe,
.remove = avl6862_fe_remove,
.resume = avl6862_fe_resume,
.suspend = avl6862_fe_suspend,
.driver = {
.name = "avl6862",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = aml_fe_dt_match,
#endif
}
};
static int __init avlfrontend_init(void) {
return platform_driver_register(&aml_fe_driver);
}
static void __exit avlfrontend_exit(void) {
platform_driver_unregister(&aml_fe_driver);
}
module_init(avlfrontend_init);
module_exit(avlfrontend_exit);
MODULE_AUTHOR("afl1");
MODULE_DESCRIPTION("AVL6862 DVB-Sx/Tx/C frontend driver");
MODULE_LICENSE("GPL");