// SPDX-License-Identifier: GPL-2.0
//
// rt700.c -- rt700 ALSA SoC audio driver
//
// Copyright(c) 2019 Realtek Semiconductor Corp.
//
//
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/pm.h>
#include <linux/soundwire/sdw.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <sound/hda_verbs.h>
#include <sound/jack.h>
#include "rt700.h"
static int rt700_index_write(struct regmap *regmap,
unsigned int reg, unsigned int value)
{
int ret;
unsigned int addr = (RT700_PRIV_INDEX_W_H << 8) | reg;
ret = regmap_write(regmap, addr, value);
if (ret < 0)
pr_err("Failed to set private value: %06x <= %04x ret=%d\n",
addr, value, ret);
return ret;
}
static int rt700_index_read(struct regmap *regmap,
unsigned int reg, unsigned int *value)
{
int ret;
unsigned int addr = (RT700_PRIV_INDEX_W_H << 8) | reg;
*value = 0;
ret = regmap_read(regmap, addr, value);
if (ret < 0)
pr_err("Failed to get private value: %06x => %04x ret=%d\n",
addr, *value, ret);
return ret;
}
static unsigned int rt700_button_detect(struct rt700_priv *rt700)
{
unsigned int btn_type = 0, val80, val81;
int ret;
ret = rt700_index_read(rt700->regmap, RT700_IRQ_FLAG_TABLE1, &val80);
if (ret < 0)
goto read_error;
ret = rt700_index_read(rt700->regmap, RT700_IRQ_FLAG_TABLE2, &val81);
if (ret < 0)
goto read_error;
val80 &= 0x0381;
val81 &= 0xff00;
switch (val80) {
case 0x0200:
case 0x0100:
case 0x0080:
btn_type |= SND_JACK_BTN_0;
break;
case 0x0001:
btn_type |= SND_JACK_BTN_3;
break;
}
switch (val81) {
case 0x8000:
case 0x4000:
case 0x2000:
btn_type |= SND_JACK_BTN_1;
break;
case 0x1000:
case 0x0800:
case 0x0400:
btn_type |= SND_JACK_BTN_2;
break;
case 0x0200: