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

[media] dvb-frontends/stv0367: refactor defaults table handling

Change defaults table writing so tables can be of dynamic length without
having to keep track of their lengths by adding and evaluating an end
marker (reg 0x0000), also move table writing to a dedicated function to
remove code duplication. Additionally mark st_register tables const since
they're used read-only.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Daniel Scheller and committed by
Mauro Carvalho Chehab
41727cbb df5a38e9

+20 -14
+20 -10
drivers/media/dvb-frontends/stv0367.c
··· 99 99 }; 100 100 101 101 /* values for STV4100 XTAL=30M int clk=53.125M*/ 102 - static struct st_register def0367ter[STV0367TER_NBREGS] = { 102 + static const struct st_register def0367ter[] = { 103 103 {R367TER_ID, 0x60}, 104 104 {R367TER_I2CRPT, 0xa0}, 105 105 /* {R367TER_I2CRPT, 0x22},*/ ··· 546 546 {R367TER_DEBUG_LT7, 0x00}, 547 547 {R367TER_DEBUG_LT8, 0x00}, 548 548 {R367TER_DEBUG_LT9, 0x00}, 549 + {0x0000, 0x00}, 549 550 }; 550 551 551 552 #define RF_LOOKUP_TABLE_SIZE 31 ··· 574 573 } 575 574 }; 576 575 577 - static struct st_register def0367cab[STV0367CAB_NBREGS] = { 576 + static const struct st_register def0367cab[] = { 578 577 {R367CAB_ID, 0x60}, 579 578 {R367CAB_I2CRPT, 0xa0}, 580 579 /*{R367CAB_I2CRPT, 0x22},*/ ··· 763 762 {R367CAB_T_O_ID_1, 0x00}, 764 763 {R367CAB_T_O_ID_2, 0x00}, 765 764 {R367CAB_T_O_ID_3, 0x00}, 765 + {0x0000, 0x00}, 766 766 }; 767 767 768 768 static ··· 903 901 return (reg & mask) >> pos; 904 902 } 905 903 #endif 904 + 905 + static void stv0367_write_table(struct stv0367_state *state, 906 + const struct st_register *deftab) 907 + { 908 + int i = 0; 909 + 910 + while (1) { 911 + if (!deftab[i].addr) 912 + break; 913 + stv0367_writereg(state, deftab[i].addr, deftab[i].value); 914 + i++; 915 + } 916 + } 917 + 906 918 static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable) 907 919 { 908 920 struct stv0367_state *state = fe->demodulator_priv; ··· 1556 1540 { 1557 1541 struct stv0367_state *state = fe->demodulator_priv; 1558 1542 struct stv0367ter_state *ter_state = state->ter_state; 1559 - int i; 1560 1543 1561 1544 dprintk("%s:\n", __func__); 1562 1545 1563 1546 ter_state->pBER = 0; 1564 1547 1565 - for (i = 0; i < STV0367TER_NBREGS; i++) 1566 - stv0367_writereg(state, def0367ter[i].addr, 1567 - def0367ter[i].value); 1548 + stv0367_write_table(state, def0367ter); 1568 1549 1569 1550 switch (state->config->xtal) { 1570 1551 /*set internal freq to 53.125MHz */ ··· 2795 2782 { 2796 2783 struct stv0367_state *state = fe->demodulator_priv; 2797 2784 struct stv0367cab_state *cab_state = state->cab_state; 2798 - int i; 2799 2785 2800 2786 dprintk("%s:\n", __func__); 2801 2787 2802 - for (i = 0; i < STV0367CAB_NBREGS; i++) 2803 - stv0367_writereg(state, def0367cab[i].addr, 2804 - def0367cab[i].value); 2788 + stv0367_write_table(state, def0367cab); 2805 2789 2806 2790 switch (state->config->ts_mode) { 2807 2791 case STV0367_DVBCI_CLOCK:
-4
drivers/media/dvb-frontends/stv0367_regs.h
··· 2639 2639 #define R367TER_DEBUG_LT9 0xf405 2640 2640 #define F367TER_F_DEBUG_LT9 0xf40500ff 2641 2641 2642 - #define STV0367TER_NBREGS 445 2643 - 2644 2642 /* ID */ 2645 2643 #define R367CAB_ID 0xf000 2646 2644 #define F367CAB_IDENTIFICATIONREGISTER 0xf00000ff ··· 3602 3604 /* T_O_ID_3 */ 3603 3605 #define R367CAB_T_O_ID_3 0xf4d3 3604 3606 #define F367CAB_TS_ID_I_H 0xf4d300ff 3605 - 3606 - #define STV0367CAB_NBREGS 187 3607 3607 3608 3608 #endif