diff options
author | Florian Mickler <florian@mickler.org> | 2011-03-21 06:19:14 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-05-20 08:28:14 -0400 |
commit | 60f81f12fa63213567b0b40546faa82b8f5d5b0c (patch) | |
tree | 7ad3f75a6840639fa07d4046d288725f9198f133 /drivers/media/dvb/dvb-usb/vp702x-fe.c | |
parent | ee52f120b0adc469f5c67815cef79ecdd01cfd14 (diff) |
[media] vp702x: use preallocated buffer in the frontend
Note: This change is tested to compile only as I don't have the
hardware.
Signed-off-by: Florian Mickler <florian@mickler.org>
Cc: Patrick Boettcher <pb@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/dvb-usb/vp702x-fe.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/vp702x-fe.c | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c index 7468a3839c5d..2bb8d4cc8d88 100644 --- a/drivers/media/dvb/dvb-usb/vp702x-fe.c +++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c | |||
@@ -41,14 +41,13 @@ struct vp702x_fe_state { | |||
41 | 41 | ||
42 | static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) | 42 | static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) |
43 | { | 43 | { |
44 | struct vp702x_device_state *dst = st->d->priv; | ||
44 | u8 *buf; | 45 | u8 *buf; |
45 | 46 | ||
46 | if (time_after(jiffies, st->next_status_check)) { | 47 | if (time_after(jiffies, st->next_status_check)) { |
47 | buf = kmalloc(10, GFP_KERNEL); | 48 | mutex_lock(&dst->buf_mutex); |
48 | if (!buf) { | 49 | buf = dst->buf; |
49 | deb_fe("%s: buffer alloc failed\n", __func__); | 50 | |
50 | return -ENOMEM; | ||
51 | } | ||
52 | vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10); | 51 | vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10); |
53 | st->lock = buf[4]; | 52 | st->lock = buf[4]; |
54 | 53 | ||
@@ -58,9 +57,8 @@ static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) | |||
58 | vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1); | 57 | vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1); |
59 | st->sig = buf[0]; | 58 | st->sig = buf[0]; |
60 | 59 | ||
61 | 60 | mutex_unlock(&dst->buf_mutex); | |
62 | st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000; | 61 | st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000; |
63 | kfree(buf); | ||
64 | } | 62 | } |
65 | return 0; | 63 | return 0; |
66 | } | 64 | } |
@@ -141,15 +139,17 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe, | |||
141 | struct dvb_frontend_parameters *fep) | 139 | struct dvb_frontend_parameters *fep) |
142 | { | 140 | { |
143 | struct vp702x_fe_state *st = fe->demodulator_priv; | 141 | struct vp702x_fe_state *st = fe->demodulator_priv; |
142 | struct vp702x_device_state *dst = st->d->priv; | ||
144 | u32 freq = fep->frequency/1000; | 143 | u32 freq = fep->frequency/1000; |
145 | /*CalFrequency*/ | 144 | /*CalFrequency*/ |
146 | /* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */ | 145 | /* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */ |
147 | u64 sr; | 146 | u64 sr; |
148 | u8 *cmd; | 147 | u8 *cmd; |
149 | 148 | ||
150 | cmd = kzalloc(10, GFP_KERNEL); | 149 | mutex_lock(&dst->buf_mutex); |
151 | if (!cmd) | 150 | |
152 | return -ENOMEM; | 151 | cmd = dst->buf; |
152 | memset(cmd, 0, 10); | ||
153 | 153 | ||
154 | cmd[0] = (freq >> 8) & 0x7f; | 154 | cmd[0] = (freq >> 8) & 0x7f; |
155 | cmd[1] = freq & 0xff; | 155 | cmd[1] = freq & 0xff; |
@@ -192,7 +192,8 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe, | |||
192 | else | 192 | else |
193 | deb_fe("tuning succeeded.\n"); | 193 | deb_fe("tuning succeeded.\n"); |
194 | 194 | ||
195 | kfree(cmd); | 195 | mutex_unlock(&dst->buf_mutex); |
196 | |||
196 | return 0; | 197 | return 0; |
197 | } | 198 | } |
198 | 199 | ||
@@ -220,21 +221,18 @@ static int vp702x_fe_get_frontend(struct dvb_frontend* fe, | |||
220 | static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, | 221 | static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, |
221 | struct dvb_diseqc_master_cmd *m) | 222 | struct dvb_diseqc_master_cmd *m) |
222 | { | 223 | { |
223 | int ret; | ||
224 | u8 *cmd; | 224 | u8 *cmd; |
225 | struct vp702x_fe_state *st = fe->demodulator_priv; | 225 | struct vp702x_fe_state *st = fe->demodulator_priv; |
226 | 226 | struct vp702x_device_state *dst = st->d->priv; | |
227 | cmd = kzalloc(10, GFP_KERNEL); | ||
228 | if (!cmd) | ||
229 | return -ENOMEM; | ||
230 | 227 | ||
231 | deb_fe("%s\n",__func__); | 228 | deb_fe("%s\n",__func__); |
232 | 229 | ||
233 | if (m->msg_len > 4) { | 230 | if (m->msg_len > 4) |
234 | ret = -EINVAL; | 231 | return -EINVAL; |
235 | goto out; | 232 | |
236 | } | 233 | mutex_lock(&dst->buf_mutex); |
237 | 234 | ||
235 | cmd = dst->buf; | ||
238 | cmd[1] = SET_DISEQC_CMD; | 236 | cmd[1] = SET_DISEQC_CMD; |
239 | cmd[2] = m->msg_len; | 237 | cmd[2] = m->msg_len; |
240 | memcpy(&cmd[3], m->msg, m->msg_len); | 238 | memcpy(&cmd[3], m->msg, m->msg_len); |
@@ -246,10 +244,10 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, | |||
246 | deb_fe("diseqc cmd failed.\n"); | 244 | deb_fe("diseqc cmd failed.\n"); |
247 | else | 245 | else |
248 | deb_fe("diseqc cmd succeeded.\n"); | 246 | deb_fe("diseqc cmd succeeded.\n"); |
249 | ret = 0; | 247 | |
250 | out: | 248 | mutex_unlock(&dst->buf_mutex); |
251 | kfree(cmd); | 249 | |
252 | return ret; | 250 | return 0; |
253 | } | 251 | } |
254 | 252 | ||
255 | static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) | 253 | static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) |
@@ -261,14 +259,11 @@ static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd | |||
261 | static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) | 259 | static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) |
262 | { | 260 | { |
263 | struct vp702x_fe_state *st = fe->demodulator_priv; | 261 | struct vp702x_fe_state *st = fe->demodulator_priv; |
262 | struct vp702x_device_state *dst = st->d->priv; | ||
264 | u8 *buf; | 263 | u8 *buf; |
265 | 264 | ||
266 | deb_fe("%s\n",__func__); | 265 | deb_fe("%s\n",__func__); |
267 | 266 | ||
268 | buf = kmalloc(10, GFP_KERNEL); | ||
269 | if (!buf) | ||
270 | return -ENOMEM; | ||
271 | |||
272 | st->tone_mode = tone; | 267 | st->tone_mode = tone; |
273 | 268 | ||
274 | if (tone == SEC_TONE_ON) | 269 | if (tone == SEC_TONE_ON) |
@@ -277,6 +272,10 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) | |||
277 | st->lnb_buf[2] = 0x00; | 272 | st->lnb_buf[2] = 0x00; |
278 | 273 | ||
279 | st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); | 274 | st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); |
275 | |||
276 | mutex_lock(&dst->buf_mutex); | ||
277 | |||
278 | buf = dst->buf; | ||
280 | memcpy(buf, st->lnb_buf, 8); | 279 | memcpy(buf, st->lnb_buf, 8); |
281 | 280 | ||
282 | vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); | 281 | vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); |
@@ -285,7 +284,8 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) | |||
285 | else | 284 | else |
286 | deb_fe("set_tone cmd succeeded.\n"); | 285 | deb_fe("set_tone cmd succeeded.\n"); |
287 | 286 | ||
288 | kfree(buf); | 287 | mutex_unlock(&dst->buf_mutex); |
288 | |||
289 | return 0; | 289 | return 0; |
290 | } | 290 | } |
291 | 291 | ||
@@ -293,13 +293,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t | |||
293 | voltage) | 293 | voltage) |
294 | { | 294 | { |
295 | struct vp702x_fe_state *st = fe->demodulator_priv; | 295 | struct vp702x_fe_state *st = fe->demodulator_priv; |
296 | struct vp702x_device_state *dst = st->d->priv; | ||
296 | u8 *buf; | 297 | u8 *buf; |
297 | deb_fe("%s\n",__func__); | 298 | deb_fe("%s\n",__func__); |
298 | 299 | ||
299 | buf = kmalloc(10, GFP_KERNEL); | ||
300 | if (!buf) | ||
301 | return -ENOMEM; | ||
302 | |||
303 | st->voltage = voltage; | 300 | st->voltage = voltage; |
304 | 301 | ||
305 | if (voltage != SEC_VOLTAGE_OFF) | 302 | if (voltage != SEC_VOLTAGE_OFF) |
@@ -308,6 +305,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t | |||
308 | st->lnb_buf[4] = 0x00; | 305 | st->lnb_buf[4] = 0x00; |
309 | 306 | ||
310 | st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); | 307 | st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); |
308 | |||
309 | mutex_lock(&dst->buf_mutex); | ||
310 | |||
311 | buf = dst->buf; | ||
311 | memcpy(buf, st->lnb_buf, 8); | 312 | memcpy(buf, st->lnb_buf, 8); |
312 | 313 | ||
313 | vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); | 314 | vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); |
@@ -316,7 +317,7 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t | |||
316 | else | 317 | else |
317 | deb_fe("set_voltage cmd succeeded.\n"); | 318 | deb_fe("set_voltage cmd succeeded.\n"); |
318 | 319 | ||
319 | kfree(buf); | 320 | mutex_unlock(&dst->buf_mutex); |
320 | return 0; | 321 | return 0; |
321 | } | 322 | } |
322 | 323 | ||