lgh06xf.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * lgh06xf.c - ATSC Tuner support for LG TDVS-H06xF
  3. *
  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. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include "dvb-pll.h"
  19. #include "lgh06xf.h"
  20. #define LG_H06XF_PLL_I2C_ADDR 0x61
  21. struct lgh06xf_priv {
  22. struct i2c_adapter *i2c;
  23. u32 frequency;
  24. };
  25. static int lgh06xf_release(struct dvb_frontend *fe)
  26. {
  27. kfree(fe->tuner_priv);
  28. fe->tuner_priv = NULL;
  29. return 0;
  30. }
  31. static int lgh06xf_set_params(struct dvb_frontend* fe,
  32. struct dvb_frontend_parameters* params)
  33. {
  34. struct lgh06xf_priv *priv = fe->tuner_priv;
  35. u8 buf[4];
  36. struct i2c_msg msg = { .addr = LG_H06XF_PLL_I2C_ADDR, .flags = 0,
  37. .buf = buf, .len = sizeof(buf) };
  38. u32 frequency;
  39. int result;
  40. if ((result = dvb_pll_configure(&dvb_pll_lg_tdvs_h06xf, buf,
  41. params->frequency, 0)) < 0)
  42. return result;
  43. else
  44. frequency = result;
  45. if (fe->ops.i2c_gate_ctrl)
  46. fe->ops.i2c_gate_ctrl(fe, 1);
  47. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  48. printk(KERN_WARNING "lgh06xf: %s error "
  49. "(addr %02x <- %02x, result = %i)\n",
  50. __FUNCTION__, buf[0], buf[1], result);
  51. if (result < 0)
  52. return result;
  53. else
  54. return -EREMOTEIO;
  55. }
  56. /* Set the Auxiliary Byte. */
  57. buf[0] = buf[2];
  58. buf[0] &= ~0x20;
  59. buf[0] |= 0x18;
  60. buf[1] = 0x50;
  61. msg.len = 2;
  62. if (fe->ops.i2c_gate_ctrl)
  63. fe->ops.i2c_gate_ctrl(fe, 1);
  64. if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
  65. printk(KERN_WARNING "lgh06xf: %s error "
  66. "(addr %02x <- %02x, result = %i)\n",
  67. __FUNCTION__, buf[0], buf[1], result);
  68. if (result < 0)
  69. return result;
  70. else
  71. return -EREMOTEIO;
  72. }
  73. priv->frequency = frequency;
  74. return 0;
  75. }
  76. static int lgh06xf_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  77. {
  78. struct lgh06xf_priv *priv = fe->tuner_priv;
  79. *frequency = priv->frequency;
  80. return 0;
  81. }
  82. static struct dvb_tuner_ops lgh06xf_tuner_ops = {
  83. .release = lgh06xf_release,
  84. .set_params = lgh06xf_set_params,
  85. .get_frequency = lgh06xf_get_frequency,
  86. };
  87. struct dvb_frontend* lgh06xf_attach(struct dvb_frontend *fe,
  88. struct i2c_adapter *i2c)
  89. {
  90. struct lgh06xf_priv *priv = NULL;
  91. priv = kzalloc(sizeof(struct lgh06xf_priv), GFP_KERNEL);
  92. if (priv == NULL)
  93. return NULL;
  94. priv->i2c = i2c;
  95. memcpy(&fe->ops.tuner_ops, &lgh06xf_tuner_ops,
  96. sizeof(struct dvb_tuner_ops));
  97. strlcpy(fe->ops.tuner_ops.info.name, dvb_pll_lg_tdvs_h06xf.name,
  98. sizeof(fe->ops.tuner_ops.info.name));
  99. fe->ops.tuner_ops.info.frequency_min = dvb_pll_lg_tdvs_h06xf.min;
  100. fe->ops.tuner_ops.info.frequency_max = dvb_pll_lg_tdvs_h06xf.max;
  101. fe->tuner_priv = priv;
  102. return fe;
  103. }
  104. EXPORT_SYMBOL(lgh06xf_attach);
  105. MODULE_DESCRIPTION("LG TDVS-H06xF ATSC Tuner support");
  106. MODULE_AUTHOR("Michael Krufky");
  107. MODULE_LICENSE("GPL");
  108. /*
  109. * Local variables:
  110. * c-basic-offset: 8
  111. * End:
  112. */