Skip to contentSkip to conversation

Add cs42l43 PC focused SoundWire CODEC

PATCH Superseded Charles Keepax 8 participants 57 messages May 12, 2023 – May 19, 2023

Subsystems (12)
Device tree bindings Sound ASoC GPIO +8 more subsystems

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Charles Keepax

author maintainer
#0 lore raw

cover Add cs42l43 PC focused SoundWire CODEC

This patch chain adds support for the Cirrus Logic cs42l43 PC focused SoundWire CODEC. Some supporting work is included in the chain, including adding an ASoC control notification helper function and adding support for IRQs generated by the in-band SoundWire alert mechanism.

The chain is currently based of v6.4-rc1 because I am not 100% sure which tree we want to send everything through. The CODEC support has a build dependency on both the SoundWire change and the ASoC soc-component change.

Thanks,
Charles

Charles Keepax (8):
ASoC: soc-component: Add notify control helper function
ASoC: ak4118: Update to use new component control notify helper
ASoC: wm_adsp: Update to use new component control notify helepr
dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding
mfd: cs42l43: Add support for cs42l43 core driver irqchip/cs42l43: Add support for the cs42l43 IRQs
pinctrl: cs42l43: Add support for the cs42l43
ASoC: cs42l43: Add support for the cs42l43

Lucas Tanure (2):
soundwire: bus: Allow SoundWire peripherals to register IRQ handlers
spi: cs42l43: Add SPI controller support

 .../bindings/mfd/cirrus,cs42l43.yaml          |  212 ++
 MAINTAINERS                                   |    7 +
 drivers/irqchip/Kconfig                       |    9 +
 drivers/irqchip/Makefile                      |    1 +
 drivers/irqchip/irq-cs42l43.c                 |  170 ++
 drivers/mfd/Kconfig                           |   23 +
 drivers/mfd/Makefile                          |    3 +
 drivers/mfd/cs42l43-i2c.c                     |   86 +
 drivers/mfd/cs42l43-sdw.c                     |  210 ++
 drivers/mfd/cs42l43.c                         | 1044 ++++++++
 drivers/mfd/cs42l43.h                         |   23 +
 drivers/pinctrl/cirrus/Kconfig                |   11 +
 drivers/pinctrl/cirrus/Makefile               |    2 +
 drivers/pinctrl/cirrus/pinctrl-cs42l43.c      |  614 +++++
 drivers/soundwire/bus.c                       |   31 +
 drivers/soundwire/bus_type.c                  |   12 +
 drivers/spi/Kconfig                           |    7 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-cs42l43.c                     |  287 +++
 include/linux/irqchip/cs42l43.h               |   61 +
 include/linux/mfd/cs42l43-regs.h              | 1172 +++++++++
 include/linux/mfd/cs42l43.h                   |   50 +
 include/linux/soundwire/sdw.h                 |    9 +
 include/sound/cs42l43.h                       |   84 +
 include/sound/soc-component.h                 |    4 +
 sound/soc/codecs/Kconfig                      |   16 +
 sound/soc/codecs/Makefile                     |    4 +
 sound/soc/codecs/ak4118.c                     |   11 +-
 sound/soc/codecs/cs42l43-jack.c               |  946 +++++++
 sound/soc/codecs/cs42l43-sdw.c                |   75 +
 sound/soc/codecs/cs42l43.c                    | 2270 +++++++++++++++++
 sound/soc/codecs/cs42l43.h                    |  117 +
 sound/soc/codecs/wm_adsp.c                    |   20 +-
 sound/soc/soc-component.c                     |   22 +
 34 files changed, 7586 insertions(+), 28 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml
 create mode 100644 drivers/irqchip/irq-cs42l43.c
 create mode 100644 drivers/mfd/cs42l43-i2c.c
 create mode 100644 drivers/mfd/cs42l43-sdw.c
 create mode 100644 drivers/mfd/cs42l43.c
 create mode 100644 drivers/mfd/cs42l43.h
 create mode 100644 drivers/pinctrl/cirrus/pinctrl-cs42l43.c
 create mode 100644 drivers/spi/spi-cs42l43.c
 create mode 100644 include/linux/irqchip/cs42l43.h
 create mode 100644 include/linux/mfd/cs42l43-regs.h
 create mode 100644 include/linux/mfd/cs42l43.h
 create mode 100644 include/sound/cs42l43.h
 create mode 100644 sound/soc/codecs/cs42l43-jack.c
 create mode 100644 sound/soc/codecs/cs42l43-sdw.c
 create mode 100644 sound/soc/codecs/cs42l43.c
 create mode 100644 sound/soc/codecs/cs42l43.h
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/10 soundwire: bus: Allow SoundWire peripherals to register IRQ handlers

From: Lucas Tanure <[email protected]>

Currently the in-band alerts for SoundWire peripherals can only be communicated to the driver through the interrupt_callback function. This however is slightly inconvient for devices that wish to share IRQ handling code between SoundWire and I2C/SPI, the later would normally register an IRQ handler with the IRQ subsystem. However there is no reason the SoundWire in-band IRQs can not also be communicated as an actual IRQ to the driver.

Add support for SoundWire peripherals to register a normal IRQ handler to receive SoundWire in-band alerts, allowing code to be shared across control buses.

---
 drivers/soundwire/bus.c       | 31 +++++++++++++++++++++++++++++++
 drivers/soundwire/bus_type.c  | 12 ++++++++++++
 include/linux/soundwire/sdw.h |  9 +++++++++
 3 files changed, 52 insertions(+)
drivers/soundwire/bus.c +31 -0
index 1ea6a64f8c4a5..30cd03757aafe 100644
@@ -3,6 +3,7 @@
 
 #include <linux/acpi.h>
 #include <linux/delay.h>
+#include <linux/irq.h>
 #include <linux/mod_devicetable.h>
 #include <linux/pm_runtime.h>
 #include <linux/soundwire/sdw_registers.h>
@@ -25,6 +26,23 @@ static int sdw_get_id(struct sdw_bus *bus)
 	return 0;
 }
 
+static int sdw_irq_map(struct irq_domain *h, unsigned int virq,
+		       irq_hw_number_t hw)
+{
+	struct sdw_bus *bus = h->host_data;
+
+	irq_set_chip_data(virq, bus);
+	irq_set_chip(virq, &bus->irq_chip);
+	irq_set_nested_thread(virq, 1);
+	irq_set_noprobe(virq);
+
+	return 0;
+}
+
+static const struct irq_domain_ops sdw_domain_ops = {
+	.map	= sdw_irq_map,
+};
+
 /**
  * sdw_bus_master_add() - add a bus Master instance
  * @bus: bus instance
@@ -142,6 +160,13 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
 	bus->params.curr_bank = SDW_BANK0;
 	bus->params.next_bank = SDW_BANK1;
 
+	bus->irq_chip.name = dev_name(bus->dev);
+	bus->domain = irq_domain_add_linear(NULL, SDW_MAX_DEVICES, &sdw_domain_ops, bus);
+	if (!bus->domain) {
+		dev_err(bus->dev, "Failed to add IRQ domain\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL(sdw_bus_master_add);
@@ -178,6 +203,9 @@ static int sdw_delete_slave(struct device *dev, void *data)
 void sdw_bus_master_delete(struct sdw_bus *bus)
 {
 	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
+
+	irq_domain_remove(bus->domain);
+
 	sdw_master_device_del(bus);
 
 	sdw_bus_debugfs_exit(bus);
@@ -1711,6 +1739,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
 				struct device *dev = &slave->dev;
 				struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
 
+				if (slave->prop.use_domain_irq && slave->irq)
+					handle_nested_irq(slave->irq);
+
 				if (drv->ops && drv->ops->interrupt_callback) {
 					slave_intr.sdca_cascade = sdca_cascade;
 					slave_intr.control_port = clear;
drivers/soundwire/bus_type.c +12 -0
index 1f43ee848eac8..fafbc284e82da 100644
@@ -122,6 +122,12 @@ static int sdw_drv_probe(struct device *dev)
 	if (drv->ops && drv->ops->read_prop)
 		drv->ops->read_prop(slave);
 
+	if (slave->prop.use_domain_irq) {
+		slave->irq = irq_create_mapping(slave->bus->domain, slave->dev_num);
+		if (!slave->irq)
+			dev_warn(dev, "Failed to map IRQ\n");
+	}
+
 	/* init the sysfs as we have properties now */
 	ret = sdw_slave_sysfs_init(slave);
 	if (ret < 0)
@@ -166,7 +172,13 @@ static int sdw_drv_remove(struct device *dev)
 	int ret = 0;
 
 	mutex_lock(&slave->sdw_dev_lock);
+
 	slave->probed = false;
+
+	if (slave->prop.use_domain_irq)
+		irq_dispose_mapping(irq_find_mapping(slave->bus->domain,
+						     slave->dev_num));
+
 	mutex_unlock(&slave->sdw_dev_lock);
 
 	if (drv->remove)
include/linux/soundwire/sdw.h +9 -0
index ef645de13ae93..c3ab5e5f9cfa4 100644
@@ -5,6 +5,8 @@
 #define __SOUNDWIRE_H
 
 #include <linux/bug.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/mod_devicetable.h>
 #include <linux/bitfield.h>
 
