blob: dca0592c5f47157bae6d1b85a751bb51f7aee6fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * device driver for philips saa7134 based TV cards
4 * i2c interface support
5 *
6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
Mauro Carvalho Chehab9a12ccf2015-04-30 06:44:56 -030023#include "saa7134.h"
24#include "saa7134-reg.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/list.h>
28#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/delay.h>
31
Michael Krufky5e453dc2006-01-09 15:32:31 -020032#include <media/v4l2-common.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/* ----------------------------------------------------------- */
35
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030036static unsigned int i2c_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037module_param(i2c_debug, int, 0644);
38MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]");
39
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030040static unsigned int i2c_scan;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041module_param(i2c_scan, int, 0444);
42MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
43
Mauro Carvalho Chehab45f38cb2015-05-13 14:09:25 -030044#define i2c_dbg(level, fmt, arg...) do { \
45 if (i2c_debug == level) \
46 printk(KERN_DEBUG pr_fmt("i2c: " fmt), ## arg); \
47 } while (0)
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -030048
Mauro Carvalho Chehab45f38cb2015-05-13 14:09:25 -030049#define i2c_cont(level, fmt, arg...) do { \
50 if (i2c_debug == level) \
51 pr_cont(fmt, ## arg); \
52 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#define I2C_WAIT_DELAY 32
55#define I2C_WAIT_RETRY 16
56
57/* ----------------------------------------------------------- */
58
59static char *str_i2c_status[] = {
60 "IDLE", "DONE_STOP", "BUSY", "TO_SCL", "TO_ARB", "DONE_WRITE",
61 "DONE_READ", "DONE_WRITE_TO", "DONE_READ_TO", "NO_DEVICE",
62 "NO_ACKN", "BUS_ERR", "ARB_LOST", "SEQ_ERR", "ST_ERR", "SW_ERR"
63};
64
65enum i2c_status {
66 IDLE = 0, // no I2C command pending
67 DONE_STOP = 1, // I2C command done and STOP executed
68 BUSY = 2, // executing I2C command
69 TO_SCL = 3, // executing I2C command, time out on clock stretching
70 TO_ARB = 4, // time out on arbitration trial, still trying
71 DONE_WRITE = 5, // I2C command done and awaiting next write command
72 DONE_READ = 6, // I2C command done and awaiting next read command
73 DONE_WRITE_TO = 7, // see 5, and time out on status echo
74 DONE_READ_TO = 8, // see 6, and time out on status echo
75 NO_DEVICE = 9, // no acknowledge on device slave address
76 NO_ACKN = 10, // no acknowledge after data byte transfer
77 BUS_ERR = 11, // bus error
78 ARB_LOST = 12, // arbitration lost during transfer
79 SEQ_ERR = 13, // erroneous programming sequence
80 ST_ERR = 14, // wrong status echoing
81 SW_ERR = 15 // software error
82};
83
84static char *str_i2c_attr[] = {
85 "NOP", "STOP", "CONTINUE", "START"
86};
87
88enum i2c_attr {
89 NOP = 0, // no operation on I2C bus
90 STOP = 1, // stop condition, no associated byte transfer
91 CONTINUE = 2, // continue with byte transfer
92 START = 3 // start condition with byte transfer
93};
94
95static inline enum i2c_status i2c_get_status(struct saa7134_dev *dev)
96{
97 enum i2c_status status;
98
99 status = saa_readb(SAA7134_I2C_ATTR_STATUS) & 0x0f;
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300100 i2c_dbg(2, "i2c stat <= %s\n", str_i2c_status[status]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return status;
102}
103
104static inline void i2c_set_status(struct saa7134_dev *dev,
105 enum i2c_status status)
106{
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300107 i2c_dbg(2, "i2c stat => %s\n", str_i2c_status[status]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 saa_andorb(SAA7134_I2C_ATTR_STATUS,0x0f,status);
109}
110
111static inline void i2c_set_attr(struct saa7134_dev *dev, enum i2c_attr attr)
112{
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300113 i2c_dbg(2, "i2c attr => %s\n", str_i2c_attr[attr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 saa_andorb(SAA7134_I2C_ATTR_STATUS,0xc0,attr << 6);
115}
116
117static inline int i2c_is_error(enum i2c_status status)
118{
119 switch (status) {
120 case NO_DEVICE:
121 case NO_ACKN:
122 case BUS_ERR:
123 case ARB_LOST:
124 case SEQ_ERR:
125 case ST_ERR:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300126 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 default:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300128 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130}
131
132static inline int i2c_is_idle(enum i2c_status status)
133{
134 switch (status) {
135 case IDLE:
136 case DONE_STOP:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300137 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 default:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300139 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141}
142
143static inline int i2c_is_busy(enum i2c_status status)
144{
145 switch (status) {
146 case BUSY:
Dmitry Belimov8fb737b2008-04-23 14:07:09 -0300147 case TO_SCL:
148 case TO_ARB:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300149 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 default:
Richard Knutssone8be02a2007-02-06 21:52:04 -0300151 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153}
154
155static int i2c_is_busy_wait(struct saa7134_dev *dev)
156{
157 enum i2c_status status;
158 int count;
159
160 for (count = 0; count < I2C_WAIT_RETRY; count++) {
161 status = i2c_get_status(dev);
162 if (!i2c_is_busy(status))
163 break;
164 saa_wait(I2C_WAIT_DELAY);
165 }
166 if (I2C_WAIT_RETRY == count)
Richard Knutssone8be02a2007-02-06 21:52:04 -0300167 return false;
168 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
171static int i2c_reset(struct saa7134_dev *dev)
172{
173 enum i2c_status status;
174 int count;
175
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300176 i2c_dbg(2, "i2c reset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 status = i2c_get_status(dev);
178 if (!i2c_is_error(status))
Richard Knutssone8be02a2007-02-06 21:52:04 -0300179 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 i2c_set_status(dev,status);
181
182 for (count = 0; count < I2C_WAIT_RETRY; count++) {
183 status = i2c_get_status(dev);
184 if (!i2c_is_error(status))
185 break;
186 udelay(I2C_WAIT_DELAY);
187 }
188 if (I2C_WAIT_RETRY == count)
Richard Knutssone8be02a2007-02-06 21:52:04 -0300189 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 if (!i2c_is_idle(status))
Richard Knutssone8be02a2007-02-06 21:52:04 -0300192 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 i2c_set_attr(dev,NOP);
Richard Knutssone8be02a2007-02-06 21:52:04 -0300195 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
198static inline int i2c_send_byte(struct saa7134_dev *dev,
199 enum i2c_attr attr,
200 unsigned char data)
201{
202 enum i2c_status status;
203 __u32 dword;
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 /* have to write both attr + data in one 32bit word */
206 dword = saa_readl(SAA7134_I2C_ATTR_STATUS >> 2);
207 dword &= 0x0f;
208 dword |= (attr << 6);
209 dword |= ((__u32)data << 8);
210 dword |= 0x00 << 16; /* 100 kHz */
211// dword |= 0x40 << 16; /* 400 kHz */
212 dword |= 0xf0 << 24;
213 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword);
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300214 i2c_dbg(2, "i2c data => 0x%x\n", data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 if (!i2c_is_busy_wait(dev))
217 return -EIO;
218 status = i2c_get_status(dev);
219 if (i2c_is_error(status))
220 return -EIO;
221 return 0;
222}
223
224static inline int i2c_recv_byte(struct saa7134_dev *dev)
225{
226 enum i2c_status status;
227 unsigned char data;
228
229 i2c_set_attr(dev,CONTINUE);
230 if (!i2c_is_busy_wait(dev))
231 return -EIO;
232 status = i2c_get_status(dev);
233 if (i2c_is_error(status))
234 return -EIO;
235 data = saa_readb(SAA7134_I2C_DATA);
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300236 i2c_dbg(2, "i2c data <= 0x%x\n", data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return data;
238}
239
240static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
241 struct i2c_msg *msgs, int num)
242{
243 struct saa7134_dev *dev = i2c_adap->algo_data;
244 enum i2c_status status;
245 unsigned char data;
246 int addr,rc,i,byte;
247
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800248 status = i2c_get_status(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!i2c_is_idle(status))
250 if (!i2c_reset(dev))
251 return -EIO;
252
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300253 i2c_dbg(2, "start xfer\n");
254 i2c_dbg(1, "i2c xfer:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 for (i = 0; i < num; i++) {
256 if (!(msgs[i].flags & I2C_M_NOSTART) || 0 == i) {
257 /* send address */
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300258 i2c_dbg(2, "send address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 addr = msgs[i].addr << 1;
260 if (msgs[i].flags & I2C_M_RD)
261 addr |= 1;
Kyle Strickland25fa2072012-02-18 02:24:53 -0300262 if (i > 0 && msgs[i].flags &
263 I2C_M_RD && msgs[i].addr != 0x40 &&
Ondrej Zary34fe2782013-04-06 14:28:16 -0300264 msgs[i].addr != 0x41 &&
Kyle Strickland25fa2072012-02-18 02:24:53 -0300265 msgs[i].addr != 0x19) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 /* workaround for a saa7134 i2c bug
267 * needed to talk to the mt352 demux
268 * thanks to pinnacle for the hint */
Michael Krufkyb9dcdb62009-05-20 16:06:10 -0300269 int quirk = 0xfe;
Mauro Carvalho Chehab6139ebc2015-05-13 14:09:42 -0300270 i2c_cont(1, " [%02x quirk]", quirk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 i2c_send_byte(dev,START,quirk);
272 i2c_recv_byte(dev);
273 }
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300274 i2c_cont(1, " < %02x", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 rc = i2c_send_byte(dev,START,addr);
276 if (rc < 0)
277 goto err;
278 }
279 if (msgs[i].flags & I2C_M_RD) {
280 /* read bytes */
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300281 i2c_dbg(2, "read bytes\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 for (byte = 0; byte < msgs[i].len; byte++) {
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300283 i2c_cont(1, " =");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 rc = i2c_recv_byte(dev);
285 if (rc < 0)
286 goto err;
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300287 i2c_cont(1, "%02x", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 msgs[i].buf[byte] = rc;
289 }
Kyle Strickland25fa2072012-02-18 02:24:53 -0300290 /* discard mysterious extra byte when reading
291 from Samsung S5H1411. i2c bus gets error
292 if we do not. */
293 if (0x19 == msgs[i].addr) {
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300294 i2c_cont(1, " ?");
Kyle Strickland25fa2072012-02-18 02:24:53 -0300295 rc = i2c_recv_byte(dev);
296 if (rc < 0)
297 goto err;
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300298 i2c_cont(1, "%02x", rc);
Kyle Strickland25fa2072012-02-18 02:24:53 -0300299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 } else {
301 /* write bytes */
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300302 i2c_dbg(2, "write bytes\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 for (byte = 0; byte < msgs[i].len; byte++) {
304 data = msgs[i].buf[byte];
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300305 i2c_cont(1, " %02x", data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 rc = i2c_send_byte(dev,CONTINUE,data);
307 if (rc < 0)
308 goto err;
309 }
310 }
311 }
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300312 i2c_dbg(2, "xfer done\n");
313 i2c_cont(1, " >");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 i2c_set_attr(dev,STOP);
315 rc = -EIO;
316 if (!i2c_is_busy_wait(dev))
317 goto err;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800318 status = i2c_get_status(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (i2c_is_error(status))
320 goto err;
Mauro Carvalho Chehabfd3113e2005-07-31 22:34:43 -0700321 /* ensure that the bus is idle for at least one bit slot */
322 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300324 i2c_cont(1, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return num;
326 err:
327 if (1 == i2c_debug) {
328 status = i2c_get_status(dev);
Mauro Carvalho Chehab30693f32015-04-30 08:21:14 -0300329 i2c_cont(1, " ERROR: %s\n", str_i2c_status[status]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
331 return rc;
332}
333
334/* ----------------------------------------------------------- */
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336static u32 functionality(struct i2c_adapter *adap)
337{
338 return I2C_FUNC_SMBUS_EMUL;
339}
340
Julia Lawall78f2c502016-08-29 10:12:01 -0300341static const struct i2c_algorithm saa7134_algo = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 .master_xfer = saa7134_i2c_xfer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 .functionality = functionality,
344};
345
346static struct i2c_adapter saa7134_adap_template = {
347 .owner = THIS_MODULE,
Jean Delvarefae91e72005-08-15 19:57:04 +0200348 .name = "saa7134",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .algo = &saa7134_algo,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350};
351
352static struct i2c_client saa7134_client_template = {
Jean Delvarefae91e72005-08-15 19:57:04 +0200353 .name = "saa7134 internal",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
356/* ----------------------------------------------------------- */
357
Maciej S. Szmigierofb2dc282016-07-02 20:27:46 -0300358/* On Medion 7134 reading EEPROM needs DVB-T demod i2c gate open */
359static void saa7134_i2c_eeprom_md7134_gate(struct saa7134_dev *dev)
360{
361 u8 subaddr = 0x7, dmdregval;
362 u8 data[2];
363 int ret;
364 struct i2c_msg i2cgatemsg_r[] = { {.addr = 0x08, .flags = 0,
365 .buf = &subaddr, .len = 1},
366 {.addr = 0x08,
367 .flags = I2C_M_RD,
368 .buf = &dmdregval, .len = 1}
369 };
370 struct i2c_msg i2cgatemsg_w[] = { {.addr = 0x08, .flags = 0,
371 .buf = data, .len = 2} };
372
373 ret = i2c_transfer(&dev->i2c_adap, i2cgatemsg_r, 2);
374 if ((ret == 2) && (dmdregval & 0x2)) {
375 pr_debug("%s: DVB-T demod i2c gate was left closed\n",
376 dev->name);
377
378 data[0] = subaddr;
379 data[1] = (dmdregval & ~0x2);
380 if (i2c_transfer(&dev->i2c_adap, i2cgatemsg_w, 1) != 1)
381 pr_err("%s: EEPROM i2c gate open failure\n",
382 dev->name);
383 }
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386static int
387saa7134_i2c_eeprom(struct saa7134_dev *dev, unsigned char *eedata, int len)
388{
389 unsigned char buf;
390 int i,err;
391
Maciej S. Szmigierofb2dc282016-07-02 20:27:46 -0300392 if (dev->board == SAA7134_BOARD_MD7134)
393 saa7134_i2c_eeprom_md7134_gate(dev);
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 dev->i2c_client.addr = 0xa0 >> 1;
396 buf = 0;
397 if (1 != (err = i2c_master_send(&dev->i2c_client,&buf,1))) {
Mauro Carvalho Chehab83582002015-04-30 06:46:34 -0300398 pr_info("%s: Huh, no eeprom present (err=%d)?\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 dev->name,err);
400 return -1;
401 }
402 if (len != (err = i2c_master_recv(&dev->i2c_client,eedata,len))) {
Mauro Carvalho Chehab83582002015-04-30 06:46:34 -0300403 pr_warn("%s: i2c eeprom read error (err=%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 dev->name,err);
405 return -1;
406 }
Mauro Carvalho Chehab3e0051c2015-04-30 09:15:08 -0300407
Mauro Carvalho Chehab6139ebc2015-05-13 14:09:42 -0300408 for (i = 0; i < len; i += 16) {
Mauro Carvalho Chehab3e0051c2015-04-30 09:15:08 -0300409 int size = (len - i) > 16 ? 16 : len - i;
Mauro Carvalho Chehab6139ebc2015-05-13 14:09:42 -0300410
Mauro Carvalho Chehab3e0051c2015-04-30 09:15:08 -0300411 pr_info("i2c eeprom %02x: %*ph\n", i, size, &eedata[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
Mauro Carvalho Chehab3e0051c2015-04-30 09:15:08 -0300413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 return 0;
415}
416
417static char *i2c_devs[128] = {
418 [ 0x20 ] = "mpeg encoder (saa6752hs)",
419 [ 0xa0 >> 1 ] = "eeprom",
420 [ 0xc0 >> 1 ] = "tuner (analog)",
421 [ 0x86 >> 1 ] = "tda9887",
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300422 [ 0x5a >> 1 ] = "remote control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423};
424
Mauro Carvalho Chehab2bb3e2e2015-04-30 09:17:34 -0300425static void do_i2c_scan(struct i2c_client *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
427 unsigned char buf;
428 int i,rc;
429
Mauro Carvalho Chehab53c4e952007-03-29 08:42:30 -0300430 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 c->addr = i;
432 rc = i2c_master_recv(c,&buf,0);
433 if (rc < 0)
434 continue;
Mauro Carvalho Chehab2bb3e2e2015-04-30 09:17:34 -0300435 pr_info("i2c scan: found device @ 0x%x [%s]\n",
436 i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438}
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440int saa7134_i2c_register(struct saa7134_dev *dev)
441{
442 dev->i2c_adap = saa7134_adap_template;
443 dev->i2c_adap.dev.parent = &dev->pci->dev;
444 strcpy(dev->i2c_adap.name,dev->name);
445 dev->i2c_adap.algo_data = dev;
Hans Verkuilfac69862009-01-17 12:17:14 -0300446 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 i2c_add_adapter(&dev->i2c_adap);
448
449 dev->i2c_client = saa7134_client_template;
450 dev->i2c_client.adapter = &dev->i2c_adap;
451
452 saa7134_i2c_eeprom(dev,dev->eedata,sizeof(dev->eedata));
453 if (i2c_scan)
Mauro Carvalho Chehab2bb3e2e2015-04-30 09:17:34 -0300454 do_i2c_scan(&dev->i2c_client);
Jean Delvarec668f322009-05-13 16:48:50 -0300455
456 /* Instantiate the IR receiver device, if present */
457 saa7134_probe_i2c_ir(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
459}
460
461int saa7134_i2c_unregister(struct saa7134_dev *dev)
462{
463 i2c_del_adapter(&dev->i2c_adap);
464 return 0;
465}