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)      Driver for Philips tda8262/tda8263 DVBS Silicon tuners
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)      (c) 2006 Andrew de Quincey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/dvb/frontend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "tda826x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define dprintk(args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		if (debug) printk(KERN_DEBUG "tda826x: " args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct tda826x_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	/* i2c details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int i2c_address;
^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 has_loopthrough:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	u32 frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static void tda826x_release(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	kfree(fe->tuner_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	fe->tuner_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int tda826x_sleep(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct tda826x_priv *priv = fe->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u8 buf [] = { 0x00, 0x8d };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dprintk("%s:\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (!priv->has_loopthrough)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		buf[1] = 0xad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		fe->ops.i2c_gate_ctrl(fe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		dprintk("%s: i2c error\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		fe->ops.i2c_gate_ctrl(fe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return (ret == 1) ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int tda826x_set_params(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct tda826x_priv *priv = fe->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u32 div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u32 ksyms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32 bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u8 buf [11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	dprintk("%s:\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	div = (p->frequency + (1000-1)) / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* BW = ((1 + RO) * SR/2 + 5) * 1.3      [SR in MSPS, BW in MHz] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* with R0 = 0.35 and some transformations: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ksyms = p->symbol_rate / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	bandwidth = (878 * ksyms + 6500000) / 1000000 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (bandwidth < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		bandwidth = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	else if (bandwidth > 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		bandwidth = 36;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	buf[0] = 0x00; // subaddress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	buf[1] = 0x09; // powerdown RSSI + the magic value 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!priv->has_loopthrough)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		buf[1] |= 0x20; // power down loopthrough if not needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	buf[3] = div >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	buf[4] = div << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	buf[5] = ((bandwidth - 5) << 3) | 7; /* baseband cut-off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	buf[7] = 0x83; // charge pumps at high, tests off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		fe->ops.i2c_gate_ctrl(fe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		dprintk("%s: i2c error\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		fe->ops.i2c_gate_ctrl(fe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	priv->frequency = div * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return (ret == 1) ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct tda826x_priv *priv = fe->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	*frequency = priv->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct dvb_tuner_ops tda826x_tuner_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		.name = "Philips TDA826X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		.frequency_min_hz =  950 * MHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.frequency_max_hz = 2175 * MHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.release = tda826x_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.sleep = tda826x_sleep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.set_params = tda826x_set_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.get_frequency = tda826x_get_frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct tda826x_priv *priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	u8 b1 [] = { 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct i2c_msg msg[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		{ .addr = addr, .flags = 0,        .buf = NULL, .len = 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		{ .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	dprintk("%s:\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		fe->ops.i2c_gate_ctrl(fe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ret = i2c_transfer (i2c, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (fe->ops.i2c_gate_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		fe->ops.i2c_gate_ctrl(fe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!(b1[1] & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (priv == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	priv->i2c_address = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	priv->i2c = i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	priv->has_loopthrough = has_loopthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	fe->tuner_priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL(tda826x_attach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) MODULE_DESCRIPTION("DVB TDA826x driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_AUTHOR("Andrew de Quincey");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) MODULE_LICENSE("GPL");