From: Andre Przywara Date: Tue, 12 Feb 2019 10:41:11 +0000 Subject: [U-Boot] [PATCH v2 1/4] spi: sunxi: Enable and disable SPI clock on bus claim/release In-Reply-To: <20190212104114.225551-1-andre.przywara@arm.com> References: <20190212104114.225551-1-andre.przywara@arm.com> Message-ID: <20190212104114.225551-2-andre.przywara@arm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Oskari Lemmela Introduce a function to disable the SPI clock, and turn it on and off on bus claim/release, instead of enabling it just once at probe time. Signed-off-by: Oskari Lemmela Signed-off-by: Andre Przywara --- drivers/spi/sun4i_spi.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/spi/sun4i_spi.c b/drivers/spi/sun4i_spi.c index 38cc743c61..61a5f3522e 100644 --- a/drivers/spi/sun4i_spi.c +++ b/drivers/spi/sun4i_spi.c @@ -239,7 +239,7 @@ static int sun4i_spi_parse_pins(struct udevice *dev) return 0; } -static inline void sun4i_spi_enable_clock(void) +static void sun4i_spi_enable_clock(void) { struct sunxi_ccm_reg *const ccm = (struct sunxi_ccm_reg *const)SUNXI_CCM_BASE; @@ -248,6 +248,16 @@ static inline void sun4i_spi_enable_clock(void) writel((1 << 31), &ccm->spi0_clk_cfg); } +static void sun4i_spi_disable_clock(void) +{ + struct sunxi_ccm_reg *const ccm = + (struct sunxi_ccm_reg *const)SUNXI_CCM_BASE; + + writel(0, &ccm->spi0_clk_cfg); + clrbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_SPI0)); + +} + static int sun4i_spi_ofdata_to_platdata(struct udevice *bus) { struct sun4i_spi_platdata *plat = dev_get_platdata(bus); @@ -269,7 +279,6 @@ static int sun4i_spi_probe(struct udevice *bus) struct sun4i_spi_platdata *plat = dev_get_platdata(bus); struct sun4i_spi_priv *priv = dev_get_priv(bus); - sun4i_spi_enable_clock(); sun4i_spi_parse_pins(bus); priv->regs = (struct sun4i_spi_regs *)(uintptr_t)plat->base_addr; @@ -282,9 +291,12 @@ static int sun4i_spi_claim_bus(struct udevice *dev) { struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); + sun4i_spi_enable_clock(); + writel(SUN4I_CTL_ENABLE | SUN4I_CTL_MASTER | SUN4I_CTL_TP | SUN4I_CTL_CS_MANUAL | SUN4I_CTL_CS_ACTIVE_LOW, &priv->regs->ctl); + return 0; } @@ -297,6 +309,8 @@ static int sun4i_spi_release_bus(struct udevice *dev) reg &= ~SUN4I_CTL_ENABLE; writel(reg, &priv->regs->ctl); + sun4i_spi_disable_clock(); + return 0; } -- 2.14.5