/* sound/soc/samsung/s3c24xx_simtec.c * * Copyright 2009 Simtec Electronics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include #include #include #include "s3c24xx-i2s.h" #include "s3c24xx_simtec.h" static struct s3c24xx_audio_simtec_pdata *pdata; static struct clk *xtal_clk; static int spk_gain; static int spk_unmute; /** * speaker_gain_get - read the speaker gain setting. * @kcontrol: The control for the speaker gain. * @ucontrol: The value that needs to be updated. * * Read the value for the AMP gain control. */ static int speaker_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.integer.value[0] = spk_gain; return 0; } /** * speaker_gain_set - set the value of the speaker amp gain * @value: The value to write. */ static void speaker_gain_set(int value) { gpio_set_value_cansleep(pdata->amp_gain[0], value & 1); gpio_set_value_cansleep(pdata->amp_gain[1], value >> 1); } /** * speaker_gain_put - set the speaker gain setting. * @kcontrol: The control for the speaker gain. * @ucontrol: The value that needs to be set. * * Set the value of the speaker gain from the specified * @ucontrol setting. * * Note, if the speaker amp is muted, then we do not set a gain value * as at-least one of the ICs that is fitted will try and power up even * if the main control is set to off. */ static int speaker_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int value = ucontrol->value.integer.value[0]; spk_gain = value; if (!spk_unmute) speaker_gain_set(value); return 0; } static const struct snd_kcontrol_new amp_gain_controls[] = { SOC_SINGLE_EXT("Speaker Gain", 0, 0, 3, 0, speaker_gain_get, speaker_gain_put), }; /** * spk_unmute_state - set the unmute state of the speaker * @to: zero to unmute, non-zero to ununmute. */ static void spk_unmute_state(int to) { pr_debug("%s: to=%d\n", __func__, to); spk_unmute = to; gpio_set_value(pdata->amp_gpio, to); /* if we're umuting, also re-set the gain */ if (to && pdata->amp_gain[0] > 0) speaker_gain_set(spk_gain); } /** * speaker_unmute_get - read the speaker unmute setting. * @kcontrol: The control for the speaker gain. * @ucontrol: The value that needs to be updated. * * Read the value for the AMP gain control. */ static int speaker_unmute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.integer.value[0] = spk_unmute; return 0; } /** * speaker_unmute_put - set the speaker unmute setting. * @kcontrol: The control for the speaker gain. * @ucontrol: The value that needs to be set. * * Set the value of the speaker gain from the specified * @ucontrol setting. */ static int speaker_unmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { spk_unmute_state(ucontrol->value.integer.value[0]); return 0; } /* This is added as a manual control as the speaker amps create clicks * when their power state is changed, which are far more noticeable than * anything produced by the CODEC itself. */ static const struct snd_kcontrol_new amp_unmute_controls[] = { SOC_SINGLE_EXT("Speaker Switch", 0, 0, 1, 0, speaker_unmute_get, speaker_unmute_put), }; void simtec_audio_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_card *card = rtd->card; if (pdata->amp_gpio > 0) { pr_debug("%s: adding amp routes\n", __func__); snd_soc_add_card_controls(card, amp_unmute_controls, ARRAY_SIZE(amp_unmute_controls)); } if (pdata->amp_gain[0] > 0) { pr_debug("%s: adding amp controls\n", __func__); snd_soc_add_card_controls(card, amp_gain_controls, ARRAY_SIZE(amp_gain_controls)); } } EXPORT_SYMBOL_GPL(simtec_audio_init); #define CODEC_CLOCK 12000000 /** * simtec_hw_params - update hardware parameters * @substream: The audio substream instance. * @params: The parameters requested. * * Update the codec data routing and configuration settings * from the supplied data. */ static int simtec_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int ret; ret = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); if (ret) { pr_err( "%s: failed setting codec sysclk\n", __func__); return ret; } if (pdata->use_mpllin) { ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_MPLL, 0, SND_SOC_CLOCK_OUT); if (ret) { pr_err("%s: failed to set MPLLin as clksrc\n", __func__); return ret; } } if (pdata->output_cdclk) { int cdclk_scale; cdclk_scale = clk_get_rate(xtal_clk) / CODEC_CLOCK; cdclk_scale--; ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, cdclk_scale); } return 0; } static int simtec_call_startup(struct s3c24xx_audio_simtec_pdata *pd) { /* call any board supplied startup code, this currently only * covers the bast/vr1000 which have a CPLD in the way of the * LRCLK */ if (pd->startup) pd->startup(); return 0; } static struct snd_soc_ops simtec_snd_ops = { .hw_params = simtec_hw_params, }; /** * attach_gpio_amp - get and configure the necessary gpios * @dev: The device we're probing. * @pd: The platform data supplied by the board. * * If there is a GPIO based amplifier attached to the board, claim * the necessary GPIO lines for it, and set default values. */ static int attach_gpio_amp(struct device *dev, struct s3c24xx_audio_simtec_pdata *pd) { int ret; /* attach gpio amp gain (if any) */ if (pdata->amp_gain[0] > 0) { ret = gpio_request(pd->amp_gain[0], "gpio-amp-gain0"); if (ret) { dev_err(dev, "cannot get amp gpio gain0\n"); return ret; } ret = gpio_request(pd->amp_gain[1], "gpio-amp-gain1"); if (ret) { dev_err(dev, "cannot get amp gpio gain1\n"); gpio_free(pdata->amp_gain[0]); return ret; } gpio_direction_output(pd->amp_gain[0], 0); gpio_direction_output(pd->amp_gain[1], 0); } /* note, currently we assume GPA0 isn't valid amp */ if (pdata->amp_gpio > 0) { ret = gpio_request(pd->amp_gpio, "gpio-amp"); if (ret) { dev_err(dev, "cannot get amp gpio %d (%d)\n", pd->amp_gpio, ret); goto err_amp; } /* set the amp off at startup */ spk_unmute_state(0); } return 0; err_amp: if (pd->amp_gain[0] > 0) { gpio_free(pd->amp_gain[0]); gpio_free(pd->amp_gain[1]); } return ret; } static void detach_gpio_amp(struct s3c24xx_audio_simtec_pdata *pd) { if (pd->amp_gain[0] > 0) { gpio_free(pd->amp_gain[0]); gpio_free(pd->amp_gain[1]); } if (pd->amp_gpio > 0) gpio_free(pd->amp_gpio); } #ifdef CONFIG_PM static int simtec_audio_resume(struct device *dev) { simtec_call_startup(pdata); return 0; } const struct dev_pm_ops simtec_audio_pmops = { .resume = simtec_audio_resume, }; EXPORT_SYMBOL_GPL(simtec_audio_pmops); #endif int simtec_audio_core_probe(struct platform_device *pdev, struct snd_soc_card *card) { struct platform_device *snd_dev; int ret; card->dai_link->ops = &simtec_snd_ops; card->dai_link->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM; pdata = pdev->dev.platform_data; if (!pdata) { dev_err(&pdev->dev, "no platform data supplied\n"); return -EINVAL; } simtec_call_startup(pdata); xtal_clk = clk_get(&pdev->dev, "xtal"); if (IS_ERR(xtal_clk)) { dev_err(&pdev->dev, "could not get clkout0\n"); return -EINVAL; } dev_info(&pdev->dev, "xtal rate is %ld\n", clk_get_rate(xtal_clk)); ret = attach_gpio_amp(&pdev->dev, pdata); if (ret) goto err_clk; snd_dev = platform_device_alloc("soc-audio", -1); if (!snd_dev) { dev_err(&pdev->dev, "failed to alloc soc-audio devicec\n"); ret = -ENOMEM; goto err_gpio; } platform_set_drvdata(snd_dev, card); ret = platform_device_add(snd_dev); if (ret) { dev_err(&pdev->dev, "failed to add soc-audio dev\n"); goto err_pdev; } platform_set_drvdata(pdev, snd_dev); return 0; err_pdev: platform_device_put(snd_dev); err_gpio: detach_gpio_amp(pdata); err_clk: clk_put(xtal_clk); return ret; } EXPORT_SYMBOL_GPL(simtec_audio_core_probe); int simtec_audio_remove(struct platform_device *pdev) { struct platform_device *snd_dev = platform_get_drvdata(pdev); platform_device_unregister(snd_dev); detach_gpio_amp(pdata); clk_put(xtal_clk); return 0; } EXPORT_SYMBOL_GPL(simtec_audio_remove); MODULE_AUTHOR("Ben Dooks "); MODULE_DESCRIPTION("ALSA SoC Simtec Audio common support"); MODULE_LICENSE("GPL"); firmware load for nope-test-firmware.bin failed with error -2 misc test_firmware: Falling back to user helper BUG: unable to handle kernel NULL pointer dereference at 0000000000000038 IP: _request_firmware+0xa27/0xad0 PGD 0 Oops: 0000 [#1] SMP Modules linked in: test_firmware(E) ... etc ... CPU: 1 PID: 1396 Comm: fw_fallback.sh Tainted: G W E 4.10.0-rc3-next-20170111+ #30 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.1-0-g8891697-prebuilt.qemu-project.org 04/01/2014 task: ffff9740b27f4340 task.stack: ffffbb15c0bc8000 RIP: 0010:_request_firmware+0xa27/0xad0 RSP: 0018:ffffbb15c0bcbd10 EFLAGS: 00010246 RAX: 00000000fffffffe RBX: ffff9740afe5aa80 RCX: 0000000000000000 RDX: ffff9740b27f4340 RSI: 0000000000000283 RDI: 0000000000000000 RBP: ffffbb15c0bcbd90 R08: ffffbb15c0bcbcd8 R09: 0000000000000000 R10: 0000000894a0d4b1 R11: 000000000000008c R12: ffffffffc0312480 R13: 0000000000000005 R14: ffff9740b1c32400 R15: 00000000000003e8 FS: 00007f8604422700(0000) GS:ffff9740bfc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000038 CR3: 000000012164c000 CR4: 00000000000006e0 Call Trace: request_firmware+0x37/0x50 trigger_request_store+0x79/0xd0 [test_firmware] dev_attr_store+0x18/0x30 sysfs_kf_write+0x37/0x40 kernfs_fop_write+0x110/0x1a0 __vfs_write+0x37/0x160 ? _cond_resched+0x1a/0x50 vfs_write+0xb5/0x1a0 SyS_write+0x55/0xc0 ? trace_do_page_fault+0x37/0xd0 entry_SYSCALL_64_fastpath+0x1e/0xad RIP: 0033:0x7f8603f49620 RSP: 002b:00007fff6287b788 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 000055c307b110a0 RCX: 00007f8603f49620 RDX: 0000000000000016 RSI: 000055c3084d8a90 RDI: 0000000000000001 RBP: 0000000000000016 R08: 000000000000c0ff R09: 000055c3084d6336 R10: 000055c307b108b0 R11: 0000000000000246 R12: 000055c307b13c80 R13: 000055c3084d6320 R14: 0000000000000000 R15: 00007fff6287b950 Code: 9f 64 84 e8 9c 61 fe ff b8 f4 ff ff ff e9 6b f9 ff ff 48 c7 c7 40 6b 8d 84 89 45 a8 e8 43 84 18 00 49 8b be 00 03 00 00 8b 45 a8 <83> 7f 38 02 74 08 e8 6e ec ff ff 8b 45 a8 49 c7 86 00 03 00 00 RIP: _request_firmware+0xa27/0xad0 RSP: ffffbb15c0bcbd10 CR2: 0000000000000038 ---[ end trace 6d94ac339c133e6f ]--- Fixes: 5d47ec02c37e ("firmware: Correct handling of fw_state_wait() return value") Reported-and-Tested-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reported-and-Tested-by: Patrick Bruenn <p.bruenn@beckhoff.com> Reported-by: Chris Wilson <chris@chris-wilson.co.uk> CC: <stable@vger.kernel.org> [3.10+] Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'sound/pci/oxygen')