Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3595382imm; Mon, 4 Jun 2018 06:20:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLxiiJqQE4m0/WDRV7IDAwOq66WN3UsOM9qLRT3RFaXw1kECPScfyQkeWwn1RxFyd8IQ/8v X-Received: by 2002:a17:902:7d8e:: with SMTP id a14-v6mr18359953plm.218.1528118438935; Mon, 04 Jun 2018 06:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528118438; cv=none; d=google.com; s=arc-20160816; b=Kz3STZ1qkQc3Uo4O4e6Vyo47jnnsNlO6b2VCUpXS/o8GoeINUThcuBQMM2iyQxA3Ir y/UebkJWeSoMUDtEOM/3GZTScArREcgqb6i0DnZ0Yf00+f51qkGwLLxR86gagDvbMztx fvjjg2v18DB3Ez2hPNLYnzmEk0fS+baB1nF3UIe8s0fzfLiDQVjcf8QZ36ioqod0+rau TDm3Usjyiy9hXLjSH49SJzptaomibZYt9oYysmqPs3aiUhcpfkNrKVXaU+0+cGI4vgNI JxBytrLr2it+nxeJjaltBzyIkKhT0Lqdt+yNjvb8zWJEfyAYEeY4ZxKub9NO7SaCpvDE 74tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=heWU3nyRvqEoPPdi/ddj0ZGAxKBvT6vh3rz2xoUGD5I=; b=b+PulK3hvh/ENsCdyM2OuA632kjfeKTJNhskD/nnFYh4ZbuRZ935pn0LCxX9Gkg+Rq QJrgPpcwRgRw89pfYCv039pJLviQSKFuFNirJKothnNZO1ietTiaWt+G9kH+o2NTsEDs jvhC9AkcM72/K+KERitot5YurLCtUOewE/+pnCgEAJ8fwjHsVRlhvj02N3oIj+drVjIC m5mcOd3GmOK3pv4s49exMu1Zj6MOlYquHMSO2Y++smTI6mJIYJt7m2rxnpqe5B8BAwPy m9HVupliS5Ry+OT3SJ+iqAlmHJ5v9tyPqhth4gHYppFjDiyfW7Sy9Y8cUhhpPe9QDACW Z+oA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si27605858plg.230.2018.06.04.06.20.23; Mon, 04 Jun 2018 06:20:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753369AbeFDNTZ (ORCPT + 99 others); Mon, 4 Jun 2018 09:19:25 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:37371 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753144AbeFDNTW (ORCPT ); Mon, 4 Jun 2018 09:19:22 -0400 Received: by mail-lf0-f68.google.com with SMTP id r2-v6so25151975lff.4; Mon, 04 Jun 2018 06:19:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=heWU3nyRvqEoPPdi/ddj0ZGAxKBvT6vh3rz2xoUGD5I=; b=uDYPIpCdzn4dO+jiGHq1YgqL18r/NX9ReQ7kvrBQnmLxaxsBhMVaoM4979LYxljLAi sZzJ/cgL0jrKeB6CelwrqeYtv9QKB6iuVy2QX5f96+oXqtVyy0U3q/pCtwMzOnlc1pp6 HLUdfgXvBwXck/JmS+lO0LTZi6xPhHmtALTwwzWbj+0M82+Xp6jhQjmnAWsoCjsY7tZ5 QrSIJ5nk085fs9DxX2V/JzlqnH0BDdjq/0bzj6Mje0iAFTgOlemKQLUxdjZkelEmRZdD 8FXkhBq5o/WTtE0omOSUug+lVx/gUwkqER6kbUnL/XTaejW6LOSdRP4HQcJTGHcgsZAV tkcQ== X-Gm-Message-State: APt69E2S+K7kdm49/1k335QRq+CxDhKS6YTBfPT6EQU+MWlXXQ43K2rM zmx7tECsEHdJmksiNIvkMv8= X-Received: by 2002:a19:d1d4:: with SMTP id i203-v6mr1323543lfg.93.1528118360696; Mon, 04 Jun 2018 06:19:20 -0700 (PDT) Received: from localhost.localdomain ([213.255.186.34]) by smtp.gmail.com with ESMTPSA id h4-v6sm4633363ljc.8.2018.06.04.06.19.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 06:19:20 -0700 (PDT) Date: Mon, 4 Jun 2018 16:19:13 +0300 From: Matti Vaittinen To: mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, lee.jones@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, mazziesaccount@gmail.com Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, mikko.mutanen@fi.rohmeurope.com, heikki.haikola@fi.rohmeurope.com Subject: [PATCH v5 4/4] clk: bd71837: Add driver for BD71837 PMIC clock Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support BD71837 gateable 32768 Hz clock. Signed-off-by: Matti Vaittinen --- drivers/clk/Kconfig | 7 +++ drivers/clk/Makefile | 1 + drivers/clk/clk-bd71837.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 drivers/clk/clk-bd71837.c diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 41492e980ef4..e693496f202a 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -279,6 +279,13 @@ config COMMON_CLK_STM32H7 ---help--- Support for stm32h7 SoC family clocks +config COMMON_CLK_BD71837 + tristate "Clock driver for ROHM BD71837 PMIC MFD" + depends on MFD_BD71837 + help + This driver supports ROHM BD71837 PMIC clock. + + source "drivers/clk/bcm/Kconfig" source "drivers/clk/hisilicon/Kconfig" source "drivers/clk/imgtec/Kconfig" diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index de6d06ac790b..8393c4af7d5a 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -21,6 +21,7 @@ endif obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o +obj-$(CONFIG_COMMON_CLK_BD71837) += clk-bd71837.o obj-$(CONFIG_COMMON_CLK_CDCE706) += clk-cdce706.o obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o diff --git a/drivers/clk/clk-bd71837.c b/drivers/clk/clk-bd71837.c new file mode 100644 index 000000000000..5ba6c05c5a98 --- /dev/null +++ b/drivers/clk/clk-bd71837.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 ROHM Semiconductors +// bd71837.c -- ROHM BD71837MWV clock driver + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +struct bd71837_clk { + struct clk_hw hw; + uint8_t reg; + uint8_t mask; + unsigned long rate; + struct platform_device *pdev; + struct bd71837 *mfd; +}; + +static int bd71837_clk_set(struct clk_hw *hw, int status) +{ + struct bd71837_clk *c = container_of(hw, struct bd71837_clk, hw); + + return bd71837_update_bits(c->mfd, c->reg, c->mask, status); +} + +static void bd71837_clk_disable(struct clk_hw *hw) +{ + int rv; + struct bd71837_clk *c = container_of(hw, struct bd71837_clk, hw); + + rv = bd71837_clk_set(hw, 0); + if (rv) + dev_dbg(&c->pdev->dev, "Failed to disable 32K clk (%d)\n", rv); +} + +static int bd71837_clk_enable(struct clk_hw *hw) +{ + return bd71837_clk_set(hw, 1); +} + +static int bd71837_clk_is_enabled(struct clk_hw *hw) +{ + struct bd71837_clk *c = container_of(hw, struct bd71837_clk, hw); + + return c->mask & bd71837_reg_read(c->mfd, c->reg); +} + +static unsigned long bd71837_clk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct bd71837_clk *c = container_of(hw, struct bd71837_clk, hw); + + return c->rate; +} + +static const struct clk_ops bd71837_clk_ops = { + .recalc_rate = &bd71837_clk_recalc_rate, + .prepare = &bd71837_clk_enable, + .unprepare = &bd71837_clk_disable, + .is_prepared = &bd71837_clk_is_enabled, +}; + +static int bd71837_clk_probe(struct platform_device *pdev) +{ + struct bd71837_clk *c; + int rval = -ENOMEM; + struct bd71837 *mfd = dev_get_drvdata(pdev->dev.parent); + struct clk_init_data init = { + .name = "bd71837-32k-out", + .ops = &bd71837_clk_ops, + }; + + c = devm_kzalloc(&pdev->dev, sizeof(*c), GFP_KERNEL); + if (!c) + goto err_out; + + c->reg = BD71837_REG_OUT32K; + c->mask = BD71837_OUT32K_EN; + c->rate = BD71837_CLK_RATE; + c->mfd = mfd; + c->pdev = pdev; + + of_property_read_string_index(pdev->dev.parent->of_node, + "clock-output-names", 0, + &init.name); + + c->hw.init = &init; + + rval = devm_clk_hw_register(&pdev->dev, &c->hw); + if (rval) { + dev_err(&pdev->dev, "failed to register 32K clk"); + goto err_out; + } + + if (pdev->dev.parent->of_node) { + rval = of_clk_add_hw_provider(pdev->dev.parent->of_node, + of_clk_hw_simple_get, + &c->hw); + if (rval) { + dev_err(&pdev->dev, "adding clk provider failed\n"); + goto err_out; + } + } + + rval = clk_hw_register_clkdev(&c->hw, init.name, NULL); + if (rval) { + dev_err(&pdev->dev, "failed to register clkdev for bd71837"); + goto err_clean_provider; + } + + platform_set_drvdata(pdev, c); + + return 0; + +err_clean_provider: + of_clk_del_provider(pdev->dev.parent->of_node); +err_out: + return rval; +} + +static int bd71837_clk_remove(struct platform_device *pdev) +{ + if (pdev->dev.parent->of_node) + of_clk_del_provider(pdev->dev.parent->of_node); + return 0; +} + +static struct platform_driver bd71837_clk = { + .driver = { + .name = "bd71837-clk", + }, + .probe = bd71837_clk_probe, + .remove = bd71837_clk_remove, +}; + +module_platform_driver(bd71837_clk); + +MODULE_AUTHOR("Matti Vaittinen "); +MODULE_DESCRIPTION("BD71837 chip clk driver"); +MODULE_LICENSE("GPL"); -- 2.14.3