lnbp22.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * lnbp22.h - driver for lnb supply and control ic lnbp22
  3. *
  4. * Copyright (C) 2006 Dominik Kuhlen
  5. * Based on lnbp21 driver
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  23. *
  24. *
  25. * the project's page is at http://www.linuxtv.org
  26. */
  27. #include <linux/delay.h>
  28. #include <linux/errno.h>
  29. #include <linux/init.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/string.h>
  34. #include <linux/slab.h>
  35. #include "dvb_frontend.h"
  36. #include "lnbp22.h"
  37. static int debug;
  38. module_param(debug, int, 0644);
  39. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  40. #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
  41. struct lnbp22 {
  42. u8 config[4];
  43. struct i2c_adapter *i2c;
  44. };
  45. static int lnbp22_set_voltage(struct dvb_frontend *fe,
  46. enum fe_sec_voltage voltage)
  47. {
  48. struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
  49. struct i2c_msg msg = {
  50. .addr = 0x08,
  51. .flags = 0,
  52. .buf = (char *)&lnbp22->config,
  53. .len = sizeof(lnbp22->config),
  54. };
  55. dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__, voltage,
  56. SEC_VOLTAGE_18, SEC_VOLTAGE_13);
  57. lnbp22->config[3] = 0x60; /* Power down */
  58. switch (voltage) {
  59. case SEC_VOLTAGE_OFF:
  60. break;
  61. case SEC_VOLTAGE_13:
  62. lnbp22->config[3] |= LNBP22_EN;
  63. break;
  64. case SEC_VOLTAGE_18:
  65. lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
  66. break;
  67. default:
  68. return -EINVAL;
  69. }
  70. dprintk(1, "%s: 0x%02x)\n", __func__, lnbp22->config[3]);
  71. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  72. }
  73. static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  74. {
  75. struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
  76. struct i2c_msg msg = {
  77. .addr = 0x08,
  78. .flags = 0,
  79. .buf = (char *)&lnbp22->config,
  80. .len = sizeof(lnbp22->config),
  81. };
  82. dprintk(1, "%s: %d\n", __func__, (int)arg);
  83. if (arg)
  84. lnbp22->config[3] |= LNBP22_LLC;
  85. else
  86. lnbp22->config[3] &= ~LNBP22_LLC;
  87. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  88. }
  89. static void lnbp22_release(struct dvb_frontend *fe)
  90. {
  91. dprintk(1, "%s\n", __func__);
  92. /* LNBP power off */
  93. lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
  94. /* free data */
  95. kfree(fe->sec_priv);
  96. fe->sec_priv = NULL;
  97. }
  98. struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
  99. struct i2c_adapter *i2c)
  100. {
  101. struct lnbp22 *lnbp22 = kmalloc(sizeof(struct lnbp22), GFP_KERNEL);
  102. if (!lnbp22)
  103. return NULL;
  104. /* default configuration */
  105. lnbp22->config[0] = 0x00; /* ? */
  106. lnbp22->config[1] = 0x28; /* ? */
  107. lnbp22->config[2] = 0x48; /* ? */
  108. lnbp22->config[3] = 0x60; /* Power down */
  109. lnbp22->i2c = i2c;
  110. fe->sec_priv = lnbp22;
  111. /* detect if it is present or not */
  112. if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  113. dprintk(0, "%s LNBP22 not found\n", __func__);
  114. kfree(lnbp22);
  115. fe->sec_priv = NULL;
  116. return NULL;
  117. }
  118. /* install release callback */
  119. fe->ops.release_sec = lnbp22_release;
  120. /* override frontend ops */
  121. fe->ops.set_voltage = lnbp22_set_voltage;
  122. fe->ops.enable_high_lnb_voltage = lnbp22_enable_high_lnb_voltage;
  123. return fe;
  124. }
  125. EXPORT_SYMBOL(lnbp22_attach);
  126. MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
  127. MODULE_AUTHOR("Dominik Kuhlen");
  128. MODULE_LICENSE("GPL");