1 /*
2 ** =============================================================================
3 ** Copyright (c) 2016 Texas Instruments Inc.
4 **
5 ** This program is free software; you can redistribute it and/or modify it under
6 ** the terms of the GNU General Public License as published by the Free Software
7 ** Foundation; version 2.
8 **
9 ** This program is distributed in the hope that it will be useful, but WITHOUT
10 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 ** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 **
13 ** You should have received a copy of the GNU General Public License along with
14 ** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 ** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 **
17 ** File:
18 ** tas2555.h
19 **
20 ** Description:
21 ** definitions and data structures for TAS2555 Android Linux driver
22 **
23 ** =============================================================================
24 */
26 #ifndef _TAS2555_H
27 #define _TAS2555_H
29 #include <linux/regmap.h>
31 /* Page Control Register */
32 #define TAS2555_PAGECTL_REG 0
34 /* Book Control Register (available in page0 of each book) */
35 #define TAS2555_BOOKCTL_PAGE 0
36 #define TAS2555_BOOKCTL_REG 127
38 #define TAS2555_REG(book, page, reg) ((((unsigned int)book * 256 * 128) + \
39 ((unsigned int)page * 128)) + reg)
41 #define TAS2555_BOOK_ID(reg) ((unsigned char)(reg / (256 * 128)))
42 #define TAS2555_PAGE_ID(reg) ((unsigned char)((reg % (256 * 128)) / 128))
43 #define TAS2555_BOOK_REG(reg) ((unsigned char)(reg % (256 * 128)))
44 #define TAS2555_PAGE_REG(reg) ((unsigned char)((reg % (256 * 128)) % 128))
46 /* Book0, Page0 registers */
47 #define TAS2555_SW_RESET_REG TAS2555_REG(0, 0, 1)
48 #define TAS2555_REV_PGID_REG TAS2555_REG(0, 0, 3)
49 #define TAS2555_POWER_CTRL1_REG TAS2555_REG(0, 0, 4)
50 #define TAS2555_POWER_CTRL2_REG TAS2555_REG(0, 0, 5)
52 #define TAS2555_SPK_CTRL_REG TAS2555_REG(0, 0, 6)
53 /* B0P0R6 - TAS2555_SPK_CTRL_REG */
54 #define TAS2555_DAC_GAIN_MASK (0xf << 3)
55 #define TAS2555_DAC_GAIN_SHIFT 0x03
57 #define TAS2555_MUTE_REG TAS2555_REG(0, 0, 7)
58 #define TAS2555_CHANNEL_CTRL_REG TAS2555_REG(0, 0, 8)
59 #define TAS2555_ADC_INPUT_SEL_REG TAS2555_REG(0, 0, 9)
60 #define TAS2555_NONAME10_REG TAS2555_REG(0, 0, 10)
61 #define TAS2555_NONAME11_REG TAS2555_REG(0, 0, 11)
62 #define TAS2555_NONAME12_REG TAS2555_REG(0, 0, 12)
63 #define TAS2555_NONAME13_REG TAS2555_REG(0, 0, 13)
64 #define TAS2555_NONAME14_REG TAS2555_REG(0, 0, 14)
65 #define TAS2555_NONAME15_REG TAS2555_REG(0, 0, 15)
66 #define TAS2555_NONAME16_REG TAS2555_REG(0, 0, 16)
67 #define TAS2555_NONAME17_REG TAS2555_REG(0, 0, 17)
68 #define TAS2555_NONAME18_REG TAS2555_REG(0, 0, 18)
69 #define TAS2555_SAR_SAMPLING_TIME_REG TAS2555_REG(0, 0, 19)
70 #define TAS2555_SAR_ADC1_REG TAS2555_REG(0, 0, 20)
71 #define TAS2555_SAR_ADC2_REG TAS2555_REG(0, 0, 21)
72 #define TAS2555_CRC_CHECKSUM_REG TAS2555_REG(0, 0, 32)
73 #define TAS2555_CRC_RESET_REG TAS2555_REG(0, 0, 33)
74 #define TAS2555_DSP_MODE_SELECT_REG TAS2555_REG(0, 0, 34)
75 #define TAS2555_NONAME42_REG TAS2555_REG(0, 0, 42)
76 #define TAS2555_CLK_ERR_CTRL TAS2555_REG(0, 0, 44)
77 #define TAS2555_POWER_UP_FLAG_REG TAS2555_REG(0, 0, 100)
78 #define TAS2555_FLAGS_1 TAS2555_REG(0, 0, 104)
79 #define TAS2555_FLAGS_2 TAS2555_REG(0, 0, 108)
80 /* Book0, Page1 registers */
81 #define TAS2555_ASI1_DAC_FORMAT_REG TAS2555_REG(0, 1, 1)
82 #define TAS2555_ASI1_ADC_FORMAT_REG TAS2555_REG(0, 1, 2)
83 #define TAS2555_ASI1_OFFSET1_REG TAS2555_REG(0, 1, 3)
84 #define TAS2555_ASI1_ADC_PATH_REG TAS2555_REG(0, 1, 7)
85 #define TAS2555_ASI1_DAC_BCLK_REG TAS2555_REG(0, 1, 8)
86 #define TAS2555_ASI1_DAC_WCLK_REG TAS2555_REG(0, 1, 9)
87 #define TAS2555_ASI1_ADC_BCLK_REG TAS2555_REG(0, 1, 10)
88 #define TAS2555_ASI1_ADC_WCLK_REG TAS2555_REG(0, 1, 11)
89 #define TAS2555_ASI1_DIN_DOUT_MUX_REG TAS2555_REG(0, 1, 12)
90 #define TAS2555_ASI1_BDIV_CLK_SEL_REG TAS2555_REG(0, 1, 13)
91 #define TAS2555_ASI1_BDIV_CLK_RATIO_REG TAS2555_REG(0, 1, 14)
92 #define TAS2555_ASI1_WDIV_CLK_RATIO_REG TAS2555_REG(0, 1, 15)
93 #define TAS2555_ASI1_DAC_CLKOUT_REG TAS2555_REG(0, 1, 16)
94 #define TAS2555_ASI1_ADC_CLKOUT_REG TAS2555_REG(0, 1, 17)
96 #define TAS2555_ASI2_DAC_FORMAT_REG TAS2555_REG(0, 1, 21)
97 #define TAS2555_ASI2_ADC_FORMAT_REG TAS2555_REG(0, 1, 22)
98 #define TAS2555_ASI2_OFFSET1_REG TAS2555_REG(0, 1, 23)
99 #define TAS2555_ASI2_ADC_PATH_REG TAS2555_REG(0, 1, 27)
100 #define TAS2555_ASI2_DAC_BCLK_REG TAS2555_REG(0, 1, 28)
101 #define TAS2555_ASI2_DAC_WCLK_REG TAS2555_REG(0, 1, 29)
102 #define TAS2555_ASI2_ADC_BCLK_REG TAS2555_REG(0, 1, 30)
103 #define TAS2555_ASI2_ADC_WCLK_REG TAS2555_REG(0, 1, 31)
104 #define TAS2555_ASI2_DIN_DOUT_MUX_REG TAS2555_REG(0, 1, 32)
105 #define TAS2555_ASI2_BDIV_CLK_SEL_REG TAS2555_REG(0, 1, 33)
106 #define TAS2555_ASI2_BDIV_CLK_RATIO_REG TAS2555_REG(0, 1, 34)
107 #define TAS2555_ASI2_WDIV_CLK_RATIO_REG TAS2555_REG(0, 1, 35)
108 #define TAS2555_ASI2_DAC_CLKOUT_REG TAS2555_REG(0, 1, 36)
109 #define TAS2555_ASI2_ADC_CLKOUT_REG TAS2555_REG(0, 1, 37)
111 #define TAS2555_GPIO1_PIN_REG TAS2555_REG(0, 1, 61)
112 #define TAS2555_GPIO2_PIN_REG TAS2555_REG(0, 1, 62)
113 #define TAS2555_GPIO3_PIN_REG TAS2555_REG(0, 1, 63)
114 #define TAS2555_GPIO4_PIN_REG TAS2555_REG(0, 1, 64)
115 #define TAS2555_GPIO5_PIN_REG TAS2555_REG(0, 1, 65)
116 #define TAS2555_GPIO6_PIN_REG TAS2555_REG(0, 1, 66)
117 #define TAS2555_GPIO7_PIN_REG TAS2555_REG(0, 1, 67)
118 #define TAS2555_GPIO8_PIN_REG TAS2555_REG(0, 1, 68)
119 #define TAS2555_GPIO9_PIN_REG TAS2555_REG(0, 1, 69)
120 #define TAS2555_GPIO10_PIN_REG TAS2555_REG(0, 1, 70)
122 #define TAS2555_GPI_PIN_REG TAS2555_REG(0, 1, 77)
123 #define TAS2555_GPIO_HIZ_CTRL1_REG TAS2555_REG(0, 1, 79)
124 #define TAS2555_GPIO_HIZ_CTRL2_REG TAS2555_REG(0, 1, 80)
125 #define TAS2555_GPIO_HIZ_CTRL3_REG TAS2555_REG(0, 1, 81)
126 #define TAS2555_GPIO_HIZ_CTRL4_REG TAS2555_REG(0, 1, 82)
127 #define TAS2555_GPIO_HIZ_CTRL5_REG TAS2555_REG(0, 1, 83)
129 #define TAS2555_BIT_BANG_CTRL_REG TAS2555_REG(0, 1, 87)
130 #define TAS2555_BIT_BANG_OUT1_REG TAS2555_REG(0, 1, 88)
131 #define TAS2555_BIT_BANG_OUT2_REG TAS2555_REG(0, 1, 89)
132 #define TAS2555_BIT_BANG_IN1_REG TAS2555_REG(0, 1, 90)
133 #define TAS2555_BIT_BANG_IN2_REG TAS2555_REG(0, 1, 91)
134 #define TAS2555_BIT_BANG_IN3_REG TAS2555_REG(0, 1, 92)
136 #define TAS2555_PDM_IN_CLK_REG TAS2555_REG(0, 1, 94)
137 #define TAS2555_PDM_IN_PIN_REG TAS2555_REG(0, 1, 95)
139 #define TAS2555_ASIM_IFACE1_REG TAS2555_REG(0, 1, 98)
140 #define TAS2555_ASIM_FORMAT_REG TAS2555_REG(0, 1, 99)
141 #define TAS2555_ASIM_IFACE3_REG TAS2555_REG(0, 1, 100)
142 #define TAS2555_ASIM_IFACE4_REG TAS2555_REG(0, 1, 101)
143 #define TAS2555_ASIM_IFACE5_REG TAS2555_REG(0, 1, 102)
144 #define TAS2555_ASIM_IFACE6_REG TAS2555_REG(0, 1, 103)
145 #define TAS2555_ASIM_IFACE7_REG TAS2555_REG(0, 1, 104)
146 #define TAS2555_ASIM_IFACE8_REG TAS2555_REG(0, 1, 105)
147 #define TAS2555_ASIM_IFACE9_REG TAS2555_REG(0, 1, 106)
149 #define TAS2555_MAIN_CLKIN_REG TAS2555_REG(0, 1, 115)
150 #define TAS2555_PLL_CLKIN_REG TAS2555_REG(0, 1, 116)
151 #define TAS2555_CLKOUT_MUX_REG TAS2555_REG(0, 1, 117)
152 #define TAS2555_CLKOUT_CDIV_REG TAS2555_REG(0, 1, 118)
154 #define TAS2555_HACK_GP01_REG TAS2555_REG(0, 1, 122)
156 #define TAS2555_HACK01_REG TAS2555_REG(0, 2, 10)
158 #define TAS2555_TEST_MODE_REG TAS2555_REG(0, 253, 13)
159 #define TAS2555_BROADCAST_REG TAS2555_REG(0, 253, 54)
160 #define TAS2555_CRYPTIC_REG TAS2555_REG(0, 253, 71)
162 //#define TAS2555__REG TAS2555_REG(0, 1, )
163 //#define TAS2555__REG TAS2555_REG(1, 0, )
164 #define TAS2555_DAC_INTERPOL_REG TAS2555_REG(100, 0, 1)
165 #define TAS2555_SOFT_MUTE_REG TAS2555_REG(100, 0, 7)
166 #define TAS2555_PLL_P_VAL_REG TAS2555_REG(100, 0, 27)
167 #define TAS2555_PLL_J_VAL_REG TAS2555_REG(100, 0, 28)
168 #define TAS2555_PLL_D_VAL_MSB_REG TAS2555_REG(100, 0, 29)
169 #define TAS2555_PLL_D_VAL_LSB_REG TAS2555_REG(100, 0, 30)
170 #define TAS2555_CLK_MISC_REG TAS2555_REG(100, 0, 31)
171 #define TAS2555_PLL_N_VAL_REG TAS2555_REG(100, 0, 32)
172 #define TAS2555_DAC_MADC_VAL_REG TAS2555_REG(100, 0, 33)
173 #define TAS2555_ISENSE_DIV_REG TAS2555_REG(100, 0, 42)
174 #define TAS2555_RAMP_CLK_DIV_MSB_REG TAS2555_REG(100, 0, 43)
175 #define TAS2555_RAMP_CLK_DIV_LSB_REG TAS2555_REG(100, 0, 44)
176 /* Bits */
177 /* B0P0R4 - TAS2555_POWER_CTRL1_REG */
178 #define TAS2555_SW_SHUTDOWN (0x1 << 0)
179 #define TAS2555_MADC_POWER_UP (0x1 << 3)
180 #define TAS2555_MDAC_POWER_UP (0x1 << 4)
181 #define TAS2555_NDIV_POWER_UP (0x1 << 5)
182 #define TAS2555_PLL_POWER_UP (0x1 << 6)
183 #define TAS2555_DSP_POWER_UP (0x1 << 7)
185 /* B0P0R5 - TAS2555_POWER_CTRL2_REG */
186 #define TAS2555_VSENSE_ENABLE (0x1 << 0)
187 #define TAS2555_ISENSE_ENABLE (0x1 << 1)
188 #define TAS2555_BOOST_ENABLE (0x1 << 5)
189 #define TAS2555_CLASSD_ENABLE (0x1 << 7)
191 /* B0P0R7 - TAS2555_MUTE_REG */
192 #define TAS2555_CLASSD_MUTE (0x1 << 0)
193 #define TAS2555_ISENSE_MUTE (0x1 << 1)
195 /* B0P253R13 - TAS2555_TEST_MODE_REG */
196 #define TAS2555_TEST_MODE_ENABLE (13)
197 #define TAS2555_TEST_MODE_MASK (0xf << 0)
199 /* B0P253R71 - TAS2555_CRYPTIC_REG */
200 #define TAS2555_OSC_TRIM_CAP(x) ((x & 0x3f) << 0)
201 #define TAS2555_DISABLE_ENCRYPTION (0x1 << 6)
202 #define TAS2555_SL_COMP (0x1 << 7)
204 /* B0P1R115/6 - TAS2555_MAIN/PLL_CLKIN_REG */
205 #define TAS2555_XXX_CLKIN_GPIO1 (0)
206 #define TAS2555_XXX_CLKIN_GPIO2 (1)
207 #define TAS2555_XXX_CLKIN_GPIO3 (2)
208 #define TAS2555_XXX_CLKIN_GPIO4 (3)
209 #define TAS2555_XXX_CLKIN_GPIO5 (4)
210 #define TAS2555_XXX_CLKIN_GPIO6 (5)
211 #define TAS2555_XXX_CLKIN_GPIO7 (6)
212 #define TAS2555_XXX_CLKIN_GPIO8 (7)
213 #define TAS2555_XXX_CLKIN_GPIO9 (8)
214 #define TAS2555_XXX_CLKIN_GPIO10 (9)
215 #define TAS2555_XXX_CLKIN_GPI1 (12)
216 #define TAS2555_XXX_CLKIN_GPI2 (13)
217 #define TAS2555_XXX_CLKIN_GPI3 (14)
218 #define TAS2555_NDIV_CLKIN_PLL (15)
219 #define TAS2555_PLL_CLKIN_INT_OSC (15)
221 #define TAS2555_MCLK_CLKIN_SRC_GPIO1 (0)
222 #define TAS2555_MCLK_CLKIN_SRC_GPIO2 (1)
223 #define TAS2555_MCLK_CLKIN_SRC_GPIO3 (2)
224 #define TAS2555_MCLK_CLKIN_SRC_GPIO4 (3)
225 #define TAS2555_MCLK_CLKIN_SRC_GPIO5 (4)
226 #define TAS2555_MCLK_CLKIN_SRC_GPIO6 (5)
227 #define TAS2555_MCLK_CLKIN_SRC_GPIO7 (6)
228 #define TAS2555_MCLK_CLKIN_SRC_GPIO8 (7)
229 #define TAS2555_MCLK_CLKIN_SRC_GPIO9 (8)
230 #define TAS2555_MCLK_CLKIN_SRC_GPIO10 (9)
231 #define TAS2555_MCLK_CLKIN_SRC_GPI1 (12)
232 #define TAS2555_MCLK_CLKIN_SRC_GPI2 (13)
233 #define TAS2555_MCLK_CLKIN_SRC_GPI3 (14)
235 #define TAS2555_FORMAT_I2S (0x0 << 5)
236 #define TAS2555_FORMAT_DSP (0x1 << 5)
237 #define TAS2555_FORMAT_RIGHT_J (0x2 << 5)
238 #define TAS2555_FORMAT_LEFT_J (0x3 << 5)
239 #define TAS2555_FORMAT_MONO_PCM (0x4 << 5)
240 #define TAS2555_FORMAT_MASK (0x7 << 5)
242 #define TAS2555_WORDLENGTH_16BIT (0x0 << 3)
243 #define TAS2555_WORDLENGTH_20BIT (0x1 << 3)
244 #define TAS2555_WORDLENGTH_24BIT (0x2 << 3)
245 #define TAS2555_WORDLENGTH_32BIT (0x3 << 3)
246 #define TAS2555_WORDLENGTH_MASK TAS2555_WORDLENGTH_32BIT
248 /* B100P0R7 - TAS2555_SOFT_MUTE_REG */
249 #define TAS2555_PDM_SOFT_MUTE (0x1 << 0)
250 #define TAS2555_VSENSE_SOFT_MUTE (0x1 << 1)
251 #define TAS2555_ISENSE_SOFT_MUTE (0x1 << 2)
252 #define TAS2555_CLASSD_SOFT_MUTE (0x1 << 3)
254 /* B100P0R27 - TAS2555_PLL_P_VAL_REG */
255 #define TAS2555_PLL_P_VAL_MASK (0x3f << 0)
257 /* B100P0R28 - TAS2555_PLL_J_VAL_REG */
258 #define TAS2555_PLL_J_VAL_MASK ((unsigned int ) (0x7f << 0))
259 #define TAS2555_PLL_J_VAL_MASKX 0x00
261 /* B100P0R29-30 - TAS2555_PLL_D_VAL_MSB/LSB_REG */
262 #define TAS2555_PLL_D_MSB_VAL(x) ((x >> 8) & 0x3f)
263 #define TAS2555_PLL_D_LSB_VAL(x) (x & 0xff)
265 /* B100P0R31 - TAS2555_CLK_MISC_REG */
266 #define TAS2555_DSP_CLK_FROM_PLL (0x1 << 5)
268 #define TAS2555_FW_NAME "tas2555s_uCDSP.bin"
270 #define TAS2555_BROADCAST_ADDR 0x4c
272 typedef struct {
273 unsigned int mnType;
274 unsigned char mbPChkSumPresent;
275 unsigned char mnPChkSum;
276 unsigned char mbYChkSumPresent;
277 unsigned char mnYChkSum;
278 unsigned int mnCommands;
279 unsigned char *mpData;
280 } TBlock;
282 typedef struct {
283 char mpName[64];
284 char *mpDescription;
285 unsigned int mnBlocks;
286 TBlock *mpBlocks;
287 } TData;
289 typedef struct {
290 char mpName[64];
291 char *mpDescription;
292 TData mData;
293 } TProgram;
295 typedef struct {
296 char mpName[64];
297 char *mpDescription;
298 TBlock mBlock;
299 } TPLL;
301 typedef struct {
302 char mpName[64];
303 char *mpDescription;
304 unsigned int mnProgram;
305 unsigned int mnPLL;
306 unsigned int mnSamplingRate;
307 TData mData;
308 } TConfiguration;
310 typedef struct
311 {
312 char mpName[64];
313 char *mpDescription;
314 unsigned int mnProgram;
315 unsigned int mnConfiguration;
316 TBlock mBlock;
317 } TCalibration;
319 typedef struct {
320 unsigned int mnFWSize;
321 unsigned int mnChecksum;
322 unsigned int mnPPCVersion;
323 unsigned int mnFWVersion;
324 unsigned int mnDriverVersion;
325 unsigned int mnTimeStamp;
326 char mpDDCName[64];
327 char *mpDescription;
328 unsigned int mnDeviceFamily;
329 unsigned int mnDevice;
330 unsigned int mnPLLs;
331 TPLL *mpPLLs;
332 unsigned int mnPrograms;
333 TProgram *mpPrograms;
334 unsigned int mnConfigurations;
335 TConfiguration *mpConfigurations;
336 unsigned int mnCalibrations;
337 TCalibration *mpCalibrations;
338 } TFirmware;
340 struct tas2555_register {
341 int book;
342 int page;
343 int reg;
344 };
346 enum channel{
347 channel_left = 0x01,
348 channel_right = 0x02,
349 channel_both = (channel_left|channel_right),
350 channel_broadcast = 0x4,
351 } ;
353 struct tas2555_priv {
354 struct device *dev;
355 struct regmap *mpRegmap;
356 struct i2c_client *client;
357 int mnResetGPIO;
358 struct mutex dev_lock;
359 TFirmware *mpFirmware;
360 TFirmware *mpCalFirmware;
361 unsigned int mnCurrentProgram;
362 unsigned int mnCurrentSampleRate;
363 unsigned int mnCurrentConfiguration;
364 unsigned int mnCurrentCalibration;
365 enum channel mnCurrentChannel;
366 unsigned char mnLAddr;
367 unsigned char mnRAddr;
368 unsigned char mnLCurrentBook;
369 unsigned char mnLCurrentPage;
370 unsigned char mnRCurrentBook;
371 unsigned char mnRCurrentPage;
372 unsigned int mnLBroadcastSet;
373 unsigned int mnRBroadcastSet;
374 bool mbTILoadActive;
375 int reset_gpio;
376 bool mbPowerUp;
377 bool mbLoadConfigurationPostPowerUp;
378 bool mbLoadCalibrationPostPowerUp;
379 bool mbCalibrationLoaded;
380 int (*read) (struct tas2555_priv * pTAS2555,
381 enum channel chn,
382 unsigned int reg,
383 unsigned int *pValue);
384 int (*write) (struct tas2555_priv * pTAS2555,
385 enum channel chn,
386 unsigned int reg,
387 unsigned int Value);
388 int (*bulk_read) (struct tas2555_priv * pTAS2555,
389 enum channel chn,
390 unsigned int reg,
391 unsigned char *pData,
392 unsigned int len);
393 int (*bulk_write) (struct tas2555_priv * pTAS2555,
394 enum channel chn,
395 unsigned int reg,
396 unsigned char *pData,
397 unsigned int len);
398 int (*update_bits) (struct tas2555_priv * pTAS2555,
399 enum channel chn,
400 unsigned int reg,
401 unsigned int mask,
402 unsigned int value);
403 int (*set_config) (struct tas2555_priv *pTAS2555,
404 int config);
405 int (*set_calibration) (struct tas2555_priv *pTAS2555,
406 int calibration);
408 #ifdef CONFIG_TAS2555_MISC_STEREO
409 int mnDBGCmd;
410 int mnCurrentReg;
411 struct mutex file_lock;
412 #endif
414 };
416 #endif /* _TAS2555_H */