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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Frontend driver for the GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Thanks to GENPIX for the sample code used to implement this module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This module is based off the vp7045 and vp702x modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "gp8psk-fe.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <media/dvb_frontend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define dprintk(fmt, arg...) do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	if (debug)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		printk(KERN_DEBUG pr_fmt("%s: " fmt),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		       __func__, ##arg);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct gp8psk_fe_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct dvb_frontend fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	const struct gp8psk_fe_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	bool is_rev1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u8 lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u16 snr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned long next_status_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long status_check_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	st->ops->in(st->priv, GET_8PSK_CONFIG, 0, 0, &status, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return status & bmDCtuned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return st->ops->out(st->priv, SET_8PSK_CONFIG, mode, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u8 buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (time_after(jiffies,st->next_status_check)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		st->ops->in(st->priv, GET_SIGNAL_LOCK, 0, 0, &st->lock, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		st->ops->in(st->priv, GET_SIGNAL_STRENGTH, 0, 0, buf, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		st->snr = (buf[1]) << 8 | buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int gp8psk_fe_read_status(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				 enum fe_status *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	gp8psk_fe_update_status(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (st->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		*status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		*status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (*status & FE_HAS_LOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		st->status_check_interval = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		st->status_check_interval = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^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) /* not supported by this Frontend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	(void) fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	*ber = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /* not supported by this Frontend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	(void) fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	*unc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	gp8psk_fe_update_status(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* snr is reported in dBu*256 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	*snr = st->snr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	gp8psk_fe_update_status(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* snr is reported in dBu*256 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* snr / 38.4 ~= 100% strength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* snr * 17 returns 100% strength as 65535 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (st->snr > 0xf00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		*strength = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		*strength = (st->snr << 4) + st->snr; /* snr*17 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	tune->min_delay_ms = 800;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return 0;
^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) static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u8 cmd[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	u32 freq = c->frequency * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	dprintk("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	cmd[4] = freq         & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	cmd[5] = (freq >> 8)  & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	cmd[6] = (freq >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	cmd[7] = (freq >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (c->delivery_system == SYS_DVBS && c->modulation == PSK_8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		c->delivery_system = SYS_TURBO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	switch (c->delivery_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	case SYS_DVBS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (c->modulation != QPSK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			dprintk("%s: unsupported modulation selected (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				__func__, c->modulation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		c->fec_inner = FEC_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	case SYS_DVBS2: /* kept for backwards compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		dprintk("%s: DVB-S2 delivery system selected\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	case SYS_TURBO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		dprintk("%s: Turbo-FEC delivery system selected\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dprintk("%s: unsupported delivery system selected (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			__func__, c->delivery_system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	cmd[0] =  c->symbol_rate        & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	cmd[1] = (c->symbol_rate >>  8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	cmd[2] = (c->symbol_rate >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	cmd[3] = (c->symbol_rate >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	switch (c->modulation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	case QPSK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (st->is_rev1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			if (gp8psk_tuned_to_DCII(fe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				st->ops->reload(st->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		switch (c->fec_inner) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		case FEC_1_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			cmd[9] = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		case FEC_2_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			cmd[9] = 1; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		case FEC_3_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			cmd[9] = 2; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		case FEC_5_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			cmd[9] = 3; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		case FEC_7_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			cmd[9] = 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		case FEC_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			cmd[9] = 5; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			cmd[9] = 5; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (c->delivery_system == SYS_TURBO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			cmd[8] = ADV_MOD_TURBO_QPSK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			cmd[8] = ADV_MOD_DVB_QPSK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	case PSK_8: /* PSK_8 is for compatibility with DN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		cmd[8] = ADV_MOD_TURBO_8PSK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		switch (c->fec_inner) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		case FEC_2_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			cmd[9] = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		case FEC_3_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			cmd[9] = 1; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		case FEC_3_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			cmd[9] = 2; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		case FEC_5_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			cmd[9] = 3; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		case FEC_8_9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			cmd[9] = 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			cmd[9] = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	case QAM_16: /* QAM_16 is for compatibility with DN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		cmd[8] = ADV_MOD_TURBO_16QAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		cmd[9] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	default: /* Unknown modulation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		dprintk("%s: unsupported modulation selected (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			__func__, c->modulation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (st->is_rev1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		gp8psk_set_tuner_mode(fe, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	st->ops->out(st->priv, TUNE_8PSK, 0, 0, cmd, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	st->lock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	st->next_status_check = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	st->status_check_interval = 200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				    struct dvb_diseqc_master_cmd *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	dprintk("%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, m->msg[0], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			m->msg, m->msg_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				       enum fe_sec_mini_cmd burst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	dprintk("%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	/* These commands are certainly wrong */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, cmd, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			&cmd, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			      enum fe_sec_tone_mode tone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (st->ops->out(st->priv, SET_22KHZ_TONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			 (tone == SEC_TONE_ON), 0, NULL, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				 enum fe_sec_voltage voltage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (st->ops->out(st->priv, SET_LNB_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return st->ops->out(st->priv, USE_EXTRA_VOLT, onoff, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	u8 cmd = sw_cmd & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (st->ops->out(st->priv, SET_DN_SWITCH, cmd, 0, NULL, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (st->ops->out(st->priv, SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			0, NULL, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static void gp8psk_fe_release(struct dvb_frontend* fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct gp8psk_fe_state *st = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static const struct dvb_frontend_ops gp8psk_fe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct dvb_frontend *gp8psk_fe_attach(const struct gp8psk_fe_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				      void *priv, bool is_rev1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct gp8psk_fe_state *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!ops || !ops->in || !ops->out || !ops->reload) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		pr_err("Error! gp8psk-fe ops not defined.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	st = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	memcpy(&st->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	st->fe.demodulator_priv = st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	st->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	st->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	st->is_rev1 = is_rev1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	pr_info("Frontend %sattached\n", is_rev1 ? "revision 1 " : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return &st->fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) EXPORT_SYMBOL_GPL(gp8psk_fe_attach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static const struct dvb_frontend_ops gp8psk_fe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	.delsys = { SYS_DVBS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	.info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		.name			= "Genpix DVB-S",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		.frequency_min_hz	=  800 * MHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		.frequency_max_hz	= 2250 * MHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		.frequency_stepsize_hz	=  100 * kHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		.symbol_rate_min        = 1000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		.symbol_rate_max        = 45000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		.symbol_rate_tolerance  = 500,  /* ppm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		.caps = FE_CAN_INVERSION_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			 * FE_CAN_QAM_16 is for compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.release = gp8psk_fe_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.init = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.sleep = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	.set_frontend = gp8psk_fe_set_frontend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.get_tune_settings = gp8psk_fe_get_tune_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	.read_status = gp8psk_fe_read_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	.read_ber = gp8psk_fe_read_ber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	.read_signal_strength = gp8psk_fe_read_signal_strength,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	.read_snr = gp8psk_fe_read_snr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	.read_ucblocks = gp8psk_fe_read_unc_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	.diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	.diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	.set_tone = gp8psk_fe_set_tone,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	.set_voltage = gp8psk_fe_set_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	.dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	.enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) MODULE_DESCRIPTION("Frontend Driver for Genpix DVB-S");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) MODULE_VERSION("1.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) MODULE_LICENSE("GPL");