From patchwork Mon Feb 17 12:56:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 24769 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DAC4202B2 for ; Mon, 17 Feb 2014 12:57:19 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf23531137iec.8 for ; Mon, 17 Feb 2014 04:57:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Phpze5+TAgGBItbrx70tACZsP4AHWRdr7BcgtFL9ALA=; b=JReQ/EkJx45f3mPxf22qSwPPlhuC4/fBeLTV+H9sisTXruPhtlNA7SH4UPw4Z4xRwC vWnIH2i0z3vepAGi+85KrgBlgpkqXtpj6ZZ/JR86Gpd54vRX+Ig2z5iKARPLz4Q8CMGn GItQ5HbOfRPikAznW4TWgQvU0ycx8+1R5uo9M+r0hmfNtlGhArDeWQNRm0QDb9Xt//WJ Uqkf+FD8s9wCM6dYBCQW/sdokqtDOJ67YZ3RyQZk4tEO7ATTSrkpGAcwUW2pD6Z1+2vO gB2F+Aom6ZG5H8N46uny4/C4u0yGhCdYB264iXjljcXa899uiwbGN0grvG8eAGjVMKw4 1PSA== X-Gm-Message-State: ALoCoQngvXXhVYCfRmjjBXAz+PGbVt7IE1kK2yieIK3/x1st1m18e5oON+cF2SK0oJwhtFzo6kaF X-Received: by 10.42.75.10 with SMTP id y10mr9258108icj.19.1392641838652; Mon, 17 Feb 2014 04:57:18 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.100 with SMTP id 91ls860540qgi.18.gmail; Mon, 17 Feb 2014 04:57:18 -0800 (PST) X-Received: by 10.52.27.9 with SMTP id p9mr10739169vdg.28.1392641838555; Mon, 17 Feb 2014 04:57:18 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id t20si4451702vek.41.2014.02.17.04.57.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 04:57:18 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id ik5so11604542vcb.37 for ; Mon, 17 Feb 2014 04:57:18 -0800 (PST) X-Received: by 10.52.164.39 with SMTP id yn7mr11012619vdb.25.1392641838431; Mon, 17 Feb 2014 04:57:18 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp136081vcz; Mon, 17 Feb 2014 04:57:17 -0800 (PST) X-Received: by 10.180.98.165 with SMTP id ej5mr12647515wib.33.1392641837485; Mon, 17 Feb 2014 04:57:17 -0800 (PST) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by mx.google.com with ESMTPS id cq8si7983378wib.31.2014.02.17.04.57.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 04:57:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.179 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.179; Received: by mail-wi0-f179.google.com with SMTP id hn9so2353699wib.6 for ; Mon, 17 Feb 2014 04:57:17 -0800 (PST) X-Received: by 10.180.160.206 with SMTP id xm14mr12900442wib.25.1392641836913; Mon, 17 Feb 2014 04:57:16 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id fm3sm32159841wib.8.2014.02.17.04.57.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 04:57:16 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: alexandre.torgue@st.com, Lee Jones , Tejun Heo , linux-ide@vger.kernel.org Subject: [PATCH 3/3] ahci: st: Add support for ST's SATA IP Date: Mon, 17 Feb 2014 12:56:58 +0000 Message-Id: <1392641818-23419-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392641818-23419-1-git-send-email-lee.jones@linaro.org> References: <1392641818-23419-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Cc: Tejun Heo Cc: linux-ide@vger.kernel.org Signed-off-by: Lee Jones --- drivers/ata/Kconfig | 9 ++ drivers/ata/Makefile | 1 + drivers/ata/ahci_st.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 285 insertions(+) create mode 100644 drivers/ata/ahci_st.c diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 4e73772..a0798f3 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -97,6 +97,15 @@ config SATA_AHCI_PLATFORM If unsure, say N. +config SATA_AHCI_ST + tristate "ST SATA support" + depends on SATA_AHCI_PLATFORM + select GENERIC_PHY + help + This option enables support for ST SATA controller. + + If unsure, say N. + config AHCI_IMX tristate "Freescale i.MX AHCI SATA support" depends on SATA_AHCI_PLATFORM && MFD_SYSCON diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index 46518c6..3379a7d 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_ATA) += libata.o obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o obj-$(CONFIG_SATA_ACARD_AHCI) += acard-ahci.o libahci.o obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o +obj-$(CONFIG_SATA_AHCI_ST) += ahci_st.o obj-$(CONFIG_SATA_FSL) += sata_fsl.o obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o obj-$(CONFIG_SATA_SIL24) += sata_sil24.o diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c new file mode 100644 index 0000000..23342bf --- /dev/null +++ b/drivers/ata/ahci_st.c @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2012 STMicroelectronics Limited + * + * Authors: Francesco Virlinzi + * Alexandre Torgue + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AHCI_OOBR 0xbc +#define AHCI_OOBR_WE BIT(31) +#define AHCI_OOBR_CWMIN_SHIFT 24 +#define AHCI_OOBR_CWMAX_SHIFT 16 +#define AHCI_OOBR_CIMIN_SHIFT 8 +#define AHCI_OOBR_CIMAX_SHIFT 0 + +struct ahci_st_drv_data { + struct platform_device *ahci; + struct phy *phy; + struct reset_control *pwr; + struct reset_control *sw_rst; + struct reset_control *pwr_rst; + void __iomem *mmio; + struct clk *clk; +}; + +static void ahci_st_configure_oob(void __iomem *mmio) +{ + unsigned long old_val, new_val; + + new_val = (0x02 << AHCI_OOBR_CWMIN_SHIFT) | + (0x04 << AHCI_OOBR_CWMAX_SHIFT) | + (0x08 << AHCI_OOBR_CIMIN_SHIFT) | + (0x0C << AHCI_OOBR_CIMAX_SHIFT); + + old_val = readl(mmio + AHCI_OOBR); + writel(old_val | AHCI_OOBR_WE, mmio + AHCI_OOBR); + writel(new_val | AHCI_OOBR_WE, mmio + AHCI_OOBR); + writel(new_val, mmio + AHCI_OOBR); +} + +static int ahci_st_probe_resets(struct platform_device *pdev, + struct ahci_st_drv_data *ahci_dev) +{ + int err; + + ahci_dev->pwr = devm_reset_control_get(&pdev->dev, "pwr-dwn"); + if (IS_ERR(ahci_dev->pwr)) { + dev_info(&pdev->dev, "power reset control not defined\n"); + } else { + err = reset_control_deassert(ahci_dev->pwr); + if (err) { + dev_err(&pdev->dev, "unable to bring out of pwrdwn\n"); + return err; + } + } + + ahci_dev->sw_rst = devm_reset_control_get(&pdev->dev, "sw-rst"); + if (IS_ERR(ahci_dev->sw_rst)) { + dev_info(&pdev->dev, "soft reset control not defined\n"); + } else { + err = reset_control_deassert(ahci_dev->sw_rst); + if (err) { + dev_err(&pdev->dev, "unable to bring out of reset\n"); + return err; + } + } + + ahci_dev->pwr_rst = devm_reset_control_get(&pdev->dev, "pwr-rst"); + if (IS_ERR(ahci_dev->pwr_rst)) + dev_dbg(&pdev->dev, "power soft reset control not defined\n"); + else { + err = reset_control_deassert(ahci_dev->pwr_rst); + if (err) { + dev_err(&pdev->dev, "unable to bring out of reset\n"); + return err; + } + } + + return 0; +} + +static int ahci_st_init(struct device *ahci_dev, void __iomem *mmio) +{ + struct platform_device *pdev = to_platform_device(ahci_dev->parent); + struct ahci_st_drv_data *drv_data = platform_get_drvdata(pdev); + int ret; + + ret = clk_prepare_enable(drv_data->clk); + if (ret) + return ret; + + ret = phy_init(drv_data->phy); + if (ret) { + clk_disable_unprepare(drv_data->clk); + return ret; + } + + drv_data->mmio = mmio; + ahci_st_configure_oob(mmio); + + return 0; +} + +static void ahci_st_exit(struct device *ahci_dev) +{ + struct platform_device *pdev = to_platform_device(ahci_dev->parent); + struct ahci_st_drv_data *drv_data = platform_get_drvdata(pdev); + int ret; + + if (drv_data->pwr) { + ret = reset_control_assert(drv_data->pwr); + if (ret) + dev_err(&pdev->dev, "unable to bring out of pwrdwn\n"); + } + + clk_disable_unprepare(drv_data->clk); +} + +#ifdef CONFIG_PM_SLEEP +static int ahci_st_suspend(struct device *ahci_dev) +{ + struct platform_device *pdev = to_platform_device(ahci_dev->parent); + struct ahci_st_drv_data *drv_data = platform_get_drvdata(pdev); + int ret; + + if (drv_data->pwr) { + ret = reset_control_assert(drv_data->pwr); + if (ret) { + dev_err(&pdev->dev, "unable to pwrdwn"); + return ret; + } + } + + clk_disable_unprepare(drv_data->clk); + + return 0; +} + +static int ahci_st_resume(struct device *ahci_dev) +{ + struct platform_device *pdev = to_platform_device(ahci_dev->parent); + struct ahci_st_drv_data *drv_data = platform_get_drvdata(pdev); + int ret; + + clk_prepare_enable(drv_data->clk); + + if (drv_data->pwr) { + ret = reset_control_deassert(drv_data->pwr); + if (ret) { + dev_err(&pdev->dev, "unable to bring out of pwrdwn\n"); + return ret; + } + } + + ahci_st_configure_oob(drv_data->mmio); + + ret = phy_init(drv_data->phy); + if (ret) + return ret; + + if (drv_data->sw_rst) { + ret = reset_control_deassert(drv_data->sw_rst); + if (ret) { + dev_err(&pdev->dev, "unable to bring out of sw-rst\n"); + return ret; + } + } + + if (drv_data->pwr_rst) { + ret = reset_control_deassert(drv_data->pwr_rst); + if (ret) { + dev_err(&pdev->dev, "unable to bring out of pwr-rst\n"); + return ret; + } + } + + return 0; +} +#endif + +static struct ahci_platform_data ahci_st_platform_data = { + .init = ahci_st_init, + .exit = ahci_st_exit, +#ifdef CONFIG_PM_SLEEP + .suspend = ahci_st_suspend, + .resume = ahci_st_resume, +#endif +}; + +static int ahci_st_driver_probe(struct platform_device *pdev) +{ + int err, id; + struct ahci_st_drv_data *drv_data; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct platform_device_info ahci_info = { + .parent = dev, + .name = "ahci", + .id = pdev->id, + .res = pdev->resource, + .num_res = pdev->num_resources, + .data = &ahci_st_platform_data, + .size_data = sizeof(ahci_st_platform_data), + }; + + if (np) { + id = of_alias_get_id(dev->of_node, "sata"); + if (id > 0) + ahci_info.id = id; + + ahci_info.dma_mask = DMA_BIT_MASK(32); + } + + drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL); + if (!drv_data) + return -ENOMEM; + + err = ahci_st_probe_resets(pdev, drv_data); + if (err) + return err; + + drv_data->clk = devm_clk_get(&pdev->dev, "ahci_clk"); + if (IS_ERR(drv_data->clk)) { + dev_err(&pdev->dev, "ahci_clk clk not found\n"); + return PTR_ERR(drv_data->clk); + } + + drv_data->phy = devm_phy_get(&pdev->dev, "ahci_phy"); + if (IS_ERR(drv_data->phy)) { + dev_err(&pdev->dev, "no PHY configured\n"); + return PTR_ERR(drv_data->phy); + } + + platform_set_drvdata(pdev, drv_data); + + drv_data->ahci = platform_device_register_full(&ahci_info); + + return PTR_ERR_OR_ZERO(drv_data->ahci); +} + +static struct of_device_id st_ahci_match[] = { + { .compatible = "st,ahci", }, + {}, +}; +MODULE_DEVICE_TABLE(of, st_ahci_match); + +static struct platform_driver ahci_st_driver = { + .driver = { + .name = "ahci_st", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(st_ahci_match), + }, + .probe = ahci_st_driver_probe, +}; +module_platform_driver(ahci_st_driver); + +MODULE_AUTHOR("Alexandre Torgue "); +MODULE_AUTHOR("Francesco Virlinzi "); +MODULE_DESCRIPTION("STMicroelectronics Sata Ahci driver"); +MODULE_LICENSE("GPL v2");