@@ -369,6 +371,7 @@ struct sdw_dpn_prop {
  * @clock_reg_supported: the Peripheral implements the clock base and scale
  * registers introduced with the SoundWire 1.2 specification. SDCA devices
  * do not need to set this boolean property as the registers are required.
+ * @use_domain_irq: call actual IRQ handler on slave, as well as callback
  */
 struct sdw_slave_prop {
 	u32 mipi_revision;
@@ -393,6 +396,7 @@ struct sdw_slave_prop {
 	u8 scp_int1_mask;
 	u32 quirks;
 	bool clock_reg_supported;
+	bool use_domain_irq;
 };
 
 #define SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY	BIT(0)
@@ -640,6 +644,7 @@ struct sdw_slave_ops {
  * struct sdw_slave - SoundWire Slave
  * @id: MIPI device ID
  * @dev: Linux device
+ * @irq: IRQ number
  * @status: Status reported by the Slave
  * @bus: Bus handle
  * @prop: Slave properties
@@ -669,6 +674,7 @@ struct sdw_slave_ops {
 struct sdw_slave {
 	struct sdw_slave_id id;
 	struct device dev;
+	int irq;
 	enum sdw_slave_status status;
 	struct sdw_bus *bus;
 	struct sdw_slave_prop prop;
@@ -883,6 +889,7 @@ struct sdw_master_ops {
  * is used to compute and program bus bandwidth, clock, frame shape,
  * transport and port parameters
  * @debugfs: Bus debugfs
+ * @domain: IRQ domain
  * @defer_msg: Defer message
  * @clk_stop_timeout: Clock stop timeout computed
  * @bank_switch_timeout: Bank switch timeout computed
@@ -916,6 +923,8 @@ struct sdw_bus {
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs;
 #endif
+	struct irq_chip irq_chip;
+	struct irq_domain *domain;
 	struct sdw_defer defer_msg;
 	unsigned int clk_stop_timeout;
 	u32 bank_switch_timeout;
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 01/10] soundwire: bus: Allow SoundWire peripherals to register IRQ handlers

drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1744

Quoted 10 lines
drivers/soundwire/bus.c +3 -0
@@ -1711,6 +1739,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
 				struct device *dev = &slave->dev;
 				struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
 
+				if (slave->prop.use_domain_irq && slave->irq)
+					handle_nested_irq(slave->irq);
+

I am a bit lost here, I can understand that alerts would be handled by a dedicated handler, but here the code continues and will call the existing interrupt_callback.

Is this intentional? I wonder if there's a risk with two entities dealing with the same event and programming the same registers. Shouldn't there be some sort of 'either or' rule?

Quoted 48 lines
drivers/soundwire/bus.c +0 -0
 				if (drv->ops && drv->ops->interrupt_callback) {
 					slave_intr.sdca_cascade = sdca_cascade;
 					slave_intr.control_port = clear;
drivers/soundwire/bus_type.c +12 -0
index 1f43ee848eac8..fafbc284e82da 100644
@@ -122,6 +122,12 @@ static int sdw_drv_probe(struct device *dev)
 	if (drv->ops && drv->ops->read_prop)
 		drv->ops->read_prop(slave);
 
+	if (slave->prop.use_domain_irq) {
+		slave->irq = irq_create_mapping(slave->bus->domain, slave->dev_num);
+		if (!slave->irq)
+			dev_warn(dev, "Failed to map IRQ\n");
+	}
+
 	/* init the sysfs as we have properties now */
 	ret = sdw_slave_sysfs_init(slave);
 	if (ret < 0)
@@ -166,7 +172,13 @@ static int sdw_drv_remove(struct device *dev)
 	int ret = 0;
 
 	mutex_lock(&slave->sdw_dev_lock);
+
 	slave->probed = false;
+
+	if (slave->prop.use_domain_irq)
+		irq_dispose_mapping(irq_find_mapping(slave->bus->domain,
+						     slave->dev_num));
+
 	mutex_unlock(&slave->sdw_dev_lock);
 
 	if (drv->remove)
include/linux/soundwire/sdw.h +2 -0
index ef645de13ae93..c3ab5e5f9cfa4 100644
@@ -5,6 +5,8 @@
 #define __SOUNDWIRE_H
 
 #include <linux/bug.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/mod_devicetable.h>
 #include <linux/bitfield.h>
 

include/linux/soundwire/sdw.h struct sdw_dpn_prop { · line 374

Quoted 4 lines
include/linux/soundwire/sdw.h +1 -0
@@ -369,6 +371,7 @@ struct sdw_dpn_prop {
  * @clock_reg_supported: the Peripheral implements the clock base and scale
  * registers introduced with the SoundWire 1.2 specification. SDCA devices
  * do not need to set this boolean property as the registers are required.
+ * @use_domain_irq: call actual IRQ handler on slave, as well as callback

what callback, the interrupt_callback? That would mean the interrupt is handled twice?

I am probably missing something here?

Quoted 9 lines
include/linux/soundwire/sdw.h +1 -0
  */
 struct sdw_slave_prop {
 	u32 mipi_revision;
@@ -393,6 +396,7 @@ struct sdw_slave_prop {
 	u8 scp_int1_mask;
 	u32 quirks;
 	bool clock_reg_supported;
+	bool use_domain_irq;
 };
author maintainer
#3 lore raw

Re: [PATCH 01/10] soundwire: bus: Allow SoundWire peripherals to register IRQ handlers

Quoted 12 lines · Pierre-Louis Bossart

drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1744

Quoted 7 lines
drivers/soundwire/bus.c +3 -0
@@ -1711,6 +1739,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
 				struct device *dev = &slave->dev;
 				struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
 
+				if (slave->prop.use_domain_irq && slave->irq)
+					handle_nested_irq(slave->irq);
+

I am a bit lost here, I can understand that alerts would be handled by a dedicated handler, but here the code continues and will call the existing interrupt_callback.

Quoted 4 lines

Is this intentional? I wonder if there's a risk with two entities dealing with the same event and programming the same registers. Shouldn't there be some sort of 'either or' rule?

I guess there is a risk of them "handling" the IRQ twice, although it is hard to see why you would write the driver that way. Also since they are sequencial the second would I guess just see that no IRQs are pending.

The intention for calling both is that it facilitates using the same IRQ handler for I2C and SoundWire. At least on the Cirrus devices there are a bunch of chip specific registers that need treated exactly the same on I2C and SoundWire, but then a couple of extra registers that need handled in the SoundWire case. This way the handling of those can be kept completely in the SoundWire part of the code and not ifdef-ed into the main IRQ path.

Thanks,
Charles

#4 lore raw

Re: [PATCH 01/10] soundwire: bus: Allow SoundWire peripherals to register IRQ handlers

Quoted 23 lines · Charles Keepax
Quoted 12 lines · Pierre-Louis Bossart

drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1744

Quoted 7 lines
drivers/soundwire/bus.c +3 -0
@@ -1711,6 +1739,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
 				struct device *dev = &slave->dev;
 				struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
 
+				if (slave->prop.use_domain_irq && slave->irq)
+					handle_nested_irq(slave->irq);
+

I am a bit lost here, I can understand that alerts would be handled by a dedicated handler, but here the code continues and will call the existing interrupt_callback.

Quoted 4 lines

Is this intentional? I wonder if there's a risk with two entities dealing with the same event and programming the same registers. Shouldn't there be some sort of 'either or' rule?

I guess there is a risk of them "handling" the IRQ twice, although it is hard to see why you would write the driver that way. Also since they are sequencial the second would I guess just see that no IRQs are pending.

Quoted 8 lines

The intention for calling both is that it facilitates using the same IRQ handler for I2C and SoundWire. At least on the Cirrus devices there are a bunch of chip specific registers that need treated exactly the same on I2C and SoundWire, but then a couple of extra registers that need handled in the SoundWire case. This way the handling of those can be kept completely in the SoundWire part of the code and not ifdef-ed into the main IRQ path.

Sounds good to me, but it's worth adding a comment and improving the commit message with design intent/rules since it's a common part in drivers/soundwire/

author maintainer
#5 lore raw

Re: [PATCH 01/10] soundwire: bus: Allow SoundWire peripherals to register IRQ handlers

Quoted 35 lines · Pierre-Louis Bossart
Quoted 23 lines · Charles Keepax
Quoted 12 lines · Pierre-Louis Bossart

drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1744

Quoted 7 lines
drivers/soundwire/bus.c +3 -0
@@ -1711,6 +1739,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
 				struct device *dev = &slave->dev;
 				struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
 
+				if (slave->prop.use_domain_irq && slave->irq)
+					handle_nested_irq(slave->irq);
+

I am a bit lost here, I can understand that alerts would be handled by a dedicated handler, but here the code continues and will call the existing interrupt_callback.

Quoted 4 lines

Is this intentional? I wonder if there's a risk with two entities dealing with the same event and programming the same registers. Shouldn't there be some sort of 'either or' rule?

I guess there is a risk of them "handling" the IRQ twice, although it is hard to see why you would write the driver that way. Also since they are sequencial the second would I guess just see that no IRQs are pending.

Quoted 8 lines

The intention for calling both is that it facilitates using the same IRQ handler for I2C and SoundWire. At least on the Cirrus devices there are a bunch of chip specific registers that need treated exactly the same on I2C and SoundWire, but then a couple of extra registers that need handled in the SoundWire case. This way the handling of those can be kept completely in the SoundWire part of the code and not ifdef-ed into the main IRQ path.

Quoted 3 lines

Sounds good to me, but it's worth adding a comment and improving the commit message with design intent/rules since it's a common part in drivers/soundwire/

Yeah no issues with updating the commit message to explain that in more detail.

Thanks,
Charles

author maintainer
#6 lore raw

PATCH 2/10 ASoC: soc-component: Add notify control helper function

In reply to Charles Keepax

Add a function to allow ASoC drivers to easily notify an ALSA control change. This function will automatically add any component naming prefix into the control name.

---
 include/sound/soc-component.h |  4 ++++
 sound/soc/soc-component.c     | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/sound/soc-component.h +4 -0
index 0814ed1438640..0b47603c9db29 100644
@@ -454,6 +454,10 @@ int snd_soc_component_force_enable_pin_unlocked(
 	struct snd_soc_component *component,
 	const char *pin);
 
+/* component controls */
+int snd_soc_component_notify_control(struct snd_soc_component *component,
+				     const char * const ctl);
+
 /* component driver ops */
 int snd_soc_component_open(struct snd_soc_component *component,
 			   struct snd_pcm_substream *substream);
sound/soc/soc-component.c +22 -0
index ff25718ff2e88..4356cc320fea0 100644
@@ -236,6 +236,28 @@ int snd_soc_component_force_enable_pin_unlocked(
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
 
+int snd_soc_component_notify_control(struct snd_soc_component *component,
+				     const char * const ctl)
+{
+	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
+	struct snd_kcontrol *kctl;
+
+	if (component->name_prefix)
+		snprintf(name, ARRAY_SIZE(name), "%s %s", component->name_prefix, ctl);
+	else
+		snprintf(name, ARRAY_SIZE(name), "%s", ctl);
+
+	kctl = snd_soc_card_get_kcontrol(component->card, name);
+	if (!kctl)
+		return soc_component_ret(component, -EINVAL);
+
+	snd_ctl_notify(component->card->snd_card,
+		       SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_component_notify_control);
+
 /**
  * snd_soc_component_set_jack - configure component jack.
  * @component: COMPONENTs
Signature · 1 line
2.30.2
author maintainer
#7 lore raw

PATCH 3/10 ASoC: ak4118: Update to use new component control notify helper

In reply to Charles Keepax

Update the driver to use the new ASoC core control notify helper. This also fixes a bug where the control would not be found if the CODEC was given a name prefix.

---
 sound/soc/codecs/ak4118.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
sound/soc/codecs/ak4118.c +2 -9
index b6d9a10bdccdc..74ccfb0d921d6 100644
@@ -264,8 +264,6 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data)
 	struct ak4118_priv *ak4118 = data;
 	struct snd_soc_component *component = ak4118->component;
 	struct snd_kcontrol_new *kctl_new;
-	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_id *id;
 	unsigned int i;
 
 	if (!component)
@@ -273,13 +271,8 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data)
 
 	for (i = 0; i < ARRAY_SIZE(ak4118_iec958_controls); i++) {
 		kctl_new = &ak4118_iec958_controls[i];
-		kctl = snd_soc_card_get_kcontrol(component->card,
-						 kctl_new->name);
-		if (!kctl)
-			continue;
-		id = &kctl->id;
-		snd_ctl_notify(component->card->snd_card,
-			       SNDRV_CTL_EVENT_MASK_VALUE, id);
+
+		snd_soc_component_notify_control(component, kctl_new->name);
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
2.30.2
#8 lore raw

Re: [PATCH 03/10] ASoC: ak4118: Update to use new component control notify helper

sound/soc/codecs/ak4118.c

Quoted 10 lines · Charles Keepax

Update the driver to use the new ASoC core control notify helper. This also fixes a bug where the control would not be found if the CODEC was given a name prefix.

---
 sound/soc/codecs/ak4118.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
sound/soc/codecs/ak4118.c +0 -0

should patches 2, 3, 4 be part of a separate series, they really have nothing to do with the Cirrus CS32L43?

Quoted 28 lines

index b6d9a10bdccdc..74ccfb0d921d6 100644

sound/soc/codecs/ak4118.c +2 -9
@@ -264,8 +264,6 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data)
 	struct ak4118_priv *ak4118 = data;
 	struct snd_soc_component *component = ak4118->component;
 	struct snd_kcontrol_new *kctl_new;
-	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_id *id;
 	unsigned int i;
 
 	if (!component)
@@ -273,13 +271,8 @@ static irqreturn_t ak4118_irq_handler(int irq, void *data)
 
 	for (i = 0; i < ARRAY_SIZE(ak4118_iec958_controls); i++) {
 		kctl_new = &ak4118_iec958_controls[i];
-		kctl = snd_soc_card_get_kcontrol(component->card,
-						 kctl_new->name);
-		if (!kctl)
-			continue;
-		id = &kctl->id;
-		snd_ctl_notify(component->card->snd_card,
-			       SNDRV_CTL_EVENT_MASK_VALUE, id);
+
+		snd_soc_component_notify_control(component, kctl_new->name);
 	}
 
 	return IRQ_HANDLED;
author maintainer
#9 lore raw

Re: [PATCH 03/10] ASoC: ak4118: Update to use new component control notify helper

Quoted 10 lines · Pierre-Louis Bossart
Quoted 9 lines · Charles Keepax

Update the driver to use the new ASoC core control notify helper. This also fixes a bug where the control would not be found if the CODEC was given a name prefix.

---
 sound/soc/codecs/ak4118.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
Quoted 4 lines

sound/soc/codecs/ak4118.c

Quoted 1 line
sound/soc/codecs/ak4118.c +0 -0

should patches 2, 3, 4 be part of a separate series, they really have nothing to do with the Cirrus CS32L43?

Patch 2 has a build dependency on the CODEC patch, 3/4 are debatable. I could do the series without these patches and do a seperate chain with those three patches and an extra patch to convert the cs42l43, if that is preferred to shrink the chain.

Thanks,
Charles

author maintainer
#10 lore raw

PATCH 4/10 ASoC: wm_adsp: Update to use new component control notify helepr

In reply to Charles Keepax
---
 sound/soc/codecs/wm_adsp.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
sound/soc/codecs/wm_adsp.c +1 -19
index 216120b68b64b..6270cb2e9395c 100644
@@ -686,8 +686,6 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
 {
 	struct cs_dsp_coeff_ctl *cs_ctl = cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg);
 	struct wm_coeff_ctl *ctl;
-	struct snd_kcontrol *kcontrol;
-	char ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
 	int ret;
 
 	ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len);
@@ -699,23 +697,7 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
 
 	ctl = cs_ctl->priv;
 
-	if (dsp->component->name_prefix)
-		snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s",
-			 dsp->component->name_prefix, ctl->name);
-	else
-		snprintf(ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s",
-			 ctl->name);
-
-	kcontrol = snd_soc_card_get_kcontrol(dsp->component->card, ctl_name);
-	if (!kcontrol) {
-		adsp_err(dsp, "Can't find kcontrol %s\n", ctl_name);
-		return -EINVAL;
-	}
-
-	snd_ctl_notify(dsp->component->card->snd_card,
-		       SNDRV_CTL_EVENT_MASK_VALUE, &kcontrol->id);
-
-	return 0;
+	return snd_soc_component_notify_control(dsp->component, ctl->name);
 }
 EXPORT_SYMBOL_GPL(wm_adsp_write_ctl);
 
Signature · 1 line
2.30.2
author maintainer
#11 lore raw

PATCH 5/10 dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

In reply to Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a YAML DT binding document for this device.

---
 .../bindings/mfd/cirrus,cs42l43.yaml          | 212 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 213 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +212 -0
new file mode 100644
index 0000000000000..e1fd70e0a3467
@@ -0,0 +1,212 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/cirrus,cs42l43.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic CS42L43 Audio CODEC
+
+maintainers:
+  - [email protected]
+
+description: |
+  The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface
+  (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed
+  for portable applications. It provides a high dynamic range, stereo
+  DAC for headphone output, two integrated Class D amplifiers for
+  loudspeakers, and two ADCs for wired headset microphone input or
+  stereo line input. PDM inputs are provided for digital microphones.
+
+required:
+  - compatible
+  - reg
+  - VDD_P-supply
+  - VDD_A-supply
+  - VDD_D-supply
+  - VDD_IO-supply
+  - VDD_CP-supply
+
+additionalProperties: false
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs42l43
+
+  reg:
+    maxItems: 1
+
+  VDD_P-supply:
+    description:
+      Power supply for the high voltage interface.
+
+  VDD_A-supply:
+    description:
+      Power supply for internal analog circuits.
+
+  VDD_D-supply:
+    description:
+      Power supply for internal digital circuits.
+
+  VDD_IO-supply:
+    description:
+      Power supply for external interface and internal digital logic.
+
+  VDD_CP-supply:
+    description:
+      Power supply for the amplifier 3 and 4 charge pump.
+
+  VDD_AMP-supply:
+    description:
+      Power supply for amplifier 1 and 2.
+
+  reset-gpios:
+    maxItems: 1
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  gpio-ranges:
+    items:
+      - description: A phandle to the CODEC pinctrl node
+        minimum: 0
+      - const: 0
+      - const: 0
+      - const: 3
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  interrupts:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    const: 1
+
+  clocks:
+    items:
+      - description: Synchronous audio clock provided on mclk_in.
+
+  clock-names:
+    const: mclk
+
+  pinctrl:
+    type: object
+
+    allOf:
+      - $ref: "../pinctrl/pinctrl.yaml#"
+
+    properties:
+      pin-settings:
+        type: object
+
+        additionalProperties: false
+
+        patternProperties:
+          '-pins$':
+            type: object
+
+            allOf:
+              - $ref: "../pinctrl/pincfg-node.yaml#"
+              - $ref: "../pinctrl/pinmux-node.yaml#"
+
+            oneOf:
+              - required: [ groups ]
+              - required: [ pins ]
+
+            unevaluatedProperties: false
+
+            properties:
+              groups:
+                enum: [ gpio1, gpio2, gpio3, asp, pdmout2, pdmout1, i2c, spi ]
+
+              pins:
+                enum: [ gpio1, gpio2, gpio3,
+                        asp_dout, asp_fsync, asp_bclk,
+                        pdmout2_clk, pdmout2_data, pdmout1_clk, pdmout1_data,
+                        i2c_sda, i2c_scl,
+                        spi_miso, spi_sck, spi_ssb ]
+
+              function:
+                enum: [ gpio, spdif, irq, mic-shutter, spk-shutter ]
+
+              drive-strength:
+                description: Set drive strength in mA
+                enum: [ 1, 2, 4, 8, 9, 10, 12, 16 ]
+
+              input-debounce:
+                description: Set input debounce in uS
+                enum: [ 0, 85 ]
+
+  spi:
+    type: object
+
+    allOf:
+      - $ref: "../spi/spi-controller.yaml#"
+
+    unevaluatedProperties: false
+
+examples:
+  - |
+    i2c@e0004000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        reg = <0xe0004000 0x1000>;
+
+        cs42l43: codec@1a {
+            compatible = "cirrus,cs42l43";
+            reg = <0x1a>;
+
+            VDD_P-supply = <&vdd5v0>;
+            VDD_D-supply = <&vdd1v8>;
+            VDD_A-supply = <&vdd1v8>;
+            VDD_IO-supply = <&vdd1v8>;
+            VDD_CP-supply = <&vdd1v8>;
+            VDD_AMP-supply = <&vdd5v0>;
+
+            reset-gpios = <&gpio 0>;
+
+            gpio-controller;
+            #gpio-cells = <2>;
+            gpio-ranges = <&cs42l43_pins 0 0 3>;
+
+            interrupt-controller;
+            #interrupt-cells = <2>;
+            interrupt-parent = <&gpio>;
+            interrupts = <56 8>;
+
+            #sound-dai-cells = <1>;
+
+            clocks = <&clks 0>;
+            clock-names = "mclk";
+
+            cs42l43_pins: pinctrl {
+                pinctrl-names = "default";
+                pinctrl-0 = <&pinsettings>;
+
+                pinsettings: pin-settings {
+                    shutter-pins {
+                        groups = "gpio3";
+                        function = "mic-shutter";
+                    };
+                };
+            };
+
+            spi {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                cs-gpios = <&cs42l43 1 0>;
+
+                sensor@0 {
+                    compatible = "bosch,bme680";
+                    reg = <0>;
+                    spi-max-frequency = <1400000>;
+                };
+            };
+        };
+    };
MAINTAINERS +1 -0
index 7e0b87d5aa2e5..0db9f37eec258 100644
@@ -4926,6 +4926,7 @@ M:	Richard Fitzgerald <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/cirrus,cs*
 F:	Documentation/devicetree/bindings/sound/cirrus,cs*
 F:	include/dt-bindings/sound/cs*
 F:	include/sound/cs*
Signature · 1 line
2.30.2
#12 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 22 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a YAML DT binding document for this device.

---
 .../bindings/mfd/cirrus,cs42l43.yaml          | 212 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 213 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +0 -0
new file mode 100644
index 0000000000000..e1fd70e0a3467

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 7

Quoted 7 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +7 -0
@@ -0,0 +1,212 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/cirrus,cs42l43.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic CS42L43 Audio CODEC

That's audio codec, so it should be in sound, not MFD.

Quoted 10 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +10 -0
+
+maintainers:
+  - [email protected]
+
+description: |
+  The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface
+  (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed
+  for portable applications. It provides a high dynamic range, stereo
+  DAC for headphone output, two integrated Class D amplifiers for
+  loudspeakers, and two ADCs for wired headset microphone input or

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 27

Quoted 10 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +10 -0
+  stereo line input. PDM inputs are provided for digital microphones.
+
+required:
+  - compatible
+  - reg
+  - VDD_P-supply
+  - VDD_A-supply
+  - VDD_D-supply
+  - VDD_IO-supply
+  - VDD_CP-supply

lowercase, no underscores in all property names.

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 29

Quoted 2 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +2 -0
+
+additionalProperties: false

This order is quite unexpected... please do not invent your own layout. Use example-schema as your starting point. I suspect there will be many things to fix, so limited review follows (not complete).

Missing ref to dai-common

Quoted 59 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +59 -0
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs42l43
+
+  reg:
+    maxItems: 1
+
+  VDD_P-supply:
+    description:
+      Power supply for the high voltage interface.
+
+  VDD_A-supply:
+    description:
+      Power supply for internal analog circuits.
+
+  VDD_D-supply:
+    description:
+      Power supply for internal digital circuits.
+
+  VDD_IO-supply:
+    description:
+      Power supply for external interface and internal digital logic.
+
+  VDD_CP-supply:
+    description:
+      Power supply for the amplifier 3 and 4 charge pump.
+
+  VDD_AMP-supply:
+    description:
+      Power supply for amplifier 1 and 2.
+
+  reset-gpios:
+    maxItems: 1
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  gpio-ranges:
+    items:
+      - description: A phandle to the CODEC pinctrl node
+        minimum: 0
+      - const: 0
+      - const: 0
+      - const: 3
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  interrupts:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    const: 1

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 98

Quoted 10 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +10 -0
+
+  clocks:
+    items:
+      - description: Synchronous audio clock provided on mclk_in.
+
+  clock-names:
+    const: mclk
+
+  pinctrl:
+    type: object

additionalProperties: false

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 101

Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    allOf:
+      - $ref: "../pinctrl/pinctrl.yaml#"

No quotes, absolute path, so /schemas/pinctrl/....

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 104

Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    properties:
+      pin-settings:

What's this node about? pinctrl/pinctrl/pins? One level too much.

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 115

Quoted 11 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +11 -0
+        type: object
+
+        additionalProperties: false
+
+        patternProperties:
+          '-pins$':
+            type: object
+
+            allOf:
+              - $ref: "../pinctrl/pincfg-node.yaml#"
+              - $ref: "../pinctrl/pinmux-node.yaml#"

Same comments.

Quoted 24 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +24 -0
+
+            oneOf:
+              - required: [ groups ]
+              - required: [ pins ]
+
+            unevaluatedProperties: false
+
+            properties:
+              groups:
+                enum: [ gpio1, gpio2, gpio3, asp, pdmout2, pdmout1, i2c, spi ]
+
+              pins:
+                enum: [ gpio1, gpio2, gpio3,
+                        asp_dout, asp_fsync, asp_bclk,
+                        pdmout2_clk, pdmout2_data, pdmout1_clk, pdmout1_data,
+                        i2c_sda, i2c_scl,
+                        spi_miso, spi_sck, spi_ssb ]
+
+              function:
+                enum: [ gpio, spdif, irq, mic-shutter, spk-shutter ]
+
+              drive-strength:
+                description: Set drive strength in mA
+                enum: [ 1, 2, 4, 8, 9, 10, 12, 16 ]

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 149

Quoted 10 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +10 -0
+
+              input-debounce:
+                description: Set input debounce in uS
+                enum: [ 0, 85 ]
+
+  spi:
+    type: object
+
+    allOf:
+      - $ref: "../spi/spi-controller.yaml#"

Same comments.

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 158

Quoted 9 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +9 -0
+
+    unevaluatedProperties: false
+
+examples:
+  - |
+    i2c@e0004000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        reg = <0xe0004000 0x1000>;

Drop, just i2c

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 171

Quoted 13 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +13 -0
+
+        cs42l43: codec@1a {
+            compatible = "cirrus,cs42l43";
+            reg = <0x1a>;
+
+            VDD_P-supply = <&vdd5v0>;
+            VDD_D-supply = <&vdd1v8>;
+            VDD_A-supply = <&vdd1v8>;
+            VDD_IO-supply = <&vdd1v8>;
+            VDD_CP-supply = <&vdd1v8>;
+            VDD_AMP-supply = <&vdd5v0>;
+
+            reset-gpios = <&gpio 0>;

Use proper defines for flags.

Best regards,
Krzysztof

author maintainer
#13 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 8 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 7

Quoted 4 lines · Charles Keepax

+$id: http://devicetree.org/schemas/mfd/cirrus,cs42l43.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +2 -0
+
+title: Cirrus Logic CS42L43 Audio CODEC

That's audio codec, so it should be in sound, not MFD.

Is this true even despite the device being implemented as an MFD? I am happy to move it, and will do so unless I hear otherwise.

Quoted 7 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+  - VDD_P-supply
+  - VDD_A-supply
+  - VDD_D-supply
+  - VDD_IO-supply
+  - VDD_CP-supply

lowercase, no underscores in all property names.

I guess we can rename all the regulators to lower case.

Quoted 8 lines
Quoted 1 line

+additionalProperties: false

This order is quite unexpected... please do not invent your own layout. Use example-schema as your starting point. I suspect there will be many things to fix, so limited review follows (not complete).

Missing ref to dai-common

Apologies for that I was a little hesitant about this but this order did make the binding document much more readable, the intentation got really hard to follow in the traditional order. I guess since I have things working now I can put it back, again I will do so unless I hear otherwise.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+  pinctrl:
+    type: object

additionalProperties: false

Can do.

Quoted 6 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 101

Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    allOf:
+      - $ref: "../pinctrl/pinctrl.yaml#"

No quotes, absolute path, so /schemas/pinctrl/....

Can do.

Quoted 6 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 104

Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    properties:
+      pin-settings:

What's this node about? pinctrl/pinctrl/pins? One level too much.

codec/pinctrl/pins

The device is a codec, so the main node should be called codec, then it has a subnode called pinctrl to satisfy the pinctrl DT binding.

Quoted 9 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 158

Quoted 6 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +6 -0
+examples:
+  - |
+    i2c@e0004000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        reg = <0xe0004000 0x1000>;

Drop, just i2c

Can do.

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +7 -0
+
+        cs42l43: codec@1a {
+            compatible = "cirrus,cs42l43";
+            reg = <0x1a>;
+
+            VDD_P-supply = <&vdd5v0>;
+            VDD_D-supply = <&vdd1v8>;
Quoted 8 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 171

Quoted 6 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +6 -0
+            VDD_A-supply = <&vdd1v8>;
+            VDD_IO-supply = <&vdd1v8>;
+            VDD_CP-supply = <&vdd1v8>;
+            VDD_AMP-supply = <&vdd5v0>;
+
+            reset-gpios = <&gpio 0>;

Use proper defines for flags.

Can do.

Thanks,
Charles

#14 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 11 lines · Charles Keepax
Quoted 8 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 7

Quoted 4 lines · Charles Keepax

+$id: http://devicetree.org/schemas/mfd/cirrus,cs42l43.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +2 -0
+
+title: Cirrus Logic CS42L43 Audio CODEC

That's audio codec, so it should be in sound, not MFD.

Is this true even despite the device being implemented as an MFD?

Implementation in Linux almost does not matter here. Bindings location match the device main purpose. We indeed stuff into MFD bindings things like PMIC, because PMIC is a bit more than just regulators, and we do not have here subsystem for PMICs. If you call it Audio Codec, then I vote for sound directory for bindings.

Quoted 19 lines

I am happy to move it, and will do so unless I hear otherwise.

Quoted 7 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 27

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+  - VDD_P-supply
+  - VDD_A-supply
+  - VDD_D-supply
+  - VDD_IO-supply
+  - VDD_CP-supply

lowercase, no underscores in all property names.

I guess we can rename all the regulators to lower case.

Quoted 7 lines
Quoted 1 line

+additionalProperties: false

This order is quite unexpected... please do not invent your own layout. Use example-schema as your starting point. I suspect there will be many things to fix, so limited review follows (not complete).

Quoted 7 lines
Quoted 1 line

Missing ref to dai-common

Apologies for that I was a little hesitant about this but this order did make the binding document much more readable, the intentation got really hard to follow in the traditional order. I guess since I have things working now I can put it back, again I will do so unless I hear otherwise.

The additional/unevaluatedProperties from child nodes are indeed moved then up - following the property:
pinctrl:
type: object
additionalProperties: false

but that's exception and for the rest I don't see any troubles with indentation. That would be the only binding... so what's here so special?

Quoted 22 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+  pinctrl:
+    type: object

additionalProperties: false

Can do.

Quoted 6 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 101

Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    allOf:
+      - $ref: "../pinctrl/pinctrl.yaml#"

No quotes, absolute path, so /schemas/pinctrl/....

Can do.

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +3 -0
+
+    properties:
+      pin-settings:
Quoted 8 lines
Quoted 2 lines

What's this node about? pinctrl/pinctrl/pins? One level too much.

codec/pinctrl/pins

The device is a codec, so the main node should be called codec, then it has a subnode called pinctrl to satisfy the pinctrl DT binding.

Sure, but then you do not need pin-settings. Look at Qualcomm bindings for example:

Documentation/devicetree/bindings/pinctrl/qcom,sm8550-tlmm.yaml

Best regards,
Krzysztof

#15 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

In reply to Charles Keepax
Quoted 4 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for

...

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 82

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2

Hm, are you sure? Who is the consumer/user of this interrupt controller?

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 90

Quoted 8 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +8 -0
+
+  interrupts:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    const: 1
+
+  clocks:

Best regards,
Krzysztof

author maintainer
#16 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 8 lines · Krzysztof Kozlowski
Quoted 4 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for

...

Quoted 8 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 82

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2

Hm, are you sure? Who is the consumer/user of this interrupt controller?

Anyone who wants the device has GPIOs that can signal IRQs. Some of the other IRQs could be more generally useful, such as some of the jack detection ones.

Thanks,
Charles

#17 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 18 lines · Charles Keepax
Quoted 8 lines · Krzysztof Kozlowski
Quoted 4 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for

...

Quoted 8 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 82

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2

Hm, are you sure? Who is the consumer/user of this interrupt controller?

Quoted 3 lines

Anyone who wants the device has GPIOs that can signal IRQs. Some of the other IRQs could be more generally useful, such as some of the jack detection ones.

OK, makes sense, but it is a bit odd then to have:
codec {
which is GPIO and interrupt controller, but not pin controller pinctrl {
pin controller, which is not GPIO and not interrupt controller
}
}
Maybe all the GPIO/pin/related interrupt properties should be moved to pinctrl node?

Best regards,
Krzysztof

author maintainer
#18 lore raw

Re: [PATCH 05/10] dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding

Quoted 24 lines · Krzysztof Kozlowski
Quoted 18 lines · Charles Keepax
Quoted 8 lines · Krzysztof Kozlowski
Quoted 4 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for

...

Quoted 8 lines

Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml line 82

Quoted 5 lines
Documentation/devicetree/bindings/mfd/cirrus,cs42l43.yaml new file +5 -0
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2

Hm, are you sure? Who is the consumer/user of this interrupt controller?

Quoted 3 lines

Anyone who wants the device has GPIOs that can signal IRQs. Some of the other IRQs could be more generally useful, such as some of the jack detection ones.

Quoted 10 lines

OK, makes sense, but it is a bit odd then to have:
codec {
which is GPIO and interrupt controller, but not pin controller pinctrl {
pin controller, which is not GPIO and not interrupt controller
}
}
Maybe all the GPIO/pin/related interrupt properties should be moved to pinctrl node?

I will have a look at that although I have a vague memory that this made the pinctrl very sad doing this. Presumably a bug somewhere but might take me a while to figure that out. The interrupt controller is a bit of a grey area as well since it has a bunch of IRQs that don't relate to the pins as well as some that do. So logically it might be better suited on the root node.

Thanks,
Charles

author maintainer
#19 lore raw

PATCH 6/10 mfd: cs42l43: Add support for cs42l43 core driver

In reply to Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The MFD component registers and initialises the device and provides PM/system power management.

---
 MAINTAINERS                      |    2 +
 drivers/mfd/Kconfig              |   23 +
 drivers/mfd/Makefile             |    3 +
 drivers/mfd/cs42l43-i2c.c        |   86 +++
 drivers/mfd/cs42l43-sdw.c        |  210 ++++++
 drivers/mfd/cs42l43.c            | 1044 ++++++++++++++++++++++++++
 drivers/mfd/cs42l43.h            |   23 +
 include/linux/mfd/cs42l43-regs.h | 1172 ++++++++++++++++++++++++++++++
 include/linux/mfd/cs42l43.h      |   50 ++
 9 files changed, 2613 insertions(+)
 create mode 100644 drivers/mfd/cs42l43-i2c.c
 create mode 100644 drivers/mfd/cs42l43-sdw.c
 create mode 100644 drivers/mfd/cs42l43.c
 create mode 100644 drivers/mfd/cs42l43.h
 create mode 100644 include/linux/mfd/cs42l43-regs.h
 create mode 100644 include/linux/mfd/cs42l43.h
MAINTAINERS +2 -0
index 0db9f37eec258..8d2076941ff36 100644
@@ -4928,7 +4928,9 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/cirrus,cs*
 F:	Documentation/devicetree/bindings/sound/cirrus,cs*
+F:	drivers/mfd/cs42l43*
 F:	include/dt-bindings/sound/cs*
+F:	include/linux/mfd/cs42l43*
 F:	include/sound/cs*
 F:	sound/pci/hda/cs*
 F:	sound/pci/hda/hda_cs_dsp_ctl.*
drivers/mfd/Kconfig +23 -0
index e90463c4441ce..65ceb1be41296 100644
@@ -237,6 +237,29 @@ config MFD_CROS_EC_DEV
 	  To compile this driver as a module, choose M here: the module will be
 	  called cros-ec-dev.
 
+config MFD_CS42L43
+	tristate
+	select MFD_CORE
+	select REGMAP
+
+config MFD_CS42L43_I2C
+	tristate "Cirrus Logic CS42L43 (I2C)"
+	depends on I2C
+	select REGMAP_I2C
+	select MFD_CS42L43
+	help
+	  Select this to support the Cirrus Logic CS42L43 PC CODEC with
+	  headphone and class D speaker drivers over I2C.
+
+config MFD_CS42L43_SDW
+	tristate "Cirrus Logic CS42L43 (SoundWire)"
+	depends on SOUNDWIRE
+	select REGMAP_SOUNDWIRE
+	select MFD_CS42L43
+	help
+	  Select this to support the Cirrus Logic CS42L43 PC CODEC with
+	  headphone and class D speaker drivers over SoundWire.
+
 config MFD_MADERA
 	tristate "Cirrus Logic Madera codecs"
 	select MFD_CORE
drivers/mfd/Makefile +3 -0
index 1d2392f06f78a..407bc2f98dc19 100644
@@ -13,6 +13,9 @@ obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
 obj-$(CONFIG_MFD_BCM590XX)	+= bcm590xx.o
 obj-$(CONFIG_MFD_BD9571MWV)	+= bd9571mwv.o
 obj-$(CONFIG_MFD_CROS_EC_DEV)	+= cros_ec_dev.o
+obj-$(CONFIG_MFD_CS42L43)	+= cs42l43.o
+obj-$(CONFIG_MFD_CS42L43_I2C)	+= cs42l43-i2c.o
+obj-$(CONFIG_MFD_CS42L43_SDW)	+= cs42l43-sdw.o
 obj-$(CONFIG_MFD_ENE_KB3930)	+= ene-kb3930.o
 obj-$(CONFIG_MFD_EXYNOS_LPASS)	+= exynos-lpass.o
 obj-$(CONFIG_MFD_GATEWORKS_GSC)	+= gateworks-gsc.o
drivers/mfd/cs42l43-i2c.c new file +86 -0

86 lines not on this page · raw message

drivers/mfd/cs42l43-sdw.c new file +210 -0

210 lines not on this page · raw message

drivers/mfd/cs42l43.c new file +1044 -0

1,044 lines not on this page · raw message

drivers/mfd/cs42l43.h new file +23 -0
new file mode 100644
index 0000000000000..9983d6f13f1f5
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CS42L43 core driver internal data
+ *
+ * Copyright (C) 2022-2023 Cirrus Logic, Inc. and
+ *                         Cirrus Logic International Semiconductor Ltd.
+ */
+
+#include <linux/mfd/cs42l43.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+
+#ifndef CS42L43_CORE_INT_H
+#define CS42L43_CORE_INT_H
+
+extern const struct regmap_config cs42l43_i2c_regmap;
+extern const struct regmap_config cs42l43_sdw_regmap;
+extern const struct dev_pm_ops cs42l43_pm_ops;
+
+int cs42l43_dev_probe(struct cs42l43 *cs42l43);
+void cs42l43_dev_remove(struct cs42l43 *cs42l43);
+
+#endif /* CS42L43_CORE_INT_H */
include/linux/mfd/cs42l43-regs.h new file +1172 -0

1,172 lines not on this page · raw message

include/linux/mfd/cs42l43.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.30.2
#20 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 36 lines
drivers/mfd/cs42l43-sdw.c new file +33 -0
+static int cs42l43_sdw_update_status(struct sdw_slave *sdw, enum sdw_slave_status status)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(&sdw->dev);
+
+	switch (status) {
+	case SDW_SLAVE_ATTACHED:
+		dev_dbg(cs42l43->dev, "Device attach\n");
+
+		sdw_write_no_pm(sdw, CS42L43_GEN_INT_MASK_1,
+				CS42L43_INT_STAT_GEN1_MASK);
+
+		cs42l43->attached = true;
+
+		complete(&cs42l43->device_attach);
+		break;
+	case SDW_SLAVE_UNATTACHED:
+		dev_dbg(cs42l43->dev, "Device detach\n");
+
+		cs42l43->attached = false;
+
+		reinit_completion(&cs42l43->device_attach);
+		complete(&cs42l43->device_detach);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int cs42l43_sdw_interrupt(struct sdw_slave *sdw,
+				 struct sdw_slave_intr_status *status)
+{

drivers/mfd/cs42l43-sdw.c line 125

Quoted 10 lines
drivers/mfd/cs42l43-sdw.c new file +10 -0
+	/*
+	 * There is only a single bit in GEN_INT_STAT_1 and it doesn't clear if
+	 * IRQs are still pending so doing a read/write here after handling the
+	 * IRQ is fine.
+	 */
+	sdw_read_no_pm(sdw, CS42L43_GEN_INT_STAT_1);
+	sdw_write_no_pm(sdw, CS42L43_GEN_INT_STAT_1, 1);
+
+	return 0;
+}

not really getting the comment and code above. Where is the IRQ handled? In the 'other non-SoundWire part"?

Quoted 47 lines
drivers/mfd/cs42l43.c new file +47 -0
+static void cs42l43_boot_work(struct work_struct *work)
+{
+	struct cs42l43 *cs42l43 = container_of(work, struct cs42l43, boot_work);
+	unsigned int devid, revid, otp;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Boot work running\n");
+
+	ret = cs42l43_wait_for_attach(cs42l43);
+	if (ret)
+		goto err;
+
+	if (cs42l43->sdw)
+		cs42l43->irq = cs42l43->sdw->irq;
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_DEVID, &devid);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read devid: %d\n", ret);
+		goto err;
+	}
+
+	switch (devid) {
+	case 0x42a43:
+		break;
+	default:
+		dev_err(cs42l43->dev, "Unrecognised devid: 0x%06x\n", devid);
+		goto err;
+	}
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_REVID, &revid);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read rev: %d\n", ret);
+		goto err;
+	}
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_OTP_REVISION_ID, &otp);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read otp rev: %d\n", ret);
+		goto err;
+	}
+
+	dev_info(cs42l43->dev,
+		 "devid: 0x%06x, rev: 0x%02x, otp: 0x%02x\n", devid, revid, otp);
+
+	ret = cs42l43_mcu_update(cs42l43);
+	if (ret)
+		goto err;

drivers/mfd/cs42l43.c line 768

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
+		goto err;
+	}
+
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);

any reason why the two pm_runtime routines are not placed last, just before the return?

Quoted 62 lines
drivers/mfd/cs42l43.c new file +60 -0
+	ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+				   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),
+				   NULL, 0, NULL);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to add subdevices: %d\n", ret);
+		goto err;
+	}
+
+	dev_dbg(cs42l43->dev, "Successfully initialised\n");
+
+	return;
+
+err:
+	pm_runtime_put_sync(cs42l43->dev);
+	cs42l43_dev_remove(cs42l43);
+}
 
 
+int cs42l43_dev_probe(struct cs42l43 *cs42l43)
+{
+	int i, ret;
+
+	dev_set_drvdata(cs42l43->dev, cs42l43);
+
+	mutex_init(&cs42l43->pll_lock);
+	init_completion(&cs42l43->device_attach);
+	init_completion(&cs42l43->device_detach);
+	init_completion(&cs42l43->firmware_download);
+	INIT_WORK(&cs42l43->boot_work, cs42l43_boot_work);
+
+	regcache_cache_only(cs42l43->regmap, true);
+
+	cs42l43->reset = devm_gpiod_get_optional(cs42l43->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(cs42l43->reset)) {
+		ret = PTR_ERR(cs42l43->reset);
+		dev_err(cs42l43->dev, "Failed to get reset: %d\n", ret);
+		return ret;
+	}
+
+	cs42l43->vdd_p = devm_regulator_get(cs42l43->dev, "VDD_P");
+	if (IS_ERR(cs42l43->vdd_p)) {
+		ret = PTR_ERR(cs42l43->vdd_p);
+		dev_err(cs42l43->dev, "Failed to get VDD_P: %d\n", ret);
+		return ret;
+	}
+
+	cs42l43->vdd_d = devm_regulator_get(cs42l43->dev, "VDD_D");
+	if (IS_ERR(cs42l43->vdd_d)) {
+		ret = PTR_ERR(cs42l43->vdd_d);
+		dev_err(cs42l43->dev, "Failed to get VDD_D: %d\n", ret);
+		return ret;
+	}
+
+	BUILD_BUG_ON(ARRAY_SIZE(cs42l43_core_supplies) != CS42L43_N_SUPPLIES);
+
+	for (i = 0; i < CS42L43_N_SUPPLIES; i++)
+		cs42l43->core_supplies[i].supply = cs42l43_core_supplies[i];
+
+	ret = devm_regulator_bulk_get(cs42l43->dev, CS42L43_N_SUPPLIES,
+				      cs42l43->core_supplies);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to get core supplies: %d\n", ret);

drivers/mfd/cs42l43.c

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+		return ret;
+	}
+
+	ret = cs42l43_power_up(cs42l43);
+	if (ret)
+		return ret;
+
+	pm_runtime_set_autosuspend_delay(cs42l43->dev, 250);
+	pm_runtime_use_autosuspend(cs42l43->dev);
+	pm_runtime_set_active(cs42l43->dev);> +	pm_runtime_get_noresume(cs42l43->dev);

you probably want a comment to explain that the get_noresume() is intentional to prevent the device from suspending before the workqueue is handled.

Quoted 19 lines
drivers/mfd/cs42l43.c new file +18 -0
+	pm_runtime_enable(cs42l43->dev);
+
+	queue_work(system_long_wq, &cs42l43->boot_work);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(cs42l43_dev_probe, MFD_CS42L43);
 
+static int __maybe_unused cs42l43_suspend(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	int ret;
+
+	dev_dbg(cs42l43->dev, "System suspend\n");
+
+	/*
+	 * Don't care about being resumed here, but we do want force_resume to
+	 * always trigger an actual resume, so that register state for the
+	 * MCU/GPIOs is returned as soon as possible after system resume

drivers/mfd/cs42l43.c line 947

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	 */
+	pm_runtime_get_noresume(dev);
+
+	ret = pm_runtime_force_suspend(dev);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to force suspend: %d\n", ret);
+		return ret;
+	}
+
+	pm_runtime_put_noidle(dev);

Is the get_noresume/put_noidle useful here? What does it do?

And it seems wrong anyways, if pm_runtime_force_suspend() fails then the usage-count is not decreased.

Surprising sequence...

Quoted 43 lines
drivers/mfd/cs42l43.c new file +43 -0
+
+	ret = cs42l43_power_down(cs42l43);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int __maybe_unused cs42l43_resume(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	int ret;
+
+	dev_dbg(cs42l43->dev, "System resume\n");
+
+	ret = cs42l43_power_up(cs42l43);
+	if (ret)
+		return ret;
+
+	ret = pm_runtime_force_resume(dev);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to force resume: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int __maybe_unused cs42l43_runtime_suspend(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+
+	dev_dbg(cs42l43->dev, "Runtime suspend\n");
+
+	/*
+	 * Whilst we don't power the chip down here, going into runtime
+	 * suspend lets the SoundWire bus power down, which means we can't
+	 * communicate with the device any more.
+	 */
+	regcache_cache_only(cs42l43->regmap, true);
+
+	return 0;
+}

drivers/mfd/cs42l43.c line 1000

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+
+static int __maybe_unused cs42l43_runtime_resume(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	unsigned int reset_canary;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Runtime resume\n");
+
+	ret = cs42l43_wait_for_attach(cs42l43);

is there a specific reason why the existing initialization_complete is not used?

Quoted 34 lines
drivers/mfd/cs42l43.c new file +34 -0
+	if (ret)
+		return ret;
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_RELID, &reset_canary);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to check reset canary: %d\n", ret);
+		goto err;
+	}
+
+	if (!reset_canary) {
+		/*
+		 * If the canary has cleared the chip has reset, re-handle the
+		 * MCU and mark the cache as dirty to indicate the chip reset.
+		 */
+		ret = cs42l43_mcu_update(cs42l43);
+		if (ret)
+			goto err;
+
+		regcache_mark_dirty(cs42l43->regmap);
+	}
+
+	ret = regcache_sync(cs42l43->regmap);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to restore register cache: %d\n", ret);
+		goto err;
+	}
+
+	return 0;
+
+err:
+	regcache_cache_only(cs42l43->regmap, true);
+
+	return ret;
+}
author maintainer
#21 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 8 lines · Pierre-Louis Bossart
Quoted 8 lines
drivers/mfd/cs42l43-sdw.c new file +8 -0
+static int cs42l43_sdw_interrupt(struct sdw_slave *sdw,
+				 struct sdw_slave_intr_status *status)
+{
+	/*
+	 * There is only a single bit in GEN_INT_STAT_1 and it doesn't clear if
+	 * IRQs are still pending so doing a read/write here after handling the
+	 * IRQ is fine.
+	 */
Quoted 8 lines

drivers/mfd/cs42l43-sdw.c line 125

Quoted 5 lines
drivers/mfd/cs42l43-sdw.c new file +5 -0
+	sdw_read_no_pm(sdw, CS42L43_GEN_INT_STAT_1);
+	sdw_write_no_pm(sdw, CS42L43_GEN_INT_STAT_1, 1);
+
+	return 0;
+}

