xref: /linux/sound/soc/codecs/fs-amp-lib.h (revision 68a052239fc4b351e961f698b824f7654a346091)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * fs-amp-lib.h --- Common library for FourSemi Audio Amplifiers
4  *
5  * Copyright (C) 2016-2025 Shanghai FourSemi Semiconductor Co.,Ltd.
6  */
7 
8 #ifndef __FS_AMP_LIB_H__
9 #define __FS_AMP_LIB_H__
10 
11 #define HI_U16(a)		(((a) >> 8) & 0xFF)
12 #define LO_U16(a)		((a) & 0xFF)
13 #define FS_TABLE_NAME_LEN	(4)
14 #define FS_SCENE_COUNT_MAX	(16)
15 #define FS_CMD_DELAY_MS_MAX	(100) /* 100ms */
16 
17 #define FS_CMD_DELAY		(0xFF)
18 #define FS_CMD_BURST		(0xFE)
19 #define FS_CMD_UPDATE		(0xFD)
20 
21 #define FS_SOC_ENUM_EXT(xname, xhandler_info, xhandler_get, xhandler_put) \
22 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
23 	.info = xhandler_info, \
24 	.get = xhandler_get, .put = xhandler_put \
25 }
26 
27 enum fs_index_type {
28 	FS_INDEX_INFO = 0,
29 	FS_INDEX_STCOEF,
30 	FS_INDEX_SCENE,
31 	FS_INDEX_MODEL,
32 	FS_INDEX_REG,
33 	FS_INDEX_EFFECT,
34 	FS_INDEX_STRING,
35 	FS_INDEX_WOOFER,
36 	FS_INDEX_MAX,
37 };
38 
39 #pragma pack(push, 1)
40 
41 struct fs_reg_val {
42 	u8 reg;
43 	u16 val;
44 };
45 
46 struct fs_reg_bits {
47 	u8 cmd; /* FS_CMD_UPDATE */
48 	u8 reg;
49 	u16 val;
50 	u16 mask;
51 };
52 
53 struct fs_cmd_pkg {
54 	union {
55 		u8 cmd;
56 		struct fs_reg_val regv;
57 		struct fs_reg_bits regb;
58 	};
59 };
60 
61 struct fs_fwm_index {
62 	/* Index type */
63 	u16 type;
64 	/* Offset address starting from the end of header */
65 	u16 offset;
66 };
67 
68 struct fs_fwm_table {
69 	char name[FS_TABLE_NAME_LEN];
70 	u16 size; /* size of buf */
71 	u8 buf[];
72 };
73 
74 struct fs_scene_index {
75 	/* Offset address(scene name) in string table */
76 	u16 name;
77 	/* Offset address(scene reg) in register table */
78 	u16 reg;
79 	/* Offset address(scene model) in model table */
80 	u16 model;
81 	/* Offset address(scene effect) in effect table */
82 	u16 effect;
83 };
84 
85 struct fs_reg_table {
86 	u16 size; /* size of buf */
87 	u8 buf[];
88 };
89 
90 struct fs_file_table {
91 	u16 name;
92 	u16 size; /* size of buf */
93 	u8 buf[];
94 };
95 
96 struct fs_fwm_date {
97 	u32 year:12;
98 	u32 month:4;
99 	u32 day:5;
100 	u32 hour:5;
101 	u32 minute:6;
102 };
103 
104 struct fs_fwm_header {
105 	u16 version;
106 	u16 project; /* Offset address(project name) in string table */
107 	u16 device; /* Offset address(device name) in string table */
108 	struct fs_fwm_date date;
109 	u16 crc16;
110 	u16 crc_size; /* Starting position for CRC checking */
111 	u16 chip_type;
112 	u16 addr; /* 7-bit i2c address */
113 	u16 spkid;
114 	u16 rsvd[6];
115 	u8 params[];
116 };
117 
118 #pragma pack(pop)
119 
120 struct fs_i2s_srate {
121 	u32 srate; /* Sample rate */
122 	u16 i2ssr; /* Value of Bit field[I2SSR] */
123 };
124 
125 struct fs_pll_div {
126 	unsigned int bclk; /* Rate of bit clock */
127 	u16 pll1;
128 	u16 pll2;
129 	u16 pll3;
130 };
131 
132 struct fs_amp_scene {
133 	const char *name;
134 	const struct fs_reg_table  *reg;
135 	const struct fs_file_table *model;
136 	const struct fs_file_table *effect;
137 };
138 
139 struct fs_amp_lib {
140 	const struct fs_fwm_header *hdr;
141 	const struct fs_fwm_table *table[FS_INDEX_MAX];
142 	struct fs_amp_scene *scene;
143 	struct device *dev;
144 	int scene_count;
145 	u16 devid;
146 };
147 
148 int fs_amp_load_firmware(struct fs_amp_lib *amp_lib, const char *name);
149 
150 #endif // __FS_AMP_LIB_H__
151