From patchwork Sun Nov 22 16:11:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1404511 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=libero.it header.i=@libero.it header.a=rsa-sha256 header.s=s2014 header.b=KKejVi46; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CfFjX2ppNz9sSf for ; Mon, 23 Nov 2020 03:14:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 18C4E82627; Sun, 22 Nov 2020 17:12:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=libero.it header.i=@libero.it header.b="KKejVi46"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F0B7825D6; Sun, 22 Nov 2020 17:12:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,FREEMAIL_FROM, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from libero.it (smtp-31-i2.italiaonline.it [213.209.12.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E4162825C4 for ; Sun, 22 Nov 2020 17:11:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dariobin@libero.it Received: from passgat-Modern-14-A10M.homenet.telecomitalia.it ([87.2.94.187]) by smtp-31.iol.local with ESMTPA id grxekH1hlQgqqgrxvkn9r7; Sun, 22 Nov 2020 17:11:51 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1606061511; bh=NnKY4xIlioeJarAMZY5T1hh0cXEKf5VXZ9udLfF082w=; h=From; b=KKejVi46DzA+m3ST88ihCoEEgb5AKXnpo7EBmmdClKheC5MKtw1nPrECBR69Cn8Oh Jxwe/Yzb36c8Qp1B7h8jA16z4hc7W+x2yje3Gh3SlCBP36Y/TXNbjB4OB9LEmSdkHU tQweMEL6r7dUN+LIiys/9LDdj0srYB6DpBHX2L/jULkc90VQBOg0X3XJGzR02RdE6R a8qz5ZYcbhlTNvBc/DK2jhzaRbaaZj8mOE5XT17gusLP0lg66g+s2iA4c8PbU5TBpU 3wqMTKWCe3/VdvJYOT8nCkz57BXwecfyVcJ9b8VgbR64rxaF5Mo6eJpJ/njKlDdJ7o NnYBL1QVo6oXA== X-CNFS-Analysis: v=2.4 cv=K4fnowaI c=1 sm=1 tr=0 ts=5fba8dc7 a=/8YHF75YQ9f7f3UrJFxoKA==:117 a=/8YHF75YQ9f7f3UrJFxoKA==:17 a=giGMya_9bqG73uW0DOkA:9 a=VebPhTEsAmedPqsa:21 a=0EUnVi4Mf4TanU7B:21 From: Dario Binacchi To: u-boot@lists.denx.de Cc: Dario Binacchi , Lukasz Majewski Subject: [PATCH v6 13/28] clk: ti: add support for clkctrl clocks Date: Sun, 22 Nov 2020 17:11:13 +0100 Message-Id: <20201122161128.13753-14-dariobin@libero.it> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201122161128.13753-1-dariobin@libero.it> References: <20201122161128.13753-1-dariobin@libero.it> X-CMAE-Envelope: MS4xfATbyotLDEueWPrYLjBeORDEl0hPUqTPrHkb1ohIs91o+kqLl3diTiLc3kHJ8LRGiWRav2Z3Oq0fosg3/eIg8mJZYd92mc02Sk3xS1CqIGTZOmAgajDW 0inuObR6oGTUMzKLA+sGoCjzg5+hr25NOTAhnHE4HYEFRdhqgrTrVC2O6nanf2FvTgG3kJmVD7J+i89bI2Q8BWPT5Va1bTO2qjN1JMbf/7M8bZOx2Lr63+2a VlVxLn82wIBXmJ3Xde0b2cB78nXecg6E3iuVk9mI/KA= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Until now the clkctrl clocks have been enabled/disabled through platform routines. Thanks to this patch they can be enabled and configured directly by the probed devices that need to use them. For DT binding details see Linux doc: - Documentation/devicetree/bindings/clock/ti-clkctrl.txt Signed-off-by: Dario Binacchi --- (no changes since v5) Changes in v5: - Move the clk-ti-ctrl.c file to drivers/clk/ti with the name clk-ctrl.c. Changes in v4: - Include device_compat.h header for dev_xxx macros. - Fix compilation errors on the dev parameter of the dev_xx macros. Changes in v3: - Fix access to registers listed by device tree following resync of am33xx-clock.dtsi with Linux 5.9-rc7. - Remove doc/device-tree-bindings/clock/ti,clkctrl.txt. - Add to commit message the references to linux kernel dt binding documentation. drivers/clk/ti/Kconfig | 6 ++ drivers/clk/ti/Makefile | 1 + drivers/clk/ti/clk-ctrl.c | 154 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 drivers/clk/ti/clk-ctrl.c diff --git a/drivers/clk/ti/Kconfig b/drivers/clk/ti/Kconfig index 30959a316a..9e257a2eb7 100644 --- a/drivers/clk/ti/Kconfig +++ b/drivers/clk/ti/Kconfig @@ -10,6 +10,12 @@ config CLK_TI_AM3_DPLL This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL provides all interface clocks and functional clocks to the processor. +config CLK_TI_CTRL + bool "TI OMAP4 clock controller" + depends on CLK && OF_CONTROL + help + This enables the clock controller driver support on TI's SoCs. + config CLK_TI_DIVIDER bool "TI divider clock driver" depends on CLK && OF_CONTROL && CLK_CCF diff --git a/drivers/clk/ti/Makefile b/drivers/clk/ti/Makefile index f8aa735c83..ed45f18311 100644 --- a/drivers/clk/ti/Makefile +++ b/drivers/clk/ti/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-am3-dpll.o clk-am3-dpll-x2.o +obj-$(CONFIG_CLK_TI_CTRL) += clk-ctrl.o obj-$(CONFIG_CLK_TI_DIVIDER) += clk-divider.o obj-$(CONFIG_CLK_TI_GATE) += clk-gate.o obj-$(CONFIG_CLK_TI_MUX) += clk-mux.o diff --git a/drivers/clk/ti/clk-ctrl.c b/drivers/clk/ti/clk-ctrl.c new file mode 100644 index 0000000000..74271aaf56 --- /dev/null +++ b/drivers/clk/ti/clk-ctrl.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * OMAP clock controller support + * + * Copyright (C) 2020 Dario Binacchi + */ + +#include +#include +#include +#include +#include + +struct clk_ti_ctrl_offs { + fdt_addr_t start; + fdt_size_t end; +}; + +struct clk_ti_ctrl_priv { + int offs_num; + struct clk_ti_ctrl_offs *offs; +}; + +static int clk_ti_ctrl_check_offs(struct clk *clk, fdt_addr_t offs) +{ + struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev); + int i; + + for (i = 0; i < priv->offs_num; i++) { + if (offs >= priv->offs[i].start && offs <= priv->offs[i].end) + return 0; + } + + return -EFAULT; +} + +static int clk_ti_ctrl_disable(struct clk *clk) +{ + struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev); + u32 *clk_modules[2] = { }; + fdt_addr_t offs; + int err; + + offs = priv->offs[0].start + clk->id; + err = clk_ti_ctrl_check_offs(clk, offs); + if (err) { + dev_err(clk->dev, "invalid offset: 0x%lx\n", offs); + return err; + } + + clk_modules[0] = (u32 *)(offs); + dev_dbg(clk->dev, "module address=%p\n", clk_modules[0]); + do_disable_clocks(NULL, clk_modules, 1); + return 0; +} + +static int clk_ti_ctrl_enable(struct clk *clk) +{ + struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev); + u32 *clk_modules[2] = { }; + fdt_addr_t offs; + int err; + + offs = priv->offs[0].start + clk->id; + err = clk_ti_ctrl_check_offs(clk, offs); + if (err) { + dev_err(clk->dev, "invalid offset: 0x%lx\n", offs); + return err; + } + + clk_modules[0] = (u32 *)(offs); + dev_dbg(clk->dev, "module address=%p\n", clk_modules[0]); + do_enable_clocks(NULL, clk_modules, 1); + return 0; +} + +static ulong clk_ti_ctrl_get_rate(struct clk *clk) +{ + return 0; +} + +static int clk_ti_ctrl_of_xlate(struct clk *clk, + struct ofnode_phandle_args *args) +{ + if (args->args_count != 2) { + dev_err(clk->dev, "invaild args_count: %d\n", args->args_count); + return -EINVAL; + } + + if (args->args_count) + clk->id = args->args[0]; + else + clk->id = 0; + + dev_dbg(clk->dev, "name=%s, id=%ld\n", clk->dev->name, clk->id); + return 0; +} + +static int clk_ti_ctrl_ofdata_to_platdata(struct udevice *dev) +{ + struct clk_ti_ctrl_priv *priv = dev_get_priv(dev); + fdt_size_t fdt_size; + int i, size; + + size = dev_read_size(dev, "reg"); + if (size < 0) { + dev_err(dev, "failed to get 'reg' size\n"); + return size; + } + + priv->offs_num = size / 2 / sizeof(u32); + dev_dbg(dev, "size=%d, regs_num=%d\n", size, priv->offs_num); + + priv->offs = kmalloc_array(priv->offs_num, sizeof(*priv->offs), + GFP_KERNEL); + if (!priv->offs) + return -ENOMEM; + + for (i = 0; i < priv->offs_num; i++) { + priv->offs[i].start = + dev_read_addr_size_index(dev, i, &fdt_size); + if (priv->offs[i].start == FDT_ADDR_T_NONE) { + dev_err(dev, "failed to get offset %d\n", i); + return -EINVAL; + } + + priv->offs[i].end = priv->offs[i].start + fdt_size; + dev_dbg(dev, "start=0x%08lx, end=0x%08lx\n", + priv->offs[i].start, priv->offs[i].end); + } + + return 0; +} + +static struct clk_ops clk_ti_ctrl_ops = { + .of_xlate = clk_ti_ctrl_of_xlate, + .enable = clk_ti_ctrl_enable, + .disable = clk_ti_ctrl_disable, + .get_rate = clk_ti_ctrl_get_rate, +}; + +static const struct udevice_id clk_ti_ctrl_ids[] = { + {.compatible = "ti,clkctrl"}, + {}, +}; + +U_BOOT_DRIVER(clk_ti_ctrl) = { + .name = "ti_ctrl_clk", + .id = UCLASS_CLK, + .of_match = clk_ti_ctrl_ids, + .ofdata_to_platdata = clk_ti_ctrl_ofdata_to_platdata, + .ops = &clk_ti_ctrl_ops, + .priv_auto_alloc_size = sizeof(struct clk_ti_ctrl_priv), +};