From patchwork Thu Feb 2 02:12:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 139042 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE911B6F99 for ; Thu, 2 Feb 2012 13:15:44 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RsmAu-0008Sq-BT; Thu, 02 Feb 2012 02:13:26 +0000 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RsmAP-0008Ju-W8 for linux-arm-kernel@lists.infradead.org; Thu, 02 Feb 2012 02:12:55 +0000 Received: from mail31-ch1-R.bigfish.com (10.43.68.246) by CH1EHSOBE004.bigfish.com (10.43.70.54) with Microsoft SMTP Server id 14.1.225.23; Thu, 2 Feb 2012 02:12:53 +0000 Received: from mail31-ch1 (localhost [127.0.0.1]) by mail31-ch1-R.bigfish.com (Postfix) with ESMTP id B84B63804E2; Thu, 2 Feb 2012 02:12:53 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275dhz2dh87h2a8h668h839h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail31-ch1 (localhost.localdomain [127.0.0.1]) by mail31-ch1 (MessageSwitch) id 1328148771560366_4705; Thu, 2 Feb 2012 02:12:51 +0000 (UTC) Received: from CH1EHSMHS011.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.246]) by mail31-ch1.bigfish.com (Postfix) with ESMTP id 82C3724004C; Thu, 2 Feb 2012 02:12:51 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS011.bigfish.com (10.43.70.11) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 2 Feb 2012 02:12:50 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.355.3; Wed, 1 Feb 2012 20:12:49 -0600 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id q122CTOf028023; Wed, 1 Feb 2012 20:12:46 -0600 (CST) From: Richard Zhao To: Subject: [PATCH v2 5/9] ARM: mxc: convert audmux-v2 to a platform driver Date: Thu, 2 Feb 2012 10:12:04 +0800 Message-ID: <1328148728-32258-6-git-send-email-richard.zhao@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1328148728-32258-1-git-send-email-richard.zhao@linaro.org> References: <1328148728-32258-1-git-send-email-richard.zhao@linaro.org> MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.182 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: alsa-devel@alsa-project.org, patches@linaro.org, devicetree-discuss@lists.ozlabs.org, broonie@opensource.wolfsonmicro.com, linux-doc@vger.kernel.org, eric.miao@linaro.org, kernel@pengutronix.de, shawn.guo@linaro.org, Richard Zhao X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org Plaform driver is more flexible and easy to add DT support. Signed-off-by: Richard Zhao --- arch/arm/plat-mxc/audmux-v2.c | 102 ++++++++++++++++++++++++++++++---------- 1 files changed, 76 insertions(+), 26 deletions(-) diff --git a/arch/arm/plat-mxc/audmux-v2.c b/arch/arm/plat-mxc/audmux-v2.c index 8cced35..d53c029 100644 --- a/arch/arm/plat-mxc/audmux-v2.c +++ b/arch/arm/plat-mxc/audmux-v2.c @@ -24,6 +24,9 @@ #include #include +#define DRIVER_NAME "audmux-v2" + +struct resource *audmux_res; static struct clk *audmux_clk; static void __iomem *audmux_base; @@ -140,7 +143,7 @@ static const struct file_operations audmux_debugfs_fops = { .llseek = default_llseek, }; -static void audmux_debugfs_init(void) +static void __init audmux_debugfs_init(void) { int i; char buf[20]; @@ -159,10 +162,18 @@ static void audmux_debugfs_init(void) i); } } + +static void __exit audmux_debugfs_remove(void) +{ + debugfs_remove_recursive(audmux_debugfs_root); +} #else static inline void audmux_debugfs_init(void) { } +static void audmux_debugfs_remove(void) +{ +} #endif int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr, @@ -184,36 +195,75 @@ int mxc_audmux_v2_configure_port(unsigned int port, unsigned int ptcr, } EXPORT_SYMBOL_GPL(mxc_audmux_v2_configure_port); -static int mxc_audmux_v2_init(void) +static int __init mxc_audmux_v2_probe(struct platform_device *pdev) { - int ret; - if (cpu_is_mx51()) { - audmux_base = MX51_IO_ADDRESS(MX51_AUDMUX_BASE_ADDR); - } else if (cpu_is_mx31()) { - audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR); - } else if (cpu_is_mx35()) { - audmux_clk = clk_get(NULL, "audmux"); - if (IS_ERR(audmux_clk)) { - ret = PTR_ERR(audmux_clk); - printk(KERN_ERR "%s: cannot get clock: %d\n", __func__, - ret); - return ret; - } - audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR); - } else if (cpu_is_mx25()) { - audmux_clk = clk_get(NULL, "audmux"); - if (IS_ERR(audmux_clk)) { - ret = PTR_ERR(audmux_clk); - printk(KERN_ERR "%s: cannot get clock: %d\n", __func__, - ret); - return ret; - } - audmux_base = MX25_IO_ADDRESS(MX25_AUDMUX_BASE_ADDR); + struct resource *res; + resource_size_t res_size; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "can't get device resources\n"); + return -ENOENT; + } + + res_size = resource_size(res); + + if (!request_mem_region(res->start, res_size, DRIVER_NAME)) { + dev_err(&pdev->dev, "request_mem_region failed\n"); + return -EBUSY; + } + + audmux_base = ioremap(res->start, res_size); + + if (!audmux_base) { + dev_err(&pdev->dev, "ioremap failed\n"); + release_mem_region(res->start, resource_size(res)); + return -EIO; + } + + audmux_clk = clk_get(&pdev->dev, "audmux"); + if (IS_ERR(audmux_clk)) { + dev_warn(&pdev->dev, "cannot get clock: %ld\n", + PTR_ERR(audmux_clk)); + audmux_clk = NULL; } audmux_debugfs_init(); + audmux_res = res; return 0; } -postcore_initcall(mxc_audmux_v2_init); +static int __exit mxc_audmux_v2_remove(struct platform_device *pdev) +{ + audmux_debugfs_remove(); + clk_put(audmux_clk); + iounmap(audmux_base); + release_mem_region(audmux_res->start, resource_size(audmux_res)); + + return 0; +} + +static struct platform_driver mxc_audmux_v2_driver = { + .remove = __exit_p(mxc_audmux_v2_remove), + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + } +}; + +static int __init mxc_audmux_v2_init(void) +{ + return platform_driver_probe(&mxc_audmux_v2_driver, + mxc_audmux_v2_probe); +} +subsys_initcall(mxc_audmux_v2_init); + +static void __exit mxc_audmux_v2_exit(void) +{ + platform_driver_unregister(&mxc_audmux_v2_driver); +} +module_exit(mxc_audmux_v2_exit); + +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRIVER_NAME);