aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolin Chen <b42378@freescale.com>2013-06-06 07:38:45 -0400
committerMark Brown <broonie@linaro.org>2013-06-06 09:26:29 -0400
commite75a52c6723a61a0d768ee53794e86b7edbe54f0 (patch)
tree5abad6076e08c9307299183d57de552442204c93
parentd683b96b072dc4680fc74964eca77e6a23d1fa6e (diff)
ASoC: WM8962: Create default platform data structure
Embed a copy of struct wm8962_pdata in stuct wm8962_priv so that there's no need to check validity of pdata any more. Signed-off-by: Nicolin Chen <b42378@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--sound/soc/codecs/wm8962.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index e9710280e5e1..d56dd867057d 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -51,6 +51,7 @@ static const char *wm8962_supply_names[WM8962_NUM_SUPPLIES] = {
51 51
52/* codec private data */ 52/* codec private data */
53struct wm8962_priv { 53struct wm8962_priv {
54 struct wm8962_pdata pdata;
54 struct regmap *regmap; 55 struct regmap *regmap;
55 struct snd_soc_codec *codec; 56 struct snd_soc_codec *codec;
56 57
@@ -2345,12 +2346,13 @@ static const struct snd_soc_dapm_route wm8962_spk_stereo_intercon[] = {
2345 2346
2346static int wm8962_add_widgets(struct snd_soc_codec *codec) 2347static int wm8962_add_widgets(struct snd_soc_codec *codec)
2347{ 2348{
2348 struct wm8962_pdata *pdata = dev_get_platdata(codec->dev); 2349 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
2350 struct wm8962_pdata *pdata = &wm8962->pdata;
2349 struct snd_soc_dapm_context *dapm = &codec->dapm; 2351 struct snd_soc_dapm_context *dapm = &codec->dapm;
2350 2352
2351 snd_soc_add_codec_controls(codec, wm8962_snd_controls, 2353 snd_soc_add_codec_controls(codec, wm8962_snd_controls,
2352 ARRAY_SIZE(wm8962_snd_controls)); 2354 ARRAY_SIZE(wm8962_snd_controls));
2353 if (pdata && pdata->spk_mono) 2355 if (pdata->spk_mono)
2354 snd_soc_add_codec_controls(codec, wm8962_spk_mono_controls, 2356 snd_soc_add_codec_controls(codec, wm8962_spk_mono_controls,
2355 ARRAY_SIZE(wm8962_spk_mono_controls)); 2357 ARRAY_SIZE(wm8962_spk_mono_controls));
2356 else 2358 else
@@ -2360,7 +2362,7 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)
2360 2362
2361 snd_soc_dapm_new_controls(dapm, wm8962_dapm_widgets, 2363 snd_soc_dapm_new_controls(dapm, wm8962_dapm_widgets,
2362 ARRAY_SIZE(wm8962_dapm_widgets)); 2364 ARRAY_SIZE(wm8962_dapm_widgets));
2363 if (pdata && pdata->spk_mono) 2365 if (pdata->spk_mono)
2364 snd_soc_dapm_new_controls(dapm, wm8962_dapm_spk_mono_widgets, 2366 snd_soc_dapm_new_controls(dapm, wm8962_dapm_spk_mono_widgets,
2365 ARRAY_SIZE(wm8962_dapm_spk_mono_widgets)); 2367 ARRAY_SIZE(wm8962_dapm_spk_mono_widgets));
2366 else 2368 else
@@ -2369,7 +2371,7 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)
2369 2371
2370 snd_soc_dapm_add_routes(dapm, wm8962_intercon, 2372 snd_soc_dapm_add_routes(dapm, wm8962_intercon,
2371 ARRAY_SIZE(wm8962_intercon)); 2373 ARRAY_SIZE(wm8962_intercon));
2372 if (pdata && pdata->spk_mono) 2374 if (pdata->spk_mono)
2373 snd_soc_dapm_add_routes(dapm, wm8962_spk_mono_intercon, 2375 snd_soc_dapm_add_routes(dapm, wm8962_spk_mono_intercon,
2374 ARRAY_SIZE(wm8962_spk_mono_intercon)); 2376 ARRAY_SIZE(wm8962_spk_mono_intercon));
2375 else 2377 else
@@ -3333,14 +3335,14 @@ static struct gpio_chip wm8962_template_chip = {
3333static void wm8962_init_gpio(struct snd_soc_codec *codec) 3335static void wm8962_init_gpio(struct snd_soc_codec *codec)
3334{ 3336{
3335 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3337 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3336 struct wm8962_pdata *pdata = dev_get_platdata(codec->dev); 3338 struct wm8962_pdata *pdata = &wm8962->pdata;
3337 int ret; 3339 int ret;
3338 3340
3339 wm8962->gpio_chip = wm8962_template_chip; 3341 wm8962->gpio_chip = wm8962_template_chip;
3340 wm8962->gpio_chip.ngpio = WM8962_MAX_GPIO; 3342 wm8962->gpio_chip.ngpio = WM8962_MAX_GPIO;
3341 wm8962->gpio_chip.dev = codec->dev; 3343 wm8962->gpio_chip.dev = codec->dev;
3342 3344
3343 if (pdata && pdata->gpio_base) 3345 if (pdata->gpio_base)
3344 wm8962->gpio_chip.base = pdata->gpio_base; 3346 wm8962->gpio_chip.base = pdata->gpio_base;
3345 else 3347 else
3346 wm8962->gpio_chip.base = -1; 3348 wm8962->gpio_chip.base = -1;
@@ -3373,7 +3375,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3373{ 3375{
3374 int ret; 3376 int ret;
3375 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3377 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3376 struct wm8962_pdata *pdata = dev_get_platdata(codec->dev); 3378 struct wm8962_pdata *pdata = &wm8962->pdata;
3377 u16 *reg_cache = codec->reg_cache; 3379 u16 *reg_cache = codec->reg_cache;
3378 int i, trigger, irq_pol; 3380 int i, trigger, irq_pol;
3379 bool dmicclk, dmicdat; 3381 bool dmicclk, dmicdat;
@@ -3421,30 +3423,28 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3421 WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA, 3423 WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA,
3422 0); 3424 0);
3423 3425
3424 if (pdata) { 3426 /* Apply static configuration for GPIOs */
3425 /* Apply static configuration for GPIOs */ 3427 for (i = 0; i < ARRAY_SIZE(pdata->gpio_init); i++)
3426 for (i = 0; i < ARRAY_SIZE(pdata->gpio_init); i++) 3428 if (pdata->gpio_init[i]) {
3427 if (pdata->gpio_init[i]) { 3429 wm8962_set_gpio_mode(codec, i + 1);
3428 wm8962_set_gpio_mode(codec, i + 1); 3430 snd_soc_write(codec, 0x200 + i,
3429 snd_soc_write(codec, 0x200 + i, 3431 pdata->gpio_init[i] & 0xffff);
3430 pdata->gpio_init[i] & 0xffff); 3432 }
3431 }
3432 3433
3433 /* Put the speakers into mono mode? */ 3434 /* Put the speakers into mono mode? */
3434 if (pdata->spk_mono) 3435 if (pdata->spk_mono)
3435 reg_cache[WM8962_CLASS_D_CONTROL_2] 3436 reg_cache[WM8962_CLASS_D_CONTROL_2]
3436 |= WM8962_SPK_MONO; 3437 |= WM8962_SPK_MONO;
3437 3438
3438 /* Micbias setup, detection enable and detection 3439 /* Micbias setup, detection enable and detection
3439 * threasholds. */ 3440 * threasholds. */
3440 if (pdata->mic_cfg) 3441 if (pdata->mic_cfg)
3441 snd_soc_update_bits(codec, WM8962_ADDITIONAL_CONTROL_4, 3442 snd_soc_update_bits(codec, WM8962_ADDITIONAL_CONTROL_4,
3442 WM8962_MICDET_ENA | 3443 WM8962_MICDET_ENA |
3443 WM8962_MICDET_THR_MASK | 3444 WM8962_MICDET_THR_MASK |
3444 WM8962_MICSHORT_THR_MASK | 3445 WM8962_MICSHORT_THR_MASK |
3445 WM8962_MICBIAS_LVL, 3446 WM8962_MICBIAS_LVL,
3446 pdata->mic_cfg); 3447 pdata->mic_cfg);
3447 }
3448 3448
3449 /* Latch volume update bits */ 3449 /* Latch volume update bits */
3450 snd_soc_update_bits(codec, WM8962_LEFT_INPUT_VOLUME, 3450 snd_soc_update_bits(codec, WM8962_LEFT_INPUT_VOLUME,
@@ -3506,7 +3506,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3506 wm8962_init_gpio(codec); 3506 wm8962_init_gpio(codec);
3507 3507
3508 if (wm8962->irq) { 3508 if (wm8962->irq) {
3509 if (pdata && pdata->irq_active_low) { 3509 if (pdata->irq_active_low) {
3510 trigger = IRQF_TRIGGER_LOW; 3510 trigger = IRQF_TRIGGER_LOW;
3511 irq_pol = WM8962_IRQ_POL; 3511 irq_pol = WM8962_IRQ_POL;
3512 } else { 3512 } else {
@@ -3603,6 +3603,10 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3603 init_completion(&wm8962->fll_lock); 3603 init_completion(&wm8962->fll_lock);
3604 wm8962->irq = i2c->irq; 3604 wm8962->irq = i2c->irq;
3605 3605
3606 /* If platform data was supplied, update the default data in priv */
3607 if (pdata)
3608 memcpy(&wm8962->pdata, pdata, sizeof(struct wm8962_pdata));
3609
3606 for (i = 0; i < ARRAY_SIZE(wm8962->supplies); i++) 3610 for (i = 0; i < ARRAY_SIZE(wm8962->supplies); i++)
3607 wm8962->supplies[i].supply = wm8962_supply_names[i]; 3611 wm8962->supplies[i].supply = wm8962_supply_names[i];
3608 3612
@@ -3666,7 +3670,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3666 goto err_enable; 3670 goto err_enable;
3667 } 3671 }
3668 3672
3669 if (pdata && pdata->in4_dc_measure) { 3673 if (wm8962->pdata.in4_dc_measure) {
3670 ret = regmap_register_patch(wm8962->regmap, 3674 ret = regmap_register_patch(wm8962->regmap,
3671 wm8962_dc_measure, 3675 wm8962_dc_measure,
3672 ARRAY_SIZE(wm8962_dc_measure)); 3676 ARRAY_SIZE(wm8962_dc_measure));