From patchwork Sun Dec 3 09:17:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 10089127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BFFB560595 for ; Sun, 3 Dec 2017 09:18:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B572F28EF4 for ; Sun, 3 Dec 2017 09:18:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA3482911F; Sun, 3 Dec 2017 09:18:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA31028F19 for ; Sun, 3 Dec 2017 09:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HKFwNU54FEDpu8aSHBVf1+f/okobjNGkKk2T4v68Bqc=; b=Beb9tYxPV0XWhqAHZbQdRZZypE NrPxB+LPIRZdhQ8DEVxgvE8R2n+6MXXJqA6B7T2X5zvUiF5dX8N8Gy6YG8RGh4GtQZ3OczwcvB8Sv brXegQuhkF+gndkA/jmBwaXoJ02AUrVosh0RF4kLGw23Et7CDBD8YQUlRLC0fzDPbNPzPXh0whMW3 rZnTjYEmpoyTvMSu8u2Mf7x6T7Fm3Ijz5DjjxqKRLLXHfFcYkyLq8V7W4M4DK/VkEkYjqjHDUZOU5 1skjIRlQn5kv2HQIuW+jbXfBLpKYquKgKLecc8FWILMDCFv/eIX6HZCrJXtPH9D/O52HcUCJ6YTwp osGfa8mA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLQQ1-0002EV-4O; Sun, 03 Dec 2017 09:18:37 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLQPu-0002AC-1k for linux-amlogic@lists.infradead.org; Sun, 03 Dec 2017 09:18:33 +0000 Received: by mail-wr0-x242.google.com with SMTP id h1so14111877wre.12 for ; Sun, 03 Dec 2017 01:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mkRAo0dkuMa2rKkkNiFDET8dNFOYAaVa5//vYqa96Ew=; b=jiYQHhdHAp8x0+iDcjqC6RHlq8/N0hHTLCznw0mVDayYQbMZNFCrxmjUSvsIvXC3tt GrrCMfxVaoOgVlr01ssQIeyeMabMS18ptDRBpKbJSm6QBEdvj+hq23M1cyY4KJvtEWjA Ssj4QS2LMM9MoZWqkPF8mNDE8jgs7QK6or7jBRcT1EFMw/97Tr5o25h2RgiFAtiNtMWy ZoEQ31O+NiEdu5V8WzLs3e6vvKwwntH+H7osrkwL6kW6MbuoXFmok++72wTgdr0mnt2J zfKzTFA1Ll71wRYjkY3dEdgdIzi1TXhfjG2O64DIYphx4Jt5htn1kcPNsqK0rqlNAxUd v/LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mkRAo0dkuMa2rKkkNiFDET8dNFOYAaVa5//vYqa96Ew=; b=Ch/zfOjWeoFSTfck32voEzyttIvceY8Vj4YflfJZYIfRzsPnL/PrBWRITmUpBiHvRr lflLXfrgKzbpQtR6eW/t8O0PIU+gqEW7fi3jS8GcE64OVOb3WjxwjgGtkzzMjL2xLlUd iGweGu/VuTOy13zJFvtCd6x0qlcPvCYND34kfuKD+8lAsKHm/VIF2LDcb+CKYuO9UYNJ PH7dng1wg8vfhyZ6QxPjhukzC4JqJnjo9Srx25i432yHsHeTukf3lWzfRmBJbwRemD6P Fzhuyjh0bxK+lLg47LWG2bGOS0BGZYXjbv5PgT8Uf1a7C8+TPBgOw+MfXQJs49ZRpZYt JZpQ== X-Gm-Message-State: AJaThX4gSK+nA8LEcC4id1+zs77VexeiD7h1eVnETcL5WLMOmIna6Pdf KdpRnRPjF8dYk3E3THfdMbQ= X-Google-Smtp-Source: AGs4zMa1SX4BP0S719u/Fle/++o5vI91biWWBW6bPygNmITGUwrb2dc5mQKa49gef6ifLkSz/DLPcA== X-Received: by 10.223.156.133 with SMTP id d5mr10343130wre.43.1512292690306; Sun, 03 Dec 2017 01:18:10 -0800 (PST) Received: from sark.homenet.telecomitalia.it (host96-211-dynamic.211-62-r.retail.telecomitalia.it. [62.211.211.96]) by smtp.gmail.com with ESMTPSA id y99sm5414172wmh.0.2017.12.03.01.18.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Dec 2017 01:18:09 -0800 (PST) From: Beniamino Galvani To: u-boot@lists.denx.de Subject: [PATCH 4/4] meson: use the clock driver Date: Sun, 3 Dec 2017 10:17:13 +0100 Message-Id: <20171203091713.22029-5-b.galvani@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171203091713.22029-1-b.galvani@gmail.com> References: <20171203091713.22029-1-b.galvani@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171203_011830_498278_D71D7838 X-CRM114-Status: GOOD ( 13.25 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Albert Aribaud , Neil Armstrong , Simon Glass , Beniamino Galvani , linux-amlogic@lists.infradead.org, Heiko Schocher , =?UTF-8?q?Andreas=20F=C3=A4rber?= MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the clk framework to initialize clocks from drivers that need them instead of having hardcoded frequencies and initializations from board code. Signed-off-by: Beniamino Galvani Reviewed-by: Simon Glass --- arch/arm/include/asm/arch-meson/gxbb.h | 10 ---------- arch/arm/include/asm/arch-meson/i2c.h | 11 ----------- board/amlogic/odroid-c2/odroid-c2.c | 4 +--- board/amlogic/p212/p212.c | 3 +-- drivers/i2c/meson_i2c.c | 20 +++++++++++++++++--- 5 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 arch/arm/include/asm/arch-meson/i2c.h diff --git a/arch/arm/include/asm/arch-meson/gxbb.h b/arch/arm/include/asm/arch-meson/gxbb.h index 95a6fe6998..48a2ab7425 100644 --- a/arch/arm/include/asm/arch-meson/gxbb.h +++ b/arch/arm/include/asm/arch-meson/gxbb.h @@ -40,14 +40,4 @@ /* Ethernet memory power domain */ #define GXBB_MEM_PD_REG_0_ETH_MASK (BIT(2) | BIT(3)) -/* Clock gates */ -#define GXBB_GCLK_MPEG_0 GXBB_HIU_ADDR(0x50) -#define GXBB_GCLK_MPEG_1 GXBB_HIU_ADDR(0x51) -#define GXBB_GCLK_MPEG_2 GXBB_HIU_ADDR(0x52) -#define GXBB_GCLK_MPEG_OTHER GXBB_HIU_ADDR(0x53) -#define GXBB_GCLK_MPEG_AO GXBB_HIU_ADDR(0x54) - -#define GXBB_GCLK_MPEG_0_I2C BIT(9) -#define GXBB_GCLK_MPEG_1_ETH BIT(3) - #endif /* __GXBB_H__ */ diff --git a/arch/arm/include/asm/arch-meson/i2c.h b/arch/arm/include/asm/arch-meson/i2c.h deleted file mode 100644 index 783bc3786f..0000000000 --- a/arch/arm/include/asm/arch-meson/i2c.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright 2017 - Beniamino Galvani - * - * SPDX-License-Identifier: GPL-2.0+ - */ -#ifndef _MESON_I2C_H_ -#define _MESON_I2C_H_ - -#define MESON_I2C_CLK_RATE 167000000 - -#endif diff --git a/board/amlogic/odroid-c2/odroid-c2.c b/board/amlogic/odroid-c2/odroid-c2.c index a5ea8dc5af..833f01b4cf 100644 --- a/board/amlogic/odroid-c2/odroid-c2.c +++ b/board/amlogic/odroid-c2/odroid-c2.c @@ -34,9 +34,7 @@ int misc_init_r(void) GXBB_ETH_REG_0_PHY_CLK_EN | GXBB_ETH_REG_0_CLK_EN); - /* Enable power and clock gate */ - setbits_le32(GXBB_GCLK_MPEG_0, GXBB_GCLK_MPEG_0_I2C); - setbits_le32(GXBB_GCLK_MPEG_1, GXBB_GCLK_MPEG_1_ETH); + /* Enable power */ clrbits_le32(GXBB_MEM_PD_REG_0, GXBB_MEM_PD_REG_0_ETH_MASK); /* Reset PHY on GPIOZ_14 */ diff --git a/board/amlogic/p212/p212.c b/board/amlogic/p212/p212.c index ece8096c5c..907bbb286e 100644 --- a/board/amlogic/p212/p212.c +++ b/board/amlogic/p212/p212.c @@ -36,8 +36,7 @@ int misc_init_r(void) out_le32(GXBB_ETH_REG_2, 0x10110181); out_le32(GXBB_ETH_REG_3, 0xe40908ff); - /* Enable power and clock gate */ - setbits_le32(GXBB_GCLK_MPEG_1, GXBB_GCLK_MPEG_1_ETH); + /* Enable power */ clrbits_le32(GXBB_MEM_PD_REG_0, GXBB_MEM_PD_REG_0_ETH_MASK); if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { diff --git a/drivers/i2c/meson_i2c.c b/drivers/i2c/meson_i2c.c index 2434d9ed53..1d92b09c32 100644 --- a/drivers/i2c/meson_i2c.c +++ b/drivers/i2c/meson_i2c.c @@ -4,8 +4,8 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include -#include #include +#include #include #include @@ -43,6 +43,7 @@ struct i2c_regs { }; struct meson_i2c { + struct clk clk; struct i2c_regs *regs; struct i2c_msg *msg; bool last; @@ -209,9 +210,13 @@ static int meson_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, static int meson_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) { struct meson_i2c *i2c = dev_get_priv(bus); - unsigned int clk_rate = MESON_I2C_CLK_RATE; + ulong clk_rate; unsigned int div; + clk_rate = clk_get_rate(&i2c->clk); + if (IS_ERR_VALUE(clk_rate)) + return -EINVAL; + div = DIV_ROUND_UP(clk_rate, speed * 4); /* clock divider has 12 bits */ @@ -226,7 +231,7 @@ static int meson_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) clrsetbits_le32(&i2c->regs->ctrl, REG_CTRL_CLKDIVEXT_MASK, (div >> 10) << REG_CTRL_CLKDIVEXT_SHIFT); - debug("meson i2c: set clk %u, src %u, div %u\n", speed, clk_rate, div); + debug("meson i2c: set clk %u, src %lu, div %u\n", speed, clk_rate, div); return 0; } @@ -234,6 +239,15 @@ static int meson_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) static int meson_i2c_probe(struct udevice *bus) { struct meson_i2c *i2c = dev_get_priv(bus); + int ret; + + ret = clk_get_by_index(bus, 0, &i2c->clk); + if (ret < 0) + return ret; + + ret = clk_enable(&i2c->clk); + if (ret) + return ret; i2c->regs = dev_read_addr_ptr(bus); clrbits_le32(&i2c->regs->ctrl, REG_CTRL_START);