not really getting the comment and code above. Where is the IRQ handled? In the 'other non-SoundWire part"?

Yeah in the actual IRQ handler, I will update the comment to make this more clear.

Quoted 4 lines
Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
Quoted 8 lines

drivers/mfd/cs42l43.c line 768

Quoted 5 lines
drivers/mfd/cs42l43.c new file +5 -0
+		goto err;
+	}
+
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);

any reason why the two pm_runtime routines are not placed last, just before the return?

Yeah that probably makes more sense I will update.

Quoted 4 lines
Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+	ret = cs42l43_power_up(cs42l43);
+	if (ret)
+		return ret;
+
Quoted 8 lines

drivers/mfd/cs42l43.c line 911

Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+	pm_runtime_set_autosuspend_delay(cs42l43->dev, 250);
+	pm_runtime_use_autosuspend(cs42l43->dev);
+	pm_runtime_set_active(cs42l43->dev);
+	pm_runtime_get_noresume(cs42l43->dev);

you probably want a comment to explain that the get_noresume() is intentional to prevent the device from suspending before the workqueue is handled.

Yeah will add one.

Quoted 8 lines
Quoted 8 lines
drivers/mfd/cs42l43.c new file +8 -0
+	/*
+	 * Don't care about being resumed here, but we do want force_resume to
+	 * always trigger an actual resume, so that register state for the
+	 * MCU/GPIOs is returned as soon as possible after system resume
+	 */
+	pm_runtime_get_noresume(dev);
+
+	ret = pm_runtime_force_suspend(dev);
Quoted 8 lines

