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