Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp401879imn; Thu, 28 Jul 2022 04:24:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vj2QJ297ADlgp6U398aNyDJF30flV/OoRPMWt6KAU21mmNgI/acM91RT2Okf6k76tO9HR7 X-Received: by 2002:a05:6a00:ac1:b0:52b:5db8:f362 with SMTP id c1-20020a056a000ac100b0052b5db8f362mr26735676pfl.80.1659007488670; Thu, 28 Jul 2022 04:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659007488; cv=none; d=google.com; s=arc-20160816; b=SYrq2oibrb+y/c9U6nhZL0bVa66vQsh9kfZFobRIq5JxU76G+NGk/7wZV8u9wU/0bp 8jlKKCc4uaFlKGZAWmj+BZdED4DSNmUUchS4cTkGaZGA1buDRG7lP9/0sjKtQLezeO4g lRoN5uY5/MV8zr0xPFYpIp0sSOT4KLTVDjxcyTM96ei52H91tiG4SuYcnpftJ2tkWagk FUa+vqw+AShTBHczE/oZMuC7svlfY1d4QoWa+L+ZV0U5D0dhrTlsW6S5ylKs/mOmkAMk rHKpt+SW/UDQtLx9eHGGwTjRlF4IF9pedHVWBP4vd65Qq+ZtSaQ1XVkJFtUqnUcwNOak ZYRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=MT1vicVBKMErOF29vUfCHo0rtXuUWIvTz+zjXl8btBY=; b=OiIKRaYPTwLKVJI3VBrGb5IFhvfobSy20QTtrPn3w12agMoekilA9Nxk5pjBwahPmr 54AtMvweClqo3W5hJEAhTEXrokGaU3sft68akTIcjtpo8zA4+1dv+J4gfFrPbxHQUHmf EGNlXr/6Sg9gEXtFCUf2B7LlgChlgLOfYcLOJi+zEkhpeMytLDeCnLxe7eia3Khu3Xjp 1BKtmsVamjhgZoFHwtVBOj5+OgaxaIH00kU/gC5ldYwuV6ty4rgcBmxIbRohZZRVrjI1 lCAqVpDHNb0Sx2FGLeB7hh/CjNTUsF91Oy8h+gOjsoIW+Wj+5LnN6j9PITGiqhCVt0md MUKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=Gpi1x6iE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l21-20020a17090af8d500b001f193a54751si4921058pjd.31.2022.07.28.04.24.33; Thu, 28 Jul 2022 04:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=Gpi1x6iE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237187AbiG1LWW (ORCPT + 99 others); Thu, 28 Jul 2022 07:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236921AbiG1LUd (ORCPT ); Thu, 28 Jul 2022 07:20:33 -0400 Received: from mail.baikalelectronics.com (unknown [87.245.175.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F22A683C4; Thu, 28 Jul 2022 04:19:39 -0700 (PDT) Received: from mail (mail.baikal.int [192.168.51.25]) by mail.baikalelectronics.com (Postfix) with ESMTP id 45B3116CF; Thu, 28 Jul 2022 14:22:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.com 45B3116CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1659007322; bh=MT1vicVBKMErOF29vUfCHo0rtXuUWIvTz+zjXl8btBY=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Gpi1x6iEoe7PdGKilas3oYKaOI4PHh1fngmc15buUAXpbrWbhYfb+IaMY26P7lDvb m2mDn1/M767LN9OGU7/Samrpgph7Fr5RIkQhcgpJ1x889eJFXysoY7/t+4ktyqYr9g WvSIyZtisjY8KwN5EPqy35MqYrWy9KmnJKthkUVY= Received: from localhost (192.168.53.207) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 28 Jul 2022 14:19:37 +0300 From: Serge Semin To: Damien Le Moal , Hans de Goede , Jens Axboe , Hannes Reinecke , Serge Semin CC: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Rob Herring , , , Subject: [PATCH RESEND v6 22/23] ata: ahci-dwc: Add Baikal-T1 AHCI SATA interface support Date: Thu, 28 Jul 2022 14:19:03 +0300 Message-ID: <20220728111905.12427-23-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220728111905.12427-1-Sergey.Semin@baikalelectronics.ru> References: <20220728111905.12427-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,T_SPF_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's almost fully compatible DWC AHCI SATA IP-core derivative except the reference clocks source, which need to be very carefully selected. In particular the DWC AHCI SATA PHY can be clocked either from the pads ref_pad_clk_{m,p} or from the internal wires ref_alt_clk_{m,n}. In the later case the clock signal is generated from the Baikal-T1 CCU SATA PLL. The clocks source is selected by means of the ref_use_pad wire connected to the CCU SATA reference clock CSR. In normal situation it would be much more handy to use the internal reference clock source, but alas we haven't managed to make the AHCI controller working well with it so far. So it's preferable to have the controller clocked from the external clock generator and fallback to the internal clock source only as a last resort. Other than that the controller is full compatible with the DWC AHCI SATA IP-core. Signed-off-by: Serge Semin Reviewed-by: Hannes Reinecke --- Changelog v2: - Rename 'syscon' property to 'baikal,bt1-syscon'. - Change the local objects prefix from 'dwc_ahci_' to 'ahci_dwc_', from 'bt1_ahci_' to 'ahci_bt1_'. (@Damien) Changelog v4: - Convert ahci_bt1_plat to being statically defined. (@kbot) - Drop Baikal-T1 syscon reference relying on the clock controller and the platform setup having the proper clock source selected. (@Rob) --- drivers/ata/Kconfig | 1 + drivers/ata/ahci_dwc.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 675bb44144d3..79242d82c755 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -179,6 +179,7 @@ config AHCI_DM816 config AHCI_DWC tristate "Synopsys DWC AHCI SATA support" select SATA_HOST + select MFD_SYSCON if (MIPS_BAIKAL_T1 || COMPILE_TEST) help This option enables support for the Synopsys DWC AHCI SATA controller implementation. diff --git a/drivers/ata/ahci_dwc.c b/drivers/ata/ahci_dwc.c index 44a9bb7696ab..03a1af1c2b1f 100644 --- a/drivers/ata/ahci_dwc.c +++ b/drivers/ata/ahci_dwc.c @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include #include "ahci.h" @@ -90,6 +92,20 @@ #define AHCI_DWC_PORT_PHYCR 0x74 #define AHCI_DWC_PORT_PHYSR 0x78 +/* Baikal-T1 AHCI SATA specific registers */ +#define AHCI_BT1_HOST_PHYCR AHCI_DWC_HOST_GPCR +#define AHCI_BT1_HOST_MPLM_MASK GENMASK(29, 23) +#define AHCI_BT1_HOST_LOSDT_MASK GENMASK(22, 20) +#define AHCI_BT1_HOST_CRR BIT(19) +#define AHCI_BT1_HOST_CRW BIT(18) +#define AHCI_BT1_HOST_CRCD BIT(17) +#define AHCI_BT1_HOST_CRCA BIT(16) +#define AHCI_BT1_HOST_CRDI_MASK GENMASK(15, 0) + +#define AHCI_BT1_HOST_PHYSR AHCI_DWC_HOST_GPSR +#define AHCI_BT1_HOST_CRA BIT(16) +#define AHCI_BT1_HOST_CRDO_MASK GENMASK(15, 0) + struct ahci_dwc_plat_data { unsigned int pflags; unsigned int hflags; @@ -106,6 +122,39 @@ struct ahci_dwc_host_priv { u32 dmacr[AHCI_MAX_PORTS]; }; +static int ahci_bt1_init(struct ahci_host_priv *hpriv) +{ + struct ahci_dwc_host_priv *dpriv = hpriv->plat_data; + int ret; + + /* APB, application and reference clocks are required */ + if (!ahci_platform_find_clk(hpriv, "pclk") || + !ahci_platform_find_clk(hpriv, "aclk") || + !ahci_platform_find_clk(hpriv, "ref")) { + dev_err(&dpriv->pdev->dev, "No system clocks specified\n"); + return -EINVAL; + } + + /* + * Fully reset the SATA AXI and ref clocks domain to ensure the state + * machine is working from scratch especially if the reference clocks + * source has been changed. + */ + ret = ahci_platform_assert_rsts(hpriv); + if (ret) { + dev_err(&dpriv->pdev->dev, "Couldn't assert the resets\n"); + return ret; + } + + ret = ahci_platform_deassert_rsts(hpriv); + if (ret) { + dev_err(&dpriv->pdev->dev, "Couldn't de-assert the resets\n"); + return ret; + } + + return 0; +} + static struct ahci_host_priv *ahci_dwc_get_resources(struct platform_device *pdev) { struct ahci_dwc_host_priv *dpriv; @@ -416,9 +465,15 @@ static struct ahci_dwc_plat_data ahci_dwc_plat = { .pflags = AHCI_PLATFORM_GET_RESETS, }; +static struct ahci_dwc_plat_data ahci_bt1_plat = { + .pflags = AHCI_PLATFORM_GET_RESETS | AHCI_PLATFORM_RST_TRIGGER, + .init = ahci_bt1_init, +}; + static const struct of_device_id ahci_dwc_of_match[] = { { .compatible = "snps,dwc-ahci", &ahci_dwc_plat }, { .compatible = "snps,spear-ahci", &ahci_dwc_plat }, + { .compatible = "baikal,bt1-ahci", &ahci_bt1_plat }, {}, }; MODULE_DEVICE_TABLE(of, ahci_dwc_of_match); -- 2.35.1