Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Auvitek AU0828 USB bridge |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 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 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/moduleparam.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/delay.h> |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 26 | #include <linux/io.h> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 27 | |
| 28 | #include "au0828.h" |
Devin Heitmueller | faaf01b | 2012-08-06 22:47:04 -0300 | [diff] [blame] | 29 | #include "media/tuner.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 30 | #include <media/v4l2-common.h> |
| 31 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 32 | static int i2c_scan; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 33 | module_param(i2c_scan, int, 0444); |
| 34 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); |
| 35 | |
Devin Heitmueller | baede40 | 2012-08-06 22:47:06 -0300 | [diff] [blame] | 36 | #define I2C_WAIT_DELAY 25 |
| 37 | #define I2C_WAIT_RETRY 1000 |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 38 | |
| 39 | static inline int i2c_slave_did_write_ack(struct i2c_adapter *i2c_adap) |
| 40 | { |
| 41 | struct au0828_dev *dev = i2c_adap->algo_data; |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 42 | return au0828_read(dev, AU0828_I2C_STATUS_201) & |
| 43 | AU0828_I2C_STATUS_NO_WRITE_ACK ? 0 : 1; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static inline int i2c_slave_did_read_ack(struct i2c_adapter *i2c_adap) |
| 47 | { |
| 48 | struct au0828_dev *dev = i2c_adap->algo_data; |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 49 | return au0828_read(dev, AU0828_I2C_STATUS_201) & |
| 50 | AU0828_I2C_STATUS_NO_READ_ACK ? 0 : 1; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static int i2c_wait_read_ack(struct i2c_adapter *i2c_adap) |
| 54 | { |
| 55 | int count; |
| 56 | |
| 57 | for (count = 0; count < I2C_WAIT_RETRY; count++) { |
| 58 | if (!i2c_slave_did_read_ack(i2c_adap)) |
| 59 | break; |
| 60 | udelay(I2C_WAIT_DELAY); |
| 61 | } |
| 62 | |
| 63 | if (I2C_WAIT_RETRY == count) |
| 64 | return 0; |
| 65 | |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | static inline int i2c_is_read_busy(struct i2c_adapter *i2c_adap) |
| 70 | { |
| 71 | struct au0828_dev *dev = i2c_adap->algo_data; |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 72 | return au0828_read(dev, AU0828_I2C_STATUS_201) & |
| 73 | AU0828_I2C_STATUS_READ_DONE ? 0 : 1; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static int i2c_wait_read_done(struct i2c_adapter *i2c_adap) |
| 77 | { |
| 78 | int count; |
| 79 | |
| 80 | for (count = 0; count < I2C_WAIT_RETRY; count++) { |
| 81 | if (!i2c_is_read_busy(i2c_adap)) |
| 82 | break; |
| 83 | udelay(I2C_WAIT_DELAY); |
| 84 | } |
| 85 | |
| 86 | if (I2C_WAIT_RETRY == count) |
| 87 | return 0; |
| 88 | |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | static inline int i2c_is_write_done(struct i2c_adapter *i2c_adap) |
| 93 | { |
| 94 | struct au0828_dev *dev = i2c_adap->algo_data; |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 95 | return au0828_read(dev, AU0828_I2C_STATUS_201) & |
| 96 | AU0828_I2C_STATUS_WRITE_DONE ? 1 : 0; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static int i2c_wait_write_done(struct i2c_adapter *i2c_adap) |
| 100 | { |
| 101 | int count; |
| 102 | |
| 103 | for (count = 0; count < I2C_WAIT_RETRY; count++) { |
| 104 | if (i2c_is_write_done(i2c_adap)) |
| 105 | break; |
| 106 | udelay(I2C_WAIT_DELAY); |
| 107 | } |
| 108 | |
| 109 | if (I2C_WAIT_RETRY == count) |
| 110 | return 0; |
| 111 | |
| 112 | return 1; |
| 113 | } |
| 114 | |
| 115 | static inline int i2c_is_busy(struct i2c_adapter *i2c_adap) |
| 116 | { |
| 117 | struct au0828_dev *dev = i2c_adap->algo_data; |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 118 | return au0828_read(dev, AU0828_I2C_STATUS_201) & |
| 119 | AU0828_I2C_STATUS_BUSY ? 1 : 0; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static int i2c_wait_done(struct i2c_adapter *i2c_adap) |
| 123 | { |
| 124 | int count; |
| 125 | |
| 126 | for (count = 0; count < I2C_WAIT_RETRY; count++) { |
| 127 | if (!i2c_is_busy(i2c_adap)) |
| 128 | break; |
| 129 | udelay(I2C_WAIT_DELAY); |
| 130 | } |
| 131 | |
| 132 | if (I2C_WAIT_RETRY == count) |
| 133 | return 0; |
| 134 | |
| 135 | return 1; |
| 136 | } |
| 137 | |
| 138 | /* FIXME: Implement join handling correctly */ |
| 139 | static int i2c_sendbytes(struct i2c_adapter *i2c_adap, |
| 140 | const struct i2c_msg *msg, int joined_rlen) |
| 141 | { |
| 142 | int i, strobe = 0; |
| 143 | struct au0828_dev *dev = i2c_adap->algo_data; |
| 144 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 145 | dprintk(4, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 146 | |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 147 | au0828_write(dev, AU0828_I2C_MULTIBYTE_MODE_2FF, 0x01); |
Devin Heitmueller | 32c000a | 2009-03-11 03:00:41 -0300 | [diff] [blame] | 148 | |
Devin Heitmueller | 16af6f5 | 2009-04-01 00:11:31 -0300 | [diff] [blame] | 149 | /* Set the I2C clock */ |
Devin Heitmueller | ad03d30 | 2012-08-06 22:47:13 -0300 | [diff] [blame] | 150 | if (((dev->board.tuner_type == TUNER_XC5000) || |
| 151 | (dev->board.tuner_type == TUNER_XC5000C)) && |
Devin Heitmueller | faaf01b | 2012-08-06 22:47:04 -0300 | [diff] [blame] | 152 | (dev->board.tuner_addr == msg->addr) && |
| 153 | (msg->len == 64)) { |
| 154 | /* Hack to speed up firmware load. The xc5000 lets us do up |
| 155 | to 400 KHz when in firmware download mode */ |
| 156 | au0828_write(dev, AU0828_I2C_CLK_DIVIDER_202, |
| 157 | AU0828_I2C_CLK_250KHZ); |
| 158 | } else { |
| 159 | /* Use the i2c clock speed in the board configuration */ |
| 160 | au0828_write(dev, AU0828_I2C_CLK_DIVIDER_202, |
| 161 | dev->board.i2c_clk_divider); |
| 162 | } |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 163 | |
| 164 | /* Hardware needs 8 bit addresses */ |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 165 | au0828_write(dev, AU0828_I2C_DEST_ADDR_203, msg->addr << 1); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 166 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 167 | dprintk(4, "SEND: %02x\n", msg->addr); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 168 | |
Devin Heitmueller | dc8685b | 2009-03-11 03:00:56 -0300 | [diff] [blame] | 169 | /* Deal with i2c_scan */ |
| 170 | if (msg->len == 0) { |
| 171 | /* The analog tuner detection code makes use of the SMBUS_QUICK |
| 172 | message (which involves a zero length i2c write). To avoid |
| 173 | checking the status register when we didn't strobe out any |
| 174 | actual bytes to the bus, just do a read check. This is |
| 175 | consistent with how I saw i2c device checking done in the |
| 176 | USB trace of the Windows driver */ |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 177 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 178 | AU0828_I2C_TRIGGER_READ); |
| 179 | |
Devin Heitmueller | dc8685b | 2009-03-11 03:00:56 -0300 | [diff] [blame] | 180 | if (!i2c_wait_done(i2c_adap)) |
| 181 | return -EIO; |
| 182 | |
| 183 | if (i2c_wait_read_ack(i2c_adap)) |
| 184 | return -EIO; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 189 | for (i = 0; i < msg->len;) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 190 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 191 | dprintk(4, " %02x\n", msg->buf[i]); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 192 | |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 193 | au0828_write(dev, AU0828_I2C_WRITE_FIFO_205, msg->buf[i]); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 194 | |
| 195 | strobe++; |
| 196 | i++; |
| 197 | |
| 198 | if ((strobe >= 4) || (i >= msg->len)) { |
| 199 | |
| 200 | /* Strobe the byte into the bus */ |
| 201 | if (i < msg->len) |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 202 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 203 | AU0828_I2C_TRIGGER_WRITE | |
| 204 | AU0828_I2C_TRIGGER_HOLD); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 205 | else |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 206 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 207 | AU0828_I2C_TRIGGER_WRITE); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 208 | |
| 209 | /* Reset strobe trigger */ |
| 210 | strobe = 0; |
| 211 | |
| 212 | if (!i2c_wait_write_done(i2c_adap)) |
| 213 | return -EIO; |
| 214 | |
| 215 | } |
| 216 | |
| 217 | } |
| 218 | if (!i2c_wait_done(i2c_adap)) |
| 219 | return -EIO; |
| 220 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 221 | dprintk(4, "\n"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 222 | |
| 223 | return msg->len; |
| 224 | } |
| 225 | |
| 226 | /* FIXME: Implement join handling correctly */ |
| 227 | static int i2c_readbytes(struct i2c_adapter *i2c_adap, |
| 228 | const struct i2c_msg *msg, int joined) |
| 229 | { |
| 230 | struct au0828_dev *dev = i2c_adap->algo_data; |
| 231 | int i; |
| 232 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 233 | dprintk(4, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 234 | |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 235 | au0828_write(dev, AU0828_I2C_MULTIBYTE_MODE_2FF, 0x01); |
Devin Heitmueller | 32c000a | 2009-03-11 03:00:41 -0300 | [diff] [blame] | 236 | |
Devin Heitmueller | 16af6f5 | 2009-04-01 00:11:31 -0300 | [diff] [blame] | 237 | /* Set the I2C clock */ |
| 238 | au0828_write(dev, AU0828_I2C_CLK_DIVIDER_202, |
| 239 | dev->board.i2c_clk_divider); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 240 | |
| 241 | /* Hardware needs 8 bit addresses */ |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 242 | au0828_write(dev, AU0828_I2C_DEST_ADDR_203, msg->addr << 1); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 243 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 244 | dprintk(4, " RECV:\n"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 245 | |
| 246 | /* Deal with i2c_scan */ |
| 247 | if (msg->len == 0) { |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 248 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 249 | AU0828_I2C_TRIGGER_READ); |
| 250 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 251 | if (i2c_wait_read_ack(i2c_adap)) |
| 252 | return -EIO; |
| 253 | return 0; |
| 254 | } |
| 255 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 256 | for (i = 0; i < msg->len;) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 257 | |
| 258 | i++; |
| 259 | |
| 260 | if (i < msg->len) |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 261 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 262 | AU0828_I2C_TRIGGER_READ | |
| 263 | AU0828_I2C_TRIGGER_HOLD); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 264 | else |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 265 | au0828_write(dev, AU0828_I2C_TRIGGER_200, |
| 266 | AU0828_I2C_TRIGGER_READ); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 267 | |
| 268 | if (!i2c_wait_read_done(i2c_adap)) |
| 269 | return -EIO; |
| 270 | |
Devin Heitmueller | 9beb0de | 2009-03-31 23:58:49 -0300 | [diff] [blame] | 271 | msg->buf[i-1] = au0828_read(dev, AU0828_I2C_READ_FIFO_209) & |
| 272 | 0xff; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 273 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 274 | dprintk(4, " %02x\n", msg->buf[i-1]); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 275 | } |
| 276 | if (!i2c_wait_done(i2c_adap)) |
| 277 | return -EIO; |
| 278 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 279 | dprintk(4, "\n"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 280 | |
| 281 | return msg->len; |
| 282 | } |
| 283 | |
| 284 | static int i2c_xfer(struct i2c_adapter *i2c_adap, |
| 285 | struct i2c_msg *msgs, int num) |
| 286 | { |
| 287 | int i, retval = 0; |
| 288 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 289 | dprintk(4, "%s(num = %d)\n", __func__, num); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 290 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 291 | for (i = 0; i < num; i++) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 292 | dprintk(4, "%s(num = %d) addr = 0x%02x len = 0x%x\n", |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 293 | __func__, num, msgs[i].addr, msgs[i].len); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 294 | if (msgs[i].flags & I2C_M_RD) { |
| 295 | /* read */ |
| 296 | retval = i2c_readbytes(i2c_adap, &msgs[i], 0); |
| 297 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && |
| 298 | msgs[i].addr == msgs[i + 1].addr) { |
| 299 | /* write then read from same address */ |
| 300 | retval = i2c_sendbytes(i2c_adap, &msgs[i], |
| 301 | msgs[i + 1].len); |
| 302 | if (retval < 0) |
| 303 | goto err; |
| 304 | i++; |
| 305 | retval = i2c_readbytes(i2c_adap, &msgs[i], 1); |
| 306 | } else { |
| 307 | /* write */ |
| 308 | retval = i2c_sendbytes(i2c_adap, &msgs[i], 0); |
| 309 | } |
| 310 | if (retval < 0) |
| 311 | goto err; |
| 312 | } |
| 313 | return num; |
| 314 | |
| 315 | err: |
| 316 | return retval; |
| 317 | } |
| 318 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 319 | static u32 au0828_functionality(struct i2c_adapter *adap) |
| 320 | { |
| 321 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; |
| 322 | } |
| 323 | |
| 324 | static struct i2c_algorithm au0828_i2c_algo_template = { |
| 325 | .master_xfer = i2c_xfer, |
| 326 | .functionality = au0828_functionality, |
| 327 | }; |
| 328 | |
| 329 | /* ----------------------------------------------------------------------- */ |
| 330 | |
| 331 | static struct i2c_adapter au0828_i2c_adap_template = { |
| 332 | .name = DRIVER_NAME, |
| 333 | .owner = THIS_MODULE, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 334 | .algo = &au0828_i2c_algo_template, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | static struct i2c_client au0828_i2c_client_template = { |
| 338 | .name = "au0828 internal", |
| 339 | }; |
| 340 | |
| 341 | static char *i2c_devs[128] = { |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 342 | [0x8e >> 1] = "au8522", |
| 343 | [0xa0 >> 1] = "eeprom", |
| 344 | [0xc2 >> 1] = "tuner/xc5000", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | static void do_i2c_scan(char *name, struct i2c_client *c) |
| 348 | { |
| 349 | unsigned char buf; |
| 350 | int i, rc; |
| 351 | |
| 352 | for (i = 0; i < 128; i++) { |
| 353 | c->addr = i; |
| 354 | rc = i2c_master_recv(c, &buf, 0); |
| 355 | if (rc < 0) |
| 356 | continue; |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 357 | printk(KERN_INFO "%s: i2c scan: found device @ 0x%x [%s]\n", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 358 | name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); |
| 359 | } |
| 360 | } |
| 361 | |
Jean Delvare | a824f0f | 2011-11-09 13:27:53 -0300 | [diff] [blame] | 362 | /* init + register i2c adapter */ |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 363 | int au0828_i2c_register(struct au0828_dev *dev) |
| 364 | { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 365 | dprintk(1, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 366 | |
Ezequiel Garcia | f01e0ff | 2012-10-23 15:57:14 -0300 | [diff] [blame] | 367 | dev->i2c_adap = au0828_i2c_adap_template; |
| 368 | dev->i2c_algo = au0828_i2c_algo_template; |
| 369 | dev->i2c_client = au0828_i2c_client_template; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 370 | |
| 371 | dev->i2c_adap.dev.parent = &dev->usbdev->dev; |
| 372 | |
| 373 | strlcpy(dev->i2c_adap.name, DRIVER_NAME, |
| 374 | sizeof(dev->i2c_adap.name)); |
| 375 | |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 376 | dev->i2c_adap.algo = &dev->i2c_algo; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 377 | dev->i2c_adap.algo_data = dev; |
Michael Krufky | 8a4e786 | 2012-12-04 11:30:00 -0300 | [diff] [blame] | 378 | #ifdef CONFIG_VIDEO_AU0828_V4L2 |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 379 | i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); |
Michael Krufky | 8a4e786 | 2012-12-04 11:30:00 -0300 | [diff] [blame] | 380 | #else |
| 381 | i2c_set_adapdata(&dev->i2c_adap, dev); |
| 382 | #endif |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 383 | i2c_add_adapter(&dev->i2c_adap); |
| 384 | |
| 385 | dev->i2c_client.adapter = &dev->i2c_adap; |
| 386 | |
| 387 | if (0 == dev->i2c_rc) { |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 388 | printk(KERN_INFO "%s: i2c bus registered\n", DRIVER_NAME); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 389 | if (i2c_scan) |
| 390 | do_i2c_scan(DRIVER_NAME, &dev->i2c_client); |
| 391 | } else |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 392 | printk(KERN_INFO "%s: i2c bus register FAILED\n", DRIVER_NAME); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 393 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 394 | return dev->i2c_rc; |
| 395 | } |
| 396 | |
| 397 | int au0828_i2c_unregister(struct au0828_dev *dev) |
| 398 | { |
| 399 | i2c_del_adapter(&dev->i2c_adap); |
| 400 | return 0; |
| 401 | } |
| 402 | |