From patchwork Fri Mar 16 08:16:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Liu X-Patchwork-Id: 7330 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 0A28923E13 for ; Fri, 16 Mar 2012 08:17:31 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id AC91FA1821A for ; Fri, 16 Mar 2012 08:17:30 +0000 (UTC) Received: by iage36 with SMTP id e36so6826802iag.11 for ; Fri, 16 Mar 2012 01:17:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=Mz5YibtVPQRE33yTXEpJbpAVbl/rm2PuySM9Gqu7O+8=; b=kKZEKWOVJ2vVTtzu6q5xKlzsjMvKPtORMYHBt1s4E15q9MP2GqjX9C0NW4oRpLg0KQ LPfSvIJ3n5kF/PltCEJ1ajrFpMWWvpyvFGUIZBwxcrp9uk7gKyFTnrBsiOtH38yOpAtD AGN1NyENxJCGmJf/8kxyIiMGcrDbnBDk+WH9yNfe8YoDUJXw0q2tbH2Qql6GVM0cWBgs yqsocgMqP/MnG7+UTY43/MxKX7vueYWu9SMOfvujK5149GHKj6ApGC3PQ5qtqzmjnQvS FhEEQlqHnf1C5nPLiu6aEKd+tg5CI0JzepqUO9CpEgbUc2TkqACwoScoAKnJYhb3LEKv jRiw== Received: by 10.42.145.72 with SMTP id e8mr956203icv.0.1331885850067; Fri, 16 Mar 2012 01:17:30 -0700 (PDT) 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.53.18 with SMTP id k18csp2617ibg; Fri, 16 Mar 2012 01:17:29 -0700 (PDT) Received: by 10.68.138.197 with SMTP id qs5mr12066406pbb.78.1331885848796; Fri, 16 Mar 2012 01:17:28 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id l3si5757331pbs.94.2012.03.16.01.17.28 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Mar 2012 01:17:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of paul.liu@linaro.org) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of paul.liu@linaro.org) smtp.mail=paul.liu@linaro.org Received: by dakn40 with SMTP id n40so5635152dak.37 for ; Fri, 16 Mar 2012 01:17:28 -0700 (PDT) Received: by 10.68.242.197 with SMTP id ws5mr11956654pbc.84.1331885848142; Fri, 16 Mar 2012 01:17:28 -0700 (PDT) Received: from freya.lan (host-77.138-185-111.static.totalbb.net.tw. [111.185.138.77]) by mx.google.com with ESMTPS id q10sm3780517pbb.10.2012.03.16.01.17.17 (version=SSLv3 cipher=OTHER); Fri, 16 Mar 2012 01:17:27 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, patches@linaro.org, "Ying-Chun Liu (PaulLiu)" , Samuel Ortiz , Mark Brown , Venu Byravarasu , Peter Korsgaard , Arnd Bergmann , Rob Lee Subject: [PATCH v10] mfd: Add anatop mfd driver Date: Fri, 16 Mar 2012 16:16:56 +0800 Message-Id: <1331885816-26902-1-git-send-email-paul.liu@linaro.org> X-Mailer: git-send-email 1.7.9.1 X-Gm-Message-State: ALoCoQnb7neUkOZnkDdtnOwDOnTRkGKLCtnbnfjEZeL2SxZz13kWF4Qzg0OkJZrMHURcr+7yVRp6 From: "Ying-Chun Liu (PaulLiu)" Anatop is a mfd chip embedded in Freescale i.MX6Q SoC. Anatop provides regulators and thermal. This driver handles the address space and the operation of the mfd device. Signed-off-by: Ying-Chun Liu (PaulLiu) Acked-by: Shawn Guo Cc: Samuel Ortiz Cc: Mark Brown Cc: Venu Byravarasu Cc: Peter Korsgaard Cc: Arnd Bergmann Cc: Rob Lee Reviewed-by: Arnd Bergmann --- drivers/mfd/Kconfig | 8 +++ drivers/mfd/Makefile | 1 + drivers/mfd/anatop-mfd.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/anatop.h | 40 +++++++++++++ 4 files changed, 186 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/anatop-mfd.c create mode 100644 include/linux/mfd/anatop.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 82da448..c3a9f31 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -846,6 +846,14 @@ config MFD_INTEL_MSIC Passage) chip. This chip embeds audio, battery, GPIO, etc. devices used in Intel Medfield platforms. +config MFD_ANATOP + bool "Support for Freescale i.MX on-chip ANATOP controller" + depends on SOC_IMX6Q + help + Select this option to enable Freescale i.MX on-chip ANATOP + MFD controller. This controller embeds regulator and + thermal devices for Freescale i.MX platforms. + endmenu endif diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 27430d3..42c8bf6 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -113,3 +113,4 @@ obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o obj-$(CONFIG_MFD_S5M_CORE) += s5m-core.o s5m-irq.o +obj-$(CONFIG_MFD_ANATOP) += anatop-mfd.o diff --git a/drivers/mfd/anatop-mfd.c b/drivers/mfd/anatop-mfd.c new file mode 100644 index 0000000..2af4248 --- /dev/null +++ b/drivers/mfd/anatop-mfd.c @@ -0,0 +1,137 @@ +/* + * Anatop MFD driver + * + * Copyright (C) 2012 Ying-Chun Liu (PaulLiu) + * Copyright (C) 2012 Linaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +u32 anatop_get_bits(struct anatop *adata, u32 addr, int bit_shift, + int bit_width) +{ + u32 val, mask; + + if (bit_width == 32) + mask = ~0; + else + mask = (1 << bit_width) - 1; + + val = readl(adata->ioreg + addr); + val = (val >> bit_shift) & mask; + + return val; +} +EXPORT_SYMBOL_GPL(anatop_get_bits); + +void anatop_set_bits(struct anatop *adata, u32 addr, int bit_shift, + int bit_width, u32 data) +{ + u32 val, mask; + + if (bit_width == 32) + mask = ~0; + else + mask = (1 << bit_width) - 1; + + spin_lock(&adata->reglock); + val = readl(adata->ioreg + addr) & ~(mask << bit_shift); + writel((data << bit_shift) | val, adata->ioreg + addr); + spin_unlock(&adata->reglock); +} +EXPORT_SYMBOL_GPL(anatop_set_bits); + +static const struct of_device_id of_anatop_match[] = { + { .compatible = "fsl,imx6q-anatop", }, + { }, +}; + +static int __devinit of_anatop_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + void *ioreg; + struct anatop *drvdata; + + ioreg = of_iomap(np, 0); + if (!ioreg) + return -EADDRNOTAVAIL; + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + drvdata->ioreg = ioreg; + spin_lock_init(&drvdata->reglock); + platform_set_drvdata(pdev, drvdata); + of_platform_populate(np, of_anatop_match, NULL, dev); + + return 0; +} + +static int __devexit of_anatop_remove(struct platform_device *pdev) +{ + struct anatop *drvdata; + drvdata = platform_get_drvdata(pdev); + iounmap(drvdata->ioreg); + + return 0; +} + +static struct platform_driver anatop_of_driver = { + .driver = { + .name = "anatop-mfd", + .owner = THIS_MODULE, + .of_match_table = of_anatop_match, + }, + .probe = of_anatop_probe, + .remove = of_anatop_remove, +}; + +static int __init anatop_init(void) +{ + return platform_driver_register(&anatop_of_driver); +} +postcore_initcall(anatop_init); + +static void __exit anatop_exit(void) +{ + platform_driver_unregister(&anatop_of_driver); +} +module_exit(anatop_exit); + +MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) "); +MODULE_DESCRIPTION("ANATOP MFD driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/anatop.h b/include/linux/mfd/anatop.h new file mode 100644 index 0000000..22c1007 --- /dev/null +++ b/include/linux/mfd/anatop.h @@ -0,0 +1,40 @@ +/* + * anatop.h - Anatop MFD driver + * + * Copyright (C) 2012 Ying-Chun Liu (PaulLiu) + * Copyright (C) 2012 Linaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __LINUX_MFD_ANATOP_H +#define __LINUX_MFD_ANATOP_H + +#include + +/** + * anatop - MFD data + * @ioreg: ioremap register + * @reglock: spinlock for register read/write + */ +struct anatop { + void *ioreg; + spinlock_t reglock; +}; + +extern u32 anatop_get_bits(struct anatop *, u32, int, int); +extern void anatop_set_bits(struct anatop *, u32, int, int, u32); + +#endif /* __LINUX_MFD_ANATOP_H */