isl6405.c 4.3 KB

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