mantis_vp2033.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Mantis VP-2033 driver
  3. Copyright (C) 2005, 2006 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 "mantis_common.h"
  17. #include "mantis_vp2033.h"
  18. #define MANTIS_MODEL_NAME "VP-2033"
  19. #define MANTIS_DEV_TYPE "DVB-C"
  20. struct mantis_hwconfig vp2033_mantis_config = {
  21. .model_name = MANTIS_MODEL_NAME,
  22. .dev_type = MANTIS_DEV_TYPE,
  23. .ts_size = MANTIS_TS_204,
  24. };
  25. struct tda1002x_config philips_cu1216_config = {
  26. .demod_address = 0x18 >> 1,
  27. .invert = 1,
  28. };
  29. u8 read_pwm(struct mantis_pci *mantis)
  30. {
  31. u8 b = 0xff;
  32. u8 pwm;
  33. struct i2c_msg msg[] = {
  34. {.addr = 0x50,.flags = 0,.buf = &b,.len = 1},
  35. {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1}
  36. };
  37. if ((i2c_transfer(&mantis->adapter, msg, 2) != 2)
  38. || (pwm == 0xff))
  39. pwm = 0x48;
  40. return pwm;
  41. }
  42. int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  43. {
  44. struct mantis_pci *mantis = fe->dvb->priv;
  45. u8 buf[6];
  46. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  47. int i;
  48. #define CU1216_IF 36125000
  49. #define TUNER_MUL 62500
  50. u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
  51. buf[0] = (div >> 8) & 0x7f;
  52. buf[1] = div & 0xff;
  53. buf[2] = 0xce;
  54. buf[3] = (params->frequency < 150000000 ? 0x01 :
  55. params->frequency < 445000000 ? 0x02 : 0x04);
  56. buf[4] = 0xde;
  57. buf[5] = 0x20;
  58. if (fe->ops.i2c_gate_ctrl)
  59. fe->ops.i2c_gate_ctrl(fe, 1);
  60. if (i2c_transfer(&mantis->adapter, &msg, 1) != 1)
  61. return -EIO;
  62. /* wait for the pll lock */
  63. msg.flags = I2C_M_RD;
  64. msg.len = 1;
  65. for (i = 0; i < 20; i++) {
  66. if (fe->ops.i2c_gate_ctrl)
  67. fe->ops.i2c_gate_ctrl(fe, 1);
  68. if (i2c_transfer(&mantis->adapter, &msg, 1) == 1 && (buf[0] & 0x40))
  69. break;
  70. msleep(10);
  71. }
  72. /* switch the charge pump to the lower current */
  73. msg.flags = 0;
  74. msg.len = 2;
  75. msg.buf = &buf[2];
  76. buf[2] &= ~0x40;
  77. if (fe->ops.i2c_gate_ctrl)
  78. fe->ops.i2c_gate_ctrl(fe, 1);
  79. if (i2c_transfer(&mantis->adapter, &msg, 1) != 1)
  80. return -EIO;
  81. return 0;
  82. }