diff options
Diffstat (limited to 'drivers/media/dvb/frontends/dib0070.c')
-rw-r--r-- | drivers/media/dvb/frontends/dib0070.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/drivers/media/dvb/frontends/dib0070.c b/drivers/media/dvb/frontends/dib0070.c index d4e466a90e43..1d47d4da7d4c 100644 --- a/drivers/media/dvb/frontends/dib0070.c +++ b/drivers/media/dvb/frontends/dib0070.c | |||
@@ -73,27 +73,47 @@ struct dib0070_state { | |||
73 | 73 | ||
74 | u8 wbd_gain_current; | 74 | u8 wbd_gain_current; |
75 | u16 wbd_offset_3_3[2]; | 75 | u16 wbd_offset_3_3[2]; |
76 | |||
77 | /* for the I2C transfer */ | ||
78 | struct i2c_msg msg[2]; | ||
79 | u8 i2c_write_buffer[3]; | ||
80 | u8 i2c_read_buffer[2]; | ||
76 | }; | 81 | }; |
77 | 82 | ||
78 | static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg) | 83 | static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg) |
79 | { | 84 | { |
80 | u8 b[2]; | 85 | state->i2c_write_buffer[0] = reg; |
81 | struct i2c_msg msg[2] = { | 86 | |
82 | { .addr = state->cfg->i2c_address, .flags = 0, .buf = ®, .len = 1 }, | 87 | memset(state->msg, 0, 2 * sizeof(struct i2c_msg)); |
83 | { .addr = state->cfg->i2c_address, .flags = I2C_M_RD, .buf = b, .len = 2 }, | 88 | state->msg[0].addr = state->cfg->i2c_address; |
84 | }; | 89 | state->msg[0].flags = 0; |
85 | if (i2c_transfer(state->i2c, msg, 2) != 2) { | 90 | state->msg[0].buf = state->i2c_write_buffer; |
91 | state->msg[0].len = 1; | ||
92 | state->msg[1].addr = state->cfg->i2c_address; | ||
93 | state->msg[1].flags = I2C_M_RD; | ||
94 | state->msg[1].buf = state->i2c_read_buffer; | ||
95 | state->msg[1].len = 2; | ||
96 | |||
97 | if (i2c_transfer(state->i2c, state->msg, 2) != 2) { | ||
86 | printk(KERN_WARNING "DiB0070 I2C read failed\n"); | 98 | printk(KERN_WARNING "DiB0070 I2C read failed\n"); |
87 | return 0; | 99 | return 0; |
88 | } | 100 | } |
89 | return (b[0] << 8) | b[1]; | 101 | return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1]; |
90 | } | 102 | } |
91 | 103 | ||
92 | static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val) | 104 | static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val) |
93 | { | 105 | { |
94 | u8 b[3] = { reg, val >> 8, val & 0xff }; | 106 | state->i2c_write_buffer[0] = reg; |
95 | struct i2c_msg msg = { .addr = state->cfg->i2c_address, .flags = 0, .buf = b, .len = 3 }; | 107 | state->i2c_write_buffer[1] = val >> 8; |
96 | if (i2c_transfer(state->i2c, &msg, 1) != 1) { | 108 | state->i2c_write_buffer[2] = val & 0xff; |
109 | |||
110 | memset(state->msg, 0, sizeof(struct i2c_msg)); | ||
111 | state->msg[0].addr = state->cfg->i2c_address; | ||
112 | state->msg[0].flags = 0; | ||
113 | state->msg[0].buf = state->i2c_write_buffer; | ||
114 | state->msg[0].len = 3; | ||
115 | |||
116 | if (i2c_transfer(state->i2c, state->msg, 1) != 1) { | ||
97 | printk(KERN_WARNING "DiB0070 I2C write failed\n"); | 117 | printk(KERN_WARNING "DiB0070 I2C write failed\n"); |
98 | return -EREMOTEIO; | 118 | return -EREMOTEIO; |
99 | } | 119 | } |