History log of /linux-master/sound/soc/codecs/rt5640.c
Revision Date Author Comments
# 6413849b 21-Feb-2024 Cezary Rojewski <cezary.rojewski@intel.com>

ASoC: codecs: rt5640: Simplify mclk initialization

Most of clk_xxx() functions do check if provided clk-pointer is
non-NULL. These do not check if the pointer is an error-pointer.
Providing such to a clk_xxx() results in a panic.

rt5640_set_dai_sysclk() is an example of that - clk_set_rate() is not
guarded by IS_ERR().

By utilizing _optional() variant of devm_clk_get() the driver code is
both simplified and more robust. There is no need to remember about
IS_ERR(clk) checks each time mclk is accessed.

Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://msgid.link/r/20240221152516.852353-6-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8fc7cc50 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Only cancel jack-detect work on suspend if active

If jack-detection is not used; or has already been disabled then
there is no need to call rt5640_cancel_work().

Move the rt5640_cancel_work() inside the "if (rt5640->jack) {}" block,
grouping it together with the disabling of the IRQ which queues the work
in the first place.

This also makes suspend() symetrical with resume() which re-queues the work
in an "if (rt5640->jack) {}" block.

Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-7-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8c8bf3df 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Fix IRQ not being free-ed for HDA jack detect mode

Set "rt5640->irq_requested = true" after a successful request_irq()
in rt5640_enable_hda_jack_detect(), so that rt5640_disable_jack_detect()
properly frees the IRQ.

This fixes the IRQ not being freed on rmmod / driver unbind.

Fixes: 2b9c8d2b3c89 ("ASoC: rt5640: Add the HDA header support")
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-6-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# b5e85e53 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Enable the IRQ on resume after configuring jack-detect

The jack-detect IRQ should be enabled *after* the jack-detect related
configuration registers have been programmed.

Move the enable_irq() call for this to after the register setup.

Fixes: 5fabcc90e79b ("ASoC: rt5640: Fix Jack work after system suspend")
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-5-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 786120eb 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Do not disable/enable IRQ twice on suspend/resume

When jack-detect was originally added disabling the IRQ during suspend
was done by the sound/soc/intel/boards/bytcr_rt5640.c driver
calling snd_soc_component_set_jack(NULL) on suspend, which calls
rt5640_disable_jack_detect(), which calls free_irq() which also
disables it.

Commit 5fabcc90e79b ("ASoC: rt5640: Fix Jack work after system suspend")
added disable_irq() / enable_irq() calls on suspend/resume for machine
drivers which do not call snd_soc_component_set_jack(NULL) on suspend.

The new disable_irq() / enable_irq() are made conditional by
"if (rt5640->irq)" statements, but this is true for the machine drivers
which do call snd_soc_component_set_jack(NULL) on suspend too, causing
a disable_irq() call there on the already free-ed IRQ.

Change the "if (rt5640->irq)" condition to "if (rt5640->jack)" to fix this,
rt5640->jack is only set if the jack-detect IRQ handler is still active
when rt5640_suspend() runs.

And adjust rt5640_enable_hda_jack_detect()'s request_irq() error handling
to set rt5640->jack to NULL to match (note that the old setting of irq to
-ENOXIO still resulted in disable_irq(-ENOXIO) calls on suspend).

Fixes: 5fabcc90e79b ("ASoC: rt5640: Fix Jack work after system suspend")
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-4-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# df7d595f 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Fix sleep in atomic context

Following prints are observed while testing audio on Jetson AGX Orin which
has onboard RT5640 audio codec:

BUG: sleeping function called from invalid context at kernel/workqueue.c:3027
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/0
preempt_count: 10001, expected: 0
RCU nest depth: 0, expected: 0
------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at kernel/irq/handle.c:159 __handle_irq_event_percpu+0x1e0/0x270
---[ end trace ad1c64905aac14a6 ]-

The IRQ handler rt5640_irq() runs in interrupt context and can sleep
during cancel_delayed_work_sync().

The only thing which rt5640_irq() does is cancel + (re-)queue
the jack_work delayed_work. This can be done in a single non sleeping
call by replacing queue_delayed_work() with mod_delayed_work(),
avoiding the sleep in atomic context.

Fixes: 051dade34695 ("ASoC: rt5640: Fix the wrong state of JD1 and JD2")
Reported-by: Sameer Pujar <spujar@nvidia.com>
Closes: https://lore.kernel.org/r/1688015537-31682-4-git-send-email-spujar@nvidia.com
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-3-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# fa6a0c0c 12-Sep-2023 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Revert "Fix sleep in atomic context"

Commit 70a6404ff610 ("ASoC: rt5640: Fix sleep in atomic context")
not only switched from request_irq() to request_threaded_irq(),
to fix the sleep in atomic context issue, but it also added
devm management of the IRQ by actually switching to
devm_request_threaded_irq() (without any explanation in the commit
message for this change).

This is wrong since the IRQ was already explicitly managed by
the driver. On unbind the ASoC core will call rt5640_set_jack(NULL)
which in turn will call rt5640_disable_jack_detect() which
frees the IRQ already. So now we have a double free.

Besides the unexplained switch to devm being wrong, the actual fix
for the sleep in atomic context issue also is not the best solution.

The only thing which rt5640_irq() does is cancel + (re-)queue
the jack_work delayed_work. This can be done in a single non sleeping
call by replacing queue_delayed_work() with mod_delayed_work(),
which does not sleep. Using mod_delayed_work() is a much better fix
then adding a thread which does nothing other then queuing a work-item.

This patch is a straight revert of the troublesome changes, the switch
to mod_delayed_work() is done in a separate follow-up patch.

Fixes: 70a6404ff610 ("ASoC: rt5640: Fix sleep in atomic context")
Cc: Sameer Pujar <spujar@nvidia.com>
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230912113245.320159-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8e665715 19-Aug-2023 Senhong Liu <liusenhong2022@email.szu.edu.cn>

ASoC: rt5640: fix typos

I noticed typos and i fixed them.

