mantis_vp2033.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. Mantis VP-2033 driver
  4. Copyright (C) Manu Abraham ([email protected])
  5. */
  6. #include <linux/signal.h>
  7. #include <linux/sched.h>
  8. #include <linux/interrupt.h>
  9. #include <media/dmxdev.h>
  10. #include <media/dvbdev.h>
  11. #include <media/dvb_demux.h>
  12. #include <media/dvb_frontend.h>
  13. #include <media/dvb_net.h>
  14. #include "tda1002x.h"
  15. #include "mantis_common.h"
  16. #include "mantis_ioc.h"
  17. #include "mantis_dvb.h"
  18. #include "mantis_vp2033.h"
  19. #define MANTIS_MODEL_NAME "VP-2033"
  20. #define MANTIS_DEV_TYPE "DVB-C"
  21. static struct tda1002x_config vp2033_tda1002x_cu1216_config = {
  22. .demod_address = 0x18 >> 1,
  23. .invert = 1,
  24. };
  25. static struct tda10023_config vp2033_tda10023_cu1216_config = {
  26. .demod_address = 0x18 >> 1,
  27. .invert = 1,
  28. };
  29. static u8 read_pwm(struct mantis_pci *mantis)
  30. {
  31. struct i2c_adapter *adapter = &mantis->adapter;
  32. u8 b = 0xff;
  33. u8 pwm;
  34. struct i2c_msg msg[] = {
  35. {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
  36. {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
  37. };
  38. if ((i2c_transfer(adapter, msg, 2) != 2)
  39. || (pwm == 0xff))
  40. pwm = 0x48;
  41. return pwm;
  42. }
  43. static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
  44. {
  45. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  46. struct mantis_pci *mantis = fe->dvb->priv;
  47. struct i2c_adapter *adapter = &mantis->adapter;
  48. u8 buf[6];
  49. struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
  50. int i;
  51. #define CU1216_IF 36125000
  52. #define TUNER_MUL 62500
  53. u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
  54. buf[0] = (div >> 8) & 0x7f;
  55. buf[1] = div & 0xff;
  56. buf[2] = 0xce;
  57. buf[3] = (p->frequency < 150000000 ? 0x01 :
  58. p->frequency < 445000000 ? 0x02 : 0x04);
  59. buf[4] = 0xde;
  60. buf[5] = 0x20;
  61. if (fe->ops.i2c_gate_ctrl)
  62. fe->ops.i2c_gate_ctrl(fe, 1);
  63. if (i2c_transfer(adapter, &msg, 1) != 1)
  64. return -EIO;
  65. /* wait for the pll lock */
  66. msg.flags = I2C_M_RD;
  67. msg.len = 1;
  68. for (i = 0; i < 20; i++) {
  69. if (fe->ops.i2c_gate_ctrl)
  70. fe->ops.i2c_gate_ctrl(fe, 1);
  71. if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
  72. break;
  73. msleep(10);
  74. }
  75. /* switch the charge pump to the lower current */
  76. msg.flags = 0;
  77. msg.len = 2;
  78. msg.buf = &buf[2];
  79. buf[2] &= ~0x40;
  80. if (fe->ops.i2c_gate_ctrl)
  81. fe->ops.i2c_gate_ctrl(fe, 1);
  82. if (i2c_transfer(adapter, &msg, 1) != 1)
  83. return -EIO;
  84. return 0;
  85. }
  86. static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
  87. {
  88. struct i2c_adapter *adapter = &mantis->adapter;
  89. int err = 0;
  90. err = mantis_frontend_power(mantis, POWER_ON);
  91. if (err == 0) {
  92. mantis_frontend_soft_reset(mantis);
  93. msleep(250);
  94. dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
  95. fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,
  96. adapter,
  97. read_pwm(mantis));
  98. if (fe) {
  99. dprintk(MANTIS_ERROR, 1,
  100. "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
  101. vp2033_tda1002x_cu1216_config.demod_address);
  102. } else {
  103. fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,
  104. adapter,
  105. read_pwm(mantis));
  106. if (fe) {
  107. dprintk(MANTIS_ERROR, 1,
  108. "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
  109. vp2033_tda1002x_cu1216_config.demod_address);
  110. }
  111. }
  112. if (fe) {
  113. fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
  114. dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
  115. } else {
  116. return -1;
  117. }
  118. } else {
  119. dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
  120. adapter->name,
  121. err);
  122. return -EIO;
  123. }
  124. mantis->fe = fe;
  125. dprintk(MANTIS_DEBUG, 1, "Done!");
  126. return 0;
  127. }
  128. struct mantis_hwconfig vp2033_config = {
  129. .model_name = MANTIS_MODEL_NAME,
  130. .dev_type = MANTIS_DEV_TYPE,
  131. .ts_size = MANTIS_TS_204,
  132. .baud_rate = MANTIS_BAUD_9600,
  133. .parity = MANTIS_PARITY_NONE,
  134. .bytes = 0,
  135. .frontend_init = vp2033_frontend_init,
  136. .power = GPIF_A12,
  137. .reset = GPIF_A13,
  138. };