mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Samuel Ortiz <sameo@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	patches@opensource.wolfsonmicro.com,
	Charles Keepax <ckeepax@opensource.wolfsonmicro.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 13/15] mfd: arizona: Add a hardware patch mechanism
Date: Mon,  1 Apr 2013 18:28:10 +0100	[thread overview]
Message-ID: <1364837292-30191-13-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1364837292-30191-1-git-send-email-broonie@opensource.wolfsonmicro.com>

From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

This patch adds facilities for apply a register patch contained within
the chip using the write sequencer.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/mfd/arizona-core.c |  103 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 559129e..6ca5cfb 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -242,6 +242,84 @@ static int arizona_wait_for_boot(struct arizona *arizona)
 	return ret;
 }
 
+static int arizona_apply_hardware_patch(struct arizona* arizona)
+{
+	unsigned int fll, sysclk;
+	int ret;
+
+	regcache_cache_bypass(arizona->regmap, true);
+
+	/* Cache existing FLL and SYSCLK settings */
+	ret = regmap_read(arizona->regmap, ARIZONA_FLL1_CONTROL_1, &fll);
+	if (ret < 0) {
+		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) {
+		dev_err(arizona->dev, "Failed to cache SYSCLK settings: %d\n",
+			ret);
+		return ret;
+	}
+
+	/* 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) {
+		dev_err(arizona->dev,
+			"Failed to start FLL in freerunning mode: %d\n",
+			ret);
+		return ret;
+	}
+	ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
+			       ARIZONA_FLL1_CLOCK_OK_STS,
+			       ARIZONA_FLL1_CLOCK_OK_STS);
+	if (ret < 0) {
+		ret = -ETIMEDOUT;
+		goto err_fll;
+	}
+
+	ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, 0x0144);
+	if (ret < 0) {
+		dev_err(arizona->dev, "Failed to start SYSCLK: %d\n", ret);
+		goto err_fll;
+	}
+
+	/* 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) {
+		dev_err(arizona->dev, "Failed to start write sequencer: %d\n",
+			ret);
+		goto err_sysclk;
+	}
+	ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
+			       ARIZONA_WSEQ_BUSY, 0);
+	if (ret < 0) {
+		regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
+				ARIZONA_WSEQ_ABORT);
+		ret = -ETIMEDOUT;
+	}
+
+err_sysclk:
+	ret = regmap_write(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, sysclk);
+	if (ret < 0)
+		dev_err(arizona->dev,
+			"Failed to re-apply old SYSCLK settings: %d\n",
+			ret);
+
+err_fll:
+	ret = regmap_write(arizona->regmap, ARIZONA_FLL1_CONTROL_1, fll);
+	if (ret < 0)
+		dev_err(arizona->dev,
+			"Failed to re-apply old FLL settings: %d\n",
+			ret);
+
+	regcache_cache_bypass(arizona->regmap, false);
+	return ret;
+}
+
 #ifdef CONFIG_PM_RUNTIME
 static int arizona_runtime_resume(struct device *dev)
 {
@@ -272,6 +350,17 @@ static int arizona_runtime_resume(struct device *dev)
 				ret);
 			goto err;
 		}
+
+		ret = arizona_apply_hardware_patch(arizona);
+		if (ret != 0) {
+			dev_err(arizona->dev,
+				"Failed to apply hardware patch: %d\n",
+				ret);
+			goto err;
+		}
+		break;
+	default:
+		break;
 	}
 
 	ret = regcache_sync(arizona->regmap);
@@ -510,6 +599,20 @@ int arizona_dev_init(struct arizona *arizona)
 				ret);
 			goto err_reset;
 		}
+
+		switch (arizona->type) {
+		case WM5102:
+			ret = arizona_apply_hardware_patch(arizona);
+			if (ret != 0) {
+				dev_err(arizona->dev,
+					"Failed to apply hardware patch: %d\n",
+					ret);
+				goto err_reset;
+			}
+			break;
+		default:
+			break;
+		}
 	}
 
 	for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
-- 
1.7.10.4


  parent reply	other threads:[~2013-04-01 17:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01 17:27 [PATCH 0/15] arizona updates for v3.10 Mark Brown
2013-04-01 17:27 ` [PATCH 01/15] mfd: arizona: Disable all wake sources by default Mark Brown
2013-04-01 17:27   ` [PATCH 02/15] mfd: arizona: Clarify error message for failed primary IRQ request Mark Brown
2013-04-01 17:28   ` [PATCH 03/15] mfd: arizona: Basic support for edge triggered IRQs Mark Brown
2013-04-01 17:28   ` [PATCH 04/15] mfd: arizona: Allow GPIO to be specified for IRQ line Mark Brown
2013-04-01 17:28   ` [PATCH 05/15] mfd: arizona: Try to use interrupt flags from interrupt controller Mark Brown
2013-04-01 17:28   ` [PATCH 06/15] mfd: arizona: Support configuring MICBIASes into bypass mode Mark Brown
2013-04-01 17:28   ` [PATCH 07/15] mfd: wm5102: Update patch for latest evaluation Mark Brown
2013-04-01 17:28   ` [PATCH 08/15] mfd: arizona: Fully support the use of MCLK1 as the 32kHz clock source Mark Brown
2013-04-01 17:28   ` [PATCH 09/15] mfd: arizona: Unconditionally enable 32kHz clock Mark Brown
2013-04-01 17:28   ` [PATCH 10/15] mfd: wm5102: Only use the lowest three bits of device revision Mark Brown
2013-04-01 17:28   ` [PATCH 11/15] mfd: wm5102: Manually apply register patch Mark Brown
2013-04-01 17:28   ` [PATCH 12/15] mfd: arizona: Factor out register polling Mark Brown
2013-04-01 17:28   ` Mark Brown [this message]
2013-04-01 17:28   ` [PATCH 14/15] mfd: wm5102: Deactivate standard boot sequence Mark Brown
2013-04-01 17:28   ` [PATCH 15/15] mfd: wm5102: Update defaults to match patch Mark Brown
2013-04-03 18:04 ` [PATCH 0/15] arizona updates for v3.10 Mark Brown
2013-04-03 18:05   ` [PATCH 1/3] mfd: arizona: Hold device in reset while ramping supplies Mark Brown
2013-04-03 18:05     ` [PATCH 2/3] mfd: arizona: Wait for internal clocks to startup after reset Mark Brown
2013-04-03 18:05     ` [PATCH 3/3] mfd: wm5102: Don't wait for boot when boot sequencer is disabled Mark Brown
2013-04-08  9:25   ` [PATCH 0/15] arizona updates for v3.10 Samuel Ortiz
2013-04-08  9:38     ` Samuel Ortiz
2013-04-08 10:04       ` Mark Brown
2013-04-08 10:19         ` Mark Brown
2013-04-08 14:31           ` Samuel Ortiz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364837292-30191-13-git-send-email-broonie@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome