summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTracy Yi2016-11-09 19:22:11 -0600
committerTracy Yi2016-11-09 19:22:11 -0600
commitf68888fd493c0de89f8a34ef0394c888c7026633 (patch)
tree4929fbec31612154fb7ef9f50406c55bc7cd7bf0
parent61dd2fb4e715e320ab3ad41bf48a84863a815212 (diff)
downloadtas2560-stereo-android-driver-f68888fd493c0de89f8a34ef0394c888c7026633.tar.gz
tas2560-stereo-android-driver-f68888fd493c0de89f8a34ef0394c888c7026633.tar.xz
tas2560-stereo-android-driver-f68888fd493c0de89f8a34ef0394c888c7026633.zip
<TI-tas2560-stereo>Remove checkpatch errors
Signed-off-by: Tracy Yi <tracy-yi@ti.com>
-rw-r--r--[-rwxr-xr-x]Kconfig2
-rw-r--r--[-rwxr-xr-x]License text GPLv2.txt0
-rw-r--r--[-rwxr-xr-x]Makefile0
-rw-r--r--[-rwxr-xr-x]dai_link.readme0
-rw-r--r--[-rwxr-xr-x]dts.readme0
-rw-r--r--[-rwxr-xr-x]tas2560-codec.c145
-rw-r--r--[-rwxr-xr-x]tas2560-codec.h2
-rw-r--r--[-rwxr-xr-x]tas2560-core.c342
-rw-r--r--[-rwxr-xr-x]tas2560-core.h4
-rw-r--r--[-rwxr-xr-x]tas2560-misc.c532
-rw-r--r--[-rwxr-xr-x]tas2560-misc.h4
-rw-r--r--[-rwxr-xr-x]tas2560-regmap.c265
-rw-r--r--[-rwxr-xr-x]tas2560.h30
13 files changed, 663 insertions, 663 deletions
diff --git a/Kconfig b/Kconfig
index 257a186..e3305a3 100755..100644
--- a/Kconfig
+++ b/Kconfig
@@ -11,5 +11,5 @@ config TAS2560_CODEC_STEREO
11 11
12config TAS2560_MISC_STEREO 12config TAS2560_MISC_STEREO
13 bool "Misc Driver support" 13 bool "Misc Driver support"
14 14
15endif # SND_SOC_TAS2560_STEREO 15endif # SND_SOC_TAS2560_STEREO
diff --git a/License text GPLv2.txt b/License text GPLv2.txt
index d159169..d159169 100755..100644
--- a/License text GPLv2.txt
+++ b/License text GPLv2.txt
diff --git a/Makefile b/Makefile
index 1680dc5..1680dc5 100755..100644
--- a/Makefile
+++ b/Makefile
diff --git a/dai_link.readme b/dai_link.readme
index 59caa20..59caa20 100755..100644
--- a/dai_link.readme
+++ b/dai_link.readme
diff --git a/dts.readme b/dts.readme
index 20c93b0..20c93b0 100755..100644
--- a/dts.readme
+++ b/dts.readme
diff --git a/tas2560-codec.c b/tas2560-codec.c
index 695c8be..d7d3c8f 100755..100644
--- a/tas2560-codec.c
+++ b/tas2560-codec.c
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -25,7 +25,7 @@
25 25
26#ifdef CONFIG_TAS2560_CODEC_STEREO 26#ifdef CONFIG_TAS2560_CODEC_STEREO
27 27
28#define DEBUG 28#define DEBUG
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
31#include <linux/init.h> 31#include <linux/init.h>
@@ -55,37 +55,37 @@
55#define MAX_CLIENTS 8 55#define MAX_CLIENTS 8
56static struct i2c_client *g_client[MAX_CLIENTS]; 56static struct i2c_client *g_client[MAX_CLIENTS];
57 57
58static unsigned int tas2560_read(struct snd_soc_codec *codec, unsigned int reg) 58static unsigned int tas2560_read(struct snd_soc_codec *codec, unsigned int reg)
59{ 59{
60 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 60 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
61 unsigned int value = 0; 61 unsigned int value = 0;
62 int ret = 0; 62 int ret = 0;
63 63
64 dev_err(pTAS2560->dev, "%s, should not get here\n", __FUNCTION__); 64 dev_err(pTAS2560->dev, "%s, should not get here\n", __func__);
65 //ret = pTAS2560->read(pTAS2560, reg, &value); 65 /*ret = pTAS2560->read(pTAS2560, reg, &value);*/
66 if(ret >=0 ) 66 if (ret >= 0)
67 return value; 67 return value;
68 else 68 else
69 return ret; 69 return ret;
70} 70}
71 71
72static int tas2560_write(struct snd_soc_codec *codec, unsigned int reg, 72static int tas2560_write(struct snd_soc_codec *codec, unsigned int reg,
73 unsigned int value) 73 unsigned int value)
74{ 74{
75 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 75 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
76 76
77 dev_err(pTAS2560->dev, "%s, should not get here\n", __FUNCTION__); 77 dev_err(pTAS2560->dev, "%s, should not get here\n", __func__);
78 78
79 return 1;//pTAS2560->write(pTAS2560, reg, value); 79 return 1;/*pTAS2560->write(pTAS2560, reg, value);*/
80} 80}
81 81
82static int tas2560_AIF_post_event(struct snd_soc_dapm_widget *w, 82static int tas2560_AIF_post_event(struct snd_soc_dapm_widget *w,
83 struct snd_kcontrol *kcontrol, int event) 83 struct snd_kcontrol *kcontrol, int event)
84{ 84{
85 struct snd_soc_codec *codec = w->codec; 85 struct snd_soc_codec *codec = w->codec;
86 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 86 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
87 87
88 switch(event){ 88 switch (event) {
89 case SND_SOC_DAPM_POST_PMU: 89 case SND_SOC_DAPM_POST_PMU:
90 dev_dbg(pTAS2560->dev, "SND_SOC_DAPM_POST_PMU"); 90 dev_dbg(pTAS2560->dev, "SND_SOC_DAPM_POST_PMU");
91 tas2560_enable(pTAS2560, true); 91 tas2560_enable(pTAS2560, true);
@@ -99,11 +99,10 @@ static int tas2560_AIF_post_event(struct snd_soc_dapm_widget *w,
99 return 0; 99 return 0;
100} 100}
101 101
102static const struct snd_soc_dapm_widget tas2560_dapm_widgets[] = 102static const struct snd_soc_dapm_widget tas2560_dapm_widgets[] = {
103{
104 SND_SOC_DAPM_AIF_IN_E("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM, 0, 0, 103 SND_SOC_DAPM_AIF_IN_E("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM, 0, 0,
105 tas2560_AIF_post_event,SND_SOC_DAPM_POST_PMU | 104 tas2560_AIF_post_event, SND_SOC_DAPM_POST_PMU |
106 SND_SOC_DAPM_POST_PMD), 105 SND_SOC_DAPM_POST_PMD),
107 SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0), 106 SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
108 107
109 SND_SOC_DAPM_OUT_DRV("ClassD", SND_SOC_NOPM, 0, 0, NULL, 0), 108 SND_SOC_DAPM_OUT_DRV("ClassD", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -125,7 +124,7 @@ static int tas2560_startup(struct snd_pcm_substream *substream,
125{ 124{
126 struct snd_soc_codec *codec = dai->codec; 125 struct snd_soc_codec *codec = dai->codec;
127 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 126 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
128 127
129 dev_dbg(pTAS2560->dev, "%s\n", __func__); 128 dev_dbg(pTAS2560->dev, "%s\n", __func__);
130 pTAS2560->mnClkid = -1; 129 pTAS2560->mnClkid = -1;
131 pTAS2560->mnClkin = -1; 130 pTAS2560->mnClkin = -1;
@@ -146,23 +145,23 @@ static int tas2560_mute(struct snd_soc_dai *dai, int mute)
146{ 145{
147 struct snd_soc_codec *codec = dai->codec; 146 struct snd_soc_codec *codec = dai->codec;
148 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 147 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
149 148
150 dev_dbg(pTAS2560->dev, "%s, %d\n", __func__, mute); 149 dev_dbg(pTAS2560->dev, "%s, %d\n", __func__, mute);
151 150
152 return 0; 151 return 0;
153} 152}
154 153
155static int tas2560_set_dai_sysclk(struct snd_soc_dai *dai,int clk_id, 154static int tas2560_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
156 unsigned int freq, int dir) 155 unsigned int freq, int dir)
157{ 156{
158 struct snd_soc_codec *codec = dai->codec; 157 struct snd_soc_codec *codec = dai->codec;
159 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 158 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
160 int ret = 0; 159 int ret = 0;
161 160
162 dev_dbg(pTAS2560->dev, "%s\n", __func__); 161 dev_dbg(pTAS2560->dev, "%s\n", __func__);
163 162
164 ret = tas2560_set_pll_clkin(pTAS2560, clk_id, freq); 163 ret = tas2560_set_pll_clkin(pTAS2560, clk_id, freq);
165 164
166 return ret; 165 return ret;
167} 166}
168 167
@@ -172,17 +171,17 @@ static int tas2560_hw_params(struct snd_pcm_substream *substream,
172{ 171{
173 struct snd_soc_codec *codec = dai->codec; 172 struct snd_soc_codec *codec = dai->codec;
174 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 173 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
175 174
176 dev_dbg(pTAS2560->dev, "%s\n", __func__); 175 dev_dbg(pTAS2560->dev, "%s\n", __func__);
177 176
178 tas2560_set_SampleRate(pTAS2560, params_rate(params)); 177 tas2560_set_SampleRate(pTAS2560, params_rate(params));
179 tas2560_set_bit_rate(pTAS2560, snd_pcm_format_width(params_format(params))); 178 tas2560_set_bit_rate(pTAS2560, snd_pcm_format_width(params_format(params)));
180 pTAS2560->mnFrameSize = snd_soc_params_to_frame_size(params); 179 pTAS2560->mnFrameSize = snd_soc_params_to_frame_size(params);
181 180
182 if(pTAS2560->mnClkid == -1){ 181 if (pTAS2560->mnClkid == -1) {
183 tas2560_set_dai_sysclk(dai,TAS2560_PLL_CLKIN_BCLK, 0, 1); 182 tas2560_set_dai_sysclk(dai, TAS2560_PLL_CLKIN_BCLK, 0, 1);
184 } 183 }
185 184
186 tas2560_setupPLL(pTAS2560, pTAS2560->mnClkin); 185 tas2560_setupPLL(pTAS2560, pTAS2560->mnClkin);
187 186
188 return 0; 187 return 0;
@@ -206,7 +205,7 @@ static int tas2560_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
206 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 205 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
207 int ret = 0; 206 int ret = 0;
208 207
209 dev_info(codec->dev,"%s, fmt=0x%x\n",__func__, fmt); 208 dev_info(codec->dev, "%s, fmt=0x%x\n", __func__, fmt);
210 ret = tas2560_set_ASI_fmt(pTAS2560, fmt); 209 ret = tas2560_set_ASI_fmt(pTAS2560, fmt);
211 return ret; 210 return ret;
212} 211}
@@ -218,7 +217,7 @@ static struct snd_soc_dai_ops tas2560_dai_ops = {
218 .hw_params = tas2560_hw_params, 217 .hw_params = tas2560_hw_params,
219 .prepare = tas2560_prepare, 218 .prepare = tas2560_prepare,
220 .set_sysclk = tas2560_set_dai_sysclk, 219 .set_sysclk = tas2560_set_dai_sysclk,
221 .set_fmt = tas2560_set_dai_fmt, 220 .set_fmt = tas2560_set_dai_fmt,
222}; 221};
223 222
224#define TAS2560_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 223#define TAS2560_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
@@ -243,18 +242,20 @@ static int tas2560_codec_probe(struct snd_soc_codec *codec)
243{ 242{
244 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 243 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
245 struct i2c_client *pClient; 244 struct i2c_client *pClient;
246 static int nClient = 0; 245 static int nClient;
246 nClient = 0;
247 247
248 dev_dbg(pTAS2560->dev, "%s\n", __func__); 248 dev_dbg(pTAS2560->dev, "%s\n", __func__);
249 249
250 //pTAS2560->codec = codec; 250 /*pTAS2560->codec = codec;*/
251 251
252 /* DR boost */ 252 /* DR boost */
253 snd_soc_write(codec,TAS2560_DR_BOOST_REG, 0x04); 253 snd_soc_write(codec, TAS2560_DR_BOOST_REG, 0x04);
254 snd_soc_write(codec,TAS2560_DEV_MODE_REG, 0x02); 254 snd_soc_write(codec, TAS2560_DEV_MODE_REG, 0x02);
255 255
256 codec->control_data = g_client[nClient]; 256 codec->control_data = g_client[nClient];
257 if (nClient < MAX_CLIENTS - 1) nClient++; 257 if (nClient < MAX_CLIENTS - 1)
258 nClient++;
258 259
259 pClient = codec->control_data; 260 pClient = codec->control_data;
260 261
@@ -277,7 +278,7 @@ static int tas2560_get_load(struct snd_kcontrol *pKcontrol,
277 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec); 278 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec);
278 279
279 pUcontrol->value.integer.value[0] = pTAS2560->mnLoad; 280 pUcontrol->value.integer.value[0] = pTAS2560->mnLoad;
280 281
281 return 0; 282 return 0;
282} 283}
283 284
@@ -288,11 +289,11 @@ static int tas2560_set_load(struct snd_kcontrol *pKcontrol,
288 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol); 289 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol);
289#else 290#else
290 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol); 291 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol);
291#endif 292#endif
292 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec); 293 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec);
293 294
294 pTAS2560->mnLoad = pUcontrol->value.integer.value[0]; 295 pTAS2560->mnLoad = pUcontrol->value.integer.value[0];
295 dev_dbg(pCodec->dev,"%s:load = 0x%x\n",__func__, 296 dev_dbg(pCodec->dev, "%s:load = 0x%x\n", __func__,
296 pTAS2560->mnLoad); 297 pTAS2560->mnLoad);
297 298
298 tas2560_setLoad(pTAS2560, pTAS2560->mnLoad); 299 tas2560_setLoad(pTAS2560, pTAS2560->mnLoad);
@@ -306,11 +307,11 @@ static int tas2560_get_Sampling_Rate(struct snd_kcontrol *pKcontrol,
306 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol); 307 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol);
307#else 308#else
308 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol); 309 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol);
309#endif 310#endif
310 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec); 311 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec);
311 312
312 pUcontrol->value.integer.value[0] = pTAS2560->mnSamplingRate; 313 pUcontrol->value.integer.value[0] = pTAS2560->mnSamplingRate;
313 dev_dbg(pCodec->dev,"%s: %d\n",__func__, 314 dev_dbg(pCodec->dev, "%s: %d\n", __func__,
314 pTAS2560->mnSamplingRate); 315 pTAS2560->mnSamplingRate);
315 return 0; 316 return 0;
316} 317}
@@ -322,11 +323,11 @@ static int tas2560_set_Sampling_Rate(struct snd_kcontrol *pKcontrol,
322 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol); 323 struct snd_soc_codec *pCodec = snd_soc_kcontrol_codec(pKcontrol);
323#else 324#else
324 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol); 325 struct snd_soc_codec *pCodec = snd_kcontrol_chip(pKcontrol);
325#endif 326#endif
326 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec); 327 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(pCodec);
327 328
328 int sampleRate = pUcontrol->value.integer.value[0]; 329 int sampleRate = pUcontrol->value.integer.value[0];
329 dev_dbg(pCodec->dev,"%s: %d\n",__func__, sampleRate); 330 dev_dbg(pCodec->dev, "%s: %d\n", __func__, sampleRate);
330 tas2560_set_SampleRate(pTAS2560, sampleRate); 331 tas2560_set_SampleRate(pTAS2560, sampleRate);
331 332
332 return 0; 333 return 0;
@@ -339,11 +340,11 @@ static int tas2560_power_ctrl_get(struct snd_kcontrol *pKcontrol,
339 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol); 340 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
340#else 341#else
341 struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol); 342 struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
342#endif 343#endif
343 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 344 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
344 345
345 pValue->value.integer.value[0] = pTAS2560->mbPowerUp; 346 pValue->value.integer.value[0] = pTAS2560->mbPowerUp;
346 dev_dbg(codec->dev,"tas2560_power_ctrl_get = 0x%x\n", 347 dev_dbg(codec->dev, "tas2560_power_ctrl_get = 0x%x\n",
347 pTAS2560->mbPowerUp); 348 pTAS2560->mbPowerUp);
348 349
349 return 0; 350 return 0;
@@ -356,7 +357,7 @@ static int tas2560_power_ctrl_put(struct snd_kcontrol *pKcontrol,
356 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol); 357 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
357#else 358#else
358 struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol); 359 struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
359#endif 360#endif
360 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec); 361 struct tas2560_priv *pTAS2560 = snd_soc_codec_get_drvdata(codec);
361 362
362 int bPowerUp = pValue->value.integer.value[0]; 363 int bPowerUp = pValue->value.integer.value[0];
@@ -365,17 +366,17 @@ static int tas2560_power_ctrl_put(struct snd_kcontrol *pKcontrol,
365 return 0; 366 return 0;
366} 367}
367 368
368static const char *load_text[] = {"8_Ohm","6_Ohm","4_Ohm"}; 369static const char *load_text[] = {"8_Ohm", "6_Ohm", "4_Ohm"};
369 370
370static const struct soc_enum load_enum[] = { 371static const struct soc_enum load_enum[] = {
371 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(load_text),load_text), 372 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(load_text), load_text),
372}; 373};
373 374
374static const char *Sampling_Rate_text[] = {"48_khz","44.1_khz",\ 375static const char *Sampling_Rate_text[] = {"48_khz", "44.1_khz",\
375 "16_khz","8_khz"}; 376 "16_khz", "8_khz"};
376 377
377static const struct soc_enum Sampling_Rate_enum[] = { 378static const struct soc_enum Sampling_Rate_enum[] = {
378 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(Sampling_Rate_text),Sampling_Rate_text), 379 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(Sampling_Rate_text), Sampling_Rate_text),
379}; 380};
380 381
381/* 382/*
@@ -386,12 +387,12 @@ static DECLARE_TLV_DB_SCALE(dac_tlv, 0, 100, 0);
386static const struct snd_kcontrol_new tas2560_snd_controls[] = { 387static const struct snd_kcontrol_new tas2560_snd_controls[] = {
387 SOC_SINGLE_TLV("DAC Playback Volume", TAS2560_SPK_CTRL_REG, 0, 0x0f, 0, 388 SOC_SINGLE_TLV("DAC Playback Volume", TAS2560_SPK_CTRL_REG, 0, 0x0f, 0,
388 dac_tlv), 389 dac_tlv),
389 SOC_ENUM_EXT("TAS2560 Boost load",load_enum[0], 390 SOC_ENUM_EXT("TAS2560 Boost load", load_enum[0],
390 tas2560_get_load,tas2560_set_load), 391 tas2560_get_load, tas2560_set_load),
391 SOC_ENUM_EXT("TAS2560 Sampling Rate",Sampling_Rate_enum[0], 392 SOC_ENUM_EXT("TAS2560 Sampling Rate", Sampling_Rate_enum[0],
392 tas2560_get_Sampling_Rate,tas2560_set_Sampling_Rate), 393 tas2560_get_Sampling_Rate, tas2560_set_Sampling_Rate),
393 SOC_SINGLE_EXT("TAS2560 PowerCtrl", SND_SOC_NOPM, 0, 0x0001, 0, 394 SOC_SINGLE_EXT("TAS2560 PowerCtrl", SND_SOC_NOPM, 0, 0x0001, 0,
394 tas2560_power_ctrl_get, tas2560_power_ctrl_put), 395 tas2560_power_ctrl_get, tas2560_power_ctrl_put),
395}; 396};
396 397
397 398
@@ -412,19 +413,19 @@ int tas2560_register_codec(struct tas2560_priv *pTAS2560)
412{ 413{
413 int nResult = 0; 414 int nResult = 0;
414 415
415 dev_info(pTAS2560->dev, "%s, enter\n", __FUNCTION__); 416 dev_info(pTAS2560->dev, "%s, enter\n", __func__);
416 417
417 nResult = snd_soc_register_codec(pTAS2560->dev, 418 nResult = snd_soc_register_codec(pTAS2560->dev,
418 &soc_codec_driver_tas2560, 419 &soc_codec_driver_tas2560,
419 tas2560_dai_driver, ARRAY_SIZE(tas2560_dai_driver)); 420 tas2560_dai_driver, ARRAY_SIZE(tas2560_dai_driver));
420 421
421 return nResult; 422 return nResult;
422} 423}
423 424
424int tas2560_deregister_codec(struct tas2560_priv *pTAS2560) 425int tas2560_deregister_codec(struct tas2560_priv *pTAS2560)
425{ 426{
426 snd_soc_unregister_codec(pTAS2560->dev); 427 snd_soc_unregister_codec(pTAS2560->dev);
427 428
428 return 0; 429 return 0;
429} 430}
430 431
@@ -433,4 +434,4 @@ MODULE_AUTHOR("Texas Instruments Inc.");
433MODULE_DESCRIPTION("TAS2560 ALSA SOC Smart Amplifier driver"); 434MODULE_DESCRIPTION("TAS2560 ALSA SOC Smart Amplifier driver");
434MODULE_LICENSE("GPLv2"); 435MODULE_LICENSE("GPLv2");
435 436
436#endif //CONFIG_TAS2560_CODEC 437#endif /*CONFIG_TAS2560_CODEC*/
diff --git a/tas2560-codec.h b/tas2560-codec.h
index c0b321b..dda7b62 100755..100644
--- a/tas2560-codec.h
+++ b/tas2560-codec.h
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
diff --git a/tas2560-core.c b/tas2560-core.c
index b4eb7c8..0461bc5 100755..100644
--- a/tas2560-core.c
+++ b/tas2560-core.c
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -22,7 +22,7 @@
22** 22**
23** ============================================================================= 23** =============================================================================
24*/ 24*/
25#define DEBUG 25#define DEBUG
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/init.h> 28#include <linux/init.h>
@@ -50,13 +50,12 @@
50#define MAX_CLIENTS 8 50#define MAX_CLIENTS 8
51 51
52#if 0 52#if 0
53static unsigned int p_tas2560_startup_data[] = 53static unsigned int p_tas2560_startup_data[] = {
54{
55 /* reg address size values */ 54 /* reg address size values */
56 TAS2560_MUTE_REG, 0x01, 0x41, 55 TAS2560_MUTE_REG, 0x01, 0x41,
57 TAS2560_MDELAY, 0x01, 0x10, 56 TAS2560_MDELAY, 0x01, 0x10,
58 //TAS2560_CLK_SEL, 0x01, 0x01, 57 /*TAS2560_CLK_SEL, 0x01, 0x01,
59 //TAS2560_SET_FREQ, 0x01, 0x10, 58 TAS2560_SET_FREQ, 0x01, 0x10,*/
60 59
61 TAS2560_BOOST_HEAD, 0x04, 0x04, 0xcc, 0xcc, 0xcc, 60 TAS2560_BOOST_HEAD, 0x04, 0x04, 0xcc, 0xcc, 0xcc,
62 61
@@ -64,14 +63,13 @@ static unsigned int p_tas2560_startup_data[] =
64}; 63};
65#endif 64#endif
66 65
67static unsigned int p_tas2560_IV_HPF_data[] = 66static unsigned int p_tas2560_IV_HPF_data[] = {
68{
69 /* reg address size values */ 67 /* reg address size values */
70 /*Isense path HPF cut off -> 2Hz*/ 68 /*Isense path HPF cut off -> 2Hz*/
71 channel_both, TAS2560_ISENSE_PATH_CTL1, 0x04, 0x7F, 0xFB, 0xB5, 0x00, 69 channel_both, TAS2560_ISENSE_PATH_CTL1, 0x04, 0x7F, 0xFB, 0xB5, 0x00,
72 channel_both, TAS2560_ISENSE_PATH_CTL2, 0x04, 0x80, 0x04, 0x4C, 0x00, 70 channel_both, TAS2560_ISENSE_PATH_CTL2, 0x04, 0x80, 0x04, 0x4C, 0x00,
73 channel_both, TAS2560_ISENSE_PATH_CTL3, 0x04, 0x7F, 0xF7, 0x6A, 0x00, 71 channel_both, TAS2560_ISENSE_PATH_CTL3, 0x04, 0x7F, 0xF7, 0x6A, 0x00,
74 /*all pass*/ 72 /*all pass*/
75 channel_both, TAS2560_HPF_CUTOFF_CTL1, 0x04, 0x7F, 0xFF, 0xFF, 0xFF, 73 channel_both, TAS2560_HPF_CUTOFF_CTL1, 0x04, 0x7F, 0xFF, 0xFF, 0xFF,
76 channel_both, TAS2560_HPF_CUTOFF_CTL2, 0x04, 0x00, 0x00, 0x00, 0x00, 74 channel_both, TAS2560_HPF_CUTOFF_CTL2, 0x04, 0x00, 0x00, 0x00, 0x00,
77 channel_both, TAS2560_HPF_CUTOFF_CTL3, 0x04, 0x00, 0x00, 0x00, 0x00, 75 channel_both, TAS2560_HPF_CUTOFF_CTL3, 0x04, 0x00, 0x00, 0x00, 0x00,
@@ -86,8 +84,7 @@ static unsigned int p_tas2560_IV_HPF_data[] =
86 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 84 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
87}; 85};
88 86
89static unsigned int p_tas2560_48khz_data[] = 87static unsigned int p_tas2560_48khz_data[] = {
90{
91 /* reg address size values */ 88 /* reg address size values */
92 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01, 89 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01,
93 channel_both, TAS2560_SR_CTRL2, 0x01, 0x08, 90 channel_both, TAS2560_SR_CTRL2, 0x01, 0x08,
@@ -95,8 +92,7 @@ static unsigned int p_tas2560_48khz_data[] =
95 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 92 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
96}; 93};
97 94
98static unsigned int p_tas2560_16khz_data[] = 95static unsigned int p_tas2560_16khz_data[] = {
99{
100 /* reg address size values */ 96 /* reg address size values */
101 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01, 97 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01,
102 channel_both, TAS2560_SR_CTRL2, 0x01, 0x18, 98 channel_both, TAS2560_SR_CTRL2, 0x01, 0x18,
@@ -104,8 +100,7 @@ static unsigned int p_tas2560_16khz_data[] =
104 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 100 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
105}; 101};
106 102
107static unsigned int p_tas2560_8khz_data[] = 103static unsigned int p_tas2560_8khz_data[] = {
108{
109 /* reg address size values */ 104 /* reg address size values */
110 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01, 105 channel_both, TAS2560_SR_CTRL1, 0x01, 0x01,
111 channel_both, TAS2560_SR_CTRL2, 0x01, 0x30, 106 channel_both, TAS2560_SR_CTRL2, 0x01, 0x30,
@@ -113,8 +108,7 @@ static unsigned int p_tas2560_8khz_data[] =
113 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 108 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
114}; 109};
115 110
116static unsigned int p_tas2560_4Ohm_data[] = 111static unsigned int p_tas2560_4Ohm_data[] = {
117{
118 /* reg address size values */ 112 /* reg address size values */
119 channel_both, TAS2560_BOOST_ON, 0x04, 0x6f, 0x5c, 0x28, 0xf5, 113 channel_both, TAS2560_BOOST_ON, 0x04, 0x6f, 0x5c, 0x28, 0xf5,
120 channel_both, TAS2560_BOOST_OFF, 0x04, 0x67, 0xae, 0x14, 0x7a, 114 channel_both, TAS2560_BOOST_OFF, 0x04, 0x67, 0xae, 0x14, 0x7a,
@@ -129,8 +123,7 @@ static unsigned int p_tas2560_4Ohm_data[] =
129 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 123 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
130}; 124};
131 125
132static unsigned int p_tas2560_6Ohm_data[] = 126static unsigned int p_tas2560_6Ohm_data[] = {
133{
134 /* reg address size values */ 127 /* reg address size values */
135 channel_both, TAS2560_BOOST_ON, 0x04, 0x73, 0x33, 0x33, 0x33, 128 channel_both, TAS2560_BOOST_ON, 0x04, 0x73, 0x33, 0x33, 0x33,
136 channel_both, TAS2560_BOOST_OFF, 0x04, 0x6b, 0x85, 0x1e, 0xb8, 129 channel_both, TAS2560_BOOST_OFF, 0x04, 0x6b, 0x85, 0x1e, 0xb8,
@@ -145,8 +138,7 @@ static unsigned int p_tas2560_6Ohm_data[] =
145 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 138 channel_both, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
146}; 139};
147 140
148static unsigned int p_tas2560_8Ohm_data[] = 141static unsigned int p_tas2560_8Ohm_data[] = {
149{
150 /* reg address size values */ 142 /* reg address size values */
151 channel_both, TAS2560_BOOST_ON, 0x04, 0x75, 0xC2, 0x8F, 0x00, 143 channel_both, TAS2560_BOOST_ON, 0x04, 0x75, 0xC2, 0x8F, 0x00,
152 channel_both, TAS2560_BOOST_OFF, 0x04, 0x6E, 0x14, 0x7A, 0x00, 144 channel_both, TAS2560_BOOST_OFF, 0x04, 0x6E, 0x14, 0x7A, 0x00,
@@ -163,25 +155,24 @@ static unsigned int p_tas2560_8Ohm_data[] =
163 155
164static void tas2560_i2c_load_data(struct tas2560_priv *pTAS2560, 156static void tas2560_i2c_load_data(struct tas2560_priv *pTAS2560,
165 unsigned int *pData) { 157 unsigned int *pData) {
166 enum channel chn; 158 enum channel chn;
167 unsigned int nRegister; 159 unsigned int nRegister;
168 unsigned int *nData; 160 unsigned int *nData;
169 unsigned int nLength = 0; 161 unsigned int nLength = 0;
170 unsigned int nLoop = 0; 162 unsigned int nLoop = 0;
171 unsigned int i =0; 163 unsigned int i = 0;
172 164
173 do{ 165 do {
174 chn = pData[nLength]; 166 chn = pData[nLength];
175 nRegister = pData[nLength + 1]; 167 nRegister = pData[nLength + 1];
176 nLoop = pData[nLength + 2]; 168 nLoop = pData[nLength + 2];
177 nData = &pData[nLength + 3]; 169 nData = &pData[nLength + 3];
178 if (nRegister == TAS2560_MDELAY){ 170 if (nRegister == TAS2560_MDELAY) {
179 mdelay(nData[0]); 171 mdelay(nData[0]);
180 } 172 } else {
181 else{ 173 if (nRegister != 0xFFFFFFFF) {
182 if (nRegister != 0xFFFFFFFF){
183 i = 0; 174 i = 0;
184 while(nLoop!=0){ 175 while (nLoop != 0) {
185 pTAS2560->write(pTAS2560, chn, ((nRegister+i)), nData[i]); 176 pTAS2560->write(pTAS2560, chn, ((nRegister+i)), nData[i]);
186 nLoop--; 177 nLoop--;
187 i++; 178 i++;
@@ -192,12 +183,12 @@ static void tas2560_i2c_load_data(struct tas2560_priv *pTAS2560,
192 } while (nRegister != 0xFFFFFFFF); 183 } while (nRegister != 0xFFFFFFFF);
193} 184}
194 185
195void tas2560_sw_shutdown(struct tas2560_priv *pTAS2560, 186void tas2560_sw_shutdown(struct tas2560_priv *pTAS2560,
196 int sw_shutdown) 187 int sw_shutdown)
197{ 188{
198 if (sw_shutdown) 189 if (sw_shutdown)
199 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG, 190 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG,
200 TAS2560_PWR_BIT_MASK,0); 191 TAS2560_PWR_BIT_MASK, 0);
201 else 192 else
202 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG, 193 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG,
203 TAS2560_PWR_BIT_MASK, TAS2560_PWR_BIT_MASK); 194 TAS2560_PWR_BIT_MASK, TAS2560_PWR_BIT_MASK);
@@ -206,96 +197,96 @@ void tas2560_sw_shutdown(struct tas2560_priv *pTAS2560,
206int tas2560_set_SampleRate(struct tas2560_priv *pTAS2560, unsigned int nSamplingRate) 197int tas2560_set_SampleRate(struct tas2560_priv *pTAS2560, unsigned int nSamplingRate)
207{ 198{
208 int ret = 0; 199 int ret = 0;
209 200
210 switch(nSamplingRate){ 201 switch (nSamplingRate) {
211 case 48000: 202 case 48000:
212 dev_dbg(pTAS2560->dev,"Sampling rate = 48 khz\n"); 203 dev_dbg(pTAS2560->dev, "Sampling rate = 48 khz\n");
213 tas2560_i2c_load_data(pTAS2560,p_tas2560_48khz_data); 204 tas2560_i2c_load_data(pTAS2560, p_tas2560_48khz_data);
214 break; 205 break;
215 case 44100: 206 case 44100:
216 dev_dbg(pTAS2560->dev,"Sampling rate = 44.1 khz\n"); 207 dev_dbg(pTAS2560->dev, "Sampling rate = 44.1 khz\n");
217 pTAS2560->write(pTAS2560, channel_both,TAS2560_SR_CTRL1, 0x11); 208 pTAS2560->write(pTAS2560, channel_both, TAS2560_SR_CTRL1, 0x11);
218 break; 209 break;
219 case 16000: 210 case 16000:
220 dev_dbg(pTAS2560->dev,"Sampling rate = 16 khz\n"); 211 dev_dbg(pTAS2560->dev, "Sampling rate = 16 khz\n");
221 tas2560_i2c_load_data(pTAS2560,p_tas2560_16khz_data); 212 tas2560_i2c_load_data(pTAS2560, p_tas2560_16khz_data);
222 break; 213 break;
223 case 8000: 214 case 8000:
224 dev_dbg(pTAS2560->dev,"Sampling rate = 8 khz\n"); 215 dev_dbg(pTAS2560->dev, "Sampling rate = 8 khz\n");
225 tas2560_i2c_load_data(pTAS2560,p_tas2560_8khz_data); 216 tas2560_i2c_load_data(pTAS2560, p_tas2560_8khz_data);
226 break; 217 break;
227 default: 218 default:
228 dev_err(pTAS2560->dev,"Invalid Sampling rate, %d\n", nSamplingRate); 219 dev_err(pTAS2560->dev, "Invalid Sampling rate, %d\n", nSamplingRate);
229 ret = -1; 220 ret = -1;
230 break; 221 break;
231 } 222 }
232 223
233 if(ret >= 0) 224 if (ret >= 0)
234 pTAS2560->mnSamplingRate = nSamplingRate; 225 pTAS2560->mnSamplingRate = nSamplingRate;
235 226
236 return ret; 227 return ret;
237} 228}
238 229
239int tas2560_set_bit_rate(struct tas2560_priv *pTAS2560, unsigned int nBitRate) 230int tas2560_set_bit_rate(struct tas2560_priv *pTAS2560, unsigned int nBitRate)
240{ 231{
241 int ret = 0, n = -1; 232 int ret = 0, n = -1;
242 233
243 dev_dbg(pTAS2560->dev, " nBitRate = %d \n", 234 dev_dbg(pTAS2560->dev, " nBitRate = %d \n",
244 nBitRate); 235 nBitRate);
245 switch(nBitRate){ 236 switch (nBitRate) {
246 case 16: 237 case 16:
247 n = 0; 238 n = 0;
248 break; 239 break;
249 case 20: 240 case 20:
250 n = 1; 241 n = 1;
251 break; 242 break;
252 case 24: 243 case 24:
253 n = 2; 244 n = 2;
254 break; 245 break;
255 case 32: 246 case 32:
256 n = 3; 247 n = 3;
257 break; 248 break;
258 } 249 }
259 250
260 if(n >= 0) 251 if (n >= 0)
261 ret = pTAS2560->update_bits(pTAS2560, channel_both, 252 ret = pTAS2560->update_bits(pTAS2560, channel_both,
262 TAS2560_DAI_FMT, 0x03, n); 253 TAS2560_DAI_FMT, 0x03, n);
263 254
264 return ret; 255 return ret;
265} 256}
266 257
267int tas2560_get_bit_rate(struct tas2560_priv *pTAS2560) 258int tas2560_get_bit_rate(struct tas2560_priv *pTAS2560)
268{ 259{
269 int nBitRate = -1, value = -1, ret = 0; 260 int nBitRate = -1, value = -1, ret = 0;
270 261
271 ret = pTAS2560->read(pTAS2560, channel_left, TAS2560_DAI_FMT, &value); 262 ret = pTAS2560->read(pTAS2560, channel_left, TAS2560_DAI_FMT, &value);
272 value &= 0x03; 263 value &= 0x03;
273 264
274 switch(value){ 265 switch (value) {
275 case 0: 266 case 0:
276 nBitRate = 16; 267 nBitRate = 16;
277 break; 268 break;
278 case 1: 269 case 1:
279 nBitRate = 20; 270 nBitRate = 20;
280 break; 271 break;
281 case 2: 272 case 2:
282 nBitRate = 24; 273 nBitRate = 24;
283 break; 274 break;
284 case 3: 275 case 3:
285 nBitRate = 32; 276 nBitRate = 32;
286 break; 277 break;
287 default: 278 default:
288 break; 279 break;
289 } 280 }
290 281
291 return nBitRate; 282 return nBitRate;
292} 283}
293 284
294int tas2560_set_ASI_fmt(struct tas2560_priv *pTAS2560, unsigned int fmt) 285int tas2560_set_ASI_fmt(struct tas2560_priv *pTAS2560, unsigned int fmt)
295{ 286{
296 u8 serial_format = 0, asi_cfg_1=0; 287 u8 serial_format = 0, asi_cfg_1 = 0;
297 int ret = 0; 288 int ret = 0;
298 289
299 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 290 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
300 case SND_SOC_DAIFMT_CBS_CFS: 291 case SND_SOC_DAIFMT_CBS_CFS:
301 asi_cfg_1 = 0x00; 292 asi_cfg_1 = 0x00;
@@ -313,7 +304,7 @@ int tas2560_set_ASI_fmt(struct tas2560_priv *pTAS2560, unsigned int fmt)
313 dev_err(pTAS2560->dev, "ASI format master is not found\n"); 304 dev_err(pTAS2560->dev, "ASI format master is not found\n");
314 ret = -EINVAL; 305 ret = -EINVAL;
315 } 306 }
316 307
317 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 308 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
318 case SND_SOC_DAIFMT_NB_NF: 309 case SND_SOC_DAIFMT_NB_NF:
319 asi_cfg_1 |= 0x00; 310 asi_cfg_1 |= 0x00;
@@ -331,16 +322,16 @@ int tas2560_set_ASI_fmt(struct tas2560_priv *pTAS2560, unsigned int fmt)
331 dev_err(pTAS2560->dev, "ASI format Inverse is not found\n"); 322 dev_err(pTAS2560->dev, "ASI format Inverse is not found\n");
332 ret = -EINVAL; 323 ret = -EINVAL;
333 } 324 }
334 325
335 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_ASI_CFG_1, TAS2560_DIRINV_MASK, 326 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_ASI_CFG_1, TAS2560_DIRINV_MASK,
336 asi_cfg_1); 327 asi_cfg_1);
337 328
338 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK ){ 329 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
339 case (SND_SOC_DAIFMT_I2S ): 330 case (SND_SOC_DAIFMT_I2S):
340 serial_format |= TAS2560_DATAFORMAT_I2S; 331 serial_format |= TAS2560_DATAFORMAT_I2S;
341 break; 332 break;
342 case (SND_SOC_DAIFMT_DSP_A ): 333 case (SND_SOC_DAIFMT_DSP_A):
343 case (SND_SOC_DAIFMT_DSP_B ): 334 case (SND_SOC_DAIFMT_DSP_B):
344 serial_format |= TAS2560_DATAFORMAT_DSP; 335 serial_format |= TAS2560_DATAFORMAT_DSP;
345 break; 336 break;
346 case (SND_SOC_DAIFMT_RIGHT_J): 337 case (SND_SOC_DAIFMT_RIGHT_J):
@@ -367,7 +358,7 @@ int tas2560_set_pll_clkin(struct tas2560_priv *pTAS2560, int clk_id,
367 int ret = 0; 358 int ret = 0;
368 unsigned char pll_in = 0; 359 unsigned char pll_in = 0;
369 dev_dbg(pTAS2560->dev, "%s, clkid=%d\n", __func__, clk_id); 360 dev_dbg(pTAS2560->dev, "%s, clkid=%d\n", __func__, clk_id);
370 361
371 switch (clk_id) { 362 switch (clk_id) {
372 case TAS2560_PLL_CLKIN_BCLK: 363 case TAS2560_PLL_CLKIN_BCLK:
373 pll_in = 0; 364 pll_in = 0;
@@ -383,16 +374,16 @@ int tas2560_set_pll_clkin(struct tas2560_priv *pTAS2560, int clk_id,
383 ret = -EINVAL; 374 ret = -EINVAL;
384 break; 375 break;
385 } 376 }
386 377
387 if(ret >= 0){ 378 if (ret >= 0) {
388 pTAS2560->update_bits(pTAS2560, 379 pTAS2560->update_bits(pTAS2560,
389 channel_both, 380 channel_both,
390 TAS2560_CLK_SEL, 381 TAS2560_CLK_SEL,
391 TAS2560_PLL_SRC_MASK, 382 TAS2560_PLL_SRC_MASK,
392 pll_in<<6); 383 pll_in<<6);
393 pTAS2560->mnClkid = clk_id; 384 pTAS2560->mnClkid = clk_id;
394 pTAS2560->mnClkin = freq; 385 pTAS2560->mnClkin = freq;
395 } 386 }
396 387
397 return ret; 388 return ret;
398} 389}
@@ -403,12 +394,12 @@ int tas2560_setupPLL(struct tas2560_priv *pTAS2560, int pll_clkin)
403 unsigned int power = 0, temp; 394 unsigned int power = 0, temp;
404 unsigned int d, pll_clkin_divide; 395 unsigned int d, pll_clkin_divide;
405 u8 j, p; 396 u8 j, p;
406 int ret = 0; 397 int ret = 0;
407 398
408 if (!pll_clkin || (pll_clkin < 0)) { 399 if (!pll_clkin || (pll_clkin < 0)) {
409 if (pTAS2560->mnClkid != TAS2560_PLL_CLKIN_BCLK){ 400 if (pTAS2560->mnClkid != TAS2560_PLL_CLKIN_BCLK) {
410 dev_err(pTAS2560->dev, 401 dev_err(pTAS2560->dev,
411 "pll_in %d, pll_clkin frequency err:%d\n", 402 "pll_in %d, pll_clkin frequency err:%d\n",
412 pTAS2560->mnClkid, pll_clkin); 403 pTAS2560->mnClkid, pll_clkin);
413 return -EINVAL; 404 return -EINVAL;
414 } 405 }
@@ -417,65 +408,68 @@ int tas2560_setupPLL(struct tas2560_priv *pTAS2560, int pll_clkin)
417 } 408 }
418 409
419 pTAS2560->read(pTAS2560, channel_left, TAS2560_PWR_REG, &power); 410 pTAS2560->read(pTAS2560, channel_left, TAS2560_PWR_REG, &power);
420 if(power&TAS2560_PWR_BIT_MASK){ 411 if (power&TAS2560_PWR_BIT_MASK) {
421 dev_dbg(pTAS2560->dev, "power down to update PLL\n"); 412 dev_dbg(pTAS2560->dev, "power down to update PLL\n");
422 pTAS2560->write(pTAS2560, channel_both, TAS2560_PWR_REG, TAS2560_PWR_BIT_MASK|TAS2560_MUTE_MASK); 413 pTAS2560->write(pTAS2560, channel_both, TAS2560_PWR_REG, TAS2560_PWR_BIT_MASK|TAS2560_MUTE_MASK);
423 } 414 }
424 415
425 /* Fill in the PLL control registers for J & D 416 /* Fill in the PLL control registers for J & D
426 * pll_clk = (pll_clkin * J.D) / P 417 * pll_clk = (pll_clkin * J.D) / P
427 * Need to fill in J and D here based on incoming freq 418 * Need to fill in J and D here based on incoming freq
428 */ 419 */
429 if(pll_clkin <= 40000000) 420 if (pll_clkin <= 40000000)
430 p = 1; 421 p = 1;
431 else if(pll_clkin <= 80000000) 422 else if (pll_clkin <= 80000000)
432 p = 2; 423 p = 2;
433 else if(pll_clkin <= 160000000) 424 else if (pll_clkin <= 160000000)
434 p = 3; 425 p = 3;
435 else{ 426 else {
436 dev_err(pTAS2560->dev, "PLL Clk In %d not covered here\n", pll_clkin); 427 dev_err(pTAS2560->dev, "PLL Clk In %d not covered here\n", pll_clkin);
437 ret = -EINVAL; 428 ret = -EINVAL;
438 } 429 }
439 430
440 if(ret >=0){ 431 if (ret >= 0) {
441 j = (pll_clk * p) / pll_clkin; 432 j = (pll_clk * p) / pll_clkin;
442 d = (pll_clk * p) % pll_clkin; 433 d = (pll_clk * p) % pll_clkin;
443 d /= (pll_clkin / 10000); 434 d /= (pll_clkin / 10000);
444 435
445 pll_clkin_divide = pll_clkin/(1<<p); 436 pll_clkin_divide = pll_clkin/(1<<p);
446 437
447 if((d ==0) 438 if ((d == 0)
448 &&((pll_clkin_divide <512000)|| (pll_clkin_divide >20000000))){ 439 && ((pll_clkin_divide < 512000) || (pll_clkin_divide > 20000000))) {
449 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, pll_in=%d\n", pll_clkin); 440 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, pll_in=%d\n", pll_clkin);
450 ret = -EINVAL; 441 ret = -EINVAL;
451 } 442 }
452 443
453 if((d!=0) 444 if ((d != 0)
454 &&((pll_clkin_divide < 10000000)||(pll_clkin_divide>20000000))){ 445 && ((pll_clkin_divide < 10000000) || (pll_clkin_divide > 20000000))) {
455 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, pll_in=%d\n", pll_clkin); 446 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, pll_in=%d\n", pll_clkin);
456 ret = -EINVAL; 447 ret = -EINVAL;
457 } 448 }
458 449
459 if(j == 0){ 450 if (j == 0) {
460 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, j ZERO\n"); 451 dev_err(pTAS2560->dev, "PLL cal ERROR!!!, j ZERO\n");
461 ret = -EINVAL; 452 ret = -EINVAL;
462 } 453 }
463 } 454 }
464 455
465 if(ret >= 0){ 456 if (ret >= 0) {
466 dev_info(pTAS2560->dev, 457 dev_info(pTAS2560->dev,
467 "PLL clk_in = %d, P=%d, J.D=%d.%d\n", pll_clkin, p, j, d); 458 "PLL clk_in = %d, P=%d, J.D=%d.%d\n", pll_clkin, p, j, d);
468 //update P 459 /*update P*/
469 if(p == 64) temp = 0; 460 if (p == 64)
470 else temp = p; 461 temp = 0;
462 else
463 temp = p;
471 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_CLK_SEL, TAS2560_PLL_P_MASK, temp); 464 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_CLK_SEL, TAS2560_PLL_P_MASK, temp);
472 465
473 //Update J 466 /*Update J*/
474 temp = j; 467 temp = j;
475 if(pll_clkin < 1000000) temp |= 0x80; 468 if (pll_clkin < 1000000)
469 temp |= 0x80;
476 pTAS2560->write(pTAS2560, channel_both, TAS2560_SET_FREQ, temp); 470 pTAS2560->write(pTAS2560, channel_both, TAS2560_SET_FREQ, temp);
477 471
478 //Update D 472 /*Update D*/
479 temp = (d&0x00ff); 473 temp = (d&0x00ff);
480 pTAS2560->write(pTAS2560, channel_both, TAS2560_PLL_D_LSB, temp); 474 pTAS2560->write(pTAS2560, channel_both, TAS2560_PLL_D_LSB, temp);
481 temp = ((d&0x3f00)>>8); 475 temp = ((d&0x3f00)>>8);
@@ -483,10 +477,10 @@ int tas2560_setupPLL(struct tas2560_priv *pTAS2560, int pll_clkin)
483 } 477 }
484 478
485 /* Restore PLL status */ 479 /* Restore PLL status */
486 if(power&TAS2560_PWR_BIT_MASK){ 480 if (power&TAS2560_PWR_BIT_MASK) {
487 pTAS2560->write(pTAS2560, channel_both, TAS2560_PWR_REG, power); 481 pTAS2560->write(pTAS2560, channel_both, TAS2560_PWR_REG, power);
488 } 482 }
489 483
490 return ret; 484 return ret;
491} 485}
492 486
@@ -494,43 +488,43 @@ int tas2560_setLoad(struct tas2560_priv *pTAS2560, int load)
494{ 488{
495 int ret = 0; 489 int ret = 0;
496 int value = -1; 490 int value = -1;
497
498 dev_dbg(pTAS2560->dev,"%s:0x%x\n",__func__, load);
499 491
500 switch(load){ 492 dev_dbg(pTAS2560->dev, "%s:0x%x\n", __func__, load);
493
494 switch (load) {
501 case LOAD_8OHM: 495 case LOAD_8OHM:
502 value = 0; 496 value = 0;
503 tas2560_i2c_load_data(pTAS2560,p_tas2560_8Ohm_data); 497 tas2560_i2c_load_data(pTAS2560, p_tas2560_8Ohm_data);
504 break; 498 break;
505 case LOAD_6OHM: 499 case LOAD_6OHM:
506 value = 1; 500 value = 1;
507 tas2560_i2c_load_data(pTAS2560,p_tas2560_6Ohm_data); 501 tas2560_i2c_load_data(pTAS2560, p_tas2560_6Ohm_data);
508 break; 502 break;
509 case LOAD_4OHM: 503 case LOAD_4OHM:
510 value = 2; 504 value = 2;
511 tas2560_i2c_load_data(pTAS2560,p_tas2560_4Ohm_data); 505 tas2560_i2c_load_data(pTAS2560, p_tas2560_4Ohm_data);
512 break; 506 break;
513 default: 507 default:
514 break; 508 break;
515 } 509 }
516 510
517 if(value >=0){ 511 if (value >= 0) {
518 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_LOAD, LOAD_MASK, value<<3); 512 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_LOAD, LOAD_MASK, value<<3);
519 } 513 }
520 return ret; 514 return ret;
521} 515}
522 516
523int tas2560_getLoad(struct tas2560_priv *pTAS2560) 517int tas2560_getLoad(struct tas2560_priv *pTAS2560)
524{ 518{
525 int ret = -1; 519 int ret = -1;
526 int value = -1; 520 int value = -1;
527 521
528 dev_dbg(pTAS2560->dev,"%s\n",__func__); 522 dev_dbg(pTAS2560->dev, "%s\n", __func__);
529 pTAS2560->read(pTAS2560, channel_left, TAS2560_LOAD, &value); 523 pTAS2560->read(pTAS2560, channel_left, TAS2560_LOAD, &value);
530 524
531 value = (value&0x18)>>3; 525 value = (value&0x18)>>3;
532 526
533 switch(value){ 527 switch (value) {
534 case 0: 528 case 0:
535 ret = LOAD_8OHM; 529 ret = LOAD_8OHM;
536 break; 530 break;
@@ -543,7 +537,7 @@ int tas2560_getLoad(struct tas2560_priv *pTAS2560)
543 default: 537 default:
544 break; 538 break;
545 } 539 }
546 540
547 return ret; 541 return ret;
548} 542}
549 543
@@ -551,22 +545,22 @@ int tas2560_get_volume(struct tas2560_priv *pTAS2560)
551{ 545{
552 int ret = -1; 546 int ret = -1;
553 int value = -1; 547 int value = -1;
554 548
555 dev_dbg(pTAS2560->dev,"%s\n",__func__); 549 dev_dbg(pTAS2560->dev, "%s\n", __func__);
556 ret = pTAS2560->read(pTAS2560, channel_left, TAS2560_SPK_CTRL_REG, &value); 550 ret = pTAS2560->read(pTAS2560, channel_left, TAS2560_SPK_CTRL_REG, &value);
557 if(ret >=0) 551 if (ret >= 0)
558 return (value&0x0f); 552 return value&0x0f;
559 553
560 return ret; 554 return ret;
561} 555}
562 556
563int tas2560_set_volume(struct tas2560_priv *pTAS2560, int volume) 557int tas2560_set_volume(struct tas2560_priv *pTAS2560, int volume)
564{ 558{
565 int ret = -1; 559 int ret = -1;
566 560
567 dev_dbg(pTAS2560->dev,"%s\n",__func__); 561 dev_dbg(pTAS2560->dev, "%s\n", __func__);
568 ret = pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_SPK_CTRL_REG, 0x0f, volume&0x0f); 562 ret = pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_SPK_CTRL_REG, 0x0f, volume&0x0f);
569 563
570 return ret; 564 return ret;
571} 565}
572 566
@@ -574,7 +568,7 @@ int tas2560_parse_dt(struct device *dev,
574 struct tas2560_priv *pTAS2560) 568 struct tas2560_priv *pTAS2560)
575{ 569{
576 struct device_node *np = dev->of_node; 570 struct device_node *np = dev->of_node;
577 int rc= 0, ret = 0; 571 int rc = 0, ret = 0;
578 unsigned int value; 572 unsigned int value;
579 573
580 rc = of_property_read_u32(np, "ti,load", &pTAS2560->mnLoad); 574 rc = of_property_read_u32(np, "ti,load", &pTAS2560->mnLoad);
@@ -582,10 +576,10 @@ int tas2560_parse_dt(struct device *dev,
582 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n", 576 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n",
583 "ti,load", np->full_name, rc); 577 "ti,load", np->full_name, rc);
584 ret = -1; 578 ret = -1;
585 }else{ 579 } else {
586 dev_dbg(pTAS2560->dev, "ti,load=%d", pTAS2560->mnLoad); 580 dev_dbg(pTAS2560->dev, "ti,load=%d", pTAS2560->mnLoad);
587 } 581 }
588 582
589 pTAS2560->mnResetGPIO = of_get_named_gpio(np, 583 pTAS2560->mnResetGPIO = of_get_named_gpio(np,
590 "ti,cdc-reset-gpio", 0); 584 "ti,cdc-reset-gpio", 0);
591 if (pTAS2560->mnResetGPIO < 0) { 585 if (pTAS2560->mnResetGPIO < 0) {
@@ -593,34 +587,34 @@ int tas2560_parse_dt(struct device *dev,
593 "ti,cdc-reset-gpio", np->full_name, 587 "ti,cdc-reset-gpio", np->full_name,
594 pTAS2560->mnResetGPIO); 588 pTAS2560->mnResetGPIO);
595 ret = -1; 589 ret = -1;
596 }else{ 590 } else {
597 dev_dbg(pTAS2560->dev, "ti,cdc-reset-gpio=%d", pTAS2560->mnResetGPIO); 591 dev_dbg(pTAS2560->dev, "ti,cdc-reset-gpio=%d", pTAS2560->mnResetGPIO);
598 } 592 }
599 593
600 if(ret >=0){ 594 if (ret >= 0) {
601 rc = of_property_read_u32(np, "ti,left-channel", &value); 595 rc = of_property_read_u32(np, "ti,left-channel", &value);
602 if (rc) { 596 if (rc) {
603 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n", 597 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n",
604 "ti,left-channel", np->full_name, rc); 598 "ti,left-channel", np->full_name, rc);
605 ret = -2; 599 ret = -2;
606 }else{ 600 } else {
607 pTAS2560->mnLAddr = value; 601 pTAS2560->mnLAddr = value;
608 dev_dbg(pTAS2560->dev, "ti,left-channel=0x%x\n", pTAS2560->mnLAddr); 602 dev_dbg(pTAS2560->dev, "ti,left-channel=0x%x\n", pTAS2560->mnLAddr);
609 } 603 }
610 } 604 }
611 605
612 if(ret >=0){ 606 if (ret >= 0) {
613 rc = of_property_read_u32(np, "ti,right-channel", &value); 607 rc = of_property_read_u32(np, "ti,right-channel", &value);
614 if (rc) { 608 if (rc) {
615 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n", 609 dev_err(pTAS2560->dev, "Looking up %s property in node %s failed %d\n",
616 "ti,right-channel", np->full_name, rc); 610 "ti,right-channel", np->full_name, rc);
617 ret = -3; 611 ret = -3;
618 }else{ 612 } else {
619 pTAS2560->mnRAddr = value; 613 pTAS2560->mnRAddr = value;
620 dev_dbg(pTAS2560->dev, "ti,right-channel=0x%x", pTAS2560->mnRAddr); 614 dev_dbg(pTAS2560->dev, "ti,right-channel=0x%x", pTAS2560->mnRAddr);
621 } 615 }
622 } 616 }
623 617
624 return ret; 618 return ret;
625} 619}
626 620
@@ -628,15 +622,15 @@ void tas2560_enable(struct tas2560_priv *pTAS2560, bool bEnable)
628{ 622{
629 if (bEnable) { 623 if (bEnable) {
630 if (!pTAS2560->mbPowerUp) { 624 if (!pTAS2560->mbPowerUp) {
631 dev_dbg(pTAS2560->dev,"%s power up\n",__func__); 625 dev_dbg(pTAS2560->dev, "%s power up\n", __func__);
632 tas2560_i2c_load_data(pTAS2560,p_tas2560_IV_HPF_data); 626 tas2560_i2c_load_data(pTAS2560, p_tas2560_IV_HPF_data);
633 pTAS2560->mbPowerUp = true; 627 pTAS2560->mbPowerUp = true;
634 } 628 }
635 } else { 629 } else {
636 if (pTAS2560->mbPowerUp) { 630 if (pTAS2560->mbPowerUp) {
637 dev_dbg(pTAS2560->dev,"%s power down\n",__func__); 631 dev_dbg(pTAS2560->dev, "%s power down\n", __func__);
638 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG, 632 pTAS2560->update_bits(pTAS2560, channel_both, TAS2560_PWR_REG,
639 TAS2560_PWR_BIT_MASK,0); 633 TAS2560_PWR_BIT_MASK, 0);
640 mdelay(30); 634 mdelay(30);
641 pTAS2560->mbPowerUp = false; 635 pTAS2560->mbPowerUp = false;
642 } 636 }
@@ -645,4 +639,4 @@ void tas2560_enable(struct tas2560_priv *pTAS2560, bool bEnable)
645 639
646MODULE_AUTHOR("Texas Instruments Inc."); 640MODULE_AUTHOR("Texas Instruments Inc.");
647MODULE_DESCRIPTION("TAS2560 common functions for Android Linux"); 641MODULE_DESCRIPTION("TAS2560 common functions for Android Linux");
648MODULE_LICENSE("GPLv2"); \ No newline at end of file 642MODULE_LICENSE("GPLv2");
diff --git a/tas2560-core.h b/tas2560-core.h
index 5716604..9a71f61 100755..100644
--- a/tas2560-core.h
+++ b/tas2560-core.h
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -41,5 +41,5 @@ int tas2560_set_pll_clkin(struct tas2560_priv *pTAS2560, int clk_id, unsigned in
41int tas2560_parse_dt(struct device *dev, struct tas2560_priv *pTAS2560); 41int tas2560_parse_dt(struct device *dev, struct tas2560_priv *pTAS2560);
42void tas2560_sw_shutdown(struct tas2560_priv *pTAS2560, int sw_shutdown); 42void tas2560_sw_shutdown(struct tas2560_priv *pTAS2560, int sw_shutdown);
43void tas2560_enable(struct tas2560_priv *pTAS2560, bool bEnable); 43void tas2560_enable(struct tas2560_priv *pTAS2560, bool bEnable);
44 44
45#endif /* _TAS2560_CORE_H */ 45#endif /* _TAS2560_CORE_H */
diff --git a/tas2560-misc.c b/tas2560-misc.c
index 4b8ec17..f1beb94 100755..100644
--- a/tas2560-misc.c
+++ b/tas2560-misc.c
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -49,19 +49,21 @@
49#include "tas2560-misc.h" 49#include "tas2560-misc.h"
50#include <linux/dma-mapping.h> 50#include <linux/dma-mapping.h>
51 51
52 52
53static int g_logEnable = 1; 53static int g_logEnable = 1;
54static struct tas2560_priv *g_tas2560 = NULL; 54static struct tas2560_priv *g_tas2560;
55 55
56static int tas2560_file_open(struct inode *inode, struct file *file) 56static int tas2560_file_open(struct inode *inode, struct file *file)
57{ 57{
58 struct tas2560_priv *pTAS2560 = g_tas2560; 58 struct tas2560_priv *pTAS2560 = g_tas2560;
59
60 if (!try_module_get(THIS_MODULE)) return -ENODEV;
61 59
62 file->private_data = (void*)pTAS2560; 60 if (!try_module_get(THIS_MODULE))
63 61 return -ENODEV;
64 if(g_logEnable) dev_info(pTAS2560->dev, 62
63 file->private_data = (void *)pTAS2560;
64
65 if (g_logEnable)
66 dev_info(pTAS2560->dev,
65 "%s\n", __FUNCTION__); 67 "%s\n", __FUNCTION__);
66 return 0; 68 return 0;
67} 69}
@@ -70,10 +72,11 @@ static int tas2560_file_release(struct inode *inode, struct file *file)
70{ 72{
71 struct tas2560_priv *pTAS2560 = (struct tas2560_priv *)file->private_data; 73 struct tas2560_priv *pTAS2560 = (struct tas2560_priv *)file->private_data;
72 74
73 if(g_logEnable) dev_info(pTAS2560->dev, 75 if (g_logEnable)
76 dev_info(pTAS2560->dev,
74 "%s\n", __FUNCTION__); 77 "%s\n", __FUNCTION__);
75 78
76 file->private_data = (void*)NULL; 79 file->private_data = (void *)NULL;
77 module_put(THIS_MODULE); 80 module_put(THIS_MODULE);
78 81
79 return 0; 82 return 0;
@@ -88,121 +91,125 @@ static ssize_t tas2560_file_read(struct file *file, char *buf, size_t count, lof
88 unsigned char *p_kBuf = NULL; 91 unsigned char *p_kBuf = NULL;
89 92
90 mutex_lock(&pTAS2560->file_lock); 93 mutex_lock(&pTAS2560->file_lock);
91 94
92 switch(pTAS2560->mnDBGCmd) 95 switch (pTAS2560->mnDBGCmd) {
96 case TIAUDIO_CMD_REG_READ:
93 { 97 {
94 case TIAUDIO_CMD_REG_READ: 98 if (g_logEnable)
95 { 99 dev_info(pTAS2560->dev,
96 if(g_logEnable) dev_info(pTAS2560->dev, 100 "TIAUDIO_CMD_REG_READ: current_reg = 0x%x, count=%d\n", pTAS2560->mnCurrentReg, (int)count);
97 "TIAUDIO_CMD_REG_READ: current_reg = 0x%x, count=%d\n", pTAS2560->mnCurrentReg, (int)count); 101 if (count == 1) {
98 if(count == 1){ 102 ret = pTAS2560->read(pTAS2560, pTAS2560->mnCurrentChannel,
99 ret = pTAS2560->read(pTAS2560, pTAS2560->mnCurrentChannel, 103 pTAS2560->mnCurrentReg, &nValue);
100 pTAS2560->mnCurrentReg, &nValue); 104 if (0 > ret) {
101 if( 0 > ret) { 105 dev_err(pTAS2560->dev, "dev read fail %d\n", ret);
102 dev_err(pTAS2560->dev, "dev read fail %d\n", ret); 106 break;
103 break;
104 }
105
106 value = (u8)nValue;
107 if(g_logEnable) dev_info(pTAS2560->dev,
108 "TIAUDIO_CMD_REG_READ: nValue=0x%x, value=0x%x\n",
109 nValue, value);
110 ret = copy_to_user(buf, &value, 1);
111 if (0 != ret) {
112 /* Failed to copy all the data, exit */
113 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
114 }
115 }else if(count > 1){
116 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL);
117 if(p_kBuf != NULL){
118 ret = pTAS2560->bulk_read(pTAS2560, pTAS2560->mnCurrentChannel,
119 pTAS2560->mnCurrentReg, p_kBuf, count);
120 if( 0 > ret) {
121 dev_err(pTAS2560->dev, "dev bulk read fail %d\n", ret);
122 }else{
123 ret = copy_to_user(buf, p_kBuf, count);
124 if (0 != ret) {
125 /* Failed to copy all the data, exit */
126 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
127 }
128 }
129
130 kfree(p_kBuf);
131 }else{
132 dev_err(pTAS2560->dev, "read no mem\n");
133 }
134 } 107 }
135 } 108
136 break; 109 value = (u8)nValue;
137 110 if (g_logEnable)
138 case TIAUDIO_CMD_SAMPLERATE: 111 dev_info(pTAS2560->dev,
139 { 112 "TIAUDIO_CMD_REG_READ: nValue=0x%x, value=0x%x\n",
140 if(g_logEnable) dev_info(pTAS2560->dev, 113 nValue, value);
141 "TIAUDIO_CMD_SAMPLERATE: count = %d\n", 114 ret = copy_to_user(buf, &value, 1);
142 (int)count); 115 if (0 != ret) {
143 if(count == 4){ 116 /* Failed to copy all the data, exit */
144 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL); 117 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
145 if(p_kBuf != NULL){ 118 }
146 p_kBuf[0] = (pTAS2560->mnSamplingRate&0x000000ff); 119 } else if (count > 1) {
147 p_kBuf[1] = ((pTAS2560->mnSamplingRate&0x0000ff00)>>8); 120 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL);
148 p_kBuf[2] = ((pTAS2560->mnSamplingRate&0x00ff0000)>>16); 121 if (p_kBuf != NULL) {
149 p_kBuf[3] = ((pTAS2560->mnSamplingRate&0xff000000)>>24); 122 ret = pTAS2560->bulk_read(pTAS2560, pTAS2560->mnCurrentChannel,
150 123 pTAS2560->mnCurrentReg, p_kBuf, count);
124 if (0 > ret) {
125 dev_err(pTAS2560->dev, "dev bulk read fail %d\n", ret);
126 } else {
151 ret = copy_to_user(buf, p_kBuf, count); 127 ret = copy_to_user(buf, p_kBuf, count);
152 if (0 != ret) { 128 if (0 != ret) {
153 /* Failed to copy all the data, exit */ 129 /* Failed to copy all the data, exit */
154 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret); 130 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
155 } 131 }
156 132 }
157 kfree(p_kBuf); 133
158 }else{ 134 kfree(p_kBuf);
159 dev_err(pTAS2560->dev, "read no mem\n"); 135 } else {
160 } 136 dev_err(pTAS2560->dev, "read no mem\n");
161 } 137 }
162 } 138 }
163 break; 139 }
164 140 break;
165 case TIAUDIO_CMD_BITRATE: 141
166 { 142 case TIAUDIO_CMD_SAMPLERATE:
167 if(g_logEnable) dev_info(pTAS2560->dev, 143 {
168 "TIAUDIO_CMD_BITRATE: count = %d\n", 144 if (g_logEnable)
169 (int)count); 145 dev_info(pTAS2560->dev,
170 146 "TIAUDIO_CMD_SAMPLERATE: count = %d\n",
171 if(count == 1){ 147 (int)count);
172 int bitRate = tas2560_get_bit_rate(pTAS2560); 148 if (count == 4) {
173 if(bitRate >=0){ 149 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL);
174 ret = copy_to_user(buf, &bitRate, 1); 150 if (p_kBuf != NULL) {
175 if (0 != ret) { 151 p_kBuf[0] = (pTAS2560->mnSamplingRate&0x000000ff);
152 p_kBuf[1] = ((pTAS2560->mnSamplingRate&0x0000ff00)>>8);
153 p_kBuf[2] = ((pTAS2560->mnSamplingRate&0x00ff0000)>>16);
154 p_kBuf[3] = ((pTAS2560->mnSamplingRate&0xff000000)>>24);
155
156 ret = copy_to_user(buf, p_kBuf, count);
157 if (0 != ret) {
176 /* Failed to copy all the data, exit */ 158 /* Failed to copy all the data, exit */
177 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret); 159 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
178 } 160 }
179 } 161
162 kfree(p_kBuf);
163 } else {
164 dev_err(pTAS2560->dev, "read no mem\n");
180 } 165 }
181 } 166 }
182 break; 167 }
183 168 break;
184 case TIAUDIO_CMD_DACVOLUME: 169
185 { 170 case TIAUDIO_CMD_BITRATE:
186 if(g_logEnable) dev_info(pTAS2560->dev, 171 {
187 "TIAUDIO_CMD_DACVOLUME: count = %d\n", 172 if (g_logEnable)
188 (int)count); 173 dev_info(pTAS2560->dev,
189 174 "TIAUDIO_CMD_BITRATE: count = %d\n",
190 if(count == 1){ 175 (int)count);
191 int volume = tas2560_get_volume(pTAS2560); 176
192 if(volume >=0){ 177 if (count == 1) {
193 ret = copy_to_user(buf, &volume, 1); 178 int bitRate = tas2560_get_bit_rate(pTAS2560);
194 if (0 != ret) { 179 if (bitRate >= 0) {
195 /* Failed to copy all the data, exit */ 180 ret = copy_to_user(buf, &bitRate, 1);
196 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret); 181 if (0 != ret) {
197 } 182 /* Failed to copy all the data, exit */
198 } 183 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
184 }
199 } 185 }
200 } 186 }
201 break;
202 } 187 }
203 pTAS2560->mnDBGCmd = 0; 188 break;
189
190 case TIAUDIO_CMD_DACVOLUME:
191 {
192 if (g_logEnable)
193 dev_info(pTAS2560->dev,
194 "TIAUDIO_CMD_DACVOLUME: count = %d\n",
195 (int)count);
204 196
205 mutex_unlock(&pTAS2560->file_lock); 197 if (count == 1) {
198 int volume = tas2560_get_volume(pTAS2560);
199 if (volume >= 0) {
200 ret = copy_to_user(buf, &volume, 1);
201 if (0 != ret) {
202 /* Failed to copy all the data, exit */
203 dev_err(pTAS2560->dev, "copy to user fail %d\n", ret);
204 }
205 }
206 }
207 }
208 break;
209 }
210 pTAS2560->mnDBGCmd = 0;
211
212 mutex_unlock(&pTAS2560->file_lock);
206 return count; 213 return count;
207} 214}
208 215
@@ -210,146 +217,145 @@ static ssize_t tas2560_file_write(struct file *file, const char *buf, size_t cou
210{ 217{
211 struct tas2560_priv *pTAS2560 = (struct tas2560_priv *)file->private_data; 218 struct tas2560_priv *pTAS2560 = (struct tas2560_priv *)file->private_data;
212 int ret = 0; 219 int ret = 0;
213// unsigned int value = 0; 220/* unsigned int value = 0;*/
214 unsigned char *p_kBuf = NULL; 221 unsigned char *p_kBuf = NULL;
215 unsigned int reg = 0; 222 unsigned int reg = 0;
216 unsigned int len = 0; 223 unsigned int len = 0;
217 enum channel chl; 224 enum channel chl;
218 225
219 mutex_lock(&pTAS2560->file_lock); 226 mutex_lock(&pTAS2560->file_lock);
220 227
221 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL); 228 p_kBuf = (unsigned char *)kzalloc(count, GFP_KERNEL);
222 if(p_kBuf == NULL) { 229 if (p_kBuf == NULL) {
223 dev_err(pTAS2560->dev, "write no mem\n"); 230 dev_err(pTAS2560->dev, "write no mem\n");
224 goto err; 231 goto err;
225 } 232 }
226 233
227 ret = copy_from_user(p_kBuf, buf, count); 234 ret = copy_from_user(p_kBuf, buf, count);
228 if (0 != ret) { 235 if (0 != ret) {
229 dev_err(pTAS2560->dev,"copy_from_user failed.\n"); 236 dev_err(pTAS2560->dev, "copy_from_user failed.\n");
230 goto err; 237 goto err;
231 } 238 }
232 239
233 pTAS2560->mnDBGCmd = p_kBuf[0]; 240 pTAS2560->mnDBGCmd = p_kBuf[0];
234 switch(pTAS2560->mnDBGCmd) 241 switch (pTAS2560->mnDBGCmd) {
242 case TIAUDIO_CMD_REG_WITE:
243 if (count > 6) {
244 chl = p_kBuf[1];
245 reg = ((unsigned int)p_kBuf[2] << 24) +
246 ((unsigned int)p_kBuf[3] << 16) +
247 ((unsigned int)p_kBuf[4] << 8) +
248 (unsigned int)p_kBuf[5];
249 len = count - 6;
250 if (len == 1) {
251 ret = pTAS2560->write(pTAS2560, chl, reg, p_kBuf[6]);
252 if (g_logEnable)
253 dev_info(pTAS2560->dev,
254 "TIAUDIO_CMD_REG_WITE, Reg=0x%x, Val=0x%x\n",
255 reg, p_kBuf[5]);
256 } else {
257 ret = pTAS2560->bulk_write(pTAS2560, chl, reg, &p_kBuf[6], len);
258 }
259 } else {
260 dev_err(pTAS2560->dev, "%s, write len fail, count=%d.\n",
261 __FUNCTION__, (int)count);
262 }
263 pTAS2560->mnDBGCmd = 0;
264 break;
265
266 case TIAUDIO_CMD_REG_READ:
267 if (count == 6) {
268 pTAS2560->mnCurrentChannel = p_kBuf[1];
269 pTAS2560->mnCurrentReg = ((unsigned int)p_kBuf[2] << 24) +
270 ((unsigned int)p_kBuf[3] << 16) +
271 ((unsigned int)p_kBuf[4] << 8) +
272 (unsigned int)p_kBuf[5];
273 if (g_logEnable) {
274 dev_info(pTAS2560->dev,
275 "TIAUDIO_CMD_REG_READ, whole=0x%x\n",
276 pTAS2560->mnCurrentReg);
277 }
278 } else {
279 dev_err(pTAS2560->dev, "read len fail.\n");
280 }
281 break;
282
283 case TIAUDIO_CMD_DEBUG_ON:
235 { 284 {
236 case TIAUDIO_CMD_REG_WITE: 285 if (count == 2) {
237 if(count > 6){ 286 g_logEnable = p_kBuf[1];
238 chl = p_kBuf[1];
239 reg = ((unsigned int)p_kBuf[2] << 24) +
240 ((unsigned int)p_kBuf[3] << 16) +
241 ((unsigned int)p_kBuf[4] << 8) +
242 (unsigned int)p_kBuf[5];
243 len = count - 6;
244 if(len == 1){
245 ret = pTAS2560->write(pTAS2560, chl, reg, p_kBuf[6]);
246 if(g_logEnable)
247 dev_info(pTAS2560->dev,
248 "TIAUDIO_CMD_REG_WITE, Reg=0x%x, Val=0x%x\n",
249 reg, p_kBuf[5]);
250 }else{
251 ret = pTAS2560->bulk_write(pTAS2560, chl, reg, &p_kBuf[6], len);
252 }
253 }else{
254 dev_err(pTAS2560->dev,"%s, write len fail, count=%d.\n",
255 __FUNCTION__, (int)count);
256 } 287 }
257 pTAS2560->mnDBGCmd = 0; 288 pTAS2560->mnDBGCmd = 0;
258 break; 289 }
259 290 break;
260 case TIAUDIO_CMD_REG_READ: 291
261 if(count == 6){ 292 case TIAUDIO_CMD_SAMPLERATE:
262 pTAS2560->mnCurrentChannel = p_kBuf[1]; 293 {
263 pTAS2560->mnCurrentReg = ((unsigned int)p_kBuf[2] << 24) + 294 if (count == 5) {
264 ((unsigned int)p_kBuf[3] << 16) + 295 unsigned int nSampleRate = ((unsigned int)p_kBuf[1] << 24) +
265 ((unsigned int)p_kBuf[4] << 8) + 296 ((unsigned int)p_kBuf[2] << 16) +
266 (unsigned int)p_kBuf[5]; 297 ((unsigned int)p_kBuf[3] << 8) +
267 if(g_logEnable){ 298 (unsigned int)p_kBuf[4];
299 if (g_logEnable)
268 dev_info(pTAS2560->dev, 300 dev_info(pTAS2560->dev,
269 "TIAUDIO_CMD_REG_READ, whole=0x%x\n", 301 "TIAUDIO_CMD_SAMPLERATE, set to %d\n",
270 pTAS2560->mnCurrentReg); 302 nSampleRate);
271 } 303
272 }else{ 304 tas2560_set_SampleRate(pTAS2560, nSampleRate);
273 dev_err(pTAS2560->dev,"read len fail.\n");
274 }
275 break;
276
277 case TIAUDIO_CMD_DEBUG_ON:
278 {
279 if(count == 2){
280 g_logEnable = p_kBuf[1];
281 }
282 pTAS2560->mnDBGCmd = 0;
283 }
284 break;
285
286 case TIAUDIO_CMD_SAMPLERATE:
287 {
288 if(count == 5){
289 unsigned int nSampleRate = ((unsigned int)p_kBuf[1] << 24) +
290 ((unsigned int)p_kBuf[2] << 16) +
291 ((unsigned int)p_kBuf[3] << 8) +
292 (unsigned int)p_kBuf[4];
293 if(g_logEnable)
294 dev_info(pTAS2560->dev,
295 "TIAUDIO_CMD_SAMPLERATE, set to %d\n",
296 nSampleRate);
297
298 tas2560_set_SampleRate(pTAS2560, nSampleRate);
299 }
300 } 305 }
301 break; 306 }
302 307 break;
303 case TIAUDIO_CMD_BITRATE: 308
304 { 309 case TIAUDIO_CMD_BITRATE:
305 if(count == 2){ 310 {
306 if(g_logEnable) 311 if (count == 2) {
307 dev_info(pTAS2560->dev, 312 if (g_logEnable)
308 "TIAUDIO_CMD_BITRATE, set to %d\n", 313 dev_info(pTAS2560->dev,
309 p_kBuf[1]); 314 "TIAUDIO_CMD_BITRATE, set to %d\n",
310 315 p_kBuf[1]);
311 tas2560_set_bit_rate(pTAS2560, p_kBuf[1]); 316
312 } 317 tas2560_set_bit_rate(pTAS2560, p_kBuf[1]);
313 } 318 }
314 break; 319 }
315 320 break;
316 case TIAUDIO_CMD_DACVOLUME: 321
317 { 322 case TIAUDIO_CMD_DACVOLUME:
318 if(count == 2){ 323 {
319 unsigned char volume = (p_kBuf[1] & 0x0f); 324 if (count == 2) {
320 if(g_logEnable) 325 unsigned char volume = (p_kBuf[1] & 0x0f);
321 dev_info(pTAS2560->dev, 326 if (g_logEnable)
322 "TIAUDIO_CMD_DACVOLUME, set to %d\n", 327 dev_info(pTAS2560->dev,
323 volume); 328 "TIAUDIO_CMD_DACVOLUME, set to %d\n",
324 329 volume);
325 tas2560_set_volume(pTAS2560, volume); 330
326 } 331 tas2560_set_volume(pTAS2560, volume);
327 } 332 }
328 break; 333 }
329 334 break;
330 case TIAUDIO_CMD_SPEAKER: 335
331 { 336 case TIAUDIO_CMD_SPEAKER:
332 if(count == 2){ 337 {
333 if(g_logEnable) 338 if (count == 2) {
334 dev_info(pTAS2560->dev, 339 if (g_logEnable)
335 "TIAUDIO_CMD_SPEAKER, set to %d\n", 340 dev_info(pTAS2560->dev,
336 p_kBuf[1]); 341 "TIAUDIO_CMD_SPEAKER, set to %d\n",
337 tas2560_enable(pTAS2560, (p_kBuf[1]>0)); 342 p_kBuf[1]);
338 } 343 tas2560_enable(pTAS2560, (p_kBuf[1] > 0));
339 } 344 }
340 break; 345 }
341 346 break;
342 default: 347
343 pTAS2560->mnDBGCmd = 0; 348 default:
344 break; 349 pTAS2560->mnDBGCmd = 0;
350 break;
345 } 351 }
346 352
347err: 353err:
348 if(p_kBuf != NULL) 354 if (p_kBuf != NULL)
349 kfree(p_kBuf); 355 kfree(p_kBuf);
350 356
351 mutex_unlock(&pTAS2560->file_lock); 357 mutex_unlock(&pTAS2560->file_lock);
352 358
353 return count; 359 return count;
354} 360}
355 361
@@ -357,48 +363,47 @@ static long tas2560_file_unlocked_ioctl(struct file *file, unsigned int cmd, uns
357{ 363{
358 struct tas2560_priv *pTAS2560 = file->private_data; 364 struct tas2560_priv *pTAS2560 = file->private_data;
359 int ret = 0; 365 int ret = 0;
360 366
361 mutex_lock(&pTAS2560->file_lock); 367 mutex_lock(&pTAS2560->file_lock);
362 368
363 switch (cmd) { 369 switch (cmd) {
364 case SMARTPA_SPK_DAC_VOLUME: 370 case SMARTPA_SPK_DAC_VOLUME:
365 { 371 {
366 u8 volume = (arg & 0x0f); 372 u8 volume = (arg & 0x0f);
367 tas2560_set_volume(pTAS2560, volume); 373 tas2560_set_volume(pTAS2560, volume);
368 } 374 }
369 break; 375 break;
370
371 case SMARTPA_SPK_POWER_ON:
372 {
373 tas2560_enable(pTAS2560, true);
374 }
375 break;
376
377 case SMARTPA_SPK_POWER_OFF:
378 {
379 tas2560_enable(pTAS2560, false);
380 }
381 break;
382
383 case SMARTPA_SPK_SET_SAMPLERATE:
384 {
385 tas2560_set_SampleRate(pTAS2560, arg);
386 }
387 break;
388 376
389 case SMARTPA_SPK_SET_BITRATE: 377 case SMARTPA_SPK_POWER_ON:
390 { 378 {
391 tas2560_set_bit_rate(pTAS2560, arg); 379 tas2560_enable(pTAS2560, true);
392 } 380 }
393 break; 381 break;
382
383 case SMARTPA_SPK_POWER_OFF:
384 {
385 tas2560_enable(pTAS2560, false);
386 }
387 break;
388
389 case SMARTPA_SPK_SET_SAMPLERATE:
390 {
391 tas2560_set_SampleRate(pTAS2560, arg);
392 }
393 break;
394
395 case SMARTPA_SPK_SET_BITRATE:
396 {
397 tas2560_set_bit_rate(pTAS2560, arg);
394 } 398 }
395 399 break;
400 }
401
396 mutex_unlock(&pTAS2560->file_lock); 402 mutex_unlock(&pTAS2560->file_lock);
397 return ret; 403 return ret;
398} 404}
399 405
400static struct file_operations fops = 406static struct file_operations fops = {
401{
402 .owner = THIS_MODULE, 407 .owner = THIS_MODULE,
403 .read = tas2560_file_read, 408 .read = tas2560_file_read,
404 .write = tas2560_file_write, 409 .write = tas2560_file_write,
@@ -408,30 +413,29 @@ static struct file_operations fops =
408}; 413};
409 414
410#define MODULE_NAME "tas2560" 415#define MODULE_NAME "tas2560"
411static struct miscdevice tas2560_misc = 416static struct miscdevice tas2560_misc = {
412{
413 .minor = MISC_DYNAMIC_MINOR, 417 .minor = MISC_DYNAMIC_MINOR,
414 .name = MODULE_NAME, 418 .name = MODULE_NAME,
415 .fops = &fops, 419 .fops = &fops,
416}; 420};
417 421
418int tas2560_register_misc(struct tas2560_priv * pTAS2560) 422int tas2560_register_misc(struct tas2560_priv *pTAS2560)
419{ 423{
420 int ret = 0; 424 int ret = 0;
421 425
422 g_tas2560 = pTAS2560; 426 g_tas2560 = pTAS2560;
423 427
424 ret = misc_register(&tas2560_misc); 428 ret = misc_register(&tas2560_misc);
425 if (ret) { 429 if (ret) {
426 dev_err(pTAS2560->dev, "TAS2560 misc fail: %d\n", ret); 430 dev_err(pTAS2560->dev, "TAS2560 misc fail: %d\n", ret);
427 } 431 }
428 432
429 dev_info(pTAS2560->dev, "%s, leave\n", __FUNCTION__); 433 dev_info(pTAS2560->dev, "%s, leave\n", __FUNCTION__);
430 434
431 return ret; 435 return ret;
432} 436}
433 437
434int tas2560_deregister_misc(struct tas2560_priv * pTAS2560) 438int tas2560_deregister_misc(struct tas2560_priv *pTAS2560)
435{ 439{
436 misc_deregister(&tas2560_misc); 440 misc_deregister(&tas2560_misc);
437 return 0; 441 return 0;
@@ -440,4 +444,4 @@ int tas2560_deregister_misc(struct tas2560_priv * pTAS2560)
440MODULE_AUTHOR("Texas Instruments Inc."); 444MODULE_AUTHOR("Texas Instruments Inc.");
441MODULE_DESCRIPTION("TAS2560 Misc Smart Amplifier driver"); 445MODULE_DESCRIPTION("TAS2560 Misc Smart Amplifier driver");
442MODULE_LICENSE("GPLv2"); 446MODULE_LICENSE("GPLv2");
443#endif //CONFIG_TAS2560_MISC 447#endif /*CONFIG_TAS2560_MISC*/
diff --git a/tas2560-misc.h b/tas2560-misc.h
index 3bd141a..c29895c 100755..100644
--- a/tas2560-misc.h
+++ b/tas2560-misc.h
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -44,6 +44,6 @@
44#define SMARTPA_SPK_SET_BITRATE _IOWR(TAS2560_MAGIC_NUMBER, 8, unsigned long) 44#define SMARTPA_SPK_SET_BITRATE _IOWR(TAS2560_MAGIC_NUMBER, 8, unsigned long)
45 45
46int tas2560_register_misc(struct tas2560_priv *pTAS2560); 46int tas2560_register_misc(struct tas2560_priv *pTAS2560);
47int tas2560_deregister_misc(struct tas2560_priv *pTAS2560); 47int tas2560_deregister_misc(struct tas2560_priv *pTAS2560);
48 48
49#endif /* _TAS2560_MISC_H */ 49#endif /* _TAS2560_MISC_H */
diff --git a/tas2560-regmap.c b/tas2560-regmap.c
index 97d8f5d..e9d3569 100755..100644
--- a/tas2560-regmap.c
+++ b/tas2560-regmap.c
@@ -14,9 +14,9 @@
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 * 15 *
16 */ 16 */
17#ifdef CONFIG_TAS2560_REGMAP_STEREO 17#ifdef CONFIG_TAS2560_REGMAP_STEREO
18 18
19#define DEBUG 19#define DEBUG
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/moduleparam.h> 21#include <linux/moduleparam.h>
22#include <linux/err.h> 22#include <linux/err.h>
@@ -41,71 +41,72 @@
41static int tas2560_change_page(struct tas2560_priv *pTAS2560, enum channel chn, int page) 41static int tas2560_change_page(struct tas2560_priv *pTAS2560, enum channel chn, int page)
42{ 42{
43 int ret = 0; 43 int ret = 0;
44 44
45 if(chn&channel_left){ 45 if (chn&channel_left) {
46 if (pTAS2560->mnLCurrentPage != page){ 46 if (pTAS2560->mnLCurrentPage != page) {
47 pTAS2560->client->addr = pTAS2560->mnLAddr; 47 pTAS2560->client->addr = pTAS2560->mnLAddr;
48 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_PAGE, page); 48 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_PAGE, page);
49 if(ret < 0) 49 if (ret < 0)
50 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 50 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
51 __FUNCTION__, __LINE__, ret); 51 __FUNCTION__, __LINE__, ret);
52 else 52 else
53 pTAS2560->mnLCurrentPage = page; 53 pTAS2560->mnLCurrentPage = page;
54 } 54 }
55 } 55 }
56 56
57 if(ret >= 0){ 57 if (ret >= 0) {
58 if(chn&channel_right){ 58 if (chn&channel_right) {
59 if (pTAS2560->mnRCurrentPage != page){ 59 if (pTAS2560->mnRCurrentPage != page) {
60 pTAS2560->client->addr = pTAS2560->mnRAddr; 60 pTAS2560->client->addr = pTAS2560->mnRAddr;
61 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_PAGE, page); 61 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_PAGE, page);
62 if(ret < 0) 62 if (ret < 0)
63 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 63 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
64 __FUNCTION__, __LINE__, ret); 64 __FUNCTION__, __LINE__, ret);
65 else 65 else
66 pTAS2560->mnRCurrentPage = page; 66 pTAS2560->mnRCurrentPage = page;
67 } 67 }
68 } 68 }
69 } 69 }
70 70
71 return ret; 71 return ret;
72} 72}
73 73
74static int tas2560_change_book(struct tas2560_priv *pTAS2560, enum channel chn, int book) 74static int tas2560_change_book(struct tas2560_priv *pTAS2560, enum channel chn, int book)
75{ 75{
76 int ret = 0; 76 int ret = 0;
77 77
78 if(chn&channel_left){ 78 if (chn&channel_left) {
79 if (pTAS2560->mnLCurrentBook != book){ 79 if (pTAS2560->mnLCurrentBook != book) {
80 ret = tas2560_change_page(pTAS2560, channel_left, 0); 80 ret = tas2560_change_page(pTAS2560, channel_left, 0);
81 if(ret >= 0){ 81 if (ret >= 0) {
82 pTAS2560->client->addr = pTAS2560->mnLAddr; 82 pTAS2560->client->addr = pTAS2560->mnLAddr;
83 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_REG, book); 83 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_REG, book);
84 if(ret < 0) 84 if (ret < 0)
85 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 85 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
86 __FUNCTION__, __LINE__, ret); 86 __FUNCTION__, __LINE__, ret);
87 else 87 else
88 pTAS2560->mnLCurrentBook = book; 88 pTAS2560->mnLCurrentBook = book;
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 if(ret >= 0){ 93 if (ret >= 0) {
94 if(chn&channel_right){ 94 if (chn&channel_right) {
95 if (pTAS2560->mnRCurrentBook != book){ 95 if (pTAS2560->mnRCurrentBook != book) {
96 ret = tas2560_change_page(pTAS2560, channel_right, 0); 96 ret = tas2560_change_page(pTAS2560, channel_right, 0);
97 if(ret >= 0){ 97 if (ret >= 0) {
98 pTAS2560->client->addr = pTAS2560->mnRAddr; 98 pTAS2560->client->addr = pTAS2560->mnRAddr;
99 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_REG, book); 99 ret = regmap_write(pTAS2560->regmap, TAS2560_BOOKCTL_REG, book);
100 if(ret >= 0) pTAS2560->mnRCurrentBook = book; 100 if (ret >= 0)
101 pTAS2560->mnRCurrentBook = book;
101 else 102 else
102 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 103 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
103 __FUNCTION__, __LINE__, ret); 104 __FUNCTION__, __LINE__, ret);
104 } 105 }
105 } 106 }
106 } 107 }
107 } 108 }
108 109
109 return ret; 110 return ret;
110} 111}
111 112
@@ -117,71 +118,71 @@ static int tas2560_dev_read(struct tas2560_priv *pTAS2560,
117 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u\n", __func__, 118 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u\n", __func__,
118 TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg), 119 TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg),
119 TAS2560_PAGE_REG(reg)); 120 TAS2560_PAGE_REG(reg));
120 121
121 mutex_lock(&pTAS2560->dev_lock); 122 mutex_lock(&pTAS2560->dev_lock);
122 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg)); 123 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg));
123 if(ret >= 0 ) 124 if (ret >= 0)
124 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg)); 125 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg));
125 126
126 if(ret >= 0 ){ 127 if (ret >= 0) {
127 if(chn == channel_left){ 128 if (chn == channel_left) {
128 pTAS2560->client->addr = pTAS2560->mnLAddr; 129 pTAS2560->client->addr = pTAS2560->mnLAddr;
129 ret = regmap_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pValue); 130 ret = regmap_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pValue);
130 if(ret < 0) 131 if (ret < 0)
131 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 132 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
132 __FUNCTION__, __LINE__, ret); 133 __FUNCTION__, __LINE__, ret);
133 }else if(chn == channel_left){ 134 } else if (chn == channel_left) {
134 pTAS2560->client->addr = pTAS2560->mnRAddr; 135 pTAS2560->client->addr = pTAS2560->mnRAddr;
135 ret = regmap_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pValue); 136 ret = regmap_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pValue);
136 if(ret < 0) 137 if (ret < 0)
137 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 138 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
138 __FUNCTION__, __LINE__, ret); 139 __FUNCTION__, __LINE__, ret);
139 }else{ 140 } else {
140 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 141 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
141 __FUNCTION__, __LINE__, ret); 142 __FUNCTION__, __LINE__, ret);
142 } 143 }
143 } 144 }
144 mutex_unlock(&pTAS2560->dev_lock); 145 mutex_unlock(&pTAS2560->dev_lock);
145 return ret; 146 return ret;
146} 147}
147 148
148static int tas2560_dev_write(struct tas2560_priv *pTAS2560, 149static int tas2560_dev_write(struct tas2560_priv *pTAS2560,
149 enum channel chn, unsigned int reg, unsigned int value) 150 enum channel chn, unsigned int reg, unsigned int value)
150{ 151{
151 int ret = -1; 152 int ret = -1;
152 153
153 mutex_lock(&pTAS2560->dev_lock); 154 mutex_lock(&pTAS2560->dev_lock);
154 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg)); 155 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg));
155 if(ret >= 0) 156 if (ret >= 0)
156 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg)); 157 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg));
157 158
158 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, VAL: 0x%02x\n", 159 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, VAL: 0x%02x\n",
159 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg), 160 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg),
160 TAS2560_PAGE_REG(reg), value); 161 TAS2560_PAGE_REG(reg), value);
161 if(ret >= 0){ 162 if (ret >= 0) {
162 if(chn&channel_left){ 163 if (chn&channel_left) {
163 pTAS2560->client->addr = pTAS2560->mnLAddr; 164 pTAS2560->client->addr = pTAS2560->mnLAddr;
164 ret = regmap_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), 165 ret = regmap_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg),
165 value); 166 value);
166 if(ret < 0) 167 if (ret < 0)
167 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 168 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
168 __FUNCTION__, __LINE__, ret); 169 __FUNCTION__, __LINE__, ret);
169 } 170 }
170 171
171 if(chn&channel_right){ 172 if (chn&channel_right) {
172 pTAS2560->client->addr = pTAS2560->mnRAddr; 173 pTAS2560->client->addr = pTAS2560->mnRAddr;
173 ret = regmap_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), 174 ret = regmap_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg),
174 value); 175 value);
175 if(ret < 0) 176 if (ret < 0)
176 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 177 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
177 __FUNCTION__, __LINE__, ret); 178 __FUNCTION__, __LINE__, ret);
178 } 179 }
179 } 180 }
180 mutex_unlock(&pTAS2560->dev_lock); 181 mutex_unlock(&pTAS2560->dev_lock);
181 return ret; 182 return ret;
182} 183}
183 184
184static int tas2560_dev_bulk_write(struct tas2560_priv *pTAS2560, 185static int tas2560_dev_bulk_write(struct tas2560_priv *pTAS2560,
185 enum channel chn, unsigned int reg, 186 enum channel chn, unsigned int reg,
186 unsigned char *pData, unsigned int nLength) 187 unsigned char *pData, unsigned int nLength)
187{ 188{
@@ -189,27 +190,27 @@ static int tas2560_dev_bulk_write(struct tas2560_priv *pTAS2560,
189 190
190 mutex_lock(&pTAS2560->dev_lock); 191 mutex_lock(&pTAS2560->dev_lock);
191 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg)); 192 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg));
192 if(ret >= 0) 193 if (ret >= 0)
193 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg)); 194 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg));
194 195
195 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n", 196 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n",
196 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg), 197 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg),
197 TAS2560_PAGE_REG(reg), nLength); 198 TAS2560_PAGE_REG(reg), nLength);
198 199
199 if(ret >= 0){ 200 if (ret >= 0) {
200 if(chn&channel_left){ 201 if (chn&channel_left) {
201 pTAS2560->client->addr = pTAS2560->mnLAddr; 202 pTAS2560->client->addr = pTAS2560->mnLAddr;
202 ret = regmap_bulk_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength); 203 ret = regmap_bulk_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength);
203 if(ret < 0) 204 if (ret < 0)
204 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 205 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
205 __FUNCTION__, __LINE__, ret); 206 __FUNCTION__, __LINE__, ret);
206 } 207 }
207 208
208 if(chn&channel_right){ 209 if (chn&channel_right) {
209 pTAS2560->client->addr = pTAS2560->mnRAddr; 210 pTAS2560->client->addr = pTAS2560->mnRAddr;
210 ret = regmap_bulk_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength); 211 ret = regmap_bulk_write(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength);
211 if(ret < 0) 212 if (ret < 0)
212 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 213 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
213 __FUNCTION__, __LINE__, ret); 214 __FUNCTION__, __LINE__, ret);
214 } 215 }
215 } 216 }
@@ -217,7 +218,7 @@ static int tas2560_dev_bulk_write(struct tas2560_priv *pTAS2560,
217 return ret; 218 return ret;
218} 219}
219 220
220static int tas2560_dev_bulk_read(struct tas2560_priv *pTAS2560, 221static int tas2560_dev_bulk_read(struct tas2560_priv *pTAS2560,
221 enum channel chn, unsigned int reg, 222 enum channel chn, unsigned int reg,
222 unsigned char *pData, unsigned int nLength) 223 unsigned char *pData, unsigned int nLength)
223{ 224{
@@ -225,35 +226,35 @@ static int tas2560_dev_bulk_read(struct tas2560_priv *pTAS2560,
225 226
226 mutex_lock(&pTAS2560->dev_lock); 227 mutex_lock(&pTAS2560->dev_lock);
227 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg)); 228 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg));
228 if(ret >= 0) 229 if (ret >= 0)
229 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg)); 230 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg));
230 231
231 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n", 232 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, len: 0x%02x\n",
232 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg), 233 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg),
233 TAS2560_PAGE_REG(reg), nLength); 234 TAS2560_PAGE_REG(reg), nLength);
234 235
235 if(ret >= 0){ 236 if (ret >= 0) {
236 if(chn == channel_left){ 237 if (chn == channel_left) {
237 pTAS2560->client->addr = pTAS2560->mnLAddr; 238 pTAS2560->client->addr = pTAS2560->mnLAddr;
238 ret = regmap_bulk_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength); 239 ret = regmap_bulk_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength);
239 if(ret < 0) 240 if (ret < 0)
240 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 241 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
241 __FUNCTION__, __LINE__, ret); 242 __FUNCTION__, __LINE__, ret);
242 }else if(chn == channel_right){ 243 } else if (chn == channel_right) {
243 pTAS2560->client->addr = pTAS2560->mnRAddr; 244 pTAS2560->client->addr = pTAS2560->mnRAddr;
244 ret = regmap_bulk_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength); 245 ret = regmap_bulk_read(pTAS2560->regmap, TAS2560_PAGE_REG(reg), pData, nLength);
245 if(ret < 0) 246 if (ret < 0)
246 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 247 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
247 __FUNCTION__, __LINE__, ret); 248 __FUNCTION__, __LINE__, ret);
248 }else 249 } else
249 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 250 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
250 __FUNCTION__, __LINE__, ret); 251 __FUNCTION__, __LINE__, ret);
251 } 252 }
252 mutex_unlock(&pTAS2560->dev_lock); 253 mutex_unlock(&pTAS2560->dev_lock);
253 return ret; 254 return ret;
254} 255}
255 256
256static int tas2560_dev_update_bits(struct tas2560_priv *pTAS2560, 257static int tas2560_dev_update_bits(struct tas2560_priv *pTAS2560,
257 enum channel chn, unsigned int reg, 258 enum channel chn, unsigned int reg,
258 unsigned int mask, unsigned int value) 259 unsigned int mask, unsigned int value)
259{ 260{
@@ -261,32 +262,32 @@ static int tas2560_dev_update_bits(struct tas2560_priv *pTAS2560,
261 262
262 mutex_lock(&pTAS2560->dev_lock); 263 mutex_lock(&pTAS2560->dev_lock);
263 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg)); 264 ret = tas2560_change_book(pTAS2560, chn, TAS2560_BOOK_ID(reg));
264 if(ret >= 0) 265 if (ret >= 0)
265 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg)); 266 ret = tas2560_change_page(pTAS2560, chn, TAS2560_PAGE_ID(reg));
266 267
267 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, mask: 0x%x, val=0x%x\n", 268 dev_dbg(pTAS2560->dev, "%s: BOOK:PAGE:REG %u:%u:%u, mask: 0x%x, val=0x%x\n",
268 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg), 269 __func__, TAS2560_BOOK_ID(reg), TAS2560_PAGE_ID(reg),
269 TAS2560_PAGE_REG(reg), mask, value); 270 TAS2560_PAGE_REG(reg), mask, value);
270 271
271 if(ret >= 0){ 272 if (ret >= 0) {
272 if(chn&channel_left){ 273 if (chn&channel_left) {
273 pTAS2560->client->addr = pTAS2560->mnLAddr; 274 pTAS2560->client->addr = pTAS2560->mnLAddr;
274 ret = regmap_update_bits(pTAS2560->regmap, TAS2560_PAGE_REG(reg), mask, value); 275 ret = regmap_update_bits(pTAS2560->regmap, TAS2560_PAGE_REG(reg), mask, value);
275 if(ret < 0) 276 if (ret < 0)
276 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 277 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
277 __FUNCTION__, __LINE__, ret); 278 __FUNCTION__, __LINE__, ret);
278 } 279 }
279 280
280 if(chn&channel_right){ 281 if (chn&channel_right) {
281 pTAS2560->client->addr = pTAS2560->mnRAddr; 282 pTAS2560->client->addr = pTAS2560->mnRAddr;
282 ret = regmap_update_bits(pTAS2560->regmap, TAS2560_PAGE_REG(reg), mask, value); 283 ret = regmap_update_bits(pTAS2560->regmap, TAS2560_PAGE_REG(reg), mask, value);
283 if(ret < 0) 284 if (ret < 0)
284 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n", 285 dev_err(pTAS2560->dev, "%s, line %d,ERROR %d\n",
285 __FUNCTION__, __LINE__, ret); 286 __FUNCTION__, __LINE__, ret);
286 } 287 }
287 288
288 } 289 }
289 290
290 mutex_unlock(&pTAS2560->dev_lock); 291 mutex_unlock(&pTAS2560->dev_lock);
291 return ret; 292 return ret;
292} 293}
@@ -315,19 +316,19 @@ static int tas2560_i2c_probe(struct i2c_client *client,
315{ 316{
316 struct tas2560_priv *pTAS2560; 317 struct tas2560_priv *pTAS2560;
317 int ret; 318 int ret;
318// static int nClient = 0; 319/* static int nClient = 0;*/
320
321 dev_info(&client->dev, "%s enter\n", __func__);
319 322
320 dev_info(&client->dev, "%s enter\n",__func__);
321
322 pTAS2560 = devm_kzalloc(&client->dev, sizeof(struct tas2560_priv), GFP_KERNEL); 323 pTAS2560 = devm_kzalloc(&client->dev, sizeof(struct tas2560_priv), GFP_KERNEL);
323 if (pTAS2560 == NULL){ 324 if (pTAS2560 == NULL) {
324 dev_err(&client->dev, "%s, -ENOMEM \n",__func__); 325 dev_err(&client->dev, "%s, -ENOMEM \n", __func__);
325 return -ENOMEM; 326 return -ENOMEM;
326 } 327 }
327 328
328 pTAS2560->dev = &client->dev; 329 pTAS2560->dev = &client->dev;
329 pTAS2560->client = client; 330 pTAS2560->client = client;
330 331
331 i2c_set_clientdata(client, pTAS2560); 332 i2c_set_clientdata(client, pTAS2560);
332 333
333 dev_set_drvdata(&client->dev, pTAS2560); 334 dev_set_drvdata(&client->dev, pTAS2560);
@@ -340,52 +341,52 @@ static int tas2560_i2c_probe(struct i2c_client *client,
340 return ret; 341 return ret;
341 } 342 }
342 343
343 if (client->dev.of_node){ 344 if (client->dev.of_node) {
344 tas2560_parse_dt(&client->dev, pTAS2560); 345 tas2560_parse_dt(&client->dev, pTAS2560);
345 346
346#ifdef SMART_AMP_HW_RESET 347#ifdef SMART_AMP_HW_RESET
347 if(pTAS2560->mnResetGPIO > 0){ 348 if (pTAS2560->mnResetGPIO > 0) {
348 ret = gpio_request(pTAS2560->mnResetGPIO, "TAS2560_RESET"); 349 ret = gpio_request(pTAS2560->mnResetGPIO, "TAS2560_RESET");
349 if (ret) { 350 if (ret) {
350 dev_err(pTAS2560->dev, "%s: Failed to request gpio %d\n", __func__, 351 dev_err(pTAS2560->dev, "%s: Failed to request gpio %d\n", __func__,
351 pTAS2560->mnResetGPIO); 352 pTAS2560->mnResetGPIO);
352 pTAS2560->mnResetGPIO = 0; 353 pTAS2560->mnResetGPIO = 0;
353 }else{ 354 } else {
354 gpio_direction_output(pTAS2560->mnResetGPIO, 0); 355 gpio_direction_output(pTAS2560->mnResetGPIO, 0);
355 msleep(5); 356 msleep(5);
356 gpio_direction_output(pTAS2560->mnResetGPIO, 1); 357 gpio_direction_output(pTAS2560->mnResetGPIO, 1);
357 msleep(1); 358 msleep(1);
358 } 359 }
359 } 360 }
360#endif 361#endif
361 } 362 }
362 363
363 pTAS2560->mnLCurrentBook = -1; 364 pTAS2560->mnLCurrentBook = -1;
364 pTAS2560->mnLCurrentPage = -1; 365 pTAS2560->mnLCurrentPage = -1;
365 pTAS2560->mnRCurrentBook = -1; 366 pTAS2560->mnRCurrentBook = -1;
366 pTAS2560->mnRCurrentPage = -1; 367 pTAS2560->mnRCurrentPage = -1;
367 368
368 pTAS2560->read = tas2560_dev_read; 369 pTAS2560->read = tas2560_dev_read;
369 pTAS2560->write = tas2560_dev_write; 370 pTAS2560->write = tas2560_dev_write;
370 pTAS2560->bulk_read = tas2560_dev_bulk_read; 371 pTAS2560->bulk_read = tas2560_dev_bulk_read;
371 pTAS2560->bulk_write = tas2560_dev_bulk_write; 372 pTAS2560->bulk_write = tas2560_dev_bulk_write;
372 pTAS2560->update_bits = tas2560_dev_update_bits; 373 pTAS2560->update_bits = tas2560_dev_update_bits;
373 mutex_init(&pTAS2560->dev_lock); 374 mutex_init(&pTAS2560->dev_lock);
374 375
375 ret = tas2560_dev_write(pTAS2560, channel_both, TAS2560_SW_RESET_REG, 0x01); 376 ret = tas2560_dev_write(pTAS2560, channel_both, TAS2560_SW_RESET_REG, 0x01);
376 if(ret < 0){ 377 if (ret < 0) {
377 dev_err(pTAS2560->dev, "ERROR I2C comm, %d\n", ret); 378 dev_err(pTAS2560->dev, "ERROR I2C comm, %d\n", ret);
378 return ret; 379 return ret;
379 } 380 }
380 381
381 udelay(100); 382 udelay(100);
382 383
383#ifdef CONFIG_TAS2560_CODEC 384#ifdef CONFIG_TAS2560_CODEC
384 tas2560_register_codec(pTAS2560); 385 tas2560_register_codec(pTAS2560);
385#else 386#else
386 pTAS2560->write(pTAS2560, channel_both, TAS2560_DR_BOOST_REG, 0x04); 387 pTAS2560->write(pTAS2560, channel_both, TAS2560_DR_BOOST_REG, 0x04);
387 pTAS2560->write(pTAS2560,channel_both, TAS2560_DEV_MODE_REG, 0x02); 388 pTAS2560->write(pTAS2560, channel_both, TAS2560_DEV_MODE_REG, 0x02);
388 tas2560_set_ASI_fmt(pTAS2560, 389 tas2560_set_ASI_fmt(pTAS2560,
389 SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_NB_NF|SND_SOC_DAIFMT_I2S); 390 SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_NB_NF|SND_SOC_DAIFMT_I2S);
390 tas2560_set_bit_rate(pTAS2560, 24); 391 tas2560_set_bit_rate(pTAS2560, 24);
391 tas2560_set_SampleRate(pTAS2560, 48000); 392 tas2560_set_SampleRate(pTAS2560, 48000);
@@ -394,7 +395,7 @@ static int tas2560_i2c_probe(struct i2c_client *client,
394 tas2560_setLoad(pTAS2560, LOAD_8OHM); 395 tas2560_setLoad(pTAS2560, LOAD_8OHM);
395#endif 396#endif
396 397
397#ifdef CONFIG_TAS2560_MISC 398#ifdef CONFIG_TAS2560_MISC
398 mutex_init(&pTAS2560->file_lock); 399 mutex_init(&pTAS2560->file_lock);
399 tas2560_register_misc(pTAS2560); 400 tas2560_register_misc(pTAS2560);
400#endif 401#endif
@@ -406,18 +407,18 @@ static int tas2560_i2c_probe(struct i2c_client *client,
406static int tas2560_i2c_remove(struct i2c_client *client) 407static int tas2560_i2c_remove(struct i2c_client *client)
407{ 408{
408 struct tas2560_priv *pTAS2560 = i2c_get_clientdata(client); 409 struct tas2560_priv *pTAS2560 = i2c_get_clientdata(client);
409 410
410 dev_info(pTAS2560->dev, "%s\n", __FUNCTION__); 411 dev_info(pTAS2560->dev, "%s\n", __FUNCTION__);
411 412
412#ifdef CONFIG_TAS2560_CODEC 413#ifdef CONFIG_TAS2560_CODEC
413 tas2560_deregister_codec(pTAS2560); 414 tas2560_deregister_codec(pTAS2560);
414#endif 415#endif
415 416
416#ifdef CONFIG_TAS2560_MISC 417#ifdef CONFIG_TAS2560_MISC
417 tas2560_deregister_misc(pTAS2560); 418 tas2560_deregister_misc(pTAS2560);
418 mutex_destroy(&pTAS2560->file_lock); 419 mutex_destroy(&pTAS2560->file_lock);
419#endif 420#endif
420 421
421 return 0; 422 return 0;
422} 423}
423 424
diff --git a/tas2560.h b/tas2560.h
index feb5b78..2acdd83 100755..100644
--- a/tas2560.h
+++ b/tas2560.h
@@ -3,7 +3,7 @@
3** Copyright (c) 2016 Texas Instruments Inc. 3** Copyright (c) 2016 Texas Instruments Inc.
4** 4**
5** This program is free software; you can redistribute it and/or modify it under 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 6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2. 7** Foundation; version 2.
8** 8**
9** This program is distributed in the hope that it will be useful, but WITHOUT 9** This program is distributed in the hope that it will be useful, but WITHOUT
@@ -146,7 +146,7 @@ enum channel{
146struct tas2560_priv { 146struct tas2560_priv {
147 u8 i2c_regs_status; 147 u8 i2c_regs_status;
148 struct device *dev; 148 struct device *dev;
149 struct i2c_client *client; 149 struct i2c_client *client;
150 struct regmap *regmap; 150 struct regmap *regmap;
151 151
152 unsigned char mnLAddr; 152 unsigned char mnLAddr;
@@ -154,9 +154,9 @@ struct tas2560_priv {
154 int mnLCurrentBook; 154 int mnLCurrentBook;
155 int mnLCurrentPage; 155 int mnLCurrentPage;
156 int mnRCurrentBook; 156 int mnRCurrentBook;
157 int mnRCurrentPage; 157 int mnRCurrentPage;
158 enum channel mnCurrentChannel; 158 enum channel mnCurrentChannel;
159 159
160 struct mutex dev_lock; 160 struct mutex dev_lock;
161 //struct tas2560_dai_cfg dai_cfg[3]; 161 //struct tas2560_dai_cfg dai_cfg[3];
162 int mnClkin; 162 int mnClkin;
@@ -166,32 +166,32 @@ struct tas2560_priv {
166 int mnResetGPIO; 166 int mnResetGPIO;
167 int mnSamplingRate ; 167 int mnSamplingRate ;
168 int mnFrameSize; 168 int mnFrameSize;
169 169
170 int (*read) (struct tas2560_priv * pTAS2555, 170 int (*read) (struct tas2560_priv * pTAS2555,
171 enum channel chn, 171 enum channel chn,
172 unsigned int reg, 172 unsigned int reg,
173 unsigned int *pValue); 173 unsigned int *pValue);
174 int (*write) (struct tas2560_priv * pTAS2555, 174 int (*write) (struct tas2560_priv * pTAS2555,
175 enum channel chn, 175 enum channel chn,
176 unsigned int reg, 176 unsigned int reg,
177 unsigned int Value); 177 unsigned int Value);
178 int (*bulk_read) (struct tas2560_priv * pTAS2555, 178 int (*bulk_read) (struct tas2560_priv * pTAS2555,
179 enum channel chn, 179 enum channel chn,
180 unsigned int reg, 180 unsigned int reg,
181 unsigned char *pData, unsigned int len); 181 unsigned char *pData, unsigned int len);
182 int (*bulk_write) (struct tas2560_priv * pTAS2555, 182 int (*bulk_write) (struct tas2560_priv * pTAS2555,
183 enum channel chn, 183 enum channel chn,
184 unsigned int reg, 184 unsigned int reg,
185 unsigned char *pData, unsigned int len); 185 unsigned char *pData, unsigned int len);
186 int (*update_bits) (struct tas2560_priv * pTAS2555, 186 int (*update_bits) (struct tas2560_priv * pTAS2555,
187 enum channel chn, 187 enum channel chn,
188 unsigned int reg, 188 unsigned int reg,
189 unsigned int mask, unsigned int value); 189 unsigned int mask, unsigned int value);
190 190
191#ifdef CONFIG_TAS2560_MISC_STEREO 191#ifdef CONFIG_TAS2560_MISC_STEREO
192 int mnDBGCmd; 192 int mnDBGCmd;
193 int mnCurrentReg; 193 int mnCurrentReg;
194 struct mutex file_lock; 194 struct mutex file_lock;
195#endif 195#endif
196}; 196};
197#endif 197#endif