Message ID | 20200901162225.33343-3-pierre-louis.bossart@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | regmap: add SoundWire 1.2 MBQ support | expand |
On 01-09-20, 11:22, Pierre-Louis Bossart wrote: > The upcoming SDCA (SoundWire Device Class Audio) specification defines > a hierarchical encoding to interface with Class-defined capabilities. > > The specification is not yet accessible to the general public but this > information is released with explicit permission from the MIPI Board > to avoid delays with SDCA support on Linux platforms. > > A block of 64 MBytes of register addresses is allocated to SDCA > controls, starting at address 0x40000000. The 26 LSBs which identify > individual controls are set based on the following variables: > > - Function Number. An SCDA device can be split in up to 8 independent > Functions. Each of these Functions is described in the SDCA > specification, e.g. Smart Amplifier, Smart Microphone, Simple > Microphone, Jack codec, HID, etc. > > - Entity Number. Within each Function, an Entity is an identifiable > block. Up to 127 Entities are connected in a pre-defined > graph (similar to USB), with Entity0 reserved for Function-level > configurations. In contrast to USB, the SDCA spec pre-defines > Function Types, topologies, and allowed options, i.e. the degree of > freedom is not unlimited to limit the possibility of errors in > descriptors leading to software quirks. > > - Control Selector. Within each Entity, the SDCA specification defines > up-to 48 controls such as Mute, Gain, AGC, etc, and 16 > implementation defined ones. Some Control Selectors might be used > for low-level platform setup, and other exposed to applications and > users. Note that the same Control Selector capability, e.g. Latency > control, might be located at different offsets in different > entities - the Control Selector mapping is Entity-specific. > > - Control Number. Some Control Selectors allow channel-specific values > to be set, with up to 64 channels allowed. This is mostly used for > volume control. > > - Current/Next values. Some Control Selectors are > 'Dual-Ranked'. Software may either update the Current value directly > for immediate effect. Alternatively, software may write into the > 'Next' values and update the SoundWire 1.2 'Commit Groups' register > to copy 'Next' values into 'Current' ones in a synchronized > manner. This is different from bank switching which is typically > used to change the bus configuration only. > > - MBQ. the Multi-Byte Quantity bit is used to provide atomic updates > when accessing more that one byte, for example a 16-bit volume > control would be updated consistently, the intermediate values > mixing old MSB with new LSB are not applied. > > These 6 parameters are used to build a 32-bit address to access the > desired Controls. Because of address range, paging is required, but > the most often used parameter values are placed in the lower 16 bits > of the address. This helps to keep the paging registers constant while > updating Controls for a specific Device/Function. This is good, thanks for adding it in changelog. Can you also add this description to Documentation (that can come as an individual patch), > > Reviewed-by: Rander Wang <rander.wang@linux.intel.com> > Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com> > Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> > Acked-by: Bard Liao <yung-chuan.liao@linux.intel.com> > Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> > --- > include/linux/soundwire/sdw_registers.h | 33 +++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/include/linux/soundwire/sdw_registers.h b/include/linux/soundwire/sdw_registers.h > index 5d3c271af7d1..99ff7afc27a2 100644 > --- a/include/linux/soundwire/sdw_registers.h > +++ b/include/linux/soundwire/sdw_registers.h > @@ -305,4 +305,37 @@ > #define SDW_CASC_PORT_MASK_INTSTAT3 1 > #define SDW_CASC_PORT_REG_OFFSET_INTSTAT3 2 > > +/* > + * v1.2 device - SDCA address mapping > + * > + * Spec definition > + * Bits Contents > + * 31 0 (required by addressing range) > + * 30:26 0b10000 (Control Prefix) So this is for 30:26 > + * 25 0 (Reserved) > + * 24:22 Function Number [2:0] > + * 21 Entity[6] > + * 20:19 Control Selector[5:4] > + * 18 0 (Reserved) > + * 17:15 Control Number[5:3] > + * 14 Next > + * 13 MBQ > + * 12:7 Entity[5:0] > + * 6:3 Control Selector[3:0] > + * 2:0 Control Number[2:0] > + */ > + > +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ > + (BIT(30) | \ Programmatically this is fine, but then since we are defining for the description above, IMO it would actually make sense for this to be defined as FIELD_PREP: FIELD_PREP(GENMASK(30, 26), 1) or better u32_encode_bits(GENMASK(30, 26), 1) > + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and below? > + FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) | \ > + FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | \ > + FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | \ > + FIELD_PREP(GENMASK(12, 7), FIELD_GET(GENMASK(5, 0), (ent))) | \ > + FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | \ > + FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) Also, can we rather have a nice function for this, that would look much cleaner And while at it, consider defining masks for various fields rather than using numbers in GENMASK() above, that would look better, be more readable and people can reuse it.
Thanks for the review Vinod, > This is good, thanks for adding it in changelog. Can you also add this > description to Documentation (that can come as an individual patch), ok >> +/* >> + * v1.2 device - SDCA address mapping >> + * >> + * Spec definition >> + * Bits Contents >> + * 31 0 (required by addressing range) >> + * 30:26 0b10000 (Control Prefix) > > So this is for 30:26 I don't get the comment, sorry. > >> + * 25 0 (Reserved) >> + * 24:22 Function Number [2:0] >> + * 21 Entity[6] >> + * 20:19 Control Selector[5:4] >> + * 18 0 (Reserved) >> + * 17:15 Control Number[5:3] >> + * 14 Next >> + * 13 MBQ >> + * 12:7 Entity[5:0] >> + * 6:3 Control Selector[3:0] >> + * 2:0 Control Number[2:0] >> + */ >> + >> +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ >> + (BIT(30) | \ > > Programmatically this is fine, but then since we are defining for the > description above, IMO it would actually make sense for this to be defined > as FIELD_PREP: > > FIELD_PREP(GENMASK(30, 26), 1) > > or better > > u32_encode_bits(GENMASK(30, 26), 1) > >> + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ > > Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and > below? Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and your other patches for bitfield access only use FIELD_PREP/FIELD_GET. I really don't care about which macro is used but it wouldn't hurt to have some level of consistency between different parts of the code? Why not use FIELD_PREP/GET everywhere? >> + FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) | \ >> + FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | \ >> + FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | \ >> + FIELD_PREP(GENMASK(12, 7), FIELD_GET(GENMASK(5, 0), (ent))) | \ >> + FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | \ >> + FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) > > Also, can we rather have a nice function for this, that would look much > cleaner I am not sure what would be cleaner but fine. > And while at it, consider defining masks for various fields rather than > using numbers in GENMASK() above, that would look better, be more > readable and people can reuse it. Actually on this one I disagree. These fields are not intended to be used by anyone, the goal is precisely to hide them behind regmap, and the use of raw numbers makes it easier to cross-check the documentation and the code. Adding a separate set of definitions would not increase readability.
On 08-09-20, 08:33, Pierre-Louis Bossart wrote: > Thanks for the review Vinod, > > > This is good, thanks for adding it in changelog. Can you also add this > > description to Documentation (that can come as an individual patch), > > ok > > > > +/* > > > + * v1.2 device - SDCA address mapping > > > + * > > > + * Spec definition > > > + * Bits Contents > > > + * 31 0 (required by addressing range) > > > + * 30:26 0b10000 (Control Prefix) > > > > So this is for 30:26 > > I don't get the comment, sorry. I should have added see below. > > > > > + * 25 0 (Reserved) > > > + * 24:22 Function Number [2:0] > > > + * 21 Entity[6] > > > + * 20:19 Control Selector[5:4] > > > + * 18 0 (Reserved) > > > + * 17:15 Control Number[5:3] > > > + * 14 Next > > > + * 13 MBQ > > > + * 12:7 Entity[5:0] > > > + * 6:3 Control Selector[3:0] > > > + * 2:0 Control Number[2:0] > > > + */ > > > + > > > +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ > > > + (BIT(30) | \ > > > > Programmatically this is fine, but then since we are defining for the > > description above, IMO it would actually make sense for this to be defined > > as FIELD_PREP: > > > > FIELD_PREP(GENMASK(30, 26), 1) > > > > or better > > > > u32_encode_bits(GENMASK(30, 26), 1) > > > > > + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ > > > > Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and > > below? > > Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and > your other patches for bitfield access only use FIELD_PREP/FIELD_GET. yes and looking at this, I feel u32_encode_bits(GENMASK(24, 22), (fun)) would look better than FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) Do you agree? > > I really don't care about which macro is used but it wouldn't hurt to have > some level of consistency between different parts of the code? Why not use > FIELD_PREP/GET everywhere? > > > > + FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) | \ > > > + FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | \ > > > + FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | \ > > > + FIELD_PREP(GENMASK(12, 7), FIELD_GET(GENMASK(5, 0), (ent))) | \ > > > + FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | \ > > > + FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) > > > > Also, can we rather have a nice function for this, that would look much > > cleaner > > I am not sure what would be cleaner but fine. Ok > > And while at it, consider defining masks for various fields rather than > > using numbers in GENMASK() above, that would look better, be more > > readable and people can reuse it. > > Actually on this one I disagree. These fields are not intended to be used by > anyone, the goal is precisely to hide them behind regmap, and the use of raw > numbers makes it easier to cross-check the documentation and the code. > Adding a separate set of definitions would not increase readability. Which one would you prefer: #define SDCA_FUN_MASK GENMASK(24, 22) foo |= u32_encode_bits(SDCA_FUN_MASK, fun) Or the one proposed...?
>>>> + * 25 0 (Reserved) >>>> + * 24:22 Function Number [2:0] >>>> + * 21 Entity[6] >>>> + * 20:19 Control Selector[5:4] >>>> + * 18 0 (Reserved) >>>> + * 17:15 Control Number[5:3] >>>> + * 14 Next >>>> + * 13 MBQ >>>> + * 12:7 Entity[5:0] >>>> + * 6:3 Control Selector[3:0] >>>> + * 2:0 Control Number[2:0] >>>> + */ >>>> + >>>> +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ >>>> + (BIT(30) | \ >>> >>> Programmatically this is fine, but then since we are defining for the >>> description above, IMO it would actually make sense for this to be defined >>> as FIELD_PREP: >>> >>> FIELD_PREP(GENMASK(30, 26), 1) >>> >>> or better >>> >>> u32_encode_bits(GENMASK(30, 26), 1) >>> >>>> + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ >>> >>> Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and >>> below? >> >> Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and >> your other patches for bitfield access only use FIELD_PREP/FIELD_GET. > > yes and looking at this, I feel u32_encode_bits(GENMASK(24, 22), (fun)) > would look better than FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) > > Do you agree? The Function (fun) case is the easy one: the value is not split in two. But look at the entity case, it's split in two: FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) FIELD_PREP(GENMASK(12, 7), FIELD_GET(GENMASK(5, 0), (ent))) same for control FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | and same for channel number FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) I don't see how we can avoid using the FIELD_GET to extract the relevant bits from entity, control, channel number values. Or I am missing your point completely. >>> And while at it, consider defining masks for various fields rather than >>> using numbers in GENMASK() above, that would look better, be more >>> readable and people can reuse it. >> >> Actually on this one I disagree. These fields are not intended to be used by >> anyone, the goal is precisely to hide them behind regmap, and the use of raw >> numbers makes it easier to cross-check the documentation and the code. >> Adding a separate set of definitions would not increase readability. > > Which one would you prefer: > > #define SDCA_FUN_MASK GENMASK(24, 22) > > foo |= u32_encode_bits(SDCA_FUN_MASK, fun) > > Or the one proposed...? Same as above, let's see what this does with the control case where we'd need to have four definitions: #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) And the code would look like foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK1, FIELD_GET(SDCA_CONTROL_ORIG_MASK1, fun)); foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK2, FIELD_GET(SDCA_CONTROL_ORIG_MASK2, fun)); The original suggestion was: FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | I prefer the original... Adding these defines doesn't really add value because a) the values will not be reused anywhere else. b) we need 12 of those defines b) we need a prefix for those defines which makes the code heavier
On 09-09-20, 08:48, Pierre-Louis Bossart wrote: > > > > > > + * 25 0 (Reserved) > > > > > + * 24:22 Function Number [2:0] > > > > > + * 21 Entity[6] > > > > > + * 20:19 Control Selector[5:4] > > > > > + * 18 0 (Reserved) > > > > > + * 17:15 Control Number[5:3] > > > > > + * 14 Next > > > > > + * 13 MBQ > > > > > + * 12:7 Entity[5:0] > > > > > + * 6:3 Control Selector[3:0] > > > > > + * 2:0 Control Number[2:0] > > > > > + */ > > > > > + > > > > > +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ > > > > > + (BIT(30) | \ > > > > > > > > Programmatically this is fine, but then since we are defining for the > > > > description above, IMO it would actually make sense for this to be defined > > > > as FIELD_PREP: > > > > > > > > FIELD_PREP(GENMASK(30, 26), 1) > > > > > > > > or better > > > > > > > > u32_encode_bits(GENMASK(30, 26), 1) > > > > > > > > > + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ > > > > > > > > Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and > > > > below? > > > > > > Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and > > > your other patches for bitfield access only use FIELD_PREP/FIELD_GET. > > > > yes and looking at this, I feel u32_encode_bits(GENMASK(24, 22), (fun)) > > would look better than FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) > > > > Do you agree? > > The Function (fun) case is the easy one: the value is not split in two. > > But look at the entity case, it's split in two: > > FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) FIELD_PREP(GENMASK(12, 7), > FIELD_GET(GENMASK(5, 0), (ent))) > > same for control > > FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | > FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | > > and same for channel number > > FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | > FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) > > I don't see how we can avoid using the FIELD_GET to extract the relevant > bits from entity, control, channel number values. No, you dont need FIELD_GET, that would be pointless for this helper if that was the case > > Or I am missing your point completely. Correct It should be: foo |= u32_encode_bits(val, FOO_MASK_A); which would write val into bits represented by FOO_MASK_A by appropriately shifting val and masking it with FOO_MASK_A So net result is bits in FOO_MASK_A are modified with val, rest of the bits are not touched > > > > > > And while at it, consider defining masks for various fields rather than > > > > using numbers in GENMASK() above, that would look better, be more > > > > readable and people can reuse it. > > > > > > Actually on this one I disagree. These fields are not intended to be used by > > > anyone, the goal is precisely to hide them behind regmap, and the use of raw > > > numbers makes it easier to cross-check the documentation and the code. > > > Adding a separate set of definitions would not increase readability. > > > > Which one would you prefer: > > > > #define SDCA_FUN_MASK GENMASK(24, 22) > > > > foo |= u32_encode_bits(SDCA_FUN_MASK, fun) > > > > Or the one proposed...? > > Same as above, let's see what this does with the control case where we'd > need to have four definitions: > > #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) > #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) > #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) > #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) > > And the code would look like > > foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK1, > FIELD_GET(SDCA_CONTROL_ORIG_MASK1, fun)); > foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK2, > FIELD_GET(SDCA_CONTROL_ORIG_MASK2, fun)); > > The original suggestion was: > > FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | > FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | > > I prefer the original... Adding these defines doesn't really add value > because > a) the values will not be reused anywhere else. > b) we need 12 of those defines > b) we need a prefix for those defines which makes the code heavier
On 9/10/20 1:22 AM, Vinod Koul wrote: > On 09-09-20, 08:48, Pierre-Louis Bossart wrote: >> >>>>>> + * 25 0 (Reserved) >>>>>> + * 24:22 Function Number [2:0] >>>>>> + * 21 Entity[6] >>>>>> + * 20:19 Control Selector[5:4] >>>>>> + * 18 0 (Reserved) >>>>>> + * 17:15 Control Number[5:3] >>>>>> + * 14 Next >>>>>> + * 13 MBQ >>>>>> + * 12:7 Entity[5:0] >>>>>> + * 6:3 Control Selector[3:0] >>>>>> + * 2:0 Control Number[2:0] >>>>>> + */ >>>>>> + >>>>>> +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ >>>>>> + (BIT(30) | \ >>>>> >>>>> Programmatically this is fine, but then since we are defining for the >>>>> description above, IMO it would actually make sense for this to be defined >>>>> as FIELD_PREP: >>>>> >>>>> FIELD_PREP(GENMASK(30, 26), 1) >>>>> >>>>> or better >>>>> >>>>> u32_encode_bits(GENMASK(30, 26), 1) >>>>> >>>>>> + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ >>>>> >>>>> Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and >>>>> below? >>>> >>>> Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and >>>> your other patches for bitfield access only use FIELD_PREP/FIELD_GET. >>> >>> yes and looking at this, I feel u32_encode_bits(GENMASK(24, 22), (fun)) >>> would look better than FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) >>> >>> Do you agree? >> >> The Function (fun) case is the easy one: the value is not split in two. >> >> But look at the entity case, it's split in two: >> >> FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) FIELD_PREP(GENMASK(12, 7), >> FIELD_GET(GENMASK(5, 0), (ent))) >> >> same for control >> >> FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | >> FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | >> >> and same for channel number >> >> FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | >> FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) >> >> I don't see how we can avoid using the FIELD_GET to extract the relevant >> bits from entity, control, channel number values. > > No, you dont need FIELD_GET, that would be pointless for this helper if > that was the case I don't get how one would specify which parts of the original value are extracted? > >> >> Or I am missing your point completely. > > Correct > > It should be: > > foo |= u32_encode_bits(val, FOO_MASK_A); > > which would write val into bits represented by FOO_MASK_A by > appropriately shifting val and masking it with FOO_MASK_A > > So net result is bits in FOO_MASK_A are modified with val, rest of the > bits are not touched Vinod, please see the explanation below [1], we need to split the original value in two and insert the bits in two separate locations. You only considered the simple case for the functions, your proposal will not work for entities, controls and channel numbers. >> >> >>>>> And while at it, consider defining masks for various fields rather than >>>>> using numbers in GENMASK() above, that would look better, be more >>>>> readable and people can reuse it. >>>> >>>> Actually on this one I disagree. These fields are not intended to be used by >>>> anyone, the goal is precisely to hide them behind regmap, and the use of raw >>>> numbers makes it easier to cross-check the documentation and the code. >>>> Adding a separate set of definitions would not increase readability. >>> >>> Which one would you prefer: >>> >>> #define SDCA_FUN_MASK GENMASK(24, 22) >>> >>> foo |= u32_encode_bits(SDCA_FUN_MASK, fun) >>> >>> Or the one proposed...? >> >> Same as above, let's see what this does with the control case where we'd >> need to have four definitions: [1] >> >> #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) >> #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) >> #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) >> #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) >> >> And the code would look like >> >> foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK1, >> FIELD_GET(SDCA_CONTROL_ORIG_MASK1, fun)); >> foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK2, >> FIELD_GET(SDCA_CONTROL_ORIG_MASK2, fun)); >> >> The original suggestion was: >> >> FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | >> FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | >> >> I prefer the original... Adding these defines doesn't really add value >> because >> a) the values will not be reused anywhere else. >> b) we need 12 of those defines >> b) we need a prefix for those defines which makes the code heavier >
On 10-09-20, 08:53, Pierre-Louis Bossart wrote: > > > On 9/10/20 1:22 AM, Vinod Koul wrote: > > On 09-09-20, 08:48, Pierre-Louis Bossart wrote: > > > > > > > > > > + * 25 0 (Reserved) > > > > > > > + * 24:22 Function Number [2:0] > > > > > > > + * 21 Entity[6] > > > > > > > + * 20:19 Control Selector[5:4] > > > > > > > + * 18 0 (Reserved) > > > > > > > + * 17:15 Control Number[5:3] > > > > > > > + * 14 Next > > > > > > > + * 13 MBQ > > > > > > > + * 12:7 Entity[5:0] > > > > > > > + * 6:3 Control Selector[3:0] > > > > > > > + * 2:0 Control Number[2:0] > > > > > > > + */ > > > > > > > + > > > > > > > +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ > > > > > > > + (BIT(30) | \ > > > > > > > > > > > > Programmatically this is fine, but then since we are defining for the > > > > > > description above, IMO it would actually make sense for this to be defined > > > > > > as FIELD_PREP: > > > > > > > > > > > > FIELD_PREP(GENMASK(30, 26), 1) > > > > > > > > > > > > or better > > > > > > > > > > > > u32_encode_bits(GENMASK(30, 26), 1) > > > > > > > > > > > > > + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ > > > > > > > > > > > > Why not use u32_encode_bits(GENMASK(24, 22), (fun)) instead for this and > > > > > > below? > > > > > > > > > > Because your comment for the v1 review was to use FIELD_PREP/FIELD_GET, and > > > > > your other patches for bitfield access only use FIELD_PREP/FIELD_GET. > > > > > > > > yes and looking at this, I feel u32_encode_bits(GENMASK(24, 22), (fun)) > > > > would look better than FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) > > > > > > > > Do you agree? > > > > > > The Function (fun) case is the easy one: the value is not split in two. > > > > > > But look at the entity case, it's split in two: > > > > > > FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) FIELD_PREP(GENMASK(12, 7), > > > FIELD_GET(GENMASK(5, 0), (ent))) > > > > > > same for control > > > > > > FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | > > > FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | > > > > > > and same for channel number > > > > > > FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | > > > FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) > > > > > > I don't see how we can avoid using the FIELD_GET to extract the relevant > > > bits from entity, control, channel number values. > > > > No, you dont need FIELD_GET, that would be pointless for this helper if > > that was the case > > I don't get how one would specify which parts of the original value are > extracted? > > > > > > > > > Or I am missing your point completely. > > > > Correct > > > > It should be: > > > > foo |= u32_encode_bits(val, FOO_MASK_A); > > > > which would write val into bits represented by FOO_MASK_A by > > appropriately shifting val and masking it with FOO_MASK_A > > > > So net result is bits in FOO_MASK_A are modified with val, rest of the > > bits are not touched > > Vinod, please see the explanation below [1], we need to split the original > value in two and insert the bits in two separate locations. > > You only considered the simple case for the functions, your proposal will > not work for entities, controls and channel numbers. > > > > > > > > > > > > > And while at it, consider defining masks for various fields rather than > > > > > > using numbers in GENMASK() above, that would look better, be more > > > > > > readable and people can reuse it. > > > > > > > > > > Actually on this one I disagree. These fields are not intended to be used by > > > > > anyone, the goal is precisely to hide them behind regmap, and the use of raw > > > > > numbers makes it easier to cross-check the documentation and the code. > > > > > Adding a separate set of definitions would not increase readability. > > > > > > > > Which one would you prefer: > > > > > > > > #define SDCA_FUN_MASK GENMASK(24, 22) > > > > > > > > foo |= u32_encode_bits(SDCA_FUN_MASK, fun) > > > > > > > > Or the one proposed...? > > > > > > Same as above, let's see what this does with the control case where we'd > > > need to have four definitions: > > [1] > > > > > > > #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) > > > #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) > > > #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) > > > #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) I think I missed ORIG and DEST stuff, what does this mean here? Relooking at the bit definition, for example 'Control Number' is defined in both 17:15 as well as 2:0, why is that. Is it split? How does one program a control number into this? > > > > > > And the code would look like > > > > > > foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK1, > > > FIELD_GET(SDCA_CONTROL_ORIG_MASK1, fun)); > > > foo |= u32_encode_bits(SDCA_CONTROL_DEST_MASK2, > > > FIELD_GET(SDCA_CONTROL_ORIG_MASK2, fun)); > > > > > > The original suggestion was: > > > > > > FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | > > > FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | > > > > > > I prefer the original... Adding these defines doesn't really add value > > > because > > > a) the values will not be reused anywhere else. > > > b) we need 12 of those defines > > > b) we need a prefix for those defines which makes the code heavier > >
Hi Vinod, >>>>>>>> + * 25 0 (Reserved) >>>>>>>> + * 24:22 Function Number [2:0] >>>>>>>> + * 21 Entity[6] >>>>>>>> + * 20:19 Control Selector[5:4] >>>>>>>> + * 18 0 (Reserved) >>>>>>>> + * 17:15 Control Number[5:3] >>>>>>>> + * 14 Next >>>>>>>> + * 13 MBQ >>>>>>>> + * 12:7 Entity[5:0] >>>>>>>> + * 6:3 Control Selector[3:0] >>>>>>>> + * 2:0 Control Number[2:0] [...] >>>> >>>> #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) >>>> #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) >>>> #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) >>>> #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) > > I think I missed ORIG and DEST stuff, what does this mean here? If you missed this, it means my explanations are not good enough and I need to make it clearer in the commit log/documentation. Point taken, I'll improve this for the next version. > Relooking at the bit definition, for example 'Control Number' is defined > in both 17:15 as well as 2:0, why is that. Is it split? > > How does one program a control number into this? A Control Number is represented on 6 bits. See the documentation above. 17:15 Control Selector[5:3] 2:0 Control Selector[2:0] The 3 MSBs for into bits 17:15 of the address, and the 3 LSBs into bits 2:0 of the address. The second part is simpler for Control Number but for entities and control selectors the LSB positions don't match. Yes it's convoluted but it was well-intended: in most cases, there is a limited number of entities, control selectors, channel numbers, and putting the LSBs together in the 16-LSB of the address helps avoid reprogramming paging registers: all the addresses for a given function typically map into the same page. That said, I am not sure the optimization is that great in the end, because we end-up having to play with bits for each address. Fewer changes of the paging registers but tons of operations in the core. I wasn't around when this mapping was defined, and it is what is is now. There's hardware built based on this formula so we have to make it work. Does this clarify the usage? If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all ears. At the end of the day, the mapping is pre-defined and we don't have any degree of freedom. What I do want is that this macro/inline function is shared by all codec drivers so that we don't have different interpretations of how the address is constructed. Thanks, -Pierre
Hi Pierre, On 11-09-20, 09:50, Pierre-Louis Bossart wrote: > > > > > > > > > + * 25 0 (Reserved) > > > > > > > > > + * 24:22 Function Number [2:0] > > > > > > > > > + * 21 Entity[6] > > > > > > > > > + * 20:19 Control Selector[5:4] > > > > > > > > > + * 18 0 (Reserved) > > > > > > > > > + * 17:15 Control Number[5:3] > > > > > > > > > + * 14 Next > > > > > > > > > + * 13 MBQ > > > > > > > > > + * 12:7 Entity[5:0] > > > > > > > > > + * 6:3 Control Selector[3:0] > > > > > > > > > + * 2:0 Control Number[2:0] > > [...] > > > > > > > > > > > #define SDCA_CONTROL_DEST_MASK1 GENMASK(20, 19) > > > > > #define SDCA_CONTROL_ORIG_MASK1 GENMASK(5, 4) > > > > > #define SDCA_CONTROL_DEST_MASK2 GENMASK(6, 3) > > > > > #define SDCA_CONTROL_ORIG_MASK2 GENMASK(3, 0) > > > > I think I missed ORIG and DEST stuff, what does this mean here? > > If you missed this, it means my explanations are not good enough and I need > to make it clearer in the commit log/documentation. Point taken, I'll > improve this for the next version. > > > Relooking at the bit definition, for example 'Control Number' is defined > > in both 17:15 as well as 2:0, why is that. Is it split? > > > > How does one program a control number into this? > > A Control Number is represented on 6 bits. > > See the documentation above. > > 17:15 Control Selector[5:3] > 2:0 Control Selector[2:0] > > The 3 MSBs for into bits 17:15 of the address, and the 3 LSBs into bits 2:0 > of the address. The second part is simpler for Control Number but for > entities and control selectors the LSB positions don't match. > > Yes it's convoluted but it was well-intended: in most cases, there is a > limited number of entities, control selectors, channel numbers, and putting > the LSBs together in the 16-LSB of the address helps avoid reprogramming > paging registers: all the addresses for a given function typically map into > the same page. > > That said, I am not sure the optimization is that great in the end, because > we end-up having to play with bits for each address. Fewer changes of the > paging registers but tons of operations in the core. > > I wasn't around when this mapping was defined, and it is what is is now. > There's hardware built based on this formula so we have to make it work. > > Does this clarify the usage? Thanks, that is very helpful. I have overlooked this bit. For LSB bits, I dont think this is an issue. I expect it to work, for example: #define CONTROL_LSB_MASK GENMASK(2, 0) foo |= u32_encode_bits(control, CONTROL_LSB_MASK); would mask the control value and program that in specific bitfeild. But for MSB bits, I am not sure above will work so, you may need to extract the bits and then use, for example: #define CONTROL_MSB_BITS GENMASK(5, 3) #define CONTROL_MSB_MASK GENMASK(17, 15) control = FIELD_GET(CONTROL_MSB_BITS, control); foo |= u32_encode_bits(control, CONTROL_MSB_MASK); > If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all > ears. At the end of the day, the mapping is pre-defined and we don't have > any degree of freedom. What I do want is that this macro/inline function is > shared by all codec drivers so that we don't have different interpretations > of how the address is constructed. Absolutely, this need to be defined here and used by everyone else.
> For LSB bits, I dont think this is an issue. I expect it to work, for example: > #define CONTROL_LSB_MASK GENMASK(2, 0) > foo |= u32_encode_bits(control, CONTROL_LSB_MASK); > > would mask the control value and program that in specific bitfeild. > > But for MSB bits, I am not sure above will work so, you may need to extract > the bits and then use, for example: > #define CONTROL_MSB_BITS GENMASK(5, 3) > #define CONTROL_MSB_MASK GENMASK(17, 15) > > control = FIELD_GET(CONTROL_MSB_BITS, control); > foo |= u32_encode_bits(control, CONTROL_MSB_MASK); > >> If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all >> ears. At the end of the day, the mapping is pre-defined and we don't have >> any degree of freedom. What I do want is that this macro/inline function is >> shared by all codec drivers so that we don't have different interpretations >> of how the address is constructed. > > Absolutely, this need to be defined here and used by everyone else. Compare: #define SDCA_CONTROL_MSB_BITS GENMASK(5, 3) #define SDCA_CONTROL_MSB_MASK GENMASK(17, 15) #define SDCA_CONTROL_LSB_MASK GENMASK(2, 0) foo |= u32_encode_bits(control, SDCA_CONTROL_LSB_MASK); control = FIELD_GET(SDCA_CONTROL_MSB_BITS, control); foo |= u32_encode_bits(control, SDCA_CONTROL_MSB_MASK); with the original proposal: foo |= FIELD_GET(GENMASK(2, 0), control)) foo |= FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), control)) it gets worse when the LSB positions don't match, you need another variable and an additional mask. I don't see how this improves readability? I get that hard-coding magic numbers is a bad thing in general, but in this case there are limited benefits to the use of additional defines.
On 14-09-20, 09:44, Pierre-Louis Bossart wrote: > > For LSB bits, I dont think this is an issue. I expect it to work, for example: > > #define CONTROL_LSB_MASK GENMASK(2, 0) > > foo |= u32_encode_bits(control, CONTROL_LSB_MASK); > > > > would mask the control value and program that in specific bitfeild. > > > > But for MSB bits, I am not sure above will work so, you may need to extract > > the bits and then use, for example: > > #define CONTROL_MSB_BITS GENMASK(5, 3) > > #define CONTROL_MSB_MASK GENMASK(17, 15) > > > > control = FIELD_GET(CONTROL_MSB_BITS, control); > > foo |= u32_encode_bits(control, CONTROL_MSB_MASK); > > > > > If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all > > > ears. At the end of the day, the mapping is pre-defined and we don't have > > > any degree of freedom. What I do want is that this macro/inline function is > > > shared by all codec drivers so that we don't have different interpretations > > > of how the address is constructed. > > > > Absolutely, this need to be defined here and used by everyone else. > > Compare: > > #define SDCA_CONTROL_MSB_BITS GENMASK(5, 3) > #define SDCA_CONTROL_MSB_MASK GENMASK(17, 15) > #define SDCA_CONTROL_LSB_MASK GENMASK(2, 0) > > foo |= u32_encode_bits(control, SDCA_CONTROL_LSB_MASK); > control = FIELD_GET(SDCA_CONTROL_MSB_BITS, control); > foo |= u32_encode_bits(control, SDCA_CONTROL_MSB_MASK); > > with the original proposal: > > foo |= FIELD_GET(GENMASK(2, 0), control)) > foo |= FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), control)) > > it gets worse when the LSB positions don't match, you need another variable > and an additional mask. > > I don't see how this improves readability? I get that hard-coding magic > numbers is a bad thing in general, but in this case there are limited > benefits to the use of additional defines. I think it would be prudent to define the masks and use them rather than magic values. Also it makes it future proof Thanks
On 9/16/20 7:35 AM, Vinod Koul wrote: > On 14-09-20, 09:44, Pierre-Louis Bossart wrote: >>> For LSB bits, I dont think this is an issue. I expect it to work, for example: >>> #define CONTROL_LSB_MASK GENMASK(2, 0) >>> foo |= u32_encode_bits(control, CONTROL_LSB_MASK); >>> >>> would mask the control value and program that in specific bitfeild. >>> >>> But for MSB bits, I am not sure above will work so, you may need to extract >>> the bits and then use, for example: >>> #define CONTROL_MSB_BITS GENMASK(5, 3) >>> #define CONTROL_MSB_MASK GENMASK(17, 15) >>> >>> control = FIELD_GET(CONTROL_MSB_BITS, control); >>> foo |= u32_encode_bits(control, CONTROL_MSB_MASK); >>> >>>> If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all >>>> ears. At the end of the day, the mapping is pre-defined and we don't have >>>> any degree of freedom. What I do want is that this macro/inline function is >>>> shared by all codec drivers so that we don't have different interpretations >>>> of how the address is constructed. >>> >>> Absolutely, this need to be defined here and used by everyone else. >> >> Compare: >> >> #define SDCA_CONTROL_MSB_BITS GENMASK(5, 3) >> #define SDCA_CONTROL_MSB_MASK GENMASK(17, 15) >> #define SDCA_CONTROL_LSB_MASK GENMASK(2, 0) >> >> foo |= u32_encode_bits(control, SDCA_CONTROL_LSB_MASK); >> control = FIELD_GET(SDCA_CONTROL_MSB_BITS, control); >> foo |= u32_encode_bits(control, SDCA_CONTROL_MSB_MASK); >> >> with the original proposal: >> >> foo |= FIELD_GET(GENMASK(2, 0), control)) >> foo |= FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), control)) >> >> it gets worse when the LSB positions don't match, you need another variable >> and an additional mask. >> >> I don't see how this improves readability? I get that hard-coding magic >> numbers is a bad thing in general, but in this case there are limited >> benefits to the use of additional defines. > > I think it would be prudent to define the masks and use them rather than > magic values. Also it makes it future proof I don't see your point at all. The values cannot be modified, a different macro would be needed for a standard change. Anyways, I am not going to argue further, I'll use your code example as is and move on.
diff --git a/include/linux/soundwire/sdw_registers.h b/include/linux/soundwire/sdw_registers.h index 5d3c271af7d1..99ff7afc27a2 100644 --- a/include/linux/soundwire/sdw_registers.h +++ b/include/linux/soundwire/sdw_registers.h @@ -305,4 +305,37 @@ #define SDW_CASC_PORT_MASK_INTSTAT3 1 #define SDW_CASC_PORT_REG_OFFSET_INTSTAT3 2 +/* + * v1.2 device - SDCA address mapping + * + * Spec definition + * Bits Contents + * 31 0 (required by addressing range) + * 30:26 0b10000 (Control Prefix) + * 25 0 (Reserved) + * 24:22 Function Number [2:0] + * 21 Entity[6] + * 20:19 Control Selector[5:4] + * 18 0 (Reserved) + * 17:15 Control Number[5:3] + * 14 Next + * 13 MBQ + * 12:7 Entity[5:0] + * 6:3 Control Selector[3:0] + * 2:0 Control Number[2:0] + */ + +#define SDW_SDCA_CTL(fun, ent, ctl, ch) \ + (BIT(30) | \ + FIELD_PREP(GENMASK(24, 22), FIELD_GET(GENMASK(2, 0), (fun))) | \ + FIELD_PREP(BIT(21), FIELD_GET(BIT(6), (ent))) | \ + FIELD_PREP(GENMASK(20, 19), FIELD_GET(GENMASK(5, 4), (ctl))) | \ + FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), (ch))) | \ + FIELD_PREP(GENMASK(12, 7), FIELD_GET(GENMASK(5, 0), (ent))) | \ + FIELD_PREP(GENMASK(6, 3), FIELD_GET(GENMASK(3, 0), (ctl))) | \ + FIELD_PREP(GENMASK(2, 0), FIELD_GET(GENMASK(2, 0), (ch)))) + +#define SDW_SDCA_MBQ_CTL(reg) ((reg) | BIT(13)) +#define SDW_SDCA_NEXT_CTL(reg) ((reg) | BIT(14)) + #endif /* __SDW_REGISTERS_H */