Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 1 | /* |
Ruslan Pisarev | d005864 | 2010-10-20 06:35:54 -0300 | [diff] [blame] | 2 | * tm6000-i2c.c - driver for TM5600/TM6000/TM6010 USB video capture devices |
| 3 | * |
| 4 | * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org> |
| 5 | * |
| 6 | * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com> |
| 7 | * - Fix SMBus Read Byte command |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation version 2 |
| 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. |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/usb.h> |
| 26 | #include <linux/i2c.h> |
| 27 | |
| 28 | #include "tm6000.h" |
| 29 | #include "tm6000-regs.h" |
| 30 | #include <media/v4l2-common.h> |
| 31 | #include <media/tuner.h> |
| 32 | #include "tuner-xc2028.h" |
| 33 | |
| 34 | |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 35 | /* ----------------------------------------------------------- */ |
| 36 | |
Ruslan Pisarev | d7fe4a6 | 2010-10-20 06:34:40 -0300 | [diff] [blame] | 37 | static unsigned int i2c_debug; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 38 | module_param(i2c_debug, int, 0644); |
| 39 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); |
| 40 | |
Timofey Trofimov | 52e0a72 | 2010-05-29 13:52:46 -0300 | [diff] [blame] | 41 | #define i2c_dprintk(lvl, fmt, args...) if (i2c_debug >= lvl) do { \ |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 42 | printk(KERN_DEBUG "%s at %s: " fmt, \ |
Curtis McEnroe | 0f063c6 | 2011-06-02 20:33:32 -0400 | [diff] [blame] | 43 | dev->name, __func__, ##args); } while (0) |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 44 | |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 45 | static int tm6000_i2c_send_regs(struct tm6000_core *dev, unsigned char addr, |
| 46 | __u8 reg, char *buf, int len) |
| 47 | { |
Dmitri Belimov | 20dead8 | 2010-04-27 22:32:43 -0300 | [diff] [blame] | 48 | int rc; |
| 49 | unsigned int tsleep; |
| 50 | unsigned int i2c_packet_limit = 16; |
| 51 | |
| 52 | if (dev->dev_type == TM6010) |
| 53 | i2c_packet_limit = 64; |
| 54 | |
| 55 | if (!buf) |
| 56 | return -1; |
| 57 | |
| 58 | if (len < 1 || len > i2c_packet_limit) { |
| 59 | printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n", |
| 60 | len, i2c_packet_limit); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | /* capture mutex */ |
| 65 | rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | |
| 66 | USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, |
| 67 | addr | reg << 8, 0, buf, len); |
| 68 | |
| 69 | if (rc < 0) { |
| 70 | /* release mutex */ |
| 71 | return rc; |
| 72 | } |
| 73 | |
| 74 | /* Calculate delay time, 14000us for 64 bytes */ |
| 75 | tsleep = ((len * 200) + 200 + 1000) / 1000; |
| 76 | msleep(tsleep); |
| 77 | |
| 78 | /* release mutex */ |
| 79 | return rc; |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Generic read - doesn't work fine with 16bit registers */ |
| 83 | static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr, |
| 84 | __u8 reg, char *buf, int len) |
| 85 | { |
| 86 | int rc; |
Stefan Ringel | 02512fe | 2010-02-22 14:35:06 -0300 | [diff] [blame] | 87 | u8 b[2]; |
Dmitri Belimov | 20dead8 | 2010-04-27 22:32:43 -0300 | [diff] [blame] | 88 | unsigned int i2c_packet_limit = 16; |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 89 | |
Dmitri Belimov | 20dead8 | 2010-04-27 22:32:43 -0300 | [diff] [blame] | 90 | if (dev->dev_type == TM6010) |
| 91 | i2c_packet_limit = 64; |
| 92 | |
| 93 | if (!buf) |
| 94 | return -1; |
| 95 | |
| 96 | if (len < 1 || len > i2c_packet_limit) { |
| 97 | printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n", |
| 98 | len, i2c_packet_limit); |
| 99 | return -1; |
| 100 | } |
| 101 | |
| 102 | /* capture mutex */ |
Stefan Ringel | 02512fe | 2010-02-22 14:35:06 -0300 | [diff] [blame] | 103 | if ((dev->caps.has_zl10353) && (dev->demod_addr << 1 == addr) && (reg % 2 == 0)) { |
| 104 | /* |
| 105 | * Workaround an I2C bug when reading from zl10353 |
| 106 | */ |
| 107 | reg -= 1; |
| 108 | len += 1; |
| 109 | |
| 110 | rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 111 | REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, b, len); |
| 112 | |
| 113 | *buf = b[1]; |
| 114 | } else { |
| 115 | rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 116 | REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); |
Stefan Ringel | 02512fe | 2010-02-22 14:35:06 -0300 | [diff] [blame] | 117 | } |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 118 | |
Dmitri Belimov | 20dead8 | 2010-04-27 22:32:43 -0300 | [diff] [blame] | 119 | /* release mutex */ |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 120 | return rc; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * read from a 16bit register |
| 125 | * for example xc2028, xc3028 or xc3028L |
| 126 | */ |
| 127 | static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr, |
| 128 | __u16 reg, char *buf, int len) |
| 129 | { |
Dmitri Belimov | 20dead8 | 2010-04-27 22:32:43 -0300 | [diff] [blame] | 130 | int rc; |
| 131 | unsigned char ureg; |
| 132 | |
| 133 | if (!buf || len != 2) |
| 134 | return -1; |
| 135 | |
| 136 | /* capture mutex */ |
| 137 | if (dev->dev_type == TM6010) { |
| 138 | ureg = reg & 0xFF; |
| 139 | rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | |
| 140 | USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, |
| 141 | addr | (reg & 0xFF00), 0, &ureg, 1); |
| 142 | |
| 143 | if (rc < 0) { |
| 144 | /* release mutex */ |
| 145 | return rc; |
| 146 | } |
| 147 | |
| 148 | msleep(1400 / 1000); |
| 149 | rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | |
| 150 | USB_RECIP_DEVICE, REQ_35_AFTEK_TUNER_READ, |
| 151 | reg, 0, buf, len); |
| 152 | } else { |
| 153 | rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | |
| 154 | USB_RECIP_DEVICE, REQ_14_SET_GET_I2C_WR2_RDN, |
| 155 | addr, reg, buf, len); |
| 156 | } |
| 157 | |
| 158 | /* release mutex */ |
| 159 | return rc; |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 160 | } |
| 161 | |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 162 | static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, |
| 163 | struct i2c_msg msgs[], int num) |
| 164 | { |
| 165 | struct tm6000_core *dev = i2c_adap->algo_data; |
| 166 | int addr, rc, i, byte; |
| 167 | |
| 168 | if (num <= 0) |
| 169 | return 0; |
| 170 | for (i = 0; i < num; i++) { |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 171 | addr = (msgs[i].addr << 1) & 0xff; |
Timofey Trofimov | 52e0a72 | 2010-05-29 13:52:46 -0300 | [diff] [blame] | 172 | i2c_dprintk(2, "%s %s addr=0x%x len=%d:", |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 173 | (msgs[i].flags & I2C_M_RD) ? "read" : "write", |
| 174 | i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); |
Mauro Carvalho Chehab | 427f7fa | 2009-09-14 16:37:13 -0300 | [diff] [blame] | 175 | if (msgs[i].flags & I2C_M_RD) { |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 176 | /* read request without preceding register selection */ |
| 177 | /* |
| 178 | * The TM6000 only supports a read transaction |
| 179 | * immediately after a 1 or 2 byte write to select |
| 180 | * a register. We cannot fulfil this request. |
| 181 | */ |
| 182 | i2c_dprintk(2, " read without preceding write not" |
| 183 | " supported"); |
| 184 | rc = -EOPNOTSUPP; |
| 185 | goto err; |
| 186 | } else if (i + 1 < num && msgs[i].len <= 2 && |
| 187 | (msgs[i + 1].flags & I2C_M_RD) && |
| 188 | msgs[i].addr == msgs[i + 1].addr) { |
| 189 | /* 1 or 2 byte write followed by a read */ |
| 190 | if (i2c_debug >= 2) |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 191 | for (byte = 0; byte < msgs[i].len; byte++) |
| 192 | printk(" %02x", msgs[i].buf[byte]); |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 193 | i2c_dprintk(2, "; joined to read %s len=%d:", |
| 194 | i == num - 2 ? "stop" : "nonstop", |
| 195 | msgs[i + 1].len); |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 196 | |
| 197 | if (msgs[i].len == 2) { |
| 198 | rc = tm6000_i2c_recv_regs16(dev, addr, |
| 199 | msgs[i].buf[0] << 8 | msgs[i].buf[1], |
| 200 | msgs[i + 1].buf, msgs[i + 1].len); |
| 201 | } else { |
| 202 | rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0], |
| 203 | msgs[i + 1].buf, msgs[i + 1].len); |
| 204 | } |
| 205 | |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 206 | i++; |
Stefan Ringel | 20cabed | 2010-02-05 19:57:04 -0300 | [diff] [blame] | 207 | |
Stefan Ringel | 685b122 | 2010-02-21 17:10:36 -0300 | [diff] [blame] | 208 | if (addr == dev->tuner_addr << 1) { |
Stefan Ringel | f1434f4 | 2010-04-02 13:52:50 -0300 | [diff] [blame] | 209 | tm6000_set_reg(dev, REQ_50_SET_START, 0, 0); |
| 210 | tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0); |
Stefan Ringel | 20cabed | 2010-02-05 19:57:04 -0300 | [diff] [blame] | 211 | } |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 212 | if (i2c_debug >= 2) |
| 213 | for (byte = 0; byte < msgs[i].len; byte++) |
| 214 | printk(" %02x", msgs[i].buf[byte]); |
| 215 | } else { |
| 216 | /* write bytes */ |
| 217 | if (i2c_debug >= 2) |
| 218 | for (byte = 0; byte < msgs[i].len; byte++) |
| 219 | printk(" %02x", msgs[i].buf[byte]); |
Stefan Ringel | 4e11502 | 2010-02-22 14:35:05 -0300 | [diff] [blame] | 220 | rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0], |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 221 | msgs[i].buf + 1, msgs[i].len - 1); |
Stefan Ringel | 20cabed | 2010-02-05 19:57:04 -0300 | [diff] [blame] | 222 | |
Stefan Ringel | 685b122 | 2010-02-21 17:10:36 -0300 | [diff] [blame] | 223 | if (addr == dev->tuner_addr << 1) { |
Stefan Ringel | f1434f4 | 2010-04-02 13:52:50 -0300 | [diff] [blame] | 224 | tm6000_set_reg(dev, REQ_50_SET_START, 0, 0); |
| 225 | tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0); |
Stefan Ringel | 20cabed | 2010-02-05 19:57:04 -0300 | [diff] [blame] | 226 | } |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 227 | } |
Chris Pascoe | e30b9d6 | 2007-11-24 04:34:42 -0300 | [diff] [blame] | 228 | if (i2c_debug >= 2) |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 229 | printk("\n"); |
| 230 | if (rc < 0) |
| 231 | goto err; |
| 232 | } |
| 233 | |
| 234 | return num; |
| 235 | err: |
Timofey Trofimov | 52e0a72 | 2010-05-29 13:52:46 -0300 | [diff] [blame] | 236 | i2c_dprintk(2, " ERROR: %i\n", rc); |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 237 | return rc; |
| 238 | } |
| 239 | |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 240 | static int tm6000_i2c_eeprom(struct tm6000_core *dev) |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 241 | { |
| 242 | int i, rc; |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 243 | unsigned char *p = dev->eedata; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 244 | unsigned char bytes[17]; |
| 245 | |
| 246 | dev->i2c_client.addr = 0xa0 >> 1; |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 247 | dev->eedata_size = 0; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 248 | |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 249 | bytes[16] = '\0'; |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 250 | for (i = 0; i < sizeof(dev->eedata); ) { |
| 251 | *p = i; |
| 252 | rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1); |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 253 | if (rc < 1) { |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 254 | if (p == dev->eedata) |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 255 | goto noeeprom; |
| 256 | else { |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 257 | printk(KERN_WARNING |
| 258 | "%s: i2c eeprom read error (err=%d)\n", |
| 259 | dev->name, rc); |
| 260 | } |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 261 | return -EINVAL; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 262 | } |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 263 | dev->eedata_size++; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 264 | p++; |
| 265 | if (0 == (i % 16)) |
| 266 | printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i); |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 267 | printk(" %02x", dev->eedata[i]); |
| 268 | if ((dev->eedata[i] >= ' ') && (dev->eedata[i] <= 'z')) |
| 269 | bytes[i%16] = dev->eedata[i]; |
Timofey Trofimov | 52e0a72 | 2010-05-29 13:52:46 -0300 | [diff] [blame] | 270 | else |
| 271 | bytes[i%16] = '.'; |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 272 | |
| 273 | i++; |
| 274 | |
| 275 | if (0 == (i % 16)) { |
| 276 | bytes[16] = '\0'; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 277 | printk(" %s\n", bytes); |
| 278 | } |
| 279 | } |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 280 | if (0 != (i%16)) { |
| 281 | bytes[i%16] = '\0'; |
| 282 | for (i %= 16; i < 16; i++) |
| 283 | printk(" "); |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 284 | printk(" %s\n", bytes); |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 285 | } |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 286 | |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 287 | return 0; |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 288 | |
| 289 | noeeprom: |
| 290 | printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 291 | dev->name, rc); |
| 292 | return -EINVAL; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* ----------------------------------------------------------- */ |
| 296 | |
| 297 | /* |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 298 | * functionality() |
| 299 | */ |
| 300 | static u32 functionality(struct i2c_adapter *adap) |
| 301 | { |
| 302 | return I2C_FUNC_SMBUS_EMUL; |
| 303 | } |
| 304 | |
Jean Delvare | 7bd444e | 2010-11-07 12:53:44 -0300 | [diff] [blame] | 305 | static const struct i2c_algorithm tm6000_algo = { |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 306 | .master_xfer = tm6000_i2c_xfer, |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 307 | .functionality = functionality, |
| 308 | }; |
| 309 | |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 310 | /* ----------------------------------------------------------- */ |
| 311 | |
| 312 | /* |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 313 | * tm6000_i2c_register() |
| 314 | * register i2c bus |
| 315 | */ |
| 316 | int tm6000_i2c_register(struct tm6000_core *dev) |
| 317 | { |
Jean Delvare | 7bd444e | 2010-11-07 12:53:44 -0300 | [diff] [blame] | 318 | int rc; |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 319 | |
Jean Delvare | 7bd444e | 2010-11-07 12:53:44 -0300 | [diff] [blame] | 320 | dev->i2c_adap.owner = THIS_MODULE; |
| 321 | dev->i2c_adap.algo = &tm6000_algo; |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 322 | dev->i2c_adap.dev.parent = &dev->udev->dev; |
Jean Delvare | 7bd444e | 2010-11-07 12:53:44 -0300 | [diff] [blame] | 323 | strlcpy(dev->i2c_adap.name, dev->name, sizeof(dev->i2c_adap.name)); |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 324 | dev->i2c_adap.algo_data = dev; |
Mauro Carvalho Chehab | 427f7fa | 2009-09-14 16:37:13 -0300 | [diff] [blame] | 325 | i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); |
Jean Delvare | 7bd444e | 2010-11-07 12:53:44 -0300 | [diff] [blame] | 326 | rc = i2c_add_adapter(&dev->i2c_adap); |
| 327 | if (rc) |
| 328 | return rc; |
| 329 | |
| 330 | dev->i2c_client.adapter = &dev->i2c_adap; |
| 331 | strlcpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE); |
Mauro Carvalho Chehab | 792bc09 | 2011-04-20 18:43:24 -0300 | [diff] [blame] | 332 | tm6000_i2c_eeprom(dev); |
Mauro Carvalho Chehab | d4e15bc | 2007-11-05 15:39:41 -0300 | [diff] [blame] | 333 | |
Mauro Carvalho Chehab | 9701dc9 | 2009-09-14 09:42:41 -0300 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * tm6000_i2c_unregister() |
| 339 | * unregister i2c_bus |
| 340 | */ |
| 341 | int tm6000_i2c_unregister(struct tm6000_core *dev) |
| 342 | { |
| 343 | i2c_del_adapter(&dev->i2c_adap); |
| 344 | return 0; |
| 345 | } |