drivers/mfd/cs42l43.c line 947

Quoted 6 lines
drivers/mfd/cs42l43.c new file +6 -0
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to force suspend: %d\n", ret);
+		return ret;
+	}
+
+	pm_runtime_put_noidle(dev);

Is the get_noresume/put_noidle useful here? What does it do?

The hope was the comment would explain this :-) Yeah it is a slightly surprising sequence. It is about ensuring force_resume runs a runtime resume, which it will only do if the reference count is resumed when we suspend.

I will add a little more to the comment to hopefully clarify why we are doing this.

Quoted 2 lines

And it seems wrong anyways, if pm_runtime_force_suspend() fails then the usage-count is not decreased.

Yeah that is bug, thanks for the spot I will fix that up.

Quoted 4 lines
Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+static int __maybe_unused cs42l43_runtime_resume(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	unsigned int reset_canary;
Quoted 8 lines

drivers/mfd/cs42l43.c line 1000

Quoted 5 lines
drivers/mfd/cs42l43.c new file +5 -0
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Runtime resume\n");
+
+	ret = cs42l43_wait_for_attach(cs42l43);

is there a specific reason why the existing initialization_complete is not used?

Not massively, the driver does a fair amount of detaching and attaching during probe (has to soft reset a few times and they cause the device to fall off the bus). It was just slightly easier to keep track of all of them keeping the code internal to the driver and once we were doing it anyway it was less code to use the same mechanism on resume.

Thanks,
Charles

#22 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

In reply to Charles Keepax
Quoted 10 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The MFD component registers and initialises the device and provides PM/system power management.

Thank you for your patch. There is something to discuss/improve.

Quoted 15 lines
drivers/mfd/cs42l43.c new file +15 -0
+static const char * const cs42l43_core_supplies[] = {
+	"VDD_A", "VDD_IO", "VDD_CP",
+};
+
+static const char * const cs42l43_parent_supplies[] = { "VDD_AMP" };
+
+static const struct mfd_cell cs42l43_devs[] = {
+	{ .name = "cs42l43-pinctrl", },
+	{ .name = "cs42l43-irq", },
+	{ .name = "cs42l43-spi", },
+	{
+		.name = "cs42l43-codec",
+		.parent_supplies = cs42l43_parent_supplies,
+		.num_parent_supplies = ARRAY_SIZE(cs42l43_parent_supplies),
+	},

drivers/mfd/cs42l43.c line 449

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+};
+
+static int cs42l43_soft_reset(struct cs42l43 *cs42l43)
+{
+	static const struct reg_sequence reset[] = {
+		{ CS42L43_SFT_RESET, 0x5A000000 },
+	};
+	unsigned long time;
+
+	dev_dbg(cs42l43->dev, "Soft resetting\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 40 lines
drivers/mfd/cs42l43.c new file +40 -0
+
+	reinit_completion(&cs42l43->device_detach);
+
+	/* apply cache only as the device will also fall off the soundwire bus */
+	regcache_cache_only(cs42l43->regmap, true);
+	regmap_multi_reg_write_bypassed(cs42l43->regmap, reset, ARRAY_SIZE(reset));
+
+	msleep(20);
+
+	if (cs42l43->sdw) {
+		time = wait_for_completion_timeout(&cs42l43->device_detach,
+						   msecs_to_jiffies(100));
+		if (!time) {
+			dev_err(cs42l43->dev, "Timed out waiting for device detach\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	return -EAGAIN;
+}
+
+static int cs42l43_wait_for_attach(struct cs42l43 *cs42l43)
+{
+	unsigned long time;
+
+	if (!cs42l43->attached) {
+		time = wait_for_completion_timeout(&cs42l43->device_attach,
+						   msecs_to_jiffies(500));
+		if (!time) {
+			dev_err(cs42l43->dev, "Timed out waiting for device re-attach\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	regcache_cache_only(cs42l43->regmap, false);
+
+	// Must enable OSC_DIV before doing any SoundWire reads
+	if (cs42l43->sdw)
+		regmap_write(cs42l43->regmap, CS42L43_OSC_DIV_SEL, 0x1);
+

drivers/mfd/cs42l43.c line 499

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	return 0;
+}
+
+static int cs42l43_mcu_stage_2_3(struct cs42l43 *cs42l43, bool shadow)
+{
+	unsigned int need_reg = CS42L43_NEED_CONFIGS;
+	unsigned int val;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Moving firmware to stage 3\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 23 lines
drivers/mfd/cs42l43.c new file +23 -0
+
+	if (shadow)
+		need_reg = CS42L43_FW_SH_BOOT_CFG_NEED_CONFIGS;
+
+	regmap_write(cs42l43->regmap, need_reg, 0x0);
+
+	ret = regmap_read_poll_timeout(cs42l43->regmap, CS42L43_BOOT_STATUS,
+				       val, (val == 3), 5000, 20000);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to move to stage 3: %d, 0x%x\n", ret, val);
+		return ret;
+	}
+
+	return -EAGAIN;
+}
+
+static int cs42l43_mcu_stage_3_2(struct cs42l43 *cs42l43)
+{
+	dev_dbg(cs42l43->dev, "Returning firmware to stage 2\n");
+
+	regmap_write(cs42l43->regmap, CS42L43_FW_CTRL_NEED_CONFIGS,
+		     CS42L43_FW_PATCH_NEED_CFG_MASK);
+	regmap_write(cs42l43->regmap, CS42L43_FW_CTRL_HAVE_CONFIGS, 0x0);

drivers/mfd/cs42l43.c line 532

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+
+	return cs42l43_soft_reset(cs42l43);
+}
+
+static int cs42l43_mcu_disable(struct cs42l43 *cs42l43)
+{
+	unsigned int val;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Disabling firmware\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 23 lines
drivers/mfd/cs42l43.c new file +23 -0
+
+	regmap_write(cs42l43->regmap, CS42L43_FW_CTRL_MM_MCU_CFG_REG, 0xF05AA50F);
+	regmap_write(cs42l43->regmap, CS42L43_FW_CTRL_MM_CTRL_SELECTION, 0x1);
+	regmap_write(cs42l43->regmap, CS42L43_MCU_SW_INTERRUPT, CS42L43_CONTROL_IND_MASK);
+	regmap_write(cs42l43->regmap, CS42L43_MCU_SW_INTERRUPT, 0);
+
+	ret = regmap_read_poll_timeout(cs42l43->regmap, CS42L43_SOFT_INT_SHADOW, val,
+				       (val & CS42L43_CONTROL_APPLIED_INT_MASK),
+				       5000, 20000);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to disable firmware: %d, 0x%x\n", ret, val);
+		return ret;
+	}
+
+	/* Soft reset to clear any register state the firmware left behind */
+	return cs42l43_soft_reset(cs42l43);
+}
+
+struct cs42l43_patch_header {
+	__le16 version;
+	__le16 size;
+	u8 reserved;
+	u8 secure;

drivers/mfd/cs42l43.c line 565

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	__le16 bss_size;
+	__le32 apply_addr;
+	__le32 checksum;
+	__le32 sha;
+	__le16 swrev;
+	__le16 patchid;
+	__le16 ipxid;
+	__le16 romver;
+	__le32 load_addr;
+} __packed;

Put all structs together at the top.

Quoted 5 lines
drivers/mfd/cs42l43.c new file +5 -0
+
+static void cs42l43_mcu_load_firmware(const struct firmware *firmware, void *context)
+{
+	struct cs42l43 *cs42l43 = context;
+	struct cs42l43_patch_header *hdr;

drivers/mfd/cs42l43.c line 580

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	unsigned int loadaddr, val;
+	int ret;
+
+	if (!firmware) {
+		dev_err(cs42l43->dev, "Failed to load firmware\n");
+		cs42l43->firmware_error = -ENODEV;
+		goto err;
+	}
+
+	dev_dbg(cs42l43->dev, "Updating firmware\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

drivers/mfd/cs42l43.c line 582

Quoted 2 lines
drivers/mfd/cs42l43.c new file +2 -0
+
+	hdr = (void *)&firmware->data[0];

Aren't you dropping here const? Why? That's not recommended programming.

Quoted 126 lines
drivers/mfd/cs42l43.c new file +126 -0
+	loadaddr = le32_to_cpu(hdr->load_addr);
+
+	if (le16_to_cpu(hdr->version) != 0x3) {
+		dev_err(cs42l43->dev, "Bad firmware file format: %d\n", hdr->version);
+		cs42l43->firmware_error = -EINVAL;
+		goto err_release;
+	}
+
+	regmap_write(cs42l43->regmap, CS42L43_PATCH_START_ADDR, loadaddr);
+	regmap_bulk_write(cs42l43->regmap, loadaddr + 0x100000,
+			  &firmware->data[0], firmware->size / sizeof(u32));
+
+	regmap_write(cs42l43->regmap, CS42L43_MCU_SW_INTERRUPT, CS42L43_PATCH_IND_MASK);
+	regmap_write(cs42l43->regmap, CS42L43_MCU_SW_INTERRUPT, 0);
+
+	ret = regmap_read_poll_timeout(cs42l43->regmap, CS42L43_SOFT_INT_SHADOW, val,
+				       (val & CS42L43_PATCH_APPLIED_INT_MASK),
+				       5000, 500000);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to update firmware: %d, 0x%x\n", ret, val);
+		cs42l43->firmware_error = ret;
+		goto err_release;
+	}
+
+err_release:
+	release_firmware(firmware);
+err:
+	complete(&cs42l43->firmware_download);
+}
+
+static int cs42l43_mcu_update_step(struct cs42l43 *cs42l43)
+{
+	unsigned int mcu_rev, bios_rev, boot_status, secure_cfg;
+	bool patched, shadow;
+	int ret;
+
+	// Clear any stale software interrupt bits
+	regmap_read(cs42l43->regmap, CS42L43_SOFT_INT, &mcu_rev);
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_BOOT_STATUS, &boot_status);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read boot status: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_MCU_SW_REV, &mcu_rev);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read firmware revision: %d\n", ret);
+		return ret;
+	}
+
+	bios_rev = ((mcu_rev & CS42L43_BIOS_MAJOR_REV_MASK) << 12) |
+		   ((mcu_rev & CS42L43_BIOS_MINOR_REV_MASK) << 4) |
+		   ((mcu_rev & CS42L43_BIOS_SUBMINOR_REV_MASK) >> 8);
+	mcu_rev = ((mcu_rev & CS42L43_FW_MAJOR_REV_MASK) << 12) |
+		  ((mcu_rev & CS42L43_FW_MINOR_REV_MASK) << 4) |
+		  ((mcu_rev & CS42L43_FW_SUBMINOR_REV_MASK) >> 8);
+
+	patched = mcu_rev >= 0x2105 || bios_rev > 0x0000;
+	shadow = mcu_rev >= 0x2200;
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_BOOT_CONTROL, &secure_cfg);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read security settings: %d\n", ret);
+		return ret;
+	}
+
+	cs42l43->hw_lock = secure_cfg & CS42L43_LOCK_HW_STS_MASK;
+
+	if (!patched && cs42l43->hw_lock) {
+		dev_err(cs42l43->dev, "Unpatched secure device\n");
+		return -EPERM;
+	}
+
+	dev_dbg(cs42l43->dev, "Firmware(0x%x) in boot stage %d\n", mcu_rev, boot_status);
+
+	switch (boot_status) {
+	case 2:
+		if (!patched) {
+			ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
+						      "cs42l43.bin", cs42l43->dev,
+						      GFP_KERNEL, cs42l43,
+						      cs42l43_mcu_load_firmware);
+			if (ret) {
+				dev_err(cs42l43->dev, "Failed to request firmware: %d\n", ret);
+				return ret;
+			}
+
+			wait_for_completion(&cs42l43->firmware_download);
+
+			if (cs42l43->firmware_error)
+				return cs42l43->firmware_error;
+
+			return -EAGAIN;
+		} else {
+			return cs42l43_mcu_stage_2_3(cs42l43, shadow);
+		}
+	case 3:
+		if (patched)
+			return cs42l43_mcu_disable(cs42l43);
+		else
+			return cs42l43_mcu_stage_3_2(cs42l43);
+	case 4:
+		return 0;
+	default:
+		dev_err(cs42l43->dev, "Invalid boot status: %d\n", boot_status);
+		return -EINVAL;
+	}
+}
+
+static int cs42l43_mcu_update(struct cs42l43 *cs42l43)
+{
+	const int update_retries = 5;
+	int i, ret;
+
+	for (i = 0; i < update_retries; i++) {
+		ret = cs42l43_mcu_update_step(cs42l43);
+		if (ret != -EAGAIN)
+			return ret;
+
+		ret = cs42l43_wait_for_attach(cs42l43);
+		if (ret)
+			return ret;
+	}
+
+	dev_err(cs42l43->dev, "Failed retrying update\n");

drivers/mfd/cs42l43.c line 718

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	return -ETIMEDOUT;
+}
+
+static void cs42l43_boot_work(struct work_struct *work)
+{
+	struct cs42l43 *cs42l43 = container_of(work, struct cs42l43, boot_work);
+	unsigned int devid, revid, otp;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Boot work running\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 43 lines
drivers/mfd/cs42l43.c new file +43 -0
+
+	ret = cs42l43_wait_for_attach(cs42l43);
+	if (ret)
+		goto err;
+
+	if (cs42l43->sdw)
+		cs42l43->irq = cs42l43->sdw->irq;
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_DEVID, &devid);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read devid: %d\n", ret);
+		goto err;
+	}
+
+	switch (devid) {
+	case 0x42a43:
+		break;
+	default:
+		dev_err(cs42l43->dev, "Unrecognised devid: 0x%06x\n", devid);
+		goto err;
+	}
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_REVID, &revid);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read rev: %d\n", ret);
+		goto err;
+	}
+
+	ret = regmap_read(cs42l43->regmap, CS42L43_OTP_REVISION_ID, &otp);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to read otp rev: %d\n", ret);
+		goto err;
+	}
+
+	dev_info(cs42l43->dev,
+		 "devid: 0x%06x, rev: 0x%02x, otp: 0x%02x\n", devid, revid, otp);
+
+	ret = cs42l43_mcu_update(cs42l43);
+	if (ret)
+		goto err;
+
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));

drivers/mfd/cs42l43.c line 771

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
+		goto err;
+	}
+
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);
+
+	ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+				   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

drivers/mfd/cs42l43.c line 778

Quoted 7 lines
drivers/mfd/cs42l43.c new file +7 -0
+				   NULL, 0, NULL);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to add subdevices: %d\n", ret);
+		goto err;
+	}
+
+	dev_dbg(cs42l43->dev, "Successfully initialised\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 64 lines
drivers/mfd/cs42l43.c new file +64 -0
+
+	return;
+
+err:
+	pm_runtime_put_sync(cs42l43->dev);
+	cs42l43_dev_remove(cs42l43);
+}
+
+static int cs42l43_power_up(struct cs42l43 *cs42l43)
+{
+	int ret;
+
+	ret = regulator_enable(cs42l43->vdd_p);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to enable VDD_P: %d\n", ret);
+		return ret;
+	}
+
+	usleep_range(50, 100); /* VDD_P must be on for 50uS before any other supply */
+
+	gpiod_set_value_cansleep(cs42l43->reset, 1);
+
+	ret = regulator_bulk_enable(CS42L43_N_SUPPLIES, cs42l43->core_supplies);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to enable core supplies: %d\n", ret);
+		goto err_reset;
+	}
+
+	ret = regulator_enable(cs42l43->vdd_d);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to enable VDD_D: %d\n", ret);
+		goto err_core_supplies;
+	}
+
+	usleep_range(1000, 2000);
+
+	dev_dbg(cs42l43->dev, "Powered up\n");
+
+	return 0;
+
+err_core_supplies:
+	regulator_bulk_disable(CS42L43_N_SUPPLIES, cs42l43->core_supplies);
+err_reset:
+	gpiod_set_value_cansleep(cs42l43->reset, 0);
+	regulator_disable(cs42l43->vdd_p);
+
+	return ret;
+}
+
+static int cs42l43_power_down(struct cs42l43 *cs42l43)
+{
+	int ret;
+
+	ret = regulator_disable(cs42l43->vdd_d);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to disable VDD_D: %d\n", ret);
+		return ret;
+	}
+
+	ret = regulator_bulk_disable(CS42L43_N_SUPPLIES, cs42l43->core_supplies);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to disable core supplies: %d\n", ret);
+		return ret;
+	}

