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

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

Merge "ASoC: wsa881x: Fix calculation of temperature on wsa881x"

parents a83c0842 0f0e407b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ snd-soc-wcd9335-objs := wcd9335.o wcd9xxx-common-v2.o wcd9xxx-resmgr-v2.o
snd-soc-wcd9xxx-objs := wcd9xxx-resmgr.o wcd9xxx-mbhc.o wcd9xxx-common.o
audio-ext-clock-objs := audio-ext-clk.o
snd-soc-wcd-cpe-objs := wcd_cpe_services.o wcd_cpe_core.o
snd-soc-wsa881x-objs := wsa881x.o wsa881x-tables.o wsa881x-regmap.o
snd-soc-wsa881x-objs := wsa881x.o wsa881x-tables.o wsa881x-regmap.o wsa881x-temp-sensor.o
snd-soc-wcd-mbhc-objs := wcd-mbhc-v2.o
snd-soc-wl1273-objs := wl1273.o
snd-soc-wm-adsp-objs := wm_adsp.o
+9 −0
Original line number Diff line number Diff line
@@ -181,6 +181,15 @@ static bool wsa881x_volatile_register(struct device *dev, unsigned int reg)
	case WSA881X_SPKR_STATUS1:
	case WSA881X_SPKR_STATUS2:
	case WSA881X_SPKR_STATUS3:
	case WSA881X_OTP_REG_0:
	case WSA881X_OTP_REG_1:
	case WSA881X_OTP_REG_2:
	case WSA881X_OTP_REG_3:
	case WSA881X_OTP_REG_4:
	case WSA881X_OTP_REG_5:
	case WSA881X_TEMP_DOUT_MSB:
	case WSA881X_TEMP_DOUT_LSB:
	case WSA881X_TEMP_OP:
		return true;
	default:
		return false;
+8 −4
Original line number Diff line number Diff line
@@ -29,8 +29,9 @@
#define WSA881X_TEMP_DOUT_MSB	0x000A
#define WSA881X_TEMP_DOUT_LSB	0x000B
#define TEMP_INVALID	0xFFFF
#define WSA881X_THERMAL_TEMP_OP 0x0003

