From patchwork Thu Jul 26 08:42:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinayak Holikatti X-Patchwork-Id: 10246 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 40BC823F61 for ; Thu, 26 Jul 2012 08:43:55 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id E78FDA18846 for ; Thu, 26 Jul 2012 08:43:54 +0000 (UTC) Received: by ghbz12 with SMTP id z12so1696519ghb.11 for ; Thu, 26 Jul 2012 01:43:54 -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 :dkim-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=52W6PT+b4HqT3bqYpjX8UEi7SB6O5w4j2uvxbvcXrTw=; b=drHCfuEdM0zrExOnYXSMGEVaqBzpI55a9ztUUyRcRiWMFWOJbodoH97OxJJ9dfldf9 ltKFC6f+xA+iLivAjAKYJo23D2vHZvTlmb42ikM+FrWEfXze8s3u1UPG11MGxNG+esCQ ozc5FoI5f40ekKKLA0Mm+SsL0HC/zP9cl8rBSNUMBtZ8R6ufoMkfqV+LAnPxmbpbPiHb mkuBK9W0WcgdQKZHex1cQG8boZaPMSi3JbDsl9XtSI8qSVBPnsZQZBXbOVwi1I+xtPjE lEDfvRmy+YbVVTF9rFBg28CTwFE2w+T0MIe7TnuY1SYgUe6/sRNeBtj20AgWIYDU8zP0 3FXw== Received: by 10.50.182.229 with SMTP id eh5mr983478igc.38.1343292234219; Thu, 26 Jul 2012 01:43:54 -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.43.93.3 with SMTP id bs3csp129856icc; Thu, 26 Jul 2012 01:43:53 -0700 (PDT) Received: by 10.66.90.41 with SMTP id bt9mr18884795pab.32.1343292233382; Thu, 26 Jul 2012 01:43:53 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id tc8si38486893pbc.204.2012.07.26.01.43.52 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Jul 2012 01:43:53 -0700 (PDT) Received-SPF: pass (google.com: domain of vinholikatti@gmail.com designates 209.85.160.50 as permitted sender) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vinholikatti@gmail.com designates 209.85.160.50 as permitted sender) smtp.mail=vinholikatti@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-pb0-f50.google.com with SMTP id rr4so3300121pbb.37 for ; Thu, 26 Jul 2012 01:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=52W6PT+b4HqT3bqYpjX8UEi7SB6O5w4j2uvxbvcXrTw=; b=aKXHXV/oZhoMt/4ayst+A2ACUh2E9c+GuVPSvctE7xI3fqJonn29WwXd91a+KXljR1 PJVwxbuMjjwsXjTeVHo3twt+JHKjOCs1f+yDA3UQE6miDBvce9HKhhBLAJDOwS1vb/zd ddSow/urYn8sDhvc9AYGK0rbxQbFFqYJipfwze/93f3Qrj46nTT+HVw8YJP4RfjpsQPS 8H+juYRpirGqglmMt8EqGw16J7XgBBlsjMoxKsAkoG/oB5gmc1+8q1713HloHuiHpl2w 0SB7nMS6+8roIX7XN7UTwTEqBtj4WuNuWyWYAaIwUgUcT2uSarRo6LoJo6KUWLroTka/ KKUw== Received: by 10.68.196.193 with SMTP id io1mr3551612pbc.17.1343292231872; Thu, 26 Jul 2012 01:43:51 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id ny4sm16127173pbb.57.2012.07.26.01.43.40 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Jul 2012 01:43:45 -0700 (PDT) From: Vinayak Holikatti To: James.Bottomley@hansenpartnership.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org, linux-samsung-soc@vger.kernel.org, arnd@linaro.org, girish.shivananjappa@linaro.org, saugata.das@linaro.org, vishak.g@samsung.com, venkat@linaro.org, k.rajesh@samsung.com, dsaxena@linaro.org, ilho215.lee@samsung.com, nala.la@samsung.com, sreekumar.c@samsung.com, Vinayak Holikatti , Santosh Yaraganavi Subject: [PATCH V3 3/4] [SCSI] ufs: Add Platform glue driver for ufshcd Date: Thu, 26 Jul 2012 14:12:49 +0530 Message-Id: <1343292170-2599-4-git-send-email-vinholikatti@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1343292170-2599-1-git-send-email-vinholikatti@gmail.com> References: <1343292170-2599-1-git-send-email-vinholikatti@gmail.com> X-Gm-Message-State: ALoCoQmkk9ecyG+kWs7Vgmij0cJ9wDYhBWw4oMrVd+gq5dO9Wh1i/82vvgd/qYvvjjFhcGUZWSmx This patch adds Platform glue driver for ufshcd. Reviewed-by: Namjae Jeon Signed-off-by: Vinayak Holikatti Signed-off-by: Santosh Yaraganavi --- drivers/scsi/ufs/Kconfig | 11 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd-pltfrm.c | 222 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 drivers/scsi/ufs/ufshcd-pltfrm.c diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig index 265a8c8..8c06330 100644 --- a/drivers/scsi/ufs/Kconfig +++ b/drivers/scsi/ufs/Kconfig @@ -67,3 +67,14 @@ config SCSI_UFSHCD_PCI If you have a controller with this interface, say Y or M here. If unsure, say N. + +config SCSI_UFSHCD_PLATFORM + tristate "Platform based UFS Controller support" + depends on SCSI_UFSHCD + ---help--- + This selects the UFS host controller support. If you have a + platform with UFS controller, say Y or M here. + + If you have a controller with this interface, say Y or M here. + + If unsure, say N. diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile index 9eda0df..1e5bd48 100644 --- a/drivers/scsi/ufs/Makefile +++ b/drivers/scsi/ufs/Makefile @@ -1,3 +1,4 @@ # UFSHCD makefile obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o +obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c new file mode 100644 index 0000000..68e1675 --- /dev/null +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -0,0 +1,222 @@ +/* + * Universal Flash Storage Host controller driver + * + * This code is based on drivers/scsi/ufs/ufshcd-pltfm.c + * Copyright (C) 2011-2012 Samsung India Software Operations + * + * Santosh Yaraganavi + * Vinayak Holikatti + * + * 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. + * + * NO WARRANTY + * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT + * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is + * solely responsible for determining the appropriateness of using and + * distributing the Program and assumes all risks associated with its + * exercise of rights under this Agreement, including but not limited to + * the risks and costs of program errors, damage to or loss of data, + * programs or equipment, and unavailability or interruption of operations. + + * DISCLAIMER OF LIABILITY + * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED + * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES + + * 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 "ufshcd.h" +#include "ufshcd_common.h" +#include + +#ifdef CONFIG_PM +/** + * ufshcd_pltfrm_suspend - suspend power management function + * @pdev: pointer to Platform device handle + * @mesg: power state + * + * Returns -ENOSYS + */ +static int ufshcd_pltfrm_suspend(struct platform_device *pdev, + pm_message_t mesg) +{ + /* + * TODO: + * 1. Block SCSI requests from SCSI midlayer + * 2. Change the internal driver state to non operational + * 3. Set UTRLRSR and UTMRLRSR bits to zero + * 4. Wait until outstanding commands are completed + * 5. Set HCE to zero to send the UFS host controller to reset state + */ + + return -ENOSYS; +} + +/** + * ufshcd_pltfrm_resume - resume power management function + * @pdev: pointer to Platform device handle + * + * Returns -ENOSYS + */ +static int ufshcd_pltfrm_resume(struct platform_device *pdev) +{ + /* + * TODO: + * 1. Set HCE to 1, to start the UFS host controller + * initialization process + * 2. Set UTRLRSR and UTMRLRSR bits to 1 + * 3. Change the internal driver state to operational + * 4. Unblock SCSI requests from SCSI midlayer + */ + + return -ENOSYS; +} +#endif + +/** + * ufshcd_pltfrm_probe - probe routine of the driver + * @pdev: pointer to Platform device handle + * + * Returns 0 on success, non-zero value on failure + */ +static int __devinit +ufshcd_pltfrm_probe(struct platform_device *pdev) +{ + struct ufs_hba *hba; + void __iomem *mmio_base; + struct resource *mem_res; + struct resource *irq_res; + resource_size_t mem_size; + int err; + struct device *dev = &pdev->dev; + + mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem_res) { + dev_err(&pdev->dev, + "%s: Memory resource not available\n", __FILE__); + err = -ENODEV; + goto out_error; + } + + mem_size = resource_size(mem_res); + if (!request_mem_region(mem_res->start, mem_size, "ufshcd")) { + dev_err(&pdev->dev, + "ufshcd: Cannot reserve the memory resource\n"); + err = -EBUSY; + goto out_error; + } + + mmio_base = ioremap_nocache(mem_res->start, mem_size); + if (!mmio_base) { + dev_err(&pdev->dev, "memory map failed\n"); + err = -ENOMEM; + goto out_release_regions; + } + + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!irq_res) { + dev_err(&pdev->dev, "ufshcd: IRQ resource not available\n"); + err = -ENODEV; + goto out_iounmap; + } + + err = dma_set_coherent_mask(dev, dev->coherent_dma_mask); + if (err) { + dev_err(&pdev->dev, "set dma mask failed\n"); + goto out_iounmap; + } + + err = ufshcd_init(&pdev->dev, &hba, mmio_base, irq_res->start); + if (err) { + dev_err(&pdev->dev, "%s: Intialization failed\n", + __FILE__); + goto out_iounmap; + } + + platform_set_drvdata(pdev, hba); + + return 0; + +out_iounmap: + iounmap(mmio_base); +out_release_regions: + release_mem_region(mem_res->start, mem_size); +out_error: + return err; +} + +/** + * ufshcd_pltfrm_remove - remove platform driver routine + * @pdev: pointer to platform device handle + * + * Returns 0 on success, non-zero value on failure + */ +static int __devexit ufshcd_pltfrm_remove(struct platform_device *pdev) +{ + struct resource *mem_res; + struct resource *irq_res; + resource_size_t mem_size; + struct ufs_hba *hba = platform_get_drvdata(pdev); + + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + + if (!irq_res) + dev_err(&pdev->dev, "ufshcd: IRQ resource not available\n"); + else + free_irq(irq_res->start, hba); + + ufshcd_remove(hba); + mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem_res) + dev_err(&pdev->dev, "ufshcd: Memory resource not available\n"); + else { + mem_size = resource_size(mem_res); + release_mem_region(mem_res->start, mem_size); + } + platform_set_drvdata(pdev, NULL); + return 0; +} + +static const struct of_device_id ufs_of_match[] = { + { .compatible = "jedec,ufs-1.1"}, +}; + +static struct platform_driver ufshcd_pltfrm_driver = { + .probe = ufshcd_pltfrm_probe, + .remove = __devexit_p(ufshcd_pltfrm_remove), +#ifdef CONFIG_PM + .suspend = ufshcd_pltfrm_suspend, + .resume = ufshcd_pltfrm_resume, +#endif + .driver = { + .name = "ufshcd", + .owner = THIS_MODULE, + .of_match_table = ufs_of_match, + }, +}; + +module_platform_driver(ufshcd_pltfrm_driver); + +MODULE_AUTHOR("Santosh Yaragnavi "); +MODULE_AUTHOR("Vinayak Holikatti "); +MODULE_DESCRIPTION("Platform based UFS host controller driver"); +MODULE_LICENSE("GPL"); +MODULE_VERSION(UFSHCD_DRIVER_VERSION);