Re: [PATCH v3 1/4] mfd: arizona: Factor out SYSCLK enable from wm5102 hardware patch

From: Lee Jones
Date: Mon Mar 30 2015 - 07:23:09 EST


On Mon, 23 Mar 2015, Charles Keepax wrote:

> wm5102 applies a custom hardware boot sequence, for this the SYSCLK
> needs to be enabled. This patch factors out the code that enables
> SYSCLK for this sequence such that it can be used for other boot time
> operations that require SYSCLK.
>
> Signed-off-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> ---
>
> Changes since v3:
> - Split out enable and disable for the freerunning SYSCLK instead
> of having a single function that takes a function pointer.
> - Improve some naming for the sake of clarity
> - Update error handling to use if (err) rather than if (err != 0)
> - Added comment on register patch
>
> Thanks,
> Charles
>
> drivers/mfd/arizona-core.c | 103 ++++++++++++++++++++++++++++++-------------
> 1 files changed, 72 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
> index 6ca6dfa..695c68e 100644
> --- a/drivers/mfd/arizona-core.c
> +++ b/drivers/mfd/arizona-core.c
> @@ -250,20 +250,26 @@ static int arizona_wait_for_boot(struct arizona *arizona)
> return ret;
> }
>
> -static int arizona_apply_hardware_patch(struct arizona* arizona)
> +struct arizona_sysclk_state {
> + unsigned int fll;
> + unsigned int sysclk;
> +};
> +
> +static int arizona_enable_freerun_sysclk(struct arizona *arizona,
> + struct arizona_sysclk_state *state)
> {
> - unsigned int fll, sysclk;
> int ret, err;
>
> /* Cache existing FLL and SYSCLK settings */
> - ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &fll);
> - if (ret != 0) {
> + ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &state->fll);
> + if (ret) {
> dev_err(arizona->dev, "Failed to cache FLL settings: %d\n",
> ret);
> return ret;
> }
> - ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, &sysclk);
> - if (ret != 0) {
> + ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
> + &state->sysclk);
> + if (ret) {
> dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
> ret);
> return ret;
> @@ -272,7 +278,7 @@ static int arizona_apply_hardware_patch(struct arizona* arizona)
> /* Start up SYSCLK using the FLL in free running mode */
> ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1,
> ARIZONA_FLL1_ENA | ARIZONA_FLL1_FREERUN);
> - if (ret != 0) {
> + if (ret) {
> dev_err(arizona->dev,
> "Failed to start FLL in freerunning mode: %d\n",
> ret);
> @@ -281,50 +287,85 @@ static int arizona_apply_hardware_patch(struct arizona* arizona)
> ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
> ARIZONA_FLL1_CLOCK_OK_STS,
> ARIZONA_FLL1_CLOCK_OK_STS);
> - if (ret != 0) {
> + if (ret) {
> ret = -ETIMEDOUT;
> goto err_fll;
> }
>
> ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
> - if (ret != 0) {
> + if (ret) {
> dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
> goto err_fll;
> }
>
> + return 0;
> +
> +err_fll:
> + err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
> + if (err)
> + dev_err(arizona->dev,
> + "Failed to re-apply old FLL settings: %d\n",
> + err);

Nit: How is it that the regmap_write() line fit on 80 chars and the
"err);" bit can't?

> + return ret;
> +}
> +
> +static int arizona_disable_freerun_sysclk(struct arizona *arizona,
> + struct arizona_sysclk_state *state)
> +{
> + int ret = 0;
> + int err;
> +
> + err = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1,
> + state->sysclk);
> + if (err) {
> + dev_err(arizona->dev,
> + "Failed to re-apply old SYSCLK settings: %d\n",
> + err);

Same there, this extra linewrap seems unnecessary.

> + ret = err;
> + }

Can you explain the resson for using 'err' and and not 'ret'?

> + err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, state->fll);
> + if (err) {
> + dev_err(arizona->dev,
> + "Failed to re-apply old FLL settings: %d\n",
> + err);
> + ret = err;
> + }
> +
> + return ret;
> +}
> +
> +static int wm5102_apply_hardware_patch(struct arizona *arizona)
> +{
> + struct arizona_sysclk_state state;
> + int err, ret;
> +
> + ret = arizona_enable_freerun_sysclk(arizona, &state);
> + if (ret)
> + return ret;
> +
> /* Start the write sequencer and wait for it to finish */
> ret = regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
> ARIZONA_WSEQ_ENA | ARIZONA_WSEQ_START | 160);
> - if (ret != 0) {
> + if (ret) {
> dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
> ret);
> - goto err_sysclk;
> + goto err;
> }
> +
> ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
> ARIZONA_WSEQ_BUSY, 0);
> - if (ret != 0) {
> + if (ret) {
> regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
> - ARIZONA_WSEQ_ABORT);
> + ARIZONA_WSEQ_ABORT);
> ret = -ETIMEDOUT;
> }
>
> -err_sysclk:
> - err = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, sysclk);
> - if (err != 0) {
> - dev_err(arizona->dev,
> - "Failed to re-apply old SYSCLK settings: %d\n",
> - err);
> - }
> -
> -err_fll:
> - err = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, fll);
> - if (err != 0) {
> - dev_err(arizona->dev,
> - "Failed to re-apply old FLL settings: %d\n",
> - err);
> - }
> +err:
> + err = arizona_disable_freerun_sysclk(arizona, &state);
>
> - if (ret != 0)
> + if (ret)
> return ret;
> else
> return err;

return ret ?: err;

> @@ -366,7 +407,7 @@ static int arizona_runtime_resume(struct device *dev)
> goto err;
> }
>
> - ret = arizona_apply_hardware_patch(arizona);
> + ret = wm5102_apply_hardware_patch(arizona);
> if (ret != 0) {
> dev_err(arizona->dev,
> "Failed to apply hardware patch: %d\n",
> @@ -891,7 +932,7 @@ int arizona_dev_init(struct arizona *arizona)
>
> switch (arizona->type) {
> case WM5102:
> - ret = arizona_apply_hardware_patch(arizona);
> + ret = wm5102_apply_hardware_patch(arizona);
> if (ret != 0) {
> dev_err(arizona->dev,
> "Failed to apply hardware patch: %d\n",

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org â Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/