static void calculate_temp(long temp_val, int dmeas,
static void calculate_temp(long *temp_val, int dmeas,
			struct snd_soc_codec *codec,
			int dig_base_addr)
{
@@ -49,10 +50,10 @@ static void calculate_temp(long temp_val, int dmeas,
	d2 = ((d2_msb << 0x8) | d2_lsb) >> 0x6;

	if (d1 == d2) {
		temp_val = TEMP_INVALID;
		*temp_val = TEMP_INVALID;
		return;
	}
	temp_val = t1 + ((dmeas - d1)/(d2 - d1)) * (t2 - t1);
	*temp_val = t1 + ((dmeas - d1)/(d2 - d1)) * (t2 - t1);
}

static int wsa881x_get_temp(struct thermal_zone_device *thermal,
@@ -82,6 +83,9 @@ static int wsa881x_get_temp(struct thermal_zone_device *thermal,
		pr_err("%s: wsa acquire failed: %d\n", __func__, ret);
		return ret;
	}
	snd_soc_update_bits(codec,
			    pdata->ana_base + WSA881X_THERMAL_TEMP_OP,
			    0x04, 0x04);
	dmeas_cur_msb =
		snd_soc_read(codec,
			pdata->ana_base + WSA881X_TEMP_DOUT_MSB);
@@ -90,7 +94,7 @@ static int wsa881x_get_temp(struct thermal_zone_device *thermal,
			pdata->ana_base + WSA881X_TEMP_DOUT_LSB);
	dmeas = ((dmeas_cur_msb << 0x8) | dmeas_cur_lsb) >> 0x6;
	pr_debug("%s: dmeas: %d\n", __func__, dmeas);
	calculate_temp(temp_val, dmeas, codec, pdata->dig_base);
	calculate_temp(&temp_val, dmeas, codec, pdata->dig_base);
	if (temp_val <= LOW_TEMP_THRESHOLD ||
			temp_val >= HIGH_TEMP_THRESHOLD) {
		ret = -EAGAIN;
+45 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <sound/soc-dapm.h>
#include <sound/tlv.h>
#include "wsa881x.h"
#include "wsa881x-temp-sensor.h"

enum {
	G_18DB = 0,
@@ -83,6 +84,9 @@ struct wsa881x_priv {
	bool visense_enable;
	struct swr_port port[WSA881X_MAX_SWR_PORTS];
	int pd_gpio;
	struct wsa881x_tz_priv tz_pdata;
	int bg_cnt;
	struct mutex bg_lock;
};

#define SWR_SLV_MAX_REG_ADDR	0x390
@@ -338,13 +342,28 @@ static int wsa881x_visense_adc_ctrl(struct snd_soc_codec *codec, bool enable)

static int wsa881x_bandgap_ctrl(struct snd_soc_codec *codec, bool enable)
{
	dev_dbg(codec->dev, "%s: enable:%d\n", __func__, enable);
	struct wsa881x_priv *wsa881x = snd_soc_codec_get_drvdata(codec);

	dev_dbg(codec->dev, "%s: enable:%d, bg_count:%d\n", __func__,
		enable, wsa881x->bg_cnt);
	mutex_lock(&wsa881x->bg_lock);
	if (enable) {
		snd_soc_update_bits(codec, WSA881X_TEMP_OP, 0x08, 0x08);
		++wsa881x->bg_cnt;
		if (wsa881x->bg_cnt == 1) {
			snd_soc_update_bits(codec, WSA881X_TEMP_OP,
					    0x08, 0x08);
			/* 400usec sleep is needed as per HW requirement */
			usleep_range(400, 410);
		}
	} else {
		--wsa881x->bg_cnt;
		if (wsa881x->bg_cnt <= 0) {
			WARN_ON(wsa881x->bg_cnt < 0);
			wsa881x->bg_cnt = 0;
			snd_soc_update_bits(codec, WSA881X_TEMP_OP, 0x08, 0x00);
		}
	}
	mutex_unlock(&wsa881x->bg_lock);
	return 0;
}

@@ -695,6 +714,12 @@ static void wsa881x_init(struct snd_soc_codec *codec)
	snd_soc_update_bits(codec, WSA881X_BOOST_ZX_CTL, 0x20, 0x00);
}

static int32_t wsa881x_resource_acquire(struct snd_soc_codec *codec,
						bool enable)
{
	return wsa881x_bandgap_ctrl(codec, enable);
}

static int wsa881x_probe(struct snd_soc_codec *codec)
{
	struct wsa881x_priv *wsa881x = snd_soc_codec_get_drvdata(codec);
@@ -720,13 +745,28 @@ static int wsa881x_probe(struct snd_soc_codec *codec)
		return ret;
	}
	dev->dev_num = devnum;
	mutex_init(&wsa881x->bg_lock);
	snprintf(wsa881x->tz_pdata.name, sizeof(wsa881x->tz_pdata.name),
		"%s.%x", "wsatz", (u8)dev->addr);
	wsa881x->bg_cnt = 0;
	wsa881x->tz_pdata.codec = codec;
	wsa881x->tz_pdata.dig_base = WSA881X_DIGITAL_BASE;
	wsa881x->tz_pdata.ana_base = WSA881X_ANALOG_BASE;
	wsa881x->tz_pdata.wsa_resource_acquire = wsa881x_resource_acquire;
	wsa881x_init_thermal(&wsa881x->tz_pdata);
	wsa881x_init(codec);

	return ret;
}

static int wsa881x_remove(struct snd_soc_codec *codec)
{
	/* Add codec shutdown sequence */
	struct wsa881x_priv *wsa881x = snd_soc_codec_get_drvdata(codec);

	if (wsa881x->tz_pdata.tz_dev)
		wsa881x_deinit_thermal(wsa881x->tz_pdata.tz_dev);
	mutex_destroy(&wsa881x->bg_lock);

	return 0;
}