mantis_vp2040.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. Mantis VP-2040 driver
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/signal.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include "dmxdev.h"
  20. #include "dvbdev.h"
  21. #include "dvb_demux.h"
  22. #include "dvb_frontend.h"
  23. #include "dvb_net.h"
  24. #include "tda1002x.h"
  25. #include "mantis_common.h"
  26. #include "mantis_ioc.h"
  27. #include "mantis_dvb.h"
  28. #include "mantis_vp2040.h"
  29. #define MANTIS_MODEL_NAME "VP-2040"
  30. #define MANTIS_DEV_TYPE "DVB-C"
  31. static struct tda1002x_config vp2040_tda1002x_cu1216_config = {
  32. .demod_address = 0x18 >> 1,
  33. .invert = 1,
  34. };
  35. static struct tda10023_config vp2040_tda10023_cu1216_config = {
  36. .demod_address = 0x18 >> 1,
  37. .invert = 1,
  38. };
  39. static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
  40. {
  41. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  42. struct mantis_pci *mantis = fe->dvb->priv;
  43. struct i2c_adapter *adapter = &mantis->adapter;
  44. u8 buf[6];
  45. struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
  46. int i;
  47. #define CU1216_IF 36125000
  48. #define TUNER_MUL 62500
  49. u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
  50. buf[0] = (div >> 8) & 0x7f;
  51. buf[1] = div & 0xff;
  52. buf[2] = 0xce;
  53. buf[3] = (p->frequency < 150000000 ? 0x01 :
  54. p->frequency < 445000000 ? 0x02 : 0x04);
  55. buf[4] = 0xde;
  56. buf[5] = 0x20;
  57. if (fe->ops.i2c_gate_ctrl)
  58. fe->ops.i2c_gate_ctrl(fe, 1);
  59. if (i2c_transfer(adapter, &msg, 1) != 1)
  60. return -EIO;
  61. /* wait for the pll lock */
  62. msg.flags = I2C_M_RD;
  63. msg.len = 1;
  64. for (i = 0; i < 20; i++) {
  65. if (fe->ops.i2c_gate_ctrl)
  66. fe->ops.i2c_gate_ctrl(fe, 1);
  67. if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
  68. break;
  69. msleep(10);
  70. }
  71. /* switch the charge pump to the lower current */
  72. msg.flags = 0;
  73. msg.len = 2;
  74. msg.buf = &buf[2];
  75. buf[2] &= ~0x40;
  76. if (fe->ops.i2c_gate_ctrl)
  77. fe->ops.i2c_gate_ctrl(fe, 1);
  78. if (i2c_transfer(adapter, &msg, 1) != 1)
  79. return -EIO;
  80. return 0;
  81. }
  82. static u8 read_pwm(struct mantis_pci *mantis)
  83. {
  84. struct i2c_adapter *adapter = &mantis->adapter;
  85. u8 b = 0xff;
  86. u8 pwm;
  87. struct i2c_msg msg[] = {
  88. {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
  89. {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
  90. };
  91. if ((i2c_transfer(adapter, msg, 2) != 2)
  92. || (pwm == 0xff))
  93. pwm = 0x48;
  94. return pwm;
  95. }
  96. static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
  97. {
  98. struct i2c_adapter *adapter = &mantis->adapter;
  99. int err = 0;
  100. err = mantis_frontend_power(mantis, POWER_ON);
  101. if (err == 0) {
  102. mantis_frontend_soft_reset(mantis);
  103. msleep(250);
  104. dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
  105. fe = dvb_attach(tda10021_attach, &vp2040_tda1002x_cu1216_config,
  106. adapter,
  107. read_pwm(mantis));
  108. if (fe) {
  109. dprintk(MANTIS_ERROR, 1,
  110. "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
  111. vp2040_tda1002x_cu1216_config.demod_address);
  112. } else {
  113. fe = dvb_attach(tda10023_attach, &vp2040_tda10023_cu1216_config,
  114. adapter,
  115. read_pwm(mantis));
  116. if (fe) {
  117. dprintk(MANTIS_ERROR, 1,
  118. "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
  119. vp2040_tda1002x_cu1216_config.demod_address);
  120. }
  121. }
  122. if (fe) {
  123. fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
  124. dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
  125. } else {
  126. return -1;
  127. }
  128. } else {
  129. dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
  130. adapter->name,
  131. err);
  132. return -EIO;
  133. }
  134. mantis->fe = fe;
  135. dprintk(MANTIS_DEBUG, 1, "Done!");
  136. return 0;
  137. }
  138. struct mantis_hwconfig vp2040_config = {
  139. .model_name = MANTIS_MODEL_NAME,
  140. .dev_type = MANTIS_DEV_TYPE,
  141. .ts_size = MANTIS_TS_204,
  142. .baud_rate = MANTIS_BAUD_9600,
  143. .parity = MANTIS_PARITY_NONE,
  144. .bytes = 0,
  145. .frontend_init = vp2040_frontend_init,
  146. .power = GPIF_A12,
  147. .reset = GPIF_A13,
  148. };