isl6405.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * isl6405.c - driver for dual lnb supply and control ic ISL6405
  4. *
  5. * Copyright (C) 2008 Hartmut Hackmann
  6. * Copyright (C) 2006 Oliver Endriss
  7. *
  8. * the project's page is at https://linuxtv.org
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/errno.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/string.h>
  16. #include <linux/slab.h>
  17. #include <media/dvb_frontend.h>
  18. #include "isl6405.h"
  19. struct isl6405 {
  20. u8 config;
  21. u8 override_or;
  22. u8 override_and;
  23. struct i2c_adapter *i2c;
  24. u8 i2c_addr;
  25. };
  26. static int isl6405_set_voltage(struct dvb_frontend *fe,
  27. enum fe_sec_voltage voltage)
  28. {
  29. struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv;
  30. struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0,
  31. .buf = &isl6405->config,
  32. .len = sizeof(isl6405->config) };
  33. if (isl6405->override_or & 0x80) {
  34. isl6405->config &= ~(ISL6405_VSEL2 | ISL6405_EN2);
  35. switch (voltage) {
  36. case SEC_VOLTAGE_OFF:
  37. break;
  38. case SEC_VOLTAGE_13:
  39. isl6405->config |= ISL6405_EN2;
  40. break;
  41. case SEC_VOLTAGE_18:
  42. isl6405->config |= (ISL6405_EN2 | ISL6405_VSEL2);
  43. break;
  44. default:
  45. return -EINVAL;
  46. }
  47. } else {
  48. isl6405->config &= ~(ISL6405_VSEL1 | ISL6405_EN1);
  49. switch (voltage) {
  50. case SEC_VOLTAGE_OFF:
  51. break;
  52. case SEC_VOLTAGE_13:
  53. isl6405->config |= ISL6405_EN1;
  54. break;
  55. case SEC_VOLTAGE_18:
  56. isl6405->config |= (ISL6405_EN1 | ISL6405_VSEL1);
  57. break;
  58. default:
  59. return -EINVAL;
  60. }
  61. }
  62. isl6405->config |= isl6405->override_or;
  63. isl6405->config &= isl6405->override_and;
  64. return (i2c_transfer(isl6405->i2c, &msg, 1) == 1) ? 0 : -EIO;
  65. }
  66. static int isl6405_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  67. {
  68. struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv;
  69. struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0,
  70. .buf = &isl6405->config,
  71. .len = sizeof(isl6405->config) };
  72. if (isl6405->override_or & 0x80) {
  73. if (arg)
  74. isl6405->config |= ISL6405_LLC2;
  75. else
  76. isl6405->config &= ~ISL6405_LLC2;
  77. } else {
  78. if (arg)
  79. isl6405->config |= ISL6405_LLC1;
  80. else
  81. isl6405->config &= ~ISL6405_LLC1;
  82. }
  83. isl6405->config |= isl6405->override_or;
  84. isl6405->config &= isl6405->override_and;
  85. return (i2c_transfer(isl6405->i2c, &msg, 1) == 1) ? 0 : -EIO;
  86. }
  87. static void isl6405_release(struct dvb_frontend *fe)
  88. {
  89. /* power off */
  90. isl6405_set_voltage(fe, SEC_VOLTAGE_OFF);
  91. /* free */
  92. kfree(fe->sec_priv);
  93. fe->sec_priv = NULL;
  94. }
  95. struct dvb_frontend *isl6405_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c,
  96. u8 i2c_addr, u8 override_set, u8 override_clear)
  97. {
  98. struct isl6405 *isl6405 = kmalloc(sizeof(struct isl6405), GFP_KERNEL);
  99. if (!isl6405)
  100. return NULL;
  101. /* default configuration */
  102. if (override_set & 0x80)
  103. isl6405->config = ISL6405_ISEL2;
  104. else
  105. isl6405->config = ISL6405_ISEL1;
  106. isl6405->i2c = i2c;
  107. isl6405->i2c_addr = i2c_addr;
  108. fe->sec_priv = isl6405;
  109. /* bits which should be forced to '1' */
  110. isl6405->override_or = override_set;
  111. /* bits which should be forced to '0' */
  112. isl6405->override_and = ~override_clear;
  113. /* detect if it is present or not */
  114. if (isl6405_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  115. kfree(isl6405);
  116. fe->sec_priv = NULL;
  117. return NULL;
  118. }
  119. /* install release callback */
  120. fe->ops.release_sec = isl6405_release;
  121. /* override frontend ops */
  122. fe->ops.set_voltage = isl6405_set_voltage;
  123. fe->ops.enable_high_lnb_voltage = isl6405_enable_high_lnb_voltage;
  124. return fe;
  125. }
  126. EXPORT_SYMBOL_GPL(isl6405_attach);
  127. MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6405");
  128. MODULE_AUTHOR("Hartmut Hackmann & Oliver Endriss");
  129. MODULE_LICENSE("GPL");