Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 656d8be9 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ASoC: wcd_cpe_core: Add core support for CPE"

parents df52e0bc 318691a4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@
#define CMI_OBM_FLAG_IN_BAND	0
#define CMI_OBM_FLAG_OUT_BAND	1

#define CMI_SHMEM_ALLOC_FAILED 0xff

/*
 * Future Service ID's can be added one line
 * before the CMI_CPE_SERVICE_ID_MAX
+115 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __CPE_CORE_H__
#define __CPE_CORE_H__

#include <linux/types.h>
#include <linux/wait.h>
#include <linux/msm_ion.h>
#include <sound/lsm_params.h>

enum {
	CMD_INIT_STATE = 0,
	CMD_SENT,
	CMD_RESP_RCVD,
};

struct wcd_cpe_afe_port_cfg {
	u8 port_id;
	u16 bit_width;
	u16 num_channels;
	u32 sample_rate;
};

struct cpe_lsm_session {
	/* sound model related */
	void *snd_model_data;
	u8 *conf_levels;
	void *cmi_reg_handle;
	void *priv_d;

	void (*event_cb) (void *priv_data,
			  u8 detect_status,
			  u8 size, u8 *payload);

	struct completion cmd_comp;
	struct wcd_cpe_afe_port_cfg afe_port_cfg;
	struct mutex lsm_lock;

	u32 snd_model_size;
	u32 lsm_mem_handle;
	u16 cmd_err_code;
	u8 id;
	u8 num_confidence_levels;
};

struct wcd_cpe_afe_ops {
	int (*afe_set_params) (void *core_handle,
			       struct wcd_cpe_afe_port_cfg *cfg);

	int (*afe_port_start) (void *core_handle,
			       struct wcd_cpe_afe_port_cfg *cfg);

	int (*afe_port_stop) (void *core_handle,
			       struct wcd_cpe_afe_port_cfg *cfg);

	int (*afe_port_suspend) (void *core_handle,
			       struct wcd_cpe_afe_port_cfg *cfg);

	int (*afe_port_resume) (void *core_handle,
			       struct wcd_cpe_afe_port_cfg *cfg);
};

struct wcd_cpe_lsm_ops {

	struct cpe_lsm_session *(*lsm_alloc_session)
			(void *core_handle, void *lsm_priv_d,
			 void (*event_cb) (void *priv_data,
					   u8 detect_status,
					   u8 size, u8 *payload));

	int (*lsm_dealloc_session)
		(void *core_handle, struct cpe_lsm_session *);

	int (*lsm_open_tx) (void *core_handle,
			    struct cpe_lsm_session *, u16, u16);

	int (*lsm_close_tx) (void *core_handle,
			     struct cpe_lsm_session *);

	int (*lsm_shmem_alloc) (void *core_handle,
				struct cpe_lsm_session *, u32 size);

	int (*lsm_shmem_dealloc) (void *core_handle,
				  struct cpe_lsm_session *);

	int (*lsm_register_snd_model) (void *core_handle,
				       struct cpe_lsm_session *,
				       enum lsm_detection_mode, bool);

	int (*lsm_deregister_snd_model) (void *core_handle,
					 struct cpe_lsm_session *);

	int (*lsm_start) (void *core_handle,
			  struct cpe_lsm_session *);

	int (*lsm_stop) (void *core_handle,
			 struct cpe_lsm_session *);

};

int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *);
int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *);
void *wcd_cpe_get_core_handle(struct snd_soc_codec *);
#endif
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ snd-soc-wcd9330-objs := wcd9330.o wcd9330-tables.o
snd-soc-wcd9xxx-objs := wcd9xxx-resmgr.o wcd9xxx-mbhc.o wcd9xxx-common.o
snd-soc-msm8x10-wcd-objs := msm8x10-wcd.o msm8x10-wcd-tables.o wcd9xxx-common.o
snd-soc-msm8x16-wcd-objs := msm8x16-wcd.o msm8x16-wcd-tables.o wcd-mbhc-v2.o
snd-soc-wcd-cpe-objs := wcd_cpe_services.o
snd-soc-wcd-cpe-objs := wcd_cpe_services.o wcd_cpe_core.o
snd-soc-wl1273-objs := wl1273.o
snd-soc-wm-adsp-objs := wm_adsp.o
snd-soc-wm0010-objs := wm0010.o
+103 −4
Original line number Diff line number Diff line
@@ -38,9 +38,10 @@
#include "wcd9330.h"
#include "wcd9xxx-resmgr.h"
#include "wcd9xxx-common.h"
#include "wcd_cpe_core.h"

