From patchwork Fri Jul 13 14:28:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinayak Holikatti X-Patchwork-Id: 9991 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 B02DF23E3D for ; Fri, 13 Jul 2012 14:29:00 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 6A142A182B9 for ; Fri, 13 Jul 2012 14:29:00 +0000 (UTC) Received: by yhpp61 with SMTP id p61so4059670yhp.11 for ; Fri, 13 Jul 2012 07:29:00 -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=c0/iKiJbFkk0qNOSYAirA3GHsdSX6q52Ji8LlnkOf34=; b=E/A1+xM1J7K4Jb78qfbnvv/udbiF/zN44QpN+rZhsf0DqVaHcqH8i6X5XAK5hzhJ5I vYQh7F/6nHpPcela4kT6k7PQXn5oOseEz9rf44uq6YGtUSGPZi8ActUBDU7PcrJDP6NV VFSMDr8B3ZhBPqyOeE629t9Q7TaXRHfgyQK5tAOPfNnIM8uJKlg53DmmZR6ULxOggP3t K1cKPIl6iUkwiMIpS6WYdmgkMOo9pC98Cj82+32cxpHZzcJnHgImumRWlHMlXMl2aVq8 YCpBM3v1+e9GIPgSy5kWS5QC+mUoRDWEsQdCOmI3ShJXLAL9zib1I3KjYrhFlzkmpK+T 6ehQ== Received: by 10.50.163.99 with SMTP id yh3mr1089452igb.53.1342189739564; Fri, 13 Jul 2012 07:28:59 -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.241.2 with SMTP id lc2csp16250ibb; Fri, 13 Jul 2012 07:28:58 -0700 (PDT) Received: by 10.236.200.232 with SMTP id z68mr1281277yhn.46.1342189738292; Fri, 13 Jul 2012 07:28:58 -0700 (PDT) Received: from mail-gh0-f178.google.com (mail-gh0-f178.google.com [209.85.160.178]) by mx.google.com with ESMTPS id b49si7289811yho.138.2012.07.13.07.28.56 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jul 2012 07:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of vinholikatti@gmail.com designates 209.85.160.178 as permitted sender) client-ip=209.85.160.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vinholikatti@gmail.com designates 209.85.160.178 as permitted sender) smtp.mail=vinholikatti@gmail.com; dkim=pass header.i=@gmail.com Received: by ghbf1 with SMTP id f1so4249243ghb.37 for ; Fri, 13 Jul 2012 07:28:56 -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=c0/iKiJbFkk0qNOSYAirA3GHsdSX6q52Ji8LlnkOf34=; b=XLc2eNAb3YVcvZnCTnAYO4Pan5TIhtO5bN+1IUaTyfQ87K55B/oZB7wEqZNeKk17A8 ZA8wyqoZr00RasMMGnGNZDbari0AfhULLr8ZT6c+gNlT0mjxaSiCKTKsA8Lv8jkOXSvI Z8T4eNUlmrcb53iw9QT0H1LDMb3JUtKwCE+ZdFAGl2Prrj1PzYXxmeojccWHn/DklGgY RHklJd/H1KwUsrp5q5ciNzmfz21sf7HyWMbxu1fS7k8KDN4A6mxqHJt2ypga5+qAX6j4 n4GlKkkk+h4mj03a0Xtuu+UWoKfrUyse9xKg2VySOt122+XcX6xKIoXiyb8clL9tMn1H P0bg== Received: by 10.66.73.5 with SMTP id h5mr2390252pav.79.1342189736193; Fri, 13 Jul 2012 07:28:56 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id ns5sm6114960pbb.26.2012.07.13.07.28.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jul 2012 07:28:55 -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, santoshsy@gmail.com, 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 Subject: [PATCH V2 3/4] [SCSI] ufs: Add Platform glue driver for ufshcd Date: Fri, 13 Jul 2012 19:58:17 +0530 Message-Id: <1342189698-20393-2-git-send-email-vinholikatti@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1342189698-20393-1-git-send-email-vinholikatti@gmail.com> References: <1342189698-20393-1-git-send-email-vinholikatti@gmail.com> X-Gm-Message-State: ALoCoQkP5xWThussZftZDvBtmva+XfzblItfzi8DY04XgKZ4yeVvlm3BSBvYpoK0zSADB+V36CRa This patch adds Platform glue driver for ufshcd. Signed-off-by: Vinayak Holikatti Signed-off-by: Santosh Yaraganavi Reviewed-by: Namjae Jeon --- drivers/scsi/ufs/Kconfig | 11 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufshcd-pltfrm.c | 215 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 227 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..1d3a63f --- /dev/null +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -0,0 +1,215 @@ +/* + * 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_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_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); + + ufshcd_remove(hba); + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!irq_res) + dev_err(&pdev->dev, "ufshcd: IRQ resource not available\n"); + free_irq(irq_res->start, hba); + mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + 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);