| From: D. Hugh Redelmeier <[EMAIL PROTECTED]>
| I had a quick look at the original and was startled by a number of
| things. Here is a patch that should cut down on stack usage and cut down
| on object code. It seems like a no-brainer to me.
|
| The main change is to make as many seq arrays as possible static const.
| If they had a non-const part, I had to leave them on the stack. David
| went to the trouble of kmallocing everything.
Here is a revised version. I improved a comment and I added "const"
to those seq arrays that could not be made "static const".
All the previous description still applies.
===================================================================
RCS file: ivtv-0.3.2e/driver/RCS/cx25840-driver.c,v
retrieving revision 1.1
diff -u -r1.1 ivtv-0.3.2e/driver/cx25840-driver.c
--- ivtv-0.3.2e/driver/cx25840-driver.c 2005/02/23 09:06:12 1.1
+++ ivtv-0.3.2e/driver/cx25840-driver.c 2005/02/23 18:53:28
@@ -167,7 +167,7 @@
static int analyze=0;
-static inline int i2c_master_send_wrap(struct i2c_client *client, u8 *b, int
len) {
+static inline int i2c_master_send_wrap(struct i2c_client *client, const u8 *b,
int len) {
struct cx25840_state *s=i2c_get_clientdata(client);
int i;
int ptr=b[0]*256+b[1];
@@ -248,7 +248,7 @@
}
}
-void setting_sequencer(struct i2c_client *client, __u8 *ptr) {
+static void setting_sequencer(struct i2c_client *client, const __u8 *ptr) {
struct cx25840_state *state=i2c_get_clientdata(client);
int cnt=0;
__u8 reg_buff[number_of_registers+2];
@@ -266,7 +266,7 @@
// This is ugly but effective for development.....
u16 saddr=client->addr;
u16 naddr=ptr[3];
- u8 *i2c_data =&ptr[4];
+ const u8 *i2c_data =&ptr[4];
int ret;
ptr+=2+2+len;
if (ptr[0]!=0xBB||ptr[1]!=0x44) break; ptr+=2;
@@ -305,7 +305,7 @@
}
memset (dirt, 0, sizeof(dirt));
} else if (setting==special_tag_setting) {
- char *tag=CX25840_SEQUENCE_GET_TAG(ptr);
+ const char *tag=CX25840_SEQUENCE_GET_TAG(ptr);
ptr+=CX25840_SEQUENCE_GET_TAG_LENGTH(ptr);
if (ptr[0]!=0xBB||ptr[1]!=0x44) break; ptr+=2;
DEBUG(1, "Sequence tag: '%s'",tag);
@@ -416,7 +416,7 @@
}
static int load_aud_fw(struct i2c_client *client) {
- u8 start_fw_load[]= {
+ static const u8 start_fw_load[]= {
CX25840_TAG('F','W',' ','D','L',' ','S','t','a','r','t'),
CX25840_SET_DL_ADDR_LB(0x0000), // '*'
(Default 0x0000) Reg: 0x0800 Start bit: 0 Bit length: 8
CX25840_SET_DL_ADDR_HB(0x0000), // '*'
(Default 0x0000) Reg: 0x0801 Start bit: 0 Bit length: 8
@@ -429,7 +429,7 @@
CX25840_END
};
- u8 end_fw_load[]= {
+ static const u8 end_fw_load[]= {
CX25840_TAG('F','W',' ','D','L',' ','S','t','o','p'),
CX25840_SET_AUTO_INC_DIS(0x0000), // 'Do the
auto-address increment' (Default 0x0000) Reg: 0x0000 Start bit: 5 Bit length: 1
CX25840_SET_DL_ENABLE(0x0000), // 'Disable'
(Default 0x0000) Reg: 0x0803 Start bit: 3 Bit length: 1
@@ -539,7 +539,7 @@
// CX25840_EXECUTE,
/*
- static void cx25840_reset(struct i2c_client *client) {
+ static const static void cx25840_reset(struct i2c_client *client) {
CX25840_TAG('R','e','s','e','t'),
WI2C(3, I_cx25840, 0x00,0x00, 0x01),
@@ -556,7 +556,7 @@
END
*/
- unsigned char seq[]={
+ static const unsigned char seq[]={
CX25840_TAG('B','o','o','t','.'),
CX25840_SET_VD_SOFT_RST(1), // Video assert
CX25840_SET_SOFT_RESET(1), // Soft reset assert
@@ -796,12 +796,12 @@
DEBUG(0, "Decoder set size %dx%d (from %dx%d) -> scale %ux%u, filter %d",
wind->width, wind->height, Hsrc, Vsrc, HSC, VSC, filter);
{
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('S','c','a','l','e'),
CX25840_SET_VS_INTRLACE(1),
- CX25840_SET_VFILT(filter),
- CX25840_SET_HSCALE(HSC),
- CX25840_SET_VSCALE(VSC),
+ CX25840_SET_VFILT(filter), /* not a compile-time constant */
+ CX25840_SET_HSCALE(HSC), /* not a compile-time constant */
+ CX25840_SET_VSCALE(VSC), /* not a compile-time constant */
CX25840_EXECUTE,
CX25840_END};
@@ -849,9 +849,9 @@
state->audio = *iarg;
{
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('S','a','m','p','l','e',' ','r','a','t','e'),
- CX25840_SET_SRC3_PHASE_INC(pinc),
+ CX25840_SET_SRC3_PHASE_INC(pinc), /* not a compile-time constant */
CX25840_EXECUTE,
CX25840_END};
setting_sequencer(client, seq);
@@ -933,7 +933,7 @@
state->input = *iarg;
switch (cx25840_input_layout[state->input]) {
case CX25840_COMPOSITE: {
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('C','o','m','p','o','s','i','t','e'),
CX25840_SET_START_MICROCNTL(0x0000),
CX25840_SET_SOFT_RESET(0x0001),
@@ -959,7 +959,7 @@
CX25840_SET_SA_MUTE_EN(0x0000),
CX25840_SET_PAR_MUTE_EN(0x0000),
CX25840_SET_AC97_MUTE_EN(0x0000),
- CX25840_SET_SRC3_PHASE_INC(41942880/freq_out),
+ CX25840_SET_SRC3_PHASE_INC(41942880/freq_out), /* not a
compile-time constant */
CX25840_EXECUTE,
CX25840_SET_START_MICROCNTL(0x0000),
@@ -973,7 +973,7 @@
break;
}
case CX25840_SVIDEO: {
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('S','-','v','i','d','e','o'),
CX25840_SET_START_MICROCNTL(0x0000),
CX25840_SET_SOFT_RESET(0x0001),
@@ -1063,7 +1063,7 @@
CX25840_SET_SA_MUTE_EN(0x0000), // 'Disable' (Default
0x00, Register 0x8d3.2-3)
CX25840_SET_PAR_MUTE_EN(0x0000), // 'Disable' (Default
0x00, Register 0x8d3.3-4)
CX25840_SET_AC97_MUTE_EN(0x0000), // 'Disable' (Default
0x00, Register 0x8d3.4-5)
- CX25840_SET_SRC3_PHASE_INC(41942880/freq_out),
+ CX25840_SET_SRC3_PHASE_INC(41942880/freq_out), /* not a
compile-time constant */
CX25840_SET_SRC3_FIFO_RD_TH(0x0008), // '*' (Default 0x08,
Register 0x903.0-4)
CX25840_SET_SRC4_PHASE_INC(0x15555), // '*' (Default
0x14faa, Register 0x904.0-18)
CX25840_SET_SRC4_FIFO_RD_TH(0x0008), // '*' (Default 0x08,
Register 0x907.0-4)
@@ -1083,8 +1083,8 @@
break;
}
case CX25840_TUNER: {
- u8 seq[]={
- CX25840_TAG('T','u','n','e','r','
',cardtype==0?'1':'5',cardtype==0?'5':'0','0'),
+ const u8 seq[]={
+ CX25840_TAG('T','u','n','e','r','
',cardtype==0?'1':'5',cardtype==0?'5':'0','0'), /* not a compile-time
constant */
CX25840_SET_START_MICROCNTL(0x0000), // FW stop.
CX25840_SET_VD_SOFT_RST(0x0001), // Assert video reset
@@ -1093,18 +1093,18 @@
CX25840_SET_CH_SEL_ADC2(0x0000),
CX25840_SET_DUAL_MODE_ADC2(0x0000),
- CX25840_SET_CH_1__SOURCE(cardtype==2?0x0001:0x0006),
+ CX25840_SET_CH_1__SOURCE(cardtype==2?0x0001:0x0006), /* not a
compile-time constant */
CX25840_SET_CH_2__SOURCE(0x0003),
- CX25840_SET_CH_3__SOURCE(cardtype==0?0x0001:0x0000), // 1 for
150, 0 for 500
+ CX25840_SET_CH_3__SOURCE(cardtype==0?0x0001:0x0000), // 1 for
150, 0 for 500 [not a compile-time constant]
CX25840_SET_AUX_PLL_POST(0x0018),
CX25840_SET_VID_FMT_SEL(0x0000), // Auto-select video format
- CX25840_SET_AUD_STANDARD(audiofmt), // Force auto-detect of
audio
+ CX25840_SET_AUD_STANDARD(audiofmt), // Force auto-detect of
audio [not a compile-time constant]
CX25840_SET_AUD_MODE_AUD_SYSTEM(0x000F), // Force auto-detect of audio
CX25840_SET_PREF_MODE(0x0004), // Preferred audio mode is
stereo
CX25840_SET_MUTE_NO_PREF_MODE(0x0000), // Don't mute if preferred
output unavailable
CX25840_SET_PATH1_SEL_CTL(0x0000), // Set the audio source
- CX25840_SET_SRC3_PHASE_INC(41942880/freq_out),
+ CX25840_SET_SRC3_PHASE_INC(41942880/freq_out), /* not a compile-time
constant */
CX25840_SET_SOFT1_MUTE_EN(0x0001),
CX25840_SET_SRC1_MUTE_EN(0x0000),
CX25840_SET_SA_MUTE_EN(0x0000),
@@ -1122,7 +1122,7 @@
break;
}
case 6: {
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('T','u','n','n','e','r',' ','1','5','0'),
CX25840_SET_START_MICROCNTL(0x0000), // FW stop.
@@ -1163,7 +1163,7 @@
CX25840_SET_SA_MUTE_EN(0x0000),
CX25840_SET_PAR_MUTE_EN(0x0000),
CX25840_SET_AC97_MUTE_EN(0x0000),
- CX25840_SET_SRC3_PHASE_INC(41246400/freq_out),
+ CX25840_SET_SRC3_PHASE_INC(41246400/freq_out), /* not a
compile-time constant */
CX25840_EXECUTE,
CX25840_SET_START_MICROCNTL(0x0001), // FW Start
@@ -1195,7 +1195,7 @@
state->enable = enable;
if (state->enable) {
- u8 seq[]={
+ static const u8 seq[]={
CX25840_TAG('E','n','a','b','l','e'), // Modified regs delta
//CX25840_SET_START_MICROCNTL(0x0000), // FW stop.
@@ -1335,13 +1335,13 @@
state->hue = pic->hue;
{
- u8 seq[]={
+ const u8 seq[]={
CX25840_TAG('P','i','c','t','u','r','e'),
- CX25840_SET_USAT(pic->sat*2),
- CX25840_SET_VSAT(pic->sat*2),
- CX25840_SET_BRIGHT((state->bright-128)),
- CX25840_SET_CNTRST(state->contrast*2),
- CX25840_SET_HUE(pic->hue),
+ CX25840_SET_USAT(pic->sat*2), /* not a compile-time constant */
+ CX25840_SET_VSAT(pic->sat*2), /* not a compile-time constant
*/
+ CX25840_SET_BRIGHT((state->bright-128)), /* not a compile-time
constant */
+ CX25840_SET_CNTRST(state->contrast*2), /* not a compile-time constant
*/
+ CX25840_SET_HUE(pic->hue), /* not a compile-time constant */
CX25840_EXECUTE,
CX25840_END};
@@ -1353,7 +1353,7 @@
break;
}
case DECODER_RESET: {
- u8 seq[]={
+ static const u8 seq[]={
CX25840_TAG('R','e','s','e','t'),
CX25840_SET_START_MICROCNTL(0x0000), // FW stop.
CX25840_SET_SOFT_RESET(0x0001), // Soft reset assert.
================================================================
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
ivtv-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ivtv-devel