lnbp22.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * To obtain the license, point your browser to
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. *
  22. * the project's page is at https://linuxtv.org
  23. */
  24. #include <linux/delay.h>
  25. #include <linux/errno.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/string.h>
  31. #include <linux/slab.h>
  32. #include <media/dvb_frontend.h>
  33. #include "lnbp22.h"
  34. static int debug;
  35. module_param(debug, int, 0644);
  36. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  37. #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
  38. struct lnbp22 {
  39. u8 config[4];
  40. struct i2c_adapter *i2c;
  41. };
  42. static int lnbp22_set_voltage(struct dvb_frontend *fe,
  43. enum fe_sec_voltage voltage)
  44. {
  45. struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
  46. struct i2c_msg msg = {
  47. .addr = 0x08,
  48. .flags = 0,
  49. .buf = (char *)&lnbp22->config,
  50. .len = sizeof(lnbp22->config),
  51. };
  52. dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__, voltage,
  53. SEC_VOLTAGE_18, SEC_VOLTAGE_13);
  54. lnbp22->config[3] = 0x60; /* Power down */
  55. switch (voltage) {
  56. case SEC_VOLTAGE_OFF:
  57. break;
  58. case SEC_VOLTAGE_13:
  59. lnbp22->config[3] |= LNBP22_EN;
  60. break;
  61. case SEC_VOLTAGE_18:
  62. lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
  63. break;
  64. default:
  65. return -EINVAL;
  66. }
  67. dprintk(1, "%s: 0x%02x)\n", __func__, lnbp22->config[3]);
  68. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  69. }
  70. static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  71. {
  72. struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
  73. struct i2c_msg msg = {
  74. .addr = 0x08,
  75. .flags = 0,
  76. .buf = (char *)&lnbp22->config,
  77. .len = sizeof(lnbp22->config),
  78. };
  79. dprintk(1, "%s: %d\n", __func__, (int)arg);
  80. if (arg)
  81. lnbp22->config[3] |= LNBP22_LLC;
  82. else
  83. lnbp22->config[3] &= ~LNBP22_LLC;
  84. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  85. }
  86. static void lnbp22_release(struct dvb_frontend *fe)
  87. {
  88. dprintk(1, "%s\n", __func__);
  89. /* LNBP power off */
  90. lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
  91. /* free data */
  92. kfree(fe->sec_priv);
  93. fe->sec_priv = NULL;
  94. }
  95. struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
  96. struct i2c_adapter *i2c)
  97. {
  98. struct lnbp22 *lnbp22 = kmalloc(sizeof(struct lnbp22), GFP_KERNEL);
  99. if (!lnbp22)
  100. return NULL;
  101. /* default configuration */
  102. lnbp22->config[0] = 0x00; /* ? */
  103. lnbp22->config[1] = 0x28; /* ? */
  104. lnbp22->config[2] = 0x48; /* ? */
  105. lnbp22->config[3] = 0x60; /* Power down */
  106. lnbp22->i2c = i2c;
  107. fe->sec_priv = lnbp22;
  108. /* detect if it is present or not */
  109. if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  110. dprintk(0, "%s LNBP22 not found\n", __func__);
  111. kfree(lnbp22);
  112. fe->sec_priv = NULL;
  113. return NULL;
  114. }
  115. /* install release callback */
  116. fe->ops.release_sec = lnbp22_release;
  117. /* override frontend ops */
  118. fe->ops.set_voltage = lnbp22_set_voltage;
  119. fe->ops.enable_high_lnb_voltage = lnbp22_enable_high_lnb_voltage;
  120. return fe;
  121. }
  122. EXPORT_SYMBOL(lnbp22_attach);
  123. MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
  124. MODULE_AUTHOR("Dominik Kuhlen");
  125. MODULE_LICENSE("GPL");