Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * lnbp21.c - driver for lnb supply and control ic lnbp21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006, 2009 Oliver Endriss <o.endriss@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
^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/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <media/dvb_frontend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "lnbp21.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "lnbh24.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct lnbp21 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u8			config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u8			override_or;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	u8			override_and;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct i2c_adapter	*i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	u8			i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int lnbp21_set_voltage(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			      enum fe_sec_voltage voltage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct i2c_msg msg = {	.addr = lnbp21->i2c_addr, .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 				.buf = &lnbp21->config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 				.len = sizeof(lnbp21->config) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	lnbp21->config &= ~(LNBP21_VSEL | LNBP21_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	switch(voltage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	case SEC_VOLTAGE_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	case SEC_VOLTAGE_13:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		lnbp21->config |= LNBP21_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	case SEC_VOLTAGE_18:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		lnbp21->config |= (LNBP21_EN | LNBP21_VSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	lnbp21->config |= lnbp21->override_or;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	lnbp21->config &= lnbp21->override_and;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct i2c_msg msg = {	.addr = lnbp21->i2c_addr, .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				.buf = &lnbp21->config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				.len = sizeof(lnbp21->config) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		lnbp21->config |= LNBP21_LLC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		lnbp21->config &= ~LNBP21_LLC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	lnbp21->config |= lnbp21->override_or;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	lnbp21->config &= lnbp21->override_and;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static int lnbp21_set_tone(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			   enum fe_sec_tone_mode tone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct i2c_msg msg = {	.addr = lnbp21->i2c_addr, .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				.buf = &lnbp21->config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				.len = sizeof(lnbp21->config) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	switch (tone) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	case SEC_TONE_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		lnbp21->config &= ~LNBP21_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case SEC_TONE_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		lnbp21->config |= LNBP21_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -EINVAL;
^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) 	lnbp21->config |= lnbp21->override_or;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	lnbp21->config &= lnbp21->override_and;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void lnbp21_release(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* LNBP power off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* free data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	kfree(fe->sec_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	fe->sec_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static struct dvb_frontend *lnbx2x_attach(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				struct i2c_adapter *i2c, u8 override_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				u8 override_clear, u8 i2c_addr, u8 config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!lnbp21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* default configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	lnbp21->config = config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	lnbp21->i2c = i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	lnbp21->i2c_addr = i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	fe->sec_priv = lnbp21;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* bits which should be forced to '1' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	lnbp21->override_or = override_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* bits which should be forced to '0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	lnbp21->override_and = ~override_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* detect if it is present or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		kfree(lnbp21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/* install release callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	fe->ops.release_sec = lnbp21_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* override frontend ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	fe->ops.set_voltage = lnbp21_set_voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!(override_clear & LNBH24_TEN)) /*22kHz logic controlled by demod*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		fe->ops.set_tone = lnbp21_set_tone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				struct i2c_adapter *i2c, u8 override_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				u8 override_clear, u8 i2c_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return lnbx2x_attach(fe, i2c, override_set, override_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 							i2c_addr, LNBH24_TTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) EXPORT_SYMBOL(lnbh24_attach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				struct i2c_adapter *i2c, u8 override_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				u8 override_clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return lnbx2x_attach(fe, i2c, override_set, override_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 							0x08, LNBP21_ISEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL(lnbp21_attach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21, lnbh24");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) MODULE_AUTHOR("Oliver Endriss, Igor M. Liplianin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) MODULE_LICENSE("GPL");