mantis_vp2033.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. Mantis VP-2033 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_vp2033.h"
  29. #define MANTIS_MODEL_NAME "VP-2033"
  30. #define MANTIS_DEV_TYPE "DVB-C"
  31. static struct tda1002x_config vp2033_tda1002x_cu1216_config = {
  32. .demod_address = 0x18 >> 1,
  33. .invert = 1,
  34. };
  35. static struct tda10023_config vp2033_tda10023_cu1216_config = {
  36. .demod_address = 0x18 >> 1,
  37. .invert = 1,
  38. };
  39. static u8 read_pwm(struct mantis_pci *mantis)
  40. {
  41. struct i2c_adapter *adapter = &mantis->adapter;
  42. u8 b = 0xff;
  43. u8 pwm;
  44. struct i2c_msg msg[] = {
  45. {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
  46. {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
  47. };
  48. if ((i2c_transfer(adapter, msg, 2) != 2)
  49. || (pwm == 0xff))
  50. pwm = 0x48;
  51. return pwm;
  52. }
  53. static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
  54. {
  55. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  56. struct mantis_pci *mantis = fe->dvb->priv;
  57. struct i2c_adapter *adapter = &mantis->adapter;
  58. u8 buf[6];
  59. struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
  60. int i;
  61. #define CU1216_IF 36125000
  62. #define TUNER_MUL 62500
  63. u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
  64. buf[0] = (div >> 8) & 0x7f;
  65. buf[1] = div & 0xff;
  66. buf[2] = 0xce;
  67. buf[3] = (p->frequency < 150000000 ? 0x01 :
  68. p->frequency < 445000000 ? 0x02 : 0x04);
  69. buf[4] = 0xde;
  70. buf[5] = 0x20;
  71. if (fe->ops.i2c_gate_ctrl)
  72. fe->ops.i2c_gate_ctrl(fe, 1);
  73. if (i2c_transfer(adapter, &msg, 1) != 1)
  74. return -EIO;
  75. /* wait for the pll lock */
  76. msg.flags = I2C_M_RD;
  77. msg.len = 1;
  78. for (i = 0; i < 20; i++) {
  79. if (fe->ops.i2c_gate_ctrl)
  80. fe->ops.i2c_gate_ctrl(fe, 1);
  81. if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
  82. break;
  83. msleep(10);
  84. }
  85. /* switch the charge pump to the lower current */
  86. msg.flags = 0;
  87. msg.len = 2;
  88. msg.buf = &buf[2];
  89. buf[2] &= ~0x40;
  90. if (fe->ops.i2c_gate_ctrl)
  91. fe->ops.i2c_gate_ctrl(fe, 1);
  92. if (i2c_transfer(adapter, &msg, 1) != 1)
  93. return -EIO;
  94. return 0;
  95. }
  96. static int vp2033_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, &vp2033_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. vp2033_tda1002x_cu1216_config.demod_address);
  112. } else {
  113. fe = dvb_attach(tda10023_attach, &vp2033_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. vp2033_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 vp2033_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 = vp2033_frontend_init,
  146. .power = GPIF_A12,
  147. .reset = GPIF_A13,
  148. };