Skip to contentSkip to conversation

Cirrus Logic family of ADCs

PATCH Superseded Paul Handrigan 3 participants 8 messages Jun 7, 2024 – Jun 14, 2024

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Cirrus Logic family of ADCs

This patchset provides ASoC support for the latest family of Cirrus Logic multichannel, high performance audio ADCs. The devices that are supported are CS5302 (2 channel ADC), CS5304 (4 channel ADC), and CS5308 (8 channel ADC).

Please note that this driver only supports I2C control with SPI control to be added later.

Paul Handrigan (2):
ASoC: dt-bindings: cirrus,cs530x: Add initial DT binding
ASoC: cs530x: Support for cs530x ADCs

 .../bindings/sound/cirrus,cs530x.yaml         |  83 ++
 sound/soc/codecs/Kconfig                      |  14 +
 sound/soc/codecs/Makefile                     |   4 +
 sound/soc/codecs/cs530x-i2c.c                 |  89 ++
 sound/soc/codecs/cs530x.c                     | 991 ++++++++++++++++++
 sound/soc/codecs/cs530x.h                     | 223 ++++
 6 files changed, 1404 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml
 create mode 100644 sound/soc/codecs/cs530x-i2c.c
 create mode 100644 sound/soc/codecs/cs530x.c
 create mode 100644 sound/soc/codecs/cs530x.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 ASoC: dt-bindings: cirrus,cs530x: Add initial DT binding

Add the YAML DT bindings for the cs530x high performance audio ADCs.

---
 .../bindings/sound/cirrus,cs530x.yaml         | 83 +++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +83 -0
new file mode 100644
index 000000000000..a4e2493ff03e
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cirrus,cs530x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic cs530x family of audio ADCs
+
+maintainers:
+  - [email protected]
+  - [email protected]
+
+description: |
+  The CS530X devices are a family of high performance audio ADCs.
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs5302
+      - cirrus,cs5304
+      - cirrus,cs5308
+  reg:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    description:
+      The first cell indicating the audio interface.
+    const: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  vdd-a-supply:
+    description: voltage regulator phandle for the vdd-a supply
+
+  vdd-io-supply:
+    description: voltage regulator phandle for the vdd-io supply
+
+  cirrus,in_hiz_pin12:
+    description:
+      Sets input channels one and two to high impedence.
+    type: boolean
+
+  cirrus,in_hiz_pin34:
+    description:
+      Sets input channels three and four to high impedence.
+    type: boolean
+
+  cirrus,in_hiz_pin56:
+    description:
+      Sets input channels five and six to high impedence.
+    type: boolean
+
+  cirrus,in_hiz_pin78:
+    description:
+      Sets input channels seven and eight to high impedence.
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - "#sound-dai-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        cs5304: adc@48 {
+            #sound-dai-cells = <1>;
+            compatible = "cirrus,cs5304";
+            reg = <0x48>;
+            vdd-a-supply = <&vreg>;
+            vdd-io-supply = <&vreg>;
+            reset-gpios = <&gpio 110 GPIO_ACTIVE_HIGH>;
+            cirrus,in_hiz_pin34;
+        };
+    };
Signature · 1 line
2.34.1
#3 lore raw

PATCH 2/2 ASoC: cs530x: Support for cs530x ADCs

In reply to Paul Handrigan

Add support for the cs530x family of high performance ADCs.

---
 sound/soc/codecs/Kconfig      |  14 +
 sound/soc/codecs/Makefile     |   4 +
 sound/soc/codecs/cs530x-i2c.c |  89 +++
 sound/soc/codecs/cs530x.c     | 991 ++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs530x.h     | 223 ++++++++
 5 files changed, 1321 insertions(+)
 create mode 100644 sound/soc/codecs/cs530x-i2c.c
 create mode 100644 sound/soc/codecs/cs530x.c
 create mode 100644 sound/soc/codecs/cs530x.h
sound/soc/codecs/Kconfig +14 -0
index 3621781d63c4..8745ba193595 100644
@@ -99,6 +99,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS47L90
 	imply SND_SOC_CS47L92
 	imply SND_SOC_CS53L30
+	imply SND_SOC_CS530X_I2C
 	imply SND_SOC_CX20442
 	imply SND_SOC_CX2072X
 	imply SND_SOC_DA7210
