4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/slab.h>
23 #include "pvrusb2-eeprom.h"
24 #include "pvrusb2-hdw-internal.h"
25 #include "pvrusb2-debug.h"
27 #define trace_eeprom(...) pvr2_trace(PVR2_TRACE_EEPROM,__VA_ARGS__)
33 Read and analyze data in the eeprom. Use tveeprom to figure out
34 the packet structure, since this is another Hauppauge device and
35 internally it has a family resemblence to ivtv-type devices
39 #include <media/tveeprom.h>
41 /* We seem to only be interested in the last 128 bytes of the EEPROM */
42 #define EEPROM_SIZE 128
44 /* Grab EEPROM contents, needed for direct method. */
45 static u8
*pvr2_eeprom_fetch(struct pvr2_hdw
*hdw
)
47 struct i2c_msg msg
[2];
56 eeprom
= kmalloc(EEPROM_SIZE
,GFP_KERNEL
);
58 pvr2_trace(PVR2_TRACE_ERROR_LEGS
,
59 "Failed to allocate memory"
60 " required to read eeprom");
64 trace_eeprom("Value for eeprom addr from controller was 0x%x",
66 addr
= hdw
->eeprom_addr
;
67 /* Seems that if the high bit is set, then the *real* eeprom
68 address is shifted right now bit position (noticed this in
69 newer PVR USB2 hardware) */
70 if (addr
& 0x80) addr
>>= 1;
72 /* FX2 documentation states that a 16bit-addressed eeprom is
73 expected if the I2C address is an odd number (yeah, this is
74 strange but it's what they do) */
76 eepromSize
= (mode16
? 4096 : 256);
77 trace_eeprom("Examining %d byte eeprom at location 0x%x"
78 " using %d bit addressing",eepromSize
,addr
,
83 msg
[0].len
= mode16
? 2 : 1;
86 msg
[1].flags
= I2C_M_RD
;
88 /* We have to do the actual eeprom data fetch ourselves, because
89 (1) we're only fetching part of the eeprom, and (2) if we were
90 getting the whole thing our I2C driver can't grab it in one
91 pass - which is what tveeprom is otherwise going to attempt */
92 memset(eeprom
,0,EEPROM_SIZE
);
93 for (tcnt
= 0; tcnt
< EEPROM_SIZE
; tcnt
+= pcnt
) {
95 if (pcnt
+ tcnt
> EEPROM_SIZE
) pcnt
= EEPROM_SIZE
-tcnt
;
96 offs
= tcnt
+ (eepromSize
- EEPROM_SIZE
);
104 msg
[1].buf
= eeprom
+tcnt
;
105 if ((ret
= i2c_transfer(&hdw
->i2c_adap
,
106 msg
,ARRAY_SIZE(msg
))) != 2) {
107 pvr2_trace(PVR2_TRACE_ERROR_LEGS
,
108 "eeprom fetch set offs err=%d",ret
);
117 /* Directly call eeprom analysis function within tveeprom. */
118 int pvr2_eeprom_analyze(struct pvr2_hdw
*hdw
)
121 struct tveeprom tvdata
;
123 memset(&tvdata
,0,sizeof(tvdata
));
125 eeprom
= pvr2_eeprom_fetch(hdw
);
126 if (!eeprom
) return -EINVAL
;
129 struct i2c_client fake_client
;
130 /* Newer version expects a useless client interface */
131 fake_client
.addr
= hdw
->eeprom_addr
;
132 fake_client
.adapter
= &hdw
->i2c_adap
;
133 tveeprom_hauppauge_analog(&fake_client
,&tvdata
,eeprom
);
136 trace_eeprom("eeprom assumed v4l tveeprom module");
137 trace_eeprom("eeprom direct call results:");
138 trace_eeprom("has_radio=%d",tvdata
.has_radio
);
139 trace_eeprom("tuner_type=%d",tvdata
.tuner_type
);
140 trace_eeprom("tuner_formats=0x%x",tvdata
.tuner_formats
);
141 trace_eeprom("audio_processor=%d",tvdata
.audio_processor
);
142 trace_eeprom("model=%d",tvdata
.model
);
143 trace_eeprom("revision=%d",tvdata
.revision
);
144 trace_eeprom("serial_number=%d",tvdata
.serial_number
);
145 trace_eeprom("rev_str=%s",tvdata
.rev_str
);
146 hdw
->tuner_type
= tvdata
.tuner_type
;
147 hdw
->tuner_updated
= !0;
148 hdw
->serial_number
= tvdata
.serial_number
;
149 hdw
->std_mask_eeprom
= tvdata
.tuner_formats
;
157 Stuff for Emacs to see, in order to encourage consistent editing style:
158 *** Local Variables: ***
160 *** fill-column: 70 ***
162 *** c-basic-offset: 8 ***