Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] stb6100: get rid of get_state()/set_state()

It is tricky to get rid of those ops here, as the stv0299 driver
wants to set frequency in separate from setting the bandwidth.

So, we use a small trick: we temporarely fill the cache with
0 for either frequency or bandwidth and add some logic at
set_params to only change the property(ies) that aren't zero.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

+54 -72
+10 -36
drivers/media/dvb-frontends/stb6100.c
··· 502 502 * iqsense = 1 503 503 * tunerstep = 125000 504 504 */ 505 - state->bandwidth = 36000000; /* Hz */ 505 + state->bandwidth = 36000000; /* Hz */ 506 506 state->reference = refclk / 1000; /* kHz */ 507 507 508 508 /* Set default bandwidth. Modified, PN 13-May-10 */ 509 509 return 0; 510 510 } 511 511 512 - static int stb6100_get_state(struct dvb_frontend *fe, 513 - enum tuner_param param, 514 - struct tuner_state *state) 512 + static int stb6100_set_params(struct dvb_frontend *fe) 515 513 { 516 - switch (param) { 517 - case DVBFE_TUNER_FREQUENCY: 518 - stb6100_get_frequency(fe, &state->frequency); 519 - break; 520 - case DVBFE_TUNER_BANDWIDTH: 521 - stb6100_get_bandwidth(fe, &state->bandwidth); 522 - break; 523 - default: 524 - break; 525 - } 514 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 526 515 527 - return 0; 528 - } 516 + if (c->frequency > 0) 517 + stb6100_set_frequency(fe, c->frequency); 529 518 530 - static int stb6100_set_state(struct dvb_frontend *fe, 531 - enum tuner_param param, 532 - struct tuner_state *state) 533 - { 534 - struct stb6100_state *tstate = fe->tuner_priv; 535 - 536 - switch (param) { 537 - case DVBFE_TUNER_FREQUENCY: 538 - stb6100_set_frequency(fe, state->frequency); 539 - tstate->frequency = state->frequency; 540 - break; 541 - case DVBFE_TUNER_BANDWIDTH: 542 - stb6100_set_bandwidth(fe, state->bandwidth); 543 - tstate->bandwidth = state->bandwidth; 544 - break; 545 - default: 546 - break; 547 - } 519 + if (c->bandwidth_hz > 0) 520 + stb6100_set_bandwidth(fe, c->bandwidth_hz); 548 521 549 522 return 0; 550 523 } ··· 533 560 .init = stb6100_init, 534 561 .sleep = stb6100_sleep, 535 562 .get_status = stb6100_get_status, 536 - .get_state = stb6100_get_state, 537 - .set_state = stb6100_set_state, 563 + .set_params = stb6100_set_params, 564 + .get_frequency = stb6100_get_frequency, 565 + .get_bandwidth = stb6100_get_bandwidth, 538 566 .release = stb6100_release 539 567 }; 540 568
+21 -16
drivers/media/dvb-frontends/stb6100_cfg.h
··· 19 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 20 */ 21 21 22 + #include <linux/dvb/frontend.h> 23 + #include "dvb_frontend.h" 24 + 22 25 static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency) 23 26 { 24 27 struct dvb_frontend_ops *frontend_ops = &fe->ops; 25 28 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 26 - struct tuner_state t_state; 27 29 int err = 0; 28 30 29 - if (tuner_ops->get_state) { 30 - err = tuner_ops->get_state(fe, DVBFE_TUNER_FREQUENCY, &t_state); 31 + if (tuner_ops->get_frequency) { 32 + err = tuner_ops->get_frequency(fe, frequency); 31 33 if (err < 0) { 32 34 printk("%s: Invalid parameter\n", __func__); 33 35 return err; 34 36 } 35 - *frequency = t_state.frequency; 36 37 } 37 38 return 0; 38 39 } ··· 42 41 { 43 42 struct dvb_frontend_ops *frontend_ops = &fe->ops; 44 43 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 45 - struct tuner_state t_state; 44 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 45 + u32 bw = c->bandwidth_hz; 46 46 int err = 0; 47 47 48 - t_state.frequency = frequency; 48 + c->frequency = frequency; 49 + c->bandwidth_hz = 0; /* Don't adjust the bandwidth */ 49 50 50 - if (tuner_ops->set_state) { 51 - err = tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY, &t_state); 51 + if (tuner_ops->set_params) { 52 + err = tuner_ops->set_params(fe); 53 + c->bandwidth_hz = bw; 52 54 if (err < 0) { 53 55 printk("%s: Invalid parameter\n", __func__); 54 56 return err; ··· 64 60 { 65 61 struct dvb_frontend_ops *frontend_ops = &fe->ops; 66 62 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 67 - struct tuner_state t_state; 68 63 int err = 0; 69 64 70 - if (tuner_ops->get_state) { 71 - err = tuner_ops->get_state(fe, DVBFE_TUNER_BANDWIDTH, &t_state); 65 + if (tuner_ops->get_bandwidth) { 66 + err = tuner_ops->get_bandwidth(fe, bandwidth); 72 67 if (err < 0) { 73 68 printk("%s: Invalid parameter\n", __func__); 74 69 return err; 75 70 } 76 - *bandwidth = t_state.bandwidth; 77 71 } 78 72 return 0; 79 73 } ··· 80 78 { 81 79 struct dvb_frontend_ops *frontend_ops = &fe->ops; 82 80 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 83 - struct tuner_state t_state; 81 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 82 + u32 freq = c->frequency; 84 83 int err = 0; 85 84 86 - t_state.bandwidth = bandwidth; 85 + c->bandwidth_hz = bandwidth; 86 + c->frequency = 0; /* Don't adjust the frequency */ 87 87 88 - if (tuner_ops->set_state) { 89 - err = tuner_ops->set_state(fe, DVBFE_TUNER_BANDWIDTH, &t_state); 88 + if (tuner_ops->set_params) { 89 + err = tuner_ops->set_params(fe); 90 + c->frequency = freq; 90 91 if (err < 0) { 91 92 printk("%s: Invalid parameter\n", __func__); 92 93 return err;
+23 -20
drivers/media/dvb-frontends/stb6100_proc.h
··· 17 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 18 */ 19 19 20 + #include <linux/dvb/frontend.h> 21 + #include "dvb_frontend.h" 22 + 20 23 static int stb6100_get_freq(struct dvb_frontend *fe, u32 *frequency) 21 24 { 22 25 struct dvb_frontend_ops *frontend_ops = &fe->ops; 23 26 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 24 - struct tuner_state state; 25 27 int err = 0; 26 28 27 - if (tuner_ops->get_state) { 29 + if (tuner_ops->get_frequency) { 28 30 if (frontend_ops->i2c_gate_ctrl) 29 31 frontend_ops->i2c_gate_ctrl(fe, 1); 30 32 31 - err = tuner_ops->get_state(fe, DVBFE_TUNER_FREQUENCY, &state); 33 + err = tuner_ops->get_frequency(fe, frequency); 32 34 if (err < 0) { 33 - printk(KERN_ERR "%s: Invalid parameter\n", __func__); 35 + printk("%s: Invalid parameter\n", __func__); 34 36 return err; 35 37 } 36 38 37 39 if (frontend_ops->i2c_gate_ctrl) 38 40 frontend_ops->i2c_gate_ctrl(fe, 0); 39 - 40 - *frequency = state.frequency; 41 41 } 42 42 43 43 return 0; ··· 47 47 { 48 48 struct dvb_frontend_ops *frontend_ops = &fe->ops; 49 49 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 50 - struct tuner_state state; 50 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 51 + u32 bw = c->bandwidth_hz; 51 52 int err = 0; 52 53 53 - state.frequency = frequency; 54 + c->frequency = frequency; 55 + c->bandwidth_hz = 0; /* Don't adjust the bandwidth */ 54 56 55 - if (tuner_ops->set_state) { 57 + if (tuner_ops->set_params) { 56 58 if (frontend_ops->i2c_gate_ctrl) 57 59 frontend_ops->i2c_gate_ctrl(fe, 1); 58 60 59 - err = tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY, &state); 61 + err = tuner_ops->set_params(fe); 62 + c->bandwidth_hz = bw; 60 63 if (err < 0) { 61 - printk(KERN_ERR "%s: Invalid parameter\n", __func__); 64 + printk("%s: Invalid parameter\n", __func__); 62 65 return err; 63 66 } 64 67 ··· 77 74 { 78 75 struct dvb_frontend_ops *frontend_ops = &fe->ops; 79 76 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 80 - struct tuner_state state; 81 77 int err = 0; 82 78 83 - if (tuner_ops->get_state) { 79 + if (tuner_ops->get_bandwidth) { 84 80 if (frontend_ops->i2c_gate_ctrl) 85 81 frontend_ops->i2c_gate_ctrl(fe, 1); 86 82 87 - err = tuner_ops->get_state(fe, DVBFE_TUNER_BANDWIDTH, &state); 83 + err = tuner_ops->get_bandwidth(fe, bandwidth); 88 84 if (err < 0) { 89 85 printk(KERN_ERR "%s: Invalid parameter\n", __func__); 90 86 return err; ··· 91 89 92 90 if (frontend_ops->i2c_gate_ctrl) 93 91 frontend_ops->i2c_gate_ctrl(fe, 0); 94 - 95 - *bandwidth = state.bandwidth; 96 92 } 97 93 98 94 return 0; ··· 100 100 { 101 101 struct dvb_frontend_ops *frontend_ops = &fe->ops; 102 102 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 103 - struct tuner_state state; 103 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 104 + u32 freq = c->frequency; 104 105 int err = 0; 105 106 106 - state.bandwidth = bandwidth; 107 + c->bandwidth_hz = bandwidth; 108 + c->frequency = 0; /* Don't adjust the frequency */ 107 109 108 - if (tuner_ops->set_state) { 110 + if (tuner_ops->set_params) { 109 111 if (frontend_ops->i2c_gate_ctrl) 110 112 frontend_ops->i2c_gate_ctrl(fe, 1); 111 113 112 - err = tuner_ops->set_state(fe, DVBFE_TUNER_BANDWIDTH, &state); 114 + err = tuner_ops->set_params(fe); 115 + c->frequency = freq; 113 116 if (err < 0) { 114 117 printk(KERN_ERR "%s: Invalid parameter\n", __func__); 115 118 return err;