@@ -998,6 +999,19 @@ config SND_SOC_CS53L30
 	tristate "Cirrus Logic CS53L30 CODEC"
 	depends on I2C
 
+config SND_SOC_CS530X
+	tristate
+
+config SND_SOC_CS530X_I2C
+	tristate "Cirrus Logic CS530x ADCs (I2C)"
+	depends on I2C
+	select REGMAP
+	select REGMAP_I2C
+	select SND_SOC_CS530X
+	help
+	  Enable support for Cirrus Logic CS530X ADCs
+	  with I2C control.
+
 config SND_SOC_CX20442
 	tristate
 	depends on TTY
sound/soc/codecs/Makefile +4 -0
index d343d23c8f0f..3e08862d10e9 100644
@@ -107,6 +107,8 @@ snd-soc-cs47l85-y := cs47l85.o
 snd-soc-cs47l90-y := cs47l90.o
 snd-soc-cs47l92-y := cs47l92.o
 snd-soc-cs53l30-y := cs53l30.o
+snd-soc-cs530x-y := cs530x.o
+snd-soc-cs530x-i2c-y := cs530x-i2c.o
 snd-soc-cx20442-y := cx20442.o
 snd-soc-cx2072x-y := cx2072x.o
 snd-soc-da7210-y := da7210.o
@@ -506,6 +508,8 @@ obj-$(CONFIG_SND_SOC_CS47L85)	+= snd-soc-cs47l85.o
 obj-$(CONFIG_SND_SOC_CS47L90)	+= snd-soc-cs47l90.o
 obj-$(CONFIG_SND_SOC_CS47L92)	+= snd-soc-cs47l92.o
 obj-$(CONFIG_SND_SOC_CS53L30)	+= snd-soc-cs53l30.o
+obj-$(CONFIG_SND_SOC_CS530X)	+= snd-soc-cs530x.o
+obj-$(CONFIG_SND_SOC_CS530X_I2C)	+= snd-soc-cs530x-i2c.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_CX2072X)	+= snd-soc-cx2072x.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
sound/soc/codecs/cs530x-i2c.c new file +89 -0

89 lines not on this page · raw message

sound/soc/codecs/cs530x.c new file +991 -0

991 lines not on this page · raw message

sound/soc/codecs/cs530x.h new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/2] ASoC: cs530x: Support for cs530x ADCs

kernel test robot noticed the following build warnings:

Hi Paul,

kernel test robot noticed the following build warnings:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master v6.10-rc2 next-20240607] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Paul-Handrigan/ASoC-dt-bindings-cirrus-cs530x-Add-initial-DT-binding/20240608-042903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20240607202708.335752-3-paulha%40opensource.cirrus.com
patch subject: [PATCH 2/2] ASoC: cs530x: Support for cs530x ADCs
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20240609/[email protected]/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project d7d2d4f53fc79b4b58e8d8d08151b577c3699d4a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240609/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from sound/soc/codecs/cs530x-i2c.c:8:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/s390/include/asm/elf.h:173:
In file included from arch/s390/include/asm/mmu_context.h:11:
In file included from arch/s390/include/asm/pgalloc.h:18:
In file included from include/linux/mm.h:2253:
include/linux/vmstat.h:500:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]

     500 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     501 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:507:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     507 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     508 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:519:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     519 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     520 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:528:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     528 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     529 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   In file included from sound/soc/codecs/cs530x-i2c.c:11:
   In file included from include/linux/regmap.h:20:
   In file included from include/linux/iopoll.h:14:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
         |                                                           ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
     102 | #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
         |                                                      ^
   In file included from sound/soc/codecs/cs530x-i2c.c:11:
   In file included from include/linux/regmap.h:20:
   In file included from include/linux/iopoll.h:14:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                                                           ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
     115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
         |                                                      ^
   In file included from sound/soc/codecs/cs530x-i2c.c:11:
   In file included from include/linux/regmap.h:20:
   In file included from include/linux/iopoll.h:14:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
>> sound/soc/codecs/cs530x-i2c.c:64:21: warning: cast to smaller integer type 'enum cs530x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
      64 |                 cs530x->devtype = (enum cs530x_type)match->data;
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

18 warnings generated.

