Lines Matching +full:i2c +full:- +full:int +full:- +full:rising

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * CIMax2(R) SP2 driver in conjunction with NetUp Dual DVB-S2 CI card
16 /* Max transfer size done by I2C transfer functions */
20 bits 31-16
21 +-----------+
23 +-----------+
25 +-------+-------+-------+-------+-------+-------+-------+-------+
27 +-------+-------+-------+-------+-------+-------+-------+-------+
29 +-------+-------+-------+-------+-------+-------+-------+-------+
31 +-------+-------+-------+-------+-------+-------+-------+-------+
50 static unsigned int ci_dbg;
51 module_param(ci_dbg, int, 0644);
54 static unsigned int ci_irq_enable;
55 module_param(ci_irq_enable, int, 0644);
73 int status;
77 int current_ci_flag;
82 static int netup_read_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg, in netup_read_i2c()
83 u8 *buf, int len) in netup_read_i2c()
85 int ret; in netup_read_i2c()
103 ci_dbg_print("%s: i2c read error, Reg = 0x%02x, Status = %d\n", in netup_read_i2c()
106 return -1; in netup_read_i2c()
109 ci_dbg_print("%s: i2c read Addr=0x%04x, Reg = 0x%02x, data = %02x\n", in netup_read_i2c()
115 static int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg, in netup_write_i2c()
116 u8 *buf, int len) in netup_write_i2c()
118 int ret; in netup_write_i2c()
129 pr_warn("%s: i2c wr reg=%04x: len=%d is too big!\n", in netup_write_i2c()
131 return -EINVAL; in netup_write_i2c()
140 ci_dbg_print("%s: i2c write error, Reg=[0x%02x], Status=%d\n", in netup_write_i2c()
142 return -1; in netup_write_i2c()
148 static int netup_ci_get_mem(struct cx23885_dev *dev) in netup_ci_get_mem()
150 int mem; in netup_ci_get_mem()
167 static int netup_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot, in netup_ci_op_cam()
168 u8 flag, u8 read, int addr, u8 data) in netup_ci_op_cam()
170 struct netup_ci_state *state = en50221->data; in netup_ci_op_cam()
171 struct cx23885_tsport *port = state->priv; in netup_ci_op_cam()
172 struct cx23885_dev *dev = port->dev; in netup_ci_op_cam()
175 int mem; in netup_ci_op_cam()
176 int ret; in netup_ci_op_cam()
179 return -EINVAL; in netup_ci_op_cam()
181 if (state->current_ci_flag != flag) { in netup_ci_op_cam()
182 ret = netup_read_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_op_cam()
190 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_op_cam()
195 state->current_ci_flag = flag; in netup_ci_op_cam()
197 mutex_lock(&dev->gpio_lock); in netup_ci_op_cam()
215 (state->ci_i2c_addr == 0x40) ? NETUP_CS0 : NETUP_CS1); in netup_ci_op_cam()
220 mutex_unlock(&dev->gpio_lock); in netup_ci_op_cam()
224 return -EREMOTEIO; in netup_ci_op_cam()
227 (read) ? "read" : "write", state->ci_i2c_addr, addr, in netup_ci_op_cam()
237 int netup_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221, in netup_ci_read_attribute_mem()
238 int slot, int addr) in netup_ci_read_attribute_mem()
243 int netup_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221, in netup_ci_write_attribute_mem()
244 int slot, int addr, u8 data) in netup_ci_write_attribute_mem()
249 int netup_ci_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, in netup_ci_read_cam_ctl()
256 int netup_ci_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, in netup_ci_write_cam_ctl()
262 int netup_ci_slot_reset(struct dvb_ca_en50221 *en50221, int slot) in netup_ci_slot_reset()
264 struct netup_ci_state *state = en50221->data; in netup_ci_slot_reset()
266 int ret; in netup_ci_slot_reset()
269 return -EINVAL; in netup_ci_slot_reset()
272 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_slot_reset()
281 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_slot_reset()
285 dvb_ca_en50221_camready_irq(&state->ca, 0); in netup_ci_slot_reset()
291 int netup_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot) in netup_ci_slot_shutdown()
297 static int netup_ci_set_irq(struct dvb_ca_en50221 *en50221, u8 irq_mode) in netup_ci_set_irq()
299 struct netup_ci_state *state = en50221->data; in netup_ci_set_irq()
300 int ret; in netup_ci_set_irq()
302 if (irq_mode == state->current_irq_mode) in netup_ci_set_irq()
306 __func__, state->ci_i2c_addr, irq_mode); in netup_ci_set_irq()
307 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_set_irq()
313 state->current_irq_mode = irq_mode; in netup_ci_set_irq()
318 int netup_ci_slot_ts_ctl(struct dvb_ca_en50221 *en50221, int slot) in netup_ci_slot_ts_ctl()
320 struct netup_ci_state *state = en50221->data; in netup_ci_slot_ts_ctl()
324 return -EINVAL; in netup_ci_slot_ts_ctl()
326 netup_read_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_slot_ts_ctl()
330 return netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_slot_ts_ctl()
340 int ret; in netup_read_ci_status()
343 dvb_ca_en50221_frda_irq(&state->ca, 0); in netup_read_ci_status()
345 /* CAM module INSERT/REMOVE processing. slow operation because of i2c in netup_read_ci_status()
347 if (time_after(jiffies, state->next_status_checked_time) in netup_read_ci_status()
348 || !state->status) { in netup_read_ci_status()
349 ret = netup_read_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_read_ci_status()
352 state->next_status_checked_time = jiffies in netup_read_ci_status()
359 __func__, state->ci_i2c_addr, 0, buf[0], buf[0]); in netup_read_ci_status()
363 state->status = DVB_CA_EN50221_POLL_CAM_PRESENT | in netup_read_ci_status()
366 state->status = 0; in netup_read_ci_status()
371 int netup_ci_slot_status(struct cx23885_dev *dev, u32 pci_status) in netup_ci_slot_status()
382 port = &dev->ts1; in netup_ci_slot_status()
383 state = port->port_priv; in netup_ci_slot_status()
384 schedule_work(&state->work); in netup_ci_slot_status()
389 port = &dev->ts2; in netup_ci_slot_status()
390 state = port->port_priv; in netup_ci_slot_status()
391 schedule_work(&state->work); in netup_ci_slot_status()
398 int netup_poll_ci_slot_status(struct dvb_ca_en50221 *en50221, in netup_poll_ci_slot_status()
399 int slot, int open) in netup_poll_ci_slot_status()
401 struct netup_ci_state *state = en50221->data; in netup_poll_ci_slot_status()
404 return -EINVAL; in netup_poll_ci_slot_status()
409 return state->status; in netup_poll_ci_slot_status()
412 int netup_ci_init(struct cx23885_tsport *port) in netup_ci_init()
439 0x02, /* destination - module A */ in netup_ci_init()
442 0x00, /* int status read only */ in netup_ci_init()
444 0x05, /* EXTINT=active-high, INT=push-pull */ in netup_ci_init()
448 0x33, /* serial mode, rising in, rising out, MSB first*/ in netup_ci_init()
451 int ret; in netup_ci_init()
457 ret = -ENOMEM; in netup_ci_init()
461 port->port_priv = state; in netup_ci_init()
463 switch (port->nr) { in netup_ci_init()
465 state->ci_i2c_addr = 0x40; in netup_ci_init()
468 state->ci_i2c_addr = 0x41; in netup_ci_init()
472 state->i2c_adap = &port->dev->i2c_bus[0].i2c_adap; in netup_ci_init()
473 state->ca.owner = THIS_MODULE; in netup_ci_init()
474 state->ca.read_attribute_mem = netup_ci_read_attribute_mem; in netup_ci_init()
475 state->ca.write_attribute_mem = netup_ci_write_attribute_mem; in netup_ci_init()
476 state->ca.read_cam_control = netup_ci_read_cam_ctl; in netup_ci_init()
477 state->ca.write_cam_control = netup_ci_write_cam_ctl; in netup_ci_init()
478 state->ca.slot_reset = netup_ci_slot_reset; in netup_ci_init()
479 state->ca.slot_shutdown = netup_ci_slot_shutdown; in netup_ci_init()
480 state->ca.slot_ts_enable = netup_ci_slot_ts_ctl; in netup_ci_init()
481 state->ca.poll_slot_status = netup_poll_ci_slot_status; in netup_ci_init()
482 state->ca.data = state; in netup_ci_init()
483 state->priv = port; in netup_ci_init()
484 state->current_irq_mode = ci_irq_flags() | NETUP_IRQ_DETAM; in netup_ci_init()
486 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_init()
489 ret |= netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_init()
492 ret |= netup_write_i2c(state->i2c_adap, state->ci_i2c_addr, in netup_ci_init()
498 ret = dvb_ca_en50221_init(&port->frontends.adapter, in netup_ci_init()
499 &state->ca, in netup_ci_init()
505 INIT_WORK(&state->work, netup_read_ci_status); in netup_ci_init()
506 schedule_work(&state->work); in netup_ci_init()
524 state = (struct netup_ci_state *)port->port_priv; in netup_ci_exit()
528 if (NULL == state->ca.data) in netup_ci_exit()
531 dvb_ca_en50221_release(&state->ca); in netup_ci_exit()