summaryrefslogtreecommitdiff
path: root/drivers/media/video/sn9c102/sn9c102_core.c
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2007-04-04 17:11:04 -0300
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-04-27 15:45:27 -0300
commitc680dd603857d7218b84751e9f6f0654bbfbefa2 (patch)
tree58ce390afc6bc720a57550a2171aa1af9a4b7df9 /drivers/media/video/sn9c102/sn9c102_core.c
parent0ee32871c18a3662d8958a8e9998eb4d2ae94159 (diff)
V4L/DVB (5502): Sn9c102: more efficient register writing code
There were many places in the driver which had long sequences of constant register initializations. These were done with one function call per register. The register address and value were immediate values in the function calls. This is very inefficient, as each register and value take twice the space when they are code, as each includes a push instruction to put it on the stack. There there is the overhead, both size and time, for a function call for each register. It's also quite a few lines of C code to do this. The patch creates a function that writes multiple registers from a list, and a macro that makes it easy to construct a such a list as a const static local to send to the function. This gets rid of quite a bit of C code, and shrinks the driver by around 8k, while at the same time being more efficient. Acked-by: Luca Risolia <luca.risolia@studio.unibo.it> Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/sn9c102/sn9c102_core.c')
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index f09caf2b6e75..028f173c1cce 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -209,27 +209,40 @@ static void sn9c102_queue_unusedframes(struct sn9c102_device* cam)
}
/*****************************************************************************/
-
-int sn9c102_write_regs(struct sn9c102_device* cam, u8* buff, u16 index)
+/*
+ * Write a sequence of count value/register pairs. Returns -1 after the
+ * first failed write, or 0 for no errors.
+ */
+int sn9c102_write_regs(struct sn9c102_device* cam, const u8 valreg[][2],
+ int count)
{
struct usb_device* udev = cam->usbdev;
+ u8* value = cam->control_buffer; /* Needed for DMA'able memory */
int i, res;
- if (index + sizeof(buff) >= ARRAY_SIZE(cam->reg))
- return -1;
+ for (i = 0; i < count; i++) {
+ u8 index = valreg[i][1];
+
+ /*
+ * index is a u8, so it must be <256 and can't be out of range.
+ * If we put in a check anyway, gcc annoys us with a warning
+ * that our check is useless. People get all uppity when they
+ * see warnings in the kernel compile.
+ */
+
+ *value = valreg[i][0];
+ res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+ 0x08, 0x41, index, 0,
+ value, 1, SN9C102_CTRL_TIMEOUT);
+ if (res < 0) {
+ DBG(3, "Failed to write a register (value 0x%02X, "
+ "index 0x%02X, error %d)", *value, index, res);
+ return -1;
+ }
- res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08, 0x41,
- index, 0, buff, sizeof(buff),
- SN9C102_CTRL_TIMEOUT*sizeof(buff));
- if (res < 0) {
- DBG(3, "Failed to write registers (index 0x%02X, error %d)",
- index, res);
- return -1;
+ cam->reg[index] = *value;
}
- for (i = 0; i < sizeof(buff); i++)
- cam->reg[index+i] = buff[i];
-
return 0;
}