isl6405.c 4.1 KB

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