Signed-off-by: Senhong Liu <liusenhong2022@email.szu.edu.cn>
Link: https://lore.kernel.org/r/20230819133345.39961-1-liusenhong2022@email.szu.edu.cn
Signed-off-by: Mark Brown <broonie@kernel.org>


# a9b5f210 17-Aug-2023 Linus Walleij <linus.walleij@linaro.org>

ASoC: rt5640: Convert to just use GPIO descriptors

The RT5640 driver is already using GPIO descriptors for some
stuff, all that is needed is to convert the remaining LDO1
control line to also use descriptors.

Simplify the code using gpiod_get_optional() and drop the
special "of" parsing function: these descriptors need not
come from device tree and it's optional so hey.

Keep some NULL checks around the GPIO operations even though
gpiolib is essentially NULL-tolerant, because by checking
for whether we have a valid GPIO descriptor or not we can
avoid a 400 ms delay which is great.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20230817-descriptors-asoc-rt-v2-1-02fa2ca3e5b0@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>


# cc8ff2df 12-Jul-2023 Derek Fang <derek.fang@realtek.com>

ASoC: rt5640: Fix the issue of speaker noise

Remove the class-D internal register setting during initialization
to be compatible with most speaker designs to avoid noise.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
Link: https://lore.kernel.org/r/20230712062553.31066-1-derek.fang@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 70a6404f 28-Jun-2023 Sameer Pujar <spujar@nvidia.com>

ASoC: rt5640: Fix sleep in atomic context

Following prints are observed while testing audio on Jetson AGX Orin which
has onboard RT5640 audio codec:

BUG: sleeping function called from invalid context at kernel/workqueue.c:3027
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/0
preempt_count: 10001, expected: 0
RCU nest depth: 0, expected: 0
------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at kernel/irq/handle.c:159 __handle_irq_event_percpu+0x1e0/0x270
---[ end trace ad1c64905aac14a6 ]-

The IRQ handler rt5640_irq() runs in interrupt context and can sleep
during cancel_delayed_work_sync().

Fix this by running IRQ handler, rt5640_irq(), in thread context.
Hence replace request_irq() calls with devm_request_threaded_irq().

Fixes: 051dade34695 ("ASoC: rt5640: Fix the wrong state of JD1 and JD2")
Cc: stable@vger.kernel.org
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/1688015537-31682-4-git-send-email-spujar@nvidia.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 1ba8448b 10-Jun-2023 Mark Brown <broonie@kernel.org>

ASoC: rt5640: Use maple tree register cache

The rt5640 can only support single register read and write operations
so does not benefit from block writes. This means it gets no benefit from
using the rbtree register cache over the maple tree register cache so
convert it to use maple trees instead, it is more modern.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230609-asoc-rt-maple-v1-8-729c6553cdcf@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>


# 9abcd240 25-Apr-2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

ASoC: Switch i2c drivers back to use .probe()

