Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX23885 PCIe bridge |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org> |
Steven Toth | d19770e | 2007-03-11 20:44:05 -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> |
| 26 | #include <asm/io.h> |
| 27 | |
| 28 | #include "cx23885.h" |
| 29 | |
| 30 | #include <media/v4l2-common.h> |
| 31 | |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 32 | static unsigned int i2c_debug; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 33 | module_param(i2c_debug, int, 0644); |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 34 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 35 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 36 | static unsigned int i2c_scan; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 37 | module_param(i2c_scan, int, 0444); |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 38 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 39 | |
Steven Toth | 4513fc69 | 2008-01-12 11:36:36 -0300 | [diff] [blame] | 40 | #define dprintk(level, fmt, arg...)\ |
| 41 | do { if (i2c_debug >= level)\ |
| 42 | printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 43 | } while (0) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 44 | |
| 45 | #define I2C_WAIT_DELAY 32 |
| 46 | #define I2C_WAIT_RETRY 64 |
| 47 | |
| 48 | #define I2C_EXTEND (1 << 3) |
| 49 | #define I2C_NOSTOP (1 << 4) |
| 50 | |
| 51 | static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap) |
| 52 | { |
| 53 | struct cx23885_i2c *bus = i2c_adap->algo_data; |
| 54 | struct cx23885_dev *dev = bus->dev; |
| 55 | return cx_read(bus->reg_stat) & 0x01; |
| 56 | } |
| 57 | |
| 58 | static inline int i2c_is_busy(struct i2c_adapter *i2c_adap) |
| 59 | { |
| 60 | struct cx23885_i2c *bus = i2c_adap->algo_data; |
| 61 | struct cx23885_dev *dev = bus->dev; |
| 62 | return cx_read(bus->reg_stat) & 0x02 ? 1 : 0; |
| 63 | } |
| 64 | |
| 65 | static int i2c_wait_done(struct i2c_adapter *i2c_adap) |
| 66 | { |
| 67 | int count; |
| 68 | |
| 69 | for (count = 0; count < I2C_WAIT_RETRY; count++) { |
| 70 | if (!i2c_is_busy(i2c_adap)) |
| 71 | break; |
| 72 | udelay(I2C_WAIT_DELAY); |
| 73 | } |
| 74 | |
| 75 | if (I2C_WAIT_RETRY == count) |
| 76 | return 0; |
| 77 | |
| 78 | return 1; |
| 79 | } |
| 80 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 81 | static int i2c_sendbytes(struct i2c_adapter *i2c_adap, |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 82 | const struct i2c_msg *msg, int joined_rlen) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 83 | { |
| 84 | struct cx23885_i2c *bus = i2c_adap->algo_data; |
| 85 | struct cx23885_dev *dev = bus->dev; |
| 86 | u32 wdata, addr, ctrl; |
| 87 | int retval, cnt; |
| 88 | |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 89 | if (joined_rlen) |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 90 | dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__, |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 91 | msg->len, joined_rlen); |
| 92 | else |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 93 | dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len); |
Steven Toth | e92adc2 | 2007-09-20 01:44:27 -0300 | [diff] [blame] | 94 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 95 | /* Deal with i2c probe functions with zero payload */ |
| 96 | if (msg->len == 0) { |
| 97 | cx_write(bus->reg_addr, msg->addr << 25); |
| 98 | cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2)); |
| 99 | if (!i2c_wait_done(i2c_adap)) |
| 100 | return -EIO; |
| 101 | if (!i2c_slave_did_ack(i2c_adap)) |
| 102 | return -EIO; |
| 103 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 104 | dprintk(1, "%s() returns 0\n", __func__); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /* dev, reg + first byte */ |
| 110 | addr = (msg->addr << 25) | msg->buf[0]; |
| 111 | wdata = msg->buf[0]; |
| 112 | ctrl = bus->i2c_period | (1 << 12) | (1 << 2); |
| 113 | |
| 114 | if (msg->len > 1) |
| 115 | ctrl |= I2C_NOSTOP | I2C_EXTEND; |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 116 | else if (joined_rlen) |
| 117 | ctrl |= I2C_NOSTOP; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 118 | |
| 119 | cx_write(bus->reg_addr, addr); |
| 120 | cx_write(bus->reg_wdata, wdata); |
| 121 | cx_write(bus->reg_ctrl, ctrl); |
| 122 | |
| 123 | retval = i2c_wait_done(i2c_adap); |
| 124 | if (retval < 0) |
| 125 | goto err; |
| 126 | if (retval == 0) |
| 127 | goto eio; |
| 128 | if (i2c_debug) { |
| 129 | printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]); |
| 130 | if (!(ctrl & I2C_NOSTOP)) |
| 131 | printk(" >\n"); |
| 132 | } |
| 133 | |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 134 | for (cnt = 1; cnt < msg->len; cnt++) { |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 135 | /* following bytes */ |
| 136 | wdata = msg->buf[cnt]; |
| 137 | ctrl = bus->i2c_period | (1 << 12) | (1 << 2); |
| 138 | |
Steven Toth | e92adc2 | 2007-09-20 01:44:27 -0300 | [diff] [blame] | 139 | if (cnt < msg->len - 1) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 140 | ctrl |= I2C_NOSTOP | I2C_EXTEND; |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 141 | else if (joined_rlen) |
| 142 | ctrl |= I2C_NOSTOP; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 143 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 144 | cx_write(bus->reg_addr, addr); |
| 145 | cx_write(bus->reg_wdata, wdata); |
| 146 | cx_write(bus->reg_ctrl, ctrl); |
| 147 | |
| 148 | retval = i2c_wait_done(i2c_adap); |
| 149 | if (retval < 0) |
| 150 | goto err; |
| 151 | if (retval == 0) |
| 152 | goto eio; |
| 153 | if (i2c_debug) { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 154 | dprintk(1, " %02x", msg->buf[cnt]); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 155 | if (!(ctrl & I2C_NOSTOP)) |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 156 | dprintk(1, " >\n"); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | return msg->len; |
| 160 | |
| 161 | eio: |
| 162 | retval = -EIO; |
| 163 | err: |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 164 | if (i2c_debug) |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 165 | printk(KERN_ERR " ERR: %d\n", retval); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 166 | return retval; |
| 167 | } |
| 168 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 169 | static int i2c_readbytes(struct i2c_adapter *i2c_adap, |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 170 | const struct i2c_msg *msg, int joined) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 171 | { |
| 172 | struct cx23885_i2c *bus = i2c_adap->algo_data; |
| 173 | struct cx23885_dev *dev = bus->dev; |
| 174 | u32 ctrl, cnt; |
| 175 | int retval; |
| 176 | |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 177 | |
| 178 | if (i2c_debug && !joined) |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 179 | dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 180 | |
| 181 | /* Deal with i2c probe functions with zero payload */ |
| 182 | if (msg->len == 0) { |
| 183 | cx_write(bus->reg_addr, msg->addr << 25); |
| 184 | cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2) | 1); |
| 185 | if (!i2c_wait_done(i2c_adap)) |
| 186 | return -EIO; |
| 187 | if (!i2c_slave_did_ack(i2c_adap)) |
| 188 | return -EIO; |
| 189 | |
| 190 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 191 | dprintk(1, "%s() returns 0\n", __func__); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 195 | if (i2c_debug) { |
| 196 | if (joined) |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 197 | dprintk(1, " R"); |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 198 | else |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 199 | dprintk(1, " <R %02x", (msg->addr << 1) + 1); |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 200 | } |
Steven Toth | e92adc2 | 2007-09-20 01:44:27 -0300 | [diff] [blame] | 201 | |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 202 | for (cnt = 0; cnt < msg->len; cnt++) { |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 203 | |
| 204 | ctrl = bus->i2c_period | (1 << 12) | (1 << 2) | 1; |
| 205 | |
Steven Toth | e92adc2 | 2007-09-20 01:44:27 -0300 | [diff] [blame] | 206 | if (cnt < msg->len - 1) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 207 | ctrl |= I2C_NOSTOP | I2C_EXTEND; |
| 208 | |
| 209 | cx_write(bus->reg_addr, msg->addr << 25); |
| 210 | cx_write(bus->reg_ctrl, ctrl); |
| 211 | |
| 212 | retval = i2c_wait_done(i2c_adap); |
| 213 | if (retval < 0) |
| 214 | goto err; |
| 215 | if (retval == 0) |
| 216 | goto eio; |
| 217 | msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff; |
| 218 | if (i2c_debug) { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 219 | dprintk(1, " %02x", msg->buf[cnt]); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 220 | if (!(ctrl & I2C_NOSTOP)) |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 221 | dprintk(1, " >\n"); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | return msg->len; |
| 225 | |
| 226 | eio: |
| 227 | retval = -EIO; |
| 228 | err: |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 229 | if (i2c_debug) |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 230 | printk(KERN_ERR " ERR: %d\n", retval); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 231 | return retval; |
| 232 | } |
| 233 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 234 | static int i2c_xfer(struct i2c_adapter *i2c_adap, |
| 235 | struct i2c_msg *msgs, int num) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 236 | { |
| 237 | struct cx23885_i2c *bus = i2c_adap->algo_data; |
| 238 | struct cx23885_dev *dev = bus->dev; |
| 239 | int i, retval = 0; |
| 240 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 241 | dprintk(1, "%s(num = %d)\n", __func__, num); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 242 | |
| 243 | for (i = 0 ; i < num; i++) { |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 244 | dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n", |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 245 | __func__, num, msgs[i].addr, msgs[i].len); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 246 | if (msgs[i].flags & I2C_M_RD) { |
| 247 | /* read */ |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 248 | retval = i2c_readbytes(i2c_adap, &msgs[i], 0); |
| 249 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && |
| 250 | msgs[i].addr == msgs[i + 1].addr) { |
| 251 | /* write then read from same address */ |
| 252 | retval = i2c_sendbytes(i2c_adap, &msgs[i], |
| 253 | msgs[i + 1].len); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 254 | if (retval < 0) |
| 255 | goto err; |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 256 | i++; |
| 257 | retval = i2c_readbytes(i2c_adap, &msgs[i], 1); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 258 | } else { |
| 259 | /* write */ |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 260 | retval = i2c_sendbytes(i2c_adap, &msgs[i], 0); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 261 | } |
Chris Pascoe | 5e3c596 | 2007-12-15 03:31:09 -0300 | [diff] [blame] | 262 | if (retval < 0) |
| 263 | goto err; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 264 | } |
| 265 | return num; |
| 266 | |
| 267 | err: |
| 268 | return retval; |
| 269 | } |
| 270 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 271 | static u32 cx23885_functionality(struct i2c_adapter *adap) |
| 272 | { |
Steven Toth | 0fc0739 | 2007-03-19 18:03:03 -0300 | [diff] [blame] | 273 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static struct i2c_algorithm cx23885_i2c_algo_template = { |
| 277 | .master_xfer = i2c_xfer, |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 278 | .functionality = cx23885_functionality, |
| 279 | }; |
| 280 | |
| 281 | /* ----------------------------------------------------------------------- */ |
| 282 | |
| 283 | static struct i2c_adapter cx23885_i2c_adap_template = { |
| 284 | .name = "cx23885", |
| 285 | .owner = THIS_MODULE, |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 286 | .algo = &cx23885_i2c_algo_template, |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | static struct i2c_client cx23885_i2c_client_template = { |
| 290 | .name = "cx23885 internal", |
| 291 | }; |
| 292 | |
| 293 | static char *i2c_devs[128] = { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 294 | [0x10 >> 1] = "tda10048", |
| 295 | [0x12 >> 1] = "dib7000pc", |
| 296 | [0x1c >> 1] = "lgdt3303", |
| 297 | [0x86 >> 1] = "tda9887", |
| 298 | [0x32 >> 1] = "cx24227", |
| 299 | [0x88 >> 1] = "cx25837", |
| 300 | [0x84 >> 1] = "tda8295", |
| 301 | [0xa0 >> 1] = "eeprom", |
| 302 | [0xc0 >> 1] = "tuner/mt2131/tda8275", |
Steven Toth | 6676237 | 2008-04-22 15:38:26 -0300 | [diff] [blame] | 303 | [0xc2 >> 1] = "tuner/mt2131/tda8275/xc5000/xc3028", |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 304 | [0xc8 >> 1] = "tuner/xc3028L", |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | static void do_i2c_scan(char *name, struct i2c_client *c) |
| 308 | { |
| 309 | unsigned char buf; |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 310 | int i, rc; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 311 | |
| 312 | for (i = 0; i < 128; i++) { |
| 313 | c->addr = i; |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 314 | rc = i2c_master_recv(c, &buf, 0); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 315 | if (rc < 0) |
| 316 | continue; |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 317 | printk(KERN_INFO "%s: i2c scan: found device @ 0x%x [%s]\n", |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 318 | name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /* init + register i2c algo-bit adapter */ |
| 323 | int cx23885_i2c_register(struct cx23885_i2c *bus) |
| 324 | { |
| 325 | struct cx23885_dev *dev = bus->dev; |
| 326 | |
Harvey Harrison | 22b4e64 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 327 | dprintk(1, "%s(bus = %d)\n", __func__, bus->nr); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 328 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 329 | memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template, |
| 330 | sizeof(bus->i2c_adap)); |
| 331 | memcpy(&bus->i2c_algo, &cx23885_i2c_algo_template, |
| 332 | sizeof(bus->i2c_algo)); |
| 333 | memcpy(&bus->i2c_client, &cx23885_i2c_client_template, |
| 334 | sizeof(bus->i2c_client)); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 335 | |
| 336 | bus->i2c_adap.dev.parent = &dev->pci->dev; |
| 337 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 338 | strlcpy(bus->i2c_adap.name, bus->dev->name, |
| 339 | sizeof(bus->i2c_adap.name)); |
Steven Toth | 2e52f21 | 2007-09-04 21:32:41 -0300 | [diff] [blame] | 340 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 341 | bus->i2c_algo.data = bus; |
| 342 | bus->i2c_adap.algo_data = bus; |
Hans Verkuil | c0714f6 | 2009-03-13 08:02:43 -0300 | [diff] [blame] | 343 | i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 344 | i2c_add_adapter(&bus->i2c_adap); |
| 345 | |
| 346 | bus->i2c_client.adapter = &bus->i2c_adap; |
| 347 | |
| 348 | if (0 == bus->i2c_rc) { |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 349 | dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 350 | if (i2c_scan) { |
| 351 | printk(KERN_INFO "%s: scan bus %d:\n", |
| 352 | dev->name, bus->nr); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 353 | do_i2c_scan(dev->name, &bus->i2c_client); |
Hans Verkuil | 0d5a19f | 2009-03-29 06:53:29 -0300 | [diff] [blame] | 354 | } |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 355 | } else |
Steven Toth | 9c8ced5 | 2008-10-16 20:18:44 -0300 | [diff] [blame] | 356 | printk(KERN_WARNING "%s: i2c bus %d register FAILED\n", |
| 357 | dev->name, bus->nr); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 358 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 359 | /* Instantiate the IR receiver device, if present */ |
| 360 | if (0 == bus->i2c_rc) { |
| 361 | struct i2c_board_info info; |
| 362 | const unsigned short addr_list[] = { |
| 363 | 0x6b, I2C_CLIENT_END |
| 364 | }; |
| 365 | |
| 366 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 367 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
| 368 | i2c_new_probed_device(&bus->i2c_adap, &info, addr_list); |
| 369 | } |
| 370 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 371 | return bus->i2c_rc; |
| 372 | } |
| 373 | |
| 374 | int cx23885_i2c_unregister(struct cx23885_i2c *bus) |
| 375 | { |
| 376 | i2c_del_adapter(&bus->i2c_adap); |
| 377 | return 0; |
| 378 | } |
| 379 | |
Steven Toth | a589b66 | 2008-01-13 23:44:47 -0300 | [diff] [blame] | 380 | void cx23885_av_clk(struct cx23885_dev *dev, int enable) |
| 381 | { |
| 382 | /* write 0 to bus 2 addr 0x144 via i2x_xfer() */ |
| 383 | char buffer[3]; |
| 384 | struct i2c_msg msg; |
| 385 | dprintk(1, "%s(enabled = %d)\n", __func__, enable); |
| 386 | |
| 387 | /* Register 0x144 */ |
| 388 | buffer[0] = 0x01; |
| 389 | buffer[1] = 0x44; |
| 390 | if (enable == 1) |
| 391 | buffer[2] = 0x05; |
| 392 | else |
| 393 | buffer[2] = 0x00; |
| 394 | |
| 395 | msg.addr = 0x44; |
| 396 | msg.flags = I2C_M_TEN; |
| 397 | msg.len = 3; |
| 398 | msg.buf = buffer; |
| 399 | |
| 400 | i2c_xfer(&dev->i2c_bus[2].i2c_adap, &msg, 1); |
| 401 | } |
| 402 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 403 | /* ----------------------------------------------------------------------- */ |
| 404 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 405 | /* |
| 406 | * Local variables: |
| 407 | * c-basic-offset: 8 |
| 408 | * End: |
| 409 | */ |