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: 6559 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A8B9E23E16 for ; Thu, 2 Feb 2012 02:12:56 +0000 (UTC) Received: from mail-tul01m020-f180.google.com (mail-tul01m020-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3E275A180AC for ; Thu, 2 Feb 2012 02:12:56 +0000 (UTC) Received: by obbuo19 with SMTP id uo19so2935912obb.11 for ; Wed, 01 Feb 2012 18:12:55 -0800 (PST) Received: by 10.50.158.227 with SMTP id wx3mr10322416igb.0.1328148775448; Wed, 01 Feb 2012 18:12:55 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.169.210 with SMTP id a18cs34142ibz; Wed, 1 Feb 2012 18:12:54 -0800 (PST) Received: by 10.236.77.232 with SMTP id d68mr1070920yhe.98.1328148774552; Wed, 01 Feb 2012 18:12:54 -0800 (PST) Received: from ch1outboundpool.messaging.microsoft.com (ch1ehsobe004.messaging.microsoft.com. [216.32.181.184]) by mx.google.com with ESMTPS id g28si940367yhh.42.2012.02.01.18.12.54 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 01 Feb 2012 18:12:54 -0800 (PST) Received-SPF: neutral (google.com: 216.32.181.184 is neither permitted nor denied by best guess record for domain of richard.zhao@linaro.org) client-ip=216.32.181.184; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.181.184 is neither permitted nor denied by best guess record for domain of richard.zhao@linaro.org) smtp.mail=richard.zhao@linaro.org 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: CC: , , , , , , , , Richard Zhao 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 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);