aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx/em28xx-i2c.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@brturbo.com.br>2005-11-09 00:38:27 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 10:56:27 -0500
commit3acf28095009509c9ca1e283de821b5be9ddede6 (patch)
tree824f31e6942ac09d977103f4a010e0a349b3afa2 /drivers/media/video/em28xx/em28xx-i2c.c
parente0ec29b7e5aa1f4f1ff73ebd3003336dbe83e174 (diff)
[PATCH] v4l: 886: renamed common structures to em28xx
- Renamed common structures to em28xx Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/media/video/em28xx/em28xx-i2c.c')
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index a62e66bd65f9..b32d9852f34c 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -50,7 +50,7 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
50 * em2800_i2c_send_max4() 50 * em2800_i2c_send_max4()
51 * send up to 4 bytes to the i2c device 51 * send up to 4 bytes to the i2c device
52 */ 52 */
53static int em2800_i2c_send_max4(struct em2820 *dev, unsigned char addr, 53static int em2800_i2c_send_max4(struct em28xx *dev, unsigned char addr,
54 char *buf, int len) 54 char *buf, int len)
55{ 55{
56 int ret; 56 int ret;
@@ -67,19 +67,19 @@ static int em2800_i2c_send_max4(struct em2820 *dev, unsigned char addr,
67 if (len > 3) 67 if (len > 3)
68 b2[0] = buf[3]; 68 b2[0] = buf[3];
69 69
70 ret = dev->em2820_write_regs(dev, 4 - len, &b2[4 - len], 2 + len); 70 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len);
71 if (ret != 2 + len) { 71 if (ret != 2 + len) {
72 em2820_warn("writting to i2c device failed (error=%i)\n", ret); 72 em28xx_warn("writting to i2c device failed (error=%i)\n", ret);
73 return -EIO; 73 return -EIO;
74 } 74 }
75 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 75 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
76 write_timeout -= 5) { 76 write_timeout -= 5) {
77 ret = dev->em2820_read_reg(dev, 0x05); 77 ret = dev->em28xx_read_reg(dev, 0x05);
78 if (ret == 0x80 + len - 1) 78 if (ret == 0x80 + len - 1)
79 return len; 79 return len;
80 mdelay(5); 80 mdelay(5);
81 } 81 }
82 em2820_warn("i2c write timed out\n"); 82 em28xx_warn("i2c write timed out\n");
83 return -EIO; 83 return -EIO;
84} 84}
85 85
@@ -94,7 +94,7 @@ static int em2800_i2c_send_bytes(void *data, unsigned char addr, char *buf,
94 int wrcount = 0; 94 int wrcount = 0;
95 int count; 95 int count;
96 int maxLen = 4; 96 int maxLen = 4;
97 struct em2820 *dev = (struct em2820 *)data; 97 struct em28xx *dev = (struct em28xx *)data;
98 while (len > 0) { 98 while (len > 0) {
99 count = (len > maxLen) ? maxLen : len; 99 count = (len > maxLen) ? maxLen : len;
100 ret = em2800_i2c_send_max4(dev, addr, bufPtr, count); 100 ret = em2800_i2c_send_max4(dev, addr, bufPtr, count);
@@ -112,27 +112,27 @@ static int em2800_i2c_send_bytes(void *data, unsigned char addr, char *buf,
112 * em2800_i2c_check_for_device() 112 * em2800_i2c_check_for_device()
113 * check if there is a i2c_device at the supplied address 113 * check if there is a i2c_device at the supplied address
114 */ 114 */
115static int em2800_i2c_check_for_device(struct em2820 *dev, unsigned char addr) 115static int em2800_i2c_check_for_device(struct em28xx *dev, unsigned char addr)
116{ 116{
117 char msg; 117 char msg;
118 int ret; 118 int ret;
119 int write_timeout; 119 int write_timeout;
120 msg = addr; 120 msg = addr;
121 ret = dev->em2820_write_regs(dev, 0x04, &msg, 1); 121 ret = dev->em28xx_write_regs(dev, 0x04, &msg, 1);
122 if (ret < 0) { 122 if (ret < 0) {
123 em2820_warn("setting i2c device address failed (error=%i)\n", 123 em28xx_warn("setting i2c device address failed (error=%i)\n",
124 ret); 124 ret);
125 return ret; 125 return ret;
126 } 126 }
127 msg = 0x84; 127 msg = 0x84;
128 ret = dev->em2820_write_regs(dev, 0x05, &msg, 1); 128 ret = dev->em28xx_write_regs(dev, 0x05, &msg, 1);
129 if (ret < 0) { 129 if (ret < 0) {
130 em2820_warn("preparing i2c read failed (error=%i)\n", ret); 130 em28xx_warn("preparing i2c read failed (error=%i)\n", ret);
131 return ret; 131 return ret;
132 } 132 }
133 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 133 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
134 write_timeout -= 5) { 134 write_timeout -= 5) {
135 unsigned msg = dev->em2820_read_reg(dev, 0x5); 135 unsigned msg = dev->em28xx_read_reg(dev, 0x5);
136 if (msg == 0x94) 136 if (msg == 0x94)
137 return -ENODEV; 137 return -ENODEV;
138 else if (msg == 0x84) 138 else if (msg == 0x84)
@@ -146,21 +146,21 @@ static int em2800_i2c_check_for_device(struct em2820 *dev, unsigned char addr)
146 * em2800_i2c_recv_bytes() 146 * em2800_i2c_recv_bytes()
147 * read from the i2c device 147 * read from the i2c device
148 */ 148 */
149static int em2800_i2c_recv_bytes(struct em2820 *dev, unsigned char addr, 149static int em2800_i2c_recv_bytes(struct em28xx *dev, unsigned char addr,
150 char *buf, int len) 150 char *buf, int len)
151{ 151{
152 int ret; 152 int ret;
153 /* check for the device and set i2c read address */ 153 /* check for the device and set i2c read address */
154 ret = em2800_i2c_check_for_device(dev, addr); 154 ret = em2800_i2c_check_for_device(dev, addr);
155 if (ret) { 155 if (ret) {
156 em2820_warn 156 em28xx_warn
157 ("preparing read at i2c address 0x%x failed (error=%i)\n", 157 ("preparing read at i2c address 0x%x failed (error=%i)\n",
158 addr, ret); 158 addr, ret);
159 return ret; 159 return ret;
160 } 160 }
161 ret = dev->em2820_read_reg_req_len(dev, 0x0, 0x3, buf, len); 161 ret = dev->em28xx_read_reg_req_len(dev, 0x0, 0x3, buf, len);
162 if (ret < 0) { 162 if (ret < 0) {
163 em2820_warn("reading from i2c device at 0x%x failed (error=%i)", 163 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)",
164 addr, ret); 164 addr, ret);
165 return ret; 165 return ret;
166 } 166 }
@@ -168,66 +168,66 @@ static int em2800_i2c_recv_bytes(struct em2820 *dev, unsigned char addr,
168} 168}
169 169
170/* 170/*
171 * em2820_i2c_send_bytes() 171 * em28xx_i2c_send_bytes()
172 * untested for more than 4 bytes 172 * untested for more than 4 bytes
173 */ 173 */
174static int em2820_i2c_send_bytes(void *data, unsigned char addr, char *buf, 174static int em28xx_i2c_send_bytes(void *data, unsigned char addr, char *buf,
175 short len, int stop) 175 short len, int stop)
176{ 176{
177 int wrcount = 0; 177 int wrcount = 0;
178 struct em2820 *dev = (struct em2820 *)data; 178 struct em28xx *dev = (struct em28xx *)data;
179 179
180 wrcount = dev->em2820_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); 180 wrcount = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
181 181
182 return wrcount; 182 return wrcount;
183} 183}
184 184
185/* 185/*
186 * em2820_i2c_recv_bytes() 186 * em28xx_i2c_recv_bytes()
187 * read a byte from the i2c device 187 * read a byte from the i2c device
188 */ 188 */
189static int em2820_i2c_recv_bytes(struct em2820 *dev, unsigned char addr, 189static int em28xx_i2c_recv_bytes(struct em28xx *dev, unsigned char addr,
190 char *buf, int len) 190 char *buf, int len)
191{ 191{
192 int ret; 192 int ret;
193 ret = dev->em2820_read_reg_req_len(dev, 2, addr, buf, len); 193 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len);
194 if (ret < 0) { 194 if (ret < 0) {
195 em2820_warn("reading i2c device failed (error=%i)\n", ret); 195 em28xx_warn("reading i2c device failed (error=%i)\n", ret);
196 return ret; 196 return ret;
197 } 197 }
198 if (dev->em2820_read_reg(dev, 0x5) != 0) 198 if (dev->em28xx_read_reg(dev, 0x5) != 0)
199 return -ENODEV; 199 return -ENODEV;
200 return ret; 200 return ret;
201} 201}
202 202
203/* 203/*
204 * em2820_i2c_check_for_device() 204 * em28xx_i2c_check_for_device()
205 * check if there is a i2c_device at the supplied address 205 * check if there is a i2c_device at the supplied address
206 */ 206 */
207static int em2820_i2c_check_for_device(struct em2820 *dev, unsigned char addr) 207static int em28xx_i2c_check_for_device(struct em28xx *dev, unsigned char addr)
208{ 208{
209 char msg; 209 char msg;
210 int ret; 210 int ret;
211 msg = addr; 211 msg = addr;
212 212
213 ret = dev->em2820_read_reg_req(dev, 2, addr); 213 ret = dev->em28xx_read_reg_req(dev, 2, addr);
214 if (ret < 0) { 214 if (ret < 0) {
215 em2820_warn("reading from i2c device failed (error=%i)\n", ret); 215 em28xx_warn("reading from i2c device failed (error=%i)\n", ret);
216 return ret; 216 return ret;
217 } 217 }
218 if (dev->em2820_read_reg(dev, 0x5) != 0) 218 if (dev->em28xx_read_reg(dev, 0x5) != 0)
219 return -ENODEV; 219 return -ENODEV;
220 return 0; 220 return 0;
221} 221}
222 222
223/* 223/*
224 * em2820_i2c_xfer() 224 * em28xx_i2c_xfer()
225 * the main i2c transfer function 225 * the main i2c transfer function
226 */ 226 */
227static int em2820_i2c_xfer(struct i2c_adapter *i2c_adap, 227static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
228 struct i2c_msg msgs[], int num) 228 struct i2c_msg msgs[], int num)
229{ 229{
230 struct em2820 *dev = i2c_adap->algo_data; 230 struct em28xx *dev = i2c_adap->algo_data;
231 int addr, rc, i, byte; 231 int addr, rc, i, byte;
232 232
233 if (num <= 0) 233 if (num <= 0)
@@ -241,7 +241,7 @@ static int em2820_i2c_xfer(struct i2c_adapter *i2c_adap,
241 if (dev->is_em2800) 241 if (dev->is_em2800)
242 rc = em2800_i2c_check_for_device(dev, addr); 242 rc = em2800_i2c_check_for_device(dev, addr);
243 else 243 else
244 rc = em2820_i2c_check_for_device(dev, addr); 244 rc = em28xx_i2c_check_for_device(dev, addr);
245 if (rc < 0) { 245 if (rc < 0) {
246 dprintk2(2," no device\n"); 246 dprintk2(2," no device\n");
247 return rc; 247 return rc;
@@ -254,7 +254,7 @@ static int em2820_i2c_xfer(struct i2c_adapter *i2c_adap,
254 msgs[i].buf, 254 msgs[i].buf,
255 msgs[i].len); 255 msgs[i].len);
256 else 256 else
257 rc = em2820_i2c_recv_bytes(dev, addr, 257 rc = em28xx_i2c_recv_bytes(dev, addr,
258 msgs[i].buf, 258 msgs[i].buf,
259 msgs[i].len); 259 msgs[i].len);
260 if (i2c_debug>=2) { 260 if (i2c_debug>=2) {
@@ -273,7 +273,7 @@ static int em2820_i2c_xfer(struct i2c_adapter *i2c_adap,
273 msgs[i].buf, 273 msgs[i].buf,
274 msgs[i].len); 274 msgs[i].len);
275 else 275 else
276 rc = em2820_i2c_send_bytes(dev, addr, 276 rc = em28xx_i2c_send_bytes(dev, addr,
277 msgs[i].buf, 277 msgs[i].buf,
278 msgs[i].len, 278 msgs[i].len,
279 i == num - 1); 279 i == num - 1);
@@ -290,10 +290,10 @@ static int em2820_i2c_xfer(struct i2c_adapter *i2c_adap,
290 return rc; 290 return rc;
291} 291}
292 292
293static int em2820_i2c_eeprom(struct em2820 *dev, unsigned char *eedata, int len) 293static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
294{ 294{
295 unsigned char buf, *p = eedata; 295 unsigned char buf, *p = eedata;
296 struct em2820_eeprom *em_eeprom = (void *)eedata; 296 struct em28xx_eeprom *em_eeprom = (void *)eedata;
297 int i, err, size = len, block; 297 int i, err, size = len, block;
298 298
299 dev->i2c_client.addr = 0xa0 >> 1; 299 dev->i2c_client.addr = 0xa0 >> 1;
@@ -410,9 +410,9 @@ static void dec_use(struct i2c_adapter *adap)
410} 410}
411#endif 411#endif
412 412
413static int em2820_set_tuner(int check_eeprom, struct i2c_client *client) 413static int em28xx_set_tuner(int check_eeprom, struct i2c_client *client)
414{ 414{
415 struct em2820 *dev = client->adapter->algo_data; 415 struct em28xx *dev = client->adapter->algo_data;
416 struct tuner_setup tun_setup; 416 struct tuner_setup tun_setup;
417 417
418 if (dev->has_tuner) { 418 if (dev->has_tuner) {
@@ -420,7 +420,7 @@ static int em2820_set_tuner(int check_eeprom, struct i2c_client *client)
420 tun_setup.type = dev->tuner_type; 420 tun_setup.type = dev->tuner_type;
421 tun_setup.addr = dev->tuner_addr; 421 tun_setup.addr = dev->tuner_addr;
422 422
423 em2820_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 423 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
424 } 424 }
425 425
426 return (0); 426 return (0);
@@ -433,11 +433,11 @@ static int em2820_set_tuner(int check_eeprom, struct i2c_client *client)
433 */ 433 */
434static int attach_inform(struct i2c_client *client) 434static int attach_inform(struct i2c_client *client)
435{ 435{
436 struct em2820 *dev = client->adapter->algo_data; 436 struct em28xx *dev = client->adapter->algo_data;
437 437
438 switch (client->addr << 1) { 438 switch (client->addr << 1) {
439 case 0x86: 439 case 0x86:
440 em2820_i2c_call_clients(dev, TDA9887_SET_CONFIG, &dev->tda9887_conf); 440 em28xx_i2c_call_clients(dev, TDA9887_SET_CONFIG, &dev->tda9887_conf);
441 break; 441 break;
442 case 0x42: 442 case 0x42:
443 dprintk1(1,"attach_inform: saa7114 detected.\n"); 443 dprintk1(1,"attach_inform: saa7114 detected.\n");
@@ -453,7 +453,7 @@ static int attach_inform(struct i2c_client *client)
453 { 453 {
454 struct IR_i2c *ir = i2c_get_clientdata(client); 454 struct IR_i2c *ir = i2c_get_clientdata(client);
455 dprintk1(1,"attach_inform: IR detected (%s).\n",ir->phys); 455 dprintk1(1,"attach_inform: IR detected (%s).\n",ir->phys);
456 em2820_set_ir(dev,ir); 456 em28xx_set_ir(dev,ir);
457 break; 457 break;
458 } 458 }
459 case 0x80: 459 case 0x80:
@@ -467,19 +467,19 @@ static int attach_inform(struct i2c_client *client)
467 default: 467 default:
468 dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1); 468 dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1);
469 dev->tuner_addr = client->addr; 469 dev->tuner_addr = client->addr;
470 em2820_set_tuner(-1, client); 470 em28xx_set_tuner(-1, client);
471 } 471 }
472 472
473 return 0; 473 return 0;
474} 474}
475 475
476static struct i2c_algorithm em2820_algo = { 476static struct i2c_algorithm em28xx_algo = {
477 .master_xfer = em2820_i2c_xfer, 477 .master_xfer = em28xx_i2c_xfer,
478 .algo_control = algo_control, 478 .algo_control = algo_control,
479 .functionality = functionality, 479 .functionality = functionality,
480}; 480};
481 481
482static struct i2c_adapter em2820_adap_template = { 482static struct i2c_adapter em28xx_adap_template = {
483#ifdef I2C_PEC 483#ifdef I2C_PEC
484 .owner = THIS_MODULE, 484 .owner = THIS_MODULE,
485#else 485#else
@@ -489,14 +489,14 @@ static struct i2c_adapter em2820_adap_template = {
489#ifdef I2C_CLASS_TV_ANALOG 489#ifdef I2C_CLASS_TV_ANALOG
490 .class = I2C_CLASS_TV_ANALOG, 490 .class = I2C_CLASS_TV_ANALOG,
491#endif 491#endif
492 .name = "em2820", 492 .name = "em28xx",
493 .id = I2C_HW_B_EM2820, 493 .id = I2C_HW_B_EM28XX,
494 .algo = &em2820_algo, 494 .algo = &em28xx_algo,
495 .client_register = attach_inform, 495 .client_register = attach_inform,
496}; 496};
497 497
498static struct i2c_client em2820_client_template = { 498static struct i2c_client em28xx_client_template = {
499 .name = "em2820 internal", 499 .name = "em28xx internal",
500 .flags = I2C_CLIENT_ALLOW_USE, 500 .flags = I2C_CLIENT_ALLOW_USE,
501}; 501};
502 502
@@ -542,33 +542,33 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
542} 542}
543 543
544/* 544/*
545 * em2820_i2c_call_clients() 545 * em28xx_i2c_call_clients()
546 * send commands to all attached i2c devices 546 * send commands to all attached i2c devices
547 */ 547 */
548void em2820_i2c_call_clients(struct em2820 *dev, unsigned int cmd, void *arg) 548void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
549{ 549{
550 BUG_ON(NULL == dev->i2c_adap.algo_data); 550 BUG_ON(NULL == dev->i2c_adap.algo_data);
551 i2c_clients_command(&dev->i2c_adap, cmd, arg); 551 i2c_clients_command(&dev->i2c_adap, cmd, arg);
552} 552}
553 553
554/* 554/*
555 * em2820_i2c_register() 555 * em28xx_i2c_register()
556 * register i2c bus 556 * register i2c bus
557 */ 557 */
558int em2820_i2c_register(struct em2820 *dev) 558int em28xx_i2c_register(struct em28xx *dev)
559{ 559{
560 BUG_ON(!dev->em2820_write_regs || !dev->em2820_read_reg); 560 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
561 BUG_ON(!dev->em2820_write_regs_req || !dev->em2820_read_reg_req); 561 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
562 dev->i2c_adap = em2820_adap_template; 562 dev->i2c_adap = em28xx_adap_template;
563 dev->i2c_adap.dev.parent = &dev->udev->dev; 563 dev->i2c_adap.dev.parent = &dev->udev->dev;
564 strcpy(dev->i2c_adap.name, dev->name); 564 strcpy(dev->i2c_adap.name, dev->name);
565 dev->i2c_adap.algo_data = dev; 565 dev->i2c_adap.algo_data = dev;
566 i2c_add_adapter(&dev->i2c_adap); 566 i2c_add_adapter(&dev->i2c_adap);
567 567
568 dev->i2c_client = em2820_client_template; 568 dev->i2c_client = em28xx_client_template;
569 dev->i2c_client.adapter = &dev->i2c_adap; 569 dev->i2c_client.adapter = &dev->i2c_adap;
570 570
571 em2820_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 571 em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
572 572
573 if (i2c_scan) 573 if (i2c_scan)
574 do_i2c_scan(dev->name, &dev->i2c_client); 574 do_i2c_scan(dev->name, &dev->i2c_client);
@@ -576,10 +576,10 @@ int em2820_i2c_register(struct em2820 *dev)
576} 576}
577 577
578/* 578/*
579 * em2820_i2c_unregister() 579 * em28xx_i2c_unregister()
580 * unregister i2c_bus 580 * unregister i2c_bus
581 */ 581 */
582int em2820_i2c_unregister(struct em2820 *dev) 582int em28xx_i2c_unregister(struct em28xx *dev)
583{ 583{
584 i2c_del_adapter(&dev->i2c_adap); 584 i2c_del_adapter(&dev->i2c_adap);
585 return 0; 585 return 0;