vim +64 sound/soc/codecs/cs530x-i2c.c

    37	
    38	static int cs530x_i2c_probe(struct i2c_client *client)
    39	{
    40		struct cs530x_priv *cs530x;
    41		int ret;
    42	
    43		cs530x = devm_kzalloc(&client->dev, sizeof(struct cs530x_priv),
    44				       GFP_KERNEL);
    45		if (!cs530x)
    46			return -ENOMEM;
    47	
    48		i2c_set_clientdata(client, cs530x);
    49	
    50		cs530x->regmap = devm_regmap_init_i2c(client, &cs530x_regmap);
    51		if (IS_ERR(cs530x->regmap)) {
    52			ret = PTR_ERR(cs530x->regmap);
    53			dev_err(&client->dev, "Failed to allocate register map: %d\n",
    54				ret);
    55			return ret;
    56		}
    57	
    58		if (client->dev.of_node) {
    59			const struct of_device_id *match;
    60	
    61			match = of_match_node(cs530x_of_match, client->dev.of_node);
    62			if (match == NULL)
    63				return -EINVAL;
  > 64			cs530x->devtype = (enum cs530x_type)match->data;
    65		} else {
    66			const struct i2c_device_id *id =
    67				i2c_match_id(cs530x_i2c_id, client);
    68	
    69			cs530x->devtype = id->driver_data;
    70		}
    71	
    72		cs530x->dev = &client->dev;
    73	
    74		return cs530x_probe(cs530x);
    75	}
    76	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH 2/2] ASoC: cs530x: Support for cs530x ADCs

In reply to Paul Handrigan
Quoted 109 lines · Paul Handrigan

Add support for the cs530x family of high performance ADCs.

---

 sound/soc/codecs/Kconfig      |  14 +
 sound/soc/codecs/Makefile     |   4 +
 sound/soc/codecs/cs530x-i2c.c |  89 +++
 sound/soc/codecs/cs530x.c     | 991 ++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs530x.h     | 223 ++++++++
 5 files changed, 1321 insertions(+)
 create mode 100644 sound/soc/codecs/cs530x-i2c.c
 create mode 100644 sound/soc/codecs/cs530x.c
 create mode 100644 sound/soc/codecs/cs530x.h
sound/soc/codecs/Kconfig +14 -0
index 3621781d63c4..8745ba193595 100644
@@ -99,6 +99,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS47L90
 	imply SND_SOC_CS47L92
 	imply SND_SOC_CS53L30
+	imply SND_SOC_CS530X_I2C
 	imply SND_SOC_CX20442
 	imply SND_SOC_CX2072X
 	imply SND_SOC_DA7210
@@ -998,6 +999,19 @@ config SND_SOC_CS53L30
 	tristate "Cirrus Logic CS53L30 CODEC"
 	depends on I2C
 
+config SND_SOC_CS530X
+	tristate
+
+config SND_SOC_CS530X_I2C
+	tristate "Cirrus Logic CS530x ADCs (I2C)"
+	depends on I2C
+	select REGMAP
+	select REGMAP_I2C
+	select SND_SOC_CS530X
+	help
+	  Enable support for Cirrus Logic CS530X ADCs
+	  with I2C control.
+
 config SND_SOC_CX20442
 	tristate
 	depends on TTY
sound/soc/codecs/Makefile +4 -0
index d343d23c8f0f..3e08862d10e9 100644
@@ -107,6 +107,8 @@ snd-soc-cs47l85-y := cs47l85.o
 snd-soc-cs47l90-y := cs47l90.o
 snd-soc-cs47l92-y := cs47l92.o
 snd-soc-cs53l30-y := cs53l30.o
+snd-soc-cs530x-y := cs530x.o
+snd-soc-cs530x-i2c-y := cs530x-i2c.o
 snd-soc-cx20442-y := cx20442.o
 snd-soc-cx2072x-y := cx2072x.o
 snd-soc-da7210-y := da7210.o
@@ -506,6 +508,8 @@ obj-$(CONFIG_SND_SOC_CS47L85)	+= snd-soc-cs47l85.o
 obj-$(CONFIG_SND_SOC_CS47L90)	+= snd-soc-cs47l90.o
 obj-$(CONFIG_SND_SOC_CS47L92)	+= snd-soc-cs47l92.o
 obj-$(CONFIG_SND_SOC_CS53L30)	+= snd-soc-cs53l30.o
