[alsa-devel] [PATCH v3 0/3] ASoC: codecs: some more improvements for adau1701
v3: - fixed documentation for adi,pll-clkdiv - droped implicit I2C_M_STOP - moved regcache_sync() to adau1761_reset() - added regcache_mark_dirty() - made gpio_pll_mode and array - dropped ADAU1701_CLKDIV_MCLK_LRCLK
Thanks for the review, Lars!
Daniel Mack (3): ASoC: codecs: adau1701: allow configuration of PLL mode pins ASoC: codecs: adau1701: switch to direct regmap API usage ASoC: codecs: adau1701: add support for pin muxing
.../devicetree/bindings/sound/adi,adau1701.txt | 21 ++ sound/soc/codecs/adau1701.c | 248 ++++++++++++++++----- 2 files changed, 214 insertions(+), 55 deletions(-)
The ADAU1701 has 2 hardware pins to configure the PLL mode in accordance to the MCLK-to-LRCLK ratio. These pins have to be stable before the chip is released from reset, and a full reset cycle, including a new firmware download is needed whenever they change.
This patch adds GPIO properties to the DT bindings of the Codec, and implements makes the set_sysclk memorize the configured sysclk.
To avoid excessive reset cycles and firmware downloads, the default clock divider can be specified in DT as well. Whenever a ratio change is detected in the hw_params callback, the PLL mode lines are updates and a full reset cycle is issued.
Signed-off-by: Daniel Mack zonque@gmail.com --- .../devicetree/bindings/sound/adi,adau1701.txt | 15 +++ sound/soc/codecs/adau1701.c | 105 ++++++++++++++++----- 2 files changed, 99 insertions(+), 21 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt index 3afeda7..173ae06 100644 --- a/Documentation/devicetree/bindings/sound/adi,adau1701.txt +++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt @@ -11,6 +11,20 @@ Optional properties: - reset-gpio: A GPIO spec to define which pin is connected to the chip's !RESET pin. If specified, the driver will assert a hardware reset at probe time. + - adi,pll-clkdiv: The PLL clock divider, specifing the ratio between + MCLK and fsclk. The value is used to determine the + correct state of the two mode pins below. + Note that this value can be overridden at runtime + by configuring the Codec in an altered MCLK/LRCLK ratio + via its hwparams() call. However, the chips needs a + full reset cycle and a new firmware download each time + the configuration changes, hence this property can help + systems provide a sane default. + - adi,pll-mode-gpios: An array of two GPIO specs to describe the GPIOs + the ADAU's PLL config pins are connected to. + The state of the pins are set according to the + configured clock divider on ASoC side before the + firmware is loaded.
Examples:
@@ -19,5 +33,6 @@ Examples: compatible = "adi,adau1701"; reg = <0x34>; reset-gpio = <&gpio 23 0>; + adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>; }; }; diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index b6b1a77..6bc566f 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -91,7 +91,10 @@
struct adau1701 { int gpio_nreset; + int gpio_pll_mode[2]; unsigned int dai_fmt; + unsigned int pll_clkdiv; + unsigned int sysclk; };
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -184,13 +187,37 @@ static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg) return value; }
-static void adau1701_reset(struct snd_soc_codec *codec) +static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) { struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
if (!gpio_is_valid(adau1701->gpio_nreset)) return;
+ if (gpio_is_valid(adau1701->gpio_pll_mode[0]) && + gpio_is_valid(adau1701->gpio_pll_mode[1])) { + switch (clkdiv) { + case 64: + gpio_set_value(adau1701->gpio_pll_mode[0], 0); + gpio_set_value(adau1701->gpio_pll_mode[1], 0); + break; + case 256: + gpio_set_value(adau1701->gpio_pll_mode[0], 0); + gpio_set_value(adau1701->gpio_pll_mode[1], 1); + break; + case 384: + gpio_set_value(adau1701->gpio_pll_mode[0], 1); + gpio_set_value(adau1701->gpio_pll_mode[1], 0); + break; + case 512: + gpio_set_value(adau1701->gpio_pll_mode[0], 1); + gpio_set_value(adau1701->gpio_pll_mode[1], 1); + break; + } + } + + adau1701->pll_clkdiv = clkdiv; + gpio_set_value(adau1701->gpio_nreset, 0); /* minimum reset time is 20ns */ udelay(1); @@ -199,24 +226,6 @@ static void adau1701_reset(struct snd_soc_codec *codec) mdelay(85); }
-static int adau1701_init(struct snd_soc_codec *codec) -{ - int ret; - struct i2c_client *client = to_i2c_client(codec->dev); - - adau1701_reset(codec); - - ret = process_sigma_firmware(client, ADAU1701_FIRMWARE); - if (ret) { - dev_warn(codec->dev, "Failed to load firmware\n"); - return ret; - } - - snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); - - return 0; -} - static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec, snd_pcm_format_t format) { @@ -291,9 +300,22 @@ static int adau1701_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_codec *codec = dai->codec; + struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); snd_pcm_format_t format; unsigned int val;
+ if (adau1701->sysclk) { + unsigned int clkdiv = adau1701->sysclk / params_rate(params); + + /* + * If the mclk/lrclk ratio changes, the chip needs updated PLL + * mode GPIO settings, and a full reset cycle, including a new + * firmware upload. + */ + if (clkdiv != adau1701->pll_clkdiv) + adau1701_reset(codec, clkdiv); + } + switch (params_rate(params)) { case 192000: val = ADAU1701_DSPCTRL_SR_192; @@ -435,6 +457,7 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id, int source, unsigned int freq, int dir) { unsigned int val; + struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
switch (clk_id) { case ADAU1701_CLK_SRC_OSC: @@ -448,6 +471,7 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id, }
snd_soc_update_bits(codec, ADAU1701_OSCIPOW, ADAU1701_OSCIPOW_OPD, val); + adau1701->sysclk = freq;
return 0; } @@ -495,13 +519,21 @@ MODULE_DEVICE_TABLE(of, adau1701_dt_ids); static int adau1701_probe(struct snd_soc_codec *codec) { int ret; + struct i2c_client *client = to_i2c_client(codec->dev); + struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
codec->control_data = to_i2c_client(codec->dev);
- ret = adau1701_init(codec); - if (ret) + /* initalize with pre-configured pll mode settings */ + adau1701_reset(codec, adau1701->pll_clkdiv); + + ret = process_sigma_firmware(client, ADAU1701_FIRMWARE); + if (ret) { + dev_warn(codec->dev, "Failed to load firmware\n"); return ret; + }
+ snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); snd_soc_write(codec, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
return 0; @@ -534,6 +566,7 @@ static int adau1701_i2c_probe(struct i2c_client *client, struct adau1701 *adau1701; struct device *dev = &client->dev; int gpio_nreset = -EINVAL; + int gpio_pll_mode[2] = { -EINVAL, -EINVAL }; int ret;
adau1701 = devm_kzalloc(dev, sizeof(*adau1701), GFP_KERNEL); @@ -544,6 +577,19 @@ static int adau1701_i2c_probe(struct i2c_client *client, gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0); if (gpio_nreset < 0 && gpio_nreset != -ENOENT) return gpio_nreset; + + gpio_pll_mode[0] = of_get_named_gpio(dev->of_node, + "adi,pll-mode-gpios", 0); + if (gpio_pll_mode[0] < 0 && gpio_pll_mode[0] != -ENOENT) + return gpio_pll_mode[0]; + + gpio_pll_mode[1] = of_get_named_gpio(dev->of_node, + "adi,pll-mode-gpios", 1); + if (gpio_pll_mode[1] < 0 && gpio_pll_mode[1] != -ENOENT) + return gpio_pll_mode[1]; + + of_property_read_u32(dev->of_node, "adi,pll-clkdiv", + &adau1701->pll_clkdiv); }
if (gpio_is_valid(gpio_nreset)) { @@ -553,7 +599,24 @@ static int adau1701_i2c_probe(struct i2c_client *client, return ret; }
+ if (gpio_is_valid(gpio_pll_mode[0]) && + gpio_is_valid(gpio_pll_mode[1])) { + ret = devm_gpio_request_one(dev, gpio_pll_mode[0], + GPIOF_OUT_INIT_LOW, + "ADAU1701 PLL mode 0"); + if (ret < 0) + return ret; + + ret = devm_gpio_request_one(dev, gpio_pll_mode[1], + GPIOF_OUT_INIT_LOW, + "ADAU1701 PLL mode 1"); + if (ret < 0) + return ret; + } + adau1701->gpio_nreset = gpio_nreset; + adau1701->gpio_pll_mode[0] = gpio_pll_mode[0]; + adau1701->gpio_pll_mode[1] = gpio_pll_mode[1];
i2c_set_clientdata(client, adau1701); ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv,
On 06/21/2013 09:54 AM, Daniel Mack wrote:
The ADAU1701 has 2 hardware pins to configure the PLL mode in accordance to the MCLK-to-LRCLK ratio. These pins have to be stable before the chip is released from reset, and a full reset cycle, including a new firmware download is needed whenever they change.
This patch adds GPIO properties to the DT bindings of the Codec, and implements makes the set_sysclk memorize the configured sysclk.
To avoid excessive reset cycles and firmware downloads, the default clock divider can be specified in DT as well. Whenever a ratio change is detected in the hw_params callback, the PLL mode lines are updates and a full reset cycle is issued.
Signed-off-by: Daniel Mack zonque@gmail.com
Acked-by: Lars-Peter Clausen lars@metafoo.de
Thanks.
.../devicetree/bindings/sound/adi,adau1701.txt | 15 +++ sound/soc/codecs/adau1701.c | 105 ++++++++++++++++----- 2 files changed, 99 insertions(+), 21 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt index 3afeda7..173ae06 100644 --- a/Documentation/devicetree/bindings/sound/adi,adau1701.txt +++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt @@ -11,6 +11,20 @@ Optional properties:
- reset-gpio: A GPIO spec to define which pin is connected to the chip's !RESET pin. If specified, the driver will assert a hardware reset at probe time.
- adi,pll-clkdiv: The PLL clock divider, specifing the ratio between
MCLK and fsclk. The value is used to determine the
correct state of the two mode pins below.
Note that this value can be overridden at runtime
by configuring the Codec in an altered MCLK/LRCLK ratio
via its hwparams() call. However, the chips needs a
full reset cycle and a new firmware download each time
the configuration changes, hence this property can help
systems provide a sane default.
- adi,pll-mode-gpios: An array of two GPIO specs to describe the GPIOs
the ADAU's PLL config pins are connected to.
The state of the pins are set according to the
configured clock divider on ASoC side before the
firmware is loaded.
Examples:
@@ -19,5 +33,6 @@ Examples: compatible = "adi,adau1701"; reg = <0x34>; reset-gpio = <&gpio 23 0>;
}; };adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>;
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index b6b1a77..6bc566f 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -91,7 +91,10 @@
struct adau1701 { int gpio_nreset;
- int gpio_pll_mode[2]; unsigned int dai_fmt;
- unsigned int pll_clkdiv;
- unsigned int sysclk;
};
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -184,13 +187,37 @@ static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg) return value; }
-static void adau1701_reset(struct snd_soc_codec *codec) +static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) { struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
if (!gpio_is_valid(adau1701->gpio_nreset)) return;
- if (gpio_is_valid(adau1701->gpio_pll_mode[0]) &&
gpio_is_valid(adau1701->gpio_pll_mode[1])) {
switch (clkdiv) {
case 64:
gpio_set_value(adau1701->gpio_pll_mode[0], 0);
gpio_set_value(adau1701->gpio_pll_mode[1], 0);
break;
case 256:
gpio_set_value(adau1701->gpio_pll_mode[0], 0);
gpio_set_value(adau1701->gpio_pll_mode[1], 1);
break;
case 384:
gpio_set_value(adau1701->gpio_pll_mode[0], 1);
gpio_set_value(adau1701->gpio_pll_mode[1], 0);
break;
case 512:
gpio_set_value(adau1701->gpio_pll_mode[0], 1);
gpio_set_value(adau1701->gpio_pll_mode[1], 1);
break;
}
- }
- adau1701->pll_clkdiv = clkdiv;
- gpio_set_value(adau1701->gpio_nreset, 0); /* minimum reset time is 20ns */ udelay(1);
@@ -199,24 +226,6 @@ static void adau1701_reset(struct snd_soc_codec *codec) mdelay(85); }
-static int adau1701_init(struct snd_soc_codec *codec) -{
- int ret;
- struct i2c_client *client = to_i2c_client(codec->dev);
- adau1701_reset(codec);
- ret = process_sigma_firmware(client, ADAU1701_FIRMWARE);
- if (ret) {
dev_warn(codec->dev, "Failed to load firmware\n");
return ret;
- }
- snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT);
- return 0;
-}
static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec, snd_pcm_format_t format) { @@ -291,9 +300,22 @@ static int adau1701_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_codec *codec = dai->codec;
struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec); snd_pcm_format_t format; unsigned int val;
if (adau1701->sysclk) {
unsigned int clkdiv = adau1701->sysclk / params_rate(params);
/*
* If the mclk/lrclk ratio changes, the chip needs updated PLL
* mode GPIO settings, and a full reset cycle, including a new
* firmware upload.
*/
if (clkdiv != adau1701->pll_clkdiv)
adau1701_reset(codec, clkdiv);
}
switch (params_rate(params)) { case 192000: val = ADAU1701_DSPCTRL_SR_192;
@@ -435,6 +457,7 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id, int source, unsigned int freq, int dir) { unsigned int val;
struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
switch (clk_id) { case ADAU1701_CLK_SRC_OSC:
@@ -448,6 +471,7 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id, }
snd_soc_update_bits(codec, ADAU1701_OSCIPOW, ADAU1701_OSCIPOW_OPD, val);
adau1701->sysclk = freq;
return 0;
} @@ -495,13 +519,21 @@ MODULE_DEVICE_TABLE(of, adau1701_dt_ids); static int adau1701_probe(struct snd_soc_codec *codec) { int ret;
struct i2c_client *client = to_i2c_client(codec->dev);
struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
codec->control_data = to_i2c_client(codec->dev);
- ret = adau1701_init(codec);
- if (ret)
/* initalize with pre-configured pll mode settings */
adau1701_reset(codec, adau1701->pll_clkdiv);
ret = process_sigma_firmware(client, ADAU1701_FIRMWARE);
if (ret) {
dev_warn(codec->dev, "Failed to load firmware\n");
return ret;
}
snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); snd_soc_write(codec, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
return 0;
@@ -534,6 +566,7 @@ static int adau1701_i2c_probe(struct i2c_client *client, struct adau1701 *adau1701; struct device *dev = &client->dev; int gpio_nreset = -EINVAL;
int gpio_pll_mode[2] = { -EINVAL, -EINVAL }; int ret;
adau1701 = devm_kzalloc(dev, sizeof(*adau1701), GFP_KERNEL);
@@ -544,6 +577,19 @@ static int adau1701_i2c_probe(struct i2c_client *client, gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0); if (gpio_nreset < 0 && gpio_nreset != -ENOENT) return gpio_nreset;
gpio_pll_mode[0] = of_get_named_gpio(dev->of_node,
"adi,pll-mode-gpios", 0);
if (gpio_pll_mode[0] < 0 && gpio_pll_mode[0] != -ENOENT)
return gpio_pll_mode[0];
gpio_pll_mode[1] = of_get_named_gpio(dev->of_node,
"adi,pll-mode-gpios", 1);
if (gpio_pll_mode[1] < 0 && gpio_pll_mode[1] != -ENOENT)
return gpio_pll_mode[1];
of_property_read_u32(dev->of_node, "adi,pll-clkdiv",
&adau1701->pll_clkdiv);
}
if (gpio_is_valid(gpio_nreset)) {
@@ -553,7 +599,24 @@ static int adau1701_i2c_probe(struct i2c_client *client, return ret; }
if (gpio_is_valid(gpio_pll_mode[0]) &&
gpio_is_valid(gpio_pll_mode[1])) {
ret = devm_gpio_request_one(dev, gpio_pll_mode[0],
GPIOF_OUT_INIT_LOW,
"ADAU1701 PLL mode 0");
if (ret < 0)
return ret;
ret = devm_gpio_request_one(dev, gpio_pll_mode[1],
GPIOF_OUT_INIT_LOW,
"ADAU1701 PLL mode 1");
if (ret < 0)
return ret;
}
adau1701->gpio_nreset = gpio_nreset;
adau1701->gpio_pll_mode[0] = gpio_pll_mode[0];
adau1701->gpio_pll_mode[1] = gpio_pll_mode[1];
i2c_set_clientdata(client, adau1701); ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv,
On Fri, Jun 21, 2013 at 09:54:42AM +0200, Daniel Mack wrote:
To avoid excessive reset cycles and firmware downloads, the default clock divider can be specified in DT as well. Whenever a ratio change is detected in the hw_params callback, the PLL mode lines are updates and a full reset cycle is issued.
Why isn't it enough to just use the first setting we see - I'd expect the device to normally be powered off before audio starts including when hw_params() is called?
On 21.06.2013 17:00, Mark Brown wrote:
On Fri, Jun 21, 2013 at 09:54:42AM +0200, Daniel Mack wrote:
To avoid excessive reset cycles and firmware downloads, the default clock divider can be specified in DT as well. Whenever a ratio change is detected in the hw_params callback, the PLL mode lines are updates and a full reset cycle is issued.
Why isn't it enough to just use the first setting we see - I'd expect the device to normally be powered off before audio starts including when hw_params() is called?
Hmm, then we would postpone the firmware download to the first hw_params call in all cases. That could also work, but it'll need some rework. I'll post new patches the next days.
Daniel
Hello.
I would like to contribute to alsa development. As a first step, I have made changes for caching control devices in ucm.
Please review the following changes and let me know if I can check in the changes and how to check in?
----------------------
diff --git a/src/ucm/main.c b/src/ucm/main.c index 030c9b1..3219778 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -131,31 +131,33 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr, const char *ctl_dev) { int err; + struct list_head *pos; + struct snd_ctl_list *snd_ctl; - /* FIXME: add a list of ctl devices to uc_mgr structure and - cache accesses for multiple opened ctl devices */ - if (uc_mgr->ctl_dev != NULL && strcmp(ctl_dev, uc_mgr->ctl_dev) == 0) { - *ctl = uc_mgr->ctl; - return 0; - } - if (uc_mgr->ctl_dev) { - free(uc_mgr->ctl_dev); - uc_mgr->ctl_dev = NULL; - snd_ctl_close(uc_mgr->ctl); - + list_for_each(pos, &uc_mgr->ctl_list) { + snd_ctl = list_entry(pos, struct snd_ctl_list, list); + if(!snd_ctl) + break; + if(!strcmp(snd_ctl->ctl_dev, ctl_dev)) { + *ctl = snd_ctl->ctl; + return 0; + } } err = snd_ctl_open(ctl, ctl_dev, 0); if (err < 0) return err; - uc_mgr->ctl_dev = strdup(ctl_dev); - if (uc_mgr->ctl_dev == NULL) { - snd_ctl_close(*ctl); - return -ENOMEM; - } - uc_mgr->ctl = *ctl; + + if (*ctl) { + snd_ctl = malloc(sizeof(struct snd_ctl_list)); + snd_ctl->ctl_dev = strdup(ctl_dev); + snd_ctl->ctl = *ctl; + list_add_tail(&snd_ctl->list, &uc_mgr->ctl_list); + } + return 0; } + static int execute_cset(snd_ctl_t *ctl, char *cset) { char *pos; @@ -622,6 +624,7 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **mgr, INIT_LIST_HEAD(&uc_mgr->value_list); INIT_LIST_HEAD(&uc_mgr->active_modifiers); INIT_LIST_HEAD(&uc_mgr->active_devices); + INIT_LIST_HEAD(&uc_mgr->ctl_list); pthread_mutex_init(&uc_mgr->mutex, NULL); uc_mgr->card_name = strdup(card_name); diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 13e82da..86a51c7 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -82,6 +82,12 @@ struct dev_list { }; +struct snd_ctl_list { + snd_ctl_t *ctl; + char *ctl_dev; + struct list_head list; +}; + /* * Describes a Use Case Modifier and it's enable and disable sequences. * A use case verb can have N modifiers. @@ -183,8 +189,8 @@ struct snd_use_case_mgr { pthread_mutex_t mutex; /* change to list of ctl handles */ - snd_ctl_t *ctl; - char *ctl_dev; + + struct list_head ctl_list; }; #define uc_error SNDERR diff --git a/src/ucm/utils.c b/src/ucm/utils.c index 2def0b8..f18a2ac 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -99,6 +99,21 @@ void uc_mgr_free_value(struct list_head *base) } } + +void uc_mgr_free_ctl(struct list_head *base) +{ + struct list_head *pos, *npos; + struct snd_ctl_list *ctl_list; + + list_for_each_safe(pos, npos, base) { + ctl_list = list_entry(pos, struct snd_ctl_list, list); + free(ctl_list->ctl_dev); + snd_ctl_close(ctl_list->ctl); + list_del(&ctl_list->list); + free(ctl_list); + } +} + void uc_mgr_free_dev_list(struct list_head *base) { struct list_head *pos, *npos; @@ -220,12 +235,7 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr->active_verb = NULL; INIT_LIST_HEAD(&uc_mgr->active_devices); INIT_LIST_HEAD(&uc_mgr->active_modifiers); - if (uc_mgr->ctl != NULL) { - snd_ctl_close(uc_mgr->ctl); - uc_mgr->ctl = NULL; - } - free(uc_mgr->ctl_dev); - uc_mgr->ctl_dev = NULL; + uc_mgr_free_ctl(&uc_mgr->ctl_list); } void uc_mgr_free(snd_use_case_mgr_t *uc_mgr)
---------------------
Sajeesh
On 23.06.2013 00:10, sajeesh sidharthan wrote:
Hello.
I would like to contribute to alsa development. As a first step, I have made changes for caching control devices in ucm.
Thank you for doing this.
Please review the following changes and let me know if I can check in the changes and how to check in?
First of all, please do not hijack an email thread by clicking on the 'reply' button and changing the subject line. An email contains internal references to other mails in the same thread that most email clients won't allow you to see or edit. Your email was hence hidden inside another thread, and most likely it was overlooked by the UCM maintainer.
Second, you should always Cc: the relevant maintainers in your emails. In this case, Liam and Takashi. I copied them now.
And third, please use 'git commit', 'git format-patch' and 'git send-email', which will format everything correctly for you. And note that you need to add a 'Signed-off-by:' line with your name and email address, as done in other patches.
I can't really comment on the actual patch. Let's hope Liam or Takashi can :)
Daniel
diff --git a/src/ucm/main.c b/src/ucm/main.c index 030c9b1..3219778 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -131,31 +131,33 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr, const char *ctl_dev) { int err;
- struct list_head *pos;
- struct snd_ctl_list *snd_ctl;
- /* FIXME: add a list of ctl devices to uc_mgr structure and
cache accesses for multiple opened ctl devices */
- if (uc_mgr->ctl_dev != NULL && strcmp(ctl_dev, uc_mgr->ctl_dev) == 0) {
*ctl = uc_mgr->ctl;
return 0;
- }
- if (uc_mgr->ctl_dev) {
free(uc_mgr->ctl_dev);
uc_mgr->ctl_dev = NULL;
snd_ctl_close(uc_mgr->ctl);
- list_for_each(pos, &uc_mgr->ctl_list) {
snd_ctl = list_entry(pos, struct snd_ctl_list, list);
if(!snd_ctl)
break;
if(!strcmp(snd_ctl->ctl_dev, ctl_dev)) {
*ctl = snd_ctl->ctl;
return 0;
} err = snd_ctl_open(ctl, ctl_dev, 0); if (err < 0) return err;}
- uc_mgr->ctl_dev = strdup(ctl_dev);
- if (uc_mgr->ctl_dev == NULL) {
snd_ctl_close(*ctl);
return -ENOMEM;
- }
- uc_mgr->ctl = *ctl;
- if (*ctl) {
snd_ctl = malloc(sizeof(struct snd_ctl_list));
snd_ctl->ctl_dev = strdup(ctl_dev);
snd_ctl->ctl = *ctl;
list_add_tail(&snd_ctl->list, &uc_mgr->ctl_list);
- }
- return 0;
}
static int execute_cset(snd_ctl_t *ctl, char *cset) { char *pos; @@ -622,6 +624,7 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **mgr, INIT_LIST_HEAD(&uc_mgr->value_list); INIT_LIST_HEAD(&uc_mgr->active_modifiers); INIT_LIST_HEAD(&uc_mgr->active_devices);
INIT_LIST_HEAD(&uc_mgr->ctl_list); pthread_mutex_init(&uc_mgr->mutex, NULL);
uc_mgr->card_name = strdup(card_name);
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 13e82da..86a51c7 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -82,6 +82,12 @@ struct dev_list { };
+struct snd_ctl_list {
- snd_ctl_t *ctl;
- char *ctl_dev;
- struct list_head list;
+};
/*
- Describes a Use Case Modifier and it's enable and disable sequences.
- A use case verb can have N modifiers.
@@ -183,8 +189,8 @@ struct snd_use_case_mgr { pthread_mutex_t mutex;
/* change to list of ctl handles */
- snd_ctl_t *ctl;
- char *ctl_dev;
- struct list_head ctl_list;
};
#define uc_error SNDERR diff --git a/src/ucm/utils.c b/src/ucm/utils.c index 2def0b8..f18a2ac 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -99,6 +99,21 @@ void uc_mgr_free_value(struct list_head *base) } }
+void uc_mgr_free_ctl(struct list_head *base) +{
- struct list_head *pos, *npos;
- struct snd_ctl_list *ctl_list;
- list_for_each_safe(pos, npos, base) {
ctl_list = list_entry(pos, struct snd_ctl_list, list);
free(ctl_list->ctl_dev);
snd_ctl_close(ctl_list->ctl);
list_del(&ctl_list->list);
free(ctl_list);
- }
+}
void uc_mgr_free_dev_list(struct list_head *base) { struct list_head *pos, *npos; @@ -220,12 +235,7 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr->active_verb = NULL; INIT_LIST_HEAD(&uc_mgr->active_devices); INIT_LIST_HEAD(&uc_mgr->active_modifiers);
- if (uc_mgr->ctl != NULL) {
snd_ctl_close(uc_mgr->ctl);
uc_mgr->ctl = NULL;
- }
- free(uc_mgr->ctl_dev);
- uc_mgr->ctl_dev = NULL;
- uc_mgr_free_ctl(&uc_mgr->ctl_list);
}
void uc_mgr_free(snd_use_case_mgr_t *uc_mgr)
Sajeesh _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Mon, 24 Jun 2013 19:09:33 +0200, Daniel Mack wrote:
On 23.06.2013 00:10, sajeesh sidharthan wrote:
Hello.
I would like to contribute to alsa development. As a first step, I have made changes for caching control devices in ucm.
Thank you for doing this.
Please review the following changes and let me know if I can check in the changes and how to check in?
First of all, please do not hijack an email thread by clicking on the 'reply' button and changing the subject line. An email contains internal references to other mails in the same thread that most email clients won't allow you to see or edit. Your email was hence hidden inside another thread, and most likely it was overlooked by the UCM maintainer.
Second, you should always Cc: the relevant maintainers in your emails. In this case, Liam and Takashi. I copied them now.
And third, please use 'git commit', 'git format-patch' and 'git send-email', which will format everything correctly for you. And note that you need to add a 'Signed-off-by:' line with your name and email address, as done in other patches.
I can't really comment on the actual patch. Let's hope Liam or Takashi can :)
Well, for that, I need to understand the exact goal of the patch; i.e. what it fixes or what it provides for which purpose. The patch description is as equally important as the code change in the patch itself.
So, please give a bit more detailed (but concise) patch description.
thanks,
Takashi
Daniel
diff --git a/src/ucm/main.c b/src/ucm/main.c index 030c9b1..3219778 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -131,31 +131,33 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr, const char *ctl_dev) { int err;
- struct list_head *pos;
- struct snd_ctl_list *snd_ctl;
- /* FIXME: add a list of ctl devices to uc_mgr structure and
cache accesses for multiple opened ctl devices */
- if (uc_mgr->ctl_dev != NULL && strcmp(ctl_dev, uc_mgr->ctl_dev) == 0) {
*ctl = uc_mgr->ctl;
return 0;
- }
- if (uc_mgr->ctl_dev) {
free(uc_mgr->ctl_dev);
uc_mgr->ctl_dev = NULL;
snd_ctl_close(uc_mgr->ctl);
- list_for_each(pos, &uc_mgr->ctl_list) {
snd_ctl = list_entry(pos, struct snd_ctl_list, list);
if(!snd_ctl)
break;
if(!strcmp(snd_ctl->ctl_dev, ctl_dev)) {
*ctl = snd_ctl->ctl;
return 0;
} err = snd_ctl_open(ctl, ctl_dev, 0); if (err < 0) return err;}
- uc_mgr->ctl_dev = strdup(ctl_dev);
- if (uc_mgr->ctl_dev == NULL) {
snd_ctl_close(*ctl);
return -ENOMEM;
- }
- uc_mgr->ctl = *ctl;
- if (*ctl) {
snd_ctl = malloc(sizeof(struct snd_ctl_list));
snd_ctl->ctl_dev = strdup(ctl_dev);
snd_ctl->ctl = *ctl;
list_add_tail(&snd_ctl->list, &uc_mgr->ctl_list);
- }
- return 0;
}
static int execute_cset(snd_ctl_t *ctl, char *cset) { char *pos; @@ -622,6 +624,7 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **mgr, INIT_LIST_HEAD(&uc_mgr->value_list); INIT_LIST_HEAD(&uc_mgr->active_modifiers); INIT_LIST_HEAD(&uc_mgr->active_devices);
INIT_LIST_HEAD(&uc_mgr->ctl_list); pthread_mutex_init(&uc_mgr->mutex, NULL);
uc_mgr->card_name = strdup(card_name);
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 13e82da..86a51c7 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -82,6 +82,12 @@ struct dev_list { };
+struct snd_ctl_list {
- snd_ctl_t *ctl;
- char *ctl_dev;
- struct list_head list;
+};
/*
- Describes a Use Case Modifier and it's enable and disable sequences.
- A use case verb can have N modifiers.
@@ -183,8 +189,8 @@ struct snd_use_case_mgr { pthread_mutex_t mutex;
/* change to list of ctl handles */
- snd_ctl_t *ctl;
- char *ctl_dev;
- struct list_head ctl_list;
};
#define uc_error SNDERR diff --git a/src/ucm/utils.c b/src/ucm/utils.c index 2def0b8..f18a2ac 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -99,6 +99,21 @@ void uc_mgr_free_value(struct list_head *base) } }
+void uc_mgr_free_ctl(struct list_head *base) +{
- struct list_head *pos, *npos;
- struct snd_ctl_list *ctl_list;
- list_for_each_safe(pos, npos, base) {
ctl_list = list_entry(pos, struct snd_ctl_list, list);
free(ctl_list->ctl_dev);
snd_ctl_close(ctl_list->ctl);
list_del(&ctl_list->list);
free(ctl_list);
- }
+}
void uc_mgr_free_dev_list(struct list_head *base) { struct list_head *pos, *npos; @@ -220,12 +235,7 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr->active_verb = NULL; INIT_LIST_HEAD(&uc_mgr->active_devices); INIT_LIST_HEAD(&uc_mgr->active_modifiers);
- if (uc_mgr->ctl != NULL) {
snd_ctl_close(uc_mgr->ctl);
uc_mgr->ctl = NULL;
- }
- free(uc_mgr->ctl_dev);
- uc_mgr->ctl_dev = NULL;
- uc_mgr_free_ctl(&uc_mgr->ctl_list);
}
void uc_mgr_free(snd_use_case_mgr_t *uc_mgr)
Sajeesh _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
The hardware I/O has to be open-coded due to registers of unequal sizes. Other than that, the transition is straight forward.
Signed-off-by: Daniel Mack zonque@gmail.com --- sound/soc/codecs/adau1701.c | 120 +++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 35 deletions(-)
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index 6bc566f..c48f4c5 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -16,6 +16,7 @@ #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/regmap.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> @@ -24,16 +25,16 @@ #include "sigmadsp.h" #include "adau1701.h"
-#define ADAU1701_DSPCTRL 0x1c -#define ADAU1701_SEROCTL 0x1e -#define ADAU1701_SERICTL 0x1f +#define ADAU1701_DSPCTRL 0x081c +#define ADAU1701_SEROCTL 0x081e +#define ADAU1701_SERICTL 0x081f
-#define ADAU1701_AUXNPOW 0x22 +#define ADAU1701_AUXNPOW 0x0822
-#define ADAU1701_OSCIPOW 0x26 -#define ADAU1701_DACSET 0x27 +#define ADAU1701_OSCIPOW 0x0826 +#define ADAU1701_DACSET 0x0827
-#define ADAU1701_NUM_REGS 0x28 +#define ADAU1701_MAX_REGISTER 0x0828
#define ADAU1701_DSPCTRL_CR (1 << 2) #define ADAU1701_DSPCTRL_DAM (1 << 3) @@ -95,6 +96,7 @@ struct adau1701 { unsigned int dai_fmt; unsigned int pll_clkdiv; unsigned int sysclk; + struct regmap *regmap; };
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -126,7 +128,7 @@ static const struct snd_soc_dapm_route adau1701_dapm_routes[] = { { "ADC", NULL, "IN1" }, };
-static unsigned int adau1701_register_size(struct snd_soc_codec *codec, +static unsigned int adau1701_register_size(struct device *dev, unsigned int reg) { switch (reg) { @@ -140,33 +142,42 @@ static unsigned int adau1701_register_size(struct snd_soc_codec *codec, return 1; }
- dev_err(codec->dev, "Unsupported register address: %d\n", reg); + dev_err(dev, "Unsupported register address: %d\n", reg); return 0; }
-static int adau1701_write(struct snd_soc_codec *codec, unsigned int reg, - unsigned int value) +static bool adau1701_volatile_reg(struct device *dev, unsigned int reg) { + switch (reg) { + case ADAU1701_DACSET: + return true; + default: + return false; + } +} + +static int adau1701_reg_write(void *context, unsigned int reg, + unsigned int value) +{ + struct i2c_client *client = context; unsigned int i; unsigned int size; uint8_t buf[4]; int ret;
- size = adau1701_register_size(codec, reg); + size = adau1701_register_size(&client->dev, reg); if (size == 0) return -EINVAL;
- snd_soc_cache_write(codec, reg, value); - - buf[0] = 0x08; - buf[1] = reg; + buf[0] = reg >> 8; + buf[1] = reg & 0xff;
for (i = size + 1; i >= 2; --i) { buf[i] = value; value >>= 8; }
- ret = i2c_master_send(to_i2c_client(codec->dev), buf, size + 2); + ret = i2c_master_send(client, buf, size + 2); if (ret == size + 2) return 0; else if (ret < 0) @@ -175,16 +186,45 @@ static int adau1701_write(struct snd_soc_codec *codec, unsigned int reg, return -EIO; }
-static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg) +static int adau1701_reg_read(void *context, unsigned int reg, + unsigned int *value) { - unsigned int value; - unsigned int ret; + int ret; + unsigned int i; + unsigned int size; + uint8_t send_buf[2], recv_buf[3]; + struct i2c_client *client = context; + struct i2c_msg msgs[2]; + + size = adau1701_register_size(&client->dev, reg); + if (size == 0) + return -EINVAL;
- ret = snd_soc_cache_read(codec, reg, &value); - if (ret) + send_buf[0] = reg >> 8; + send_buf[1] = reg & 0xff; + + msgs[0].addr = client->addr; + msgs[0].len = sizeof(send_buf); + msgs[0].buf = send_buf; + msgs[0].flags = 0; + + msgs[1].addr = client->addr; + msgs[1].len = size; + msgs[1].buf = recv_buf; + msgs[1].flags = I2C_M_RD; + + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (ret < 0) return ret; + else if (ret != ARRAY_SIZE(msgs)) + return -EIO;
- return value; + *value = 0; + + for (i = 0; i < size; i++) + *value |= recv_buf[i] << (i * 8); + + return 0; }
static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) @@ -224,6 +264,9 @@ static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) gpio_set_value(adau1701->gpio_nreset, 1); /* power-up time may be as long as 85ms */ mdelay(85); + + regcache_mark_dirty(adau1701->regmap); + regcache_sync(adau1701->regmap); }
static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec, @@ -406,8 +449,8 @@ static int adau1701_set_dai_fmt(struct snd_soc_dai *codec_dai,
adau1701->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
- snd_soc_write(codec, ADAU1701_SERICTL, serictl); - snd_soc_update_bits(codec, ADAU1701_SEROCTL, + regmap_write(adau1701->regmap, ADAU1701_SERICTL, serictl); + regmap_update_bits(adau1701->regmap, ADAU1701_SEROCTL, ~ADAU1701_SEROCTL_WORD_LEN_MASK, seroctl);
return 0; @@ -522,8 +565,6 @@ static int adau1701_probe(struct snd_soc_codec *codec) struct i2c_client *client = to_i2c_client(codec->dev); struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
- codec->control_data = to_i2c_client(codec->dev); - /* initalize with pre-configured pll mode settings */ adau1701_reset(codec, adau1701->pll_clkdiv);
@@ -533,8 +574,8 @@ static int adau1701_probe(struct snd_soc_codec *codec) return ret; }
- snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); - snd_soc_write(codec, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR); + regmap_write(adau1701->regmap, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); + regmap_write(adau1701->regmap, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
return 0; } @@ -544,9 +585,6 @@ static struct snd_soc_codec_driver adau1701_codec_drv = { .set_bias_level = adau1701_set_bias_level, .idle_bias_off = true,
- .reg_cache_size = ADAU1701_NUM_REGS, - .reg_word_size = sizeof(u16), - .controls = adau1701_controls, .num_controls = ARRAY_SIZE(adau1701_controls), .dapm_widgets = adau1701_dapm_widgets, @@ -554,12 +592,19 @@ static struct snd_soc_codec_driver adau1701_codec_drv = { .dapm_routes = adau1701_dapm_routes, .num_dapm_routes = ARRAY_SIZE(adau1701_dapm_routes),
- .write = adau1701_write, - .read = adau1701_read, - .set_sysclk = adau1701_set_sysclk, };
+static const struct regmap_config adau1701_regmap = { + .reg_bits = 16, + .val_bits = 32, + .max_register = ADAU1701_MAX_REGISTER, + .cache_type = REGCACHE_RBTREE, + .volatile_reg = adau1701_volatile_reg, + .reg_write = adau1701_reg_write, + .reg_read = adau1701_reg_read, +}; + static int adau1701_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -573,6 +618,11 @@ static int adau1701_i2c_probe(struct i2c_client *client, if (!adau1701) return -ENOMEM;
+ adau1701->regmap = devm_regmap_init(dev, NULL, client, + &adau1701_regmap); + if (IS_ERR(adau1701->regmap)) + return PTR_ERR(adau1701->regmap); + if (dev->of_node) { gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0); if (gpio_nreset < 0 && gpio_nreset != -ENOENT)
On 06/21/2013 09:54 AM, Daniel Mack wrote:
The hardware I/O has to be open-coded due to registers of unequal sizes. Other than that, the transition is straight forward.
Signed-off-by: Daniel Mack zonque@gmail.com
Acked-by: Lars-Peter Clausen lars@metafoo.de
Thanks.
sound/soc/codecs/adau1701.c | 120 +++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 35 deletions(-)
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index 6bc566f..c48f4c5 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -16,6 +16,7 @@ #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/regmap.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> @@ -24,16 +25,16 @@ #include "sigmadsp.h" #include "adau1701.h"
-#define ADAU1701_DSPCTRL 0x1c -#define ADAU1701_SEROCTL 0x1e -#define ADAU1701_SERICTL 0x1f +#define ADAU1701_DSPCTRL 0x081c +#define ADAU1701_SEROCTL 0x081e +#define ADAU1701_SERICTL 0x081f
-#define ADAU1701_AUXNPOW 0x22 +#define ADAU1701_AUXNPOW 0x0822
-#define ADAU1701_OSCIPOW 0x26 -#define ADAU1701_DACSET 0x27 +#define ADAU1701_OSCIPOW 0x0826 +#define ADAU1701_DACSET 0x0827
-#define ADAU1701_NUM_REGS 0x28 +#define ADAU1701_MAX_REGISTER 0x0828
#define ADAU1701_DSPCTRL_CR (1 << 2) #define ADAU1701_DSPCTRL_DAM (1 << 3) @@ -95,6 +96,7 @@ struct adau1701 { unsigned int dai_fmt; unsigned int pll_clkdiv; unsigned int sysclk;
- struct regmap *regmap;
};
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -126,7 +128,7 @@ static const struct snd_soc_dapm_route adau1701_dapm_routes[] = { { "ADC", NULL, "IN1" }, };
-static unsigned int adau1701_register_size(struct snd_soc_codec *codec, +static unsigned int adau1701_register_size(struct device *dev, unsigned int reg) { switch (reg) { @@ -140,33 +142,42 @@ static unsigned int adau1701_register_size(struct snd_soc_codec *codec, return 1; }
- dev_err(codec->dev, "Unsupported register address: %d\n", reg);
- dev_err(dev, "Unsupported register address: %d\n", reg); return 0;
}
-static int adau1701_write(struct snd_soc_codec *codec, unsigned int reg,
unsigned int value)
+static bool adau1701_volatile_reg(struct device *dev, unsigned int reg) {
- switch (reg) {
- case ADAU1701_DACSET:
return true;
- default:
return false;
- }
+}
+static int adau1701_reg_write(void *context, unsigned int reg,
unsigned int value)
+{
- struct i2c_client *client = context; unsigned int i; unsigned int size; uint8_t buf[4]; int ret;
- size = adau1701_register_size(codec, reg);
- size = adau1701_register_size(&client->dev, reg); if (size == 0) return -EINVAL;
- snd_soc_cache_write(codec, reg, value);
- buf[0] = 0x08;
- buf[1] = reg;
buf[0] = reg >> 8;
buf[1] = reg & 0xff;
for (i = size + 1; i >= 2; --i) { buf[i] = value; value >>= 8; }
- ret = i2c_master_send(to_i2c_client(codec->dev), buf, size + 2);
- ret = i2c_master_send(client, buf, size + 2); if (ret == size + 2) return 0; else if (ret < 0)
@@ -175,16 +186,45 @@ static int adau1701_write(struct snd_soc_codec *codec, unsigned int reg, return -EIO; }
-static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg) +static int adau1701_reg_read(void *context, unsigned int reg,
unsigned int *value)
{
- unsigned int value;
- unsigned int ret;
- int ret;
- unsigned int i;
- unsigned int size;
- uint8_t send_buf[2], recv_buf[3];
- struct i2c_client *client = context;
- struct i2c_msg msgs[2];
- size = adau1701_register_size(&client->dev, reg);
- if (size == 0)
return -EINVAL;
- ret = snd_soc_cache_read(codec, reg, &value);
- if (ret)
- send_buf[0] = reg >> 8;
- send_buf[1] = reg & 0xff;
- msgs[0].addr = client->addr;
- msgs[0].len = sizeof(send_buf);
- msgs[0].buf = send_buf;
- msgs[0].flags = 0;
- msgs[1].addr = client->addr;
- msgs[1].len = size;
- msgs[1].buf = recv_buf;
- msgs[1].flags = I2C_M_RD;
- ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
- if (ret < 0) return ret;
- else if (ret != ARRAY_SIZE(msgs))
return -EIO;
- return value;
- *value = 0;
- for (i = 0; i < size; i++)
*value |= recv_buf[i] << (i * 8);
- return 0;
}
static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) @@ -224,6 +264,9 @@ static void adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv) gpio_set_value(adau1701->gpio_nreset, 1); /* power-up time may be as long as 85ms */ mdelay(85);
- regcache_mark_dirty(adau1701->regmap);
- regcache_sync(adau1701->regmap);
}
static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec, @@ -406,8 +449,8 @@ static int adau1701_set_dai_fmt(struct snd_soc_dai *codec_dai,
adau1701->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
- snd_soc_write(codec, ADAU1701_SERICTL, serictl);
- snd_soc_update_bits(codec, ADAU1701_SEROCTL,
regmap_write(adau1701->regmap, ADAU1701_SERICTL, serictl);
regmap_update_bits(adau1701->regmap, ADAU1701_SEROCTL, ~ADAU1701_SEROCTL_WORD_LEN_MASK, seroctl);
return 0;
@@ -522,8 +565,6 @@ static int adau1701_probe(struct snd_soc_codec *codec) struct i2c_client *client = to_i2c_client(codec->dev); struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
- codec->control_data = to_i2c_client(codec->dev);
- /* initalize with pre-configured pll mode settings */ adau1701_reset(codec, adau1701->pll_clkdiv);
@@ -533,8 +574,8 @@ static int adau1701_probe(struct snd_soc_codec *codec) return ret; }
- snd_soc_write(codec, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT);
- snd_soc_write(codec, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
regmap_write(adau1701->regmap, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT);
regmap_write(adau1701->regmap, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
return 0;
} @@ -544,9 +585,6 @@ static struct snd_soc_codec_driver adau1701_codec_drv = { .set_bias_level = adau1701_set_bias_level, .idle_bias_off = true,
- .reg_cache_size = ADAU1701_NUM_REGS,
- .reg_word_size = sizeof(u16),
- .controls = adau1701_controls, .num_controls = ARRAY_SIZE(adau1701_controls), .dapm_widgets = adau1701_dapm_widgets,
@@ -554,12 +592,19 @@ static struct snd_soc_codec_driver adau1701_codec_drv = { .dapm_routes = adau1701_dapm_routes, .num_dapm_routes = ARRAY_SIZE(adau1701_dapm_routes),
- .write = adau1701_write,
- .read = adau1701_read,
- .set_sysclk = adau1701_set_sysclk,
};
+static const struct regmap_config adau1701_regmap = {
- .reg_bits = 16,
- .val_bits = 32,
- .max_register = ADAU1701_MAX_REGISTER,
- .cache_type = REGCACHE_RBTREE,
- .volatile_reg = adau1701_volatile_reg,
- .reg_write = adau1701_reg_write,
- .reg_read = adau1701_reg_read,
+};
static int adau1701_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -573,6 +618,11 @@ static int adau1701_i2c_probe(struct i2c_client *client, if (!adau1701) return -ENOMEM;
- adau1701->regmap = devm_regmap_init(dev, NULL, client,
&adau1701_regmap);
- if (IS_ERR(adau1701->regmap))
return PTR_ERR(adau1701->regmap);
- if (dev->of_node) { gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0); if (gpio_nreset < 0 && gpio_nreset != -ENOENT)
The ADAU1701 has 12 pins that can be configured depending on the system configuration. Allow settting the corresponding registers from DT.
Signed-off-by: Daniel Mack zonque@gmail.com --- .../devicetree/bindings/sound/adi,adau1701.txt | 6 +++++ sound/soc/codecs/adau1701.c | 29 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt index 173ae06..8582a45 100644 --- a/Documentation/devicetree/bindings/sound/adi,adau1701.txt +++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt @@ -25,6 +25,10 @@ Optional properties: The state of the pins are set according to the configured clock divider on ASoC side before the firmware is loaded. + - adi,pin-config: An array of 12 numerical values selecting one of the + pin configurations as described in the datasheet, + table 53. Note that the value of this property has + to be prefixed with '/bits/ 8'.
Examples:
@@ -34,5 +38,7 @@ Examples: reg = <0x34>; reset-gpio = <&gpio 23 0>; adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>; + adi,pin-config = /bits/ 8 <0x4 0x7 0x5 0x5 0x4 0x4 + 0x4 0x4 0x4 0x4 0x4 0x4>; }; }; diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index c48f4c5..95216c8 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -30,6 +30,9 @@ #define ADAU1701_SERICTL 0x081f
#define ADAU1701_AUXNPOW 0x0822 +#define ADAU1701_PINCONF_0 0x0820 +#define ADAU1701_PINCONF_1 0x0821 +#define ADAU1701_AUXNPOW 0x0822
#define ADAU1701_OSCIPOW 0x0826 #define ADAU1701_DACSET 0x0827 @@ -97,6 +100,7 @@ struct adau1701 { unsigned int pll_clkdiv; unsigned int sysclk; struct regmap *regmap; + u8 pin_config[12]; };
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -132,6 +136,9 @@ static unsigned int adau1701_register_size(struct device *dev, unsigned int reg) { switch (reg) { + case ADAU1701_PINCONF_0: + case ADAU1701_PINCONF_1: + return 3; case ADAU1701_DSPCTRL: case ADAU1701_SEROCTL: case ADAU1701_AUXNPOW: @@ -162,7 +169,7 @@ static int adau1701_reg_write(void *context, unsigned int reg, struct i2c_client *client = context; unsigned int i; unsigned int size; - uint8_t buf[4]; + uint8_t buf[5]; int ret;
size = adau1701_register_size(&client->dev, reg); @@ -561,7 +568,8 @@ MODULE_DEVICE_TABLE(of, adau1701_dt_ids);
static int adau1701_probe(struct snd_soc_codec *codec) { - int ret; + int ret, i; + unsigned int val; struct i2c_client *client = to_i2c_client(codec->dev); struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
@@ -577,6 +585,19 @@ static int adau1701_probe(struct snd_soc_codec *codec) regmap_write(adau1701->regmap, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); regmap_write(adau1701->regmap, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
+ /* set up pin config */ + val = 0; + for (i = 0; i < 6; i++) + val |= adau1701->pin_config[i] << (i * 4); + + regmap_write(adau1701->regmap, ADAU1701_PINCONF_0, val); + + val = 0; + for (i = 0; i < 6; i++) + val |= adau1701->pin_config[i + 6] << (i * 4); + + regmap_write(adau1701->regmap, ADAU1701_PINCONF_1, val); + return 0; }
@@ -640,6 +661,10 @@ static int adau1701_i2c_probe(struct i2c_client *client,
of_property_read_u32(dev->of_node, "adi,pll-clkdiv", &adau1701->pll_clkdiv); + + of_property_read_u8_array(dev->of_node, "adi,pin-config", + adau1701->pin_config, + ARRAY_SIZE(adau1701->pin_config)); }
if (gpio_is_valid(gpio_nreset)) {
On 06/21/2013 09:54 AM, Daniel Mack wrote:
The ADAU1701 has 12 pins that can be configured depending on the system configuration. Allow settting the corresponding registers from DT.
Signed-off-by: Daniel Mack zonque@gmail.com
Acked-by: Lars-Peter Clausen lars@metafoo.de
Thanks.
.../devicetree/bindings/sound/adi,adau1701.txt | 6 +++++ sound/soc/codecs/adau1701.c | 29 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt index 173ae06..8582a45 100644 --- a/Documentation/devicetree/bindings/sound/adi,adau1701.txt +++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt @@ -25,6 +25,10 @@ Optional properties: The state of the pins are set according to the configured clock divider on ASoC side before the firmware is loaded.
- adi,pin-config: An array of 12 numerical values selecting one of the
pin configurations as described in the datasheet,
table 53. Note that the value of this property has
to be prefixed with '/bits/ 8'.
Examples:
@@ -34,5 +38,7 @@ Examples: reg = <0x34>; reset-gpio = <&gpio 23 0>; adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>;
adi,pin-config = /bits/ 8 <0x4 0x7 0x5 0x5 0x4 0x4
}; };0x4 0x4 0x4 0x4 0x4 0x4>;
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index c48f4c5..95216c8 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c @@ -30,6 +30,9 @@ #define ADAU1701_SERICTL 0x081f
#define ADAU1701_AUXNPOW 0x0822 +#define ADAU1701_PINCONF_0 0x0820 +#define ADAU1701_PINCONF_1 0x0821 +#define ADAU1701_AUXNPOW 0x0822
#define ADAU1701_OSCIPOW 0x0826 #define ADAU1701_DACSET 0x0827 @@ -97,6 +100,7 @@ struct adau1701 { unsigned int pll_clkdiv; unsigned int sysclk; struct regmap *regmap;
- u8 pin_config[12];
};
static const struct snd_kcontrol_new adau1701_controls[] = { @@ -132,6 +136,9 @@ static unsigned int adau1701_register_size(struct device *dev, unsigned int reg) { switch (reg) {
- case ADAU1701_PINCONF_0:
- case ADAU1701_PINCONF_1:
case ADAU1701_DSPCTRL: case ADAU1701_SEROCTL: case ADAU1701_AUXNPOW:return 3;
@@ -162,7 +169,7 @@ static int adau1701_reg_write(void *context, unsigned int reg, struct i2c_client *client = context; unsigned int i; unsigned int size;
- uint8_t buf[4];
uint8_t buf[5]; int ret;
size = adau1701_register_size(&client->dev, reg);
@@ -561,7 +568,8 @@ MODULE_DEVICE_TABLE(of, adau1701_dt_ids);
static int adau1701_probe(struct snd_soc_codec *codec) {
- int ret;
- int ret, i;
- unsigned int val; struct i2c_client *client = to_i2c_client(codec->dev); struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
@@ -577,6 +585,19 @@ static int adau1701_probe(struct snd_soc_codec *codec) regmap_write(adau1701->regmap, ADAU1701_DACSET, ADAU1701_DACSET_DACINIT); regmap_write(adau1701->regmap, ADAU1701_DSPCTRL, ADAU1701_DSPCTRL_CR);
- /* set up pin config */
- val = 0;
- for (i = 0; i < 6; i++)
val |= adau1701->pin_config[i] << (i * 4);
- regmap_write(adau1701->regmap, ADAU1701_PINCONF_0, val);
- val = 0;
- for (i = 0; i < 6; i++)
val |= adau1701->pin_config[i + 6] << (i * 4);
- regmap_write(adau1701->regmap, ADAU1701_PINCONF_1, val);
- return 0;
}
@@ -640,6 +661,10 @@ static int adau1701_i2c_probe(struct i2c_client *client,
of_property_read_u32(dev->of_node, "adi,pll-clkdiv", &adau1701->pll_clkdiv);
of_property_read_u8_array(dev->of_node, "adi,pin-config",
adau1701->pin_config,
ARRAY_SIZE(adau1701->pin_config));
}
if (gpio_is_valid(gpio_nreset)) {
participants (5)
-
Daniel Mack
-
Lars-Peter Clausen
-
Mark Brown
-
sajeesh sidharthan
-
Takashi Iwai