| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
// |
| 3 |
// rt-sdw-common.h |
| 4 |
// |
| 5 |
// Copyright(c) 2024 Realtek Semiconductor Corp. |
| 6 |
// |
| 7 |
|
| 8 |
/* |
| 9 |
* This file defines common functions used with Realtek soundwire codecs. |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef __RT_SDW_COMMON_H__ |
| 13 |
#define __RT_SDW_COMMON_H__ |
| 14 |
|
| 15 |
#define SDCA_NUM_JACK_CODEC 0x01 |
| 16 |
#define SDCA_NUM_MIC_ARRAY 0x02 |
| 17 |
#define SDCA_NUM_HID 0x03 |
| 18 |
#define SDCA_NUM_AMP 0x04 |
| 19 |
#define RT_SDCA_CTL_SELECTED_MODE 0x01 |
| 20 |
#define RT_SDCA_CTL_DETECTED_MODE 0x02 |
| 21 |
#define RT_SDCA_CTL_HIDTX_CURRENT_OWNER 0x10 |
| 22 |
#define RT_SDCA_CTL_HIDTX_MESSAGE_OFFSET 0x12 |
| 23 |
|
| 24 |
struct rt_sdca_dmic_kctrl_priv { |
| 25 |
unsigned int reg_base; |
| 26 |
unsigned int count; |
| 27 |
unsigned int max; |
| 28 |
unsigned int invert; |
| 29 |
}; |
| 30 |
|
| 31 |
#define RT_SDCA_PR_VALUE(xreg_base, xcount, xmax, xinvert) \ |
| 32 |
((unsigned long)&(struct rt_sdca_dmic_kctrl_priv) \ |
| 33 |
{.reg_base = xreg_base, .count = xcount, .max = xmax, \ |
| 34 |
.invert = xinvert}) |
| 35 |
|
| 36 |
#define RT_SDCA_FU_CTRL(xname, reg_base, xmax, xinvert, xcount, \ |
| 37 |
xinfo, xget, xput) \ |
| 38 |
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ |
| 39 |
.info = xinfo, \ |
| 40 |
.get = xget, \ |
| 41 |
.put = xput, \ |
| 42 |
.private_value = RT_SDCA_PR_VALUE(reg_base, xcount, xmax, xinvert)} |
| 43 |
|
| 44 |
#define RT_SDCA_EXT_TLV(xname, reg_base, xhandler_get,\ |
| 45 |
xhandler_put, xcount, xmax, tlv_array, xinfo) \ |
| 46 |
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ |
| 47 |
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 48 |
SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 49 |
.tlv.p = (tlv_array), \ |
| 50 |
.info = xinfo, \ |
| 51 |
.get = xhandler_get, .put = xhandler_put, \ |
| 52 |
.private_value = RT_SDCA_PR_VALUE(reg_base, xcount, xmax, 0) } |
| 53 |
|
| 54 |
|
| 55 |
int rt_sdca_index_write(struct regmap *map, unsigned int nid, |
| 56 |
unsigned int reg, unsigned int value); |
| 57 |
int rt_sdca_index_read(struct regmap *map, unsigned int nid, |
| 58 |
unsigned int reg, unsigned int *value); |
| 59 |
int rt_sdca_index_update_bits(struct regmap *map, |
| 60 |
unsigned int nid, unsigned int reg, unsigned int mask, unsigned int val); |
| 61 |
int rt_sdca_btn_type(unsigned char *buffer); |
| 62 |
int rt_sdca_headset_detect(struct regmap *map, unsigned int entity_id); |
| 63 |
int rt_sdca_button_detect(struct regmap *map, unsigned int entity_id, |
| 64 |
unsigned int hid_buf_addr, unsigned int hid_id); |
| 65 |
|
| 66 |
#endif /* __RT_SDW_COMMON_H__ */ |