+obj-$(CONFIG_SND_SOC_CS530X)	+= snd-soc-cs530x.o
+obj-$(CONFIG_SND_SOC_CS530X_I2C)	+= snd-soc-cs530x-i2c.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_CX2072X)	+= snd-soc-cx2072x.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
sound/soc/codecs/cs530x-i2c.c new file +33 -0
new file mode 100644
index 000000000000..b2f808ee6f37
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// CS530x CODEC driver
+//
+// Copyright (C) 2024 Cirrus Logic, Inc. and
+//                    Cirrus Logic International Semiconductor Ltd.
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+
+#include "cs530x.h"
+
+static const struct of_device_id cs530x_of_match[] = {
+	{
+		.compatible = "cirrus,cs5302",
+		.data = (void *)CS5302,
+	}, {
+		.compatible = "cirrus,cs5304",
+		.data = (void *)CS5304,
+	}, {
+		.compatible = "cirrus,cs5308",
+		.data = (void *)CS5308,
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, cs530x_of_match);
+
+static const struct i2c_device_id cs530x_i2c_id[] = {
+	{ "cs5302", CS5302 },
+	{ "cs5304", CS5304 },
+	{ "cs5308", CS5308 },

sound/soc/codecs/cs530x-i2c.c line 43

Quoted 10 lines
sound/soc/codecs/cs530x-i2c.c new file +10 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, cs530x_i2c_id);
+
+static int cs530x_i2c_probe(struct i2c_client *client)
+{
+	struct cs530x_priv *cs530x;
+	int ret;
+
+	cs530x = devm_kzalloc(&client->dev, sizeof(struct cs530x_priv),

sizeof(*)

I think you try to upstream some older code... please always use some new kernel drivers, which are cleaned up from trivialities, for new work.

Quoted 11 lines
sound/soc/codecs/cs530x-i2c.c new file +11 -0
+			       GFP_KERNEL);
+	if (!cs530x)
+		return -ENOMEM;
+
+	i2c_set_clientdata(client, cs530x);
+
+	cs530x->regmap = devm_regmap_init_i2c(client, &cs530x_regmap);
+	if (IS_ERR(cs530x->regmap)) {
+		ret = PTR_ERR(cs530x->regmap);
+		dev_err(&client->dev, "Failed to allocate register map: %d\n",
+			ret);

sound/soc/codecs/cs530x-i2c.c line 64

Quoted 10 lines
sound/soc/codecs/cs530x-i2c.c new file +10 -0
+		return ret;
+	}
+
+	if (client->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_node(cs530x_of_match, client->dev.of_node);
+		if (match == NULL)
+			return -EINVAL;
+		cs530x->devtype = (enum cs530x_type)match->data;

I think you open-coded device_get_match_data

sound/soc/codecs/cs530x-i2c.c line 70

Quoted 6 lines
sound/soc/codecs/cs530x-i2c.c new file +6 -0
+	} else {
+		const struct i2c_device_id *id =
+			i2c_match_id(cs530x_i2c_id, client);
+
+		cs530x->devtype = id->driver_data;
+	}

and for all of this there is a helper i2c_get_device_match_data.

Quoted 21 lines
sound/soc/codecs/cs530x-i2c.c new file +19 -0
+
+	cs530x->dev = &client->dev;
+
+	return cs530x_probe(cs530x);
+}
+
+static struct i2c_driver cs530x_i2c_driver = {
+	.driver = {
+		.name = "cs530x",
+		.of_match_table = cs530x_of_match,
+	},
+	.probe = cs530x_i2c_probe,
+	.id_table = cs530x_i2c_id,
+};
+module_i2c_driver(cs530x_i2c_driver);
+
 
 
+
+int cs530x_probe(struct cs530x_priv *cs530x)
+{

sound/soc/codecs/cs530x-i2c.c

Quoted 10 lines
sound/soc/codecs/cs530x-i2c.c new file +10 -0
+	struct device *dev = cs530x->dev;
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(cs530x->supplies); i++)
+		cs530x->supplies[i].supply = cs530x_supply_names[i];
+
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs530x->supplies),
+				      cs530x->supplies);
+	if (ret != 0) {
+		dev_err(dev, "Failed to request supplies: %d\n", ret);

return dev_err_probe()

sound/soc/codecs/cs530x-i2c.c

Quoted 7 lines
sound/soc/codecs/cs530x-i2c.c new file +7 -0
+		return ret;
+	}
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(cs530x->supplies),
+				    cs530x->supplies);
+	if (ret != 0) {
+		dev_err(dev, "Failed to enable supplies: %d\n", ret);

return dev_err_probe()

sound/soc/codecs/cs530x-i2c.c

Quoted 7 lines
sound/soc/codecs/cs530x-i2c.c new file +7 -0
+		return ret;
+	}
+
+	cs530x->reset_gpio = devm_gpiod_get_optional(dev, "reset-gpios",
+						      GPIOD_OUT_LOW);
+	if (IS_ERR(cs530x->reset_gpio)) {
+		dev_err(dev, "Reset gpio not available\n");

return dev_err_probe()

sound/soc/codecs/cs530x-i2c.c

Quoted 7 lines
sound/soc/codecs/cs530x-i2c.c new file +7 -0
+		ret = PTR_ERR(cs530x->reset_gpio);
+		goto err_regulator;
+	}
+
+	if (cs530x->reset_gpio) {
+		usleep_range(2000, 2100);
+		gpiod_set_value_cansleep(cs530x->reset_gpio, 1);

1 is to keep device in reset? This looks like you are using logical values inverted.

Quoted 12 lines
sound/soc/codecs/cs530x-i2c.c new file +12 -0
+	}
+
+	usleep_range(5000, 5100);
+	ret = cs530x_check_device_id(cs530x);
+	if (ret)
+		goto err_reset;
+
+	if (!cs530x->reset_gpio) {
+		ret = regmap_write(cs530x->regmap, CS530X_SW_RESET,
+				   CS530X_SW_RST_VAL);
+		if (ret) {
+			dev_err(dev, "Soft Reset write failed %d\n", ret);

sound/soc/codecs/cs530x-i2c.c

Quoted 10 lines
sound/soc/codecs/cs530x-i2c.c new file +10 -0
+			goto err_reset;
+		}
+	}
+
+	ret = cs530x_parse_device_properties(cs530x);
+	if (ret)
+		goto err_reset;
+
+	cs530x->dev_dai = devm_kmemdup(dev, &cs530x_dai,
+					sizeof(struct snd_soc_dai_driver),

sizeof(*)

sound/soc/codecs/cs530x-i2c.c

Quoted 6 lines
sound/soc/codecs/cs530x-i2c.c new file +6 -0
+					GFP_KERNEL);
+	if (!cs530x->dev_dai) {
+		ret = -ENOMEM;
+		goto err_reset;
+	}
+

