lnbp21.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * lnbp21.c - driver for lnb supply and control ic lnbp21
  3. *
  4. * Copyright (C) 2006, 2009 Oliver Endriss <o.endriss@gmx.de>
  5. * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
  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/string.h>
  33. #include <linux/slab.h>
  34. #include "dvb_frontend.h"
  35. #include "lnbp21.h"
  36. #include "lnbh24.h"
  37. struct lnbp21 {
  38. u8 config;
  39. u8 override_or;
  40. u8 override_and;
  41. struct i2c_adapter *i2c;
  42. u8 i2c_addr;
  43. };
  44. static int lnbp21_set_voltage(struct dvb_frontend *fe,
  45. enum fe_sec_voltage voltage)
  46. {
  47. struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
  48. struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
  49. .buf = &lnbp21->config,
  50. .len = sizeof(lnbp21->config) };
  51. lnbp21->config &= ~(LNBP21_VSEL | LNBP21_EN);
  52. switch(voltage) {
  53. case SEC_VOLTAGE_OFF:
  54. break;
  55. case SEC_VOLTAGE_13:
  56. lnbp21->config |= LNBP21_EN;
  57. break;
  58. case SEC_VOLTAGE_18:
  59. lnbp21->config |= (LNBP21_EN | LNBP21_VSEL);
  60. break;
  61. default:
  62. return -EINVAL;
  63. }
  64. lnbp21->config |= lnbp21->override_or;
  65. lnbp21->config &= lnbp21->override_and;
  66. return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
  67. }
  68. static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  69. {
  70. struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
  71. struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
  72. .buf = &lnbp21->config,
  73. .len = sizeof(lnbp21->config) };
  74. if (arg)
  75. lnbp21->config |= LNBP21_LLC;
  76. else
  77. lnbp21->config &= ~LNBP21_LLC;
  78. lnbp21->config |= lnbp21->override_or;
  79. lnbp21->config &= lnbp21->override_and;
  80. return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
  81. }
  82. static int lnbp21_set_tone(struct dvb_frontend *fe,
  83. enum fe_sec_tone_mode tone)
  84. {
  85. struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
  86. struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
  87. .buf = &lnbp21->config,
  88. .len = sizeof(lnbp21->config) };
  89. switch (tone) {
  90. case SEC_TONE_OFF:
  91. lnbp21->config &= ~LNBP21_TEN;
  92. break;
  93. case SEC_TONE_ON:
  94. lnbp21->config |= LNBP21_TEN;
  95. break;
  96. default:
  97. return -EINVAL;
  98. }
  99. lnbp21->config |= lnbp21->override_or;
  100. lnbp21->config &= lnbp21->override_and;
  101. return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
  102. }
  103. static void lnbp21_release(struct dvb_frontend *fe)
  104. {
  105. /* LNBP power off */
  106. lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF);
  107. /* free data */
  108. kfree(fe->sec_priv);
  109. fe->sec_priv = NULL;
  110. }
  111. static struct dvb_frontend *lnbx2x_attach(struct dvb_frontend *fe,
  112. struct i2c_adapter *i2c, u8 override_set,
  113. u8 override_clear, u8 i2c_addr, u8 config)
  114. {
  115. struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL);
  116. if (!lnbp21)
  117. return NULL;
  118. /* default configuration */
  119. lnbp21->config = config;
  120. lnbp21->i2c = i2c;
  121. lnbp21->i2c_addr = i2c_addr;
  122. fe->sec_priv = lnbp21;
  123. /* bits which should be forced to '1' */
  124. lnbp21->override_or = override_set;
  125. /* bits which should be forced to '0' */
  126. lnbp21->override_and = ~override_clear;
  127. /* detect if it is present or not */
  128. if (lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  129. kfree(lnbp21);
  130. return NULL;
  131. }
  132. /* install release callback */
  133. fe->ops.release_sec = lnbp21_release;
  134. /* override frontend ops */
  135. fe->ops.set_voltage = lnbp21_set_voltage;
  136. fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
  137. if (!(override_clear & LNBH24_TEN)) /*22kHz logic controlled by demod*/
  138. fe->ops.set_tone = lnbp21_set_tone;
  139. printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr);
  140. return fe;
  141. }
  142. struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
  143. struct i2c_adapter *i2c, u8 override_set,
  144. u8 override_clear, u8 i2c_addr)
  145. {
  146. return lnbx2x_attach(fe, i2c, override_set, override_clear,
  147. i2c_addr, LNBH24_TTX);
  148. }
  149. EXPORT_SYMBOL(lnbh24_attach);
  150. struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
  151. struct i2c_adapter *i2c, u8 override_set,
  152. u8 override_clear)
  153. {
  154. return lnbx2x_attach(fe, i2c, override_set, override_clear,
  155. 0x08, LNBP21_ISEL);
  156. }
  157. EXPORT_SYMBOL(lnbp21_attach);
  158. MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21, lnbh24");
  159. MODULE_AUTHOR("Oliver Endriss, Igor M. Liplianin");
  160. MODULE_LICENSE("GPL");