lnbp22.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * lnbp22.h - driver for lnb supply and control ic lnbp22
  4. *
  5. * Copyright (C) 2006 Dominik Kuhlen
  6. * Based on lnbp21 driver
  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/moduleparam.h>
  16. #include <linux/string.h>
  17. #include <linux/slab.h>
  18. #include <media/dvb_frontend.h>
  19. #include "lnbp22.h"
  20. static int debug;
  21. module_param(debug, int, 0644);
  22. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  23. #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
  24. struct lnbp22 {
  25. u8 config[4];
  26. struct i2c_adapter *i2c;
  27. };
  28. static int lnbp22_set_voltage(struct dvb_frontend *fe,
  29. enum fe_sec_voltage voltage)
  30. {
  31. struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
  32. struct i2c_msg msg = {
  33. .addr = 0x08,
  34. .flags = 0,
  35. .buf = (char *)&lnbp22->config,
  36. .len = sizeof(lnbp22->config),
  37. };
  38. dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__, voltage,
  39. SEC_VOLTAGE_18, SEC_VOLTAGE_13);
  40. lnbp22->config[3] = 0x60; /* Power down */
  41. switch (voltage) {
  42. case SEC_VOLTAGE_OFF:
  43. break;
  44. case SEC_VOLTAGE_13:
  45. lnbp22->config[3] |= LNBP22_EN;
  46. break;
  47. case SEC_VOLTAGE_18:
  48. lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
  49. break;
  50. default:
  51. return -EINVAL;
  52. }
  53. dprintk(1, "%s: 0x%02x)\n", __func__, lnbp22->config[3]);
  54. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  55. }
  56. static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
  57. {
  58. struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
  59. struct i2c_msg msg = {
  60. .addr = 0x08,
  61. .flags = 0,
  62. .buf = (char *)&lnbp22->config,
  63. .len = sizeof(lnbp22->config),
  64. };
  65. dprintk(1, "%s: %d\n", __func__, (int)arg);
  66. if (arg)
  67. lnbp22->config[3] |= LNBP22_LLC;
  68. else
  69. lnbp22->config[3] &= ~LNBP22_LLC;
  70. return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
  71. }
  72. static void lnbp22_release(struct dvb_frontend *fe)
  73. {
  74. dprintk(1, "%s\n", __func__);
  75. /* LNBP power off */
  76. lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
  77. /* free data */
  78. kfree(fe->sec_priv);
  79. fe->sec_priv = NULL;
  80. }
  81. struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
  82. struct i2c_adapter *i2c)
  83. {
  84. struct lnbp22 *lnbp22 = kmalloc(sizeof(struct lnbp22), GFP_KERNEL);
  85. if (!lnbp22)
  86. return NULL;
  87. /* default configuration */
  88. lnbp22->config[0] = 0x00; /* ? */
  89. lnbp22->config[1] = 0x28; /* ? */
  90. lnbp22->config[2] = 0x48; /* ? */
  91. lnbp22->config[3] = 0x60; /* Power down */
  92. lnbp22->i2c = i2c;
  93. fe->sec_priv = lnbp22;
  94. /* detect if it is present or not */
  95. if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
  96. dprintk(0, "%s LNBP22 not found\n", __func__);
  97. kfree(lnbp22);
  98. fe->sec_priv = NULL;
  99. return NULL;
  100. }
  101. /* install release callback */
  102. fe->ops.release_sec = lnbp22_release;
  103. /* override frontend ops */
  104. fe->ops.set_voltage = lnbp22_set_voltage;
  105. fe->ops.enable_high_lnb_voltage = lnbp22_enable_high_lnb_voltage;
  106. return fe;
  107. }
  108. EXPORT_SYMBOL_GPL(lnbp22_attach);
  109. MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
  110. MODULE_AUTHOR("Dominik Kuhlen");
  111. MODULE_LICENSE("GPL");