PageRenderTime 140ms CodeModel.GetById 60ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/media/dvb/mantis/mantis_vp2040.c

https://bitbucket.org/abioy/linux
C | 186 lines | 130 code | 35 blank | 21 comment | 23 complexity | 96418abe80a09cd05ad94857b6649cec MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
  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. struct tda1002x_config vp2040_tda1002x_cu1216_config = {
  32. .demod_address = 0x18 >> 1,
  33. .invert = 1,
  34. };
  35. 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, struct dvb_frontend_parameters *params)
  40. {
  41. struct mantis_pci *mantis = fe->dvb->priv;
  42. struct i2c_adapter *adapter = &mantis->adapter;
  43. u8 buf[6];
  44. struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
  45. int i;
  46. #define CU1216_IF 36125000
  47. #define TUNER_MUL 62500
  48. u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
  49. buf[0] = (div >> 8) & 0x7f;
  50. buf[1] = div & 0xff;
  51. buf[2] = 0xce;
  52. buf[3] = (params->frequency < 150000000 ? 0x01 :
  53. params->frequency < 445000000 ? 0x02 : 0x04);
  54. buf[4] = 0xde;
  55. buf[5] = 0x20;
  56. if (fe->ops.i2c_gate_ctrl)
  57. fe->ops.i2c_gate_ctrl(fe, 1);
  58. if (i2c_transfer(adapter, &msg, 1) != 1)
  59. return -EIO;
  60. /* wait for the pll lock */
  61. msg.flags = I2C_M_RD;
  62. msg.len = 1;
  63. for (i = 0; i < 20; i++) {
  64. if (fe->ops.i2c_gate_ctrl)
  65. fe->ops.i2c_gate_ctrl(fe, 1);
  66. if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
  67. break;
  68. msleep(10);
  69. }
  70. /* switch the charge pump to the lower current */
  71. msg.flags = 0;
  72. msg.len = 2;
  73. msg.buf = &buf[2];
  74. buf[2] &= ~0x40;
  75. if (fe->ops.i2c_gate_ctrl)
  76. fe->ops.i2c_gate_ctrl(fe, 1);
  77. if (i2c_transfer(adapter, &msg, 1) != 1)
  78. return -EIO;
  79. return 0;
  80. }
  81. static u8 read_pwm(struct mantis_pci *mantis)
  82. {
  83. struct i2c_adapter *adapter = &mantis->adapter;
  84. u8 b = 0xff;
  85. u8 pwm;
  86. struct i2c_msg msg[] = {
  87. {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
  88. {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
  89. };
  90. if ((i2c_transfer(adapter, msg, 2) != 2)
  91. || (pwm == 0xff))
  92. pwm = 0x48;
  93. return pwm;
  94. }
  95. static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
  96. {
  97. struct i2c_adapter *adapter = &mantis->adapter;
  98. int err = 0;
  99. err = mantis_frontend_power(mantis, POWER_ON);
  100. if (err == 0) {
  101. mantis_frontend_soft_reset(mantis);
  102. msleep(250);
  103. dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
  104. fe = tda10021_attach(&vp2040_tda1002x_cu1216_config,
  105. adapter,
  106. read_pwm(mantis));
  107. if (fe) {
  108. dprintk(MANTIS_ERROR, 1,
  109. "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
  110. vp2040_tda1002x_cu1216_config.demod_address);
  111. } else {
  112. fe = tda10023_attach(&vp2040_tda10023_cu1216_config,
  113. adapter,
  114. read_pwm(mantis));
  115. if (fe) {
  116. dprintk(MANTIS_ERROR, 1,
  117. "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
  118. vp2040_tda1002x_cu1216_config.demod_address);
  119. }
  120. }
  121. if (fe) {
  122. fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
  123. dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
  124. } else {
  125. return -1;
  126. }
  127. } else {
  128. dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
  129. adapter->name,
  130. err);
  131. return -EIO;
  132. }
  133. mantis->fe = fe;
  134. dprintk(MANTIS_DEBUG, 1, "Done!");
  135. return 0;
  136. }
  137. struct mantis_hwconfig vp2040_config = {
  138. .model_name = MANTIS_MODEL_NAME,
  139. .dev_type = MANTIS_DEV_TYPE,
  140. .ts_size = MANTIS_TS_204,
  141. .baud_rate = MANTIS_BAUD_9600,
  142. .parity = MANTIS_PARITY_NONE,
  143. .bytes = 0,
  144. .frontend_init = vp2040_frontend_init,
  145. .power = GPIF_A12,
  146. .reset = GPIF_A13,
  147. };