Add cs42l43 PC focused SoundWire CODEC
Subsystems (10)
Charles Keepax
maintainerv2 cover Add cs42l43 PC focused SoundWire CODEC
This patch chain adds support for the Cirrus Logic cs42l43 PC focused SoundWire CODEC. The chain is currently based of Lee's for-mfd-next branch.
Change notes are included with each patch, most of the changes are trivial, the notable ones are moving the IRQs out of irqchip and into the MFD, and moving the DT binding to sound.
Thanks,
Charles
Charles Keepax (4):
dt-bindings: mfd: cirrus,cs42l43: Add initial DT binding
mfd: cs42l43: Add support for cs42l43 core driver
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/sound/cirrus,cs42l43.yaml | 320 +++ MAINTAINERS | 5 + drivers/mfd/Kconfig | 23 + drivers/mfd/Makefile | 3 + drivers/mfd/cs42l43-i2c.c | 86 + drivers/mfd/cs42l43-sdw.c | 213 ++ drivers/mfd/cs42l43.c | 1141 +++++++++ drivers/mfd/cs42l43.h | 23 + drivers/pinctrl/cirrus/Kconfig | 11 + drivers/pinctrl/cirrus/Makefile | 2 + drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 609 +++++ drivers/soundwire/bus.c | 31 + drivers/soundwire/bus_type.c | 12 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-cs42l43.c | 279 ++ include/linux/mfd/cs42l43-regs.h | 1172 +++++++++ include/linux/mfd/cs42l43.h | 102 + include/linux/soundwire/sdw.h | 9 + include/sound/cs42l43.h | 17 + sound/soc/codecs/Kconfig | 16 + sound/soc/codecs/Makefile | 4 + sound/soc/codecs/cs42l43-jack.c | 951 +++++++ sound/soc/codecs/cs42l43-sdw.c | 75 + sound/soc/codecs/cs42l43.c | 2275 +++++++++++++++++ sound/soc/codecs/cs42l43.h | 126 + 26 files changed, 7513 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml 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/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
Charles Keepax
maintainerPATCH v2 1/6 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. Note that we allow users to use both the interrupt_callback and the IRQ handler, this is useful for devices which must clear additional chip specific SoundWire registers that are not a part of the normal IRQ flow, or the SoundWire specification.
---
Changes since v1:
- Update commit message
Thanks,
Charles
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
@@ -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
@@ -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
@@ -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
Charles Keepax
maintainerPATCH v2 2/6 dt-bindings: sound: cirrus,cs42l43: Add initial DT binding
In reply to Charles KeepaxThe 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.
---
Changes since v1:
- Move binding to sound
- Use lower case supply names
- Use absolute paths and remove quotes
- Add ref to dai-common
- Reorder some properties to be more standard
- Use defines for IRQ flags
- Make vdd-d optional
- Move gpio properties into the pinctrl node
- Allow skipping the pin-settings node
- Add jack detect properties
Thanks,
Charles
.../bindings/sound/cirrus,cs42l43.yaml | 320 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 321 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +320 -0
@@ -0,0 +1,320 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/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. + +allOf: + - $ref: dai-common.yaml# + +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. Can be internally supplied. + + 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 + + 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 + + cirrus,bias-low: + type: boolean + description: + Select a 1.8V headset micbias rather than 2.8V. + + cirrus,bias-sense-ua: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Current at which the headset micbias sense clamp will engage, 0 to + disable. + enum: [ 0, 14, 23, 41, 50, 60, 68, 86, 95 ] + default: 0 + + cirrus,bias-ramp-ms: + description: + Time in milliseconds the hardware allows for the headset micbias to + ramp up. + enum: [ 10, 40, 90, 170 ] + default: 170 + + cirrus,detect-us: + description: + Time in microseconds the type detection will run for. Long values will + cause more audible effects, but give more accurate detection. + enum: [ 20, 100, 1000, 10000, 50000, 75000, 100000, 200000 ] + default: 10000 + + cirrus,button-automute: + type: boolean + description: + Enable the hardware automuting of decimator 1 when a headset button is + pressed. + + cirrus,buttons-ohms: + description: + Impedance in Ohms for each headset button, these should be listed in + ascending order. + minItems: 1 + maxItems: 6 + + cirrus,tip-debounce-ms: + description: + Software debounce on tip sense triggering in milliseconds. + default: 0 + + cirrus,tip-invert: + type: boolean + description: + Indicates tip detect polarity, inverted implies open-circuit whilst the + jack is inserted. + + cirrus,tip-disable-pullup: + type: boolean + description: + Indicates if the internal pullup on the tip detect should be disabled. + + cirrus,tip-fall-db-ms: + description: + Time in milliseconds a falling edge on the tip detect should be hardware + debounced for. Note the falling edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,tip-rise-db-ms: + description: + Time in milliseconds a rising edge on the tip detect should be hardware + debounced for. Note the rising edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,use-ring-sense: + type: boolean + description: + Indicates if the ring sense should be used. + + cirrus,ring-invert: + type: boolean + description: + Indicates ring detect polarity, inverted implies open-circuit whilst the + jack is inserted. + + cirrus,ring-disable-pullup: + type: boolean + description: + Indicates if the internal pullup on the ring detect should be disabled. + + cirrus,ring-fall-db-ms: + description: + Time in milliseconds a falling edge on the ring detect should be hardware + debounced for. Note the falling edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,ring-rise-db-ms: + description: + Time in milliseconds a rising edge on the ring detect should be hardware + debounced for. Note the rising edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + pinctrl: + type: object + + allOf: + - $ref: /schemas/pinctrl/pinctrl.yaml# + + additionalProperties: false + + properties: + 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 + + patternProperties: + "-state$": + oneOf: + - $ref: "#/$defs/cirrus-cs42l43-state" + - patternProperties: + "-pins$": + $ref: "#/$defs/cirrus-cs42l43-state" + additionalProperties: false + + spi: + type: object + + allOf: + - $ref: /schemas/spi/spi-controller.yaml# + + unevaluatedProperties: false + +$defs: + cirrus-cs42l43-state: + type: object + + allOf: + - $ref: /schemas/pinctrl/pincfg-node.yaml# + - $ref: /schemas/pinctrl/pinmux-node.yaml# + + oneOf: + - required: [ groups ] + - required: [ pins ] + + additionalProperties: 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 ] + +required: + - compatible + - reg + - vdd-p-supply + - vdd-a-supply + - vdd-io-supply + - vdd-cp-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + cs42l43: codec@1a { + compatible = "cirrus,cs42l43"; + reg = <0x1a>; + + vdd-p-supply = <&vdd5v0>; + vdd-a-supply = <&vdd1v8>; + vdd-io-supply = <&vdd1v8>; + vdd-cp-supply = <&vdd1v8>; + vdd-amp-supply = <&vdd5v0>; + + reset-gpios = <&gpio 0>; + + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gpio>; + interrupts = <56 IRQ_TYPE_LEVEL_LOW>; + + #sound-dai-cells = <1>; + + clocks = <&clks 0>; + clock-names = "mclk"; + + cs42l43_pins: pinctrl { + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&cs42l43_pins 0 0 3>; + + pinctrl-names = "default"; + pinctrl-0 = <&pinsettings>; + + pinsettings: default-state { + shutter-pins { + groups = "gpio3"; + function = "mic-shutter"; + }; + }; + }; + + spi { + #address-cells = <1>; + #size-cells = <0>; + + cs-gpios = <&cs42l43_pins 1 0>; + + sensor@0 { + compatible = "bosch,bme680"; + reg = <0>; + spi-max-frequency = <1400000>; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -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
Charles Keepax
maintainerRe: [PATCH v2 2/6] dt-bindings: sound: cirrus,cs42l43: Add initial DT binding
MAINTAINERS M: Richard Fitzgerald <[email protected]> · line 4929
Quoted 9 lines · Charles Keepax
MAINTAINERS +1
-0@@ -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*
Just spotted this should be dropped for v3 as well, sorry.
Thanks,
Charles
Re: [PATCH v2 2/6] dt-bindings: sound: cirrus,cs42l43: Add initial DT binding
In reply to Charles KeepaxQuoted 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.
Add a YAML DT binding document for this device.
Signed-off-by Charles Keepax <[email protected]>
Thank you for your patch. There is something to discuss/improve.
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 81
Quoted 13 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +13
-0+ clocks: + items: + - description: Synchronous audio clock provided on mclk_in. + + clock-names: + const: mclk + + cirrus,bias-low: + type: boolean + description: + Select a 1.8V headset micbias rather than 2.8V. + + cirrus,bias-sense-ua:
"ua" looks like microamp. If so, microamp instead:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml
Quoted 88 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +88
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + description: + Current at which the headset micbias sense clamp will engage, 0 to + disable. + enum: [ 0, 14, 23, 41, 50, 60, 68, 86, 95 ] + default: 0 + + cirrus,bias-ramp-ms: + description: + Time in milliseconds the hardware allows for the headset micbias to + ramp up. + enum: [ 10, 40, 90, 170 ] + default: 170 + + cirrus,detect-us: + description: + Time in microseconds the type detection will run for. Long values will + cause more audible effects, but give more accurate detection. + enum: [ 20, 100, 1000, 10000, 50000, 75000, 100000, 200000 ] + default: 10000 + + cirrus,button-automute: + type: boolean + description: + Enable the hardware automuting of decimator 1 when a headset button is + pressed. + + cirrus,buttons-ohms: + description: + Impedance in Ohms for each headset button, these should be listed in + ascending order. + minItems: 1 + maxItems: 6 + + cirrus,tip-debounce-ms: + description: + Software debounce on tip sense triggering in milliseconds. + default: 0 + + cirrus,tip-invert: + type: boolean + description: + Indicates tip detect polarity, inverted implies open-circuit whilst the + jack is inserted. + + cirrus,tip-disable-pullup: + type: boolean + description: + Indicates if the internal pullup on the tip detect should be disabled. + + cirrus,tip-fall-db-ms: + description: + Time in milliseconds a falling edge on the tip detect should be hardware + debounced for. Note the falling edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,tip-rise-db-ms: + description: + Time in milliseconds a rising edge on the tip detect should be hardware + debounced for. Note the rising edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,use-ring-sense: + type: boolean + description: + Indicates if the ring sense should be used. + + cirrus,ring-invert: + type: boolean + description: + Indicates ring detect polarity, inverted implies open-circuit whilst the + jack is inserted. + + cirrus,ring-disable-pullup: + type: boolean + description: + Indicates if the internal pullup on the ring detect should be disabled. + + cirrus,ring-fall-db-ms: + description: + Time in milliseconds a falling edge on the ring detect should be hardware + debounced for. Note the falling edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + cirrus,ring-rise-db-ms:
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 179
Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +10
-0+ description: + Time in milliseconds a rising edge on the ring detect should be hardware + debounced for. Note the rising edge is considered after the invert. + enum: [ 0, 125, 250, 500, 750, 1000, 1250, 1500 ] + default: 500 + + pinctrl: + type: object + + allOf:
Drop allOf, just "$ref: ......"
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 182
Quoted 3 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +3
-0+ - $ref: /schemas/pinctrl/pinctrl.yaml# + + additionalProperties: false
Also drop blank lines between these three above.
Quoted 7 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +7
-0+ + properties: + gpio-controller: true + + '#gpio-cells': + const: 2 +
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 199
Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +10
-0+ gpio-ranges: + items: + - description: A phandle to the CODEC pinctrl node + minimum: 0 + - const: 0 + - const: 0 + - const: 3 + + patternProperties: + "-state$":
Use consistent quotes, either " or ' everywhere
Quoted 4 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +4
-0+ oneOf: + - $ref: "#/$defs/cirrus-cs42l43-state" + - patternProperties: + "-pins$":
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 213
Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +10
-0+ $ref: "#/$defs/cirrus-cs42l43-state" + additionalProperties: false + + spi: + type: object + + allOf: + - $ref: /schemas/spi/spi-controller.yaml# + + unevaluatedProperties: false
Same comments here.
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 218
Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +5
-0+ +$defs: + cirrus-cs42l43-state: + type: object +
Best regards,
Krzysztof
Charles Keepax
maintainerRe: [PATCH v2 2/6] dt-bindings: sound: cirrus,cs42l43: Add initial DT binding
Quoted 17 lines · Krzysztof Kozlowski
Quoted 1 line · Charles Keepax
+ cirrus,bias-sense-ua:
"ua" looks like microamp. If so, microamp instead:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yamlDocumentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 179
Quoted 4 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +4
-0+ pinctrl: + type: object + + allOf:Drop allOf, just "$ref: ......"
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 182
Quoted 3 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +3
-0+ - $ref: /schemas/pinctrl/pinctrl.yaml# + + additionalProperties: false
Quoted 7 lines
Also drop blank lines between these three above.
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml line 199
Quoted 2 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l43.yaml new file +2
-0+ patternProperties: + "-state$":Use consistent quotes, either " or ' everywhere
Thanks, will fix those all up for v3.
Thanks,
Charles
Charles Keepax
maintainerPATCH v2 3/6 mfd: cs42l43: Add support for cs42l43 core driver
In reply to Charles KeepaxThe 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.
---
Changes since v1:
- Move second-class IRQ muck into the MFD driver
- Make regulator names lower case
- Expand/Add/Update various comments
- Move pm_runtime_put to after mfd_add_devices
- Drop pm reference on the error path in suspend
- Avoid casting away const in mcu_load_firmware
- Use dev_err_probe
- Move cs42l43_patch_header to be at the top of the file
- Remove most of the debug prints
- Use devm_pm_runtime_enable
- Switch to plain probe rather than probe_new for I2C, now the migration is done
Thanks,
Charles
MAINTAINERS | 2 + drivers/mfd/Kconfig | 23 + drivers/mfd/Makefile | 3 + drivers/mfd/cs42l43-i2c.c | 86 +++ drivers/mfd/cs42l43-sdw.c | 213 ++++++ drivers/mfd/cs42l43.c | 1141 +++++++++++++++++++++++++++++ drivers/mfd/cs42l43.h | 23 + include/linux/mfd/cs42l43-regs.h | 1172 ++++++++++++++++++++++++++++++ include/linux/mfd/cs42l43.h | 102 +++ 9 files changed, 2765 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
@@ -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
@@ -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
@@ -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 +213 -0
213 lines not on this page · raw message
drivers/mfd/cs42l43.c new file +1141 -0
1,141 lines not on this page · raw message
drivers/mfd/cs42l43.h new file +23 -0
@@ -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 +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.30.2
Charles Keepax
maintainerPATCH v2 4/6 pinctrl: cs42l43: Add support for the cs42l43
In reply to Charles KeepaxThe 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.
---
Changes since v1:
- Tidy up code around device_set_node
- Use same node for GPIO and Pinctrl in binding
- Re-order include files
- Move gpio_chip to start of the private struct
- Use PINCTRL_PINGROUP/PINFUNCTION
- Add/remove a bunch of commas to arrays
- Change BUILD_BUG_ONs to static_asserts
- Use a ternary for value setting in cs42l43_pin_set_mux
- Remove uneccesary else
- Use str_on_off
- Use post increment operator rather than pre inc
- Use devm_pm_runtime_enable
- Use dev_err_probe
- Switch to using a platform_device_id table
- Use the callback for adding pin ranges
Thanks,
Charles
MAINTAINERS | 1 + drivers/pinctrl/cirrus/Kconfig | 11 + drivers/pinctrl/cirrus/Makefile | 2 + drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 609 +++++++++++++++++++++++ 4 files changed, 623 insertions(+) create mode 100644 drivers/pinctrl/cirrus/pinctrl-cs42l43.c
MAINTAINERS +1 -0
@@ -4929,6 +4929,7 @@ S: Maintained F: Documentation/devicetree/bindings/mfd/cirrus,cs* F: Documentation/devicetree/bindings/sound/cirrus,cs* F: drivers/mfd/cs42l43* +F: drivers/pinctrl/cirrus/pinctrl-cs42l43* F: include/dt-bindings/sound/cs* F: include/linux/mfd/cs42l43* F: include/sound/cs*
drivers/pinctrl/cirrus/Kconfig +11 -0
@@ -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
@@ -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 +609 -0
609 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v2 4/6] 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.
Signed-off-by Charles Keepax <[email protected]>
This version looks acceptable to me!
I guess it will be merged with the rest.
Yours,
Linus Walleij
Charles Keepax
maintainerPATCH v2 5/6 spi: cs42l43: Add SPI controller support
In reply to Charles KeepaxFrom: 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.
---
Changes since v1:
- Use HZ_PER_MHZ
- Return ret in un/prepare_transfer_hardware
- Use SPI_MODE_X_MASK
- Use devm_pm_runtime_enable
- Switch to using a platform_device_id table
- Use device_set_node
- Use min rather than min_t, and updating some consts to make it work
Thanks,
Charles
MAINTAINERS | 1 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-cs42l43.c | 279 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 drivers/spi/spi-cs42l43.c
MAINTAINERS +1 -0
@@ -4930,6 +4930,7 @@ F: Documentation/devicetree/bindings/mfd/cirrus,cs* F: Documentation/devicetree/bindings/sound/cirrus,cs* F: drivers/mfd/cs42l43* F: drivers/pinctrl/cirrus/pinctrl-cs42l43* +F: drivers/spi/spi-cs42l43* F: include/dt-bindings/sound/cs* F: include/linux/mfd/cs42l43* F: include/sound/cs*
drivers/spi/Kconfig +7 -0
@@ -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
@@ -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 +279 -0
279 lines not on this page · raw message
Signature · 1 line
2.30.2
Mark Brown
maintainerRe: [PATCH v2 5/6] spi: cs42l43: Add SPI controller support
On Tue, May 30, 2023 at 01:21:11PM +0100, Charles Keepax wrote:
A couple of small things:
drivers/spi/spi-cs42l43.c line 36
Quoted 3 lines
drivers/spi/spi-cs42l43.c new file +3
-0+static unsigned int cs42l43_clock_divs[16 ] = { +2 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,18 ,20 ,22 ,24 ,26 ,28 ,30 +};
Do we need to specify the size of the array? I just had to count the
number of initialisers :( Should probably also be const.
drivers/spi/spi-cs42l43.c line 48
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);
We're passing a byte stream through a u32 here - are you sure this is endian safe?
Charles Keepax
maintainerRe: [PATCH v2 5/6] spi: cs42l43: Add SPI controller support
Quoted 11 lines · Mark Brown
On Tue, May 30, 2023 at 01:21:11PM +0100, Charles Keepax wrote:
A couple of small things:
drivers/spi/spi-cs42l43.c line 36
Quoted 3 lines
drivers/spi/spi-cs42l43.c new file +3
-0+static unsigned int cs42l43_clock_divs[16 ] = { +2 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,18 ,20 ,22 ,24 ,26 ,28 ,30 +};Do we need to specify the size of the array? I just had to count the
number of initialisers :( Should probably also be const.
Quoted 5 lines
drivers/spi/spi-cs42l43.c line 48
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);We're passing a byte stream through a u32 here - are you sure this is endian safe?
Ah shoot, yeah Andy made some comments on this that seem to have got lost in my mass of fixups. I will fixup for a v3.
Thanks,
Charles
RE: [PATCH v2 5/6] spi: cs42l43: Add SPI controller support
In reply to Charles KeepaxHello,
Quoted 245 lines
-----Original Message-----
From: Charles Keepax <[email protected]>
Sent: Tuesday, May 30, 2023 5:51 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; yung- [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 5/6] spi: cs42l43: Add SPI controller supportCAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
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.
Signed-off-by Lucas Tanure <[email protected]>Signed-off-by Maciej Strozek <[email protected]>Signed-off-by Charles Keepax <[email protected]>---
Changes since v1:
- UseHZ_PER_MHZ
- Return ret in un/prepare_transfer_hardware
- UseSPI_MODE_X_MASK
- Usedevm_pm_runtime_enable
- Switch to using aplatform_device_idtable
- Usedevice_set_node
- Use min rather thanmin_t, and updating some consts to make it workThanks,
CharlesMAINTAINERS | 1 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-cs42l43.c | 279 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 drivers/spi/spi-cs42l43.cMAINTAINERS +0
-0@@ -4930,6 +4930,7 @@ F:
Documentation/devicetree/bindings/mfd/cirrus,cs*F: Documentation/devicetree/bindings/sound/cirrus,cs* F: drivers/mfd/cs42l43* F: drivers/pinctrl/cirrus/pinctrl-cs42l43*MAINTAINERS +1
-0+F: drivers/spi/spi-cs42l43* F: include/dt-bindings/sound/cs* F: include/linux/mfd/cs42l43* F: include/sound/cs*drivers/spi/Kconfig index renamed from drivers/spi/Kconfig +0
-0
3de2ebe8294aa..f6ce06de41051100644drivers/spi/Kconfig +7
-0@@ -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 SPIcontroller"
depends on ARCH_DAVINCI || ARCH_KEYSTONE || COMPILE_TEST diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index
28c4817a8a74a..49937ea0d73d0100644drivers/spi/Makefile +0
-0@@ -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.odrivers/spi/Makefile +1
-0+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.odrivers/spi/spi-cs42l43.c new file mode renamed from drivers/spi/spi-cs42l43.c +0
-0100644 index 0000000000000..5f86f4feb22c8
drivers/spi/spi-cs42l43.c new file +103
-0@@ -0,0 +1,279 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// CS42L43 SPI Controller Driver +// +// Copyright (C) 2022-2023 Cirrus Logic, Inc. and +// Cirrus Logic International Semiconductor Ltd. + +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/mfd/cs42l43.h> +#include <linux/mfd/cs42l43-regs.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <linux/spi/spi.h> +#include <linux/units.h> + +#define CS42L43_FIFO_SIZE 16 +#define CS42L43_SPI_ROOT_HZ (4 * HZ_PER_MHZ) +#define CS42L43_SPI_MAX_LENGTH 65532 + +enum cs42l43_spi_cmd { +CS42L43_WRITE , +CS42L43_READ +}; + +struct cs42l43_spi { +struct device *dev; +struct regmap *regmap; +struct spi_controller *ctlr; +}; + +static unsigned int cs42l43_clock_divs[16 ] = { +2 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,18 ,20 ,22 ,24 ,26 ,28 ,30 }; + +static int cs42l43_spi_tx (struct regmap *regmap,const u8 *buf, +unsigned int len) { +const u8 *end = buf + len; +u32 val; +int ret; + +while (buf < end) { +const u8 *block =min (buf +CS42L43_FIFO_SIZE , end); + +for (; buf < block - (sizeof (u32) -1 ); buf +=sizeof (u32)) +regmap_write (regmap,CS42L43_TX_DATA , *(const +u32 *)buf); + +if (buf < block) { +unsigned int residue = end - buf; + +memcpy (&val, buf, residue); +regmap_write (regmap,CS42L43_TX_DATA , val); + buf += residue; + } + +regmap_write (regmap,CS42L43_TRAN_CONFIG8 , +CS42L43_SPI_TX_DONE_MASK ); + + ret =regmap_read_poll_timeout (regmap,CS42L43_TRAN_STATUS1 , + val, (val &CS42L43_SPI_TX_REQUEST_MASK ), +1000 ,5000 ); +if (ret) +return ret; + } + +return 0 ; +} + +static int cs42l43_spi_rx (struct regmap *regmap,u8 *buf,unsigned int +len) { +u8 *end = buf + len; +u32 val; +int ret; + +while (buf < end) { +const u8 *block =min (buf +CS42L43_FIFO_SIZE , end); + + ret =regmap_read_poll_timeout (regmap,CS42L43_TRAN_STATUS1 , + val, (val &CS42L43_SPI_RX_REQUEST_MASK ), +1000 ,5000 ); +if (ret) +return ret; + +for (; buf < block - (sizeof (u32) -1 ); buf +=sizeof (u32)) { + ret =regmap_read (regmap,CS42L43_RX_DATA , (u32 *)buf); +if (ret) +return ret; + } + +if (buf < block) { +unsigned int residue = end - buf; + + ret =regmap_read (regmap,CS42L43_RX_DATA , &val); +if (ret) +return ret; + +memcpy (buf, &val, residue); + buf += residue; + } + + regmap_write(regmap, CS42L43_TRAN_CONFIG8,
CS42L43_SPI_RX_DONE_MASK);drivers/spi/spi-cs42l43.c new file +6
-0+ } + +return 0 ; +} + +static int cs42l43_transfer_one(struct spi_controller *ctlr, struct spi_device*spi,
drivers/spi/spi-cs42l43.c new file +16
-0+ struct spi_transfer *tfr) { +struct cs42l43_spi *priv =spi_controller_get_devdata (spi->controller); +int i, ret = -EINVAL ; + +for (i =0 ; i <ARRAY_SIZE (cs42l43_clock_divs); i++) { +if (CS42L43_SPI_ROOT_HZ / cs42l43_clock_divs[i] <= tfr->speed_hz) +break ; + } + +if (i ==ARRAY_SIZE (cs42l43_clock_divs)) +return -EINVAL ; + +regmap_write (priv->regmap,CS42L43_SPI_CLK_CONFIG1 , i); + +if (tfr->tx_buf) { + regmap_write(priv->regmap, CS42L43_TRAN_CONFIG3,
CS42L43_WRITE);drivers/spi/spi-cs42l43.c new file +3
-0+regmap_write (priv->regmap,CS42L43_TRAN_CONFIG4 , tfr->len -1 ); + }else if (tfr->rx_buf) { + regmap_write(priv->regmap, CS42L43_TRAN_CONFIG3,
CS42L43_READ);drivers/spi/spi-cs42l43.c new file +10
-0+regmap_write (priv->regmap,CS42L43_TRAN_CONFIG5 , tfr->len -1 ); + } + +regmap_write (priv->regmap,CS42L43_TRAN_CONFIG1 , +CS42L43_SPI_START_MASK ); + +if (tfr->tx_buf) + ret =cs42l43_spi_tx (priv->regmap, (const u8 *)tfr->tx_buf, tfr->len); +else if (tfr->rx_buf) + ret = cs42l43_spi_rx(priv->regmap, (u8 *)tfr->rx_buf,
drivers/spi/spi-cs42l43.c line 146
Quoted 10 lines
drivers/spi/spi-cs42l43.c new file +10
-0+ tfr->len); + +return ret; +} + +static void cs42l43_set_cs (struct spi_device *spi,bool is_high) { +struct cs42l43_spi *priv = +spi_controller_get_devdata (spi->controller); + +if (spi->chip_select ==0 )
New set/get APIs for accessing spi->chip_select were introduced by
https://github.com/torvalds/linux/commit/303feb3cc06ac0665d0ee9c1414941200e60e8a3
please use these APIs instead of accessing spi->chip_select directly.
drivers/spi/spi-cs42l43.c line 157
Quoted 11 lines
drivers/spi/spi-cs42l43.c new file +11
-0+regmap_write (priv->regmap,CS42L43_SPI_CONFIG2 , +!is_high); } + +static int cs42l43_prepare_message (struct spi_controller *ctlr,struct +spi_message *msg) { +struct cs42l43_spi *priv =spi_controller_get_devdata (ctlr); +struct spi_device *spi = msg->spi; +unsigned int spi_config1 =0 ; + +/* select another internal CS, which doesn't exist, so CS 0 is not used */ +if (spi->cs_gpiod)
Same here for spi->cs_gpio
Regards,
Amit
Quoted 133 lines
drivers/spi/spi-cs42l43.c new file +19
-0+ spi_config1 |=1 <<CS42L43_SPI_SS_SEL_SHIFT ; +if (spi->mode &SPI_CPOL ) + spi_config1 |=CS42L43_SPI_CPOL_MASK ; +if (spi->mode &SPI_CPHA ) + spi_config1 |=CS42L43_SPI_CPHA_MASK ; +if (spi->mode &SPI_3WIRE ) + spi_config1 |=CS42L43_SPI_THREE_WIRE_MASK ; + +regmap_write (priv->regmap,CS42L43_SPI_CONFIG1 , spi_config1); + +return 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);drivers/spi/spi-cs42l43.c new file +45
-0+if (ret) + dev_err(priv->dev, "Failed to enable SPI controller: + %d\n", ret); + + return ret; +} + +static int cs42l43_unprepare_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 ,0 ); +if (ret) + dev_err(priv->dev, "Failed to disable SPI controller: + %d\n", ret); + + return ret; +} + +static size_t cs42l43_spi_max_length (struct spi_device *spi) { +return CS42L43_SPI_MAX_LENGTH ; +} + +static int cs42l43_spi_probe (struct platform_device *pdev) { +struct cs42l43 *cs42l43 =dev_get_drvdata (pdev->dev.parent); +struct cs42l43_spi *priv; +struct fwnode_handle *fwnode =dev_fwnode (cs42l43->dev); +int ret; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->ctlr =devm_spi_alloc_master (&pdev->dev,sizeof (*priv->ctlr)); +if (!priv->ctlr) +return -ENOMEM ; + +spi_controller_set_devdata (priv->ctlr, priv); + + priv->dev = &pdev->dev; + priv->regmap = cs42l43->regmap; + + priv->ctlr->prepare_message = cs42l43_prepare_message; + priv->ctlr->prepare_transfer_hardware =
cs42l43_prepare_transfer_hardware;
+priv->ctlr->unprepare_transfer_hardware=cs42l43_unprepare_transfer_hardware;drivers/spi/spi-cs42l43.c new file +12
-0+ priv->ctlr->transfer_one = cs42l43_transfer_one; + priv->ctlr->set_cs = cs42l43_set_cs; + priv->ctlr->max_transfer_size = cs42l43_spi_max_length; + +if (is_of_node (fwnode)) + fwnode =fwnode_get_named_child_node (fwnode,"spi" ); + +device_set_node (&priv->ctlr->dev, fwnode); + + priv->ctlr->mode_bits =SPI_3WIRE |SPI_MODE_X_MASK ; + priv->ctlr->flags =SPI_CONTROLLER_HALF_DUPLEX ; + priv->ctlr->bits_per_word_mask = SPI_BPW_MASK(8) |
SPI_BPW_MASK(16)|drivers/spi/spi-cs42l43.c new file +4
-0+SPI_BPW_MASK (32 ); + priv->ctlr->min_speed_hz =CS42L43_SPI_ROOT_HZ / + cs42l43_clock_divs[ARRAY_SIZE (cs42l43_clock_divs) -1 ]; + priv->ctlr->max_speed_hz = CS42L43_SPI_ROOT_HZ /cs42l43_clock_divs[0];
drivers/spi/spi-cs42l43.c new file +7
-0+ priv->ctlr->use_gpio_descriptors = true; + priv->ctlr->auto_runtime_pm = true; + +devm_pm_runtime_enable (priv->dev); +pm_runtime_idle (priv->dev); + + regmap_write(priv->regmap, CS42L43_TRAN_CONFIG6,
CS42L43_FIFO_SIZE- 1);drivers/spi/spi-cs42l43.c new file +33
-0+regmap_write (priv->regmap,CS42L43_TRAN_CONFIG7 , +CS42L43_FIFO_SIZE -1 ); + +// Disable Watchdog timer and enable stall +regmap_write (priv->regmap,CS42L43_SPI_CONFIG3 ,0 ); +regmap_write (priv->regmap,CS42L43_SPI_CONFIG4 , +CS42L43_SPI_STALL_ENA_MASK ); + + ret =devm_spi_register_controller (priv->dev, priv->ctlr); +if (ret) { +pm_runtime_disable (priv->dev); +dev_err (priv->dev,"Failed to register SPI controller: %d\n" , ret); + } + +return ret; +} + +static const struct platform_device_id cs42l43_spi_id_table[] = { + {"cs42l43-spi" , }, + {} +}; +MODULE_DEVICE_TABLE (platform, cs42l43_spi_id_table); + +static struct platform_driver cs42l43_spi_driver = { + .driver = { + .name ="cs42l43-spi" , + }, + .probe = cs42l43_spi_probe, + .id_table = cs42l43_spi_id_table, +}; +module_platform_driver (cs42l43_spi_driver); + +MODULE_DESCRIPTION("CS42L43 SPI Driver"); MODULE_AUTHOR("LucasTanure
+<[email protected]>");drivers/spi/spi-cs42l43.c new file +2
-1+MODULE_AUTHOR ("Maciej Strozek <[email protected]>" ); +MODULE_LICENSE ("GPL" ); --2.30.2
Charles Keepax
maintainerRe: [PATCH v2 5/6] spi: cs42l43: Add SPI controller support
Quoted 11 lines · Amit Kumar
Quoted 1 line
+ if (
spi->chip_select== 0)New set/get APIs for accessing
spi->chip_selectwere introduced by
https://github.com/torvalds/linux/commit/303feb3cc06ac0665d0ee9c1414941200e60e8a3
please use these APIs instead of accessingspi->chip_selectdirectly.drivers/spi/spi-cs42l43.c line 157
Quoted 2 lines
drivers/spi/spi-cs42l43.c new file +2
-0+/* select another internal CS, which doesn't exist, so CS 0 is not used */ +if (spi->cs_gpiod)Same here for
spi->cs_gpio
Thanks, I will get these fixed up for v3.
Thanks,
Charles
Charles Keepax
maintainerPATCH v2 6/6 ASoC: cs42l43: Add support for the cs42l43
In reply to Charles KeepaxThe 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.
---
Changes since v1:
- Update regulator names to be lower case
- Use dev_err_probe
- Switch to a platform_device_id table
- Use devm_pm_runtime_enable
- Remove depends on IRQ as the IRQ is now merged into the MFD
- Use device properties for the jack detect settings
- Dynamically get the SoundWire port number from the DAI ID
Thanks,
Charles
include/sound/cs42l43.h | 17 + sound/soc/codecs/Kconfig | 16 + sound/soc/codecs/Makefile | 4 + sound/soc/codecs/cs42l43-jack.c | 951 +++++++++++++ sound/soc/codecs/cs42l43-sdw.c | 75 + sound/soc/codecs/cs42l43.c | 2275 +++++++++++++++++++++++++++++++ sound/soc/codecs/cs42l43.h | 126 ++ 7 files changed, 3464 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 +17 -0
@@ -0,0 +1,17 @@ +/* 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 + +#endif /* CS42L43_ASOC_EXT_H */
sound/soc/codecs/Kconfig +16 -0
@@ -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 + 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
@@ -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 +951 -0
951 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 +2275 -0
1,913 lines not on this page · raw message
sound/soc/codecs/cs42l43.h new file +126 -0
126 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.