30 #define AZ6007_FIRMWARE "dvb-usb-terratec-h7-az6007.fw"
32 static int az6007_xfer_debug;
41 #define AZ6007_READ_DATA 0xb7
42 #define AZ6007_I2C_RD 0xb9
43 #define AZ6007_POWER 0xbc
44 #define AZ6007_I2C_WR 0xbd
45 #define FX2_SCON1 0xc0
46 #define AZ6007_TS_THROUGH 0xc7
47 #define AZ6007_READ_IR 0xb4
62 .single_master =
true,
63 .enable_merr_cfg =
true,
64 .no_i2c_bridge =
false,
66 .mpeg_out_clk_strength = 0x02,
67 .qam_demod_parameter_count = 2,
68 .microcode_name =
"dvb-usb-terratec-h7-drxk.fw",
77 pr_debug(
"%s: %s\n", __func__, enable ?
"enable" :
"disable");
91 .tuner_address = 0x60,
101 usb_rcvctrlpipe(udev, 0),
104 value, index, b, blen, 5000);
106 pr_warn(
"usb read operation failed. (%d)\n", ret);
110 if (az6007_xfer_debug) {
113 print_hex_dump_bytes(
"az6007: payload: ",
121 u16 index,
u8 *b,
int blen)
129 ret = __az6007_read(d->
udev, req, value, index, b, blen);
136 static int __az6007_write(
struct usb_device *udev,
u8 req,
u16 value,
137 u16 index,
u8 *b,
int blen)
141 if (az6007_xfer_debug) {
144 print_hex_dump_bytes(
"az6007: payload: ",
149 pr_err(
"az6007: tried to write %d bytes, but I2C max size is 64 bytes\n",
155 usb_sndctrlpipe(udev, 0),
158 value, index, b, blen, 5000);
160 pr_err(
"usb write operation failed. (%d)\n", ret);
168 u16 index,
u8 *b,
int blen)
176 ret = __az6007_write(d->
udev, req, value, index, b, blen);
187 pr_debug(
"%s: %s\n", __func__, onoff ?
"enable" :
"disable");
189 return az6007_write(d, 0xbc, onoff, 0,
NULL, 0);
200 if (st->
data[1] == 0x44)
203 if ((st->
data[1] ^ st->
data[2]) == 0xff)
206 code = st->
data[1] << 8 | st->
data[2];
208 if ((st->
data[3] ^ st->
data[4]) == 0xff)
209 code = code << 8 | st->
data[3];
211 code = code << 16 | st->
data[3] << 8 | st->
data[4];
246 ret = az6007_read(d, req, value, index, b, blen);
248 pr_warn(
"usb in operation failed. (%d)\n", ret);
259 static int az6007_ci_write_attribute_mem(
struct dvb_ca_en50221 *ca,
273 pr_debug(
"%s(), slot %d\n", __func__, slot);
283 ret = az6007_write(d, req, value1, index,
NULL, blen);
285 pr_warn(
"usb out operation failed. (%d)\n", ret);
319 ret = az6007_read(d, req, value, index, b, blen);
321 pr_warn(
"usb in operation failed. (%d)\n", ret);
328 pr_debug(
"read cam data = %x from 0x%x\n", b[1], value);
359 ret = az6007_write(d, req, value1, index,
NULL, blen);
361 pr_warn(
"usb out operation failed. (%d)\n", ret);
390 ret = az6007_read(d, req, value, index, b, blen);
392 pr_warn(
"usb in operation failed. (%d)\n", ret);
401 static int az6007_ci_slot_reset(
struct dvb_ca_en50221 *ca,
int slot)
419 ret = az6007_write(d, req, value, index,
NULL, blen);
421 pr_warn(
"usb out operation failed. (%d)\n", ret);
431 ret = az6007_write(d, req, value, index,
NULL, blen);
433 pr_warn(
"usb out operation failed. (%d)\n", ret);
437 for (i = 0; i < 15; i++) {
440 if (CI_CamReady(ca, slot)) {
452 static int az6007_ci_slot_shutdown(
struct dvb_ca_en50221 *ca,
int slot)
457 static int az6007_ci_slot_ts_enable(
struct dvb_ca_en50221 *ca,
int slot)
475 ret = az6007_write(d, req, value, index,
NULL, blen);
477 pr_warn(
"usb out operation failed. (%d)\n", ret);
507 ret = az6007_read(d, req, value, index, b, blen);
509 pr_warn(
"usb in operation failed. (%d)\n", ret);
514 if (!ret && b[0] == 1) {
538 if (
NULL == state->
ca.data)
557 state->
ca.read_attribute_mem = az6007_ci_read_attribute_mem;
558 state->
ca.write_attribute_mem = az6007_ci_write_attribute_mem;
559 state->
ca.read_cam_control = az6007_ci_read_cam_control;
560 state->
ca.write_cam_control = az6007_ci_write_cam_control;
561 state->
ca.slot_reset = az6007_ci_slot_reset;
562 state->
ca.slot_shutdown = az6007_ci_slot_shutdown;
563 state->
ca.slot_ts_enable = az6007_ci_slot_ts_enable;
564 state->
ca.poll_slot_status = az6007_ci_poll_slot_status;
572 pr_err(
"Cannot initialize CI: Error %d.\n", ret);
592 pr_debug(
"%s: mac is %pM\n", __func__, mac);
609 adap->
fe[0]->sec_priv = adap;
611 adap->
fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
613 az6007_ci_init(adap);
622 pr_debug(
"attaching tuner mt2063\n");
625 if (adap->
fe[0]->ops.i2c_gate_ctrl)
626 adap->
fe[0]->ops.i2c_gate_ctrl(adap->
fe[0], 1);
628 &az6007_mt2063_config,
632 if (adap->
fe[0]->ops.i2c_gate_ctrl)
633 adap->
fe[0]->ops.i2c_gate_ctrl(adap->
fe[0], 0);
707 for (i = 0; i < num; i++) {
708 addr = msgs[
i].
addr << 1;
710 && (msgs[i].len == 1)
712 && (msgs[i + 1].
flags & I2C_M_RD)
713 && (msgs[i].addr == msgs[i + 1].addr)) {
719 if (az6007_xfer_debug)
721 addr, msgs[i].len, msgs[i + 1].len);
723 index = msgs[
i].
buf[0];
724 value = addr | (1 << 8);
725 length = 6 + msgs[i + 1].
len;
726 len = msgs[i + 1].
len;
727 ret = __az6007_read(d->
udev, req, value, index,
730 for (j = 0; j < len; j++)
731 msgs[i + 1].
buf[j] = st->
data[j + 5];
735 }
else if (!(msgs[i].
flags & I2C_M_RD)) {
737 if (az6007_xfer_debug)
741 index = msgs[
i].
buf[0];
742 value = addr | (1 << 8);
743 length = msgs[
i].
len - 1;
744 len = msgs[
i].
len - 1;
745 for (j = 0; j < len; j++)
746 st->
data[j] = msgs[i].
buf[j + 1];
747 ret = __az6007_write(d->
udev, req, value, index,
751 if (az6007_xfer_debug)
755 index = msgs[
i].
buf[0];
757 length = msgs[
i].
len + 6;
759 ret = __az6007_read(d->
udev, req, value, index,
761 for (j = 0; j < len; j++)
762 msgs[i].
buf[j] = st->
data[j + 5];
771 pr_info(
"%s ERROR: %i\n", __func__, ret);
783 .master_xfer = az6007_i2c_xfer,
784 .functionality = az6007_i2c_func,
792 pr_debug(
"Identifying az6007 state\n");
808 __az6007_write(d->
udev, 0x09, 1, 0,
NULL, 0);
809 __az6007_write(d->
udev, 0x00, 0, 0,
NULL, 0);
810 __az6007_write(d->
udev, 0x00, 0, 0,
NULL, 0);
814 ret ==
WARM ?
"warm" :
"cold");
827 pr_debug(
"Getting az6007 Remote Control properties\n");
830 rc->
query = az6007_rc_query;
839 pr_debug(
"Loading az6007 firmware\n");
846 .driver_name = KBUILD_MODNAME,
852 .i2c_algo = &az6007_i2c_algo,
853 .tuner_attach = az6007_tuner_attach,
854 .frontend_attach = az6007_frontend_attach,
855 .streaming_ctrl = az6007_streaming_ctrl,
856 .get_rc_config = az6007_get_rc_config,
857 .read_mac_address = az6007_read_mac_addr,
858 .download_firmware = az6007_download_firmware,
859 .identify_state = az6007_identify_state,
860 .power_ctrl = az6007_power_ctrl,
892 az6007_ci_init(adap);
897 static struct usb_driver az6007_usb_driver = {
898 .name = KBUILD_MODNAME,
899 .id_table = az6007_usb_table,
901 .disconnect = az6007_usb_disconnect,
908 .suspend = az6007_suspend,
909 .resume = az6007_resume,