Best regards,
Krzysztof

#2 lore raw

Re: [PATCH 1/2] ASoC: dt-bindings: cirrus,cs530x: Add initial DT binding

In reply to Paul Handrigan
Quoted 15 lines · Paul Handrigan

Add the YAML DT bindings for the cs530x high performance audio ADCs.

---
 .../bindings/sound/cirrus,cs530x.yaml         | 83 +++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +0 -0
new file mode 100644
index 000000000000..a4e2493ff03e

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 10

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +10 -0
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cirrus,cs530x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic cs530x family of audio ADCs
+
+maintainers:
+  - [email protected]

Please provide full name here.

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 13

Quoted 3 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +3 -0
+  - [email protected]
+
+description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 21

Quoted 8 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +8 -0
+  The CS530X devices are a family of high performance audio ADCs.
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs5302
+      - cirrus,cs5304
+      - cirrus,cs5308

Blank line

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 27

Quoted 6 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +6 -0
+  reg:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    description:
+      The first cell indicating the audio interface.

Drop description, it's obvious.

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 34

Quoted 7 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +7 -0
+    const: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  vdd-a-supply:
+    description: voltage regulator phandle for the vdd-a supply

Drop redundant parts "voltage regulator phandle" and say what supply is it. Do not describe DT syntax but hardware.

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 39

Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +5 -0
+
+  vdd-io-supply:
+    description: voltage regulator phandle for the vdd-io supply
+
+  cirrus,in_hiz_pin12:

No underscores in node names.

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 41

Quoted 2 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +2 -0
+    description:
+      Sets input channels one and two to high impedence.

Typo

