regmap: Add Parity bit Calculation to regmaps
Subsystems (2)
cover regmap: Add Parity bit Calculation to regmaps
From: Christopher Tyerman <[email protected]>
this patch set adds parity bit calculation to regmaps
this allow support for devices that require parity bits in their communications.
e.g. the texas instruments TPS92518-Q1 which requires a parity bit in the 7th bit of a 16 bit spi frame
or the TPS92518-Q1 which requires a parity bit in the 1st bit of a 16 bit spi frame
parity aimed to work devices where parity in reg block e.g. TPS65311-Q1 and TPS92518-Q1
TPS65311-Q1 frame format [PWRRRRRRDDDDDDDD]
TPS92518-Q1 frame format [WRRRRRPDDDDDDDDD]
P - parity bit, W - Read/Write bit, R - register, D -register data
TPS65311-Q1 parity mask 0x8000 (1000000000000000)
TPS92518-Q1 parity mask 0x0200 (0000001000000000)
calculates parity bit based up parity function defined by regmap_config->parity_calc
regmap_config->parity_calc defaults to regmap_parity_calc_even()
adds alternate parity function regmap_parity_calc_odd()
calculates parity bit for writes if regmap_config->parity_write_mask is > 0 calculates parity bit for reads if regmap_config->parity_read_mask is > 0
parity is not calculated when bus implements reg_update_bits()
Altered the regmap_format_X_X_write functions to account for padding bits allowing masks to write to either end of register address for formatted writes
Altered formatted_write to apply write and parity masks
Added parsers for 9 bit data format which are written by formatted write
Christopher Tyerman (5):
Add Parity bit Calculation to regmaps
Altered regmap_X_X_write functions to account for padding bits Added setting of writemap to formatted write
Add Parity Calculation to formatted write
Add parser for X_9 formats
drivers/base/regmap/internal.h | 6 + drivers/base/regmap/regmap.c | 250 +++++++++++++++++++++++++++++++-- include/linux/regmap.h | 32 +++++ 3 files changed, 280 insertions(+), 8 deletions(-)
base-commit: 02d6fdecb9c38de19065f6bed8d5214556fd061d
Signature · 1 line
2.25.1
RFC PATCH 1/5 regmap: Add Parity bit Calculation to regmaps
From: Christopher Tyerman <[email protected]>
regmap.h
Added parity_read_mask to regmap_config
Added parity_write_mask to regmap_config
Added (*parity_calc)() to regmap_config
Added regmap_parity_calc_even() Added regmap_parity_calc_odd()
internal.h
Added parity_read_mask to regmap
Added parity_write_mask to regmap
Added (*parity_calc) to regmap
regmap.c
Altered _regmap_raw_write_impl() to calculate parity Altered _regmap_raw_read() to calculate parity Added regmap_set_work_buf_parity_mask() Added regmap_parity_calc_even()
Added regmap_parity_calc_odd()
Added parity_even()
Added parity16_even(u16 v)
Added parity32_even(u32 v)
Added parity64_even(u64 v)
--- drivers/base/regmap/internal.h | 6 ++ drivers/base/regmap/regmap.c | 168 ++++++++++++++++++++++++++++++++- include/linux/regmap.h | 32 +++++++ 3 files changed, 204 insertions(+), 2 deletions(-)
drivers/base/regmap/internal.h +6 -0
@@ -168,6 +168,12 @@ struct regmap {/* if set, the regmap core can sleep */ bool can_sleep; + +unsigned long parity_write_mask; +unsigned long parity_read_mask; + +bool (*parity_calc)(unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len); };struct regcache_ops {
drivers/base/regmap/regmap.c +166 -2
207 lines not on this page · raw message
include/linux/regmap.h +32 -0
@@ -354,6 +354,10 @@ typedef void (*regmap_unlock)(void *);* @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE, * HWLOCK_IRQ or 0. * @can_sleep: Optional, specifies whether regmap operations can sleep. +* +* @parity_read_mask: bit mask of location of parity bit for reads +* @parity_write_mask: bit mask of location of parity bit for writes +* @parity_calc: Optional callback to calculate parity, defaults to even parity */ struct regmap_config {const char *name;
@@ -416,6 +420,12 @@ struct regmap_config {unsigned int hwlock_mode;bool can_sleep; + +unsigned long parity_read_mask; +unsigned long parity_write_mask; +bool (*parity_calc)(unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len); + };/**
@@ -1237,6 +1247,11 @@ static inline int regmap_clear_bits(struct regmap *map,int regmap_test_bits (struct regmap *map,unsigned int reg,unsigned int bits); +bool regmap_parity_calc_even (unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len); +bool regmap_parity_calc_odd (unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len); +/** * struct reg_field - Description of an register field *
@@ -1866,6 +1881,23 @@ static inline struct device *regmap_get_device(struct regmap *map)return NULL ; } +static inline bool regmap_parity_calc_even (unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return NULL ; +} + +static inline bool regmap_parity_calc_odd (unsigned long rwmask,unsigned int reg, +const void *val,size_t val_len) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return NULL ; +} + +#endif + +#endif
Signature · 1 line
2.25.1
Mark Brown
maintainerQuoted 16 lines · On Fri, Dec 17, 2021 at 10:41:00PM +0000, [email protected] wrote:
From: Christopher Tyerman <[email protected]>
regmap.hAdded
parity_read_masktoregmap_config
Addedparity_write_masktoregmap_config
Added (*parity_calc)() toregmap_configAdded
regmap_parity_calc_even()Addedregmap_parity_calc_odd()
internal.hAdded
parity_read_maskto regmap
Addedparity_write_maskto regmap
Added (*parity_calc) to regmap
Quoted 10 lines
regmap.c
Altered_regmap_raw_write_impl()to calculate parity Altered_regmap_raw_read()to calculate parity Addedregmap_set_work_buf_parity_mask()Addedregmap_parity_calc_even()
Addedregmap_parity_calc_odd()
Addedparity_even()
Addedparity16_even(u16 v)
Addedparity32_even(u32 v)
Addedparity64_even(u64 v)
This isn't a good changelog, the changelog needs to describe what is being changed in the code and why in a way that provides information to the human reader. Instead this is essentially a list of code level changes in the diff. There's some advice on changelogs in submitting-patches.rst. Without a clear changelog it's hard to review things as it's not clear what the goals are.
RFC PATCH 2/5 regmap: Altered regmap_X_X_write functions to account for padding bits
In reply to [email protected]From: Christopher Tyerman <[email protected]>
modified: drivers/base/regmap/regmap.c
--- drivers/base/regmap/regmap.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/base/regmap/regmap.c +16 -6
@@ -232,42 +232,52 @@ static void regmap_format_2_6_write(struct regmap *map, unsigned int reg, unsigned int val) {u8 *out = map->work_buf; +u8 shift = map->reg_shift; - *out = (reg <<6 ) | val; + *out = (reg << (6 + shift) | val); }static void regmap_format_4_12_write (struct regmap *map,unsigned int reg,unsigned int val) { +u8 shift = map->reg_shift;__be16 *out = map->work_buf; - *out =cpu_to_be16 ((reg <<12 ) | val); + + *out =cpu_to_be16 ((reg << (12 + shift)) | val); }static void regmap_format_7_9_write (struct regmap *map,unsigned int reg,unsigned int val) { +u8 shift = map->reg_shift;__be16 *out = map->work_buf; - *out =cpu_to_be16 ((reg <<9 ) | val); + + *out =cpu_to_be16 ((reg << (9 + shift)) | val); }static void regmap_format_7_17_write (struct regmap *map,unsigned int reg,unsigned int val) { +u8 shift = map->reg_shift;u8 *out = map->work_buf; out[2 ] = val; out[1 ] = val >>8 ; - out[0 ] = (val >>16 ) | (reg <<1 ); + out[0 ] = (val >>16 ) | (reg << (1 + shift)); }static void regmap_format_10_14_write (struct regmap *map,unsigned int reg,unsigned int val) { +u8 shift = map->reg_shift;u8 *out = map->work_buf; out[2 ] = val; - out[1 ] = (val >>8 ) | (reg <<6 ); - out[0 ] = reg >>2 ; + out[1 ] = (val >>8 ) | (reg << (6 + shift)); +if (shift <=2 ) + out[0 ] = reg >> (2 - shift); +else + out[0 ] = reg << shift; }static void regmap_format_8 (void *buf,unsigned int val,unsigned int shift)
Signature · 1 line
2.25.1
RFC PATCH 3/5 regmap: Added setting of writemap to formatted write
In reply to [email protected]From: Christopher Tyerman <[email protected]>
Added regmap_set_work_buf_flag_mask to _regmap_bus_formatted_write to ensure correct write bit value set when writemask defined
modified: drivers/base/regmap/regmap.c
--- drivers/base/regmap/regmap.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/base/regmap/regmap.c +3 -0
@@ -1964,6 +1964,9 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg, map->format.format_write (map, reg, val); +regmap_set_work_buf_flag_mask (map, map->format.reg_bytes, + map->write_flag_mask); +trace_regmap_hw_write_start (map, reg,1 ); ret = map->bus->write(map->bus_context, map->work_buf,
Signature · 1 line
2.25.1
RFC PATCH 4/5 regmap: Add Parity Calculation to formatted write
In reply to [email protected]From: Christopher Tyerman <[email protected]>
Altered formated write to set parity bit according to parity_write_mask
modified: drivers/base/regmap/regmap.c
--- drivers/base/regmap/regmap.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/base/regmap/regmap.c +4 -0
@@ -1967,6 +1967,10 @@ static int _regmap_bus_formatted_write(void *context, unsigned int reg,regmap_set_work_buf_flag_mask (map, map->format.reg_bytes, map->write_flag_mask); +regmap_set_work_buf_parity_mask (map, map->format.reg_bytes, + map->parity_write_mask, map->write_flag_mask, reg, + &val,sizeof (val)); +trace_regmap_hw_write_start (map, reg,1 ); ret = map->bus->write(map->bus_context, map->work_buf,
Signature · 1 line
2.25.1
RFC PATCH 5/5 regmap: Add parser for X_9 formats
In reply to [email protected]From: Christopher Tyerman <[email protected]>
added 9 bit Parser functions
these operate in same way as 16 bit parsers but mask out higher bits
regmap_parse_9_be()regmap_parse_9_be_inplace()regmap_parse_9_le()regmap_parse_9_le_inplace()regmap_parse_9_native()
modified: drivers/base/regmap/regmap.c
--- drivers/base/regmap/regmap.c | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
drivers/base/regmap/regmap.c +53 -0
@@ -365,6 +365,39 @@ static unsigned int regmap_parse_8(const void *buf)return b[0 ]; } +static unsigned int regmap_parse_9_be (const void *buf) +{ +return get_unaligned_be16 (buf) &0x1FF ; +} + +static unsigned int regmap_parse_9_le (const void *buf) +{ + +return get_unaligned_le16 (buf) &0x1FF ; +} + +static void regmap_parse_9_be_inplace (void *buf) +{ +u16 v =get_unaligned_be16 (buf) &0x1FF ; + +memcpy (buf, &v,sizeof (v)); +} + +static void regmap_parse_9_le_inplace (void *buf) +{ +u16 v =get_unaligned_le16 (buf) &0x1FF ; + +memcpy (buf, &v,sizeof (v)); +} + +static unsigned int regmap_parse_9_native (const void *buf) +{ +u16 v; + +memcpy (&v, buf,sizeof (v)); +return v &0x1FF ; +} +static unsigned int regmap_parse_16_be (const void *buf) {return get_unaligned_be16 (buf);
@@ -1047,6 +1080,26 @@ struct regmap *__regmap_init(struct device *dev, map->format.parse_val = regmap_parse_8; map->format.parse_inplace = regmap_parse_inplace_noop;break ; +case 9 : +switch (val_endian) { +case REGMAP_ENDIAN_BIG : +//map->format.format_val = regmap_format_9_be; + map->format.parse_val = regmap_parse_9_be; + map->format.parse_inplace = regmap_parse_9_be_inplace; +break ; +case REGMAP_ENDIAN_LITTLE : +//map->format.format_val = regmap_format_9_le; + map->format.parse_val = regmap_parse_9_le; + map->format.parse_inplace = regmap_parse_9_le_inplace; +break ; +case REGMAP_ENDIAN_NATIVE : +//map->format.format_val = regmap_format_9_native; + map->format.parse_val = regmap_parse_9_native; +break ; +default : + goto err_hwlock; + } +break ;case 16 :switch (val_endian) {case REGMAP_ENDIAN_BIG :
Signature · 1 line
2.25.1