drivers/mfd/cs42l43.c line 852

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+
+	gpiod_set_value_cansleep(cs42l43->reset, 0);
+
+	ret = regulator_disable(cs42l43->vdd_p);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to disable VDD_P: %d\n", ret);
+		return ret;
+	}
+
+	dev_dbg(cs42l43->dev, "Powered down\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

Quoted 12 lines
drivers/mfd/cs42l43.c new file +12 -0
+
+	return 0;
+}
+
+int cs42l43_dev_probe(struct cs42l43 *cs42l43)
+{
+	int i, ret;
+
+	dev_set_drvdata(cs42l43->dev, cs42l43);
+
+	mutex_init(&cs42l43->pll_lock);
+	init_completion(&cs42l43->device_attach);

drivers/mfd/cs42l43.c line 874

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	init_completion(&cs42l43->device_detach);
+	init_completion(&cs42l43->firmware_download);
+	INIT_WORK(&cs42l43->boot_work, cs42l43_boot_work);
+
+	regcache_cache_only(cs42l43->regmap, true);
+
+	cs42l43->reset = devm_gpiod_get_optional(cs42l43->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(cs42l43->reset)) {
+		ret = PTR_ERR(cs42l43->reset);
+		dev_err(cs42l43->dev, "Failed to get reset: %d\n", ret);

return dev_err_probe

In other places as well

drivers/mfd/cs42l43.c line 878

Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+		return ret;
+	}
+
+	cs42l43->vdd_p = devm_regulator_get(cs42l43->dev, "VDD_P");

Why these are not part of bulk get?

Quoted 44 lines
drivers/mfd/cs42l43.c new file +44 -0
+	if (IS_ERR(cs42l43->vdd_p)) {
+		ret = PTR_ERR(cs42l43->vdd_p);
+		dev_err(cs42l43->dev, "Failed to get VDD_P: %d\n", ret);
+		return ret;
+	}
+
+	cs42l43->vdd_d = devm_regulator_get(cs42l43->dev, "VDD_D");
+	if (IS_ERR(cs42l43->vdd_d)) {
+		ret = PTR_ERR(cs42l43->vdd_d);
+		dev_err(cs42l43->dev, "Failed to get VDD_D: %d\n", ret);
+		return ret;
+	}
+
+	BUILD_BUG_ON(ARRAY_SIZE(cs42l43_core_supplies) != CS42L43_N_SUPPLIES);
+
+	for (i = 0; i < CS42L43_N_SUPPLIES; i++)
+		cs42l43->core_supplies[i].supply = cs42l43_core_supplies[i];
+
+	ret = devm_regulator_bulk_get(cs42l43->dev, CS42L43_N_SUPPLIES,
+				      cs42l43->core_supplies);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to get core supplies: %d\n", ret);
+		return ret;
+	}
+
+	ret = cs42l43_power_up(cs42l43);
+	if (ret)
+		return ret;
+
+	pm_runtime_set_autosuspend_delay(cs42l43->dev, 250);
+	pm_runtime_use_autosuspend(cs42l43->dev);
+	pm_runtime_set_active(cs42l43->dev);
+	pm_runtime_get_noresume(cs42l43->dev);
+	pm_runtime_enable(cs42l43->dev);
+
+	queue_work(system_long_wq, &cs42l43->boot_work);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(cs42l43_dev_probe, MFD_CS42L43);
+
+void cs42l43_dev_remove(struct cs42l43 *cs42l43)
+{
+	pm_runtime_disable(cs42l43->dev);

drivers/mfd/cs42l43.c line 932

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	cs42l43_power_down(cs42l43);
+}
+EXPORT_SYMBOL_NS_GPL(cs42l43_dev_remove, MFD_CS42L43);
+
+static int __maybe_unused cs42l43_suspend(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	int ret;
+
+	dev_dbg(cs42l43->dev, "System suspend\n");

Drop simple debug statements. There are other tools in kernel to do such debugging.

Quoted 19 lines
drivers/mfd/cs42l43.c new file +19 -0
+
+	/*
+	 * Don't care about being resumed here, but we do want force_resume to
+	 * always trigger an actual resume, so that register state for the
+	 * MCU/GPIOs is returned as soon as possible after system resume
+	 */
+	pm_runtime_get_noresume(dev);
+
+	ret = pm_runtime_force_suspend(dev);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to force suspend: %d\n", ret);
+		return ret;
+	}
+
+	pm_runtime_put_noidle(dev);
+
+	ret = cs42l43_power_down(cs42l43);
+	if (ret)
+		return ret;

drivers/mfd/cs42l43.c line 961

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+
+	return 0;
+}
+
+static int __maybe_unused cs42l43_resume(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	int ret;
+
+	dev_dbg(cs42l43->dev, "System resume\n");

Ditto

Quoted 9 lines
drivers/mfd/cs42l43.c new file +9 -0
+
+	ret = cs42l43_power_up(cs42l43);
+	if (ret)
+		return ret;
+
+	ret = pm_runtime_force_resume(dev);
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to force resume: %d\n", ret);
+		return ret;

drivers/mfd/cs42l43.c line 980

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+	}
+
+	return 0;
+}
+
+static int __maybe_unused cs42l43_runtime_suspend(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+
+	dev_dbg(cs42l43->dev, "Runtime suspend\n");

Ditto

Quoted 9 lines
drivers/mfd/cs42l43.c new file +9 -0
+
+	/*
+	 * Whilst we don't power the chip down here, going into runtime
+	 * suspend lets the SoundWire bus power down, which means we can't
+	 * communicate with the device any more.
+	 */
+	regcache_cache_only(cs42l43->regmap, true);
+
+	return 0;

drivers/mfd/cs42l43.c line 999

Quoted 10 lines
drivers/mfd/cs42l43.c new file +10 -0
+}
+
+static int __maybe_unused cs42l43_runtime_resume(struct device *dev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(dev);
+	unsigned int reset_canary;
+	int ret;
+
+	dev_dbg(cs42l43->dev, "Runtime resume\n");
+

Ditto

Best regards,
Krzysztof

author maintainer
#23 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 12 lines · Krzysztof Kozlowski

drivers/mfd/cs42l43.c line 449

Quoted 8 lines · Charles Keepax
drivers/mfd/cs42l43.c new file +8 -0
+static int cs42l43_soft_reset(struct cs42l43 *cs42l43)
+{
+	static const struct reg_sequence reset[] = {
+		{ CS42L43_SFT_RESET, 0x5A000000 },
+	};
+	unsigned long time;
+
+	dev_dbg(cs42l43->dev, "Soft resetting\n");

Drop simple debug statements for function entry/exit. There are other tools in kernel to do such debugging.

I mean I guess I can begrudingly drop them, there sure are other tools but often just firing on debug is nice/simple/easy and they are not really marking function entry/exit as much as they are marking important events.

Quoted 9 lines
Quoted 9 lines
drivers/mfd/cs42l43.c new file +9 -0
+struct cs42l43_patch_header {
+	__le16 version;
+	__le16 size;
+	u8 reserved;
+	u8 secure;
+	__le16 bss_size;
+	__le32 apply_addr;
+	__le32 checksum;
+	__le32 sha;
Quoted 8 lines

drivers/mfd/cs42l43.c line 565

Quoted 6 lines
drivers/mfd/cs42l43.c new file +6 -0
+	__le16 swrev;
+	__le16 patchid;
+	__le16 ipxid;
+	__le16 romver;
+	__le32 load_addr;
+} __packed;

Put all structs together at the top.

Can do.

Quoted 3 lines

drivers/mfd/cs42l43.c line 582

Quoted 1 line
drivers/mfd/cs42l43.c new file +1 -0
+	hdr = (void *)&firmware->data[0];

Aren't you dropping here const? Why? That's not recommended programming.

Yeah that is fair will fix that up.

Quoted 7 lines
Quoted 7 lines
drivers/mfd/cs42l43.c new file +7 -0
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
+		goto err;
+	}
+
Quoted 8 lines

drivers/mfd/cs42l43.c line 771

Quoted 5 lines
drivers/mfd/cs42l43.c new file +5 -0
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);
+
+	ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+				   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

Well except SoundWire is a bit of a special boy, the hardware is not necessarily available in probe, the hardware is only available at some point later when the device attaches. Doing it this way all of the attaching (and various detach/attach cycles the device needs during configuration) are over by the time the child drivers bind, so they don't all need special code to handle that.

Quoted 6 lines

drivers/mfd/cs42l43.c line 874

Quoted 4 lines
drivers/mfd/cs42l43.c new file +4 -0
+	cs42l43->reset = devm_gpiod_get_optional(cs42l43->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(cs42l43->reset)) {
+		ret = PTR_ERR(cs42l43->reset);
+		dev_err(cs42l43->dev, "Failed to get reset: %d\n", ret);

return dev_err_probe

Yeah will put those in.

Quoted 3 lines

drivers/mfd/cs42l43.c line 878

Quoted 1 line
drivers/mfd/cs42l43.c new file +1 -0
+	cs42l43->vdd_p = devm_regulator_get(cs42l43->dev, "VDD_P");

Why these are not part of bulk get?

The comment right above explains this, VDD_P needs to be on for at least 50uS before any other supply.

Thanks,
Charles

#24 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 17 lines
Quoted 16 lines

drivers/mfd/cs42l43.c line 771

Quoted 13 lines
drivers/mfd/cs42l43.c new file +12 -0
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
+		goto err;
+	}
+
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);
+
+	ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+				   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

Quoted 6 lines

Well except SoundWire is a bit of a special boy, the hardware is not necessarily available in probe, the hardware is only available at some point later when the device attaches. Doing it this way all of the attaching (and various detach/attach cycles the device needs during configuration) are over by the time the child drivers bind, so they don't all need special code to handle that.

if the devices are added in the probe, then the regmap needs to be moved to cache-only and another special API would be needed to tell the MFD framework to turn the regmap cache-only off.

But if it's the same regmap, the regmap cache is handled in the SoundWire update_status callback so maybe Krzysztof's proposal does work?

#25 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 24 lines · Pierre-Louis Bossart
Quoted 17 lines
Quoted 16 lines

drivers/mfd/cs42l43.c line 771

Quoted 13 lines
drivers/mfd/cs42l43.c new file +12 -0
+	ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch,
+				    ARRAY_SIZE(cs42l43_reva_patch));
+	if (ret) {
+		dev_err(cs42l43->dev, "Failed to apply register patch: %d\n", ret);
+		goto err;
+	}
+
+	pm_runtime_mark_last_busy(cs42l43->dev);
+	pm_runtime_put_autosuspend(cs42l43->dev);
+
+	ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+				   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

Quoted 6 lines

Well except SoundWire is a bit of a special boy, the hardware is not necessarily available in probe, the hardware is only available at some point later when the device attaches. Doing it this way all of the attaching (and various detach/attach cycles the device needs during configuration) are over by the time the child drivers bind, so they don't all need special code to handle that.

Quoted 6 lines

if the devices are added in the probe, then the regmap needs to be moved to cache-only and another special API would be needed to tell the MFD framework to turn the regmap cache-only off.

But if it's the same regmap, the regmap cache is handled in the SoundWire update_status callback so maybe Krzysztof's proposal does work?

But you still can't access the hardware in probe(). So you'd have all
the child drivers probing but not able to talk to the hardware. The
child drivers would have to hook into the update_status() somehow so
they know when the peripheral has enumerated.
It's simpler to add them after the hardware has enumerated - they will be able to access the hardware in their probe().

#26 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 36 lines · Richard Fitzgerald
Quoted 25 lines · Pierre-Louis Bossart
Quoted 18 lines
Quoted 17 lines
Quoted 8 lines

+    ret = regmap_register_patch(cs42l43->regmap, cs42l43_reva_patch, +                    ARRAY_SIZE(cs42l43_reva_patch));
+    if (ret) {
+        dev_err(cs42l43->dev, "Failed to apply register patch:
%d\n", ret);
+        goto err;
+    }

drivers/mfd/cs42l43.c line 771

Quoted 6 lines
drivers/mfd/cs42l43.c new file +6 -0
+
+    pm_runtime_mark_last_busy(cs42l43->dev);
+    pm_runtime_put_autosuspend(cs42l43->dev);
+
+    ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE,
+                   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

Quoted 6 lines

Well except SoundWire is a bit of a special boy, the hardware is not necessarily available in probe, the hardware is only available at some point later when the device attaches. Doing it this way all of the attaching (and various detach/attach cycles the device needs during configuration) are over by the time the child drivers bind, so they don't all need special code to handle that.

Quoted 7 lines

if the devices are added in the probe, then the regmap needs to be moved to cache-only and another special API would be needed to tell the MFD framework to turn the regmap cache-only off.

But if it's the same regmap, the regmap cache is handled in the SoundWire update_status callback so maybe  Krzysztof's proposal does work?

Quoted 6 lines

But you still can't access the hardware in probe(). So you'd have all the child drivers probing but not able to talk to the hardware. The child drivers would have to hook into the update_status() somehow so they know when the peripheral has enumerated.
It's simpler to add them after the hardware has enumerated - they will be able to access the hardware in their probe().

It depends on what you mean by 'access the hardware'. If the only interface is regmap and regmap is in cache-only, then the child drivers could "access the hardware" without anything happening until after regmap is no longer cache-only.

But yeah, I realize it's a long shot.

author maintainer
#27 lore raw

Re: [PATCH 06/10] mfd: cs42l43: Add support for cs42l43 core driver

Quoted 30 lines · Pierre-Louis Bossart
Quoted 22 lines · Richard Fitzgerald
Quoted 13 lines · Pierre-Louis Bossart
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

+    ret = devm_mfd_add_devices(cs42l43->dev, PLATFORM_DEVID_NONE, +                   cs42l43_devs, ARRAY_SIZE(cs42l43_devs),

I don't why adding devices is not in probe. They use the same regmap right? So there will be no problem in probing them from MFD probe.

Quoted 6 lines

Well except SoundWire is a bit of a special boy, the hardware is not necessarily available in probe, the hardware is only available at some point later when the device attaches. Doing it this way all of the attaching (and various detach/attach cycles the device needs during configuration) are over by the time the child drivers bind, so they don't all need special code to handle that.

Quoted 7 lines

if the devices are added in the probe, then the regmap needs to be moved to cache-only and another special API would be needed to tell the MFD framework to turn the regmap cache-only off.

But if it's the same regmap, the regmap cache is handled in the SoundWire update_status callback so maybe  Krzysztof's proposal does work?

Quoted 6 lines

But you still can't access the hardware in probe(). So you'd have all the child drivers probing but not able to talk to the hardware. The child drivers would have to hook into the update_status() somehow so they know when the peripheral has enumerated.
It's simpler to add them after the hardware has enumerated - they will be able to access the hardware in their probe().

Quoted 6 lines

It depends on what you mean by 'access the hardware'. If the only interface is regmap and regmap is in cache-only, then the child drivers could "access the hardware" without anything happening until after regmap is no longer cache-only.

But yeah, I realize it's a long shot.

Yeah, its never just the regmap. Take the sound driver for example, when the sound driver binds all the components will be inplace and a soundcard will be created. This means the user could then start an audio stream before any hardware is actually available, various bits of the audio bring up rely on timing or reading state so won't work in cache-only. Yeah you could add work arounds for these problems as they arise, but you will end up with a lot of them.

I would flip this around and ask, what is the problem with adding the child devices once the device has completed initialisation? As far as I can see it looks like a choice between moving one function call with no obvious downside, against loads lines of various work arounds in each of the child drivers for whatever subsystem specific problems are caused by the device not actually being available.

Thanks,
Charles

author maintainer
#28 lore raw

PATCH 7/10 irqchip/cs42l43: Add support for the cs42l43 IRQs

In reply to Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

---
 MAINTAINERS                     |   2 +
 drivers/irqchip/Kconfig         |   9 ++
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-cs42l43.c   | 170 ++++++++++++++++++++++++++++++++
 include/linux/irqchip/cs42l43.h |  61 ++++++++++++
 5 files changed, 243 insertions(+)
 create mode 100644 drivers/irqchip/irq-cs42l43.c
 create mode 100644 include/linux/irqchip/cs42l43.h
MAINTAINERS +2 -0
index 8d2076941ff36..13945ee6cdcfe 100644
@@ -4928,8 +4928,10 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/cirrus,cs*
 F:	Documentation/devicetree/bindings/sound/cirrus,cs*
+F:	drivers/irqchip/irq-cs42l43*
 F:	drivers/mfd/cs42l43*
 F:	include/dt-bindings/sound/cs*
+F:	include/linux/irqchip/cs42l43*
 F:	include/linux/mfd/cs42l43*
 F:	include/sound/cs*
 F:	sound/pci/hda/cs*
drivers/irqchip/Kconfig +9 -0
index 09e422da482ff..05f58015749e3 100644
@@ -138,6 +138,15 @@ config BRCMSTB_L2_IRQ
 	select GENERIC_IRQ_CHIP
 	select IRQ_DOMAIN
 
+config IRQ_CS42L43
+	tristate "Cirrus Logic CS42L43 IRQ Controller"
+	depends on MFD_CS42L43
+	select REGMAP_IRQ
+	help
+	  Select this to support the IRQ functions of the Cirrus Logic
+	  CS42L43 PC CODEC, note the IRQs are required for most other
+	  functions of the device.
+
 config DAVINCI_CP_INTC
 	bool
 	select GENERIC_IRQ_CHIP
drivers/irqchip/Makefile +1 -0
index ffd945fe71aa2..d00330c1b0b95 100644
@@ -66,6 +66,7 @@ obj-$(CONFIG_BCM6345_L1_IRQ)		+= irq-bcm6345-l1.o
 obj-$(CONFIG_BCM7038_L1_IRQ)		+= irq-bcm7038-l1.o
 obj-$(CONFIG_BCM7120_L2_IRQ)		+= irq-bcm7120-l2.o
 obj-$(CONFIG_BRCMSTB_L2_IRQ)		+= irq-brcmstb-l2.o
+obj-$(CONFIG_IRQ_CS42L43)		+= irq-cs42l43.o
 obj-$(CONFIG_KEYSTONE_IRQ)		+= irq-keystone.o
 obj-$(CONFIG_MIPS_GIC)			+= irq-mips-gic.o
 obj-$(CONFIG_ARCH_MEDIATEK)		+= irq-mtk-sysirq.o irq-mtk-cirq.o
drivers/irqchip/irq-cs42l43.c new file +170 -0

170 lines not on this page · raw message

include/linux/irqchip/cs42l43.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.30.2
#29 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 10 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

This is just a another variant of the board-file theme, which has nothing to do with the irqchip subsystem.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#30 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 10 lines · Marc Zyngier
Quoted 8 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Quoted 7 lines
Quoted 2 lines

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

Apologies but I really need a little help clarifying the issues here. I am totally happy to fix things up but might need a couple pointers.

1) uses the irqchip API / uses irq domains

The driver does use both the irqchip API and domains, what part of the IRQ API are we not using that we should be?

The driver registers an irq domain using irq_domain_create_linear. It requests its parent IRQ using request_threaded_irq. It passes IRQs onto the devices requesting IRQs from it using handle_nested_irq and irq_find_mapping.

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

2) driver is firmware-driven (DT or ACPI, pick your poison)

The irq chip has representation in firmware, in fact we have tested this on both ACPI and DT. Other devices can request IRQs from it through firmware, same as they can for any other IRQ chip.

Is the objection here the table mapping the register fields that are provided as an IRQ on the device?

Thanks kindly for your review and help,
Charles

#31 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 29 lines · Charles Keepax
Quoted 10 lines · Marc Zyngier
Quoted 8 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Quoted 7 lines
Quoted 2 lines

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

Apologies but I really need a little help clarifying the issues here. I am totally happy to fix things up but might need a couple pointers.

1) uses the irqchip API / uses irq domains

The driver does use both the irqchip API and domains, what part of the IRQ API are we not using that we should be?

Quoted 7 lines

The driver registers an irq domain using irq_domain_create_linear. It requests its parent IRQ using request_threaded_irq. It passes IRQs onto the devices requesting IRQs from it using handle_nested_irq and irq_find_mapping.

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

That's one of the reasons. Look at the existing irqchip drivers: they have nothing in common with yours. The regmap irqchip abstraction may be convenient for what you are doing, but the result isn't really an irqchip driver. It is something that is a small bit of a larger device and not an interrupt controller driver on its own. The irqchip subsystem is there for "first class" interrupt controllers.

Quoted 7 lines

2) driver is firmware-driven (DT or ACPI, pick your poison)

The irq chip has representation in firmware, in fact we have tested this on both ACPI and DT. Other devices can request IRQs from it through firmware, same as they can for any other IRQ chip.

That's not what I'm talking about.

Quoted 2 lines

Is the objection here the table mapping the register fields that are provided as an IRQ on the device?

I'm referring to this sort of construct:

