Lines Matching +full:byte +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 cx231xx-i2c.c - driver for Conexant Cx23100/101/102 USB video capture devices
15 #include <linux/i2c-mux.h>
16 #include <media/v4l2-common.h>
20 /* ----------------------------------------------------------- */
41 dev->name, __func__ , ##args); \
48 return dev->port_3_switch_enabled ? I2C_1_MUX_3 : I2C_1_MUX_1; in get_real_i2c_port()
55 int i2c_port = get_real_i2c_port(dev, bus->nr); in is_tuner()
57 if (i2c_port != dev->board.tuner_i2c_master) in is_tuner()
60 if (msg->addr != dev->board.tuner_addr) in is_tuner()
63 if (dev->tuner_type != tuner_type) in is_tuner()
75 struct cx231xx_i2c *bus = i2c_adap->algo_data; in cx231xx_i2c_send_bytes()
76 struct cx231xx *dev = bus->dev; in cx231xx_i2c_send_bytes()
87 size = msg->len; in cx231xx_i2c_send_bytes()
94 if (msg->len >= 2) in cx231xx_i2c_send_bytes()
95 saddr = msg->buf[0] << 8 | msg->buf[1]; in cx231xx_i2c_send_bytes()
96 else if (msg->len == 1) in cx231xx_i2c_send_bytes()
97 saddr = msg->buf[0]; in cx231xx_i2c_send_bytes()
103 dev->xc_fw_load_done = 1; in cx231xx_i2c_send_bytes()
106 case 0x0001: /* Set TV standard - Video */ in cx231xx_i2c_send_bytes()
107 case 0x0002: /* Set TV standard - Audio */ in cx231xx_i2c_send_bytes()
112 if (dev->xc_fw_load_done) in cx231xx_i2c_send_bytes()
119 "GPIO WRITE: addr 0x%x, len %d, saddr 0x%x\n", in cx231xx_i2c_send_bytes()
120 msg->addr, msg->len, saddr); in cx231xx_i2c_send_bytes()
122 return dev->cx231xx_gpio_i2c_write(dev, in cx231xx_i2c_send_bytes()
123 msg->addr, in cx231xx_i2c_send_bytes()
124 msg->buf, in cx231xx_i2c_send_bytes()
125 msg->len); in cx231xx_i2c_send_bytes()
133 size -= saddr_len; in cx231xx_i2c_send_bytes()
134 buf_ptr = (u8 *) (msg->buf + 1); in cx231xx_i2c_send_bytes()
138 req_data.dev_addr = msg->addr; in cx231xx_i2c_send_bytes()
139 req_data.direction = msg->flags; in cx231xx_i2c_send_bytes()
141 req_data.saddr_dat = msg->buf[0]; in cx231xx_i2c_send_bytes()
145 bus->i2c_nostop = (size > 16) ? 1 : 0; in cx231xx_i2c_send_bytes()
146 bus->i2c_reserve = (loop == 0) ? 0 : 1; in cx231xx_i2c_send_bytes()
149 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_send_bytes()
153 size -= 16; in cx231xx_i2c_send_bytes()
159 bus->i2c_nostop = 0; in cx231xx_i2c_send_bytes()
160 bus->i2c_reserve = 0; in cx231xx_i2c_send_bytes()
165 req_data.dev_addr = msg->addr; in cx231xx_i2c_send_bytes()
166 req_data.direction = msg->flags; in cx231xx_i2c_send_bytes()
169 req_data.buf_size = msg->len; in cx231xx_i2c_send_bytes()
170 req_data.p_buffer = msg->buf; in cx231xx_i2c_send_bytes()
173 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_send_bytes()
181 * read a byte from the i2c device
186 struct cx231xx_i2c *bus = i2c_adap->algo_data; in cx231xx_i2c_recv_bytes()
187 struct cx231xx *dev = bus->dev; in cx231xx_i2c_recv_bytes()
194 if (msg->len == 2) in cx231xx_i2c_recv_bytes()
195 saddr = msg->buf[0] << 8 | msg->buf[1]; in cx231xx_i2c_recv_bytes()
196 else if (msg->len == 1) in cx231xx_i2c_recv_bytes()
197 saddr = msg->buf[0]; in cx231xx_i2c_recv_bytes()
199 if (dev->xc_fw_load_done) { in cx231xx_i2c_recv_bytes()
206 msg->buf[0] = 0; in cx231xx_i2c_recv_bytes()
207 if (msg->len == 2) in cx231xx_i2c_recv_bytes()
208 msg->buf[1] = 0; in cx231xx_i2c_recv_bytes()
221 "GPIO R E A D: addr 0x%x, len %d, saddr 0x%x\n", in cx231xx_i2c_recv_bytes()
222 msg->addr, msg->len, in cx231xx_i2c_recv_bytes()
223 msg->buf[0] << 8 | msg->buf[1]); in cx231xx_i2c_recv_bytes()
226 dev->cx231xx_gpio_i2c_write(dev, msg->addr, in cx231xx_i2c_recv_bytes()
227 msg->buf, in cx231xx_i2c_recv_bytes()
228 msg->len); in cx231xx_i2c_recv_bytes()
230 dev->cx231xx_gpio_i2c_read(dev, msg->addr, in cx231xx_i2c_recv_bytes()
231 msg->buf, in cx231xx_i2c_recv_bytes()
232 msg->len); in cx231xx_i2c_recv_bytes()
238 req_data.dev_addr = msg->addr; in cx231xx_i2c_recv_bytes()
239 req_data.direction = msg->flags; in cx231xx_i2c_recv_bytes()
240 req_data.saddr_len = msg->len; in cx231xx_i2c_recv_bytes()
241 req_data.saddr_dat = msg->buf[0] << 8 | msg->buf[1]; in cx231xx_i2c_recv_bytes()
242 req_data.buf_size = msg->len; in cx231xx_i2c_recv_bytes()
243 req_data.p_buffer = msg->buf; in cx231xx_i2c_recv_bytes()
246 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_recv_bytes()
251 req_data.dev_addr = msg->addr; in cx231xx_i2c_recv_bytes()
252 req_data.direction = msg->flags; in cx231xx_i2c_recv_bytes()
255 req_data.buf_size = msg->len; in cx231xx_i2c_recv_bytes()
256 req_data.p_buffer = msg->buf; in cx231xx_i2c_recv_bytes()
259 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_recv_bytes()
267 * read a byte from the i2c device
273 struct cx231xx_i2c *bus = i2c_adap->algo_data; in cx231xx_i2c_recv_bytes_with_saddr()
274 struct cx231xx *dev = bus->dev; in cx231xx_i2c_recv_bytes_with_saddr()
280 if (msg1->len == 2) in cx231xx_i2c_recv_bytes_with_saddr()
281 saddr = msg1->buf[0] << 8 | msg1->buf[1]; in cx231xx_i2c_recv_bytes_with_saddr()
282 else if (msg1->len == 1) in cx231xx_i2c_recv_bytes_with_saddr()
283 saddr = msg1->buf[0]; in cx231xx_i2c_recv_bytes_with_saddr()
286 if ((msg2->len < 16)) { in cx231xx_i2c_recv_bytes_with_saddr()
289 "i2c_read: addr 0x%x, len %d, saddr 0x%x, len %d\n", in cx231xx_i2c_recv_bytes_with_saddr()
290 msg2->addr, msg2->len, saddr, msg1->len); in cx231xx_i2c_recv_bytes_with_saddr()
303 dev->cx231xx_gpio_i2c_write(dev, msg1->addr, in cx231xx_i2c_recv_bytes_with_saddr()
304 msg1->buf, in cx231xx_i2c_recv_bytes_with_saddr()
305 msg1->len); in cx231xx_i2c_recv_bytes_with_saddr()
307 dev->cx231xx_gpio_i2c_read(dev, msg2->addr, in cx231xx_i2c_recv_bytes_with_saddr()
308 msg2->buf, in cx231xx_i2c_recv_bytes_with_saddr()
309 msg2->len); in cx231xx_i2c_recv_bytes_with_saddr()
316 req_data.dev_addr = msg2->addr; in cx231xx_i2c_recv_bytes_with_saddr()
317 req_data.direction = msg2->flags; in cx231xx_i2c_recv_bytes_with_saddr()
318 req_data.saddr_len = msg1->len; in cx231xx_i2c_recv_bytes_with_saddr()
320 req_data.buf_size = msg2->len; in cx231xx_i2c_recv_bytes_with_saddr()
321 req_data.p_buffer = msg2->buf; in cx231xx_i2c_recv_bytes_with_saddr()
324 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_recv_bytes_with_saddr()
336 struct cx231xx_i2c *bus = i2c_adap->algo_data; in cx231xx_i2c_check_for_device()
337 struct cx231xx *dev = bus->dev; in cx231xx_i2c_check_for_device()
343 req_data.dev_addr = msg->addr; in cx231xx_i2c_check_for_device()
351 status = dev->cx231xx_send_usb_command(bus, &req_data); in cx231xx_i2c_check_for_device()
363 struct cx231xx_i2c *bus = i2c_adap->algo_data; in cx231xx_i2c_xfer()
364 struct cx231xx *dev = bus->dev; in cx231xx_i2c_xfer()
365 int addr, rc, i, byte; in cx231xx_i2c_xfer() local
367 mutex_lock(&dev->i2c_lock); in cx231xx_i2c_xfer()
372 dprintk2(2, "%s %s addr=0x%x len=%d:", in cx231xx_i2c_xfer()
374 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); in cx231xx_i2c_xfer()
375 if (!msgs[i].len) { in cx231xx_i2c_xfer()
376 /* no len: check only for device presence */ in cx231xx_i2c_xfer()
380 mutex_unlock(&dev->i2c_lock); in cx231xx_i2c_xfer()
388 for (byte = 0; byte < msgs[i].len; byte++) in cx231xx_i2c_xfer()
389 printk(KERN_CONT " %02x", msgs[i].buf[byte]); in cx231xx_i2c_xfer()
393 && (msgs[i].len <= 2) && (bus->nr < 3)) { in cx231xx_i2c_xfer()
396 for (byte = 0; byte < msgs[i].len; byte++) in cx231xx_i2c_xfer()
397 printk(KERN_CONT " %02x", msgs[i].buf[byte]); in cx231xx_i2c_xfer()
401 dprintk2(2, "plus %s %s addr=0x%x len=%d:", in cx231xx_i2c_xfer()
403 i+1 == num - 1 ? "stop" : "nonstop", addr, msgs[i+1].len); in cx231xx_i2c_xfer()
408 for (byte = 0; byte < msgs[i+1].len; byte++) in cx231xx_i2c_xfer()
409 printk(KERN_CONT " %02x", msgs[i+1].buf[byte]); in cx231xx_i2c_xfer()
415 for (byte = 0; byte < msgs[i].len; byte++) in cx231xx_i2c_xfer()
416 printk(KERN_CONT " %02x", msgs[i].buf[byte]); in cx231xx_i2c_xfer()
425 mutex_unlock(&dev->i2c_lock); in cx231xx_i2c_xfer()
429 mutex_unlock(&dev->i2c_lock); in cx231xx_i2c_xfer()
433 /* ----------------------------------------------------------- */
454 /* ----------------------------------------------------------- */
483 .len = 1, in cx231xx_do_i2c_scan()
491 dev->i2c_scan_running = true; in cx231xx_do_i2c_scan()
500 dev_info(dev->dev, in cx231xx_do_i2c_scan()
507 dev->i2c_scan_running = false; in cx231xx_do_i2c_scan()
516 struct cx231xx *dev = bus->dev; in cx231xx_i2c_register()
518 if (!dev->cx231xx_send_usb_command) in cx231xx_i2c_register()
519 return -EINVAL; in cx231xx_i2c_register()
521 bus->i2c_adap = cx231xx_adap_template; in cx231xx_i2c_register()
522 bus->i2c_adap.dev.parent = dev->dev; in cx231xx_i2c_register()
524 snprintf(bus->i2c_adap.name, sizeof(bus->i2c_adap.name), "%s-%d", bus->dev->name, bus->nr); in cx231xx_i2c_register()
526 bus->i2c_adap.algo_data = bus; in cx231xx_i2c_register()
527 i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev); in cx231xx_i2c_register()
528 bus->i2c_rc = i2c_add_adapter(&bus->i2c_adap); in cx231xx_i2c_register()
530 if (0 != bus->i2c_rc) in cx231xx_i2c_register()
531 dev_warn(dev->dev, in cx231xx_i2c_register()
532 "i2c bus %d register FAILED\n", bus->nr); in cx231xx_i2c_register()
534 return bus->i2c_rc; in cx231xx_i2c_register()
543 if (!bus->i2c_rc) in cx231xx_i2c_unregister()
544 i2c_del_adapter(&bus->i2c_adap); in cx231xx_i2c_unregister()
560 dev->muxc = i2c_mux_alloc(&dev->i2c_bus[1].i2c_adap, dev->dev, 2, 0, 0, in cx231xx_i2c_mux_create()
562 if (!dev->muxc) in cx231xx_i2c_mux_create()
563 return -ENOMEM; in cx231xx_i2c_mux_create()
564 dev->muxc->priv = dev; in cx231xx_i2c_mux_create()
570 return i2c_mux_add_adapter(dev->muxc, 0, mux_no); in cx231xx_i2c_mux_register()
575 i2c_mux_del_adapters(dev->muxc); in cx231xx_i2c_mux_unregister()
582 return &dev->i2c_bus[0].i2c_adap; in cx231xx_get_i2c_adap()
584 return &dev->i2c_bus[1].i2c_adap; in cx231xx_get_i2c_adap()
586 return &dev->i2c_bus[2].i2c_adap; in cx231xx_get_i2c_adap()
588 return dev->muxc->adapter[0]; in cx231xx_get_i2c_adap()
590 return dev->muxc->adapter[1]; in cx231xx_get_i2c_adap()