Expand SoundWire MBQ register map support
Subsystems (7)
Charles Keepax
maintainerv2 cover Expand SoundWire MBQ register map support
The current SDCA MBQ (Multi-Byte Quantities) register map only supports 16-bit types, add support for more sizes and then update the rt722 driver to use the new support. We also add support for the deferring feature of MBQs to allow hardware to indicate it is not currently ready to service a read/write.
Afraid I don't have hardware to test the rt722 change so it is only build tested, but I thought it good to include a change to demonstrate the new features in use.
Changes since v1:
- Fixed a potentially uninitialised variable.
- Added some extra rt722 registers, Shuming Fan asked for.
Thanks,
Charles
Charles Keepax (6):
soundwire: SDCA: Add additional SDCA address macros
ASoC: SDCA: Update list of entity_0 controls
regmap: sdw-mbq: Add support for further MBQ register sizes
regmap: sdw-mbq: Add support for SDCA deferred controls
ASoC: rt722-sdca: Add some missing readable registers
ASoC: rt722-sdca: Make use of new expanded MBQ regmap
drivers/base/regmap/regmap-sdw-mbq.c | 219 +++++++++++++++++++++--- include/linux/regmap.h | 62 ++++++- include/linux/soundwire/sdw_registers.h | 30 +++- include/sound/sdca_function.h | 33 +++- sound/soc/codecs/rt722-sdca-sdw.c | 128 ++++++++------ sound/soc/codecs/rt722-sdca-sdw.h | 99 ++++++----- sound/soc/codecs/rt722-sdca.c | 135 ++++----------- sound/soc/codecs/rt722-sdca.h | 4 +- 8 files changed, 454 insertions(+), 256 deletions(-)
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH v2 1/6 soundwire: SDCA: Add additional SDCA address macros
Compliment the existing macro to construct an SDCA control address with macros to extract the constituent parts, and validation of such an address. Also update the masks for the original macro to use GENMASK to make mental comparisons with the included comment on the address format easier.
---
No changes since v1.
include/linux/soundwire/sdw_registers.h | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-)
include/linux/soundwire/sdw_registers.h +22 -8
@@ -4,6 +4,9 @@#ifndef __SDW_REGISTERS_H#define __SDW_REGISTERS_H +#include <linux/bitfield.h> +#include <linux/bits.h> +/* * SDW registers as defined by MIPI 1.2 Spec */
@@ -329,16 +332,27 @@* 2:0 Control Number[2:0] */ -#define SDW_SDCA_CTL (fun, ent, ctl, ch) (BIT(30) | \ - (((fun) & 0x7) << 22) | \ - (((ent) & 0x40) << 15) | \ - (((ent) & 0x3f) << 7) | \ - (((ctl) & 0x30) << 15) | \ - (((ctl) & 0x0f) << 3) | \ - (((ch) & 0x38) << 12) | \ - ((ch) & 0x07)) +#define SDW_SDCA_CTL (fun, ent, ctl, ch) (BIT(30) | \ + (((fun) & GENMASK(2, 0)) << 22) | \ + (((ent) & BIT(6)) << 15) | \ + (((ent) & GENMASK(5, 0)) << 7) | \ + (((ctl) & GENMASK(5, 4)) << 15) | \ + (((ctl) & GENMASK(3, 0)) << 3) | \ + (((ch) & GENMASK(5, 3)) << 12) | \ + ((ch) & GENMASK(2, 0))) + +#define SDW_SDCA_CTL_FUNC (reg) FIELD_GET(GENMASK(24, 22), (reg)) +#define SDW_SDCA_CTL_ENT (reg) ((FIELD_GET(BIT(21), (reg)) << 6) | \ + FIELD_GET(GENMASK(12, 7), (reg))) +#define SDW_SDCA_CTL_CSEL (reg) ((FIELD_GET(GENMASK(20, 19), (reg)) << 4) | \ + FIELD_GET(GENMASK(6, 3), (reg))) +#define SDW_SDCA_CTL_CNUM (reg) ((FIELD_GET(GENMASK(17, 15), (reg)) << 3) | \ + FIELD_GET(GENMASK(2, 0), (reg)))#define SDW_SDCA_MBQ_CTL (reg) ((reg) | BIT(13))#define SDW_SDCA_NEXT_CTL (reg) ((reg) | BIT(14)) +/* Check the reserved and fixed bits in address */ +#define SDW_SDCA_VALID_CTL (reg) (((reg) & (GENMASK(31, 25) | BIT(18) | BIT(13))) == BIT(30)) +#endif /* __SDW_REGISTERS_H */
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH v2 2/6 ASoC: SDCA: Update list of entity_0 controls
In reply to Charles KeepaxUpdate the list of entity_0 controls to better match version v1.0 of the SDCA specification. Remove both INTSTAT_CLEAR and INT_ENABLE as these are no longer used, and add some missing controls and bits into the enum. Also rename the SDCA_CONTROL prefix to SDCA_CTL because this better matches the macros in the sdw_registers.h header, and the names can get quite long so saving a few characters is definitely a plus.
---
No changes since v1.
include/sound/sdca_function.h | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
include/sound/sdca_function.h +25 -8
@@ -45,14 +45,31 @@ enum sdca_function_type {#define SDCA_FUNCTION_TYPE_IMP_DEF_NAME "ImplementationDefined"enum sdca_entity0_controls { -SDCA_CONTROL_ENTITY_0_COMMIT_GROUP_MASK =0x01 , -SDCA_CONTROL_ENTITY_0_INTSTAT_CLEAR =0x02 , -SDCA_CONTROL_ENTITY_0_INT_ENABLE =0x03 , -SDCA_CONTROL_ENTITY_0_FUNCTION_SDCA_VERSION =0x04 , -SDCA_CONTROL_ENTITY_0_FUNCTION_TOPOLOGY =0x05 , -SDCA_CONTROL_ENTITY_0_FUNCTION_MANUFACTURER_ID =0x06 , -SDCA_CONTROL_ENTITY_0_FUNCTION_ID =0x07 , -SDCA_CONTROL_ENTITY_0_FUNCTION_VERSION =0x08 +SDCA_CTL_ENTITY_0_COMMIT_GROUP_MASK =0x01 , +SDCA_CTL_ENTITY_0_FUNCTION_SDCA_VERSION =0x04 , +SDCA_CTL_ENTITY_0_FUNCTION_TYPE =0x05 , +SDCA_CTL_ENTITY_0_FUNCTION_MANUFACTURER_ID =0x06 , +SDCA_CTL_ENTITY_0_FUNCTION_ID =0x07 , +SDCA_CTL_ENTITY_0_FUNCTION_VERSION =0x08 , +SDCA_CTL_ENTITY_0_FUNCTION_EXTENSION_ID =0x09 , +SDCA_CTL_ENTITY_0_FUNCTION_EXTENSION_VERSION =0x0A , +SDCA_CTL_ENTITY_0_FUNCTION_STATUS =0x10 , +SDCA_CTL_ENTITY_0_FUNCTION_ACTION =0x11 , +SDCA_CTL_ENTITY_0_MATCHING_GUID =0x12 , +SDCA_CTL_ENTITY_0_DEVICE_MANUFACTURER_ID =0x2C , +SDCA_CTL_ENTITY_0_DEVICE_PART_ID =0x2D , +SDCA_CTL_ENTITY_0_DEVICE_VERSION =0x2E , +SDCA_CTL_ENTITY_0_DEVICE_SDCA_VERSION =0x2F , + +/* Function Status Bits */ +SDCA_CTL_ENTITY_0_DEVICE_NEWLY_ATTACHED =BIT (0 ), +SDCA_CTL_ENTITY_0_INTS_DISABLED_ABNORMALLY =BIT (1 ), +SDCA_CTL_ENTITY_0_STREAMING_STOPPED_ABNORMALLY =BIT (2 ), +SDCA_CTL_ENTITY_0_FUNCTION_FAULT =BIT (3 ), +SDCA_CTL_ENTITY_0_UMP_SEQUENCE_FAULT =BIT (4 ), +SDCA_CTL_ENTITY_0_FUNCTION_NEEDS_INITIALIZATION =BIT (5 ), +SDCA_CTL_ENTITY_0_FUNCTION_HAS_BEEN_RESET =BIT (6 ), +SDCA_CTL_ENTITY_0_FUNCTION_BUSY =BIT (7 ), };#endif
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH v2 3/6 regmap: sdw-mbq: Add support for further MBQ register sizes
In reply to Charles KeepaxSoundWire MBQ register maps typically contain a variety of register sizes, which doesn't map ideally to the regmap abstraction which expects register maps to have a consistent size. Currently the MBQ register map only allows 16-bit registers to be defined, however this leads to complex CODEC driver implementations with an 8-bit register map and a 16-bit MBQ, every control will then have a custom get and put handler that allows them to access different register maps. Further more 32-bit MBQ quantities are not currently supported.
Add support for additional MBQ sizes and to avoid the complexity of multiple register maps treat the val_size as a maximum size for the register map. Within the regmap use an ancillary callback to determine how many bytes to actually read/write to the hardware for a specific register. In the case that no callback is defined the behaviour defaults back to the existing behaviour of a fixed size register map.
---
No changes since v1.
drivers/base/regmap/regmap-sdw-mbq.c | 114 ++++++++++++++++++++++----- include/linux/regmap.h | 47 ++++++++++- 2 files changed, 139 insertions(+), 22 deletions(-)
drivers/base/regmap/regmap-sdw-mbq.c +94 -20
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 // Copyright(c) 2020 Intel Corporation. +#include <linux/bits.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/module.h>
@@ -9,35 +10,77 @@#include <linux/soundwire/sdw_registers.h> #include "internal.h" +struct regmap_mbq_context { +struct device *dev; + +struct regmap_sdw_mbq_cfg cfg; + +int val_size; +}; + +static int regmap_sdw_mbq_size (struct regmap_mbq_context *ctx,unsigned int reg) +{ +int size = ctx->val_size; + +if (ctx->cfg.mbq_size) { + size = ctx->cfg.mbq_size (ctx->dev, reg); +if (!size || size > ctx->val_size) +return -EINVAL ; + } + +return size; +} +static int regmap_sdw_mbq_write (void *context,unsigned int reg,unsigned int val) { -struct device *dev = context; +struct regmap_mbq_context *ctx = context; +struct device *dev = ctx->dev;struct sdw_slave *slave =dev_to_sdw_dev (dev); +int mbq_size =regmap_sdw_mbq_size (ctx, reg); +int shift = mbq_size *BITS_PER_BYTE ;int ret; - ret =sdw_write_no_pm (slave,SDW_SDCA_MBQ_CTL (reg), (val >>8 ) &0xff ); -if (ret <0 ) -return ret; +if (mbq_size <0 ) +return mbq_size; + +while (--mbq_size >0 ) { + shift -=BITS_PER_BYTE ; + + ret =sdw_write_no_pm (slave,SDW_SDCA_MBQ_CTL (reg), + (val >> shift) &0xff ); +if (ret <0 ) +return ret; + }return sdw_write_no_pm (slave, reg, val &0xff ); }static int regmap_sdw_mbq_read (void *context,unsigned int reg,unsigned int *val) { -struct device *dev = context; +struct regmap_mbq_context *ctx = context; +struct device *dev = ctx->dev;struct sdw_slave *slave =dev_to_sdw_dev (dev); -int read0; -int read1; +int mbq_size =regmap_sdw_mbq_size (ctx, reg); +int shift =BITS_PER_BYTE ; +int read; - read0 =sdw_read_no_pm (slave, reg); -if (read0 <0 ) -return read0; +if (mbq_size <0 ) +return mbq_size; - read1 =sdw_read_no_pm (slave,SDW_SDCA_MBQ_CTL (reg)); -if (read1 <0 ) -return read1; + read =sdw_read_no_pm (slave, reg); +if (read <0 ) +return read; - *val = (read1 <<8 ) | read0; + *val = read; + +while (--mbq_size >0 ) { + read =sdw_read_no_pm (slave,SDW_SDCA_MBQ_CTL (reg)); +if (read <0 ) +return read; + + *val |= read << shift; + shift +=BITS_PER_BYTE ; + }return 0 ; }
@@ -51,8 +94,7 @@ static const struct regmap_bus regmap_sdw_mbq = {static int regmap_sdw_mbq_config_check (const struct regmap_config *config) { -/* MBQ-based controls are only 16-bits for now */ -if (config->val_bits !=16 ) +if (config->val_bits > (sizeof (unsigned int ) *BITS_PER_BYTE ))return -ENOTSUPP ;/* Registers are 32 bits wide */
@@ -65,35 +107,67 @@ static int regmap_sdw_mbq_config_check(const struct regmap_config *config)return 0 ; } +static struct regmap_mbq_context * +regmap_sdw_mbq_gen_context (struct device *dev, +const struct regmap_config *config, +const struct regmap_sdw_mbq_cfg *mbq_config) +{ +struct regmap_mbq_context *ctx; + + ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return ERR_PTR (-ENOMEM ); + + ctx->dev = dev; + ctx->val_size = config->val_bits /BITS_PER_BYTE ; + +if (mbq_config) + ctx->cfg = *mbq_config; + +return ctx; +} +struct regmap *__regmap_init_sdw_mbq (struct sdw_slave *sdw,const struct regmap_config *config, +const struct regmap_sdw_mbq_cfg *mbq_config,struct lock_class_key *lock_key,const char *lock_name) { +struct regmap_mbq_context *ctx;int ret; ret =regmap_sdw_mbq_config_check (config);if (ret)return ERR_PTR (ret); -return __regmap_init (&sdw->dev, ®map_sdw_mbq, - &sdw->dev, config, lock_key, lock_name); + ctx =regmap_sdw_mbq_gen_context (&sdw->dev, config, mbq_config); +if (IS_ERR (ctx)) +return ERR_CAST (ctx); + +return __regmap_init (&sdw->dev, ®map_sdw_mbq, ctx, + config, lock_key, lock_name); }EXPORT_SYMBOL_GPL (__regmap_init_sdw_mbq);struct regmap *__devm_regmap_init_sdw_mbq (struct sdw_slave *sdw,const struct regmap_config *config, +const struct regmap_sdw_mbq_cfg *mbq_config,struct lock_class_key *lock_key,const char *lock_name) { +struct regmap_mbq_context *ctx;int ret; ret =regmap_sdw_mbq_config_check (config);if (ret)return ERR_PTR (ret); -return __devm_regmap_init (&sdw->dev, ®map_sdw_mbq, - &sdw->dev, config, lock_key, lock_name); + ctx =regmap_sdw_mbq_gen_context (&sdw->dev, config, mbq_config); +if (IS_ERR (ctx)) +return ERR_CAST (ctx); + +return __devm_regmap_init (&sdw->dev, ®map_sdw_mbq, ctx, + config, lock_key, lock_name); }EXPORT_SYMBOL_GPL (__devm_regmap_init_sdw_mbq);
include/linux/regmap.h +45 -2
77 lines not on this page · raw message
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH v2 4/6 regmap: sdw-mbq: Add support for SDCA deferred controls
In reply to Charles KeepaxThe SDCA specification allows for controls to be deferred. In the case of a deferred control the device will return COMMAND_IGNORED to the 8-bit operation that would cause the value to commit. Which is the final 8-bits on a write, or the first 8-bits on a read. In the case of receiving a defer, the regmap will poll the SDCA function busy bit, after which the transaction will be retried, returning an error if the function busy does not clear within a chip specific timeout. Since this is common SDCA functionality which is the 99% use-case for MBQs it makes sense to incorporate this functionality into the register map. If no MBQ configuration is specified, the behaviour will default to the existing behaviour.
---
Changes since v1:
- Initialise ret in regmap_sdw_mbq_poll_busy() to avoid potentially returning an uninitialised value.
Thanks,
Charles
drivers/base/regmap/regmap-sdw-mbq.c | 129 ++++++++++++++++++++++++--- include/linux/regmap.h | 15 ++++ 2 files changed, 130 insertions(+), 14 deletions(-)
drivers/base/regmap/regmap-sdw-mbq.c +115 -14
@@ -2,12 +2,15 @@// Copyright(c) 2020 Intel Corporation. #include <linux/bits.h> +#include <linux/delay.h> #include <linux/device.h> #include <linux/errno.h> +#include <linux/iopoll.h> #include <linux/module.h> #include <linux/regmap.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_registers.h> +#include <sound/sdca_function.h> #include "internal.h" struct regmap_mbq_context {
@@ -16,6 +19,7 @@ struct regmap_mbq_context {struct regmap_sdw_mbq_cfg cfg;int val_size; +bool (*readable_reg)(struct device *dev,unsigned int reg); };static int regmap_sdw_mbq_size (struct regmap_mbq_context *ctx,unsigned int reg)
@@ -31,18 +35,48 @@ static int regmap_sdw_mbq_size(struct regmap_mbq_context *ctx, unsigned int reg)return size; } -static int regmap_sdw_mbq_write (void *context,unsigned int reg,unsigned int val) +static bool regmap_sdw_mbq_deferrable (struct regmap_mbq_context *ctx,unsigned int reg) +{ +if (ctx->cfg.deferrable) +return ctx->cfg.deferrable (ctx->dev, reg); + +return false; +} + +static int regmap_sdw_mbq_poll_busy (struct sdw_slave *slave,unsigned int reg, +struct regmap_mbq_context *ctx) +{ +struct device *dev = &slave->dev; +int val, ret =0 ; + +dev_dbg (dev,"Deferring transaction for 0x%x\n" , reg); + + reg =SDW_SDCA_CTL (SDW_SDCA_CTL_FUNC (reg),0 , +SDCA_CTL_ENTITY_0_FUNCTION_STATUS ,0 ); + +if (ctx->readable_reg (dev, reg)) { + ret =read_poll_timeout (sdw_read_no_pm, val, + val <0 || !(val &SDCA_CTL_ENTITY_0_FUNCTION_BUSY ), + ctx->cfg.timeout_us, ctx->cfg.retry_us, + false, slave, reg); +if (val <0 ) +return val; +if (ret) +dev_err (dev,"Function busy timed out 0x%x: %d\n" , reg, val); + }else { +fsleep (ctx->cfg.timeout_us); + } + +return ret; +} + +static int regmap_sdw_mbq_write_impl (struct sdw_slave *slave, +unsigned int reg,unsigned int val, +int mbq_size,bool deferrable) { -struct regmap_mbq_context *ctx = context; -struct device *dev = ctx->dev; -struct sdw_slave *slave =dev_to_sdw_dev (dev); -int mbq_size =regmap_sdw_mbq_size (ctx, reg);int shift = mbq_size *BITS_PER_BYTE ;int ret; -if (mbq_size <0 ) -return mbq_size; -while (--mbq_size >0 ) { shift -=BITS_PER_BYTE ;
@@ -52,24 +86,58 @@ static int regmap_sdw_mbq_write(void *context, unsigned int reg, unsigned int vareturn ret; } -return sdw_write_no_pm (slave, reg, val &0xff ); + ret =sdw_write_no_pm (slave, reg, val &0xff ); +if (deferrable && ret == -ENODATA ) +return -EAGAIN ; + +return ret; } -static int regmap_sdw_mbq_read (void *context,unsigned int reg,unsigned int *val) +static int regmap_sdw_mbq_write (void *context,unsigned int reg,unsigned int val) {struct regmap_mbq_context *ctx = context;struct device *dev = ctx->dev;struct sdw_slave *slave =dev_to_sdw_dev (dev); +bool deferrable =regmap_sdw_mbq_deferrable (ctx, reg);int mbq_size =regmap_sdw_mbq_size (ctx, reg); -int shift =BITS_PER_BYTE ; -int read; +int ret;if (mbq_size <0 )return mbq_size; +/* +* Technically the spec does allow a device to set itself to busy for +* internal reasons, but since it doesn't provide any information on +* how to handle timeouts in that case, for now the code will only +* process a single wait/timeout on function busy and a single retry +* of the transaction. +*/ + ret =regmap_sdw_mbq_write_impl (slave, reg, val, mbq_size, deferrable); +if (ret == -EAGAIN ) { + ret =regmap_sdw_mbq_poll_busy (slave, reg, ctx); +if (ret) +return ret; + + ret =regmap_sdw_mbq_write_impl (slave, reg, val, mbq_size, false); + } + +return ret; +} + +static int regmap_sdw_mbq_read_impl (struct sdw_slave *slave, +unsigned int reg,unsigned int *val, +int mbq_size,bool deferrable) +{ +int shift =BITS_PER_BYTE ; +int read; + read =sdw_read_no_pm (slave, reg); -if (read <0 ) +if (read <0 ) { +if (deferrable && read == -ENODATA ) +return -EAGAIN ; +return read; + } *val = read;
@@ -85,6 +153,37 @@ static int regmap_sdw_mbq_read(void *context, unsigned int reg, unsigned int *vareturn 0 ; } +static int regmap_sdw_mbq_read (void *context,unsigned int reg,unsigned int *val) +{ +struct regmap_mbq_context *ctx = context; +struct device *dev = ctx->dev; +struct sdw_slave *slave =dev_to_sdw_dev (dev); +bool deferrable =regmap_sdw_mbq_deferrable (ctx, reg); +int mbq_size =regmap_sdw_mbq_size (ctx, reg); +int ret; + +if (mbq_size <0 ) +return mbq_size; + +/* +* Technically the spec does allow a device to set itself to busy for +* internal reasons, but since it doesn't provide any information on +* how to handle timeouts in that case, for now the code will only +* process a single wait/timeout on function busy and a single retry +* of the transaction. +*/ + ret =regmap_sdw_mbq_read_impl (slave, reg, val, mbq_size, deferrable); +if (ret == -EAGAIN ) { + ret =regmap_sdw_mbq_poll_busy (slave, reg, ctx); +if (ret) +return ret; + + ret =regmap_sdw_mbq_read_impl (slave, reg, val, mbq_size, false); + } + +return ret; +} +static const struct regmap_bus regmap_sdw_mbq = { .reg_read = regmap_sdw_mbq_read, .reg_write = regmap_sdw_mbq_write,
@@ -119,11 +218,13 @@ regmap_sdw_mbq_gen_context(struct device *dev,return ERR_PTR (-ENOMEM ); ctx->dev = dev; - ctx->val_size = config->val_bits /BITS_PER_BYTE ;if (mbq_config) ctx->cfg = *mbq_config; + ctx->val_size = config->val_bits /BITS_PER_BYTE ; + ctx->readable_reg = config->readable_reg; +return ctx; }
include/linux/regmap.h +15 -0
@@ -510,11 +510,26 @@ struct regmap_range_cfg {* struct regmap_sdw_mbq_cfg - Configuration for Multi-Byte Quantities * * @mbq_size: Callback returning the actual size of the given register. +* @deferrable: Callback returning true if the hardware can defer +* transactions to the given register. Deferral should +* only be used by SDCA parts and typically which controls +* are deferrable will be specified in either as a hard +* coded list or from the DisCo tables in the platform +* firmware. +* +* @timeout_us: The time in microseconds after which waiting for a deferred +* transaction should time out. +* @retry_us: The time in microseconds between polls of the function busy +* status whilst waiting for an opportunity to retry a deferred +* transaction. * * Provides additional configuration required for SoundWire MBQ register maps. */ struct regmap_sdw_mbq_cfg {int (*mbq_size)(struct device *dev,unsigned int reg); +bool (*deferrable)(struct device *dev,unsigned int reg); +unsigned long timeout_us; +unsigned long retry_us; };struct regmap_async ;
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH v2 5/6 ASoC: rt722-sdca: Add some missing readable registers
In reply to Charles KeepaxAdd a few missing registers from the readable register callback.
---
New since v1.
sound/soc/codecs/rt722-sdca-sdw.c | 49 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-)
sound/soc/codecs/rt722-sdca-sdw.c +46 -3
@@ -28,9 +28,50 @@ static bool rt722_sdca_readable_register(struct device *dev, unsigned int reg) 0):case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_GE49 ,RT722_SDCA_CTL_DETECTED_MODE ,0 ): -case SDW_SDCA_CTL (FUNC_NUM_HID ,RT722_SDCA_ENT_HID01 ,RT722_SDCA_CTL_HIDTX_CURRENT_OWNER , - 0) ... SDW_SDCA_CTL(FUNC_NUM_HID, RT722_SDCA_ENT_HID01, -RT722_SDCA_CTL_HIDTX_MESSAGE_LENGTH ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_XU03 ,RT722_SDCA_CTL_SELECTED_MODE , +0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , + RT722_SDCA_CTL_FU_MUTE, CH_L) ... +SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , +RT722_SDCA_CTL_FU_MUTE ,CH_R ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_XU0D , +RT722_SDCA_CTL_SELECTED_MODE ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU0F , + RT722_SDCA_CTL_FU_MUTE, CH_L) ... +SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU0F , +RT722_SDCA_CTL_FU_MUTE ,CH_R ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_PDE40 , +RT722_SDCA_CTL_REQ_POWER_STATE ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_PDE12 , +RT722_SDCA_CTL_REQ_POWER_STATE ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_CS01 , +RT722_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_CS11 , +RT722_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT722_SDCA_ENT_USER_FU1E , + RT722_SDCA_CTL_FU_MUTE, CH_01) ... +SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT722_SDCA_ENT_USER_FU1E , +RT722_SDCA_CTL_FU_MUTE ,CH_04 ): +case SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT722_SDCA_ENT_IT26 , +RT722_SDCA_CTL_VENDOR_DEF ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT722_SDCA_ENT_PDE2A , +RT722_SDCA_CTL_REQ_POWER_STATE ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT722_SDCA_ENT_CS1F , +RT722_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_HID ,RT722_SDCA_ENT_HID01 , + RT722_SDCA_CTL_HIDTX_CURRENT_OWNER, 0) ... +SDW_SDCA_CTL (FUNC_NUM_HID ,RT722_SDCA_ENT_HID01 , +RT722_SDCA_CTL_HIDTX_MESSAGE_LENGTH ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_USER_FU06 , + RT722_SDCA_CTL_FU_MUTE, CH_L) ... +SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_USER_FU06 , +RT722_SDCA_CTL_FU_MUTE ,CH_R ): +case SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_OT23 , +RT722_SDCA_CTL_VENDOR_DEF ,CH_08 ): +case SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_PDE23 , +RT722_SDCA_CTL_REQ_POWER_STATE ,0 ): +case SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_CS31 , +RT722_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ): case RT722_BUF_ADDR_HID1 ... RT722_BUF_ADDR_HID2:return true;default :
@@ -74,6 +115,7 @@ static bool rt722_sdca_mbq_readable_register(struct device *dev, unsigned int re case 0x5600000 ... 0x5600007: case 0x5700000 ... 0x5700004: case 0x5800000 ... 0x5800004: +case 0x5810000 :case 0x5b00003 :case 0x5c00011 :case 0x5d00006 :
@@ -81,6 +123,7 @@ static bool rt722_sdca_mbq_readable_register(struct device *dev, unsigned int recase 0x5f00030 : case 0x6100000 ... 0x6100051: case 0x6100055 ... 0x6100057: +case 0x6100060 :case 0x6100062 : case 0x6100064 ... 0x6100065:case 0x6100067 :
Signature · 1 line
2.39.5
Pierre-Louis Bossart
reviewerRe: [PATCH v2 5/6] ASoC: rt722-sdca: Add some missing readable registers
sound/soc/codecs/rt722-sdca-sdw.c static bool rt722_sdca_readable_register(struct device *dev, unsigned int reg) · line 38
Quoted 8 lines
sound/soc/codecs/rt722-sdca-sdw.c +6
-0+case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , + RT722_SDCA_CTL_FU_MUTE, CH_L) ... +SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , +RT722_SDCA_CTL_FU_MUTE ,CH_R ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_XU0D , +RT722_SDCA_CTL_SELECTED_MODE ,0 ):
nit-pick: maybe we should have a shorter macro when the Channel Number is not used? Using zero here means there is no channel-specific control, not an explicit intent to program ch0 and ignore chN with N>0.
Charles Keepax
maintainerRe: [PATCH v2 5/6] ASoC: rt722-sdca: Add some missing readable registers
Quoted 12 lines · Pierre-Louis Bossart
sound/soc/codecs/rt722-sdca-sdw.c static bool rt722_sdca_readable_register(struct device *dev, unsigned int reg) · line 38
Quoted 6 lines
sound/soc/codecs/rt722-sdca-sdw.c +6
-0+case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , + RT722_SDCA_CTL_FU_MUTE, CH_L) ... +SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_USER_FU05 , +RT722_SDCA_CTL_FU_MUTE ,CH_R ): +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_XU0D , +RT722_SDCA_CTL_SELECTED_MODE ,0 ):nit-pick: maybe we should have a shorter macro when the Channel Number is not used? Using zero here means there is no channel-specific control, not an explicit intent to program ch0 and ignore chN with N>0.
Yeah the current macros are a bit hard to parse, I would probably even suggest a little string pasting too so one could do something more like:
RT722_SDCA_CTL(CODEC, FU05, FU_MUTE, CH_L)
But this is all clearly a separate improvement. The purpose here is just to demonstrate using the new regmap features, not to improve the coding style of the rt722 driver.
Thanks,
Charles
Charles Keepax
maintainerPATCH v2 6/6 ASoC: rt722-sdca: Make use of new expanded MBQ regmap
In reply to Charles KeepaxNow the MBQ regmap implementation handles multiple sizes, this driver can combine its two register maps into one. So remove mbq_regmap and combine all the registers into regmap.
Also as rt722_sdca_adc_mux_get/put() only exist to access mbq_regmap, rather than doing any processing, these can now be dropped and the normal DAPM helpers used.
---
No changes since v1.
sound/soc/codecs/rt722-sdca-sdw.c | 81 ++++++------------ sound/soc/codecs/rt722-sdca-sdw.h | 99 +++++++++++----------- sound/soc/codecs/rt722-sdca.c | 135 +++++++----------------------- sound/soc/codecs/rt722-sdca.h | 4 +- 4 files changed, 105 insertions(+), 214 deletions(-)
sound/soc/codecs/rt722-sdca-sdw.c +26 -55
@@ -16,7 +16,7 @@#include "rt722-sdca.h" #include "rt722-sdca-sdw.h" -static bool rt722_sdca_readable_register (struct device *dev,unsigned int reg) +static int rt722_sdca_mbq_size (struct device *dev,unsigned int reg) {switch (reg) { case 0x2f01 ... 0x2f0a:
@@ -73,32 +73,7 @@ static bool rt722_sdca_readable_register(struct device *dev, unsigned int reg)case SDW_SDCA_CTL (FUNC_NUM_AMP ,RT722_SDCA_ENT_CS31 ,RT722_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ): case RT722_BUF_ADDR_HID1 ... RT722_BUF_ADDR_HID2: -return true; -default : -return false; - } -} - -static bool rt722_sdca_volatile_register (struct device *dev,unsigned int reg) -{ -switch (reg) { -case 0x2f01 : -case 0x2f54 : -case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_GE49 ,RT722_SDCA_CTL_DETECTED_MODE , -0 ): -case SDW_SDCA_CTL (FUNC_NUM_HID ,RT722_SDCA_ENT_HID01 ,RT722_SDCA_CTL_HIDTX_CURRENT_OWNER , - 0) ... SDW_SDCA_CTL(FUNC_NUM_HID, RT722_SDCA_ENT_HID01, -RT722_SDCA_CTL_HIDTX_MESSAGE_LENGTH ,0 ): - case RT722_BUF_ADDR_HID1 ... RT722_BUF_ADDR_HID2: -return true; -default : -return false; - } -} - -static bool rt722_sdca_mbq_readable_register (struct device *dev,unsigned int reg) -{ -switch (reg) { +return 1 ; case 0x2000000 ... 0x2000024: case 0x2000029 ... 0x200004a: case 0x2000051 ... 0x2000052:
@@ -151,15 +126,32 @@ static bool rt722_sdca_mbq_readable_register(struct device *dev, unsigned int re RT722_SDCA_CTL_FU_CH_GAIN, CH_L):case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_PLATFORM_FU44 ,RT722_SDCA_CTL_FU_CH_GAIN ,CH_R ): -return true; +return 2 ;default : -return false; +return 0 ; } } -static bool rt722_sdca_mbq_volatile_register (struct device *dev,unsigned int reg) +static struct regmap_sdw_mbq_cfg rt722_mbq_config = { + .mbq_size = rt722_sdca_mbq_size, +}; + +static bool rt722_sdca_readable_register (struct device *dev,unsigned int reg) +{ +return rt722_sdca_mbq_size (dev, reg) >0 ; +} + +static bool rt722_sdca_volatile_register (struct device *dev,unsigned int reg) {switch (reg) { +case 0x2f01 : +case 0x2f54 : +case SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT722_SDCA_ENT_GE49 ,RT722_SDCA_CTL_DETECTED_MODE , +0 ): +case SDW_SDCA_CTL (FUNC_NUM_HID ,RT722_SDCA_ENT_HID01 ,RT722_SDCA_CTL_HIDTX_CURRENT_OWNER , + 0) ... SDW_SDCA_CTL(FUNC_NUM_HID, RT722_SDCA_ENT_HID01, +RT722_SDCA_CTL_HIDTX_MESSAGE_LENGTH ,0 ): + case RT722_BUF_ADDR_HID1 ... RT722_BUF_ADDR_HID2:case 0x2000000 :case 0x200000d :case 0x2000019 :
@@ -178,7 +170,7 @@ static bool rt722_sdca_mbq_volatile_register(struct device *dev, unsigned int restatic const struct regmap_config rt722_sdca_regmap = { .reg_bits =32 , - .val_bits =8 , + .val_bits =16 , .readable_reg = rt722_sdca_readable_register, .volatile_reg = rt722_sdca_volatile_register, .max_register =0x44ffffff ,
@@ -189,20 +181,6 @@ static const struct regmap_config rt722_sdca_regmap = { .use_single_write = true, }; -static const struct regmap_config rt722_sdca_mbq_regmap = { - .name ="sdw-mbq" , - .reg_bits =32 , - .val_bits =16 , - .readable_reg = rt722_sdca_mbq_readable_register, - .volatile_reg = rt722_sdca_mbq_volatile_register, - .max_register =0x41000312 , - .reg_defaults = rt722_sdca_mbq_defaults, - .num_reg_defaults =ARRAY_SIZE (rt722_sdca_mbq_defaults), - .cache_type =REGCACHE_MAPLE , - .use_single_read = true, - .use_single_write = true, -}; -static int rt722_sdca_update_status (struct sdw_slave *slave,enum sdw_slave_status status) {
@@ -412,18 +390,14 @@ static const struct sdw_slave_ops rt722_sdca_slave_ops = {static int rt722_sdca_sdw_probe (struct sdw_slave *slave,const struct sdw_device_id *id) { -struct regmap *regmap, *mbq_regmap; +struct regmap *regmap;/* Regmap Initialization */ - mbq_regmap =devm_regmap_init_sdw_mbq (slave, &rt722_sdca_mbq_regmap); -if (IS_ERR (mbq_regmap)) -return PTR_ERR (mbq_regmap); - - regmap =devm_regmap_init_sdw (slave, &rt722_sdca_regmap); + regmap =devm_regmap_init_sdw_mbq_cfg (slave, &rt722_sdca_regmap, &rt722_mbq_config);if (IS_ERR (regmap))return PTR_ERR (regmap); -return rt722_sdca_init (&slave->dev, regmap, mbq_regmap, slave); +return rt722_sdca_init (&slave->dev, regmap, slave); }static int rt722_sdca_sdw_remove (struct sdw_slave *slave)
@@ -461,7 +435,6 @@ static int __maybe_unused rt722_sdca_dev_suspend(struct device *dev)cancel_delayed_work_sync (&rt722->jack_btn_check_work);regcache_cache_only (rt722->regmap, true); -regcache_cache_only (rt722->mbq_regmap, true);return 0 ; }
@@ -531,8 +504,6 @@ static int __maybe_unused rt722_sdca_dev_resume(struct device *dev) slave->unattach_request =0 ;regcache_cache_only (rt722->regmap, false);regcache_sync (rt722->regmap); -regcache_cache_only (rt722->mbq_regmap, false); -regcache_sync (rt722->mbq_regmap);return 0 ; }
sound/soc/codecs/rt722-sdca-sdw.h +48 -51
135 lines not on this page · raw message
sound/soc/codecs/rt722-sdca.c +30 -105
233 lines not on this page · raw message
sound/soc/codecs/rt722-sdca.h +1 -3
@@ -17,7 +17,6 @@struct rt722_sdca_priv {struct regmap *regmap; -struct regmap *mbq_regmap;struct snd_soc_component *component;struct sdw_slave *slave;struct sdw_bus_params params;
@@ -229,8 +228,7 @@ enum rt722_sdca_jd_src { };int rt722_sdca_io_init (struct device *dev,struct sdw_slave *slave); -int rt722_sdca_init (struct device *dev,struct regmap *regmap, -struct regmap *mbq_regmap,struct sdw_slave *slave); +int rt722_sdca_init (struct device *dev,struct regmap *regmap,struct sdw_slave *slave);int rt722_sdca_index_write (struct rt722_sdca_priv *rt722,unsigned int nid,unsigned int reg,unsigned int value); int rt722_sdca_index_read(struct rt722_sdca_priv *rt722,
Signature · 1 line
2.39.5
Quoted 6 lines · Charles Keepax
The current SDCA MBQ (Multi-Byte Quantities) register map only supports 16-bit types, add support for more sizes and then update the rt722 driver to use the new support. We also add support for the deferring feature of MBQs to allow hardware to indicate it is not currently ready to service a read/write.
Quoted 7 lines
Afraid I don't have hardware to test the rt722 change so it is only build tested, but I thought it good to include a change to demonstrate the new features in use.
Changes since v1:
- Fixed a potentially uninitialised variable.
- Added some extra rt722 registers, Shuming Fan asked for.
For the series:
Quoted 21 lines
Thanks,
CharlesCharles Keepax (6):
soundwire: SDCA: Add additional SDCA address macros
ASoC: SDCA: Update list ofentity_0controls
regmap: sdw-mbq: Add support for further MBQ register sizes
regmap: sdw-mbq: Add support for SDCA deferred controls
ASoC: rt722-sdca: Add some missing readable registers
ASoC: rt722-sdca: Make use of new expanded MBQ regmapdrivers/base/regmap/regmap-sdw-mbq.c | 219 +++++++++++++++++++++--- include/linux/regmap.h | 62 ++++++- include/linux/soundwire/sdw_registers.h | 30 +++- include/sound/sdca_function.h | 33 +++- sound/soc/codecs/rt722-sdca-sdw.c | 128 ++++++++------ sound/soc/codecs/rt722-sdca-sdw.h | 99 ++++++----- sound/soc/codecs/rt722-sdca.c | 135 ++++----------- sound/soc/codecs/rt722-sdca.h | 4 +- 8 files changed, 454 insertions(+), 256 deletions(-)
Mark Brown
maintainerRe: (subset) [PATCH v2 0/6] Expand SoundWire MBQ register map support
In reply to Charles KeepaxQuoted 11 lines · Charles Keepax
The current SDCA MBQ (Multi-Byte Quantities) register map only supports 16-bit types, add support for more sizes and then update the rt722 driver to use the new support. We also add support for the deferring feature of MBQs to allow hardware to indicate it is not currently ready to service a read/write.
Afraid I don't have hardware to test the rt722 change so it is only build tested, but I thought it good to include a change to demonstrate the new features in use.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/6] soundwire: SDCA: Add additional SDCA address macros
commit: 7b16e60b31202254c62a29f5c709ffb42684b6f9
[2/6] ASoC: SDCA: Update list of entity_0 controls
commit: b21468e83b787ab31aa9df8f429d2ca61def0cc9
[3/6] regmap: sdw-mbq: Add support for further MBQ register sizes
commit: fdd9ef3dce98e035d21c17fac587cb6e3c7706fd
[4/6] regmap: sdw-mbq: Add support for SDCA deferred controls
commit: 5bc493bf0c37c157bf2eb364e55a1c6f8bc43a69All 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
Mark Brown
maintainerRe: (subset) [PATCH v2 0/6] Expand SoundWire MBQ register map support
In reply to Charles KeepaxQuoted 11 lines · Charles Keepax
The current SDCA MBQ (Multi-Byte Quantities) register map only supports 16-bit types, add support for more sizes and then update the rt722 driver to use the new support. We also add support for the deferring feature of MBQs to allow hardware to indicate it is not currently ready to service a read/write.
Afraid I don't have hardware to test the rt722 change so it is only build tested, but I thought it good to include a change to demonstrate the new features in use.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[5/6] ASoC: rt722-sdca: Add some missing readable registers
commit: f9a5c4b6afc79073491acdab7f1e943ee3a19fbb
[6/6] ASoC: rt722-sdca: Make use of new expanded MBQ regmap
commit: 299ce4beaf714abe76e3ad106f2e745748f693e9All 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