+ CS42L43_IRQ_REG(HP_STARTUP_DONE, MSM),
+ CS42L43_IRQ_REG(HP_SHUTDOWN_DONE, MSM),
+ CS42L43_IRQ_REG(HSDET_DONE, MSM),
+ CS42L43_IRQ_REG(TIPSENSE_UNPLUG_DB, MSM),
+ CS42L43_IRQ_REG(TIPSENSE_PLUG_DB, MSM),
+ CS42L43_IRQ_REG(RINGSENSE_UNPLUG_DB, MSM),
+ CS42L43_IRQ_REG(RINGSENSE_PLUG_DB, MSM),
+ CS42L43_IRQ_REG(TIPSENSE_UNPLUG_PDET, MSM),
+ CS42L43_IRQ_REG(TIPSENSE_PLUG_PDET, MSM),
+ CS42L43_IRQ_REG(RINGSENSE_UNPLUG_PDET, MSM),
+ CS42L43_IRQ_REG(RINGSENSE_PLUG_PDET, MSM),

Why isn't this described in firmware tables? Why doesn't it need to be carried as part of the driver? Is "CLASS_D_AMP" something an interrupt controller driver should care about?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#32 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 8 lines · Marc Zyngier
Quoted 5 lines · Charles Keepax
Quoted 2 lines · Marc Zyngier

On Fri, 12 May 2023 13:28:35 +0100,
Charles Keepax <[email protected]> wrote:

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

Quoted 7 lines

That's one of the reasons. Look at the existing irqchip drivers: they have nothing in common with yours. The regmap irqchip abstraction may be convenient for what you are doing, but the result isn't really an irqchip driver. It is something that is a small bit of a larger device and not an interrupt controller driver on its own. The irqchip subsystem is there for "first class" interrupt controllers.

Thank you this is helpful. This device has GPIOs that other devices might want to use for IRQs, so the chip is capable of providing IRQ services to other devices in the system not just itself. This is commonly used where external boosted amps have their IRQs hooked up to the CODEC.

I guess if Mark doesn't mind I think the only internal bit of the device that uses the IRQs is the CODEC driver so I could move the IRQ handling in there, it does seem a little odd to me, but I guess I don't have any problems with it.

Quoted 17 lines
Quoted 2 lines

Is the objection here the table mapping the register fields that are provided as an IRQ on the device?

I'm referring to this sort of construct:

drivers/irqchip/irq-cs42l43.c new file +11 -0
+	CS42L43_IRQ_REG(HP_STARTUP_DONE,			MSM),
+	CS42L43_IRQ_REG(HP_SHUTDOWN_DONE,			MSM),
+	CS42L43_IRQ_REG(HSDET_DONE,				MSM),
+	CS42L43_IRQ_REG(TIPSENSE_UNPLUG_DB,			MSM),
+	CS42L43_IRQ_REG(TIPSENSE_PLUG_DB,			MSM),
+	CS42L43_IRQ_REG(RINGSENSE_UNPLUG_DB,			MSM),
+	CS42L43_IRQ_REG(RINGSENSE_PLUG_DB,			MSM),
+	CS42L43_IRQ_REG(TIPSENSE_UNPLUG_PDET,			MSM),
+	CS42L43_IRQ_REG(TIPSENSE_PLUG_PDET,			MSM),
+	CS42L43_IRQ_REG(RINGSENSE_UNPLUG_PDET,			MSM),
+	CS42L43_IRQ_REG(RINGSENSE_PLUG_PDET,			MSM),
Quoted 1 line

Why isn't this described in firmware tables?

So we probably could do that for device tree systems, but getting this into ACPI I think will be exceedingly difficult, and that is likely the primary market for the device.

Quoted 3 lines

Why doesn't it need to be
carried as part of the driver? Is "CLASS_D_AMP" something an interrupt controller driver should care about?

Ah ok so I think I am starting to understand, if I might paraphrase, your main objection here is that many of the IRQs are fixed purpose signals originating inside the chip itself, rather than external lines that can be hooked up for generic purposes.

I guess most "first class" IRQ controllers have a lot more generic IRQs than they do fixed purpose ones. Where as we only have the 3 GPIOs as generic purpose IRQ lines.

Thanks,
Charles

maintainer
#33 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 4 lines · Charles Keepax

I guess if Mark doesn't mind I think the only internal bit of the device that uses the IRQs is the CODEC driver so I could move the IRQ handling in there, it does seem a little odd to me, but I guess I don't have any problems with it.

The obvious (and previously standard) place for it would be the MFD.

author maintainer
#34 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 8 lines · Mark Brown
Quoted 4 lines · Charles Keepax

I guess if Mark doesn't mind I think the only internal bit of the device that uses the IRQs is the CODEC driver so I could move the IRQ handling in there, it does seem a little odd to me, but I guess I don't have any problems with it.

The obvious (and previously standard) place for it would be the MFD.

Alright I certainly have no objection to moving it there, although would be good to get Lee's thoughts, make sure he is happy with that too.

Thanks,
Charles

maintainer
#35 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 8 lines · Charles Keepax
Quoted 7 lines · Mark Brown
Quoted 4 lines · Charles Keepax

I guess if Mark doesn't mind I think the only internal bit of the device that uses the IRQs is the CODEC driver so I could move the IRQ handling in there, it does seem a little odd to me, but I guess I don't have any problems with it.

Quoted 5 lines
Quoted 1 line

The obvious (and previously standard) place for it would be the MFD.

Alright I certainly have no objection to moving it there, although would be good to get Lee's thoughts, make sure he is happy with that too.

Submit a patch and we'll take it from there.

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#36 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

In reply to Marc Zyngier
Quoted 39 lines · Marc Zyngier
Quoted 29 lines · Charles Keepax
Quoted 10 lines · Marc Zyngier
Quoted 8 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Quoted 7 lines
Quoted 2 lines

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

Apologies but I really need a little help clarifying the issues here. I am totally happy to fix things up but might need a couple pointers.

1) uses the irqchip API / uses irq domains

The driver does use both the irqchip API and domains, what part of the IRQ API are we not using that we should be?

Quoted 7 lines

The driver registers an irq domain using irq_domain_create_linear. It requests its parent IRQ using request_threaded_irq. It passes IRQs onto the devices requesting IRQs from it using handle_nested_irq and irq_find_mapping.

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

Quoted 6 lines

That's one of the reasons. Look at the existing irqchip drivers: they have nothing in common with yours. The regmap irqchip abstraction may be convenient for what you are doing, but the result isn't really an irqchip driver. It is something that is a small bit of a larger device and not an interrupt controller driver on its own. The irqchip subsystem is there for "first class" interrupt controllers.

I'm not aware of another subsystem that deals with !IRQChip level IRQ controllers. Where do simple or "second class" interrupt controllers go?

Signature · 1 line
Lee Jones [李琼斯]
#37 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 49 lines · Lee Jones
Quoted 39 lines · Marc Zyngier
Quoted 29 lines · Charles Keepax
Quoted 10 lines · Marc Zyngier
Quoted 8 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Quoted 7 lines
Quoted 2 lines

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

Apologies but I really need a little help clarifying the issues here. I am totally happy to fix things up but might need a couple pointers.

1) uses the irqchip API / uses irq domains

The driver does use both the irqchip API and domains, what part of the IRQ API are we not using that we should be?

Quoted 7 lines

The driver registers an irq domain using irq_domain_create_linear. It requests its parent IRQ using request_threaded_irq. It passes IRQs onto the devices requesting IRQs from it using handle_nested_irq and irq_find_mapping.

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

Quoted 6 lines

That's one of the reasons. Look at the existing irqchip drivers: they have nothing in common with yours. The regmap irqchip abstraction may be convenient for what you are doing, but the result isn't really an irqchip driver. It is something that is a small bit of a larger device and not an interrupt controller driver on its own. The irqchip subsystem is there for "first class" interrupt controllers.

Quoted 3 lines

I'm not aware of another subsystem that deals with !IRQChip level IRQ controllers. Where do simple or "second class" interrupt controllers go?

This isn't an interrupt controller. This is internal signalling, local to a single component that has been artificially broken into discrete bits, including an interrupt controller. The only *real* interrupts here are the GPIOs.

I'm happy to see an interrupt controller for the GPIOs. But the rest is just internal muck that doesn't really belong here. Where should it go? Together with the rest of the stuff that manages the block as a whole. Which looks like the MFD subsystem to me.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#38 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 55 lines · Marc Zyngier
Quoted 49 lines · Lee Jones
Quoted 39 lines · Marc Zyngier
Quoted 29 lines · Charles Keepax
Quoted 10 lines · Marc Zyngier
Quoted 8 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Quoted 7 lines
Quoted 2 lines

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Sorry, but this isn't much of an interrupt controller driver. A modern interrupt controller driver is firmware-driven (DT or ACPI, pick your poison), uses irq domains, and uses the irqchip API.

Apologies but I really need a little help clarifying the issues here. I am totally happy to fix things up but might need a couple pointers.

1) uses the irqchip API / uses irq domains

The driver does use both the irqchip API and domains, what part of the IRQ API are we not using that we should be?

Quoted 7 lines

The driver registers an irq domain using irq_domain_create_linear. It requests its parent IRQ using request_threaded_irq. It passes IRQs onto the devices requesting IRQs from it using handle_nested_irq and irq_find_mapping.

Is the objection here that regmap is making these calls for us, rather than them being hard coded into this driver?

Quoted 6 lines

That's one of the reasons. Look at the existing irqchip drivers: they have nothing in common with yours. The regmap irqchip abstraction may be convenient for what you are doing, but the result isn't really an irqchip driver. It is something that is a small bit of a larger device and not an interrupt controller driver on its own. The irqchip subsystem is there for "first class" interrupt controllers.

Quoted 3 lines

I'm not aware of another subsystem that deals with !IRQChip level IRQ controllers. Where do simple or "second class" interrupt controllers go?

Quoted 7 lines

This isn't an interrupt controller. This is internal signalling, local to a single component that has been artificially broken into discrete bits, including an interrupt controller. The only *real* interrupts here are the GPIOs.

I'm happy to see an interrupt controller for the GPIOs. But the rest is just internal muck that doesn't really belong here. Where should it

You should have been a poet! =;-)

Quoted 2 lines

go? Together with the rest of the stuff that manages the block as a whole. Which looks like the MFD subsystem to me.

Very well. Let's see this "muck" in a patch please!

Signature · 1 line
Lee Jones [李琼斯]
#39 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

Quoted 7 lines · Lee Jones
Quoted 2 lines · Marc Zyngier

I'm happy to see an interrupt controller for the GPIOs. But the rest is just internal muck that doesn't really belong here. Where should it

You should have been a poet! =;-)

Who says I'm not?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#40 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

In reply to Lee Jones
Quoted 10 lines · Lee Jones
Quoted 9 lines · Marc Zyngier
Quoted 6 lines · Lee Jones
Quoted 2 lines · Marc Zyngier

On Fri, 12 May 2023 16:39:33 +0100,
Charles Keepax <[email protected]> wrote:

I'm not aware of another subsystem that deals with !IRQChip level IRQ controllers. Where do simple or "second class" interrupt controllers go?

Quoted 5 lines
Quoted 5 lines

This isn't an interrupt controller. This is internal signalling, local to a single component that has been artificially broken into discrete bits, including an interrupt controller. The only *real* interrupts here are the GPIOs.

I would question this statement a little, they are fixed function IRQs sure but they are still real interrupts. These are lines which receive a signal and on an edge they set a stick status bit, which causes another signal to generate an edge, they have registers which let you mask events, if it walks like a duck and all. The only difference between this and a "real" interrupt is whether the chip designer or the board designer was the person who decided where the wire was connected.

Quoted 2 lines
Quoted 2 lines

I'm happy to see an interrupt controller for the GPIOs. But the rest is just internal muck that doesn't really belong here. Where should it

Internal-ish, granted many of them are primarily useful to the device itself. But it is very easy to construct situations where say knowing the speaker thermals are high, or that a jack has been inserted are useful outside of the CODEC driver itself.

Quoted 4 lines
Quoted 2 lines

go? Together with the rest of the stuff that manages the block as a whole. Which looks like the MFD subsystem to me.

Very well. Let's see this "muck" in a patch please!

Groovy I will do a re-spin moving the IRQ stuff to the MFD and lets see where we get to.

Thank you all for your help in reviewing this so far.

Thanks,
Charles

#41 lore raw

Re: [PATCH 07/10] irqchip/cs42l43: Add support for the cs42l43 IRQs

In reply to Charles Keepax
Quoted 11 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The IRQ chip provides IRQ functionality both to other parts of the cs42l43 device and to external devices that wish to use its IRQs.

Thank you for your patch. There is something to discuss/improve.

Quoted 5 lines
drivers/irqchip/irq-cs42l43.c new file +5 -0
+
+static struct platform_driver cs42l43_irq_driver = {
+	.driver = {
+		.name	= "cs42l43-irq",
+	},

drivers/irqchip/irq-cs42l43.c line 170

Quoted 10 lines
drivers/irqchip/irq-cs42l43.c new file +10 -0
+
+	.probe		= cs42l43_irq_probe,
+	.remove		= cs42l43_irq_remove,
+};
+module_platform_driver(cs42l43_irq_driver);
+
+MODULE_DESCRIPTION("CS42L43 IRQ Driver");
+MODULE_AUTHOR("Charles Keepax <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:cs42l43-irq");

You miss the ID table. Don't add aliases for missing ID entries. They do not scale and it is not their purpose.

Quoted 11 lines
include/linux/irqchip/cs42l43.h new file +5 -0
new file mode 100644
index 0000000000000..99ce0dbc96a77
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CS42L43 IRQ driver external data
+ *
+ * Copyright (C) 2022-2023 Cirrus Logic, Inc. and

include/linux/irqchip/cs42l43.h line 15

