aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <m.chehab@samsung.com>2014-08-12 17:50:22 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-08-21 16:25:30 -0400
commit47f79129ecf5fd12d847c2e63b6ce39d1df4a648 (patch)
tree6ca833bb26cb664145a84ae44b4ba4928dacaac7
parentc098c219b0c2da64250dd0542c5c54ca7245d1a5 (diff)
[media] as102: prepare as102_fe to be compiled as a module
Remove the dependencies of as102_cmd from as102, in order to allow it to be compiled as a separate module. Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r--drivers/media/usb/as102/as102_drv.c116
-rw-r--r--drivers/media/usb/as102/as102_drv.h8
-rw-r--r--drivers/media/usb/as102/as102_fe.c105
-rw-r--r--drivers/media/usb/as102/as102_fe.h29
-rw-r--r--drivers/media/usb/as102/as10x_cmd.h2
-rw-r--r--drivers/media/usb/as102/as10x_handle.h3
-rw-r--r--drivers/media/usb/as102/as10x_types.h2
7 files changed, 179 insertions, 86 deletions
diff --git a/drivers/media/usb/as102/as102_drv.c b/drivers/media/usb/as102/as102_drv.c
index ff5bd2e5657a..8be1474b2c36 100644
--- a/drivers/media/usb/as102/as102_drv.c
+++ b/drivers/media/usb/as102/as102_drv.c
@@ -24,6 +24,8 @@
24 24
25/* header file for usb device driver*/ 25/* header file for usb device driver*/
26#include "as102_drv.h" 26#include "as102_drv.h"
27#include "as10x_cmd.h"
28#include "as102_fe.h"
27#include "as102_fw.h" 29#include "as102_fw.h"
28#include "dvbdev.h" 30#include "dvbdev.h"
29 31
@@ -176,6 +178,119 @@ static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
176 return 0; 178 return 0;
177} 179}
178 180
181static int as102_set_tune(void *priv, struct as10x_tune_args *tune_args)
182{
183 struct as10x_bus_adapter_t *bus_adap = priv;
184 int ret;
185
186 /* Set frontend arguments */
187 if (mutex_lock_interruptible(&bus_adap->lock))
188 return -EBUSY;
189
190 ret = as10x_cmd_set_tune(bus_adap, tune_args);
191 if (ret != 0)
192 dev_dbg(&bus_adap->usb_dev->dev,
193 "as10x_cmd_set_tune failed. (err = %d)\n", ret);
194
195 mutex_unlock(&bus_adap->lock);
196
197 return ret;
198}
199
200static int as102_get_tps(void *priv, struct as10x_tps *tps)
201{
202 struct as10x_bus_adapter_t *bus_adap = priv;
203 int ret;
204
205 if (mutex_lock_interruptible(&bus_adap->lock))
206 return -EBUSY;
207
208 /* send abilis command: GET_TPS */
209 ret = as10x_cmd_get_tps(bus_adap, tps);
210
211 mutex_unlock(&bus_adap->lock);
212
213 return ret;
214}
215
216static int as102_get_status(void *priv, struct as10x_tune_status *tstate)
217{
218 struct as10x_bus_adapter_t *bus_adap = priv;
219 int ret;
220
221 if (mutex_lock_interruptible(&bus_adap->lock))
222 return -EBUSY;
223
224 /* send abilis command: GET_TUNE_STATUS */
225 ret = as10x_cmd_get_tune_status(bus_adap, tstate);
226 if (ret < 0) {
227 dev_dbg(&bus_adap->usb_dev->dev,
228 "as10x_cmd_get_tune_status failed (err = %d)\n",
229 ret);
230 }
231
232 mutex_unlock(&bus_adap->lock);
233
234 return ret;
235}
236
237static int as102_get_stats(void *priv, struct as10x_demod_stats *demod_stats)
238{
239 struct as10x_bus_adapter_t *bus_adap = priv;
240 int ret;
241
242 if (mutex_lock_interruptible(&bus_adap->lock))
243 return -EBUSY;
244
245 /* send abilis command: GET_TUNE_STATUS */
246 ret = as10x_cmd_get_demod_stats(bus_adap, demod_stats);
247 if (ret < 0) {
248 dev_dbg(&bus_adap->usb_dev->dev,
249 "as10x_cmd_get_demod_stats failed (probably not tuned)\n");
250 } else {
251 dev_dbg(&bus_adap->usb_dev->dev,
252 "demod status: fc: 0x%08x, bad fc: 0x%08x, bytes corrected: 0x%08x , MER: 0x%04x\n",
253 demod_stats->frame_count,
254 demod_stats->bad_frame_count,
255 demod_stats->bytes_fixed_by_rs,
256 demod_stats->mer);
257 }
258 mutex_unlock(&bus_adap->lock);
259
260 return ret;
261}
262
263static int as102_stream_ctrl(void *priv, int acquire, uint32_t elna_cfg)
264{
265 struct as10x_bus_adapter_t *bus_adap = priv;
266 int ret;
267
268 if (mutex_lock_interruptible(&bus_adap->lock))
269 return -EBUSY;
270
271 if (acquire) {
272 if (elna_enable)
273 as10x_cmd_set_context(bus_adap,
274 CONTEXT_LNA, elna_cfg);
275
276 ret = as10x_cmd_turn_on(bus_adap);
277 } else {
278 ret = as10x_cmd_turn_off(bus_adap);
279 }
280
281 mutex_unlock(&bus_adap->lock);
282
283 return ret;
284}
285
286static const struct as102_fe_ops as102_fe_ops = {
287 .set_tune = as102_set_tune,
288 .get_tps = as102_get_tps,
289 .get_status = as102_get_status,
290 .get_stats = as102_get_stats,
291 .stream_ctrl = as102_stream_ctrl,
292};
293
179int as102_dvb_register(struct as102_dev_t *as102_dev) 294int as102_dvb_register(struct as102_dev_t *as102_dev)
180{ 295{
181 struct device *dev = &as102_dev->bus_adap.usb_dev->dev; 296 struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
@@ -218,6 +333,7 @@ int as102_dvb_register(struct as102_dev_t *as102_dev)
218 333
219 /* Attach the frontend */ 334 /* Attach the frontend */
220 as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name, 335 as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name,
336 &as102_fe_ops,
221 &as102_dev->bus_adap, 337 &as102_dev->bus_adap,
222 as102_dev->elna_cfg); 338 as102_dev->elna_cfg);
223 if (!as102_dev->dvb_fe) { 339 if (!as102_dev->dvb_fe) {
diff --git a/drivers/media/usb/as102/as102_drv.h b/drivers/media/usb/as102/as102_drv.h
index 1e2a76d3c517..9430d30163a3 100644
--- a/drivers/media/usb/as102/as102_drv.h
+++ b/drivers/media/usb/as102/as102_drv.h
@@ -13,10 +13,13 @@
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 */ 14 */
15 15
16#ifndef _AS102_DRV_H
17#define _AS102_DRV_H
16#include <linux/usb.h> 18#include <linux/usb.h>
17#include <dvb_demux.h> 19#include <dvb_demux.h>
18#include <dvb_frontend.h> 20#include <dvb_frontend.h>
19#include <dmxdev.h> 21#include <dmxdev.h>
22#include "as10x_handle.h"
20#include "as10x_cmd.h" 23#include "as10x_cmd.h"
21#include "as102_usb_drv.h" 24#include "as102_usb_drv.h"
22 25
@@ -77,7 +80,4 @@ struct as102_dev_t {
77int as102_dvb_register(struct as102_dev_t *dev); 80int as102_dvb_register(struct as102_dev_t *dev);
78void as102_dvb_unregister(struct as102_dev_t *dev); 81void as102_dvb_unregister(struct as102_dev_t *dev);
79 82
80/* FIXME: move it to a separate header */ 83#endif \ No newline at end of file
81struct dvb_frontend *as102_attach(const char *name,
82 struct as10x_bus_adapter_t *bus_adap,
83 uint8_t elna_cfg);
diff --git a/drivers/media/usb/as102/as102_fe.c b/drivers/media/usb/as102/as102_fe.c
index 0cd19f23eca9..f57560c191ae 100644
--- a/drivers/media/usb/as102/as102_fe.c
+++ b/drivers/media/usb/as102/as102_fe.c
@@ -13,15 +13,17 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16#include "as102_drv.h" 16
17#include "as10x_types.h" 17#include <dvb_frontend.h>
18#include "as10x_cmd.h" 18
19#include "as102_fe.h"
19 20
20struct as102_state { 21struct as102_state {
21 struct dvb_frontend frontend; 22 struct dvb_frontend frontend;
22 struct as10x_demod_stats demod_stats; 23 struct as10x_demod_stats demod_stats;
23 struct as10x_bus_adapter_t *bus_adap;
24 24
25 const struct as102_fe_ops *ops;
26 void *priv;
25 uint8_t elna_cfg; 27 uint8_t elna_cfg;
26 28
27 /* signal strength */ 29 /* signal strength */
@@ -62,7 +64,6 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe)
62{ 64{
63 struct as102_state *state = fe->demodulator_priv; 65 struct as102_state *state = fe->demodulator_priv;
64 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 66 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
65 int ret = 0;
66 struct as10x_tune_args tune_args = { 0 }; 67 struct as10x_tune_args tune_args = { 0 };
67 68
68 /* set frequency */ 69 /* set frequency */
@@ -186,17 +187,7 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe)
186 } 187 }
187 188
188 /* Set frontend arguments */ 189 /* Set frontend arguments */
189 if (mutex_lock_interruptible(&state->bus_adap->lock)) 190 return state->ops->set_tune(state->priv, &tune_args);
190 return -EBUSY;
191
192 ret = as10x_cmd_set_tune(state->bus_adap, &tune_args);
193 if (ret != 0)
194 dev_dbg(&state->bus_adap->usb_dev->dev,
195 "as10x_cmd_set_tune failed. (err = %d)\n", ret);
196
197 mutex_unlock(&state->bus_adap->lock);
198
199 return (ret < 0) ? -EINVAL : 0;
200} 191}
201 192
202static int as102_fe_get_frontend(struct dvb_frontend *fe) 193static int as102_fe_get_frontend(struct dvb_frontend *fe)
@@ -206,14 +197,8 @@ static int as102_fe_get_frontend(struct dvb_frontend *fe)
206 int ret = 0; 197 int ret = 0;
207 struct as10x_tps tps = { 0 }; 198 struct as10x_tps tps = { 0 };
208 199
209 if (mutex_lock_interruptible(&state->bus_adap->lock))
210 return -EBUSY;
211
212 /* send abilis command: GET_TPS */ 200 /* send abilis command: GET_TPS */
213 ret = as10x_cmd_get_tps(state->bus_adap, &tps); 201 ret = state->ops->get_tps(state->priv, &tps);
214
215 mutex_unlock(&state->bus_adap->lock);
216
217 if (ret < 0) 202 if (ret < 0)
218 return ret; 203 return ret;
219 204
@@ -321,24 +306,16 @@ static int as102_fe_get_tune_settings(struct dvb_frontend *fe,
321 return 0; 306 return 0;
322} 307}
323 308
324
325static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status) 309static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
326{ 310{
327 int ret = 0; 311 int ret = 0;
328 struct as102_state *state = fe->demodulator_priv; 312 struct as102_state *state = fe->demodulator_priv;
329 struct as10x_tune_status tstate = { 0 }; 313 struct as10x_tune_status tstate = { 0 };
330 314
331 if (mutex_lock_interruptible(&state->bus_adap->lock))
332 return -EBUSY;
333
334 /* send abilis command: GET_TUNE_STATUS */ 315 /* send abilis command: GET_TUNE_STATUS */
335 ret = as10x_cmd_get_tune_status(state->bus_adap, &tstate); 316 ret = state->ops->get_status(state->priv, &tstate);
336 if (ret < 0) { 317 if (ret < 0)
337 dev_dbg(&state->bus_adap->usb_dev->dev, 318 return ret;
338 "as10x_cmd_get_tune_status failed (err = %d)\n",
339 ret);
340 goto out;
341 }
342 319
343 state->signal_strength = tstate.signal_strength; 320 state->signal_strength = tstate.signal_strength;
344 state->ber = tstate.BER; 321 state->ber = tstate.BER;
@@ -358,31 +335,19 @@ static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
358 *status = TUNE_STATUS_NOT_TUNED; 335 *status = TUNE_STATUS_NOT_TUNED;
359 } 336 }
360 337
361 dev_dbg(&state->bus_adap->usb_dev->dev, 338 pr_debug("as102: tuner status: 0x%02x, strength %d, per: %d, ber: %d\n",
362 "tuner status: 0x%02x, strength %d, per: %d, ber: %d\n", 339 tstate.tune_state, tstate.signal_strength,
363 tstate.tune_state, tstate.signal_strength, 340 tstate.PER, tstate.BER);
364 tstate.PER, tstate.BER); 341
365 342 if (!(*status & FE_HAS_LOCK)) {
366 if (*status & FE_HAS_LOCK) {
367 if (as10x_cmd_get_demod_stats(state->bus_adap,
368 (struct as10x_demod_stats *) &state->demod_stats) < 0) {
369 memset(&state->demod_stats, 0, sizeof(state->demod_stats));
370 dev_dbg(&state->bus_adap->usb_dev->dev,
371 "as10x_cmd_get_demod_stats failed (probably not tuned)\n");
372 } else {
373 dev_dbg(&state->bus_adap->usb_dev->dev,
374 "demod status: fc: 0x%08x, bad fc: 0x%08x, bytes corrected: 0x%08x , MER: 0x%04x\n",
375 state->demod_stats.frame_count,
376 state->demod_stats.bad_frame_count,
377 state->demod_stats.bytes_fixed_by_rs,
378 state->demod_stats.mer);
379 }
380 } else {
381 memset(&state->demod_stats, 0, sizeof(state->demod_stats)); 343 memset(&state->demod_stats, 0, sizeof(state->demod_stats));
344 return 0;
382 } 345 }
383 346
384out: 347 ret = state->ops->get_stats(state->priv, &state->demod_stats);
385 mutex_unlock(&state->bus_adap->lock); 348 if (ret < 0)
349 memset(&state->demod_stats, 0, sizeof(state->demod_stats));
350
386 return ret; 351 return ret;
387} 352}
388 353
@@ -436,24 +401,9 @@ static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
436static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire) 401static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
437{ 402{
438 struct as102_state *state = fe->demodulator_priv; 403 struct as102_state *state = fe->demodulator_priv;
439 int ret;
440
441 if (mutex_lock_interruptible(&state->bus_adap->lock))
442 return -EBUSY;
443 404
444 if (acquire) { 405 return state->ops->stream_ctrl(state->priv, acquire,
445 if (elna_enable) 406 state->elna_cfg);
446 as10x_cmd_set_context(state->bus_adap,
447 CONTEXT_LNA, state->elna_cfg);
448
449 ret = as10x_cmd_turn_on(state->bus_adap);
450 } else {
451 ret = as10x_cmd_turn_off(state->bus_adap);
452 }
453
454 mutex_unlock(&state->bus_adap->lock);
455
456 return ret;
457} 407}
458 408
459static struct dvb_frontend_ops as102_fe_ops = { 409static struct dvb_frontend_ops as102_fe_ops = {
@@ -488,7 +438,8 @@ static struct dvb_frontend_ops as102_fe_ops = {
488}; 438};
489 439
490struct dvb_frontend *as102_attach(const char *name, 440struct dvb_frontend *as102_attach(const char *name,
491 struct as10x_bus_adapter_t *bus_adap, 441 const struct as102_fe_ops *ops,
442 void *priv,
492 uint8_t elna_cfg) 443 uint8_t elna_cfg)
493{ 444{
494 struct as102_state *state; 445 struct as102_state *state;
@@ -496,13 +447,13 @@ struct dvb_frontend *as102_attach(const char *name,
496 447
497 state = kzalloc(sizeof(struct as102_state), GFP_KERNEL); 448 state = kzalloc(sizeof(struct as102_state), GFP_KERNEL);
498 if (state == NULL) { 449 if (state == NULL) {
499 dev_err(&bus_adap->usb_dev->dev, 450 pr_err("%s: unable to allocate memory for state\n", __func__);
500 "%s: unable to allocate memory for state\n", __func__);
501 return NULL; 451 return NULL;
502 } 452 }
503 fe = &state->frontend; 453 fe = &state->frontend;
504 fe->demodulator_priv = state; 454 fe->demodulator_priv = state;
505 state->bus_adap = bus_adap; 455 state->ops = ops;
456 state->priv = priv;
506 state->elna_cfg = elna_cfg; 457 state->elna_cfg = elna_cfg;
507 458
508 /* init frontend callback ops */ 459 /* init frontend callback ops */
diff --git a/drivers/media/usb/as102/as102_fe.h b/drivers/media/usb/as102/as102_fe.h
new file mode 100644
index 000000000000..4098cf8f8cf9
--- /dev/null
+++ b/drivers/media/usb/as102/as102_fe.h
@@ -0,0 +1,29 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2014 Mauro Carvalho Chehab <m.chehab@samsung.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include "as10x_types.h"
17
18struct as102_fe_ops {
19 int (*set_tune)(void *priv, struct as10x_tune_args *tune_args);
20 int (*get_tps)(void *priv, struct as10x_tps *tps);
21 int (*get_status)(void *priv, struct as10x_tune_status *tstate);
22 int (*get_stats)(void *priv, struct as10x_demod_stats *demod_stats);
23 int (*stream_ctrl)(void *priv, int acquire, uint32_t elna_cfg);
24};
25
26struct dvb_frontend *as102_attach(const char *name,
27 const struct as102_fe_ops *ops,
28 void *priv,
29 uint8_t elna_cfg);
diff --git a/drivers/media/usb/as102/as10x_cmd.h b/drivers/media/usb/as102/as10x_cmd.h
index 1c9ea2c2175e..83c0440dba2f 100644
--- a/drivers/media/usb/as102/as10x_cmd.h
+++ b/drivers/media/usb/as102/as10x_cmd.h
@@ -15,9 +15,7 @@
15#ifndef _AS10X_CMD_H_ 15#ifndef _AS10X_CMD_H_
16#define _AS10X_CMD_H_ 16#define _AS10X_CMD_H_
17 17
18#ifdef __KERNEL__
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#endif
21 19
22#include "as10x_types.h" 20#include "as10x_types.h"
23 21
diff --git a/drivers/media/usb/as102/as10x_handle.h b/drivers/media/usb/as102/as10x_handle.h
index e535fffbcd94..d6b58c770500 100644
--- a/drivers/media/usb/as102/as10x_handle.h
+++ b/drivers/media/usb/as102/as10x_handle.h
@@ -12,7 +12,8 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 */ 14 */
15#ifdef __KERNEL__ 15#ifndef _AS10X_HANDLE_H
16#define _AS10X_HANDLE_H
16struct as10x_bus_adapter_t; 17struct as10x_bus_adapter_t;
17struct as102_dev_t; 18struct as102_dev_t;
18 19
diff --git a/drivers/media/usb/as102/as10x_types.h b/drivers/media/usb/as102/as10x_types.h
index f82d51e542e3..80a5398b580f 100644
--- a/drivers/media/usb/as102/as10x_types.h
+++ b/drivers/media/usb/as102/as10x_types.h
@@ -15,8 +15,6 @@
15#ifndef _AS10X_TYPES_H_ 15#ifndef _AS10X_TYPES_H_
16#define _AS10X_TYPES_H_ 16#define _AS10X_TYPES_H_
17 17
18#include "as10x_handle.h"
19
20/*********************************/ 18/*********************************/
21/* MACRO DEFINITIONS */ 19/* MACRO DEFINITIONS */
22/*********************************/ 20/*********************************/