Quoted 12 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +12 -0
+    type: boolean
+
+  cirrus,in_hiz_pin34:
+    description:
+      Sets input channels three and four to high impedence.
+    type: boolean
+
+  cirrus,in_hiz_pin56:
+    description:
+      Sets input channels five and six to high impedence.
+    type: boolean
+

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +10 -0
+  cirrus,in_hiz_pin78:
+    description:
+      Sets input channels seven and eight to high impedence.
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - "#sound-dai-cells"
+

Missing ref to dai-common

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 64

Quoted 1 line
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +1 -0
+additionalProperties: false

This should be unevaluatedProperties instead

Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml line 77

Quoted 13 lines
Documentation/devicetree/bindings/sound/cirrus,cs530x.yaml new file +13 -0
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        cs5304: adc@48 {
+            #sound-dai-cells = <1>;
+            compatible = "cirrus,cs5304";
+            reg = <0x48>;

compatible is *always* the first property. reg is the second.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH 2/2] ASoC: cs530x: Support for cs530x ADCs

In reply to Krzysztof Kozlowski
Quoted 5 lines · Krzysztof Kozlowski

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	cs530x = devm_kzalloc(&client->dev, sizeof(struct cs530x_priv),

sizeof(*)

Ack

Quoted 12 lines

sound/soc/codecs/cs530x-i2c.c line 64

Quoted 8 lines
sound/soc/codecs/cs530x-i2c.c new file +8 -0
+
+	if (client->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_node(cs530x_of_match, client->dev.of_node);
+		if (match == NULL)
+			return -EINVAL;
+		cs530x->devtype = (enum cs530x_type)match->data;

I think you open-coded device_get_match_data

Quoted 9 lines

sound/soc/codecs/cs530x-i2c.c line 70

Quoted 6 lines
sound/soc/codecs/cs530x-i2c.c new file +6 -0
+	} else {
+		const struct i2c_device_id *id =
+			i2c_match_id(cs530x_i2c_id, client);
+
+		cs530x->devtype = id->driver_data;
+	}

and for all of this there is a helper i2c_get_device_match_data.

Ack

Quoted 4 lines

sound/soc/codecs/cs530x.c line 917

Quoted 2 lines
sound/soc/codecs/cs530x.c new file +2 -0
+	if (ret != 0) {
+		dev_err(dev, "Failed to request supplies: %d\n", ret);

return dev_err_probe()

Ack

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (ret != 0) {
+		dev_err(dev, "Failed to enable supplies: %d\n", ret);

return dev_err_probe()

Ack

Quoted 4 lines

sound/soc/codecs/cs530x.c line 931

Quoted 2 lines
sound/soc/codecs/cs530x.c new file +2 -0
+	if (IS_ERR(cs530x->reset_gpio)) {
+		dev_err(dev, "Reset gpio not available\n");

return dev_err_probe()

Ack

Quoted 7 lines

sound/soc/codecs/cs530x.c line 938

Quoted 4 lines
sound/soc/codecs/cs530x.c new file +4 -0
+
+	if (cs530x->reset_gpio) {
+		usleep_range(2000, 2100);
+		gpiod_set_value_cansleep(cs530x->reset_gpio, 1);

1 is to keep device in reset? This looks like you are using logical values inverted.

Thanks. The reset pin is active low. I will also change the dt binding example to reflect that.

Quoted 6 lines

sound/soc/codecs/cs530x.c line 960

Quoted 3 lines
sound/soc/codecs/cs530x.c new file +3 -0
+
+	cs530x->dev_dai = devm_kmemdup(dev, &cs530x_dai,
+					sizeof(struct snd_soc_dai_driver),

sizeof(*)

Ack

Regards,
Paul

#7 lore raw

Re: [PATCH 2/2] ASoC: cs530x: Support for cs530x ADCs

Quoted 11 lines · Paul Handrigan
Quoted 7 lines · Krzysztof Kozlowski

sound/soc/codecs/cs530x.c line 938

Quoted 4 lines
sound/soc/codecs/cs530x.c new file +4 -0
+
+	if (cs530x->reset_gpio) {
+		usleep_range(2000, 2100);
+		gpiod_set_value_cansleep(cs530x->reset_gpio, 1);

1 is to keep device in reset? This looks like you are using logical values inverted.

Thanks. The reset pin is active low. I will also change the dt binding example to reflect that.

The value here is logical from driver point of view, not wire level, so you use wrong code.

If you tested it with real and correct DTS, you would see it does not work.

Best regards,
Krzysztof