Quoted 10 lines
include/linux/irqchip/cs42l43.h new file +10 -0
+ *                         Cirrus Logic International Semiconductor Ltd.
+ */
+
+#ifndef CS42L43_IRQ_EXT_H
+#define CS42L43_IRQ_EXT_H
+
+enum cs42l43_irq_numbers {
+	CS42L43_PLL_LOST_LOCK,
+	CS42L43_PLL_READY,
+

Are these really used by other subsystems? Your IRQ handling should be anyway next to the driver.

Best regards,
Krzysztof

author maintainer
#42 lore raw

PATCH 8/10 pinctrl: cs42l43: Add support for the cs42l43

In reply to Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a basic pinctrl driver which supports driver strength for the various pins, gpios, and pinmux for the 2 multi-function pins.

---
 MAINTAINERS                              |   1 +
 drivers/pinctrl/cirrus/Kconfig           |  11 +
 drivers/pinctrl/cirrus/Makefile          |   2 +
 drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 614 +++++++++++++++++++++++
 4 files changed, 628 insertions(+)
 create mode 100644 drivers/pinctrl/cirrus/pinctrl-cs42l43.c
MAINTAINERS +1 -0
index 13945ee6cdcfe..2890f54f70afc 100644
@@ -4930,6 +4930,7 @@ F:	Documentation/devicetree/bindings/mfd/cirrus,cs*
 F:	Documentation/devicetree/bindings/sound/cirrus,cs*
 F:	drivers/irqchip/irq-cs42l43*
 F:	drivers/mfd/cs42l43*
+F:	drivers/pinctrl/cirrus/pinctrl-cs42l43*
 F:	include/dt-bindings/sound/cs*
 F:	include/linux/irqchip/cs42l43*
 F:	include/linux/mfd/cs42l43*
drivers/pinctrl/cirrus/Kconfig +11 -0
index 530426a74f751..d6318cb57aff2 100644
@@ -1,4 +1,15 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config PINCTRL_CS42L43
+	tristate "Cirrus Logic CS42L43 Pinctrl Driver"
+	depends on MFD_CS42L43
+	select GPIOLIB
+	select PINMUX
+	select PINCONF
+	select GENERIC_PINCONF
+	help
+	  Select this to support the GPIO/Pinctrl functions of the Cirrus
+	  Logic CS42L43 PC CODEC.
+
 config PINCTRL_LOCHNAGAR
 	tristate "Cirrus Logic Lochnagar pinctrl driver"
 	depends on MFD_LOCHNAGAR
drivers/pinctrl/cirrus/Makefile +2 -0
index a484518c840e3..9b618d7669071 100644
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 # Cirrus Logic pinctrl drivers
+obj-$(CONFIG_PINCTRL_CS42L43)	+= pinctrl-cs42l43.o
+
 obj-$(CONFIG_PINCTRL_LOCHNAGAR)	+= pinctrl-lochnagar.o
 
 pinctrl-madera-objs		:= pinctrl-madera-core.o
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +614 -0

614 lines not on this page · raw message

Signature · 1 line
2.30.2
#43 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 11 lines · Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a basic pinctrl driver which supports driver strength for the various pins, gpios, and pinmux for the 2 multi-function pins.

...

Quoted 22 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +22 -0
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
+	struct cs42l43_pin *priv;
+	struct pinctrl_dev *pctldev;
+	int ret;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->dev = &pdev->dev;
+	priv->regmap = cs42l43->regmap;
+
+	priv->shutters_locked = cs42l43->hw_lock;
+
+	priv->gpio_chip.request = gpiochip_generic_request;
+	priv->gpio_chip.free = gpiochip_generic_free;
+	priv->gpio_chip.direction_input = cs42l43_gpio_direction_in;
+	priv->gpio_chip.direction_output = cs42l43_gpio_direction_out;
+	priv->gpio_chip.get = cs42l43_gpio_get;
+	priv->gpio_chip.set = cs42l43_gpio_set;
+	priv->gpio_chip.label = dev_name(priv->dev);

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 556

Quoted 10 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +10 -0
+	priv->gpio_chip.parent = priv->dev;
+	priv->gpio_chip.can_sleep = true;
+	priv->gpio_chip.base = -1;
+	priv->gpio_chip.ngpio = CS42L43_NUM_GPIOS;
+	priv->gpio_chip.fwnode = dev_fwnode(cs42l43->dev);
+
+	if (is_of_node(dev_fwnode(cs42l43->dev))) {
+		device_set_node(priv->dev,
+				fwnode_get_named_child_node(dev_fwnode(cs42l43->dev),
+							    "pinctrl"));

That's something unusual. It seems you want to bind to a DT node because you miss compatible in DT node?

Quoted 7 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+	} else {
+		device_set_node(priv->dev, dev_fwnode(cs42l43->dev));
+	}
+
+	pm_runtime_enable(priv->dev);
+	pm_runtime_idle(priv->dev);
+

....

Quoted 5 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+
+static struct platform_driver cs42l43_pin_driver = {
+	.driver = {
+		.name	= "cs42l43-pinctrl",
+	},

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 614

Quoted 10 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +10 -0
+
+	.probe		= cs42l43_pin_probe,
+	.remove		= cs42l43_pin_remove,
+};
+module_platform_driver(cs42l43_pin_driver);
+
+MODULE_DESCRIPTION("CS42L43 Pinctrl Driver");
+MODULE_AUTHOR("Charles Keepax <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:cs42l43-pinctrl");

Same comment, so I guess you have this pattern everywhere.

Best regards,
Krzysztof

author maintainer
#44 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 11 lines · Krzysztof Kozlowski

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 556

Quoted 6 lines · Charles Keepax
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +6 -0
+	priv->gpio_chip.fwnode = dev_fwnode(cs42l43->dev);
+
+	if (is_of_node(dev_fwnode(cs42l43->dev))) {
+		device_set_node(priv->dev,
+				fwnode_get_named_child_node(dev_fwnode(cs42l43->dev),
+							    "pinctrl"));

That's something unusual. It seems you want to bind to a DT node because you miss compatible in DT node?

Kinda, I don't really want to add multiple compatibles for the device. This is just a CODEC device, even in device tree it seems a little weird to have multiple compatibles for a single I2C device. On ACPI I am pretty sure it would be considered flat out right wrong. The fact Linux supports the device using multiple drivers is seemed to be a Linux implementation detail, rather than describing the hardware.

The original (internal) version of the patches just had a single firmware node, but the DT schema would not verify because the node is both a pinctrl node and a spi node. And the pinctrl schema requires the node to be called "pinctrl" and the spi requires it to be called "spi", it is impossible to satisfy both.

Any advice/guidance you had on this one would be greatly appreciated?

Quoted 8 lines
Quoted 7 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+	} else {
+		device_set_node(priv->dev, dev_fwnode(cs42l43->dev));
+	}
+
+	pm_runtime_enable(priv->dev);
+	pm_runtime_idle(priv->dev);
+
Quoted 6 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 614

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +4 -0
+MODULE_DESCRIPTION("CS42L43 Pinctrl Driver");
+MODULE_AUTHOR("Charles Keepax <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:cs42l43-pinctrl");

Same comment, so I guess you have this pattern everywhere.

Yeah this is not problem to fix up, I was just unaware using the id_table was preferrable for MFD components, there are a lot of devices doing it both ways.

Thanks,
Charles

#45 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 3 lines · Charles Keepax
Quoted 2 lines · Krzysztof Kozlowski

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 551

Quoted 1 line · Charles Keepax
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +1 -0
+	priv->gpio_chip.fwnode = dev_fwnode(cs42l43->dev);

What's also a bit confusing is that gpio_chip is the parent's node, but pinctrl is not...

Quoted 10 lines
Quoted 9 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 556

Quoted 5 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+
+	if (is_of_node(dev_fwnode(cs42l43->dev))) {
+		device_set_node(priv->dev,
+				fwnode_get_named_child_node(dev_fwnode(cs42l43->dev),
+							    "pinctrl"));

That's something unusual. It seems you want to bind to a DT node because you miss compatible in DT node?

Quoted 8 lines

Kinda, I don't really want to add multiple compatibles for the device. This is just a CODEC device, even in device tree it seems a little weird to have multiple compatibles for a single I2C device. On ACPI I am pretty sure it would be considered flat out right wrong. The fact Linux supports the device using multiple drivers is seemed to be a Linux implementation detail, rather than describing the hardware.

I think if you do not have compatible, then the device node should be rather the parent (so the main node with compatible), not the child. Child is just a wrapper for pinctrls, but not something representing a device.

Best regards,
Krzysztof

#46 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

In reply to Charles Keepax

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

Quoted 9 lines

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a basic pinctrl driver which supports driver strength for the various pins, gpios, and pinmux for the 2 multi-function pins.

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 21

Quoted 5 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+#include <linux/pinctrl/consumer.h>
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/pinctrl/pinmux.h>
+#include <linux/pinctrl/pinconf.h>
+#include <linux/pinctrl/pinconf-generic.h>

Can you order them and split into a separate group that goes...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 25

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +4 -0
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+

...here?

Quoted 1 line

+#include "../pinctrl-utils.h"

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 35

Quoted 6 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+struct cs42l43_pin {
+	struct device *dev;
+	struct regmap *regmap;
+	bool shutters_locked;
 
+	struct gpio_chip gpio_chip;

If you move this to be the first member you might save a few bytes of code.

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 36

Quoted 1 line
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +1 -0
+	struct pinctrl_gpio_range range;

Is it really needed here?

Quoted 1 line

+};

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 51

Quoted 7 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+#define CS42L43_PIN(_number, _name, _reg, _field) { \
+	.number = _number, .name = _name, \
+	.drv_data = &((struct cs42l43_pin_data){ \
+		.reg = CS42L43_##_reg, \
+		.shift = CS42L43_##_field##_DRV_SHIFT, \
+		.mask = CS42L43_##_field##_DRV_MASK, \
+	}), \

Do you need this to be GCC extention for the value evaluation? I mean the compound literal, IIRC, can be used directly as

	.foo = &(struct foo){ ... },

Am I mistaken?

Quoted 1 line

+}

...

Quoted 1 line

+#define CS42L43_PINGROUP(_name) \

Use PINCTRL_PINGROUP() instead of open coded.

Quoted 5 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+(struct pingroup){				\
+	.name = #_name, \
+	.pins = cs42l43_pin_##_name##_pins, \
+	.npins = ARRAY_SIZE(cs42l43_pin_##_name##_pins) \
+}

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 137

Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+enum cs42l43_pin_funcs {
+	CS42L43_FUNC_GPIO,
+	CS42L43_FUNC_SPDIF,
+	CS42L43_FUNC_IRQ,
+	CS42L43_FUNC_MIC_SHT,
+	CS42L43_FUNC_SPK_SHT,
 
+	CS42L43_FUNC_MAX,

No comma for the terminator entry

Quoted 1 line

+};

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 141

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+static const char * const cs42l43_pin_funcs[] = {
+	"gpio", "spdif", "irq", "mic-shutter", "spk-shutter"

I would keep trailing comma.

Quoted 1 line

+};

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 152

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +4 -0
+struct cs42l43_pin_func_group {
+	const char * const *groups;
+	unsigned int ngroups;
+};

We have struct pinfunction.

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 159

Quoted 6 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +6 -0
+static const struct cs42l43_pin_func_group cs42l43_pin_func_groups[] = {
+	{ cs42l43_pin_gpio_groups,	ARRAY_SIZE(cs42l43_pin_gpio_groups) },
+	{ cs42l43_pin_spdif_groups,	ARRAY_SIZE(cs42l43_pin_spdif_groups) },
+	{ cs42l43_pin_irq_groups,	ARRAY_SIZE(cs42l43_pin_irq_groups) },
+	{ cs42l43_pin_shutter_groups,	ARRAY_SIZE(cs42l43_pin_shutter_groups) },
+	{ cs42l43_pin_shutter_groups,	ARRAY_SIZE(cs42l43_pin_shutter_groups) },

We have PINCTRL_PINFUNCTION().

Quoted 1 line

+};

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 165

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +4 -0
+static int cs42l43_pin_get_func_count(struct pinctrl_dev *pctldev)
+{
+	BUILD_BUG_ON(ARRAY_SIZE(cs42l43_pin_funcs) != CS42L43_FUNC_MAX);
+	BUILD_BUG_ON(ARRAY_SIZE(cs42l43_pin_func_groups) != CS42L43_FUNC_MAX);

Use static_assert() in the global scope instead.

Quoted 3 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+
+	return ARRAY_SIZE(cs42l43_pin_funcs);
+}

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 211

Quoted 5 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+	default:
+		reg = CS42L43_GPIO_FN_SEL;
+		mask = BIT(group_idx + CS42L43_GPIO1_FN_SEL_SHIFT);
+		val = (func_idx == CS42L43_FUNC_GPIO) <<
+				(group_idx + CS42L43_GPIO1_FN_SEL_SHIFT);

This would be better as ternary.

Quoted 2 lines
(quoted diff) +2 -0
+		break;
+	}

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 232

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+	dev_dbg(priv->dev, "Setting gpio%d to %s\n",
+		offset + 1, input ? "input" : "output");

How ' + 1' part won't be confusing?

...

Quoted 6 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +6 -0
+static inline int cs42l43_pin_get_db(struct cs42l43_pin *priv, unsigned int pin)
+{
+	unsigned int val;
+	int ret;
+
+	if (pin >= CS42L43_NUM_GPIOS)

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 333

Quoted 10 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +9 -0
+		return -ENOTSUPP;
+
+	ret = regmap_read(priv->regmap, CS42L43_GPIO_CTRL2, &val);
+	if (ret)
+		return ret;
+
+	if (val & (CS42L43_GPIO1_DEGLITCH_BYP_MASK << pin))
+		return 0;
 
+	else

Redundant.

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 334

Quoted 1 line
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +1 -0
+		return 85; // Debounce is roughly 85uS
	// Debounce is roughly 85uS
	return 85;
Quoted 1 line

+}

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 344

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+	dev_dbg(priv->dev, "Set debounce %s for %s\n",
+		us ? "on" : "off", cs42l43_pin_pins[pin].name);

str_on_off()

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 404

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+		++configs;
+		--num_configs;

Why preincrements?

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 559

Quoted 7 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+	if (is_of_node(dev_fwnode(cs42l43->dev))) {
+		device_set_node(priv->dev,
+				fwnode_get_named_child_node(dev_fwnode(cs42l43->dev),
+							    "pinctrl"));
+	} else {
+		device_set_node(priv->dev, dev_fwnode(cs42l43->dev));
+	}

This can be called once after if.

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 567

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +4 -0
+	pctldev = devm_pinctrl_register(priv->dev, &cs42l43_pin_desc, priv);
+	if (IS_ERR(pctldev)) {
+		ret = PTR_ERR(pctldev);
+		dev_err(priv->dev, "Failed to register pinctrl: %d\n", ret);
		ret = dev_err_probe();

Same for other similar cases.

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 584

Quoted 11 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +10 -0
+		goto err_pm;
+	}
 
+	if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+		ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+					     0, 0, CS42L43_NUM_GPIOS);
+		if (ret) {
+			dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+			goto err_pm;
+		}
+	}

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 596

Quoted 3 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+static int cs42l43_pin_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);

This is simply wrong order because it's a mix of non-devm_*() followed by devm_*() calls in the probe.

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 605

Quoted 6 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +5 -0
+static struct platform_driver cs42l43_pin_driver = {
+	.driver = {
+		.name	= "cs42l43-pinctrl",
+	},
 
+

Redundant blank line.

Quoted 3 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+	.probe		= cs42l43_pin_probe,
+	.remove		= cs42l43_pin_remove,
+};
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#47 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 11 lines · On Fri, May 12, 2023 at 10:19:14PM +0300, [email protected] wrote:

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

Quoted 9 lines

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

Add a basic pinctrl driver which supports driver strength for the various pins, gpios, and pinmux for the 2 multi-function pins.

Thanks for the review, will fix up most of the comments.

Quoted 11 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 51

Quoted 7 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +7 -0
+#define CS42L43_PIN(_number, _name, _reg, _field) { \
+	.number = _number, .name = _name, \
+	.drv_data = &((struct cs42l43_pin_data){ \
+		.reg = CS42L43_##_reg, \
+		.shift = CS42L43_##_field##_DRV_SHIFT, \
+		.mask = CS42L43_##_field##_DRV_MASK, \
+	}), \

Do you need this to be GCC extention for the value evaluation? I mean the compound literal, IIRC, can be used directly as

Quoted 3 lines
	.foo = &(struct foo){ ... },

Am I mistaken?

I will double check this, I had a feeling it needed the GCC extension.

Quoted 4 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 232

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+	dev_dbg(priv->dev, "Setting gpio%d to %s\n",
+		offset + 1, input ? "input" : "output");

How ' + 1' part won't be confusing?

Kinda an un-avoidable confusion somewhere, the GPIOs in the datasheet are numbered from one. So this makes the debug print match the datasheet name for the pin, which is used in the pinctrl strings as well.

Quoted 12 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 584

Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +8 -0
+	if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+		ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+					     0, 0, CS42L43_NUM_GPIOS);
+		if (ret) {
+			dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+			goto err_pm;
+		}
+	}

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

Apologies but I am not quite sure I follow you, in the device tree case this will be handled by the GPIO library. But for ACPI this information does not exist so has to be called manually, the library does not necessarily know which values to call with, although admittedly our case is trivial but not all are.

Quoted 9 lines

...

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 596

Quoted 3 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+static int cs42l43_pin_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);

This is simply wrong order because it's a mix of non-devm_*() followed by devm_*() calls in the probe.

I had missed there are now devm_pm_runtime calls, I will switch to that. But I would like to understand the wrong order, remove will be called before the devm bits are destroyed and it seems reasonable to disable the pm_runtime before destroying the pinctrl device. What exactly would run in the wrong order here?

Thanks,
Charles

#48 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 2 lines · Charles Keepax
Quoted 1 line · On Fri, May 12, 2023 at 10:19:14PM +0300, [email protected] wrote:

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

...

Quoted 9 lines
Quoted 4 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 232

Quoted 2 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +2 -0
+   dev_dbg(priv->dev, "Setting gpio%d to %s\n",
+           offset + 1, input ? "input" : "output");

How ' + 1' part won't be confusing?

Kinda an un-avoidable confusion somewhere, the GPIOs in the datasheet are numbered from one. So this makes the debug print match the datasheet name for the pin, which is used in the pinctrl strings as well.

The problem here is that the entire Linux pin control and GPIO cores in their debug/info/error messages will use offset + 0. With the above invention it will well make users confused a lot. I think you need a Linus W blessing for this.

...

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +8 -0
+   if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+           ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+                                        0, 0, CS42L43_NUM_GPIOS);
+           if (ret) {
+                   dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+                   goto err_pm;
+           }
+   }
Quoted 8 lines
Quoted 2 lines

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

Apologies but I am not quite sure I follow you, in the device tree case this will be handled by the GPIO library. But for ACPI this information does not exist so has to be called manually, the library does not necessarily know which values to call with, although admittedly our case is trivial but not all are.

Why can't the firmware provide this information? _DSD() is a part of ACPI v5.1 IIRC.

Although it might require moving some code from gpiolib-of.c to gpiolib.c with replacing OF APIs with agnostic ones.

...

Quoted 8 lines
Quoted 7 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 596

Quoted 3 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+static int cs42l43_pin_remove(struct platform_device *pdev)
+{
+   pm_runtime_disable(&pdev->dev);

This is simply wrong order because it's a mix of non-devm_*() followed by devm_*() calls in the probe.

Quoted 5 lines

I had missed there are now devm_pm_runtime calls, I will switch to that. But I would like to understand the wrong order, remove will be called before the devm bits are destroyed and it seems reasonable to disable the pm_runtime before destroying the pinctrl device. What exactly would run in the wrong order here?

At the ->remove() stage after this call an IRQ can be fired (or on SMP systems any other APIs can be called), for example. So, would it be a problem to service it with PM disabled?

But in any case the shuffling ordering like this is prone to subtle bugs. I prefer to have strict ordering if there is nothing preventing from doing that way.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#49 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 16 lines · Andy Shevchenko
Quoted 14 lines · Charles Keepax
Quoted 12 lines · On Fri, May 12, 2023 at 10:19:14PM +0300, [email protected] wrote:

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 584

Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +8 -0
+   if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+           ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+                                        0, 0, CS42L43_NUM_GPIOS);
+           if (ret) {
+                   dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+                   goto err_pm;
+           }
+   }

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

Quoted 9 lines
Quoted 5 lines

Apologies but I am not quite sure I follow you, in the device tree case this will be handled by the GPIO library. But for ACPI this information does not exist so has to be called manually, the library does not necessarily know which values to call with, although admittedly our case is trivial but not all are.

Why can't the firmware provide this information? _DSD() is a part of ACPI v5.1 IIRC.

I am very very far from confident we can guarantee that will be present in the ACPI. The ACPI is typically made for and by the Windows side.

Quoted 3 lines

Although it might require moving some code from gpiolib-of.c to gpiolib.c with replacing OF APIs with agnostic ones.

I really think if we want to start doing things that way on ACPI platforms someone with a little more clout than us needs to start doing it first. If Intel or someone was doing it that way it might give us a little more levelage to push it as being the "correct" way to do it.

I will switch to the callback, but really don't think we can rely on this being in DSD yet.

Quoted 15 lines
Quoted 9 lines
Quoted 8 lines

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 596

Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +3 -0
+static int cs42l43_pin_remove(struct platform_device *pdev)
+{
+   pm_runtime_disable(&pdev->dev);

This is simply wrong order because it's a mix of non-devm_*() followed by devm_*() calls in the probe.

Quoted 5 lines

I had missed there are now devm_pm_runtime calls, I will switch to that. But I would like to understand the wrong order, remove will be called before the devm bits are destroyed and it seems reasonable to disable the pm_runtime before destroying the pinctrl device. What exactly would run in the wrong order here?

Quoted 7 lines

At the ->remove() stage after this call an IRQ can be fired (or on SMP systems any other APIs can be called), for example. So, would it be a problem to service it with PM disabled?

But in any case the shuffling ordering like this is prone to subtle bugs. I prefer to have strict ordering if there is nothing preventing from doing that way.

Yeah happy enough to use devm_ here, just didn't know it existed and wanted to better understand your concerns as I was having difficulty seeing the issue.

Thanks,
Charles

#50 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 23 lines · Charles Keepax
Quoted 22 lines · Andy Shevchenko
Quoted 19 lines · Charles Keepax
Quoted 10 lines · On Fri, May 12, 2023 at 10:19:14PM +0300, [email protected] wrote:

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 584

Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +8 -0
+   if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+           ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+                                        0, 0, CS42L43_NUM_GPIOS);
+           if (ret) {
+                   dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+                   goto err_pm;
+           }
+   }
Quoted 2 lines

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

Apologies but I am not quite sure I follow you, in the device tree case this will be handled by the GPIO library. But for ACPI this information does not exist so has to be called manually, the library does not necessarily know which values to call with, although admittedly our case is trivial but not all are.

Quoted 6 lines
Quoted 2 lines

Why can't the firmware provide this information? _DSD() is a part of ACPI v5.1 IIRC.

I am very very far from confident we can guarantee that will be present in the ACPI. The ACPI is typically made for and by the Windows side.

Why? You may insist firmware vendors / OEMs to use that as a requirement to the platforms that would like to use your chip. The _DSD() is part of the specification, I don't see how the above can be an argument.

The times when ACPI == Windows are quite behind.

Quoted 8 lines
Quoted 2 lines

Although it might require moving some code from gpiolib-of.c to gpiolib.c with replacing OF APIs with agnostic ones.

I really think if we want to start doing things that way on ACPI platforms someone with a little more clout than us needs to start doing it first. If Intel or someone was doing it that way it might give us a little more levelage to push it as being the "correct" way to do it.

So, we have the meta-acpi [1] project which contains dozens of examples on how ACPI DSD is being used for real devices, besides some documentation in the Linux kernel.

Quoted 2 lines

I will switch to the callback, but really don't think we can rely on this being in DSD yet.

Why not?

...

Quoted 1 line
Quoted 1 line
Quoted 1 line

I had missed there are now devm_pm_runtime calls,

Btw, even if there is no such API one can always call devm_add_action() / devm_add_action_or_reset() to open code such a call.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

I will switch
to that. But I would like to understand the wrong order, remove will be called before the devm bits are destroyed and it seems reasonable to disable the pm_runtime before destroying the pinctrl device. What exactly would run in the wrong order here?

At the ->remove() stage after this call an IRQ can be fired (or on SMP systems any other APIs can be called), for example. So, would it be a problem to service it with PM disabled?

Quoted 7 lines
Quoted 3 lines

But in any case the shuffling ordering like this is prone to subtle bugs. I prefer to have strict ordering if there is nothing preventing from doing that way.

Yeah happy enough to use devm_ here, just didn't know it existed and wanted to better understand your concerns as I was having difficulty seeing the issue.

Ah, you are welcome!

...

[1]: https://github.com/westeri/meta-acpi/tree/master/recipes-bsp/acpi-tables/samples
(mostly under edison/ folder)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#51 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

Quoted 32 lines · Andy Shevchenko
Quoted 23 lines · Charles Keepax
Quoted 22 lines · Andy Shevchenko
Quoted 19 lines · Charles Keepax
Quoted 10 lines · On Fri, May 12, 2023 at 10:19:14PM +0300, [email protected] wrote:

