From patchwork Tue Apr 24 15:21:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 903576 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nic.cz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="I3eOuTux"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40VnJM41Frz9ryr for ; Wed, 25 Apr 2018 01:27:31 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1CC52C21F13; Tue, 24 Apr 2018 15:26:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D4A7DC21F64; Tue, 24 Apr 2018 15:21:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 50B3EC21E42; Tue, 24 Apr 2018 15:21:44 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id 417FEC21EBF for ; Tue, 24 Apr 2018 15:21:44 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id 0112462F26; Tue, 24 Apr 2018 17:21:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1524583304; bh=poKqcZGGKfzN8ACzZM9NizsNeD728I+Q1XqmQ1herC8=; h=From:To:Date; b=I3eOuTuxK4GwFmCxafP79WB6mBfwAfQ+VIu1lJ2Vtwe9266ndBpw+35dIX/asvohy LFSnzRHjFfCMwULH2555pNAWSOFBeHgMN+M0fiBtIGvgD4bG4NYO94tN7RCZM1Zfk7 VfGg9PPCCoF8fc/7YpJ4znC8SloZ/rf4nPDeYDGk= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Tue, 24 Apr 2018 17:21:26 +0200 Message-Id: <20180424152131.20375-16-marek.behun@nic.cz> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180424152131.20375-1-marek.behun@nic.cz> References: <20180424152131.20375-1-marek.behun@nic.cz> X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Tomas Hlavacek , Stefan Roese Subject: [U-Boot] [PATCH v2 15/20] spi: mvebu_a3700_spi: Use Armada 37xx clk driver for SPI clock frequency X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Since now we have driver for clocks on Armada 37xx, use it to determine SQF clock frequency for the SPI driver. Also change the default config files for Armada 37xx devices so that the clock driver is enabled by default, otherwise the SPI driver cannot be enabled. Signed-off-by: Marek Behun --- arch/arm/dts/armada-37xx.dtsi | 4 +-- configs/mvebu_db-88f3720_defconfig | 3 ++ configs/mvebu_espressobin-88f3720_defconfig | 3 ++ drivers/spi/Kconfig | 1 + drivers/spi/mvebu_a3700_spi.c | 52 ++++++++++++++++------------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/arch/arm/dts/armada-37xx.dtsi b/arch/arm/dts/armada-37xx.dtsi index c72fd25abc..5b4a1a49bb 100644 --- a/arch/arm/dts/armada-37xx.dtsi +++ b/arch/arm/dts/armada-37xx.dtsi @@ -301,8 +301,8 @@ #address-cells = <1>; #size-cells = <0>; #clock-cells = <0>; - clock-frequency = <160000>; - spi-max-frequency = <40000>; + spi-max-frequency = <50000000>; + clocks = <&nb_periph_clk 7>; status = "disabled"; }; diff --git a/configs/mvebu_db-88f3720_defconfig b/configs/mvebu_db-88f3720_defconfig index 67a8077a58..691d7211dc 100644 --- a/configs/mvebu_db-88f3720_defconfig +++ b/configs/mvebu_db-88f3720_defconfig @@ -36,6 +36,9 @@ CONFIG_DM_GPIO=y # CONFIG_MVEBU_GPIO is not set CONFIG_DM_I2C=y CONFIG_MISC=y +CONFIG_CLK=y +CONFIG_CLK_MVEBU=y +CONFIG_CLK_ARMADA_3720=y CONFIG_DM_MMC=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 48dae2d791..60259bcf2c 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -35,6 +35,9 @@ CONFIG_BLOCK_CACHE=y CONFIG_DM_GPIO=y CONFIG_DM_I2C=y CONFIG_MISC=y +CONFIG_CLK=y +CONFIG_CLK_MVEBU=y +CONFIG_CLK_ARMADA_3720=y CONFIG_DM_MMC=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index ec92b84ed2..06fa14ae36 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -101,6 +101,7 @@ config ICH_SPI config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" + select CLK_ARMADA_3720 help Enable the Marvell Armada 3700 SPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this diff --git a/drivers/spi/mvebu_a3700_spi.c b/drivers/spi/mvebu_a3700_spi.c index d1708a8d56..9b8b5e4d06 100644 --- a/drivers/spi/mvebu_a3700_spi.c +++ b/drivers/spi/mvebu_a3700_spi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -22,9 +23,8 @@ DECLARE_GLOBAL_DATA_PTR; #define MVEBU_SPI_A3700_CLK_POL BIT(7) #define MVEBU_SPI_A3700_FIFO_EN BIT(17) #define MVEBU_SPI_A3700_SPI_EN_0 BIT(16) -#define MVEBU_SPI_A3700_CLK_PRESCALE_BIT 0 -#define MVEBU_SPI_A3700_CLK_PRESCALE_MASK \ - (0x1f << MVEBU_SPI_A3700_CLK_PRESCALE_BIT) +#define MVEBU_SPI_A3700_CLK_PRESCALE_MASK 0x1f + /* SPI registers */ struct spi_reg { @@ -36,8 +36,7 @@ struct spi_reg { struct mvebu_spi_platdata { struct spi_reg *spireg; - unsigned int frequency; - unsigned int clock; + struct clk clk; }; static void spi_cs_activate(struct spi_reg *reg, int cs) @@ -178,17 +177,18 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz) { struct mvebu_spi_platdata *plat = dev_get_platdata(bus); struct spi_reg *reg = plat->spireg; - u32 data; + u32 data, prescale; data = readl(®->cfg); - /* Set Prescaler */ - data &= ~MVEBU_SPI_A3700_CLK_PRESCALE_MASK; + prescale = DIV_ROUND_UP(clk_get_rate(&plat->clk), hz); + if (prescale > 0x1f) + prescale = 0x1f; + else if (prescale > 0xf) + prescale = 0x10 + (prescale + 1) / 2; - /* Calculate Prescaler = (spi_input_freq / spi_max_freq) */ - if (hz > plat->frequency) - hz = plat->frequency; - data |= plat->clock / hz; + data &= ~MVEBU_SPI_A3700_CLK_PRESCALE_MASK; + data |= prescale & MVEBU_SPI_A3700_CLK_PRESCALE_MASK; writel(data, ®->cfg); @@ -252,21 +252,24 @@ static int mvebu_spi_probe(struct udevice *bus) static int mvebu_spi_ofdata_to_platdata(struct udevice *bus) { struct mvebu_spi_platdata *plat = dev_get_platdata(bus); + int ret; plat->spireg = (struct spi_reg *)devfdt_get_addr(bus); - /* - * FIXME - * Right now, mvebu does not have a clock infrastructure in U-Boot - * which should be used to query the input clock to the SPI - * controller. Once this clock driver is integrated into U-Boot - * it should be used to read the input clock and the DT property - * can be removed. - */ - plat->clock = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), - "clock-frequency", 160000); - plat->frequency = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), - "spi-max-frequency", 40000); + ret = clk_get_by_index(bus, 0, &plat->clk); + if (ret) { + dev_err(bus, "cannot get clock\n"); + return ret; + } + + return 0; +} + +static int mvebu_spi_remove(struct udevice *bus) +{ + struct mvebu_spi_platdata *plat = dev_get_platdata(bus); + + clk_free(&plat->clk); return 0; } @@ -294,4 +297,5 @@ U_BOOT_DRIVER(mvebu_spi) = { .ofdata_to_platdata = mvebu_spi_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct mvebu_spi_platdata), .probe = mvebu_spi_probe, + .remove = mvebu_spi_remove, };