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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Common methods for dibusb-based-receivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
^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) #include "dibusb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /* 3000MC/P stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) // Config Adjacent channels  Perf -cal22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static struct dibx000_agc_config dib3000p_mt2060_agc_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	.band_caps = BAND_VHF | BAND_UHF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	.setup     = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	.agc1_max = 48497,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.agc1_min = 23593,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	.agc2_max = 46531,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.agc2_min = 24904,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.agc1_pt1 = 0x65,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.agc1_pt2 = 0x69,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	.agc1_slope1 = 0x51,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.agc1_slope2 = 0x27,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.agc2_pt1 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.agc2_pt2 = 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.agc2_slope1 = 0x35,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.agc2_slope2 = 0x37,
^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 struct dib3000mc_config stk3000p_dib3000p_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	&dib3000p_mt2060_agc_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.max_time     = 0x196,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.ln_adc_level = 0x1cc7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.output_mpeg2_in_188_bytes = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.agc_command1 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.agc_command2 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.band_caps = BAND_VHF | BAND_UHF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.setup     = (1 << 8) | (5 << 5) | (1 << 4) | (1 << 3) | (0 << 2) | (2 << 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.agc1_max = 56361,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.agc1_min = 22282,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.agc2_max = 47841,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.agc2_min = 36045,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.agc1_pt1 = 0x3b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.agc1_pt2 = 0x6b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.agc1_slope1 = 0x55,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.agc1_slope2 = 0x1d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.agc2_pt1 = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.agc2_pt2 = 0x0a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.agc2_slope1 = 0x95,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.agc2_slope2 = 0x1e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct dib3000mc_config mod3000p_dib3000p_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	&dib3000p_panasonic_agc_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.max_time     = 0x51,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.ln_adc_level = 0x1cc7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.output_mpeg2_in_188_bytes = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.agc_command1 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.agc_command2 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) int dibusb_dib3000mc_frontend_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	    le16_to_cpu(adap->dev->udev->descriptor.idProduct) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			USB_PID_LITEON_DVB_T_WARM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					 &adap->dev->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 					 DEFAULT_DIB3000P_I2C_ADDRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					 &mod3000p_dib3000p_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if ((adap->fe_adap[0].fe) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 						 &adap->dev->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 						 DEFAULT_DIB3000MC_I2C_ADDRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 						 &mod3000p_dib3000p_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if ((adap->fe_adap[0].fe) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (adap->priv != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			struct dibusb_state *st = adap->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			st->ops.pid_parse = dib3000mc_pid_parse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			st->ops.pid_ctrl  = dib3000mc_pid_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static struct mt2060_config stk3000p_mt2060_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct dibusb_state *st = adap->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	u8 a,b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	u16 if1 = 1220;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct i2c_adapter *tun_i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	// First IF calibration for Liteon Sticks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_LITEON &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	    le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_LITEON_DVB_T_WARM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		dibusb_read_eeprom_byte(adap->dev,0x7E,&a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		dibusb_read_eeprom_byte(adap->dev,0x7F,&b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (a == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			if1 += b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		else if (a == 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			if1 -= b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			warn("LITE-ON DVB-T: Strange IF1 calibration :%2X %2X\n", a, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	} else if (le16_to_cpu(adap->dev->udev->descriptor.idVendor) == USB_VID_DIBCOM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		   le16_to_cpu(adap->dev->udev->descriptor.idProduct) == USB_PID_DIBCOM_MOD3001_WARM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		u8 desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		dibusb_read_eeprom_byte(adap->dev, 7, &desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		if (desc == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			a = 127;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				dibusb_read_eeprom_byte(adap->dev, a, &desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				a--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			} while (a > 7 && (desc == 0xff || desc == 0x00));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			if (desc & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				if1 -= (0xff - desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				if1 += desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk3000p_mt2060_config, if1) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		/* not found - use panasonic pll parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, tun_i2c, DVB_PLL_ENV57H1XD5) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		st->mt2060_present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		/* set the correct parameters for the dib3000p */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		dib3000mc_set_config(adap->fe_adap[0].fe, &stk3000p_dib3000p_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);