diff options
Diffstat (limited to 'drivers/media/dvb/frontends/dib7000m.c')
-rw-r--r-- | drivers/media/dvb/frontends/dib7000m.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c index 289a79837f24..79cb1c20df24 100644 --- a/drivers/media/dvb/frontends/dib7000m.c +++ b/drivers/media/dvb/frontends/dib7000m.c | |||
@@ -50,6 +50,11 @@ struct dib7000m_state { | |||
50 | u16 revision; | 50 | u16 revision; |
51 | 51 | ||
52 | u8 agc_state; | 52 | u8 agc_state; |
53 | |||
54 | /* for the I2C transfer */ | ||
55 | struct i2c_msg msg[2]; | ||
56 | u8 i2c_write_buffer[4]; | ||
57 | u8 i2c_read_buffer[2]; | ||
53 | }; | 58 | }; |
54 | 59 | ||
55 | enum dib7000m_power_mode { | 60 | enum dib7000m_power_mode { |
@@ -64,29 +69,39 @@ enum dib7000m_power_mode { | |||
64 | 69 | ||
65 | static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg) | 70 | static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg) |
66 | { | 71 | { |
67 | u8 wb[2] = { (reg >> 8) | 0x80, reg & 0xff }; | 72 | state->i2c_write_buffer[0] = (reg >> 8) | 0x80; |
68 | u8 rb[2]; | 73 | state->i2c_write_buffer[1] = reg & 0xff; |
69 | struct i2c_msg msg[2] = { | 74 | |
70 | { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 }, | 75 | memset(state->msg, 0, 2 * sizeof(struct i2c_msg)); |
71 | { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 }, | 76 | state->msg[0].addr = state->i2c_addr >> 1; |
72 | }; | 77 | state->msg[0].flags = 0; |
73 | 78 | state->msg[0].buf = state->i2c_write_buffer; | |
74 | if (i2c_transfer(state->i2c_adap, msg, 2) != 2) | 79 | state->msg[0].len = 2; |
80 | state->msg[1].addr = state->i2c_addr >> 1; | ||
81 | state->msg[1].flags = I2C_M_RD; | ||
82 | state->msg[1].buf = state->i2c_read_buffer; | ||
83 | state->msg[1].len = 2; | ||
84 | |||
85 | if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2) | ||
75 | dprintk("i2c read error on %d",reg); | 86 | dprintk("i2c read error on %d",reg); |
76 | 87 | ||
77 | return (rb[0] << 8) | rb[1]; | 88 | return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1]; |
78 | } | 89 | } |
79 | 90 | ||
80 | static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val) | 91 | static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val) |
81 | { | 92 | { |
82 | u8 b[4] = { | 93 | state->i2c_write_buffer[0] = (reg >> 8) & 0xff; |
83 | (reg >> 8) & 0xff, reg & 0xff, | 94 | state->i2c_write_buffer[1] = reg & 0xff; |
84 | (val >> 8) & 0xff, val & 0xff, | 95 | state->i2c_write_buffer[2] = (val >> 8) & 0xff; |
85 | }; | 96 | state->i2c_write_buffer[3] = val & 0xff; |
86 | struct i2c_msg msg = { | 97 | |
87 | .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4 | 98 | memset(&state->msg[0], 0, sizeof(struct i2c_msg)); |
88 | }; | 99 | state->msg[0].addr = state->i2c_addr >> 1; |
89 | return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; | 100 | state->msg[0].flags = 0; |
101 | state->msg[0].buf = state->i2c_write_buffer; | ||
102 | state->msg[0].len = 4; | ||
103 | |||
104 | return i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0; | ||
90 | } | 105 | } |
91 | static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf) | 106 | static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf) |
92 | { | 107 | { |