From patchwork Mon Dec 9 00:40:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1205814 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="O7fvFNjH"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47WPXt6zPvz9sPK for ; Mon, 9 Dec 2019 11:42:22 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C61881676; Mon, 9 Dec 2019 01:41:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="O7fvFNjH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C0D9E80661; Mon, 9 Dec 2019 01:41:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8890080661 for ; Mon, 9 Dec 2019 01:41:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd43.google.com with SMTP id v18so12972155iol.2 for ; Sun, 08 Dec 2019 16:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ieTDi8P1CkWw8j7c9zBDMq0IchoLIDpQlF+wKDBIUuA=; b=O7fvFNjHV2DlEtQS+Fbe3XTBrCZUT05TG5EtjfZC9abgat+yRpxnpAHnUNRPT4dR/E M2NHQ45Cj5AHZoPiPMDE8U2dRdQpXJ0m2NDHtt9WsNM5rTESKXy84ZYUSBCKz/0JNEvJ 6WSS+ge6PbmXGwuYs1PV3ScBiKvRD7MLGFEj0= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ieTDi8P1CkWw8j7c9zBDMq0IchoLIDpQlF+wKDBIUuA=; b=jDrkZ79niJdCPS+K4JZlU6Ks9bF/6nw675JowoI9kUKOOOSp7cNNlsZxbCV1qFvaPc 2TozgJ+IfxnHFgfLxDjcoqjig4NPZvO67Dq4lBAd/uyGCyKncHpybU/6h2svGKz8waMz RkmHXMtVFCFFmUyC1KSzEWRkMjqFy3opWtFeGPc4Q7CKo/q31CddrTRkXQ7W4QKMTorz Y3OqV9za6B4YWOBS5y0BRSgW5djZFonPSJT++EKpkj4SX/+cQgTAKn4jd1KGHhNOlWDN zOROJb73w2+3hZrBv3I3znrWHaHxUlm2zxcZWieaeTurOvVL4T3qL49K4SLhTCUSFrxH vrkA== X-Gm-Message-State: APjAAAUeH/ZxeqnPpdqoS6QlHzjfo+eJOv6J+nbbUkK7z2cLX5pscIDs nvt/lxkYPGF+ZdOPaaz4skfS7MTWSHc= X-Google-Smtp-Source: APXvYqyT4/lTfhTjDm6Y7S15BoF1KK9/xIh8oKMm+NDVn58pMRyYqAqNPVtBA3jCtkcncnpYxi7yEg== X-Received: by 2002:a05:6638:73a:: with SMTP id j26mr18171333jad.116.1575852107290; Sun, 08 Dec 2019 16:41:47 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id n3sm6286212ilm.74.2019.12.08.16.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 16:41:46 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH v7 08/17] x86: apl: Add PUNIT driver Date: Sun, 8 Dec 2019 17:40:11 -0700 Message-Id: <20191208173929.v7.8.I977f8cfb2c07f69c043475ac1b91794f4f4d4de5@changeid> X-Mailer: git-send-email 2.24.0.393.g34dc348eaf-goog In-Reply-To: <20191208173929.v7.4.I5ba86662e42269ac50c05b6db34832a966dad79a@changeid> References: <20191208173929.v7.4.I5ba86662e42269ac50c05b6db34832a966dad79a@changeid> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Add a driver for the Apollo Lake P-unit (power unit). It is modelled as a syscon driver since it only needs to be probed. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v7: None Changes in v6: - Drop Glacier Lake code - Drop platform data and pre-PCI code, since DM PCI is available in SPL Changes in v5: None Changes in v4: - Name this P-Unit instead of power unit, in the commit message - apollolake -> Apollo Lake Changes in v3: - Use pci_get_devfn() Changes in v2: None arch/x86/cpu/apollolake/Makefile | 3 + arch/x86/cpu/apollolake/punit.c | 94 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 arch/x86/cpu/apollolake/punit.c diff --git a/arch/x86/cpu/apollolake/Makefile b/arch/x86/cpu/apollolake/Makefile index 36eefcbad7..875d454157 100644 --- a/arch/x86/cpu/apollolake/Makefile +++ b/arch/x86/cpu/apollolake/Makefile @@ -3,6 +3,9 @@ # Copyright 2019 Google LLC obj-$(CONFIG_SPL_BUILD) += systemagent.o +ifndef CONFIG_TPL_BUILD +obj-y += punit.o +endif obj-y += hostbridge.o obj-y += itss.o diff --git a/arch/x86/cpu/apollolake/punit.c b/arch/x86/cpu/apollolake/punit.c new file mode 100644 index 0000000000..1a131fb0b1 --- /dev/null +++ b/arch/x86/cpu/apollolake/punit.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2019 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Punit Initialisation code. This all isn't documented, but + * this is the recipe. + */ +static int punit_init(struct udevice *dev) +{ + struct udevice *cpu; + u32 reg; + ulong start; + int ret; + + /* Thermal throttle activation offset */ + ret = uclass_first_device_err(UCLASS_CPU, &cpu); + if (ret) + return log_msg_ret("Cannot find CPU", ret); + cpu_configure_thermal_target(cpu); + + /* + * Software Core Disable Mask (P_CR_CORE_DISABLE_MASK_0_0_0_MCHBAR). + * Enable all cores here. + */ + writel(0, MCHBAR_REG(CORE_DISABLE_MASK)); + + /* P-Unit bring up */ + reg = readl(MCHBAR_REG(BIOS_RESET_CPL)); + if (reg == 0xffffffff) { + /* P-unit not found */ + debug("Punit MMIO not available\n"); + return -ENOENT; + } + + /* Set Punit interrupt pin IPIN offset 3D */ + dm_pci_write_config8(dev, PCI_INTERRUPT_PIN, 0x2); + + /* Set PUINT IRQ to 24 and INTPIN LOCK */ + writel(PUINT_THERMAL_DEVICE_IRQ_VEC_NUMBER | + PUINT_THERMAL_DEVICE_IRQ_LOCK, + MCHBAR_REG(PUNIT_THERMAL_DEVICE_IRQ)); + + /* Stage0 BIOS Reset Complete (RST_CPL) */ + enable_bios_reset_cpl(); + + /* + * Poll for bit 8 to check if PCODE has completed its action in response + * to BIOS Reset complete. We wait here till 1 ms for the bit to get + * set. + */ + start = get_timer(0); + while (!(readl(MCHBAR_REG(BIOS_RESET_CPL)) & PCODE_INIT_DONE)) { + if (get_timer(start) > 1) { + debug("PCODE Init Done timeout\n"); + return -ETIMEDOUT; + } + udelay(100); + } + debug("PUNIT init complete\n"); + + return 0; +} + +static int apl_punit_probe(struct udevice *dev) +{ + if (spl_phase() == PHASE_SPL) + return punit_init(dev); + + return 0; +} + +static const struct udevice_id apl_syscon_ids[] = { + { .compatible = "intel,apl-punit", .data = X86_SYSCON_PUNIT }, + { } +}; + +U_BOOT_DRIVER(syscon_intel_punit) = { + .name = "intel_punit_syscon", + .id = UCLASS_SYSCON, + .of_match = apl_syscon_ids, + .probe = apl_punit_probe, +};