isl6421.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * isl6421.h - driver for lnb supply and control ic ISL6421
  3. *
  4. * Copyright (C) 2006 Andrew de Quincey
  5. * Copyright (C) 2006 Oliver Endriss
  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 "isl6421.h"
  36. struct isl6421 {
  37. u8 config;
  38. u8 override_or;
  39. u8 override_and;
  40. struct i2c_adapter *i2c;
  41. u8 i2c_addr;
  42. };
  43. static int isl6421_set_voltage(struct dvb_frontend *fe,
  44. enum fe_sec_voltage voltage)
  45. {
  46. struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
  47. struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
  48. .buf = &isl6421->config,
  49. .len = sizeof(isl6421->config) };
  50. isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
  51. switch(voltage) {
  52. case SEC_VOLTAGE_OFF:
  53. break;
  54. case SEC_VOLTAGE_13:
  55. isl6421->config |= ISL6421_EN1;
  56. break;
  57. case SEC_VOLTAGE_18:
  58. isl6421->config |= (ISL6421_EN1 | ISL6421_VSEL1);
  59. break;
  60. default:
  61. return -EINVAL;
  62. }
  63. isl6421->config |= isl6421->override_or;
  64. isl6421->config &= isl6421->override_and;
  65. return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
  66. }
  67. static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  68. {
  69. struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
  70. struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
  71. .buf = &isl6421->config,
  72. .len = sizeof(isl6421->config) };
  73. if (arg)
  74. isl6421->config |= ISL6421_LLC1;
  75. else
  76. isl6421->config &= ~ISL6421_LLC1;
  77. isl6421->config |= isl6421->override_or;
  78. isl6421->config &= isl6421->override_and;
  79. return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
  80. }
  81. static int isl6421_set_tone(struct dvb_frontend *fe,
  82. enum fe_sec_tone_mode tone)
  83. {
  84. struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
  85. struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
  86. .buf = &isl6421->config,
  87. .len = sizeof(isl6421->config) };
  88. switch (tone) {
  89. case SEC_TONE_ON:
  90. isl6421->config |= ISL6421_ENT1;
  91. break;
  92. case SEC_TONE_OFF:
  93. isl6421->config &= ~ISL6421_ENT1;
  94. break;
  95. default:
  96. return -EINVAL;
  97. }
  98. isl6421->config |= isl6421->override_or;
  99. isl6421->config &= isl6421->override_and;
  100. return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
  101. }
  102. static void isl6421_release(struct dvb_frontend *fe)
  103. {
  104. /* power off */
  105. isl6421_set_voltage(fe, SEC_VOLTAGE_OFF);
  106. /* free */
  107. kfree(fe->sec_priv);
  108. fe->sec_priv = NULL;
  109. }
  110. struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
  111. u8 override_set, u8 override_clear, bool override_tone)
  112. {
  113. struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL);
  114. if (!isl6421)
  115. return NULL;
  116. /* default configuration */
  117. isl6421->config = ISL6421_ISEL1;
  118. isl6421->i2c = i2c;
  119. isl6421->i2c_addr = i2c_addr;
  120. fe->sec_priv = isl6421;
  121. /* bits which should be forced to '1' */
  122. isl6421->override_or = override_set;
  123. /* bits which should be forced to '0' */
  124. isl6421->override_and = ~override_clear;
  125. /* detect if it is present or not */
  126. if (isl6421_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  127. kfree(isl6421);
  128. fe->sec_priv = NULL;
  129. return NULL;
  130. }
  131. /* install release callback */
  132. fe->ops.release_sec = isl6421_release;
  133. /* override frontend ops */
  134. fe->ops.set_voltage = isl6421_set_voltage;
  135. fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage;
  136. if (override_tone)
  137. fe->ops.set_tone = isl6421_set_tone;
  138. return fe;
  139. }
  140. EXPORT_SYMBOL(isl6421_attach);
  141. MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6421");
  142. MODULE_AUTHOR("Andrew de Quincey & Oliver Endriss");
  143. MODULE_LICENSE("GPL");