#define TOMTOM_MAD_SLIMBUS_TX_PORT 12
#define TOMTOM_MAD_AUDIO_FIRMWARE_PATH "wcd9330/wcd9330_mad_audio.bin"
#define TOMTOM_MAD_AUDIO_FIRMWARE_PATH "wcd9320/wcd9320_mad_audio.bin"
#define TOMTOM_VALIDATE_RX_SBPORT_RANGE(port) ((port >= 16) && (port <= 23))
#define TOMTOM_CONVERT_RX_SBPORT_ID(port) (port - 16) /* RX1 port ID = 0 */

@@ -52,6 +53,15 @@
/* RX_HPH_CNP_WG_TIME increases by 0.24ms */
#define TOMTOM_WG_TIME_FACTOR_US	240

#define TOMTOM_CPE_MAJOR_VER 1
#define TOMTOM_CPE_MINOR_VER 0
#define TOMTOM_CPE_CDC_ID 1

static int cpe_debug_mode;
module_param(cpe_debug_mode, int,
	     S_IRUGO | S_IWUSR | S_IWGRP);
MODULE_PARM_DESC(cpe_debug_mode, "boot cpe in debug mode");

static atomic_t kp_tomtom_priv;

static struct afe_param_slimbus_slave_port_cfg tomtom_slimbus_slave_port_cfg = {
@@ -447,6 +457,9 @@ struct tomtom_priv {
	 * end of impedance measurement
	 */
	struct list_head reg_save_restore;

	/* handle to cpe core */
	struct wcd_cpe_core *cpe_core;
};

static const u32 comp_shift[] = {
@@ -1497,6 +1510,9 @@ static const char * const rx_rdac7_text[] = {
	"DEM6", "DEM5_INV"
};

static const char * const mad_sel_text[] = {
	"SPE", "MSM"
};

static const char * const sb_tx1_mux_text[] = {
	"ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
@@ -1678,6 +1694,9 @@ static const struct soc_enum rx_rdac5_enum =
static const struct soc_enum rx_rdac7_enum =
	SOC_ENUM_SINGLE(TOMTOM_A_CDC_CONN_MISC, 1, 2, rx_rdac7_text);

static const struct soc_enum mad_sel_enum =
	SOC_ENUM_SINGLE(TOMTOM_A_SVASS_CFG, 0, 2, mad_sel_text);

static const struct soc_enum sb_tx1_mux_enum =
	SOC_ENUM_SINGLE(TOMTOM_A_CDC_CONN_TX_SB_B1_CTL, 0, 10, sb_tx1_mux_text);

@@ -1850,6 +1869,9 @@ static const struct snd_kcontrol_new rx_dac5_mux =
static const struct snd_kcontrol_new rx_dac7_mux =
	SOC_DAPM_ENUM("RDAC7 MUX Mux", rx_rdac7_enum);

static const struct snd_kcontrol_new mad_sel_mux =
	SOC_DAPM_ENUM("MAD_SEL MUX Mux", mad_sel_enum);

static const struct snd_kcontrol_new sb_tx1_mux =
	SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);

@@ -2081,7 +2103,7 @@ static const struct snd_kcontrol_new lineout4_ground_switch =
	SOC_DAPM_SINGLE("Switch", TOMTOM_A_RX_LINE_4_DAC_CTL, 6, 1, 0);

static const struct snd_kcontrol_new aif4_mad_switch =
	SOC_DAPM_SINGLE("Switch", TOMTOM_A_CDC_CLK_OTHR_CTL, 4, 1, 0);
	SOC_DAPM_SINGLE("Switch", TOMTOM_A_SVASS_CLKRST_CTL, 0, 1, 0);

/* virtual port entries */
static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
@@ -2748,6 +2770,10 @@ static int tomtom_codec_config_mad(struct snd_soc_codec *codec)
		      mad_cal->ultrasound_info.rms_threshold_msb);

	release_firmware(fw);

	/* Set MAD intr time to 20 msec */
	snd_soc_update_bits(codec, 0x4E, 0x01F, 0x13);

	pr_debug("%s: leave ret %d\n", __func__, ret);

