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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) Siano Mobile Silicon, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) MDTV receiver kernel modules.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) Copyright (C) 2006-2008, Uri Shkolnik
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include "smscoreapi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <media/dmxdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <media/dvbdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <media/dvb_demux.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <media/dvb_frontend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include "sms-cards.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include "smsdvb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) static struct list_head g_smsdvb_clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static struct mutex g_smsdvb_clientslock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) static u32 sms_to_guard_interval_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	[0] = GUARD_INTERVAL_1_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	[1] = GUARD_INTERVAL_1_16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	[2] = GUARD_INTERVAL_1_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	[3] = GUARD_INTERVAL_1_4,
^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 u32 sms_to_code_rate_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	[0] = FEC_1_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	[1] = FEC_2_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	[2] = FEC_3_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	[3] = FEC_5_6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	[4] = FEC_7_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) };
^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 u32 sms_to_hierarchy_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	[0] = HIERARCHY_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	[1] = HIERARCHY_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	[2] = HIERARCHY_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	[3] = HIERARCHY_4,
^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 u32 sms_to_modulation_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	[0] = QPSK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	[1] = QAM_16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	[2] = QAM_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	[3] = DQPSK,
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) /* Events that may come from DVB v3 adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static void sms_board_dvb3_event(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		enum SMS_DVB3_EVENTS event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	struct smscore_device_t *coredev = client->coredev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	case DVB3_EVENT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		pr_debug("DVB3_EVENT_INIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		sms_board_event(coredev, BOARD_EVENT_BIND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	case DVB3_EVENT_SLEEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		pr_debug("DVB3_EVENT_SLEEP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	case DVB3_EVENT_HOTPLUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		pr_debug("DVB3_EVENT_HOTPLUG\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 		sms_board_event(coredev, BOARD_EVENT_POWER_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	case DVB3_EVENT_FE_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		if (client->event_fe_state != DVB3_EVENT_FE_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 			client->event_fe_state = DVB3_EVENT_FE_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 			pr_debug("DVB3_EVENT_FE_LOCK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 			sms_board_event(coredev, BOARD_EVENT_FE_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	case DVB3_EVENT_FE_UNLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			client->event_fe_state = DVB3_EVENT_FE_UNLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			pr_debug("DVB3_EVENT_FE_UNLOCK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	case DVB3_EVENT_UNC_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		if (client->event_unc_state != DVB3_EVENT_UNC_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 			client->event_unc_state = DVB3_EVENT_UNC_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 			pr_debug("DVB3_EVENT_UNC_OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 			sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	case DVB3_EVENT_UNC_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 		if (client->event_unc_state != DVB3_EVENT_UNC_ERR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 			client->event_unc_state = DVB3_EVENT_UNC_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 			pr_debug("DVB3_EVENT_UNC_ERR\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 			sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		pr_err("Unknown dvb3 api event\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	}
^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) static void smsdvb_stats_not_ready(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	struct smscore_device_t *coredev = client->coredev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	int i, n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	switch (smscore_get_device_mode(coredev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	case DEVICE_MODE_ISDBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	case DEVICE_MODE_ISDBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		n_layers = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		n_layers = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	/* Global stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	c->strength.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	c->cnr.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	c->strength.stat[0].scale = FE_SCALE_DECIBEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	/* Per-layer stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	c->post_bit_error.len = n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	c->post_bit_count.len = n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	c->block_error.len = n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	c->block_count.len = n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	 * Put all of them at FE_SCALE_NOT_AVAILABLE. They're dynamically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	 * changed when the stats become available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	for (i = 0; i < n_layers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static inline int sms_to_mode(u32 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		return TRANSMISSION_MODE_2K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		return TRANSMISSION_MODE_4K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		return TRANSMISSION_MODE_8K;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return TRANSMISSION_MODE_AUTO;
^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) static inline int sms_to_status(u32 is_demod_locked, u32 is_rf_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	if (is_demod_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		return FE_HAS_SIGNAL  | FE_HAS_CARRIER | FE_HAS_VITERBI |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		       FE_HAS_SYNC    | FE_HAS_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (is_rf_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		return FE_HAS_SIGNAL | FE_HAS_CARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static inline u32 sms_to_bw(u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	return value * 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) #define convert_from_table(value, table, defval) ({			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	u32 __ret;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	if (value < ARRAY_SIZE(table))					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		__ret = table[value];					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		__ret = defval;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	__ret;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #define sms_to_guard_interval(value)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	convert_from_table(value, sms_to_guard_interval_table,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			   GUARD_INTERVAL_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) #define sms_to_code_rate(value)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	convert_from_table(value, sms_to_code_rate_table,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 			   FEC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) #define sms_to_hierarchy(value)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	convert_from_table(value, sms_to_hierarchy_table,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			   FEC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) #define sms_to_modulation(value)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	convert_from_table(value, sms_to_modulation_table,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			   FEC_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) static void smsdvb_update_tx_params(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 				    struct sms_tx_stats *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	c->frequency = p->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	client->fe_status = sms_to_status(p->is_demod_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	c->bandwidth_hz = sms_to_bw(p->bandwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	c->transmission_mode = sms_to_mode(p->transmission_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	c->guard_interval = sms_to_guard_interval(p->guard_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	c->code_rate_HP = sms_to_code_rate(p->code_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	c->code_rate_LP = sms_to_code_rate(p->lp_code_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	c->hierarchy = sms_to_hierarchy(p->hierarchy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	c->modulation = sms_to_modulation(p->constellation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) static void smsdvb_update_per_slices(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 				     struct RECEPTION_STATISTICS_PER_SLICES_S *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	u64 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	c->modulation = sms_to_modulation(p->constellation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	/* signal Strength, in DBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	c->strength.stat[0].uvalue = p->in_band_power * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	/* Carrier to noise ratio, in DB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	c->cnr.stat[0].svalue = p->snr * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	/* PER/BER requires demod lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	if (!p->is_demod_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	/* TS PER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	client->last_per = c->block_error.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	c->block_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	c->block_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	c->block_error.stat[0].uvalue += p->ets_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	c->block_count.stat[0].uvalue += p->ets_packets + p->ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	/* ber */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	c->post_bit_error.stat[0].uvalue += p->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	c->post_bit_count.stat[0].uvalue += p->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	/* Legacy PER/BER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	tmp = p->ets_packets * 65535ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	if (p->ts_packets + p->ets_packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		do_div(tmp, p->ts_packets + p->ets_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	client->legacy_per = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static void smsdvb_update_dvb_stats(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 				    struct sms_stats *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	if (client->prt_dvb_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		client->prt_dvb_stats(client->debug_data, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	/* Update DVB modulation parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	c->frequency = p->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	client->fe_status = sms_to_status(p->is_demod_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	c->bandwidth_hz = sms_to_bw(p->bandwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	c->transmission_mode = sms_to_mode(p->transmission_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	c->guard_interval = sms_to_guard_interval(p->guard_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	c->code_rate_HP = sms_to_code_rate(p->code_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	c->code_rate_LP = sms_to_code_rate(p->lp_code_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	c->hierarchy = sms_to_hierarchy(p->hierarchy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	c->modulation = sms_to_modulation(p->constellation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	/* update reception data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	c->lna = p->is_external_lna_on ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	/* Carrier to noise ratio, in DB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	c->cnr.stat[0].svalue = p->SNR * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	/* signal Strength, in DBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	/* PER/BER requires demod lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	if (!p->is_demod_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	/* TS PER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	client->last_per = c->block_error.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	c->block_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	c->block_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	c->block_error.stat[0].uvalue += p->error_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	c->block_count.stat[0].uvalue += p->total_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	/* ber */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	c->post_bit_error.stat[0].uvalue += p->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	c->post_bit_count.stat[0].uvalue += p->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	/* Legacy PER/BER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	client->legacy_ber = p->ber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) static void smsdvb_update_isdbt_stats(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 				      struct sms_isdbt_stats *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	struct sms_isdbt_layer_stats *lr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	int i, n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	if (client->prt_isdb_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		client->prt_isdb_stats(client->debug_data, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked);
^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) 	 * Firmware 2.1 seems to report only lock status and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	 * signal strength. The signal strength indicator is at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	 * wrong field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if (p->statistics_type == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		c->strength.stat[0].uvalue = ((s32)p->transmission_mode) * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	/* Update ISDB-T transmission parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	c->frequency = p->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	c->bandwidth_hz = sms_to_bw(p->bandwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	c->transmission_mode = sms_to_mode(p->transmission_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	c->guard_interval = sms_to_guard_interval(p->guard_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	c->isdbt_partial_reception = p->partial_reception ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	n_layers = p->num_of_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	if (n_layers < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		n_layers = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	if (n_layers > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		n_layers = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	c->isdbt_layer_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	/* update reception data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	c->lna = p->is_external_lna_on ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	/* Carrier to noise ratio, in DB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	c->cnr.stat[0].svalue = p->SNR * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	/* signal Strength, in DBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	/* PER/BER and per-layer stats require demod lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (!p->is_demod_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	client->last_per = c->block_error.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	/* Clears global counters, as the code below will sum it again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	c->block_error.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	c->block_count.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	c->block_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	c->block_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	c->post_bit_error.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	c->post_bit_count.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	for (i = 0; i < n_layers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		lr = &p->layer_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		/* Update per-layer transmission parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		if (lr->number_of_segments > 0 && lr->number_of_segments < 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			c->isdbt_layer_enabled |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			c->layer[i].segment_count = lr->number_of_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		c->layer[i].modulation = sms_to_modulation(lr->constellation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		/* TS PER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		c->block_error.stat[i + 1].uvalue += lr->error_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		c->block_count.stat[i + 1].uvalue += lr->total_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		/* Update global PER counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		c->block_error.stat[0].uvalue += lr->error_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		c->block_count.stat[0].uvalue += lr->total_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		/* BER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		/* Update global BER counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		c->post_bit_error.stat[0].uvalue += lr->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		c->post_bit_count.stat[0].uvalue += lr->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) static void smsdvb_update_isdbt_stats_ex(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 					 struct sms_isdbt_stats_ex *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	struct sms_isdbt_layer_stats *lr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	int i, n_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (client->prt_isdb_stats_ex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		client->prt_isdb_stats_ex(client->debug_data, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	/* Update ISDB-T transmission parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	c->frequency = p->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	client->fe_status = sms_to_status(p->is_demod_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	c->bandwidth_hz = sms_to_bw(p->bandwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	c->transmission_mode = sms_to_mode(p->transmission_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	c->guard_interval = sms_to_guard_interval(p->guard_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	c->isdbt_partial_reception = p->partial_reception ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	n_layers = p->num_of_layers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	if (n_layers < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		n_layers = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	if (n_layers > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		n_layers = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	c->isdbt_layer_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	/* update reception data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	c->lna = p->is_external_lna_on ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	/* Carrier to noise ratio, in DB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	c->cnr.stat[0].svalue = p->SNR * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	/* signal Strength, in DBm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	c->strength.stat[0].uvalue = p->in_band_pwr * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	/* PER/BER and per-layer stats require demod lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (!p->is_demod_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	client->last_per = c->block_error.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	/* Clears global counters, as the code below will sum it again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	c->block_error.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	c->block_count.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	c->block_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	c->block_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	c->post_bit_error.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	c->post_bit_count.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	c->post_bit_error.len = n_layers + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	c->post_bit_count.len = n_layers + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	c->block_error.len = n_layers + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	c->block_count.len = n_layers + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	for (i = 0; i < n_layers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		lr = &p->layer_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		/* Update per-layer transmission parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		if (lr->number_of_segments > 0 && lr->number_of_segments < 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			c->isdbt_layer_enabled |= 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			c->layer[i].segment_count = lr->number_of_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		c->layer[i].modulation = sms_to_modulation(lr->constellation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		/* TS PER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		c->block_error.stat[i + 1].uvalue += lr->error_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		c->block_count.stat[i + 1].uvalue += lr->total_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		/* Update global PER counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		c->block_error.stat[0].uvalue += lr->error_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		c->block_count.stat[0].uvalue += lr->total_ts_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		/* ber */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		/* Update global ber counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		c->post_bit_error.stat[0].uvalue += lr->ber_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		c->post_bit_count.stat[0].uvalue += lr->ber_bit_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) (((u8 *) cb->p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			+ cb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	void *p = phdr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	struct dvb_frontend *fe = &client->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	bool is_status_update = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	switch (phdr->msg_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	case MSG_SMS_DVBT_BDA_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		 * Only feed data to dvb demux if are there any feed listening
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		 * to it and if the device has tuned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		if (client->feed_users && client->has_tuned)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			dvb_dmx_swfilter(&client->demux, p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 					 cb->size - sizeof(struct sms_msg_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	case MSG_SMS_RF_TUNE_RES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	case MSG_SMS_ISDBT_TUNE_RES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		complete(&client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	case MSG_SMS_SIGNAL_DETECTED_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		client->fe_status = FE_HAS_SIGNAL  | FE_HAS_CARRIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 				    FE_HAS_VITERBI | FE_HAS_SYNC    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				    FE_HAS_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	case MSG_SMS_NO_SIGNAL_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		client->fe_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	case MSG_SMS_TRANSMISSION_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		smsdvb_update_tx_params(client, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	case MSG_SMS_HO_PER_SLICES_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		smsdvb_update_per_slices(client, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	case MSG_SMS_GET_STATISTICS_RES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		switch (smscore_get_device_mode(client->coredev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		case DEVICE_MODE_ISDBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		case DEVICE_MODE_ISDBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 			smsdvb_update_isdbt_stats(client, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			/* Skip sms_msg_statistics_info:request_result field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 			smsdvb_update_dvb_stats(client, p + sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	/* Only for ISDB-T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	case MSG_SMS_GET_STATISTICS_EX_RES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		/* Skip sms_msg_statistics_info:request_result field? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		smsdvb_update_isdbt_stats_ex(client, p + sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		is_status_update = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		pr_debug("message not handled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	smscore_putbuffer(client->coredev, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	if (is_status_update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		if (client->fe_status & FE_HAS_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			if (client->last_per == c->block_error.stat[0].uvalue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 				sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 				sms_board_dvb3_event(client, DVB3_EVENT_UNC_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			client->has_tuned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			smsdvb_stats_not_ready(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			client->has_tuned = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 			sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		complete(&client->stats_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) static void smsdvb_media_device_unregister(struct smsdvb_client_t *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) #ifdef CONFIG_MEDIA_CONTROLLER_DVB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	struct smscore_device_t *coredev = client->coredev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	if (!coredev->media_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	media_device_unregister(coredev->media_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	media_device_cleanup(coredev->media_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	kfree(coredev->media_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	coredev->media_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) static void smsdvb_unregister_client(struct smsdvb_client_t *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	/* must be called under clientslock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	list_del(&client->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	smsdvb_debugfs_release(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	smscore_unregister_client(client->smsclient);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	dvb_unregister_frontend(&client->frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	dvb_dmxdev_release(&client->dmxdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	dvb_dmx_release(&client->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	smsdvb_media_device_unregister(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	dvb_unregister_adapter(&client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	kfree(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) static void smsdvb_onremove(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	kmutex_lock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	smsdvb_unregister_client((struct smsdvb_client_t *) context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	kmutex_unlock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) static int smsdvb_start_feed(struct dvb_demux_feed *feed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		container_of(feed->demux, struct smsdvb_client_t, demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	struct sms_msg_data pid_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	pr_debug("add pid %d(%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		  feed->pid, feed->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	client->feed_users++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	pid_msg.x_msg_header.msg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	pid_msg.x_msg_header.msg_type  = MSG_SMS_ADD_PID_FILTER_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	pid_msg.msg_data[0] = feed->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	return smsclient_sendrequest(client->smsclient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 				     &pid_msg, sizeof(pid_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		container_of(feed->demux, struct smsdvb_client_t, demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct sms_msg_data pid_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	pr_debug("remove pid %d(%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		  feed->pid, feed->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	client->feed_users--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	pid_msg.x_msg_header.msg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	pid_msg.x_msg_header.msg_type  = MSG_SMS_REMOVE_PID_FILTER_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	pid_msg.msg_data[0] = feed->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	return smsclient_sendrequest(client->smsclient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 				     &pid_msg, sizeof(pid_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 					void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 					struct completion *completion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	rc = smsclient_sendrequest(client->smsclient, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	return wait_for_completion_timeout(completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 					   msecs_to_jiffies(2000)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 						0 : -ETIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	struct sms_msg_hdr msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	/* Don't request stats too fast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	if (client->get_stats_jiffies &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	   (!time_after(jiffies, client->get_stats_jiffies)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	client->get_stats_jiffies = jiffies + msecs_to_jiffies(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	msg.msg_dst_id = HIF_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	msg.msg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	msg.msg_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	switch (smscore_get_device_mode(client->coredev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	case DEVICE_MODE_ISDBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	case DEVICE_MODE_ISDBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		* Check for firmware version, to avoid breaking for old cards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		if (client->coredev->fw_version >= 0x800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			msg.msg_type = MSG_SMS_GET_STATISTICS_EX_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	rc = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 					 &client->stats_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) static inline int led_feedback(struct smsdvb_client_t *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (!(client->fe_status & FE_HAS_LOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	return sms_board_led_feedback(client->coredev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 				     (client->legacy_ber == 0) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 				     SMS_LED_HI : SMS_LED_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) static int smsdvb_read_status(struct dvb_frontend *fe, enum fe_status *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	client = container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	rc = smsdvb_send_statistics_request(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	*stat = client->fe_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	led_feedback(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	client = container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	rc = smsdvb_send_statistics_request(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	*ber = client->legacy_ber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	led_feedback(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	s32 power = (s32) c->strength.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	client = container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	rc = smsdvb_send_statistics_request(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	if (power < -95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		*strength = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		else if (power > -29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			*strength = 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			*strength = (power + 95) * 65535 / 66;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	led_feedback(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	client = container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	rc = smsdvb_send_statistics_request(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	/* Preferred scale for SNR with legacy API: 0.1 dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	*snr = ((u32)c->cnr.stat[0].svalue) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	led_feedback(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	client = container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	rc = smsdvb_send_statistics_request(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	*ucblocks = c->block_error.stat[0].uvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	led_feedback(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 				    struct dvb_frontend_tune_settings *tune)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	tune->min_delay_ms = 400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	tune->step_size = 250000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	tune->max_drift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		struct sms_msg_hdr	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		u32		Data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	} msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	client->fe_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	client->event_fe_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	client->event_unc_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	fe->dtv_property_cache.delivery_system = SYS_DVBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	msg.msg.msg_dst_id = HIF_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	msg.msg.msg_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	msg.msg.msg_type = MSG_SMS_RF_TUNE_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	msg.msg.msg_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	msg.Data[0] = c->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	msg.Data[2] = 12000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	pr_debug("%s: freq %d band %d\n", __func__, c->frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		 c->bandwidth_hz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	switch (c->bandwidth_hz / 1000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		msg.Data[1] = BW_8_MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		msg.Data[1] = BW_7_MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		msg.Data[1] = BW_6_MHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	/* Disable LNA, if any. An error is returned if no LNA is present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	ret = sms_board_lna_control(client->coredev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		enum fe_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		/* tune with LNA off at first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 						  &client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		smsdvb_read_status(fe, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		if (status & FE_HAS_LOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		/* previous tune didn't lock - enable LNA and tune again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		sms_board_lna_control(client->coredev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 					   &client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	int board_id = smscore_get_board_id(client->coredev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	struct sms_board *board = sms_get_board(board_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	enum sms_device_type_st type = board->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		struct sms_msg_hdr	msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		u32		Data[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	} msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	fe->dtv_property_cache.delivery_system = SYS_ISDBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	msg.msg.msg_src_id  = DVBT_BDA_CONTROL_MSG_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	msg.msg.msg_dst_id  = HIF_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	msg.msg.msg_flags  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	msg.msg.msg_type   = MSG_SMS_ISDBT_TUNE_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	msg.msg.msg_length = sizeof(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	if (c->isdbt_sb_segment_idx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		c->isdbt_sb_segment_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	if (!c->isdbt_layer_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		c->isdbt_layer_enabled = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	msg.Data[0] = c->frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	msg.Data[1] = BW_ISDBT_1SEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	msg.Data[2] = 12000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	msg.Data[3] = c->isdbt_sb_segment_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	if (c->isdbt_partial_reception) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		if ((type == SMS_PELE || type == SMS_RIO) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		    c->isdbt_sb_segment_count > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			msg.Data[1] = BW_ISDBT_13SEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		else if (c->isdbt_sb_segment_count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			msg.Data[1] = BW_ISDBT_3SEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	} else if (type == SMS_PELE || type == SMS_RIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		msg.Data[1] = BW_ISDBT_13SEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	c->bandwidth_hz = 6000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	pr_debug("freq %d segwidth %d segindex %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		 c->frequency, c->isdbt_sb_segment_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		 c->isdbt_sb_segment_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	/* Disable LNA, if any. An error is returned if no LNA is present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	ret = sms_board_lna_control(client->coredev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		enum fe_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		/* tune with LNA off at first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 						  &client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		smsdvb_read_status(fe, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		if (status & FE_HAS_LOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		/* previous tune didn't lock - enable LNA and tune again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		sms_board_lna_control(client->coredev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 					   &client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static int smsdvb_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	struct smscore_device_t *coredev = client->coredev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	smsdvb_stats_not_ready(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	c->strength.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	c->cnr.stat[0].uvalue = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	client->has_tuned = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	switch (smscore_get_device_mode(coredev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	case DEVICE_MODE_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	case DEVICE_MODE_DVBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		return smsdvb_dvbt_set_frontend(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	case DEVICE_MODE_ISDBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	case DEVICE_MODE_ISDBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		return smsdvb_isdbt_set_frontend(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) static int smsdvb_init(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	sms_board_power(client->coredev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	sms_board_dvb3_event(client, DVB3_EVENT_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static int smsdvb_sleep(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	struct smsdvb_client_t *client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		container_of(fe, struct smsdvb_client_t, frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	sms_board_led_feedback(client->coredev, SMS_LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	sms_board_power(client->coredev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) static void smsdvb_release(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	/* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) static const struct dvb_frontend_ops smsdvb_fe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	.info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		.name			= "Siano Mobile Digital MDTV Receiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		.frequency_min_hz	=  44250 * kHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		.frequency_max_hz	= 867250 * kHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		.frequency_stepsize_hz	=    250 * kHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		.caps = FE_CAN_INVERSION_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 			FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			FE_CAN_GUARD_INTERVAL_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			FE_CAN_RECOVER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 			FE_CAN_HIERARCHY_AUTO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	.release = smsdvb_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	.set_frontend = smsdvb_set_frontend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	.get_tune_settings = smsdvb_get_tune_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	.read_status = smsdvb_read_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	.read_ber = smsdvb_read_ber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	.read_signal_strength = smsdvb_read_signal_strength,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	.read_snr = smsdvb_read_snr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	.read_ucblocks = smsdvb_read_ucblocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	.init = smsdvb_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	.sleep = smsdvb_sleep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static int smsdvb_hotplug(struct smscore_device_t *coredev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			  struct device *device, int arrival)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	struct smsclient_params_t params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	struct smsdvb_client_t *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	/* device removal handled by onremove callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (!arrival)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (!client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	/* register dvb adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	rc = dvb_register_adapter(&client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				  sms_get_board(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 					smscore_get_board_id(coredev))->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 				  THIS_MODULE, device, adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		pr_err("dvb_register_adapter() failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		goto adapter_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	dvb_register_media_controller(&client->adapter, coredev->media_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	/* init dvb demux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	client->demux.dmx.capabilities = DMX_TS_FILTERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	client->demux.filternum = 32; /* todo: nova ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	client->demux.feednum = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	client->demux.start_feed = smsdvb_start_feed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	client->demux.stop_feed = smsdvb_stop_feed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	rc = dvb_dmx_init(&client->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		pr_err("dvb_dmx_init failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		goto dvbdmx_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	/* init dmxdev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	client->dmxdev.filternum = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	client->dmxdev.demux = &client->demux.dmx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	client->dmxdev.capabilities = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		pr_err("dvb_dmxdev_init failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		goto dmxdev_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	/* init and register frontend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	memcpy(&client->frontend.ops, &smsdvb_fe_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	       sizeof(struct dvb_frontend_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	switch (smscore_get_device_mode(coredev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	case DEVICE_MODE_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	case DEVICE_MODE_DVBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		client->frontend.ops.delsys[0] = SYS_DVBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	case DEVICE_MODE_ISDBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	case DEVICE_MODE_ISDBT_BDA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		client->frontend.ops.delsys[0] = SYS_ISDBT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	rc = dvb_register_frontend(&client->adapter, &client->frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		pr_err("frontend registration failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		goto frontend_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	params.initial_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	params.data_type = MSG_SMS_DVBT_BDA_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	params.onresponse_handler = smsdvb_onresponse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	params.onremove_handler = smsdvb_onremove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	params.context = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	rc = smscore_register_client(coredev, &params, &client->smsclient);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		pr_err("smscore_register_client() failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		goto client_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	client->coredev = coredev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	init_completion(&client->tune_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	init_completion(&client->stats_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	kmutex_lock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	list_add(&client->entry, &g_smsdvb_clients);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	kmutex_unlock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	client->event_fe_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	client->event_unc_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	sms_board_setup(coredev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	if (smsdvb_debugfs_create(client) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		pr_info("failed to create debugfs node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	rc = dvb_create_media_graph(&client->adapter, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		pr_err("dvb_create_media_graph failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		goto media_graph_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	pr_info("DVB interface registered.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) media_graph_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	mutex_lock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	list_del(&client->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	mutex_unlock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	smsdvb_debugfs_release(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) client_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	dvb_unregister_frontend(&client->frontend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) frontend_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	dvb_dmxdev_release(&client->dmxdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) dmxdev_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	dvb_dmx_release(&client->demux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) dvbdmx_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	smsdvb_media_device_unregister(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	dvb_unregister_adapter(&client->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) adapter_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	kfree(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) static int __init smsdvb_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	INIT_LIST_HEAD(&g_smsdvb_clients);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	kmutex_init(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	smsdvb_debugfs_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	rc = smscore_register_hotplug(smsdvb_hotplug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) static void __exit smsdvb_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	smscore_unregister_hotplug(smsdvb_hotplug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	kmutex_lock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	while (!list_empty(&g_smsdvb_clients))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	smsdvb_debugfs_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	kmutex_unlock(&g_smsdvb_clientslock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) module_init(smsdvb_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) module_exit(smsdvb_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) MODULE_LICENSE("GPL");