linux/drivers/media/radio/wl128x/fmdrv_common.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 *  FM Driver for Connectivity chip of Texas Instruments.
 *
 *  This sub-module of FM driver is common for FM RX and TX
 *  functionality. This module is responsible for:
 *  1) Forming group of Channel-8 commands to perform particular
 *     functionality (eg., frequency set require more than
 *     one Channel-8 command to be sent to the chip).
 *  2) Sending each Channel-8 command to the chip and reading
 *     response back over Shared Transport.
 *  3) Managing TX and RX Queues and BH bh Works.
 *  4) Handling FM Interrupt packet and taking appropriate action.
 *  5) Loading FM firmware to the chip (common, FM TX, and FM RX
 *     firmware files based on mode selection)
 *
 *  Copyright (C) 2011 Texas Instruments
 *  Author: Raja Mani <[email protected]>
 *  Author: Manjunatha Halli <[email protected]>
 */

#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/module.h>
#include <linux/nospec.h>
#include <linux/jiffies.h>

#include "fmdrv.h"
#include "fmdrv_v4l2.h"
#include "fmdrv_common.h"
#include <linux/ti_wilink_st.h>
#include "fmdrv_rx.h"
#include "fmdrv_tx.h"

/* Region info */
static struct region_info region_configs[] =;

/* Band selection */
static u8 default_radio_region;	/* Europe/US */
module_param(default_radio_region, byte, 0);
MODULE_PARM_DESC();

/* RDS buffer blocks */
static u32 default_rds_buf =;
module_param(default_rds_buf, uint, 0444);
MODULE_PARM_DESC();

/* Radio Nr */
static u32 radio_nr =;
module_param(radio_nr, int, 0444);
MODULE_PARM_DESC();

/* FM irq handlers forward declaration */
static void fm_irq_send_flag_getcmd(struct fmdev *);
static void fm_irq_handle_flag_getcmd_resp(struct fmdev *);
static void fm_irq_handle_hw_malfunction(struct fmdev *);
static void fm_irq_handle_rds_start(struct fmdev *);
static void fm_irq_send_rdsdata_getcmd(struct fmdev *);
static void fm_irq_handle_rdsdata_getcmd_resp(struct fmdev *);
static void fm_irq_handle_rds_finish(struct fmdev *);
static void fm_irq_handle_tune_op_ended(struct fmdev *);
static void fm_irq_handle_power_enb(struct fmdev *);
static void fm_irq_handle_low_rssi_start(struct fmdev *);
static void fm_irq_afjump_set_pi(struct fmdev *);
static void fm_irq_handle_set_pi_resp(struct fmdev *);
static void fm_irq_afjump_set_pimask(struct fmdev *);
static void fm_irq_handle_set_pimask_resp(struct fmdev *);
static void fm_irq_afjump_setfreq(struct fmdev *);
static void fm_irq_handle_setfreq_resp(struct fmdev *);
static void fm_irq_afjump_enableint(struct fmdev *);
static void fm_irq_afjump_enableint_resp(struct fmdev *);
static void fm_irq_start_afjump(struct fmdev *);
static void fm_irq_handle_start_afjump_resp(struct fmdev *);
static void fm_irq_afjump_rd_freq(struct fmdev *);
static void fm_irq_afjump_rd_freq_resp(struct fmdev *);
static void fm_irq_handle_low_rssi_finish(struct fmdev *);
static void fm_irq_send_intmsk_cmd(struct fmdev *);
static void fm_irq_handle_intmsk_cmd_resp(struct fmdev *);

/*
 * When FM common module receives interrupt packet, following handlers
 * will be executed one after another to service the interrupt(s)
 */
enum fmc_irq_handler_index {};

/* FM interrupt handler table */
static int_handler_prototype int_handler_table[] =;

static long (*g_st_write) (struct sk_buff *skb);
static struct completion wait_for_fmdrv_reg_comp;

static inline void fm_irq_call(struct fmdev *fmdev)
{}

/* Continue next function in interrupt handler table */
static inline void fm_irq_call_stage(struct fmdev *fmdev, u8 stage)
{}

static inline void fm_irq_timeout_stage(struct fmdev *fmdev, u8 stage)
{}

#ifdef FM_DUMP_TXRX_PKT
 /* To dump outgoing FM Channel-8 packets */
