From patchwork Tue Jan 2 11:47:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryder Lee X-Patchwork-Id: 10140439 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 894FF60362 for ; Tue, 2 Jan 2018 12:07:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84E59287BE for ; Tue, 2 Jan 2018 12:07:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 799FC28A98; Tue, 2 Jan 2018 12:07:29 +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_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable 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 16B3A287BE for ; Tue, 2 Jan 2018 12:07:29 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=aIgpp47Wfb/Wk/XSpl1Zoe4mfPNRibql7HQ1rAlFJAk=; b=RgaiEeXeBHNp6b LrXVDvyxPJ9+Gcq3WBwi3i5/BPqPoi3JYxpziUACYDxbeOtHJJGXMDWJcpqdrmTJM1eGuXAXW46Y8 o+p7SHOn/wjmHKrMGPRdUgas7PvXOspZWFNOHqoU/rphGHk76iExI2B+m3nAhkNGb1kvD52BlPX0g 3nUaI79kVhUScUu5tfTBf5tUy0fwbtNoTmhyQ9zFifgK3VlZZpthCdg/SESi00rF+UAQvivyzTksL WtfXbcZVNiHYe03eyUag+nfquetjRnBwnKyh5ud00CPZTLTa0KcOUof5mHRxIDwhNMSEHfWkzketT 10LOnhpGc1t7zW9cs2wg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eWLLp-0002rc-N4; Tue, 02 Jan 2018 12:07:25 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eWLHx-0007YZ-3H; Tue, 02 Jan 2018 12:03:40 +0000 X-UUID: 5b18df5ade7c49f89ca28befa4458c27-20180102 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 318063103; Tue, 02 Jan 2018 19:47:36 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 2 Jan 2018 19:47:34 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 2 Jan 2018 19:47:34 +0800 From: Ryder Lee To: Mark Brown , Lee Jones Subject: [PATCH 05/12] mfd: mtk-audsys: add MediaTek audio subsystem driver Date: Tue, 2 Jan 2018 19:47:30 +0800 Message-ID: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180102_040325_724842_E2CDBDCD X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Ryder Lee , Garlic Tseng , Stephen Boyd , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a common driver for the top block of the MediaTek audio subsystem. This is a wrapper which manages resources for audio components. Signed-off-by: Ryder Lee --- drivers/mfd/Kconfig | 9 ++++ drivers/mfd/Makefile | 2 + drivers/mfd/mtk-audsys.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 drivers/mfd/mtk-audsys.c diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 1d20a80..ea50b51 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -368,6 +368,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MEDIATEK_AUDSYS + tristate "MediaTek audio subsystem interface" + select MDF_CORE + select REGMAP_MMIO + help + Select this if you have a audio subsystem in MediaTek SoC. + The audio subsystem has at least a clock driver part and some + audio components. + config MFD_MXS_LRADC tristate "Freescale i.MX23/i.MX28 LRADC" depends on ARCH_MXS || COMPILE_TEST diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index d9474ad..3e20927 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -101,6 +101,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MEDIATEK_AUDSYS) += mtk-audsys.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o diff --git a/drivers/mfd/mtk-audsys.c b/drivers/mfd/mtk-audsys.c new file mode 100644 index 0000000..89399e1 --- /dev/null +++ b/drivers/mfd/mtk-audsys.c @@ -0,0 +1,138 @@ +/* + * Mediatek audio subsystem core driver + * + * Copyright (c) 2017 MediaTek Inc. + * + * Author: Ryder Lee + * + * For licencing details see kernel-base/COPYING + * + */ + +#include +#include +#include +#include +#include + +#define AUDSYS_MAX_CLK_NUM 3 + +struct sys_dev { + struct device *dev; + struct regmap *regmap; + int clk_num; + struct clk *clks[]; +}; + +static const struct regmap_config aud_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = 0x15e0, + .cache_type = REGCACHE_NONE, +}; + +static int mtk_subsys_enable(struct sys_dev *sys) +{ + struct device *dev = sys->dev; + struct clk *clk; + int i, ret; + + for (i = 0; i < sys->clk_num; i++) { + clk = of_clk_get(dev->of_node, i); + if (IS_ERR(clk)) { + if (PTR_ERR(clk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + break; + } + sys->clks[i] = clk; + } + + for (i = 0; i < sys->clk_num && sys->clks[i]; i++) { + ret = clk_prepare_enable(sys->clks[i]); + if (ret) + goto err_enable_clks; + } + + return 0; + +err_enable_clks: + while (--i >= 0) + clk_disable_unprepare(sys->clks[i]); + + return ret; +} + +static int mtk_subsys_probe(struct platform_device *pdev) +{ + struct sys_dev *sys; + struct resource *res; + void __iomem *mmio; + int num, ret; + + num = (int)of_device_get_match_data(&pdev->dev); + if (!num) + return -EINVAL; + + sys = devm_kzalloc(&pdev->dev, sizeof(*sys) + + sizeof(struct clk *) * num, GFP_KERNEL); + if (!sys) + return -ENOMEM; + + sys->clk_num = num; + sys->dev = &pdev->dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mmio = devm_ioremap_resource(sys->dev, res); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + sys->regmap = devm_regmap_init_mmio(sys->dev, mmio, + &aud_regmap_config); + if (IS_ERR(sys->regmap)) + return PTR_ERR(sys->regmap); + + platform_set_drvdata(pdev, sys); + + /* Enable top level clocks */ + ret = mtk_subsys_enable(sys); + if (ret) + return ret; + + return devm_of_platform_populate(sys->dev); +}; + +static int mtk_subsys_remove(struct platform_device *pdev) +{ + struct sys_dev *sys = platform_get_drvdata(pdev); + int i; + + for (i = sys->clk_num - 1; i >= 0; i--) + if (sys->clks[i]) + clk_disable_unprepare(sys->clks[i]); + + return 0; +} + +static const struct of_device_id of_match_audsys[] = { + { + .compatible = "mediatek,mt2701-audsys-core", + .data = (void *)AUDSYS_MAX_CLK_NUM, + }, + {}, +}; +MODULE_DEVICE_TABLE(platform, of_match_audsys); + +static struct platform_driver audsys_drv = { + .probe = mtk_subsys_probe, + .remove = mtk_subsys_remove, + .driver = { + .name = "mediatek-audsys-core", + .of_match_table = of_match_ptr(of_match_audsys), + }, +}; + +builtin_platform_driver(audsys_drv); + +MODULE_DESCRIPTION("Mediatek audio subsystem core driver"); +MODULE_LICENSE("GPL");