Fri, May 12, 2023 at 01:28:36PM +0100, Charles Keepax kirjoitti:

drivers/pinctrl/cirrus/pinctrl-cs42l43.c line 584

Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c new file +8 -0
+   if (!of_property_read_bool(dev_of_node(cs42l43->dev), "gpio-ranges")) {
+           ret = gpiochip_add_pin_range(&priv->gpio_chip, priv->gpio_chip.label,
+                                        0, 0, CS42L43_NUM_GPIOS);
+           if (ret) {
+                   dev_err(priv->dev, "Failed to add GPIO pin range: %d\n", ret);
+                   goto err_pm;
+           }
+   }
Quoted 2 lines

Besides the fact that we have a callback for this, why GPIO library can't handle this for you already?

Apologies but I am not quite sure I follow you, in the device tree case this will be handled by the GPIO library. But for ACPI this information does not exist so has to be called manually, the library does not necessarily know which values to call with, although admittedly our case is trivial but not all are.

Quoted 6 lines
Quoted 2 lines

Why can't the firmware provide this information? _DSD() is a part of ACPI v5.1 IIRC.

I am very very far from confident we can guarantee that will be present in the ACPI. The ACPI is typically made for and by the Windows side.

Quoted 6 lines

Why? You may insist firmware vendors / OEMs to use that as a requirement to the platforms that would like to use your chip. The _DSD() is part of the specification, I don't see how the above can be an argument.

The times when ACPI == Windows are quite behind.

This is one of those Yogi Berra-isms: In theory, there is no difference between theory and practice. In practice there is.

DSD is not really used indeed for audio devices. Even for SoundWire where we inked the requirement to use DSD in a MIPI standardization document, the only _DSD properties are for the manager side, the peripheral side information is not populated or mostly useless/incorrect. Most codec drivers hard-code the properties that were intended to be set in the DSDT.

Unless there is firm evidence that the firmware does provide the required DSD properties we can assume it does not. We can't force the ecosystem to use DSD, even if it makes sense. it's frustrating but it is what it is.

maintainer
#52 lore raw

Re: [PATCH 08/10] pinctrl: cs42l43: Add support for the cs42l43

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

On Wed, May 17, 2023 at 1:13 PM Charles Keepax

Quoted 3 lines

I am very very far from confident we can guarantee that will be present in the ACPI. The ACPI is typically made for and by the Windows side.

Quoted 6 lines

Why? You may insist firmware vendors / OEMs to use that as a requirement to the platforms that would like to use your chip. The _DSD() is part of the specification, I don't see how the above can be an argument.

The times when ACPI == Windows are quite behind.

Nobody is going to loose a sale over something like that, especially when it's just not idiomatic. It's very unlikely to even be worth the effort of educating customers who don't care what DSD is when there's no ecosystem push for it, it'd just make you look difficult and weird.

author maintainer
#53 lore raw

PATCH 9/10 spi: cs42l43: Add SPI controller support

In reply to Charles Keepax

From: Lucas Tanure <[email protected]>

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The SPI component incorporates a SPI controller interface for communication with other peripheral components.

---
 MAINTAINERS               |   1 +
 drivers/spi/Kconfig       |   7 +
 drivers/spi/Makefile      |   1 +
 drivers/spi/spi-cs42l43.c | 287 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 296 insertions(+)
 create mode 100644 drivers/spi/spi-cs42l43.c
MAINTAINERS +1 -0
index 2890f54f70afc..ca4aa5cc43b7d 100644
@@ -4931,6 +4931,7 @@ F:	Documentation/devicetree/bindings/sound/cirrus,cs*
 F:	drivers/irqchip/irq-cs42l43*
 F:	drivers/mfd/cs42l43*
 F:	drivers/pinctrl/cirrus/pinctrl-cs42l43*
+F:	drivers/spi/spi-cs42l43*
 F:	include/dt-bindings/sound/cs*
 F:	include/linux/irqchip/cs42l43*
 F:	include/linux/mfd/cs42l43*
drivers/spi/Kconfig +7 -0
index 3de2ebe8294aa..f6ce06de41051 100644
@@ -281,6 +281,13 @@ config SPI_COLDFIRE_QSPI
 	  This enables support for the Coldfire QSPI controller in master
 	  mode.
 
+config SPI_CS42L43
+	tristate "Cirrus Logic CS42L43 SPI controller"
+	depends on MFD_CS42L43 && PINCTRL_CS42L43
+	help
+	  This enables support for the SPI controller inside the Cirrus Logic
+	  CS42L43 audio codec.
+
 config SPI_DAVINCI
 	tristate "Texas Instruments DaVinci/DA8x/OMAP-L/AM1x SoC SPI controller"
 	depends on ARCH_DAVINCI || ARCH_KEYSTONE || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 28c4817a8a74a..49937ea0d73d0 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_SPI_CADENCE_QUADSPI)	+= spi-cadence-quadspi.o
 obj-$(CONFIG_SPI_CADENCE_XSPI)		+= spi-cadence-xspi.o
 obj-$(CONFIG_SPI_CLPS711X)		+= spi-clps711x.o
 obj-$(CONFIG_SPI_COLDFIRE_QSPI)		+= spi-coldfire-qspi.o
+obj-$(CONFIG_SPI_CS42L43)		+= spi-cs42l43.o
 obj-$(CONFIG_SPI_DAVINCI)		+= spi-davinci.o
 obj-$(CONFIG_SPI_DLN2)			+= spi-dln2.o
 obj-$(CONFIG_SPI_DESIGNWARE)		+= spi-dw.o
drivers/spi/spi-cs42l43.c new file +287 -0

287 lines not on this page · raw message

Signature · 1 line
2.30.2
#54 lore raw

Re: [PATCH 09/10] spi: cs42l43: Add SPI controller support

Fri, May 12, 2023 at 01:28:37PM +0100, Charles Keepax kirjoitti:

Quoted 11 lines

From: Lucas Tanure <[email protected]>

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The SPI component incorporates a SPI controller interface for communication with other peripheral components.

...

Quoted 1 line

+#define CS42L43_SPI_ROOT_HZ 40000000

HZ_PER_MHZ?

...

Review

Quoted 1 line
(quoted diff) +1 -0
+		const u8 *block = min_t(const u8 *, buf + CS42L43_FIFO_SIZE, end);

Wouldn't min() work?

...

drivers/spi/spi-cs42l43.c line 47

Quoted 2 lines
drivers/spi/spi-cs42l43.c new file +2 -0
+		for (; buf < block - (sizeof(u32) - 1); buf += sizeof(u32))
+			regmap_write(regmap, CS42L43_TX_DATA, *(const u32 *)buf);

This casting might be potentially wrong taking alignment into consideration. Perhaps you need get_unaligned(). Also here the return value isn't checked, while in the read it is.

...

Review

Quoted 1 line
(quoted diff) +1 -0
+		const u8 *block = min_t(const u8 *, buf + CS42L43_FIFO_SIZE, end);

min() ?

...

drivers/spi/spi-cs42l43.c line 85

Quoted 2 lines
drivers/spi/spi-cs42l43.c new file +2 -0
+		for (; buf < block - (sizeof(u32) - 1); buf += sizeof(u32)) {
+			ret = regmap_read(regmap, CS42L43_RX_DATA, (u32 *)buf);

put_unaligned() ?

Quoted 3 lines
drivers/spi/spi-cs42l43.c new file +3 -0
+			if (ret)
+				return ret;
+		}

...

drivers/spi/spi-cs42l43.c line 181

Quoted 13 lines
drivers/spi/spi-cs42l43.c new file +12 -0
+static int cs42l43_prepare_transfer_hardware(struct spi_controller *ctlr)
+{
+	struct cs42l43_spi *priv = spi_controller_get_devdata(ctlr);
+	int ret;
+
+	ret = regmap_write(priv->regmap, CS42L43_BLOCK_EN2, CS42L43_SPI_MSTR_EN_MASK);
+	if (ret) {
+		dev_err(priv->dev, "Failed to enable SPI controller: %d\n", ret);
 
+		return ret;
+	}
+
+	return 0;

return ret; ?

Quoted 4 lines
drivers/spi/spi-cs42l43.c new file +4 -0
+}
+
+static int cs42l43_unprepare_transfer_hardware(struct spi_controller *ctlr)
+{

drivers/spi/spi-cs42l43.c line 195

Quoted 10 lines
drivers/spi/spi-cs42l43.c new file +10 -0
+	struct cs42l43_spi *priv = spi_controller_get_devdata(ctlr);
+	int ret;
+
+	ret = regmap_write(priv->regmap, CS42L43_BLOCK_EN2, 0);
+	if (ret) {
+		dev_err(priv->dev, "Failed to disable SPI controller: %d\n", ret);
+		return ret;
+	}
+
+	return 0;

Ditto.

Quoted 1 line

+}

...

drivers/spi/spi-cs42l43.c line 235

Quoted 7 lines
drivers/spi/spi-cs42l43.c new file +7 -0
+	if (is_of_node(dev_fwnode(cs42l43->dev))) {
+		priv->ctlr->dev.fwnode =
+			fwnode_get_named_child_node(dev_fwnode(cs42l43->dev), "spi");
+		priv->ctlr->dev.of_node = to_of_node(dev_fwnode(&priv->ctlr->dev));
+	} else {
+		priv->ctlr->dev.fwnode = dev_fwnode(priv->dev);
+	}

Can you use device_set_node() once you have an fwnode that needs to be passed?

...

drivers/spi/spi-cs42l43.c line 237

Quoted 1 line
drivers/spi/spi-cs42l43.c new file +1 -0
+	priv->ctlr->mode_bits = SPI_3WIRE | SPI_CPHA | SPI_CPOL;

SPI_MODE_X_MASK

...

drivers/spi/spi-cs42l43.c line 277

Quoted 6 lines
drivers/spi/spi-cs42l43.c new file +5 -0
+static struct platform_driver cs42l43_spi_driver = {
+	.driver = {
+		.name	= "cs42l43-spi",
+	},
 
+

Unneeded blank line.

Quoted 3 lines
drivers/spi/spi-cs42l43.c new file +3 -0
+	.probe		= cs42l43_spi_probe,
+	.remove		= cs42l43_spi_remove,
+};
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#55 lore raw

PATCH 10/10 ASoC: cs42l43: Add support for the cs42l43

In reply to Charles Keepax

The CS42L43 is an audio CODEC with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, SPI, and I2S/TDM interfaces designed for portable applications. It provides a high dynamic range, stereo DAC for headphone output, two integrated Class D amplifiers for loudspeakers, and two ADCs for wired headset microphone input or stereo line input. PDM inputs are provided for digital microphones.

The ASoC component provides the majority of the functionality of the device, all the audio functions.

---
 include/sound/cs42l43.h         |   84 ++
 sound/soc/codecs/Kconfig        |   16 +
 sound/soc/codecs/Makefile       |    4 +
 sound/soc/codecs/cs42l43-jack.c |  946 +++++++++++++
 sound/soc/codecs/cs42l43-sdw.c  |   75 +
 sound/soc/codecs/cs42l43.c      | 2270 +++++++++++++++++++++++++++++++
 sound/soc/codecs/cs42l43.h      |  117 ++
 7 files changed, 3512 insertions(+)
 create mode 100644 include/sound/cs42l43.h
 create mode 100644 sound/soc/codecs/cs42l43-jack.c
 create mode 100644 sound/soc/codecs/cs42l43-sdw.c
 create mode 100644 sound/soc/codecs/cs42l43.c
 create mode 100644 sound/soc/codecs/cs42l43.h
include/sound/cs42l43.h new file +84 -0
new file mode 100644
index 0000000000000..04e17bbf89f45
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CS42L43 CODEC driver external data
+ *
+ * Copyright (C) 2022-2023 Cirrus Logic, Inc. and
+ *                         Cirrus Logic International Semiconductor Ltd.
+ */
+
+#ifndef CS42L43_ASOC_EXT_H
+#define CS42L43_ASOC_EXT_H
+
+#define CS42L43_SYSCLK		0
+
+#define CS42L43_SYSCLK_MCLK	0
+#define CS42L43_SYSCLK_SDW	1
+
+#define CS42L43_N_BUTTONS	6
+
+/**
+ * struct cs42l43_plug_pdata - Configuration data for tip/ring sense.
+ *
+ * @invert: Boolean indicating pin polarity, inverted implies open-circuit
+ *          whilst the jack is inserted.
+ * @pullup: Boolean indicating if the cs42l43 should apply its internal
+ *          pull up to the pin.
+ * @fall_db_ms: Time in milliseconds a falling edge on the pin should be
+ *              debounced for. Note the falling edge is considered after
+ *              the invert.
+ * @rise_db_ms: Time in milliseconds a rising edge on the pin should be
+ *              debounced for. Note the rising edge is considered after
+ *              the invert.
+ */
+struct cs42l43_plug_pdata {
+	bool invert;
+	bool pullup;
+	unsigned int fall_db_ms;
+	unsigned int rise_db_ms;
+};
+
+/**
+ * struct cs42l43_button_pdata - Configuration data for button detect.
+ *
+ * @threshold: Impedance in Ohms under which this button will be
+ *             considered active.
+ * @button: Value to be reported for this button taken from
+ *          snd_jack_types.
+ */
+struct cs42l43_button_pdata {
+	unsigned int threshold;
+	unsigned int button;
+};
+
+/**
+ * struct cs42l43_jack_pdata - Configuration data for the accessory detect.
+ *
+ * @tip_debounce_ms: Software debounce on tip sense triggering in milliseconds.
+ * @tip: Configuration data for the tip sense pin.
+ * @ring: Configuration data for the ring sense pin.
+ * @use_ring_sense: Boolean indicating if the ring sense pin will be used.
+ * @bias_low: Select a 1.8V micbias rather than the default 2.8V.
+ * @bias_sense_ua: Current at which the bias_sense clamp will engage, 0 to disable.
+ * @bias_ramp_ms: Time in milliseconds the hardware allows for the headset
+ *                bias to ramp up.
+ * @detect_us: Time in microseconds the type detection will be run for.
+ * @enable_button_automute: Enable the hardware automuting of decimator 1
+ *                          when a headset button is pressed.
+ * @buttons: Array of button entries.
+ */
+struct cs42l43_jack_pdata {
+	int tip_debounce_ms;
+	struct cs42l43_plug_pdata tip;
+	struct cs42l43_plug_pdata ring;
+	bool use_ring_sense;
+
+	unsigned int bias_low;
+	unsigned int bias_sense_ua;
+	unsigned int bias_ramp_ms;
+	unsigned int detect_us;
+
+	bool enable_button_automute;
+	struct cs42l43_button_pdata buttons[CS42L43_N_BUTTONS];
+};
+
+#endif /* CS42L43_ASOC_EXT_H */
sound/soc/codecs/Kconfig +16 -0
index 8020097d4e4c8..449ff6d267e3e 100644
@@ -73,6 +73,8 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS35L56_SDW
 	imply SND_SOC_CS42L42
 	imply SND_SOC_CS42L42_SDW
+	imply SND_SOC_CS42L43
+	imply SND_SOC_CS42L43_SDW
 	imply SND_SOC_CS42L51_I2C
 	imply SND_SOC_CS42L52
 	imply SND_SOC_CS42L56
@@ -774,6 +776,20 @@ config SND_SOC_CS42L42_SDW
 	help
 	  Enable support for Cirrus Logic CS42L42 codec with Soundwire control
 
+config SND_SOC_CS42L43
+	tristate "Cirrus Logic CS42L43 CODEC"
+	depends on MFD_CS42L43 && IRQ_CS42L43
+	help
+	  Select this to support the audio functions of the Cirrus Logic
+	  CS42L43 PC CODEC.
+
+config SND_SOC_CS42L43_SDW
+	tristate "Cirrus Logic CS42L43 CODEC (SoundWire)"
+	depends on SND_SOC_CS42L43 && MFD_CS42L43_SDW
+	help
+	  Select this to support the audio functions of the Cirrus Logic
+	  CS42L43 PC CODEC over SoundWire.
+
 config SND_SOC_CS42L51
 	tristate
 
sound/soc/codecs/Makefile +4 -0
index 5cdbae88e6e35..dd5905ebaf530 100644
@@ -74,6 +74,8 @@ snd-soc-cs35l56-sdw-objs := cs35l56-sdw.o
 snd-soc-cs42l42-objs := cs42l42.o
 snd-soc-cs42l42-i2c-objs := cs42l42-i2c.o
 snd-soc-cs42l42-sdw-objs := cs42l42-sdw.o
+snd-soc-cs42l43-objs := cs42l43.o cs42l43-jack.o
+snd-soc-cs42l43-sdw-objs := cs42l43-sdw.o
 snd-soc-cs42l51-objs := cs42l51.o
 snd-soc-cs42l51-i2c-objs := cs42l51-i2c.o
 snd-soc-cs42l52-objs := cs42l52.o
@@ -448,6 +450,8 @@ obj-$(CONFIG_SND_SOC_CS35L56_SDW)	+= snd-soc-cs35l56-sdw.o
 obj-$(CONFIG_SND_SOC_CS42L42_CORE)	+= snd-soc-cs42l42.o
 obj-$(CONFIG_SND_SOC_CS42L42)	+= snd-soc-cs42l42-i2c.o
 obj-$(CONFIG_SND_SOC_CS42L42_SDW)	+= snd-soc-cs42l42-sdw.o
+obj-$(CONFIG_SND_SOC_CS42L43)	+= snd-soc-cs42l43.o
+obj-$(CONFIG_SND_SOC_CS42L43_SDW)	+= snd-soc-cs42l43-sdw.o
 obj-$(CONFIG_SND_SOC_CS42L51)	+= snd-soc-cs42l51.o
 obj-$(CONFIG_SND_SOC_CS42L51_I2C)	+= snd-soc-cs42l51-i2c.o
 obj-$(CONFIG_SND_SOC_CS42L52)	+= snd-soc-cs42l52.o
sound/soc/codecs/cs42l43-jack.c new file +946 -0

946 lines not on this page · raw message

sound/soc/codecs/cs42l43-sdw.c new file +75 -0

75 lines not on this page · raw message

sound/soc/codecs/cs42l43.c new file +2270 -0

1,851 lines not on this page · raw message

sound/soc/codecs/cs42l43.h new file +117 -0

117 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.30.2

Part of the diff is not shown here. View the raw message.

maintainer
#56 lore raw

Re: (subset) [PATCH 00/10] Add cs42l43 PC focused SoundWire CODEC

In reply to Charles Keepax
Quoted 6 lines · Charles Keepax

This patch chain adds support for the Cirrus Logic cs42l43 PC focused SoundWire CODEC. Some supporting work is included in the chain, including adding an ASoC control notification helper function and adding support for IRQs generated by the in-band SoundWire alert mechanism.

Quoted 6 lines

The chain is currently based of v6.4-rc1 because I am not 100% sure which tree we want to send everything through. The CODEC support has a build dependency on both the SoundWire change and the ASoC soc-component change.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[02/10] ASoC: soc-component: Add notify control helper function

        commit: ace9ed54bd874f2c63723b13b1747f6463e2587e
[03/10] ASoC: ak4118: Update to use new component control notify helper
        commit: 476d942e50d4f22d8621a18612dd6cfbf0a5d1d9
[04/10] ASoC: wm_adsp: Update to use new component control notify helepr
        commit: 95d06196c83c9dc1b6fd6cda07a1bac54ca2d568

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark