From patchwork Wed Jan 24 10:40:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125633 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp326266ljf; Wed, 24 Jan 2018 02:41:05 -0800 (PST) X-Google-Smtp-Source: AH8x225jEZ3VcMpZzAly+esFdzHFVdoi5E1+ivrUjsfJeC+/tSCzVHltGY5oOLolX3f/opkaRru/ X-Received: by 10.98.129.194 with SMTP id t185mr12511848pfd.228.1516790465323; Wed, 24 Jan 2018 02:41:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516790465; cv=none; d=google.com; s=arc-20160816; b=T36MJChixXawSqRvgVTXGhvqhyuFHgKOKDYBizXG11YBY9ZwPcZbgwUnMzI9Qav9FY 5kXBhF95KU14jLCdKLQ+GT2sL2pBaKuc6rTaMvLVDpBD3bR1cvyyzu2xpHWwv1Iq5TUs YPWFI9/FkhRKilZdjzstM1mQVkRtNls0FNH8cZ6RPD/APTgvQOEli2qt6VjaE7+OguV+ T7yiuYMp1zbsgbTOC3bJDEjRv7rkHhduflh8wPOe0RUZu1VUtj0+nW2LAq+4FK95v//B dIxWhOu47pjYQ5mPqdF24sauNhIBPwPSuth24bhfuRWn/CIW7j9j/TTAW6fwK9TOCwpG A8zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=vpzsjofM1ADSZo7cMaVVC9WMrNFGG3XwoTlrq9B5qYc=; b=jMElDCMiS8XFL5pFFUO63wawWITKpKnSpthLMw94cFNZFFWeKi7bSxkEbaI1X3f+ow O2PhaL2h2gXt+eQzFRwJyqXoxL0cEjBfBFVd6+MUipH7RppgD22cxi0QLErU35MaUWim mws47j4bqKB4yM6FO+W52Q61arssz3Jugbx96XnJfQBZ2zyubxog1biWFQrF3SLzA73u NL+nR/onAnlVTYiazE4w10NersOw8hBhyfKUAy8nvxLkx1UpNjsXexXzz2EpZusaSt46 3ecvtvEcybxawiaDW/uNRygyt0csNXbFHMmrQTDzxxobjZ4YCje8o1oXyj8ksl0I7k6N q7HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G6JYg12X; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id z27si2731971pfk.131.2018.01.24.02.41.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 02:41:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G6JYg12X; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1CBED222A3375; Wed, 24 Jan 2018 02:35:36 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D8544222A3371 for ; Wed, 24 Jan 2018 02:35:34 -0800 (PST) Received: by mail-wr0-x242.google.com with SMTP id v15so3544107wrb.8 for ; Wed, 24 Jan 2018 02:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ipmv6OyQt3wbuq6IS0RLm3S2dACUDGXpykmRG+j4nuQ=; b=G6JYg12X4r3ijWFdpE+FAbV1jXJqnwAw+cBelhegTGUhUJadKS90pA+zhbKWBluNG2 GgaffCEq7hqYbi69Gv/cJAdR2N5K8xdHvO1RkRicfz6gEWHjAw2u4D5ljc/WiegWxKOC X4AonjI6LkCX6IL0tX1KtPyBWpTPSjacgzNpk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ipmv6OyQt3wbuq6IS0RLm3S2dACUDGXpykmRG+j4nuQ=; b=bINlhC/3W0ChAPSNNUvxwhisT5ZVrG53EHYOfTnfKejKgGkrQJcoeL3ZVC74vj5TyH CbErQ8tEvZvXPFTaP7QEN2arYMmgtSyJvzAKRZ1edInfNuzXTQhCLVbOjvGt9/tHO2SH gmC3BXPmM8AfE/CEpqOupL+eNayXjPwlROc1Q7cXpBF4z0eY8fIapNjuJxA4AElbiOm3 pyzSSgHi/SthEa8niKXYJyRI85oV/WiG7OtGyokL0cLdGd6PGEOg5YZfXYhQTKa7ob0a ylrlUSMF2iuw4bwhVNv8jqMQl75tAAX7pg49wHwNiXteKpHkhH+bLsgb175hJXiLnPzN YILg== X-Gm-Message-State: AKwxyteS6bZC+iqeJey6VGhD7AwwmgWPAd3lSlGmlD8vpUwebSeWF4+o e3DWIJ/8sM+Kla/km+zs4+KLWFKbhB0= X-Received: by 10.223.184.134 with SMTP id i6mr5332170wrf.169.1516790460766; Wed, 24 Jan 2018 02:41:00 -0800 (PST) Received: from localhost.localdomain ([160.163.176.196]) by smtp.gmail.com with ESMTPSA id s25sm4502378wra.54.2018.01.24.02.40.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 02:40:59 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 24 Jan 2018 10:40:52 +0000 Message-Id: <20180124104052.9920-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [edk2] [PATCH] Silicon/SynQuacer/PlatformDxe: enable spread spectrum mode for ASM1061 SATA X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The ASM1061 SATA controller integrated into the DeveloperBox board emits too much electromagnetic radiation, so it needs spread spectrum mode enabled. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/{Asmedia118x.c => Asmedia.c} | 79 +++++++++++++++----- Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf | 2 +- 2 files changed, 60 insertions(+), 21 deletions(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia118x.c b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia.c similarity index 64% rename from Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia118x.c rename to Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia.c index c4cbacd3dff9..6c289fa1892e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia118x.c +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Asmedia.c @@ -15,9 +15,12 @@ #include "PlatformDxe.h" #define ASMEDIA_VID 0x1b21 +#define ASM1061_PID 0x0612 #define ASM1182E_PID 0x1182 #define ASM1184E_PID 0x1184 +#define ASM1061_SSC_OFFSET 0xA10 + #define ASM118x_PCIE_CAPABILITY_OFFSET 0x80 #define ASM118x_PCIE_LINK_CONTROL_OFFSET (ASM118x_PCIE_CAPABILITY_OFFSET + \ OFFSET_OF (PCI_CAPABILITY_PCIEXP, \ @@ -39,24 +42,10 @@ RetrainAsm1184eDownstreamPort ( IN EFI_PCI_IO_PROTOCOL *PciIo ) { - UINT16 PciVidPid[2]; EFI_STATUS Status; PCIE_CAP Cap; PCI_REG_PCIE_LINK_CONTROL LinkControl; - Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PCI_VENDOR_ID_OFFSET, - ARRAY_SIZE (PciVidPid), &PciVidPid); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_WARN, "%a: failed to read PCI vendor/product ID - %r\n", - __FUNCTION__, Status)); - return; - } - - if (PciVidPid[0] != ASMEDIA_VID || - (PciVidPid[1] != ASM1182E_PID && PciVidPid[1] != ASM1184E_PID)) { - return; - } - // // The upstream and downstream ports share the same PID/VID, so check // the port type. This assumes the PCIe Express capability block lives @@ -91,6 +80,34 @@ RetrainAsm1184eDownstreamPort ( STATIC VOID +EnableAsm1061SpreadSpectrum ( + IN EFI_PCI_IO_PROTOCOL *PciIo + ) +{ + EFI_STATUS Status; + UINT8 SscVal; + + DEBUG ((DEBUG_INFO, "%a: enabling spread spectrum mode 0 for ASM1061\n", + __FUNCTION__)); + + // SSC mode 0~-4000 ppm, 1:1 modulation + + SscVal = 0; + Status = PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, ASM1061_SSC_OFFSET, 1, + &SscVal); + ASSERT_EFI_ERROR (Status); + + MemoryFence (); + gBS->Stall (1); // delay at least 100 ns between writes of the same register + + SscVal = 1; + Status = PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, ASM1061_SSC_OFFSET, 1, + &SscVal); + ASSERT_EFI_ERROR (Status); +} + +STATIC +VOID EFIAPI OnPciIoProtocolNotify ( IN EFI_EVENT Event, @@ -101,6 +118,7 @@ OnPciIoProtocolNotify ( EFI_STATUS Status; EFI_HANDLE HandleBuffer; UINTN BufferSize; + UINT16 PciVidPid[2]; while (TRUE) { BufferSize = sizeof (EFI_HANDLE); @@ -114,12 +132,33 @@ OnPciIoProtocolNotify ( (VOID **)&PciIo); ASSERT_EFI_ERROR (Status); - // - // The ASM1184E 4-port PCIe switch on the DeveloperBox board (and its - // 2-port sibling of which samples were used in development) needs a - // little nudge to get it to train the downstream links at Gen2 speed. - // - RetrainAsm1184eDownstreamPort (PciIo); + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PCI_VENDOR_ID_OFFSET, + ARRAY_SIZE (PciVidPid), &PciVidPid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: failed to read PCI vendor/product ID - %r\n", + __FUNCTION__, Status)); + continue; + } + + if (PciVidPid[0] != ASMEDIA_VID) { + continue; + } + + if (PciVidPid[1] == ASM1061_PID) { + // + // The ASM1061 SATA controller as integrated into the DeveloperBox design + // emits too much electromagnetic radiation. So enable spread spectrum + // mode. + // + EnableAsm1061SpreadSpectrum (PciIo); + } else if (PciVidPid[1] == ASM1182E_PID || PciVidPid[1] == ASM1184E_PID) { + // + // The ASM1184E 4-port PCIe switch on the DeveloperBox board (and its + // 2-port sibling of which samples were used in development) needs a + // little nudge to get it to train the downstream links at Gen2 speed. + // + RetrainAsm1184eDownstreamPort (PciIo); + } } } diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf index 16412b999a40..64c90ac74e8e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf @@ -23,7 +23,7 @@ [Defines] ENTRY_POINT = PlatformDxeEntryPoint [Sources] - Asmedia118x.c + Asmedia.c Emmc.c PlatformDxe.c PlatformDxeHii.uni