	return ret;
@@ -3531,9 +3557,10 @@ static const struct snd_soc_dapm_route audio_map[] = {
	{"AIF4 VI", NULL, "SPK_OUT"},

	/* MAD */
	{"AIF4 MAD", NULL, "CDC_CONN"},
	{"MADONOFF", "Switch", "MADINPUT"},
	{"AIF4 MAD", NULL, "MADONOFF"},
	{"MAD_SEL MUX", "SPE", "MADONOFF"},
	{"MAD_SEL MUX", "MSM", "MADONOFF"},
	{"AIF4 MAD", NULL, "MAD_SEL MUX"},

	/* SLIM_MIXER("AIF1_CAP Mixer"),*/
	{"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
@@ -4330,6 +4357,9 @@ static int tomtom_volatile(struct snd_soc_codec *ssc, unsigned int reg)
		    TOMTOM_REGISTER_START_OFFSET == reg)
			return 1;

	if (reg == TOMTOM_A_SVASS_SPE_INBOX_TRG)
		return 1;

	return 0;
}

@@ -5657,6 +5687,9 @@ static const struct snd_soc_dapm_widget tomtom_dapm_widgets[] = {
	SND_SOC_DAPM_MUX("RDAC7 MUX", SND_SOC_NOPM, 0, 0,
		&rx_dac7_mux),

	SND_SOC_DAPM_MUX("MAD_SEL MUX", SND_SOC_NOPM, 0, 0,
		&mad_sel_mux),

	SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0,
		&class_h_dsm_mux, tomtom_codec_dsm_mux_event,
		SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
@@ -6982,6 +7015,72 @@ static struct regulator *tomtom_codec_find_regulator(struct snd_soc_codec *cdc,
	return NULL;
}

static struct wcd_cpe_core *tomtom_codec_get_cpe_core(
		struct snd_soc_codec *codec)
{
	struct tomtom_priv *priv = snd_soc_codec_get_drvdata(codec);
	return priv->cpe_core;
}

static int tomtom_codec_fll_enable(struct snd_soc_codec *codec,
				   bool enable)
{
	if (enable) {
		snd_soc_update_bits(codec, TOMTOM_A_FLL_KDCO_TUNE,
				    0x07, 0x05);
		snd_soc_write(codec, TOMTOM_A_FLL_LOCK_THRESH,
			      0xC2);
		snd_soc_write(codec, TOMTOM_A_FLL_LOCK_DET_COUNT,
			      0x40);
		snd_soc_update_bits(codec, TOMTOM_A_FLL_KDCO_TUNE,
				    0x80, 0x80);
		snd_soc_update_bits(codec, TOMTOM_A_FLL_TEST_ENABLE,
				    0x06, 0x06);
	} else {
		snd_soc_update_bits(codec, TOMTOM_A_FLL_KDCO_TUNE,
				    0x80, 0x00);
	}

	return 0;
}

static void tomtom_codec_cpe_setup_callbacks(
		struct wcd_cpe_cdc_cb *cpe_cb)
{
	cpe_cb->cdc_clk_en = tomtom_codec_internal_rco_ctrl;
	cpe_cb->cpe_clk_en = tomtom_codec_fll_enable;
}

int tomtom_enable_cpe(struct snd_soc_codec *codec)
{
	struct tomtom_priv *tomtom = snd_soc_codec_get_drvdata(codec);
	struct wcd_cpe_params cpe_params;
	struct wcd_cpe_cdc_cb cpe_cdc_cb;

	tomtom_codec_cpe_setup_callbacks(&cpe_cdc_cb);
	memset(&cpe_params, 0,
	       sizeof(struct wcd_cpe_params));
	cpe_params.codec = codec;
	cpe_params.get_cpe_core = tomtom_codec_get_cpe_core;
	cpe_params.cdc_cb = &cpe_cdc_cb;
	cpe_params.dbg_mode = cpe_debug_mode;
	cpe_params.cdc_major_ver = TOMTOM_CPE_MAJOR_VER;
	cpe_params.cdc_minor_ver = TOMTOM_CPE_MINOR_VER;
	cpe_params.cdc_id = TOMTOM_CPE_CDC_ID;

	tomtom->cpe_core = wcd_cpe_init_and_boot("cpe", codec,
						 &cpe_params);
	if (IS_ERR_OR_NULL(tomtom->cpe_core)) {
		dev_err(codec->dev,
			"%s: Failed to enable CPE\n",
			__func__);
		return -EINVAL;
	}

	return 0;
}
EXPORT_SYMBOL(tomtom_enable_cpe);

static int tomtom_codec_probe(struct snd_soc_codec *codec)
{
	struct wcd9xxx *control;
+1 −0
Original line number Diff line number Diff line
@@ -116,4 +116,5 @@ extern void tomtom_register_ext_clk_cb(
				int enable, bool dapm),
	int (*get_ext_clk_cnt) (void),
	struct snd_soc_codec *codec);
extern int tomtom_enable_cpe(struct snd_soc_codec *codec);
#endif
Loading