inline void dump_tx_skb_data(struct sk_buff *skb)
{
	int len, len_org;
	u8 index;
	struct fm_cmd_msg_hdr *cmd_hdr;

	cmd_hdr = (struct fm_cmd_msg_hdr *)skb->data;
	printk(KERN_INFO "<<%shdr:%02x len:%02x opcode:%02x type:%s dlen:%02x",
	       fm_cb(skb)->completion ? " " : "*", cmd_hdr->hdr,
	       cmd_hdr->len, cmd_hdr->op,
	       cmd_hdr->rd_wr ? "RD" : "WR", cmd_hdr->dlen);

	len_org = skb->len - FM_CMD_MSG_HDR_SIZE;
	if (len_org > 0) {
		printk(KERN_CONT "\n   data(%d): ", cmd_hdr->dlen);
		len = min(len_org, 14);
		for (index = 0; index < len; index++)
			printk(KERN_CONT "%x ",
			       skb->data[FM_CMD_MSG_HDR_SIZE + index]);
		printk(KERN_CONT "%s", (len_org > 14) ? ".." : "");
	}
	printk(KERN_CONT "\n");
}

 /* To dump incoming FM Channel-8 packets */
inline void dump_rx_skb_data(struct sk_buff *skb)
{
	int len, len_org;
	u8 index;
	struct fm_event_msg_hdr *evt_hdr;

	evt_hdr = (struct fm_event_msg_hdr *)skb->data;
	printk(KERN_INFO ">> hdr:%02x len:%02x sts:%02x numhci:%02x opcode:%02x type:%s dlen:%02x",
	       evt_hdr->hdr, evt_hdr->len,
	       evt_hdr->status, evt_hdr->num_fm_hci_cmds, evt_hdr->op,
	       (evt_hdr->rd_wr) ? "RD" : "WR", evt_hdr->dlen);

	len_org = skb->len - FM_EVT_MSG_HDR_SIZE;
	if (len_org > 0) {
		printk(KERN_CONT "\n   data(%d): ", evt_hdr->dlen);
		len = min(len_org, 14);
		for (index = 0; index < len; index++)
			printk(KERN_CONT "%x ",
			       skb->data[FM_EVT_MSG_HDR_SIZE + index]);
		printk(KERN_CONT "%s", (len_org > 14) ? ".." : "");
	}
	printk(KERN_CONT "\n");
}
#endif

void fmc_update_region_info(struct fmdev *fmdev, u8 region_to_set)
{}

/*
 * FM common sub-module will queue this bh work whenever it receives
 * FM packet from ST driver.
 */
static void recv_bh_work(struct work_struct *t)
{}

/* FM send_bh_work: is scheduled when FM packet has to be sent to chip */
static void send_bh_work(struct work_struct *t)
{}

/*
 * Queues FM Channel-8 packet to FM TX queue and schedules FM TX bh work for
 * transmission
 */
static int fm_send_cmd(struct fmdev *fmdev, u8 fm_op, u16 type,	void *payload,
		int payload_len, struct completion *wait_completion)
{}

/* Sends FM Channel-8 command to the chip and waits for the response */
int fmc_send_cmd(struct fmdev *fmdev, u8 fm_op, u16 type, void *payload,
		unsigned int payload_len, void *response, int *response_len)
{}

/* --- Helper functions used in FM interrupt handlers ---*/
static inline int check_cmdresp_status(struct fmdev *fmdev,
		struct sk_buff **skb)
{}

static inline void fm_irq_common_cmd_resp_helper(struct fmdev *fmdev, u8 stage)
{}

/*
 * Interrupt process timeout handler.
 * One of the irq handler did not get proper response from the chip. So take
 * recovery action here. FM interrupts are disabled in the beginning of
 * interrupt process. Therefore reset stage index to re-enable default
 * interrupts. So that next interrupt will be processed as usual.
 */
static void int_timeout_handler(struct timer_list *t)
{}

/* --------- FM interrupt handlers ------------*/
static void fm_irq_send_flag_getcmd(struct fmdev *fmdev)
{}

static void fm_irq_handle_flag_getcmd_resp(struct fmdev *fmdev)
{}

static void fm_irq_handle_hw_malfunction(struct fmdev *fmdev)
{}

static void fm_irq_handle_rds_start(struct fmdev *fmdev)
{}

static void fm_irq_send_rdsdata_getcmd(struct fmdev *fmdev)
{}

/* Keeps track of current RX channel AF (Alternate Frequency) */
static void fm_rx_update_af_cache(struct fmdev *fmdev, u8 af)
{}

/*
 * Converts RDS buffer data from big endian format
 * to little endian format.
 */
static void fm_rdsparse_swapbytes(struct fmdev *fmdev,
		struct fm_rdsdata_format *rds_format)
{}

static void fm_irq_handle_rdsdata_getcmd_resp(struct fmdev *fmdev)
{}