After commit b8a1a4cd5a98 ("i2c: Provide a temporary .probe_new()
call-back type"), all drivers being converted to .probe_new() and then
03c835f498b5 ("i2c: Switch .probe() to not take an id parameter") convert
back to (the new) .probe() to be able to eventually drop .probe_new() from
struct i2c_driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de
Link: https://lore.kernel.org/r/20230425095716.331419-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org


# 9f138bb2 09-Feb-2023 Sameer Pujar <spujar@nvidia.com>

ASoC: rt5640: Update MCLK rate in set_sysclk()

Simple-card/audio-graph-card drivers do not handle MCLK clock when it
is specified in the codec device node. The expectation here is that,
the codec should actually own up the MCLK clock and do necessary setup
in the driver.

This is inspired from,
commit dbf54a953435 ("ASoC: rt5659: Update MCLK rate in set_sysclk()").

Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/1675953417-8686-2-git-send-email-spujar@nvidia.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 44b54f54 09-Dec-2022 Ondrej Jirman <megi@xff.cz>

ASoC: rt5640: Allow configuration of LOUT to mono differential mode

LOUT output can produce either single-ended stereo signals, or mono
differential signal. Some applications are wired to use LOUT in mono
differential mode. Allow to configure it via device property.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
Signed-off-by: Jarrah Gosbell <kernel@undef.tools>
Link: https://lore.kernel.org/r/20221209105621.39237-1-kernel@undef.tools
Signed-off-by: Mark Brown <broonie@kernel.org>


# 5fabcc90 28-Nov-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fix Jack work after system suspend

We found an corner case in RT5640 codec driver which schedules jack work
after system suspend as IRQ was enabled. Due to this, hitting the error
as register access happening after suspend as jack worker thread getting
scheduled in irq handler. The patch disables the irq during the suspend
to prevent the corner case happening.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Mohan Kumar D <mkumard@nvidia.com>
Link: https://lore.kernel.org/r/20221128070825.91215-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# b2ddf399 12-Sep-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fix the issue of the abnormal JD2 status

The patch fixes the issue of the abnormal JD2 status.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/20220912072931.1856-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# afb176d4 07-Aug-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fix the JD voltage dropping issue

The patch fixes the JD voltage dropping issue in the HDA JD using.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Mohan Kumar D <mkumard@nvidia.com>
Link: https://lore.kernel.org/r/20220808052836.25791-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8dbefb20 05-Jul-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the MICBIAS1 to the dapm routing

The patch adds the MICBIAS1 to the dapm routing while the HDA header used.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/20220705101134.16792-2-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# a524837d 23-Jun-2022 Charles Keepax <ckeepax@opensource.cirrus.com>

ASoC: rt*: Remove now redundant non_legacy_dai_naming flag

The ASoC core has now been changed to default to the non-legacy DAI
naming, as such drivers using the new scheme no longer need to specify
the non_legacy_dai_naming flag.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220623125250.2355471-57-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 051dade3 05-Jul-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fix the wrong state of JD1 and JD2

The patch fixes the wrong state of JD1 and JD2 while the bst1 or bst2 is
power on in the HDA JD using.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/20220705101134.16792-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 83229680 16-May-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Do not manipulate pin "Platform Clock" if the "Platform Clock" is not in the DAPM

The pin "Platform Clock" was only used by the Intel Byt CR platform. In the
others, the error log will be informed. The patch will set the flag to
avoid the pin "Platform Clock" manipulated by the other platforms.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Reported-by: Sameer Pujar <spujar@nvidia.com>
Link: https://lore.kernel.org/r/20220516103055.20003-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 35b88858 05-Apr-2022 Stephen Kitt <steve@sk2.org>

ASoC: rt*: use simple i2c probe function

The i2c probe functions here don't use the id information provided in
their second argument, so the single-parameter i2c probe function
("probe_new") can be used instead.

This avoids scanning the identifier tables during probes.

Signed-off-by: Stephen Kitt <steve@sk2.org>
Link: https://lore.kernel.org/r/20220405130326.2107293-1-steve@sk2.org
Signed-off-by: Mark Brown <broonie@kernel.org>


# d9c5996a 10-Feb-2022 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Remove the sysclk and sysclk_src checking

Remove the sysclk and sysclk_src checking in the function set_sysclk() to
prevent the PLL power off. It is not getting re-programmed during
subsequent runs after the first run (in BIAS_OFF stage).

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Link: https://lore.kernel.org/r/20220210071900.17287-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 701d636a 05-Jan-2022 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Add support for boards with an external jack-detect GPIO

Some boards have the codec IRQ hooked-up as normally, so the driver can
still do things like headset vs headphones and button-press detection,
but instead of using one of the JD pins of the codec, an external GPIO
is used to report the jack-presence switch status of the jack.

Add support for this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220106110128.66049-5-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# b35a9ab4 05-Jan-2022 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Allow snd_soc_component_set_jack() to override the codec IRQ

On some boards where the firmware/fwnode information is in essence
read-only (x86 + ACPI boards) the i2c_client for the codec may contain
the wrong IRQ or no IRQ at all.

Since we only request the IRQ once snd_soc_component_set_jack() gets
called, allow machine drivers to override the IRQ with the proper one
through the data parameter to snd_soc_component_set_jack().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220106110128.66049-4-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# a3b1aaf7 05-Jan-2022 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Change jack_work to a delayed_work

Change jack_work from a struct work_struct to a struct delayed_work, this
is a preparation patch for adding support for boards where an external
GPIO is used for jack-detect, rather then one of the JD pins of the codec.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220106110128.66049-3-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# a2d6d84d 05-Jan-2022 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Fix possible NULL pointer deref on resume

Commit 2b9c8d2b3c89 ("ASoC: rt5640: Add the HDA header support") adds
re-queuing of the jack_work on resume when rt5640->jd_src != 0.

But the jack_work will unconditionally deref rt5640->jack and that might
be NULL. E.g. the sound/soc/intel/boards/bytcr_rt5640.c machine driver
call snd_soc_component_set_jack(codec, NULL, NULL) from pre_suspend to
disable the IRQ to avoid spurious wakeups, so when rt5640_resume()
runs rt5640->jack will be NULL in this case.

Make the queueing of the work conditional on rt5640->jack instead of
on rt5640->jd_src to fix this.

Fixes: 2b9c8d2b3c89 ("ASoC: rt5640: Add the HDA header support")
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220106110128.66049-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# e3dd4424 01-Dec-2021 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fix the wrong state of the JD in the HDA header

The patch fixes the wrong state of the JD with 1M pull up resistor in the
HDA header.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Link: https://lore.kernel.org/r/20211201095629.21818-1-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 2b9c8d2b 24-Nov-2021 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the HDA header support

The patch adds the HDA header support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Link: https://lore.kernel.org/r/20211125055812.8911-2-oder_chiou@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# a4db95b2 24-Sep-2021 Colin Ian King <colin.king@canonical.com>

ASoC: codecs: Fix spelling mistake "Unsupport" -> "Unsupported"

There are spelling mistakes in dev_err error messages. Fix them.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20210924231003.144502-1-colin.king@canonical.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# e3f2a660 19-Aug-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Add rt5640_set_ovcd_params() helper

Some devices don't use the builtin jack-detect but can still benefit
from the mic-bias-current over-current-detection to differentiate
between headphones vs a headset.

Move the ovcd init code from rt5640_enable_jack_detect() into a new
rt5640_set_ovcd_params() helper and export this helper as well
as a couple of related ovcd functions.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210819190543.784415-5-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# d21213b4 19-Aug-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Add optional hp_det_gpio parameter to rt5640_detect_headset()

Some devices don't use the builtin jack-detect but can still benefit
from the mic-bias-current over-current-detection headphones vs
headset detection done by rt5640_detect_headset().

In this case the jack-inserted check done by rt5640_detect_headset()
needs to be done through a GPIO rather then by using the codec's
builtin jack-detect. Add an optional hp_det_gpio parameter and export
rt5640_detect_headset() for use on machines where jack-detect is
handled outside of the codec.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210819190543.784415-4-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 15d54840 19-Aug-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Delay requesting IRQ until the machine-drv calls set_jack

Delay requesting the IRQ until the machine-drv calls set_jack.

The main reason for this is that the codec's IRQ is unused on some boards,
in which case we really should not call request_irq at all.

On some boards there is an IRQ listed at index 0 for the codec, but
this is not connected to the codec, but rather is directly connected
to the jack's jack-detect pin. These special setups will be handled
by the machine-driver, but the machine driver can only request the IRQ
if it is not first requested by the codec driver. Moving the request_irq
to the set_jack callback (which will not get called in this case) avoids
the codec-driver clobbering the IRQ.

Moving the request_irq also removes the need to disable the IRQ immediately
after requesting it, avoiding a small race (this could also have been fixed
by using the new IRQF_NO_AUTOEN flag when requesting the IRQ).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210819190543.784415-3-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 5caab9f4 19-Aug-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Move rt5640_disable_jack_detect() up in the rt5640.c file

Move rt5640_disable_jack_detect() to above rt5640_enable_jack_detect().
This is a preparation patch for reworking how the IRQ gets requested.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210819190543.784415-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 585fb31c 02-Aug-2021 Dmitry Osipenko <digetx@gmail.com>

ASoC: rt5640: Silence warning message about missing interrupt

Interrupt is optional for the RT5640 codec. Nexus 7 doesn't use interrupt,
this results in a noisy warning message that looks like a error condition.
Make interrupt explicitly optional to silence the message, use modern
IRQF_NO_AUTOEN flag and correct the reg[q]uest typo in the message.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Link: https://lore.kernel.org/r/20210802185258.1881-1-digetx@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 40e40469 07-Mar-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Rename 'Mono DAC Playback Volume' to 'DAC2 Playback Volume'

Rename 'Mono DAC Playback Volume' to 'DAC2 Playback Volume' and move it
from rt5640_specific_snd_controls[] to rt5640_snd_controls[].

The RT5640_DAC2_DIG_VOL register controlled by this mixer-element has
nothing to do with the Mono (Amplified) output which is only available
on the ALC5640 chip and not on the ALC5642 chip.

The RT5640_DAC2_DIG_VOL volume-control is the main volume control for
audio coming from the I2S2 / AIF2 input of the chip and as such is also
available on the ALC5642.

This commit results in the following userspace visible changes:

1. On devices with an ACL5640 codec, the 'Mono DAC Playback Volume'
control is renamed to 'DAC2 Playback Volume' allowing the alsa-lib
mixer code to properly group it with the 'DAC2 Playback Switch' which
is controlling the mute bits in the RT5640_DAC2_DIG_VOL register.

Note the removal of the 'Mono DAC Playback Volume' is not an issue for
userspace because the UCM profiles do not use it (the UCM profiles are
shared betweent the 5640 and 5642 and only the 5640 had this control).

2. On devices with an ACL5642 codec, there now will be a new
'DAC2 Playback Volume', grouped with the 'DAC2 Playback Switch'

Having a complete 'DAC2 Playback Volume' / 'DAC2 Playback Switch' pair
on both variants will allow enabling hardware-volume control by
setting the UCM PlaybackMasterElem to "DAC2" on devices where the
I2S2/AIF2 interface of the codec is used.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210307150503.34906-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 4fbd2978 02-Mar-2021 Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

ASoC: rt5640: clarify expression

cppcheck warning:

sound/soc/codecs/rt5640.c:1923:61: style: Boolean result is used in
bitwise operation. Clarify expression with
parentheses. [clarifyCondition]
(pll_code.m_bp ? 0 : pll_code.m_code) << RT5640_PLL_M_SFT |
^

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210302212527.55158-9-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 24a7b77d 26-Feb-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Fix dac- and adc- vol-tlv values being off by a factor of 10

The adc_vol_tlv volume-control has a range from -17.625 dB to +30 dB,
not -176.25 dB to + 300 dB. This wrong scale is esp. a problem in userspace
apps which translate the dB scale to a linear scale. With the logarithmic
dB scale being of by a factor of 10 we loose all precision in the lower
area of the range when apps translate things to a linear scale.

E.g. the 0 dB default, which corresponds with a value of 47 of the
0 - 127 range for the control, would be shown as 0/100 in alsa-mixer.

Since the centi-dB values used in the TLV struct cannot represent the
0.375 dB step size used by these controls, change the TLV definition
for them to specify a min and max value instead of min + stepsize.

Note this mirrors commit 3f31f7d9b540 ("ASoC: rt5670: Fix dac- and adc-
vol-tlv values being off by a factor of 10") which made the exact same
change to the rt5670 codec driver.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210226143817.84287-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# cfa26ed1 26-Feb-2021 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Fix dac- and adc- vol-tlv values being off by a factor of 10

The adc_vol_tlv volume-control has a range from -17.625 dB to +30 dB,
not -176.25 dB to + 300 dB. This wrong scale is esp. a problem in userspace
apps which translate the dB scale to a linear scale. With the logarithmic
dB scale being of by a factor of 10 we loose all precision in the lower
area of the range when apps translate things to a linear scale.

E.g. the 0 dB default, which corresponds with a value of 47 of the
0 - 127 range for the control, would be shown as 0/100 in alsa-mixer.

Since the centi-dB values used in the TLV struct cannot represent the
0.375 dB step size used by these controls, change the TLV definition
for them to specify a min and max value instead of min + stepsize.

Note this mirrors commit 3f31f7d9b540 ("ASoC: rt5670: Fix dac- and adc-
vol-tlv values being off by a factor of 10") which made the exact same
change to the rt5670 codec driver.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210226143817.84287-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 3e146b55 08-Jul-2020 Gustavo A. R. Silva <gustavoars@kernel.org>

ASoC: codecs: Use fallthrough pseudo-keyword

Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20200709010359.GA18971@embeddedor
Signed-off-by: Mark Brown <broonie@kernel.org>


# 467a2553 15-Jun-2020 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

ASoC: codecs: rt*: rename to snd_soc_component_read()

We need to use snd_soc_component_read()
instead of snd_soc_component_read32()

This patch renames _read32() to _read()

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87d05z4mce.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 89b71b3f 05-Jan-2020 Dmitry Osipenko <digetx@gmail.com>

ASoC: rt5640: Fix NULL dereference on module unload

The rt5640->jack is NULL if jack is already disabled at the time of
driver's module unloading.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Link: https://lore.kernel.org/r/20200106014707.11378-1-digetx@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# d2912cb1 04-Jun-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500

Based on 2 normalized pattern(s):

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

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 #

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-only

has been chosen to replace the boilerplate/reference in 4122 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Enrico Weigelt <info@metux.net>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# e0a99927 04-Jan-2019 Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

ASoC: rt5640: fix boolean assignments

Reported by Coccinelle:
sound/soc/codecs/rt5640.c:980:2-17: WARNING: Assignment of bool to 0/1
sound/soc/codecs/rt5640.c:984:2-17: WARNING: Assignment of bool to 0/1
sound/soc/codecs/rt5640.c:2825:1-16: WARNING: Assignment of bool to 0/1

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 1c96a2f6 01-Sep-2018 David Frey <dpfrey@gmail.com>

regmap: split up regmap_config.use_single_rw

Split regmap_config.use_single_rw into use_single_read and
use_single_write. This change enables drivers of devices which only
support bulk operations in one direction to use the regmap_bulk_*()
functions for both directions and have their bulk operation split into
single operations only when necessary.

Update all struct regmap_config instances where use_single_rw==true to
instead set both use_single_read and use_single_write. No attempt was
made to evaluate whether it is possible to set only one of
use_single_read or use_single_write.

Signed-off-by: David Frey <dpfrey@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 065dcc27 01-Aug-2018 Gustavo A. R. Silva <gustavo@embeddedor.com>

ASoC: rt5640: Mark expected switch fall-through

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Addresses-Coverity-ID: 1056547 ("Missing break in switch")
Addresses-Coverity-ID: 1056548 ("Missing break in switch")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# b16188a2 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Add button press support

Enable button press detection for headsets by using the ovcd IRQ to get
notified of button presses.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8210804b 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Add jack-detect support

Add jack-detect support, loosely based on earlier work on this by:

Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Francisco mendez <francisco.mendez@intel.com>

Note getting the OVCD to work reliable was sort of finicky, so there are
quite a few comments on this to hopefully avoid people breaking it in the
future.

This (and the follow-up button press support) has been tested on the
following devices:

Acer Iconia Tab 8 W1-810
Asus T100CHI
Asus T100TA
Asus T200TA
Axxo WT1011
Chuwi Vi8
Dell Venue 8 Pro 5830
HP Pavilion X2 10-n000nd
HP Stream 7
I.T. Works TW891
Lamina I8270
MSI S100
Peaq C1010
Pipo W4
PoV MobiiTAB-P800W (v2.0)
Toshiba Click Mini L9W-B

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=196377
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# fb509fa9 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Allow specifying dmic data pins through device-properties

Allow specifying dmic data pins through device-properties / dt. This will
allow us to stop exporting rt5640_dmic_enable() once all callers of it have
been converted to setting device-properties for this instead.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 988a5e01 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Move checking of device-properties to component probe callback

On some platforms the platform code may need to add device-properties,
rather then relying only on properties set by the firmware.

This commit moves the parsing of the device-properties from the i2c-driver
probe() function, which may be called at any time, to the component-driver
probe() function, which gets called after the platform code calls
snd_soc_register_card().

This allows the platform code to attach extra device-properties before
the device-properties are parsed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8e3ebf5e 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Remove unused rt5640_platform_data

There are no in tree users of platform-data for the rt5640 codec driver,
so lets remove support for it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8e7a1f1f 08-May-2018 Hans de Goede <hdegoede@redhat.com>

ASoC: rt5640: Remove is_sys_clk_from_pll, it has ordering issues

is_sys_clk_from_pll() is used as a snd_soc_dapm_route.connected callback,
checking RT5640_GBL_CLK to determine if the sys-clk is PLL1 and thus the
PWR_PLL bit in reg PWR_ANLG2 must be set.

RT5640_GBL_CLK is changed by rt5640_set_dai_sysclk(), which gets called by
the pre_pmu / post_pmd functions of the "Platform Clock" dapm-supply.

This creates an ordering issue, during a dapm transition first all
connected() callbacks are called to build a list of supplies to enable
and then the complete list is walked to enable the supplies. Since the
connected() check happens before enabling any supplies,
is_sys_clk_from_pll() ends up deciding if the PWR_PLL bit should be set
based on the state the "Platform Clock" supply had *before* the transition.
This sometimes results in PWR_PLL being off, even though *after* the
transition PLL1 is configured as sys-clk.

This commit removes is_sys_clk_from_pll() instead simply setting / clearing
PWR_PLL in rt5640_set_dai_sysclk() based on the selected sys-clk, which
fixes this and as a bonus results in a nice cleanup.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# d5a41b5d 28-Jan-2018 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

ASoC: rt5640: replace codec to component

Now we can replace Codec to Component. Let's do it.

Note:
xxx_codec_xxx() -> xxx_component_xxx()
.idle_bias_off = 1 -> .idle_bias_on = 0
.ignore_pmdown_time = 0 -> .use_pmdown_time = 1
- -> .endianness = 1
- -> .non_legacy_dai_naming = 1

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# a180ba45 03-Aug-2017 Bhumika Goyal <bhumirks@gmail.com>

ASoC: codecs: add const to snd_soc_codec_driver structures

Declare snd_soc_codec_driver structures as const as they are only passed
as an argument to the function snd_soc_register_codec. This argument is
of type const, so declare the structures with this property as const.
In file codecs/sn95031.c, snd_soc_codec_driver structure is also used in
a copy operation along with getting passed to snd_soc_register_codec.
So, it can be made const too.
Done using Coccinelle:

@match disable optional_qualifier@
identifier s;
position p;
@@
static struct snd_soc_codec_driver s@p={...};

@good1@
identifier match.s;
position p;
@@
snd_soc_register_codec(...,&s@p,...)

@bad@
identifier match.s;
position p!={match.p,good1.p};
@@
s@p

@depends on !bad disable optional_qualifier@
identifier match.s;
@@
static
+const
struct snd_soc_codec_driver s={...};

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 03200140 26-Jan-2017 Alexandrov Stansilav <neko@nya.ai>

ASoC: rt5640: Add "10EC3276" ACPI ID

Add ACPI ID "10EC3276" for sound card found on notebook HP Pavilion X2 10-p000.
ACPI DSDT Table on this device describes this card as ALC3276, but it is in fact rt5640.

Signed-off-by: Alexandrov Stansilav <neko@nya.ai>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 4a312c9c 12-Jan-2017 Nicholas Mc Guire <hofrat@osadl.org>

ASoC: rt5640: use msleep() for long delays

ulseep_range() uses hrtimers and provides no advantage over msleep()
for larger delays. Fix up the 70/80ms delays here passing the "min"
value to msleep(). This reduces the load on the hrtimer subsystem.

Link: http://lkml.org/lkml/2017/1/11/377
Fixes: commit 246693ba7b0b ("ASoC: rt5640: change widget sequence for depop")
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 80317c2c 03-Jan-2017 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: move DAC2 Power to rt5640_dapm_widgets

"DAC L2 Power" and "DAC R2 Power" are used by both rt5639 and rt5640.
But it was defined in rt5640_specific_dapm_widgets[]. Move them to
rt5640_dapm_widgets will let both rt5639 and rt5640 can use it.

Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# ca5f17c5 25-Oct-2016 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: add Mono ADC Capture Switch control

Mono ADC Capture Switch control is missing in the driver. So, add it.

Signed-off-by: Bard Liao <bardliao@realtek.com>
Tested-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 25fb7062 17-Oct-2016 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: enable MCLK detection

There is a power saving mechanism in rt5640. It will turn off some
unused power when MCLK is not present. We call that "MCLK detection"
and it should be enabled by default.

Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# c49aed77 12-Aug-2016 Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

ASoC: rt5640: add internal clock source support

Adding missing definitions and flags to select internal
clock source as system clock, needed for jack detection.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# b72aa483 08-Aug-2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

ASoC: codec duplicated callback function goes to component on rt5640

codec driver and component driver has duplicated callback functions,
and codec side functions are just copied to component side when
register timing. This was quick-hack, but no longer needed.
This patch moves these functions from codec driver to component driver.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 653aa464 18-Mar-2016 Sugar Zhang <sugar.zhang@rock-chips.com>

ASoC: rt5640: Correct the digital interface data select

this patch corrects the interface adc/dac control register definition
according to datasheet.

Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org


# c77dd678 08-Mar-2016 Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>

ASoC: rt5640: remove unused variable

We are getting build warning about:
sound/soc/codecs/rt5640.c:1892:11: warning: unused variable 'dai_sel'

The use of the variable was removed but the variable itself was not
removed.

Fixes: c467fc0e010b ("ASoC: rt5640: Set PLL src according to source")
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 57586fb7 07-Mar-2016 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: add supplys for dac power

The DAC1/2 power is for both DACs and related mixer/mux. Add SUPPLY
type widgets to support it.

Signed-off-by: Jack Yu <jack.yu@realtek.com>
Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# c467fc0e 07-Mar-2016 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: Set PLL src according to source

rt5640_set_dai_pll set pll source according to given source and
dai id. However, the pll source should be set according to given
source only.

Signed-off-by: Jack Yu <jack.yu@realtek.com>
Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 6049af00 22-Feb-2016 Sugar Zhang <sugar.zhang@rock-chips.com>

ASoC: rt5640: add master clock handling for rt5640

enable/disable master clock when codec is active or not.

Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 55fc2056 04-Jan-2016 Jorge Fernandez Monteagudo <jorgefm@cirsa.com>

ASoC: Intel: Atom: Add support for HP ElitePad 1000 G2

The BIOS for the HP ElitePad 1000 G2 uses an unexpected HID,
(INTCCFFD), add it to the white list of knowns HIDs.

Signed-off-by: Jorge Fernandez Monteagudo <jorgefm@cirsa.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# bee3e020 04-Jan-2016 Jack Yu <jack.yu@realtek.com>

ASoC: rt5640: add ASRC support

Signed-off-by: Jack Yu <jack.yu@realtek.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 16566e47 20-Oct-2015 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Fill up the IN3's support

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 9b850ca4 11-Aug-2015 John Lin <john.lin@realtek.com>

ASoC: rt5640: fix line out no sound issue

The power for line out was not turned on when line out is enabled.
So we add "LOUT amp" widget to turn on the power for line out.

Signed-off-by: John Lin <john.lin@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org


# 8295822d 02-Aug-2015 Lars-Peter Clausen <lars@metafoo.de>

ASoC: rt5640: Replace TLV_DB_RANGE_HEAD with DECLARE_TLV_DB_RANGE

DECLARE_TLV_DB_RANGE() has the advantage over using TLV_DB_RANGE_HEAD()
that it automatically calculates the number of items in the TLV and is
hence less prone to manual error.

Generate using the following coccinelle script

// <smpl>
@@
declarer name DECLARE_TLV_DB_RANGE;
identifier tlv;
constant x;
@@
-unsigned int tlv[] = {
- TLV_DB_RANGE_HEAD(x),
+DECLARE_TLV_DB_RANGE(tlv,
...
-};
+);
// </smpl>

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 00a6d6e5 04-Aug-2015 Oder Chiou <oder_chiou@realtek.com>

ASoC: Add function "rl6231_get_pre_div" to correct the dmic clock calculation

Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 8019ff6c 16-Jul-2015 Nariman Poushin <nariman@opensource.wolfsonmicro.com>

regmap: Use reg_sequence for multi_reg_write / register_patch

Separate the functionality using sequences of register writes from the
functions that take register defaults. This change renames the arguments
in order to support the extension of reg_sequence to take an optional
delay to be applied after any given register in a sequence is written.
This avoids adding an int to all register defaults, which could
substantially increase memory usage for regmaps with large default tables.

This also updates all the clients of multi_reg_write/register_patch.

Signed-off-by: Nariman Poushin <nariman@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 1c07a4de 14-Jul-2015 Krzysztof Kozlowski <krzk@kernel.org>

ASoC: drivers: Drop owner assignment from i2c_driver

i2c_driver does not need to set an owner because i2c_register_driver()
will set it.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 818454d1 25-Jun-2015 Jarkko Nikula <jarkko.nikula@linux.intel.com>

ASoC: rt5640: Prefix hexadecimal ID register value with 0x in error print

Make it obvious that unexpected value read from ID register is printed in
hexadecimal.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# b895dc2c 13-Jun-2015 Mathias Krause <minipli@googlemail.com>

ASoC: rt5640: Constify ACPI device ids and register defaults

Constify the ACPI device ID array and the register map, no need to have
them writable at runtime. Also drop the unneeded RT5640_INIT_REG_LEN
define.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 76aad74b 19-May-2015 Lars-Peter Clausen <lars@metafoo.de>

ASoC: rt5640: Replace direct snd_soc_codec dapm field access

The dapm field of the snd_soc_codec struct is eventually going to be
removed, in preparation for this replace all manual access to
codec->dapm.bias_level with snd_soc_codec_get_bias_level() and replace all
other manual access to codec->dapm with snd_soc_codec_get_dapm().

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>


# f4bf8d77 27-Apr-2015 Lars-Peter Clausen <lars@metafoo.de>

ASoC: Move bias level update to the core

All drivers have the same line at the end of the set_bias_level callback to
update the bias_level state. Move this update into
snd_soc_dapm_force_bias_level() and remove them from the drivers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>


# bd1204cb 27-Apr-2015 Lars-Peter Clausen <lars@metafoo.de>

ASoC: Route all bias level updates through the core

Use the new snd_soc_codec_force_bias_level() helper function to invoke the
bias_level callback of a driver instead of calling the callback by hand.
Currently the effect of this is the same, but having all bias level updates
go through a central place will allow us to move more of the bias level
management into the DAPM core.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 3463667a 23-Jan-2015 Jarkko Nikula <jarkko.nikula@linux.intel.com>

ASoC: rt5640: Add RT5642 ACPI ID for Intel Baytrail

Asus T100TAF uses ACPI ID "10EC5642" for its audio codec. I suppose it is
updated ACPI ID for the RT5642 codec since some earlier platforms are using
"10EC5640" with the RT5642 too.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# bb1cd608 14-Jan-2015 Lars-Peter Clausen <lars@metafoo.de>

ASoC: rt5640: Replace w->codec snd_soc_dapm_to_codec(w->dapm)

The codec field of the snd_soc_widget struct is eventually going to be
removed, use snd_soc_dapm_to_codec(w->dapm) instead.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>


# cd69dc88 01-Oct-2014 Jarkko Nikula <jarkko.nikula@linux.intel.com>

ASoC: rt5640: Add function for enabling DMIC from ACPI probed machine

There is no code enabling DMIC clock in systems that don't provide platform
data for rt5640 after commit 71d97a794301 ("ASoC: rt5640: Use the platform
data for DMIC settings").

I think it's worth to keep this static DMIC clock and alternative data pin
setting during probe time. For making possible to use DMIC from ACPI probed
machine (prior ACPI 5.1 with _DSD) this patch moves DMIC configuration to
new exported rt5640_dmic_enable() that machine drivers can call.

Please note, this patch moves DMIC configuration from i2c probe to codec
probe in case platform data for rt5640 is set.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# f4821e8e 26-Aug-2014 Jarkko Nikula <jarkko.nikula@linux.intel.com>

ASoC: rt5640: Do not allow regmap to use bulk read-write operations

Debugging showed Realtek RT5642 doesn't support autoincrementing writes so
driver should set the use_single_rw flag for regmap.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org


# 1657caf5 09-Jun-2014 Axel Lin <axel.lin@ingics.com>

ASoC: rt5640: Remove unneeded goto in rt5640_i2c_probe

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# d92950e7 20-May-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the function "get_clk_info" to RL6231 shared support

The patch adds the function "get_clk_info" to RL6231 shared support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 71c7a2d6 20-May-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the function of the PLL clock calculation to RL6231 shared support

The patch adds the function of the PLL clock calculation to RL6231 shared
support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 49ef7925 20-May-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add RL6231 class device shared support for RT5640, RT5645 and RT5651

The patch adds the RL6231 class device shared support for RT5640, RT5645 and
RT5651. The function of the DMIC clock calculation can be shared by RL6231
shared support.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 57f174f4 06-May-2014 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: add default case for unexpected ID

We may read an unexpected value when detemining which codec is attached.
In that case, either a unsupported codec is attached or something wrong
with I2C. The driver will not work properly on both cases. So we return
an error for that.

Signed-off-by: Bard Liao <bardliao@realtek.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 33fcec29 28-Apr-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the rt5639 support to the OF match table

The patch adds the rt5639 support to the OF match table.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 8bfc6d2d 16-Apr-2014 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: Add minimal support for RT5642

We have been using rt5640.c codec driver with RT5642 codec chip before commit
022d21f004c1 ("ASoC: rt5640: add rt5639 support"). That commits starts using
device ID reading in reset register for adding device specific controls and
routes runtime.

Now since device ID appears to be different between RT5640 and RT5642 the
driver doesn't add those controls and routes that are valid also on RT5642.

Fix this by adding a device ID found by debugging and minimal code for
supporting RT5642.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 712fb1c2 14-Apr-2014 Lars-Peter Clausen <lars@metafoo.de>

ASoC: rt5640: Replace usage deprecated MUX/ENUM macros

SND_SOC_DAPM_VALUE_MUX and SOC_DAPM_VALUE_ENUM are deprecated and merely an
alias for SND_SOC_DAPM_MUX and SOC_DAPM_ENUM. Replace the deprecated macros so
we can eventually remove their definition.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>


# affb74ad 03-Apr-2014 Sachin Kamat <sachin.kamat@linaro.org>

ASoC: rt5640: Include of.h

of_match_ptr is defined in of.h. Include it explicitly.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>


# b0c27846 09-Apr-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Add the string "rt5639" to the list of I2C device IDs

The patch adds the string "rt5639" to the list of I2C device IDs.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 022d21f0 08-Apr-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: add rt5639 support

This patch adds the rt5639 support

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 09caf300 30-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Change the setting method of idle_bias_off

The patch moves the idle_bias_off setting to struct "soc_codec_dev_rt5640".

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 3441e524 28-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Remove the unnecessary parentheses

The patch removes the unnecessary parentheses.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# acf04e63 28-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Remove the unused or incorrect setting of clock source

The patch removes the unused or incorrect setting of clock source.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 218a3f96 28-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Rename the function of clock checking

In order to identify clearly, the patch renames the function
"check_sysclk1_source" to "is_sys_clk_from_pll".

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 2f2a714c 28-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Remove the pre-allocated size of reg_default

In order to prevent the redundant memory usage, the pre-allocated size of
reg_default should be remove.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 71d97a79 27-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Use the platform data for DMIC settings

The patch uses the platform data for DMIC settings.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 9bccae73 27-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Correct the judgement of data length

The patch corrects the judgement of data length.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 4c9185be 27-Mar-2014 Oder Chiou <oder_chiou@realtek.com>

ASoC: rt5640: Move cache sync() to resume()

The patch fixes the defect in case of resume which doesn't sync the cache.

Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 03a620d8 31-Mar-2014 Stephen Warren <swarren@nvidia.com>

ASoC: rt5640: add an of_match table

Add a device tree match table. This serves to make the driver's support
of device tree more explicit. Perhaps the fallback for DT matching to
using the i2c_device_id table will go away one day, since it fails in
face of devices from different vendors with the same name.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# ab64246c 13-Mar-2014 Lars-Peter Clausen <lars@metafoo.de>

ASoC: codecs: Replace instances of rtd->codec with dai->codec

With CODEC to CODEC links rtd->codec does not necessarily point to the driver's
CODEC. CODEC drivers should always use dai->codec and never even look at the PCM
runtime.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Jyri Sarha <jsarha@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 5d6be5aa 10-Mar-2014 Xiubo Li <Li.Xiubo@freescale.com>

ASoC: codec: Simplify ASoC probe code.

For some CODEC drivers like who act as the MFDs children are ignored
by this patch.

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 4c03cb6f 18-Feb-2014 Takashi Iwai <tiwai@suse.de>

ASoC: rt5640: Remove superfluous const

As SOC_ENUM_SINGLE_DECL() itself contains const modifier now, we can
reduce const from its users.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>


# b31b2b6d 07-Feb-2014 Jarkko Nikula <jarkko.nikula@linux.intel.com>

ASoC: rt5640: Add ACPI ID for Intel Baytrail

Realtek RT5640 uses ACPI ID "10EC5640" for Intel Baytrail platforms.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org


# 5a7615cf 30-Oct-2013 Takashi Iwai <tiwai@suse.de>

ASoC: rt5640: Fix ignored error checks

The negative error value returned from get_sdp_info() is ignored
because it's assigned to unsigned variables.

Spotted by coverity CIDs 1042657, 1042658.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@linaro.org>


# ebce3114 16-Oct-2013 Mark Brown <broonie@linaro.org>

ASoC: rt5640: Don't go to standby on resume

There is no need for the CODEC to go to standby on resume since the core will
power it up as needed and in any case it is an idle_bias_off CODEC so would
normally sit with bias off while idle.

Signed-off-by: Mark Brown <broonie@linaro.org>
Tested-by: Stephen Warren <swarren@nvidia.com>


# e58f301e 16-Oct-2013 Mark Brown <broonie@linaro.org>

ASoC: rt5640: Power down LDO while suspended

If we have control over the LDO then disable it during suspend; the device
is already being put into reset so will be non-functional over suspend
anyway and this will save a small amount of power.

Signed-off-by: Mark Brown <broonie@linaro.org>
Tested-by: Stephen Warren <swarren@nvidia.com>


# 32fcb97b 19-Sep-2013 Thierry Reding <thierry.reding@gmail.com>

ASoC: rt5640: Omit ACPI match table only if !ACPI

The ACPI_PTR() macro evaluates to NULL if ACPI is disabled and hence the
ACPI match table won't be used, causing the compiler to complain. Avoid
this by protecting the table using an #ifdef CONFIG_ACPI.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 02b80773 13-Sep-2013 Liam Girdwood <liam.r.girdwood@linux.intel.com>

ASoC: rt5640: Add ACPI probing support.

Allow the RT5640 to be probed as an ACPI I2C device.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 9e9cb9b9 13-Sep-2013 Liam Girdwood <liam.r.girdwood@linux.intel.com>

ASoC: rt5640: Provide more useful hw_params error reasons.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 89d05130 13-Sep-2013 Sachin Kamat <sachin.kamat@linaro.org>

ASoC: rt5640: Staticize hp_amp_power_on

'hp_amp_power_on' is used only in this file. Make it static.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 246693ba 22-Aug-2013 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: change widget sequence for depop

Signed-off-by: Bard Liao <bardliao@realtek.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 868ead65 01-Aug-2013 Bard Liao <bardliao@realtek.com>

ASoC: rt5640: remove unused mux

Remove unused "INL Mux" and "INR Mux".

Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 9be94aea 12-Jun-2013 Stephen Warren <swarren@nvidia.com>

ASoC: rt5640: fix sparse warnings

This fixes:
975:9: sparse: Using plain integer as NULL pointer
1917:24: sparse: symbol 'rt5640_aif_dai_ops' was not declared. Should it be static?
1924:27: sparse: symbol 'rt5640_dai' was not declared. Should it be static?
2079:19: sparse: symbol 'rt5640_i2c_driver' was not declared. Should it be static?

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# dcad9f03 12-Jun-2013 Stephen Warren <swarren@nvidia.com>

ASoC: rt5640: add device tree support

Modify the RT5640 driver to parse platform data from device tree. Write
a DT binding document to describe those properties.

Slight re-ordering of rt5640_i2c_probe() to better fit the DT parsing.

Since ldo1_en is optional, guard usage of it with gpio_is_valid(), rather
than open-coding an if (gpio) check.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>


# 997b0520 10-Jun-2013 Bard Liao <bardliao@realtek.com>

ASoC: add RT5640 CODEC driver

This patch adds the ALC5640 codec driver.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Bard Liao <bardliao@realtek.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>