Skip to content

Commit

Permalink
regmap: Use reg_sequence for multi_reg_write / register_patch
Browse files Browse the repository at this point in the history
Separate the functionality using sequences of register writes from the
functions that take register defaults. This change renames the arguments
in order to support the extension of reg_sequence to take an optional
delay to be applied after any given register in a sequence is written.
This avoids adding an int to all register defaults, which could
substantially increase memory usage for regmaps with large default tables.

This also updates all the clients of multi_reg_write/register_patch.

Signed-off-by: Nariman Poushin <nariman@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Nariman Poushin authored and Mark Brown committed Jul 16, 2015
1 parent d770e55 commit 8019ff6
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 51 deletions.
2 changes: 1 addition & 1 deletion drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct regmap {
/* if set, the HW registers are known to match map->reg_defaults */
bool no_sync_defaults;

struct reg_default *patch;
struct reg_sequence *patch;
int patch_regs;

/* if set, converts bulk rw to single rw */
Expand Down
22 changes: 11 additions & 11 deletions drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ EXPORT_SYMBOL_GPL(regmap_bulk_write);
* relative. The page register has been written if that was neccessary.
*/
static int _regmap_raw_multi_reg_write(struct regmap *map,
const struct reg_default *regs,
const struct reg_sequence *regs,
size_t num_regs)
{
int ret;
Expand Down Expand Up @@ -1800,12 +1800,12 @@ static unsigned int _regmap_register_page(struct regmap *map,
}

static int _regmap_range_multi_paged_reg_write(struct regmap *map,
struct reg_default *regs,
struct reg_sequence *regs,
size_t num_regs)
{
int ret;
int i, n;
struct reg_default *base;
struct reg_sequence *base;
unsigned int this_page = 0;
/*
* the set of registers are not neccessarily in order, but
Expand Down Expand Up @@ -1843,7 +1843,7 @@ static int _regmap_range_multi_paged_reg_write(struct regmap *map,
}

static int _regmap_multi_reg_write(struct regmap *map,
const struct reg_default *regs,
const struct reg_sequence *regs,
size_t num_regs)
{
int i;
Expand Down Expand Up @@ -1895,8 +1895,8 @@ static int _regmap_multi_reg_write(struct regmap *map,
struct regmap_range_node *range;
range = _regmap_range_lookup(map, reg);
if (range) {
size_t len = sizeof(struct reg_default)*num_regs;
struct reg_default *base = kmemdup(regs, len,
size_t len = sizeof(struct reg_sequence)*num_regs;
struct reg_sequence *base = kmemdup(regs, len,
GFP_KERNEL);
if (!base)
return -ENOMEM;
Expand Down Expand Up @@ -1929,7 +1929,7 @@ static int _regmap_multi_reg_write(struct regmap *map,
* A value of zero will be returned on success, a negative errno will be
* returned in error cases.
*/
int regmap_multi_reg_write(struct regmap *map, const struct reg_default *regs,
int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
int num_regs)
{
int ret;
Expand Down Expand Up @@ -1962,7 +1962,7 @@ EXPORT_SYMBOL_GPL(regmap_multi_reg_write);
* be returned in error cases.
*/
int regmap_multi_reg_write_bypassed(struct regmap *map,
const struct reg_default *regs,
const struct reg_sequence *regs,
int num_regs)
{
int ret;
Expand Down Expand Up @@ -2552,10 +2552,10 @@ EXPORT_SYMBOL_GPL(regmap_async_complete);
* The caller must ensure that this function cannot be called
* concurrently with either itself or regcache_sync().
*/
int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
int num_regs)
{
struct reg_default *p;
struct reg_sequence *p;
int ret;
bool bypass;

Expand All @@ -2564,7 +2564,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
return 0;

p = krealloc(map->patch,
sizeof(struct reg_default) * (map->patch_regs + num_regs),
sizeof(struct reg_sequence) * (map->patch_regs + num_regs),
GFP_KERNEL);
if (p) {
memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs));
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i2c/adv7511.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static struct adv7511 *encoder_to_adv7511(struct drm_encoder *encoder)
}

/* ADI recommended values for proper operation. */
static const struct reg_default adv7511_fixed_registers[] = {
static const struct reg_sequence adv7511_fixed_registers[] = {
{ 0x98, 0x03 },
{ 0x9a, 0xe0 },
{ 0x9c, 0x30 },
Expand Down
6 changes: 3 additions & 3 deletions drivers/input/misc/drv260x.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ static void drv260x_close(struct input_dev *input)
gpiod_set_value(haptics->enable_gpio, 0);
}

static const struct reg_default drv260x_lra_cal_regs[] = {
static const struct reg_sequence drv260x_lra_cal_regs[] = {
{ DRV260X_MODE, DRV260X_AUTO_CAL },
{ DRV260X_CTRL3, DRV260X_NG_THRESH_2 },
{ DRV260X_FEEDBACK_CTRL, DRV260X_FB_REG_LRA_MODE |
DRV260X_BRAKE_FACTOR_4X | DRV260X_LOOP_GAIN_HIGH },
};

static const struct reg_default drv260x_lra_init_regs[] = {
static const struct reg_sequence drv260x_lra_init_regs[] = {
{ DRV260X_MODE, DRV260X_RT_PLAYBACK },
{ DRV260X_A_TO_V_CTRL, DRV260X_AUDIO_HAPTICS_PEAK_20MS |
DRV260X_AUDIO_HAPTICS_FILTER_125HZ },
Expand All @@ -337,7 +337,7 @@ static const struct reg_default drv260x_lra_init_regs[] = {
{ DRV260X_CTRL4, DRV260X_AUTOCAL_TIME_500MS },
};

static const struct reg_default drv260x_erm_cal_regs[] = {
static const struct reg_sequence drv260x_erm_cal_regs[] = {
{ DRV260X_MODE, DRV260X_AUTO_CAL },
{ DRV260X_A_TO_V_MIN_INPUT, DRV260X_AUDIO_HAPTICS_MIN_IN_VOLT },
{ DRV260X_A_TO_V_MAX_INPUT, DRV260X_AUDIO_HAPTICS_MAX_IN_VOLT },
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/misc/drv2665.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void drv2665_close(struct input_dev *input)
"Failed to enter standby mode: %d\n", error);
}

static const struct reg_default drv2665_init_regs[] = {
static const struct reg_sequence drv2665_init_regs[] = {
{ DRV2665_CTRL_2, 0 | DRV2665_10_MS_IDLE_TOUT },
{ DRV2665_CTRL_1, DRV2665_25_VPP_GAIN },
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/input/misc/drv2667.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ static void drv2667_close(struct input_dev *input)
"Failed to enter standby mode: %d\n", error);
}

static const struct reg_default drv2667_init_regs[] = {
static const struct reg_sequence drv2667_init_regs[] = {
{ DRV2667_CTRL_2, 0 },
{ DRV2667_CTRL_1, DRV2667_25_VPP_GAIN },
{ DRV2667_WV_SEQ_0, 1 },
{ DRV2667_WV_SEQ_1, 0 }
};

static const struct reg_default drv2667_page1_init[] = {
static const struct reg_sequence drv2667_page1_init[] = {
{ DRV2667_RAM_HDR_SZ, 0x05 },
{ DRV2667_RAM_START_HI, 0x80 },
{ DRV2667_RAM_START_LO, 0x06 },
Expand Down
2 changes: 1 addition & 1 deletion drivers/mfd/arizona-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int wm5102_apply_hardware_patch(struct arizona *arizona)
* Register patch to some of the CODECs internal write sequences
* to ensure a clean exit from the low power sleep state.
*/
static const struct reg_default wm5110_sleep_patch[] = {
static const struct reg_sequence wm5110_sleep_patch[] = {
{ 0x337A, 0xC100 },
{ 0x337B, 0x0041 },
{ 0x3300, 0xA210 },
Expand Down
2 changes: 1 addition & 1 deletion drivers/mfd/twl6040.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static const struct reg_default twl6040_defaults[] = {
{ 0x2E, 0x00 }, /* REG_STATUS (ro) */
};

static struct reg_default twl6040_patch[] = {
static struct reg_sequence twl6040_patch[] = {
/*
* Select I2C bus access to dual access registers
* Interrupt register is cleared on read
Expand Down
6 changes: 3 additions & 3 deletions drivers/mfd/wm5102-tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define WM5102_NUM_AOD_ISR 2
#define WM5102_NUM_ISR 5

static const struct reg_default wm5102_reva_patch[] = {
static const struct reg_sequence wm5102_reva_patch[] = {
{ 0x80, 0x0003 },
{ 0x221, 0x0090 },
{ 0x211, 0x0014 },
Expand Down Expand Up @@ -57,7 +57,7 @@ static const struct reg_default wm5102_reva_patch[] = {
{ 0x80, 0x0000 },
};

static const struct reg_default wm5102_revb_patch[] = {
static const struct reg_sequence wm5102_revb_patch[] = {
{ 0x19, 0x0001 },
{ 0x80, 0x0003 },
{ 0x081, 0xE022 },
Expand All @@ -80,7 +80,7 @@ static const struct reg_default wm5102_revb_patch[] = {
/* We use a function so we can use ARRAY_SIZE() */
int wm5102_patch(struct arizona *arizona)
{
const struct reg_default *wm5102_patch;
const struct reg_sequence *wm5102_patch;
int patch_size;

switch (arizona->rev) {
Expand Down
6 changes: 3 additions & 3 deletions drivers/mfd/wm5110-tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define WM5110_NUM_AOD_ISR 2
#define WM5110_NUM_ISR 5

static const struct reg_default wm5110_reva_patch[] = {
static const struct reg_sequence wm5110_reva_patch[] = {
{ 0x80, 0x3 },
{ 0x44, 0x20 },
{ 0x45, 0x40 },
Expand Down Expand Up @@ -134,7 +134,7 @@ static const struct reg_default wm5110_reva_patch[] = {
{ 0x209, 0x002A },
};

static const struct reg_default wm5110_revb_patch[] = {
static const struct reg_sequence wm5110_revb_patch[] = {
{ 0x80, 0x3 },
{ 0x36e, 0x0210 },
{ 0x370, 0x0210 },
Expand Down Expand Up @@ -224,7 +224,7 @@ static const struct reg_default wm5110_revb_patch[] = {
{ 0x80, 0x0 },
};

static const struct reg_default wm5110_revd_patch[] = {
static const struct reg_sequence wm5110_revd_patch[] = {
{ 0x80, 0x3 },
{ 0x80, 0x3 },
{ 0x393, 0x27 },
Expand Down
8 changes: 4 additions & 4 deletions drivers/mfd/wm8994-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,21 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
}
#endif

static const struct reg_default wm8994_revc_patch[] = {
static const struct reg_sequence wm8994_revc_patch[] = {
{ 0x102, 0x3 },
{ 0x56, 0x3 },
{ 0x817, 0x0 },
{ 0x102, 0x0 },
};

static const struct reg_default wm8958_reva_patch[] = {
static const struct reg_sequence wm8958_reva_patch[] = {
{ 0x102, 0x3 },
{ 0xcb, 0x81 },
{ 0x817, 0x0 },
{ 0x102, 0x0 },
};

static const struct reg_default wm1811_reva_patch[] = {
static const struct reg_sequence wm1811_reva_patch[] = {
{ 0x102, 0x3 },
{ 0x56, 0xc07 },
{ 0x5d, 0x7e },
Expand Down Expand Up @@ -326,7 +326,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
{
struct wm8994_pdata *pdata;
struct regmap_config *regmap_config;
const struct reg_default *regmap_patch = NULL;
const struct reg_sequence *regmap_patch = NULL;
const char *devname;
int ret, i, patch_regs = 0;
int pulls = 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mfd/wm8997-tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "arizona.h"

static const struct reg_default wm8997_reva_patch[] = {
static const struct reg_sequence wm8997_reva_patch[] = {
{ 0x80, 0x0003 },
{ 0x214, 0x0008 },
{ 0x458, 0x0000 },
Expand Down
17 changes: 14 additions & 3 deletions include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ struct reg_default {
unsigned int def;
};

/**
* Register/value pairs for sequences of writes
*
* @reg: Register address.
* @def: Register value.
*/
struct reg_sequence {
unsigned int reg;
unsigned int def;
};

#ifdef CONFIG_REGMAP

enum regmap_endian {
Expand Down Expand Up @@ -410,10 +421,10 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
size_t val_count);
int regmap_multi_reg_write(struct regmap *map, const struct reg_default *regs,
int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
int num_regs);
int regmap_multi_reg_write_bypassed(struct regmap *map,
const struct reg_default *regs,
const struct reg_sequence *regs,
int num_regs);
int regmap_raw_write_async(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
Expand Down Expand Up @@ -450,7 +461,7 @@ void regcache_mark_dirty(struct regmap *map);
bool regmap_check_range_table(struct regmap *map, unsigned int reg,
const struct regmap_access_table *table);

int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
int num_regs);
int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val);
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/arizona.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ static void arizona_wm5102_set_dac_comp(struct snd_soc_codec *codec,
{
struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
struct arizona *arizona = priv->arizona;
struct reg_default dac_comp[] = {
struct reg_sequence dac_comp[] = {
{ 0x80, 0x3 },
{ ARIZONA_DAC_COMP_1, 0 },
{ ARIZONA_DAC_COMP_2, 0 },
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/cs35l32.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs35l32 = {
};

/* Current and threshold powerup sequence Pg37 in datasheet */
static const struct reg_default cs35l32_monitor_patch[] = {
static const struct reg_sequence cs35l32_monitor_patch[] = {

{ 0x00, 0x99 },
{ 0x48, 0x17 },
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/cs42l52.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs42l52 = {
};

/* Current and threshold powerup sequence Pg37 */
static const struct reg_default cs42l52_threshold_patch[] = {
static const struct reg_sequence cs42l52_threshold_patch[] = {

{ 0x00, 0x99 },
{ 0x3E, 0xBA },
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/da7210.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ static struct snd_soc_codec_driver soc_codec_dev_da7210 = {

#if IS_ENABLED(CONFIG_I2C)

static struct reg_default da7210_regmap_i2c_patch[] = {
static struct reg_sequence da7210_regmap_i2c_patch[] = {

/* System controller master disable */
{ DA7210_STARTUP1, 0x00 },
Expand Down Expand Up @@ -1269,7 +1269,7 @@ static struct i2c_driver da7210_i2c_driver = {

#if defined(CONFIG_SPI_MASTER)

static struct reg_default da7210_regmap_spi_patch[] = {
static struct reg_sequence da7210_regmap_spi_patch[] = {
/* Dummy read to give two pulses over nCS for SPI */
{ DA7210_AUX2, 0x00 },
{ DA7210_AUX2, 0x00 },
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/rt5640.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5640_ranges[] = {
.window_len = 0x1, },
};

static const struct reg_default init_list[] = {
static const struct reg_sequence init_list[] = {
{RT5640_PR_BASE + 0x3d, 0x3600},
{RT5640_PR_BASE + 0x12, 0x0aa8},
{RT5640_PR_BASE + 0x14, 0x0aaa},
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/rt5645.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static const struct regmap_range_cfg rt5645_ranges[] = {
},
};

static const struct reg_default init_list[] = {
static const struct reg_sequence init_list[] = {
{RT5645_PR_BASE + 0x3d, 0x3600},
{RT5645_PR_BASE + 0x1c, 0xfd20},
{RT5645_PR_BASE + 0x20, 0x611f},
Expand All @@ -63,7 +63,7 @@ static const struct reg_default init_list[] = {
};
#define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list)

static const struct reg_default rt5650_init_list[] = {
static const struct reg_sequence rt5650_init_list[] = {
{0xf6, 0x0100},
};

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/rt5651.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static const struct regmap_range_cfg rt5651_ranges[] = {
.window_len = 0x1, },
};

static struct reg_default init_list[] = {
static struct reg_sequence init_list[] = {
{RT5651_PR_BASE + 0x3d, 0x3e00},
};

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/rt5670.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5670_ranges[] = {
.window_len = 0x1, },
};

static const struct reg_default init_list[] = {
static const struct reg_sequence init_list[] = {
{ RT5670_PR_BASE + 0x14, 0x9a8a },
{ RT5670_PR_BASE + 0x38, 0x3ba1 },
{ RT5670_PR_BASE + 0x3d, 0x3640 },
Expand Down
Loading

0 comments on commit 8019ff6

Please sign in to comment.