static void fm_irq_handle_rds_finish(struct fmdev *fmdev)
{}

static void fm_irq_handle_tune_op_ended(struct fmdev *fmdev)
{}

static void fm_irq_handle_power_enb(struct fmdev *fmdev)
{}

static void fm_irq_handle_low_rssi_start(struct fmdev *fmdev)
{}

static void fm_irq_afjump_set_pi(struct fmdev *fmdev)
{}

static void fm_irq_handle_set_pi_resp(struct fmdev *fmdev)
{}

/*
 * Set PI mask.
 * 0xFFFF = Enable PI code matching
 * 0x0000 = Disable PI code matching
 */
static void fm_irq_afjump_set_pimask(struct fmdev *fmdev)
{}

static void fm_irq_handle_set_pimask_resp(struct fmdev *fmdev)
{}

static void fm_irq_afjump_setfreq(struct fmdev *fmdev)
{}

static void fm_irq_handle_setfreq_resp(struct fmdev *fmdev)
{}

static void fm_irq_afjump_enableint(struct fmdev *fmdev)
{}

static void fm_irq_afjump_enableint_resp(struct fmdev *fmdev)
{}

static void fm_irq_start_afjump(struct fmdev *fmdev)
{}

static void fm_irq_handle_start_afjump_resp(struct fmdev *fmdev)
{}

static void fm_irq_afjump_rd_freq(struct fmdev *fmdev)
{}

static void fm_irq_afjump_rd_freq_resp(struct fmdev *fmdev)
{}

static void fm_irq_handle_low_rssi_finish(struct fmdev *fmdev)
{}

static void fm_irq_send_intmsk_cmd(struct fmdev *fmdev)
{}

static void fm_irq_handle_intmsk_cmd_resp(struct fmdev *fmdev)
{}

/* Returns availability of RDS data in internal buffer */
int fmc_is_rds_data_available(struct fmdev *fmdev, struct file *file,
				struct poll_table_struct *pts)
{}

/* Copies RDS data from internal buffer to user buffer */
int fmc_transfer_rds_from_internal_buff(struct fmdev *fmdev, struct file *file,
		u8 __user *buf, size_t count)
{}

int fmc_set_freq(struct fmdev *fmdev, u32 freq_to_set)
{}

int fmc_get_freq(struct fmdev *fmdev, u32 *cur_tuned_frq)
{}

int fmc_set_region(struct fmdev *fmdev, u8 region_to_set)
{}

int fmc_set_mute_mode(struct fmdev *fmdev, u8 mute_mode_toset)
{}

int fmc_set_stereo_mono(struct fmdev *fmdev, u16 mode)
{}

int fmc_set_rds_mode(struct fmdev *fmdev, u8 rds_en_dis)
{}

/* Sends power off command to the chip */
static int fm_power_down(struct fmdev *fmdev)
{}

/* Reads init command from FM firmware file and loads to the chip */
static int fm_download_firmware(struct fmdev *fmdev, const u8 *fw_name)
{}

/* Loads default RX configuration to the chip */
static int load_default_rx_configuration(struct fmdev *fmdev)
{}

/* Does FM power on sequence */
static int fm_power_up(struct fmdev *fmdev, u8 mode)
{}

/* Set FM Modes(TX, RX, OFF) */
int fmc_set_mode(struct fmdev *fmdev, u8 fm_mode)
{}

/* Returns current FM mode (TX, RX, OFF) */
int fmc_get_mode(struct fmdev *fmdev, u8 *fmmode)
{}

/* Called by ST layer when FM packet is available */
static long fm_st_receive(void *arg, struct sk_buff *skb)
{}

/*
 * Called by ST layer to indicate protocol registration completion
 * status.
 */
static void fm_st_reg_comp_cb(void *arg, int data)
{}

/*
 * This function will be called from FM V4L2 open function.
 * Register with ST driver and initialize driver data.
 */
int fmc_prepare(struct fmdev *fmdev)
{}

/*
 * This function will be called from FM V4L2 release function.
 * Unregister from ST driver.
 */
int fmc_release(struct fmdev *fmdev)
{}

/*
 * Module init function. Ask FM V4L module to register video device.
 * Allocate memory for FM driver context and RX RDS buffer.
 */
static int __init fm_drv_init(void)
{}

/* Module exit function. Ask FM V4L module to unregister video device */
static void __exit fm_drv_exit(void)
{}

module_init();
module_exit(fm_drv_exit);

/* ------------- Module Info ------------- */
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_VERSION();
MODULE_LICENSE();