ASoC: rt5575: Add the codec driver for the ALC5575
Subsystems (5)
Oder Chiou
maintainerv10 cover ASoC: rt5575: Add the codec driver for the ALC5575
Hi all,
This patch series adds support for the Realtek ALC5575 audio codec.
Changes in v10:
- Patch 1/3:
- export of_find_spi_controller_by_node()
- Patch 2/3:
- remove realtek,rt5575-use-spi
- add spi-parent for firmware-loading
- Patch 3/3:
- use of_find_spi_controller_by_node() to get the SPI controller and add the spi device for firmware-loading
Changes in v9:
- Patch 1/2:
- modify the comment
- change the compatible name to "realtek,rt5575-use-spi"
- Patch 2/2:
- remove the standalone rt5575_spi_driver module and integrate its functionality into the I2C driver
- move the SPI firmware-loading function to rt5575-spi.c
- use the match data to distinguish between w/wo flash
- minor fixes
- Link to v9: https://lore.kernel.org/all/[email protected]/
Changes in v8:
- Patch 1/2:
- remove the variable rt5575_spi_ready
- use the multiple compatible names to distinguish between w/wo flash
- Patch 2/2:
- add compatible enum "realtek,rt5575-with-spi"
- Link to v8: https://lore.kernel.org/all/[email protected]/
Changes in v7:
- Patch 1/2:
- add a caption for the tristates
- remove the redundant enum of the SPI command
- add the error log in the request firmware failure
- change the function name rt5575_spi_fw_loaded to rt5575_fw_load_by_spi
- minor fixes
- Patch 2/2:
- modify commit message
- Link to v7: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Patch 1/2:
- modify commit message
- add select SND_SOC_RT5575 to config SND_SOC_RT5575_SPI in the Kconfig
- revise the boiler plate in the head of the file
- sort the include files
- use a structure to transfer the spi data
- use the poll() related function instead the for-loop
- revise the UUID to the private ID
- minor fixes
- Patch 2/2:
- modify description
- Link to v6: https://lore.kernel.org/all/[email protected]/
Changes in v2 to v5:
- Patch 1/2:
- move the firmware to the subdirectory
- remove the empty functions
- remove the cache_type in the regmap_config
- add the error log in the run firmware failure
- Patch 2/2:
- nothing
- Link to v5: https://lore.kernel.org/all/[email protected]/
Oder Chiou (3):
spi: export of_find_spi_controller_by_node()
ASoC: dt-bindings: realtek,rt5575: add support for ALC5575
ASoC: rt5575: Add the codec driver for the ALC5575
.../bindings/sound/realtek,rt5575.yaml | 61 +++ drivers/spi/spi.c | 3 +- include/linux/spi/spi.h | 11 + sound/soc/codecs/Kconfig | 10 + sound/soc/codecs/Makefile | 3 + sound/soc/codecs/rt5575-spi.c | 119 ++++++ sound/soc/codecs/rt5575-spi.h | 26 ++ sound/soc/codecs/rt5575.c | 359 ++++++++++++++++++ sound/soc/codecs/rt5575.h | 54 +++ 9 files changed, 645 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/sound/realtek,rt5575.yaml create mode 100644 sound/soc/codecs/rt5575-spi.c create mode 100644 sound/soc/codecs/rt5575-spi.h create mode 100644 sound/soc/codecs/rt5575.c create mode 100644 sound/soc/codecs/rt5575.h
Signature · 1 line
2.52.0
Oder Chiou
maintainerPATCH v10 1/3 spi: export of_find_spi_controller_by_node()
Some devices are primarily described on another bus (e.g. I2C) but also have an additional SPI connection that serves as a transport for firmware loading. Export of_find_spi_controller_by_node() so drivers can obtain the SPI controller referenced by a DT phandle.
--- drivers/spi/spi.c | 3 ++- include/linux/spi/spi.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/spi/spi.c +2 -1
@@ -4771,7 +4771,7 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node) }/* The spi controllers are not using spi_bus, so we find it with another way */ -static struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) +struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) {struct device *dev;
@@ -4784,6 +4784,7 @@ static struct spi_controller *of_find_spi_controller_by_node(struct device_node/* Reference got in class_find_device */ return container_of(dev, struct spi_controller, dev); } +EXPORT_SYMBOL_GPL (of_find_spi_controller_by_node);static int of_spi_notify (struct notifier_block *nb,unsigned long action,void *arg)
include/linux/spi/spi.h +11 -0
@@ -882,6 +882,17 @@ extern int devm_spi_register_controller(struct device *dev, struct spi_controller *ctlr);extern void spi_unregister_controller (struct spi_controller *ctlr); +#if IS_ENABLED (CONFIG_OF_DYNAMIC ) +extern struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node); +#else +static inline struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node) +{ +return NULL ; +} +#endif +#if IS_ENABLED (CONFIG_ACPI ) &&IS_ENABLED (CONFIG_SPI_MASTER )extern struct spi_controller *acpi_spi_find_controller_by_adev (struct acpi_device *adev); extern struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
Signature · 1 line
2.52.0
Re: [PATCH v10 1/3] spi: export of_find_spi_controller_by_node()
Quoted 4 lines · Oder Chiou
Some devices are primarily described on another bus (e.g. I2C) but also have an additional SPI connection that serves as a transport for firmware loading. Export
of_find_spi_controller_by_node()so drivers can obtain the SPI controller referenced by a DT phandle.
One nitpick below, otherwise looks good.
Quoted 33 lines
Signed-off-by Oder Chiou <[email protected]>--- drivers/spi/spi.c | 3 ++- include/linux/spi/spi.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)drivers/spi/spi.c +2
-1@@ -4771,7 +4771,7 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node) }/* The spi controllers are not using spi_bus, so we find it with another way */ -static struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) +struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) {struct device *dev;@@ -4784,6 +4784,7 @@ static struct spi_controller *of_find_spi_controller_by_node(struct device_node/* Reference got in class_find_device */ return container_of(dev, struct spi_controller, dev); } +EXPORT_SYMBOL_GPL (of_find_spi_controller_by_node);static int of_spi_notify (struct notifier_block *nb,unsigned long action,void *arg)include/linux/spi/spi.h +0
-0
include/linux/spi/spi.h extern int devm_spi_register_controller(struct device *dev, · line 890
Quoted 9 lines
include/linux/spi/spi.h +6
-0@@ -882,6 +882,17 @@ extern int devm_spi_register_controller(struct device *dev, struct spi_controller *ctlr);extern void spi_unregister_controller (struct spi_controller *ctlr); +#if IS_ENABLED (CONFIG_OF_DYNAMIC ) +extern struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node); +#else +static inline struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node)
For both declarations, just make them one-liners. Fits the limit, even for the inliner case:
static inline struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
Quoted 8 lines
include/linux/spi/spi.h +5
-0+{ +return NULL ; +} +#endif +#if IS_ENABLED (CONFIG_ACPI ) &&IS_ENABLED (CONFIG_SPI_MASTER )extern struct spi_controller *acpi_spi_find_controller_by_adev (struct acpi_device *adev); extern struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
Rob Herring
maintainerRe: [PATCH v10 1/3] spi: export of_find_spi_controller_by_node()
In reply to Oder ChiouQuoted 37 lines · Oder Chiou
Some devices are primarily described on another bus (e.g. I2C) but also have an additional SPI connection that serves as a transport for firmware loading. Export
of_find_spi_controller_by_node()so drivers can obtain the SPI controller referenced by a DT phandle.Signed-off-by Oder Chiou <[email protected]>--- drivers/spi/spi.c | 3 ++- include/linux/spi/spi.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)drivers/spi/spi.c +2
-1@@ -4771,7 +4771,7 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node) }/* The spi controllers are not using spi_bus, so we find it with another way */ -static struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) +struct spi_controller *of_find_spi_controller_by_node (struct device_node *node) {struct device *dev;@@ -4784,6 +4784,7 @@ static struct spi_controller *of_find_spi_controller_by_node(struct device_node/* Reference got in class_find_device */ return container_of(dev, struct spi_controller, dev); } +EXPORT_SYMBOL_GPL (of_find_spi_controller_by_node);static int of_spi_notify (struct notifier_block *nb,unsigned long action,void *arg)include/linux/spi/spi.h +0
-0
include/linux/spi/spi.h extern int devm_spi_register_controller(struct device *dev, · line 885
Quoted 4 lines
include/linux/spi/spi.h +1
-0@@ -882,6 +882,17 @@ extern int devm_spi_register_controller(struct device *dev, struct spi_controller *ctlr);extern void spi_unregister_controller (struct spi_controller *ctlr); +#if IS_ENABLED (CONFIG_OF_DYNAMIC )
This has nothing to do with CONFIG_OF_DYNAMIC. CONFIG_OF is what you want, and there's probably a section for that already.
Quoted 16 lines
include/linux/spi/spi.h +10
-0+extern struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node); +#else +static inline struct spi_controller *of_find_spi_controller_by_node ( +struct device_node *node) +{ +return NULL ; +} +#endif +#if IS_ENABLED (CONFIG_ACPI ) &&IS_ENABLED (CONFIG_SPI_MASTER )extern struct spi_controller *acpi_spi_find_controller_by_adev (struct acpi_device *adev); extern struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,Signature · 1 line
2.52.0
Oder Chiou
maintainerPATCH v10 2/3 ASoC: dt-bindings: realtek,rt5575: add support for ALC5575
In reply to Oder ChiouAudio codec with I2S, I2C and SPI.
--- .../bindings/sound/realtek,rt5575.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/realtek,rt5575.yaml
Documentation/devicetree/bindings/sound/realtek,rt5575.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/realtek,rt5575.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ALC5575 audio CODEC + +maintainers: + - Oder Chiou <[email protected]> + +description: + The device supports both I2C and SPI. I2C is mandatory, while SPI is + optional depending on the hardware configuration. SPI is used for + firmware loading if present. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + const: realtek,rt5575 + + reg: + maxItems: 1 + + spi-parent: + description: + Optional phandle reference to the SPI controller used for firmware + loading. The argument specifies the chip select. + $ref: /schemas/types.yaml#/definitions/phandle-array + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + # I2C-only node + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + codec@57 { + compatible = "realtek,rt5575"; + reg = <0x57>; + }; + }; + + # I2C + optional SPI node + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + codec@57 { + compatible = "realtek,rt5575"; + reg = <0x57>; + spi-parent = <&spi0 0>; /* chip-select 0 */ + }; + };
Signature · 1 line
2.52.0
Re: [PATCH v10 2/3] ASoC: dt-bindings: realtek,rt5575: add support for ALC5575
Quoted 8 lines · Oder Chiou
Audio codec with I2S, I2C and SPI.
Signed-off-by Oder Chiou <[email protected]>--- .../bindings/sound/realtek,rt5575.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/realtek,rt5575.yaml
Oder Chiou
maintainerPATCH v10 3/3 ASoC: rt5575: Add the codec driver for the ALC5575
In reply to Oder ChiouThe ALC5575 integrates an audio DSP that typically loads its firmware from an external flash via its own SPI host interface. In certain hardware configurations, the firmware can alternatively be loaded through the SPI client interface. The driver provides basic mute and volume control functions. When the SPI client interface is enabled, firmware loading is handled by the SPI driver.
--- sound/soc/codecs/Kconfig | 10 + sound/soc/codecs/Makefile | 3 + sound/soc/codecs/rt5575-spi.c | 119 +++++++++++ sound/soc/codecs/rt5575-spi.h | 26 +++ sound/soc/codecs/rt5575.c | 359 ++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5575.h | 54 +++++ 6 files changed, 571 insertions(+) create mode 100644 sound/soc/codecs/rt5575-spi.c create mode 100644 sound/soc/codecs/rt5575-spi.h create mode 100644 sound/soc/codecs/rt5575.c create mode 100644 sound/soc/codecs/rt5575.h
sound/soc/codecs/Kconfig +10 -0
@@ -212,6 +212,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_RT1305 imply SND_SOC_RT1308 imply SND_SOC_RT5514 + imply SND_SOC_RT5575 imply SND_SOC_RT5616 imply SND_SOC_RT5631 imply SND_SOC_RT5640
@@ -1783,6 +1784,15 @@ config SND_SOC_RT5514_SPI_BUILTIN bool # force RT5514_SPI to be built-in to avoid link errors default SND_SOC_RT5514=y && SND_SOC_RT5514_SPI=m +config SND_SOC_RT5575 + tristate "Realtek ALC5575 Codec - I2C" + depends on I2C + +config SND_SOC_RT5575_SPI + tristate "Realtek ALC5575 Codec - SPI" + depends on SPI_MASTER && I2C + depends on SND_SOC_RT5575 + config SND_SOC_RT5616 tristate "Realtek RT5616 CODEC" depends on I2C
sound/soc/codecs/Makefile +3 -0
@@ -253,6 +253,8 @@ snd-soc-rt286-y := rt286.o snd-soc-rt298-y := rt298.o snd-soc-rt5514-y := rt5514.o snd-soc-rt5514-spi-y := rt5514-spi.o +snd-soc-rt5575-y := rt5575.o +snd-soc-rt5575-$(CONFIG_SND_SOC_RT5575_SPI) += rt5575-spi.o snd-soc-rt5616-y := rt5616.o snd-soc-rt5631-y := rt5631.o snd-soc-rt5640-y := rt5640.o
@@ -686,6 +688,7 @@ obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o obj-$(CONFIG_SND_SOC_RT5514_SPI_BUILTIN) += snd-soc-rt5514-spi.o +obj-$(CONFIG_SND_SOC_RT5575) += snd-soc-rt5575.o obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
sound/soc/codecs/rt5575-spi.c new file +119 -0
119 lines not on this page · raw message
sound/soc/codecs/rt5575-spi.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* rt5575-spi.h -- ALC5575 SPI driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#ifndef __RT5575_SPI_H__ +#define __RT5575_SPI_H__ + +#if IS_ENABLED (CONFIG_SND_SOC_RT5575_SPI ) +struct spi_device *rt5575_spi_get_device (struct device *dev); +int rt5575_spi_fw_load (struct spi_device *spi); +#else +static inline struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +return NULL ; +} +static inline int rt5575_spi_fw_load (struct spi_device *spi) +{ +return -EINVAL ; +} +#endif + +#endif /* __RT5575_SPI_H__ */
sound/soc/codecs/rt5575.c new file +359 -0
359 lines not on this page · raw message
sound/soc/codecs/rt5575.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 94 lines · Oder Chiou
The ALC5575 integrates an audio DSP that typically loads its firmware from an external flash via its own SPI host interface. In certain hardware configurations, the firmware can alternatively be loaded through the SPI client interface. The driver provides basic mute and volume control functions. When the SPI client interface is enabled, firmware loading is handled by the SPI driver.
Signed-off-by Oder Chiou <[email protected]>--- sound/soc/codecs/Kconfig | 10 + sound/soc/codecs/Makefile | 3 + sound/soc/codecs/rt5575-spi.c | 119 +++++++++++ sound/soc/codecs/rt5575-spi.h | 26 +++ sound/soc/codecs/rt5575.c | 359 ++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5575.h | 54 +++++ 6 files changed, 571 insertions(+)create mode 100644
sound/soc/codecs/rt5575-spi.ccreate mode 100644sound/soc/codecs/rt5575-spi.hcreate mode 100644sound/soc/codecs/rt5575.ccreate mode 100644sound/soc/codecs/rt5575.hsound/soc/codecs/Kconfig +10
-0@@ -212,6 +212,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_RT1305 imply SND_SOC_RT1308 imply SND_SOC_RT5514 + imply SND_SOC_RT5575 imply SND_SOC_RT5616 imply SND_SOC_RT5631 imply SND_SOC_RT5640@@ -1783,6 +1784,15 @@ config SND_SOC_RT5514_SPI_BUILTIN bool # force RT5514_SPI to be built-in to avoid link errors default SND_SOC_RT5514=y && SND_SOC_RT5514_SPI=m +config SND_SOC_RT5575 + tristate "Realtek ALC5575 Codec - I2C" + depends on I2C + +config SND_SOC_RT5575_SPI + tristate "Realtek ALC5575 Codec - SPI" + depends on SPI_MASTER && I2C + depends on SND_SOC_RT5575 + config SND_SOC_RT5616 tristate "Realtek RT5616 CODEC" depends on I2Csound/soc/codecs/Makefile +3
-0@@ -253,6 +253,8 @@ snd-soc-rt286-y := rt286.o snd-soc-rt298-y := rt298.o snd-soc-rt5514-y := rt5514.o snd-soc-rt5514-spi-y := rt5514-spi.o +snd-soc-rt5575-y := rt5575.o +snd-soc-rt5575-$(CONFIG_SND_SOC_RT5575_SPI) += rt5575-spi.o snd-soc-rt5616-y := rt5616.o snd-soc-rt5631-y := rt5631.o snd-soc-rt5640-y := rt5640.o@@ -686,6 +688,7 @@ obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o obj-$(CONFIG_SND_SOC_RT5514_SPI_BUILTIN) += snd-soc-rt5514-spi.o +obj-$(CONFIG_SND_SOC_RT5575) += snd-soc-rt5575.o obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.osound/soc/codecs/rt5575-spi.c new file +18
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5575-spi.c -- ALC5575 SPI driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#include <linux/firmware.h> +#include <linux/of.h> +#include <linux/spi/spi.h> + +#include "rt5575-spi.h" + +#define RT5575_SPI_CMD_BURST_WRITE 5 +#define RT5575_SPI_BUF_LEN 240 + +struct rt5575_spi_burst_write {
sound/soc/codecs/rt5575-spi.c line 28
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+u8 cmd; +u32 addr; +u8 data[RT5575_SPI_BUF_LEN ]; +u8 dummy; +} __packed; + +struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +struct device_node *spi_np; +struct spi_controller *ctlr;
Reorder to achieve reverse-christmas-tree notation. Waterfall to a number of functions found in this patch.
Quoted 33 lines
sound/soc/codecs/rt5575-spi.c new file +33
-0+struct spi_device *spi; +u32 cs; + + spi_np =of_parse_phandle (dev->of_node,"spi-parent" ,0 ); +if (!spi_np) { +dev_err (dev,"Failed to get spi-parent phandle\n" ); +return NULL ; + } + +if (of_property_read_u32_index (dev->of_node,"spi-parent" ,1 , &cs)) + cs =0 ; + +if (cs >= ctlr->num_chipselect) { +dev_err (dev,"Chip select has wrong number %d\n" , cs); +of_node_put (spi_np); +return NULL ; + } + + ctlr =of_find_spi_controller_by_node (spi_np); +of_node_put (spi_np); +if (!ctlr) +return NULL ; + + spi =spi_new_device (ctlr, &(struct spi_board_info ){ + .modalias ="rt5575" , + .chip_select = cs, + .max_speed_hz =10000000 , + }); + +spi_controller_put (ctlr); +return spi; +} +
sound/soc/codecs/rt5575-spi.c line 71
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+/** +* rt5575_spi_burst_write - Write data to SPI by rt5575 address. +* @spi: SPI device. +* @addr: Start address. +* @txbuf: Data buffer for writing. +* @len: Data length. +* +*/ +static int rt5575_spi_burst_write (struct spi_device *spi,u32 addr,const u8 *txbuf, +size_t len)
Alignment or, just make it one-liner. It fits the limit.
sound/soc/codecs/rt5575-spi.c line 74
Quoted 3 lines
sound/soc/codecs/rt5575-spi.c new file +3
-0+{ +struct rt5575_spi_burst_write buf = { + .cmd =RT5575_SPI_CMD_BURST_WRITE
Missing comma at the end.
Quoted 7 lines
sound/soc/codecs/rt5575-spi.c new file +7
-0+ }; +unsigned int end, offset =0 ; + +while (offset < len) { +if (offset +RT5575_SPI_BUF_LEN <= len) + end =RT5575_SPI_BUF_LEN ; +else
sound/soc/codecs/rt5575-spi.c line 91
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+ end = len %RT5575_SPI_BUF_LEN ; + + buf.addr =cpu_to_le32 (addr + offset); +memcpy (&buf.data, &txbuf[offset], end); +spi_write (spi, &buf,sizeof (buf)); + + offset +=RT5575_SPI_BUF_LEN ; + } + +return 0 ;
If you intend on ignoring result of spi_write()s, then I see no reason why rt5575_spi_burst_write() shouldn't be a void function.
Quoted 7 lines
sound/soc/codecs/rt5575-spi.c new file +7
-0+} + +int rt5575_spi_fw_load (struct spi_device *spi) +{ +const struct firmware *firmware; +struct device *dev = &spi->dev; +static const char *const fw_path[] = {
sound/soc/codecs/rt5575-spi.c line 108
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+"realtek/rt5575/rt5575_fw1.bin" , +"realtek/rt5575/rt5575_fw2.bin" , +"realtek/rt5575/rt5575_fw3.bin" , + "realtek/rt5575/rt5575_fw4.bin" + }; +static const u32 fw_addr[] = {0x5f400000 ,0x5f600000 ,0x5f7fe000 ,0x5f7ff000 }; +int i, ret; + +for (i =0 ; i <ARRAY_SIZE (fw_addr); i++) { + ret =request_firmware (&firmware, fw_path[i], dev);
So, in v8 or earlier the ordering of operations was different:
request_firmware(fw1); regmap_write(); regmap_write(); regmap_write(); rt5575_spi_burst_write(); release_firmware(fw1); /* Proceed with loop for the remaining fw2, fw3, fw4. */
What changed that suddenly the ordering could be simplified?
sound/soc/codecs/rt5575-spi.c line 115
Quoted 7 lines
sound/soc/codecs/rt5575-spi.c new file +7
-0+if (!ret) { +rt5575_spi_burst_write (spi, fw_addr[i], firmware->data, firmware->size); +release_firmware (firmware); + }else { +dev_err (dev,"Request firmware failure: %d\n" , ret); +return ret; + }
Please refactor this construct. When facing else-return, favour returning early to reduce indentation and make it easier to read the code.
if (ret) {
dev_err();
return ret;
}
rt5575_spi_burst_write();
release_firmware();Much better, isn't it?
Quoted 19 lines
sound/soc/codecs/rt5575-spi.c new file +4
-0+ } + +return 0 ; +}sound/soc/codecs/rt5575-spi.h new file +9
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* rt5575-spi.h -- ALC5575 SPI driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#ifndef __RT5575_SPI_H__
sound/soc/codecs/rt5575-spi.h line 19
Quoted 10 lines
sound/soc/codecs/rt5575-spi.h new file +10
-0+#define __RT5575_SPI_H__ + +#if IS_ENABLED (CONFIG_SND_SOC_RT5575_SPI ) +struct spi_device *rt5575_spi_get_device (struct device *dev); +int rt5575_spi_fw_load (struct spi_device *spi); +#else +static inline struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +return NULL ; +}
Missing newline.
Quoted 27 lines
sound/soc/codecs/rt5575-spi.h new file +7
-0+static inline int rt5575_spi_fw_load (struct spi_device *spi) +{ +return -EINVAL ; +} +#endif + +#endif /* __RT5575_SPI_H__ */ sound/soc/codecs/rt5575.c new file +14
-0@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5575.c -- ALC5575 ALSA SoC audio component driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#include <linux/i2c.h> +#include <sound/soc.h> +#include <sound/tlv.h> + +#include "rt5575.h" +#include "rt5575-spi.h"
(...)
Quoted 8 lines
sound/soc/codecs/rt5575.c new file +8
-0+static int rt5575_i2c_read (void *context,unsigned int reg,unsigned int *val) +{ +struct i2c_client *client = context; +struct rt5575_priv *rt5575 =i2c_get_clientdata (client); + +regmap_read (rt5575->dsp_regmap, reg |RT5575_DSP_MAPPING , val); + +return 0 ;
sound/soc/codecs/rt5575.c line 231
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+} + +static int rt5575_i2c_write (void *context,unsigned int reg,unsigned int val) +{ +struct i2c_client *client = context; +struct rt5575_priv *rt5575 =i2c_get_clientdata (client); + +regmap_write (rt5575->dsp_regmap, reg |RT5575_DSP_MAPPING , val); + +return 0 ;
Not an expect in regmap, but I'd leave decision to the caller whether to squelch an error or not.
For both, rt5575_i2c_read()/write() I'd just return the corresponding regmap_xxx() operation rather then '0'.
Quoted 19 lines
sound/soc/codecs/rt5575.c new file +19
-0+} + +static const struct regmap_config rt5575_regmap = { + .reg_bits =16 , + .val_bits =32 , + .reg_stride =4 , + .max_register =0xfffc , + .readable_reg = rt5575_readable_register, + .reg_read = rt5575_i2c_read, + .reg_write = rt5575_i2c_write, + .use_single_read = true, + .use_single_write = true, +}; + +static int rt5575_fw_load_by_spi (struct rt5575_priv *rt5575) +{ +struct i2c_client *i2c = rt5575->i2c; +struct spi_device *spi; +struct device *dev = &i2c->dev;
sound/soc/codecs/rt5575.c line 260
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+int ret; + + spi =rt5575_spi_get_device (dev); +if (!spi) { +dev_warn (dev,"The spi-parent not described in the DTS\n" +"The hardware configuration should be with built-in flash\n" ); + +if (!IS_ENABLED (CONFIG_SND_SOC_RT5575_SPI )) +dev_warn (dev,"If the spi-parent is set in the DTS and it is without built-in flash\n" +"Please enable CONFIG_SND_SOC_RT5575_SPI\n" );
Does this mean we always get a warning, even in case when we're dealing with non-SPI variant?
Quoted 52 lines
sound/soc/codecs/rt5575.c new file +52
-0+ +return -ENXIO ; + } + +regmap_write (rt5575->dsp_regmap,0xfafafafa ,0x00000004 ); +regmap_write (rt5575->dsp_regmap,0x18008064 ,0x00000000 ); +regmap_write (rt5575->dsp_regmap,0x18008068 ,0x0002ffff ); + + ret =rt5575_spi_fw_load (spi); +if (ret) { +dev_err (dev,"Load firmware failure: %d\n" , ret); +return -ENODEV ; + } + +regmap_write (rt5575->dsp_regmap,0x18000000 ,0x00000000 ); +regmap_update_bits (rt5575->regmap,RT5575_SW_INT ,1 ,1 ); + +regmap_read_poll_timeout (rt5575->regmap,RT5575_SW_INT , ret, !ret,100000 ,10000000 ); +if (ret) { +dev_err (dev,"Run firmware failure: %d\n" , ret); +return -ENODEV ; + } + +return 0 ; +} + +static int rt5575_i2c_probe (struct i2c_client *i2c) +{ +struct rt5575_priv *rt5575; +struct device *dev = &i2c->dev; +int ret, val; + + rt5575 =devm_kzalloc (dev,sizeof (struct rt5575_priv ),GFP_KERNEL ); +if (!rt5575) +return -ENOMEM ; + +i2c_set_clientdata (i2c, rt5575); + + rt5575->i2c = i2c; + + rt5575->dsp_regmap =devm_regmap_init_i2c (i2c, &rt5575_dsp_regmap); +if (IS_ERR (rt5575->dsp_regmap)) { + ret =PTR_ERR (rt5575->dsp_regmap); +dev_err (dev,"Failed to allocate DSP register map: %d\n" , ret); +return ret; + } + + rt5575->regmap =devm_regmap_init (dev,NULL , i2c, &rt5575_regmap); +if (IS_ERR (rt5575->regmap)) { + ret =PTR_ERR (rt5575->regmap); +dev_err (dev,"Failed to allocate register map: %d\n" , ret); +return ret;
sound/soc/codecs/rt5575.c line 322
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+ } + +regmap_read (rt5575->regmap,RT5575_ID , &val); +if (val !=RT5575_DEVICE_ID ) { +dev_err (dev,"Device with ID register %08x is not rt5575\n" , val); +return -ENODEV ; + } + +regmap_read (rt5575->regmap,RT5575_ID_1 , &val); +if (!val) {
1. The 'RT5575_DEVICE_ID' check above fails, 'val' equals RT5575_DEVICE_ID, non-zero.
2. regmap_read(RT5575_ID_1) fails, let's skip the reasoning for now. 'val' remains unchanged.
3. The '!val' check fails though nothing has been actually read, 'val' could be simply invalid.
What's the goal of this check? Shouldn't we be more precise when checking the 'formal version'?
sound/soc/codecs/rt5575.c line 328
Quoted 6 lines
sound/soc/codecs/rt5575.c new file +6
-0+dev_err (dev,"This is not formal version\n" ); +return -ENODEV ; + } + +if (rt5575_fw_load_by_spi (rt5575) == -ENODEV ) +return -ENODEV ;
Looks like a hack, not a real solution. Also, I'm surprised it's called unconditionally - even when dealing with device with no SPI component.
sound/soc/codecs/rt5575.c line 331
Quoted 3 lines
sound/soc/codecs/rt5575.c new file +3
-0+ +return devm_snd_soc_register_component (dev, &rt5575_soc_component_dev, rt5575_dai, +ARRAY_SIZE (rt5575_dai));
Alignment.
Quoted 28 lines
sound/soc/codecs/rt5575.c new file +28
-0+} + +static const struct i2c_device_id rt5575_i2c_id[] = { + {"rt5575" }, + { } +}; +MODULE_DEVICE_TABLE (i2c, rt5575_i2c_id); + +static const struct of_device_id rt5575_of_match[] = { + { .compatible ="realtek,rt5575" }, + { } +}; +MODULE_DEVICE_TABLE (of, rt5575_of_match); + +static struct i2c_driver rt5575_i2c_driver = { + .driver = { + .name ="rt5575" , + .owner =THIS_MODULE , + .of_match_table = rt5575_of_match, + }, + .probe = rt5575_i2c_probe, + .id_table = rt5575_i2c_id, +}; +module_i2c_driver (rt5575_i2c_driver); + +MODULE_DESCRIPTION ("ASoC ALC5575 driver" ); +MODULE_AUTHOR ("Oder Chiou <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Mark Brown
maintainerQuoted 8 lines · Cezary Rojewski
Quoted 6 lines · Oder Chiou
The ALC5575 integrates an audio DSP that typically loads its firmware from an external flash via its own SPI host interface. In certain hardware configurations, the firmware can alternatively be loaded through the SPI client interface. The driver provides basic mute and volume control functions. When the SPI client interface is enabled, firmware loading is handled by the SPI driver.
Please delete unneeded context from mails when replying. Doing this makes it much easier to find your reply in the message, helping ensure it won't be missed by people scrolling through the irrelevant quoted material.
Quoted 7 lines
sound/soc/codecs/rt5575-spi.c line 28
Quoted 4 lines
sound/soc/codecs/rt5575-spi.c new file +4
-0+struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +struct device_node *spi_np; +struct spi_controller *ctlr;Reorder to achieve reverse-christmas-tree notation. Waterfall to a number of functions found in this patch.
This is not a general requirement for ASoC, it's something specific to the x86 and SOF stuff.
Oder Chiou
maintainerQuoted 238 lines
-----Original Message-----
From: Cezary Rojewski <[email protected]>
Sent: Wednesday, December 17, 2025 6:46 PM
To: Oder Chiou <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Flove(HsinFu) <[email protected]>; Shuming [范書銘] <[email protected]>; Jack Yu <[email protected]>; Derek [方德義] <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v10 3/3] ASoC: rt5575: Add the codec driver for the ALC5575External mail : This email originated from outside the organization. Do not reply, click links, or open attachments unless you recognize the sender and know the content is safe.
Quoted 7 lines · Oder Chiou
The ALC5575 integrates an audio DSP that typically loads its firmware from an external flash via its own SPI host interface. In certain hardware configurations, the firmware can alternatively be loaded through the SPI client interface. The driver provides basic mute and volume control functions. When the SPI client interface is enabled, firmware loading is handled by the SPI driver.
Quoted 7 lines
Signed-off-by Oder Chiou <[email protected]>--- sound/soc/codecs/Kconfig | 10 + sound/soc/codecs/Makefile | 3 + sound/soc/codecs/rt5575-spi.c | 119 +++++++++++ sound/soc/codecs/rt5575-spi.h | 26 +++ sound/soc/codecs/rt5575.c | 359++++++++++++++++++++++++++++++++++
sound/soc/codecs/Makefile obj-$(CONFIG_SND_SOC_RT298) +=
Quoted 49 lines
sound/soc/codecs/rt5575.h | 54 +++++ 6 files changed, 571 insertions(+)create mode 100644
sound/soc/codecs/rt5575-spi.ccreate mode 100644sound/soc/codecs/rt5575-spi.hcreate mode 100644sound/soc/codecs/rt5575.ccreate mode 100644sound/soc/codecs/rt5575.hsound/soc/codecs/Kconfig +10
-0@@ -212,6 +212,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_RT1305 imply SND_SOC_RT1308 imply SND_SOC_RT5514 + imply SND_SOC_RT5575 imply SND_SOC_RT5616 imply SND_SOC_RT5631 imply SND_SOC_RT5640@@ -1783,6 +1784,15 @@ config SND_SOC_RT5514_SPI_BUILTIN bool # force RT5514_SPI to be built-in to avoid link errors default SND_SOC_RT5514=y && SND_SOC_RT5514_SPI=m +config SND_SOC_RT5575 + tristate "Realtek ALC5575 Codec - I2C" + depends on I2C + +config SND_SOC_RT5575_SPI + tristate "Realtek ALC5575 Codec - SPI" + depends on SPI_MASTER && I2C + depends on SND_SOC_RT5575 + config SND_SOC_RT5616 tristate "Realtek RT5616 CODEC" depends on I2Csound/soc/codecs/Makefile +2
-0@@ -253,6 +253,8 @@ snd-soc-rt286-y := rt286.o snd-soc-rt298-y := rt298.o snd-soc-rt5514-y := rt5514.o snd-soc-rt5514-spi-y := rt5514-spi.o +snd-soc-rt5575-y := rt5575.o +snd-soc-rt5575-$(CONFIG_SND_SOC_RT5575_SPI) += rt5575-spi.o snd-soc-rt5616-y := rt5616.o snd-soc-rt5631-y := rt5631.o snd-soc-rt5640-y := rt5640.o@@ -686,6 +688,7 @@ obj-$(CONFIG_SND_SOC_RT298) +=snd-soc-rt298.o
sound/soc/codecs/Makefile obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o
Quoted 3 lines
sound/soc/codecs/Makefile +0
-0obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o obj-$(CONFIG_SND_SOC_RT5514_SPI_BUILTIN) +=snd-soc-rt5514-spi.o
Quoted 28 lines
sound/soc/codecs/Makefile +1
-0+obj-$(CONFIG_SND_SOC_RT5575) += snd-soc-rt5575.o obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.osound/soc/codecs/rt5575-spi.c new file +18
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5575-spi.c -- ALC5575 SPI driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#include <linux/firmware.h> +#include <linux/of.h> +#include <linux/spi/spi.h> + +#include "rt5575-spi.h" + +#define RT5575_SPI_CMD_BURST_WRITE 5 +#define RT5575_SPI_BUF_LEN 240 + +struct rt5575_spi_burst_write {sound/soc/codecs/rt5575-spi.c line 28
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+u8 cmd; +u32 addr; +u8 data[RT5575_SPI_BUF_LEN ]; +u8 dummy; +} __packed; + +struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +struct device_node *spi_np; +struct spi_controller *ctlr;Reorder to achieve reverse-christmas-tree notation. Waterfall to a number of functions found in this patch.
Quoted 32 lines
sound/soc/codecs/rt5575-spi.c new file +32
-0+struct spi_device *spi; +u32 cs; + + spi_np =of_parse_phandle (dev->of_node,"spi-parent" ,0 ); +if (!spi_np) { +dev_err (dev,"Failed to get spi-parent phandle\n" ); +return NULL ; + } + +if (of_property_read_u32_index (dev->of_node,"spi-parent" ,1 , &cs)) + cs =0 ; + +if (cs >= ctlr->num_chipselect) { +dev_err (dev,"Chip select has wrong number %d\n" , cs); +of_node_put (spi_np); +return NULL ; + } + + ctlr =of_find_spi_controller_by_node (spi_np); +of_node_put (spi_np); +if (!ctlr) +return NULL ; + + spi =spi_new_device (ctlr, &(struct spi_board_info ){ + .modalias ="rt5575" , + .chip_select = cs, + .max_speed_hz =10000000 , + }); + +spi_controller_put (ctlr); +return spi; +}sound/soc/codecs/rt5575-spi.c
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+ +/** +* rt5575_spi_burst_write - Write data to SPI by rt5575 address. +* @spi: SPI device. +* @addr: Start address. +* @txbuf: Data buffer for writing. +* @len: Data length. +* +*/ +static int rt5575_spi_burst_write(struct spi_device *spi, u32 addr, const u8*txbuf,
sound/soc/codecs/rt5575-spi.c line 71
Quoted 1 line
sound/soc/codecs/rt5575-spi.c new file +1
-0+ size_t len)Alignment or, just make it one-liner. It fits the limit.
sound/soc/codecs/rt5575-spi.c line 74
Quoted 3 lines
sound/soc/codecs/rt5575-spi.c new file +3
-0+{ +struct rt5575_spi_burst_write buf = { + .cmd =RT5575_SPI_CMD_BURST_WRITE Missing comma at the end.
Quoted 7 lines
sound/soc/codecs/rt5575-spi.c new file +7
-0+ }; +unsigned int end, offset =0 ; + +while (offset < len) { +if (offset +RT5575_SPI_BUF_LEN <= len) + end =RT5575_SPI_BUF_LEN ; +else sound/soc/codecs/rt5575-spi.c line 91
Quoted 10 lines
sound/soc/codecs/rt5575-spi.c new file +10
-0+ end = len %RT5575_SPI_BUF_LEN ; + + buf.addr =cpu_to_le32 (addr + offset); +memcpy (&buf.data, &txbuf[offset], end); +spi_write (spi, &buf,sizeof (buf)); + + offset +=RT5575_SPI_BUF_LEN ; + } + +return 0 ;If you intend on ignoring result of spi_write()s, then I see no reason why
rt5575_spi_burst_write()shouldn't be a void function.sound/soc/codecs/rt5575-spi.c
Quoted 13 lines
sound/soc/codecs/rt5575-spi.c new file +13
-0+} + +int rt5575_spi_fw_load (struct spi_device *spi) +{ +const struct firmware *firmware; +struct device *dev = &spi->dev; +static const char *const fw_path[] = { +"realtek/rt5575/rt5575_fw1.bin" , +"realtek/rt5575/rt5575_fw2.bin" , +"realtek/rt5575/rt5575_fw3.bin" , +"realtek/rt5575/rt5575_fw4.bin" + }; +static const u32 fw_addr[] = {0x5f400000 ,0x5f600000 ,0x5f7fe000 ,
0x5f7ff000};sound/soc/codecs/rt5575-spi.c line 108
Quoted 4 lines
sound/soc/codecs/rt5575-spi.c new file +4
-0+int i, ret; + +for (i =0 ; i <ARRAY_SIZE (fw_addr); i++) { + ret =request_firmware (&firmware, fw_path[i], dev);So, in v8 or earlier the ordering of operations was different:
request_firmware(fw1); regmap_write(); regmap_write(); regmap_write(); rt5575_spi_burst_write(); release_firmware(fw1); /* Proceed with loop for the remaining fw2, fw3, fw4. */
Quoted 1 line
What changed that suddenly the ordering could be simplified?
Originally, request_firmware_nowait was used when the driver built into the kernel image and the firmwares was in filesystem. In order to match the following flow, if the driver is built into the kernel image, the firmwares should also be built into the kernel image.
1) boot I2C, init regmaps
2) boot SPI, load firmware
3) register ASoC component if 1) and 2) succeed
Quoted 224 lines
sound/soc/codecs/rt5575-spi.c line 110
Quoted 2 lines
sound/soc/codecs/rt5575-spi.c new file +2
-0+if (!ret) { + rt5575_spi_burst_write(spi, fw_addr[i],
firmware->data,firmware->size);sound/soc/codecs/rt5575-spi.c
Quoted 3 lines
sound/soc/codecs/rt5575-spi.c new file +3
-0+release_firmware (firmware); + }else { + dev_err(dev, "Request firmware failure: %d\n",ret);
sound/soc/codecs/rt5575-spi.c line 115
Quoted 2 lines
sound/soc/codecs/rt5575-spi.c new file +2
-0+return ret; + }Please refactor this construct. When facing else-return, favour returning early to reduce indentation and make it easier to read the code.
if (ret) { dev_err(); return ret; } rt5575_spi_burst_write(); release_firmware();Much better, isn't it?
Quoted 19 lines
sound/soc/codecs/rt5575-spi.c new file +4
-0+ } + +return 0 ; +}sound/soc/codecs/rt5575-spi.h new file +9
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* rt5575-spi.h -- ALC5575 SPI driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#ifndef __RT5575_SPI_H__sound/soc/codecs/rt5575-spi.h line 19
Quoted 10 lines
sound/soc/codecs/rt5575-spi.h new file +10
-0+#define __RT5575_SPI_H__ + +#if IS_ENABLED (CONFIG_SND_SOC_RT5575_SPI ) +struct spi_device *rt5575_spi_get_device (struct device *dev); +int rt5575_spi_fw_load (struct spi_device *spi); +#else +static inline struct spi_device *rt5575_spi_get_device (struct device *dev) +{ +return NULL ; +}Missing newline.
Quoted 27 lines
sound/soc/codecs/rt5575-spi.h new file +7
-0+static inline int rt5575_spi_fw_load (struct spi_device *spi) +{ +return -EINVAL ; +} +#endif + +#endif /* __RT5575_SPI_H__ */ sound/soc/codecs/rt5575.c new file +14
-0@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* rt5575.c -- ALC5575 ALSA SoC audio component driver +* +* Copyright(c) 2025 Realtek Semiconductor Corp. +* +*/ + +#include <linux/i2c.h> +#include <sound/soc.h> +#include <sound/tlv.h> + +#include "rt5575.h" +#include "rt5575-spi.h" (...)
Quoted 1 line
+static int rt5575_i2c_read(void *context, unsigned int reg, unsigned int
*val)
sound/soc/codecs/rt5575.c
Quoted 5 lines
sound/soc/codecs/rt5575.c new file +5
-0+{ +struct i2c_client *client = context; +struct rt5575_priv *rt5575 =i2c_get_clientdata (client); + + regmap_read(rt5575->dsp_regmap, reg | RT5575_DSP_MAPPING,val);
sound/soc/codecs/rt5575.c
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+ +return 0 ; +} + +static int rt5575_i2c_write (void *context,unsigned int reg,unsigned int val) +{ +struct i2c_client *client = context; +struct rt5575_priv *rt5575 =i2c_get_clientdata (client); + + regmap_write(rt5575->dsp_regmap, reg | RT5575_DSP_MAPPING,val);
sound/soc/codecs/rt5575.c
Quoted 2 lines
sound/soc/codecs/rt5575.c new file +2
-0+ +return 0 ;Not an expect in regmap, but I'd leave decision to the caller whether to squelch an error or not.
For both, rt5575_i2c_read()/write() I'd just return the corresponding
regmap_xxx()operation rather then '0'.Quoted 15 lines
sound/soc/codecs/rt5575.c new file +15
-0+} + +static const struct regmap_config rt5575_regmap = { + .reg_bits =16 , + .val_bits =32 , + .reg_stride =4 , + .max_register =0xfffc , + .readable_reg = rt5575_readable_register, + .reg_read = rt5575_i2c_read, + .reg_write = rt5575_i2c_write, + .use_single_read = true, + .use_single_write = true, +}; + +static int rt5575_fw_load_by_spi (struct rt5575_priv *rt5575)sound/soc/codecs/rt5575.c
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+{ + struct i2c_client *i2c = rt5575->i2c; + struct spi_device *spi; + struct device *dev = &i2c->dev; + int ret; + + spi = rt5575_spi_get_device(dev); + if (!spi) { + dev_warn(dev, "The spi-parent not described in the DTS\n" + "The hardware configuration should bewith built-in flash\n");
sound/soc/codecs/rt5575.c
Quoted 3 lines
sound/soc/codecs/rt5575.c new file +3
-0+ +if (!IS_ENABLED (CONFIG_SND_SOC_RT5575_SPI )) + dev_warn(dev, "If the spi-parent is set in the DTSand it is without built-in flash\n"
Quoted 1 line
+ "Please enable
CONFIG_SND_SOC_RT5575_SPI\n");
Does this mean we always get a warning, even in case when we're dealing with non-SPI variant?
Quoted 8 lines
sound/soc/codecs/rt5575.c new file +8
-0+ +return -ENXIO ; + } + +regmap_write (rt5575->dsp_regmap,0xfafafafa ,0x00000004 ); +regmap_write (rt5575->dsp_regmap,0x18008064 ,0x00000000 ); +regmap_write (rt5575->dsp_regmap,0x18008068 ,0x0002ffff ); +sound/soc/codecs/rt5575.c
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+ ret =rt5575_spi_fw_load (spi); +if (ret) { +dev_err (dev,"Load firmware failure: %d\n" , ret); +return -ENODEV ; + } + +regmap_write (rt5575->dsp_regmap,0x18000000 ,0x00000000 ); +regmap_update_bits (rt5575->regmap,RT5575_SW_INT ,1 ,1 ); + + regmap_read_poll_timeout(rt5575->regmap, RT5575_SW_INT,ret, !ret, 100000, 10000000);
Quoted 13 lines
sound/soc/codecs/rt5575.c new file +13
-0+if (ret) { +dev_err (dev,"Run firmware failure: %d\n" , ret); +return -ENODEV ; + } + +return 0 ; +} + +static int rt5575_i2c_probe (struct i2c_client *i2c) +{ +struct rt5575_priv *rt5575; +struct device *dev = &i2c->dev; +int ret, val;sound/soc/codecs/rt5575.c
Quoted 10 lines
sound/soc/codecs/rt5575.c new file +10
-0+ + rt5575 =devm_kzalloc (dev,sizeof (struct rt5575_priv ),GFP_KERNEL ); +if (!rt5575) +return -ENOMEM ; + +i2c_set_clientdata (i2c, rt5575); + + rt5575->i2c = i2c; + + rt5575->dsp_regmap = devm_regmap_init_i2c(i2c,
&rt5575_dsp_regmap);sound/soc/codecs/rt5575.c
Quoted 3 lines
sound/soc/codecs/rt5575.c new file +3
-0+if (IS_ERR (rt5575->dsp_regmap)) { + ret =PTR_ERR (rt5575->dsp_regmap); + dev_err(dev, "Failed to allocate DSP register map: %d\n",ret);
sound/soc/codecs/rt5575.c
Quoted 4 lines
sound/soc/codecs/rt5575.c new file +4
-0+return ret; + } + + rt5575->regmap = devm_regmap_init(dev, NULL, i2c,
&rt5575_regmap);sound/soc/codecs/rt5575.c
Quoted 9 lines
sound/soc/codecs/rt5575.c new file +9
-0+if (IS_ERR (rt5575->regmap)) { + ret =PTR_ERR (rt5575->regmap); +dev_err (dev,"Failed to allocate register map: %d\n" , ret); +return ret; + } + +regmap_read (rt5575->regmap,RT5575_ID , &val); +if (val !=RT5575_DEVICE_ID ) { + dev_err(dev, "Device with ID register %08x is not rt5575\n",val);
sound/soc/codecs/rt5575.c line 322
Quoted 5 lines
sound/soc/codecs/rt5575.c new file +5
-0+return -ENODEV ; + } + +regmap_read (rt5575->regmap,RT5575_ID_1 , &val); +if (!val) {1. The '
RT5575_DEVICE_ID' check above fails, 'val' equalsRT5575_DEVICE_ID, non-zero.
2.regmap_read(RT5575_ID_1)fails, let's skip the reasoning for now. 'val' remains unchanged.
3. The '!val' check fails though nothing has been actually read, 'val' could be simply invalid.
Quoted 2 lines
What's the goal of this check? Shouldn't we be more precise when checking the 'formal version'?
Since there is no in-formal version available, the formal version check will be removed.