From patchwork Tue Sep 5 10:30:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 810075 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xmjm63rvvz9s71 for ; Tue, 5 Sep 2017 20:35:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4A28DC21FC1; Tue, 5 Sep 2017 10:35:05 +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=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED 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 87C40C21D8D; Tue, 5 Sep 2017 10:35:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 55D7DC21FAA; Tue, 5 Sep 2017 10:34:46 +0000 (UTC) Received: from eusmtp01.atmel.com (eusmtp01.atmel.com [212.144.249.242]) by lists.denx.de (Postfix) with ESMTPS id CAAB7C21F25 for ; Tue, 5 Sep 2017 10:34:42 +0000 (UTC) Received: from apsmtp01.atmel.com (10.168.254.31) by eusmtp01.atmel.com (10.145.145.30) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Sep 2017 12:33:59 +0200 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Sep 2017 18:38:18 +0800 From: Wenyou Yang To: U-Boot Mailing List Date: Tue, 5 Sep 2017 18:30:07 +0800 Message-ID: <20170905103008.3099-2-wenyou.yang@microchip.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170905103008.3099-1-wenyou.yang@microchip.com> References: <20170905103008.3099-1-wenyou.yang@microchip.com> MIME-Version: 1.0 Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH 1/2] clk: at91: utmi: Set the reference 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" By default, it is assumed that the UTMI clock is generated from a 12 MHz reference clock (MAINCK). If it's not the case, the FREQ field of the SFR_UTMICKTRIM has to be updated to generate the UTMI clock in the proper way. The UTMI clock has a fixed rate of 480 MHz. In fact, there is no multiplier we can configure. The multiplier is managed internally, depending on the reference clock frequency, to achieve the target of 480 MHz. The patch is cloned from the patch of mailing-list: [PATCH v2] clk: at91: utmi: set the mainck rate Signed-off-by: Wenyou Yang --- arch/arm/mach-at91/include/mach/sama5_sfr.h | 5 ++ drivers/clk/at91/Kconfig | 4 ++ drivers/clk/at91/clk-utmi.c | 77 ++++++++++++++++++++++++++++- drivers/clk/at91/pmc.h | 3 ++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-at91/include/mach/sama5_sfr.h b/arch/arm/mach-at91/include/mach/sama5_sfr.h index b805a2c934..965631aad7 100644 --- a/arch/arm/mach-at91/include/mach/sama5_sfr.h +++ b/arch/arm/mach-at91/include/mach/sama5_sfr.h @@ -28,6 +28,9 @@ struct atmel_sfr { u32 l2cc_hramc; /* 0x58 */ }; +/* Register Mapping*/ +#define AT91_SFR_UTMICKTRIM 0x30 /* UTMI Clock Trimming Register */ + /* Bit field in DDRCFG */ #define ATMEL_SFR_DDRCFG_FDQIEN 0x00010000 #define ATMEL_SFR_DDRCFG_FDQSIEN 0x00020000 @@ -56,6 +59,8 @@ struct atmel_sfr { #define AT91_SFR_EBICFG_SCH1_OFF (0x0 << 12) #define AT91_SFR_EBICFG_SCH1_ON (0x1 << 12) +#define AT91_UTMICKTRIM_FREQ GENMASK(1, 0) + /* Bit field in AICREDIR */ #define ATMEL_SFR_AICREDIR_NSAIC 0x00000001 diff --git a/drivers/clk/at91/Kconfig b/drivers/clk/at91/Kconfig index 904ed48e51..2f112afa31 100644 --- a/drivers/clk/at91/Kconfig +++ b/drivers/clk/at91/Kconfig @@ -15,6 +15,10 @@ config CLK_AT91 config AT91_UTMI bool "Support UTMI PLL Clock" depends on CLK_AT91 + select REGMAP + select SPL_REGMAP + select SYSCON + select SPL_SYSCON help This option is used to enable the AT91 UTMI PLL clock driver. It is the clock provider of USB, and UPLLCK is the diff --git a/drivers/clk/at91/clk-utmi.c b/drivers/clk/at91/clk-utmi.c index af5362da42..875bf293f9 100644 --- a/drivers/clk/at91/clk-utmi.c +++ b/drivers/clk/at91/clk-utmi.c @@ -8,23 +8,80 @@ #include #include #include +#include #include #include +#include #include "pmc.h" DECLARE_GLOBAL_DATA_PTR; -#define UTMI_FIXED_MUL 40 +/* + * The purpose of this clock is to generate a 480 MHz signal. A different + * rate can't be configured. + */ +#define UTMI_RATE 480000000 static int utmi_clk_enable(struct clk *clk) { struct pmc_platdata *plat = dev_get_platdata(clk->dev); struct at91_pmc *pmc = plat->reg_base; + struct clk clk_dev; + ulong clk_rate; + u32 utmi_ref_clk_freq; u32 tmp; + int err; if (readl(&pmc->sr) & AT91_PMC_LOCKU) return 0; + /* + * If mainck rate is different from 12 MHz, we have to configure the + * FREQ field of the SFR_UTMICKTRIM register to generate properly + * the utmi clock. + */ + err = clk_get_by_index(clk->dev, 0, &clk_dev); + if (err) + return -EINVAL; + + clk_rate = clk_get_rate(&clk_dev); + switch (clk_rate) { + case 12000000: + utmi_ref_clk_freq = 0; + break; + case 16000000: + utmi_ref_clk_freq = 1; + break; + case 24000000: + utmi_ref_clk_freq = 2; + break; + /* + * Not supported on SAMA5D2 but it's not an issue since MAINCK + * maximum value is 24 MHz. + */ + case 48000000: + utmi_ref_clk_freq = 3; + break; + default: + printf("UTMICK: unsupported mainck rate\n"); + return -EINVAL; + } + + if (plat->regmap_sfr) { + err = regmap_read(plat->regmap_sfr, AT91_SFR_UTMICKTRIM, &tmp); + if (err) + return -EINVAL; + + tmp &= ~AT91_UTMICKTRIM_FREQ; + tmp |= utmi_ref_clk_freq; + err = regmap_write(plat->regmap_sfr, AT91_SFR_UTMICKTRIM, tmp); + if (err) + return -EINVAL; + } else if (utmi_ref_clk_freq) { + printf("UTMICK: sfr node required\n"); + return -EINVAL; + } + tmp = readl(&pmc->uckr); tmp |= AT91_PMC_UPLLEN | AT91_PMC_UPLLCOUNT | @@ -39,7 +96,8 @@ static int utmi_clk_enable(struct clk *clk) static ulong utmi_clk_get_rate(struct clk *clk) { - return gd->arch.main_clk_rate_hz * UTMI_FIXED_MUL; + /* UTMI clk rate is fixed. */ + return UTMI_RATE; } static struct clk_ops utmi_clk_ops = { @@ -47,6 +105,20 @@ static struct clk_ops utmi_clk_ops = { .get_rate = utmi_clk_get_rate, }; +static int utmi_clk_ofdata_to_platdata(struct udevice *dev) +{ + struct pmc_platdata *plat = dev_get_platdata(dev); + struct udevice *syscon; + + uclass_get_device_by_phandle(UCLASS_SYSCON, dev, + "regmap-sfr", &syscon); + + if (syscon) + plat->regmap_sfr = syscon_get_regmap(syscon); + + return 0; +} + static int utmi_clk_probe(struct udevice *dev) { return at91_pmc_core_probe(dev); @@ -62,6 +134,7 @@ U_BOOT_DRIVER(at91sam9x5_utmi_clk) = { .id = UCLASS_CLK, .of_match = utmi_clk_match, .probe = utmi_clk_probe, + .ofdata_to_platdata = utmi_clk_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct pmc_platdata), .ops = &utmi_clk_ops, }; diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index bd3caba48d..5abda764a2 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h @@ -8,8 +8,11 @@ #ifndef __AT91_PMC_H__ #define __AT91_PMC_H__ +#include + struct pmc_platdata { struct at91_pmc *reg_base; + struct regmap *regmap_sfr; }; int at91_pmc_core_probe(struct udevice *dev); From patchwork Tue Sep 5 10:30:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 810076 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xmjmh0sszz9sNr for ; Tue, 5 Sep 2017 20:36:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D48A2C21F2C; Tue, 5 Sep 2017 10:35:38 +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=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED 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 ABCDCC21FBB; Tue, 5 Sep 2017 10:35:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 172F6C21FC6; Tue, 5 Sep 2017 10:35:11 +0000 (UTC) Received: from eusmtp01.atmel.com (eusmtp01.atmel.com [212.144.249.243]) by lists.denx.de (Postfix) with ESMTPS id A33DEC21D8D for ; Tue, 5 Sep 2017 10:35:07 +0000 (UTC) Received: from apsmtp01.atmel.com (10.168.254.31) by eusmtp01.atmel.com (10.145.145.31) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Sep 2017 12:34:27 +0200 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Sep 2017 18:38:44 +0800 From: Wenyou Yang To: U-Boot Mailing List Date: Tue, 5 Sep 2017 18:30:08 +0800 Message-ID: <20170905103008.3099-3-wenyou.yang@microchip.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170905103008.3099-1-wenyou.yang@microchip.com> References: <20170905103008.3099-1-wenyou.yang@microchip.com> MIME-Version: 1.0 Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH 2/2] ARM: dts: at91: sama5: Add the sfr node 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For sama5d2, add the sfr node with syscon support. In order to access the SFR_UTMICKTRIM register for the utmi clock driver, add the phandle property for the utmi node to point to the sfr node. Signed-off-by: Wenyou Yang --- arch/arm/dts/sama5d2.dtsi | 6 ++++++ arch/arm/dts/sama5d3.dtsi | 2 ++ 2 files changed, 8 insertions(+) diff --git a/arch/arm/dts/sama5d2.dtsi b/arch/arm/dts/sama5d2.dtsi index d8a65145d6..4233ef8c18 100644 --- a/arch/arm/dts/sama5d2.dtsi +++ b/arch/arm/dts/sama5d2.dtsi @@ -122,6 +122,7 @@ compatible = "atmel,at91sam9x5-clk-utmi"; #clock-cells = <0>; clocks = <&main>; + regmap-sfr = <&sfr>; u-boot,dm-pre-reloc; }; @@ -660,6 +661,11 @@ status = "disabled"; }; + sfr: sfr@f8030000 { + compatible = "atmel,sama5d2-sfr", "syscon"; + reg = <0xf8030000 0x98>; + }; + sckc@f8048050 { compatible = "atmel,at91sam9x5-sckc"; reg = <0xf8048050 0x4>; diff --git a/arch/arm/dts/sama5d3.dtsi b/arch/arm/dts/sama5d3.dtsi index 84ee089202..ee0e14e516 100644 --- a/arch/arm/dts/sama5d3.dtsi +++ b/arch/arm/dts/sama5d3.dtsi @@ -998,6 +998,8 @@ interrupt-parent = <&pmc>; interrupts = ; clocks = <&main>; + regmap-sfr = <&sfr>; + u-boot,dm-pre-reloc; }; mck: masterck {