From nobody Mon Jan 26 22:53:15 2026 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 880B726C385 for ; Mon, 26 Jan 2026 19:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454489; cv=none; b=clFswvi4c0g0fVhcPOcDmTJ+U6DcXEP/fx5mRAgyLc3dfmhVHtz0Q0IaEKHo9XWDAbSf71LqCJwbw/Ww1xNX3CbbidOCtaVw5C/4kF+awfH28gaVjhYqvIMCy40yuc5HxnfFo/CJKSFO0HSVIuIQ20b28YQFTExZcCTEdpV8a7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454489; c=relaxed/simple; bh=jNDdUruLQ4NJEJ/OpjZ8iy5uqg+2jOYXB4pKKupU3R0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ah1e4JnuUOQejzpmruvphtqOi6Fpe+Z/Pi5/otKgjZHje8hZSNn8NBXgASqy10pZallBaebfnuEDTFUBNUhfFkWhFyqUWaeBdKtaRolL7+AIA9VoIgFR9DYXTCho6RW/F4/J+GpF8jRBGNFVdaBtoSLXnTTTNPedZk7k/oG3pls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=blxmw2oO; arc=none smtp.client-ip=209.85.128.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="blxmw2oO" Received: by mail-wm1-f66.google.com with SMTP id 5b1f17b1804b1-47d6a1f08bbso22514925e9.2 for ; Mon, 26 Jan 2026 11:08:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769454486; x=1770059286; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WW/HnbEVXP7K0ODU5oJ6HSJhtEpR7FF8JH3bP2DOemc=; b=blxmw2oOAnEnW4koD+G0DNbihcMKhPRHeXu2bEJ3lL3+XiLLlFkjMFW10IFqo1CEr6 cLs5yAHfszXLpvGuSdA/TOCS4NQjSGdW7hekY1oZvJKfioQyhT/iBl97Qwzf1XhqMgjZ iYUw9ObygAyxwgJ2KrG4dwLtm6RCUUCHgmii07kdJXUin1waNZGC0qOSUCDFqEoiukjJ rHeKiggNlhnneaf6xksI2rLX5Ir4iTW4mq3loPMFiRI4inkva0JjKwkT/qJpZ5efbmG9 TGpHIe6VU+R43RPyP4HRkxFJOz2HY6PK7BIPGmjvUGJHN2pO8ulilAvdlm4G4+i+P0wg M6kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769454486; x=1770059286; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WW/HnbEVXP7K0ODU5oJ6HSJhtEpR7FF8JH3bP2DOemc=; b=FrF64k6iYA9l/Zll2OedAsqDDzO3DB+lo/oqtqG5PCaC2VrqodWuVFh3mRq9GvLVoa 3DqbLmriAlnRQE6xBCUsfmpXZiwD8E7de42680KhQo3/wCuTJIUklKMTHMSULv63NEaw AZCsi9AeWtCCxn4Zum3xzS0UWxxiLbXYOEeyO3GWGtVMmvLk4xbOUKlJb8PjQsj3PUBL cC7d0/9n6Mj7rLQHya/dQHuKShDSeckTJI+TQKeVPs0B6tS8urlBahsvrzcfIicVaKbG 48oUkv4H17jC7Kz63RMpS8rWxbcrzn07H4XZpTSnlNoJpw44igKBL/LGEfSIttnCMrqP XUvg== X-Gm-Message-State: AOJu0YxpWwimJEsgcRvHRzE0Vgb6wtczhZHws8APnrWdz+0RhU89oaoD FYI+svrvr0Nw1N/FtPDt3AGz79WcLyDhLafNv/BmjZengSMyqEk6a/7T X-Gm-Gg: AZuq6aLvZOml80qQvXZo1oQdyEZYpft8CEeC5wioXvA0Pk23Apu/nCuNSOa1PbwMrPv iUc4p4oVUU9YAwd+dlMZqfI3FZ+N9sMP2IOZIUkxFhSzUpuVnm2qiOHRY/qv9mef0BSTs6Ddge0 ip/GoUv0kkKHfHsN0+XSURxdYbWliiZ/UoGfBbl2EOM0Ic4iiVDEc6quxWbLu/h7iGbPQk/OTa1 WbAYt+LECpdPaxpWZTbV85C1CqCDnXGGwYGC+Wa0fBy8JGHkbMP/TGGXq+YjPv5R4BLG+wjC+Og BPFCy0KAMHK/JID6HPPSL0VmrhhU+OtjCnhTqYE+cB/QLXRv+pwUOMdMltnDSzjGoa68Ek4sC+v FTzHcOP2AzRMhCerhBcliy6+7r151Kra3DXFVZMzt0jxuSeUbcAs4YtFbdu8bRbQzpIQUXVwpyM cjG71ouAnvUJs= X-Received: by 2002:a05:6000:40cb:b0:432:4c01:db00 with SMTP id ffacd0b85a97d-435ca145762mr9273007f8f.27.1769454485769; Mon, 26 Jan 2026 11:08:05 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c24bf8sm31802030f8f.11.2026.01.26.11.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 11:08:05 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Svyatoslav Ryhel , Sumit Gupta , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 1/5] dt-bindings: memory: Document Tegra114 Memory Controller Date: Mon, 26 Jan 2026 21:07:51 +0200 Message-ID: <20260126190755.78475-2-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126190755.78475-1-clamor95@gmail.com> References: <20260126190755.78475-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add Tegra114 support into existing Tegra124 MC schema with the most notable difference in the amount of EMEM timings. Signed-off-by: Svyatoslav Ryhel Reviewed-by: Rob Herring (Arm) --- .../nvidia,tegra124-mc.yaml | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/Documentation/devicetree/bindings/memory-controllers/nvidia,te= gra124-mc.yaml b/Documentation/devicetree/bindings/memory-controllers/nvidi= a,tegra124-mc.yaml index 7b18b4d11e0a..f8747cebb680 100644 --- a/Documentation/devicetree/bindings/memory-controllers/nvidia,tegra124-= mc.yaml +++ b/Documentation/devicetree/bindings/memory-controllers/nvidia,tegra124-= mc.yaml @@ -19,7 +19,9 @@ description: | =20 properties: compatible: - const: nvidia,tegra124-mc + enum: + - nvidia,tegra114-mc + - nvidia,tegra124-mc =20 reg: maxItems: 1 @@ -64,29 +66,12 @@ patternProperties: =20 nvidia,emem-configuration: $ref: /schemas/types.yaml#/definitions/uint32-array - description: | + description: Values to be written to the EMEM register block. See section - "15.6.1 MC Registers" in the TRM. - items: - - description: MC_EMEM_ARB_CFG - - description: MC_EMEM_ARB_OUTSTANDING_REQ - - description: MC_EMEM_ARB_TIMING_RCD - - description: MC_EMEM_ARB_TIMING_RP - - description: MC_EMEM_ARB_TIMING_RC - - description: MC_EMEM_ARB_TIMING_RAS - - description: MC_EMEM_ARB_TIMING_FAW - - description: MC_EMEM_ARB_TIMING_RRD - - description: MC_EMEM_ARB_TIMING_RAP2PRE - - description: MC_EMEM_ARB_TIMING_WAP2PRE - - description: MC_EMEM_ARB_TIMING_R2R - - description: MC_EMEM_ARB_TIMING_W2W - - description: MC_EMEM_ARB_TIMING_R2W - - description: MC_EMEM_ARB_TIMING_W2R - - description: MC_EMEM_ARB_DA_TURNS - - description: MC_EMEM_ARB_DA_COVERS - - description: MC_EMEM_ARB_MISC0 - - description: MC_EMEM_ARB_MISC1 - - description: MC_EMEM_ARB_RING1_THROTTLE + "20.11.1 MC Registers" in the Tegea114 TRM or + "15.6.1 MC Registers" in the Tegra124 TRM. + minItems: 18 + maxItems: 19 =20 required: - clock-frequency --=20 2.51.0 From nobody Mon Jan 26 22:53:15 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4C23274B2B for ; Mon, 26 Jan 2026 19:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454490; cv=none; b=FS5UxKaaNItdTHEZKD0FvmwGShD2it++NcCNJe6UmiXyO8YhGI0H0s8EQzPSSxS9BjLPda33UQlwJSE0LCxXmBu1LSxgpxmxWUHwV2fArhyP9keuvr3BEcCGra0XfcpjLRUYCTvLTvxop4sPy11g+9vH2m5TnFCbBVSrrOsqOUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454490; c=relaxed/simple; bh=vCLI0D38I7UFcPwZZbFQiumGdDRiJ+S0BamD2HUcfBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p6LZviEgAnufapP8JFmw4zUuiFqMKGWE9h5r7Sws+Td+McR3lbYkyXvhiYsLhIBlfmMxaBIjbioEDh5uyV2oXB2FzztOhL0Ntpu/fbYdtoR54aCzym0VperefNj5vo/6ashACxUOMBJpc7luJMxeps1OOtcfPfFSX8ULWYg7XIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dtjq860X; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dtjq860X" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-42fed090e5fso2965795f8f.1 for ; Mon, 26 Jan 2026 11:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769454487; x=1770059287; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VBPLwWIdtjG1mcTPYivwQD9uLIkx3G/GI8kSilZAKuE=; b=dtjq860Xkddp4LLF5ws38n7lvyP0RYMlhbdwvRlg6KfW6+FuAG2SrKpbsb78om5mDK X35Iurakx+oP3TdQqSlH6ju42ozsf86CHxr3JZ97izk5lBCyQoe9MEwru54fjvdY4pdc gcduvpz5/h6Jr7TvuBkhlPUOOQ0aZnKfys+RN/gqDCvQfSHV5CECCdpGtNjTRwRzkfQB xSH/53lGVJep54PPKeSAZ+0wCqBCpOy6reyjG6rjhXgkmaliQhzAHLtrSqaW+r45g4cH obkJ3YlVnzTnUiBfxT3dJVcRY8TTXNGTJFdP2nQuFe9mroz7g7pka3Bpc4JWm0q8BARV GaXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769454487; x=1770059287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VBPLwWIdtjG1mcTPYivwQD9uLIkx3G/GI8kSilZAKuE=; b=YETnmtU/oicLPwhh2DhpMzEuE094LqvuxFBrv9CLAm5ABay+M5aUi/bMkpMC80WCBi MVPErx6sILn0YFcc/jipMzljDSEnRh+6jcdHDtJpEB/4Q7kWwDPb9ZUJciT6PvPPKAQJ 87JM+88FBhDH/ZLhq85zVEseyfGTKYd3dUTYLEcxTM1TalUE9aI0w8WWbRm1w31pkLpB KXiRMQeyUvLVpe3DVuNzcQ9So14v4Fix6Q2QRf85Csg33ISk1+sSRxJsU/finHSfjqb0 /X5ZgbXXvYBsxXzMezeFeylHJE0wwnYkrdWf3akRAoJ9mU9xnhjW7g9L7+we7EjewpLs eZ+g== X-Gm-Message-State: AOJu0YzS1HzAJufdCGmXcjKaE/Q82IOSsooVnZqtiIEOWKnSdgQfjXaX e5I84EJ4Nw8U8YkR3UH5VmiSWaZQYtoyU3CN+Fxm1MGjU5VkFWe6bPDv X-Gm-Gg: AZuq6aIcrCIm+Y34KUOf5x87WlrhPJfvuTSX94Maw2qz+TJuTbgKZdTMrPOEBTMdsg1 8gOWKIA3Sfwc61/lbCHg+6vigpPtw7DiFMq9e0pxAl/iq9uDB48oC2equCpIgJacCBDe2TiQtY7 phXKqvLTvAbQegjoFIvBK8RgzHgOzTXNGRHL2Q7KZQWWzSjbG50JVwZtccRaGvm6KxWCytAbsLg DCZ29+iZdSRDj4WW3pdKNxMRmxuTnThkBs/cuyKU2LVKDXqAKa0nwuTabfG46PyriJL3BIxItRZ 30mXm88EkCTm/Jsq+j7jlU/o5LRKO6B0fETKvsCVtY7zzytgk4t+mhkr8QG108LZMF/0q9Q4yke KvrVM6XWb6StapR543RvADut0aWNX0ORCrSbGwVKZGvYNwXlwOJkcekV7eqRvhXHvMIxKv0feWF G8 X-Received: by 2002:a5d:64e8:0:b0:435:95dc:b8ca with SMTP id ffacd0b85a97d-435ca1addbcmr8972904f8f.40.1769454486750; Mon, 26 Jan 2026 11:08:06 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c24bf8sm31802030f8f.11.2026.01.26.11.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 11:08:06 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Svyatoslav Ryhel , Sumit Gupta , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 2/5] memory: tegra: implement EMEM regs and ICC ops for Tegra114 Date: Mon, 26 Jan 2026 21:07:52 +0200 Message-ID: <20260126190755.78475-3-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126190755.78475-1-clamor95@gmail.com> References: <20260126190755.78475-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prepare Internal Memory Controller for introduction of External Memory Controller. Signed-off-by: Svyatoslav Ryhel Reviewed-by: Mikko Perttunen --- drivers/memory/tegra/tegra114.c | 193 ++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/drivers/memory/tegra/tegra114.c b/drivers/memory/tegra/tegra11= 4.c index d03a5d162dbd..c615857f7fad 100644 --- a/drivers/memory/tegra/tegra114.c +++ b/drivers/memory/tegra/tegra114.c @@ -3,6 +3,7 @@ * Copyright (C) 2014 NVIDIA CORPORATION. All rights reserved. */ =20 +#include #include #include =20 @@ -1165,6 +1166,195 @@ static const struct tegra_mc_reset tegra114_mc_rese= ts[] =3D { TEGRA114_MC_RESET(VI, 0x200, 0x204, 17), }; =20 +static void tegra114_mc_tune_client_latency(struct tegra_mc *mc, + const struct tegra_mc_client *client, + unsigned int bandwidth_mbytes_sec) +{ + u32 arb_tolerance_compensation_nsec, arb_tolerance_compensation_div; + unsigned int fifo_size =3D client->fifo_size; + u32 arb_nsec, la_ticks, value; + + /* see 20.3.1.1 Client Configuration in Tegra4 TRM v01p */ + if (bandwidth_mbytes_sec) + arb_nsec =3D fifo_size * NSEC_PER_USEC / bandwidth_mbytes_sec; + else + arb_nsec =3D U32_MAX; + + /* + * Latency allowness should be set with consideration for the module's + * latency tolerance and internal buffering capabilities. + * + * Display memory clients use isochronous transfers and have very low + * tolerance to a belated transfers. Hence we need to compensate the + * memory arbitration imperfection for them in order to prevent FIFO + * underflow condition when memory bus is busy. + * + * VI clients also need a stronger compensation. + */ + switch (client->swgroup) { + case TEGRA_SWGROUP_MPCORE: + case TEGRA_SWGROUP_PTC: + /* + * We always want lower latency for these clients, hence + * don't touch them. + */ + return; + + case TEGRA_SWGROUP_DC: + case TEGRA_SWGROUP_DCB: + arb_tolerance_compensation_nsec =3D 1050; + arb_tolerance_compensation_div =3D 2; + break; + + case TEGRA_SWGROUP_VI: + arb_tolerance_compensation_nsec =3D 1050; + arb_tolerance_compensation_div =3D 1; + break; + + default: + arb_tolerance_compensation_nsec =3D 150; + arb_tolerance_compensation_div =3D 1; + break; + } + + if (arb_nsec > arb_tolerance_compensation_nsec) + arb_nsec -=3D arb_tolerance_compensation_nsec; + else + arb_nsec =3D 0; + + arb_nsec /=3D arb_tolerance_compensation_div; + + /* + * Latency allowance is a number of ticks a request from a particular + * client may wait in the EMEM arbiter before it becomes a high-priority + * request. + */ + la_ticks =3D arb_nsec / mc->tick; + la_ticks =3D min(la_ticks, client->regs.la.mask); + + value =3D mc_readl(mc, client->regs.la.reg); + value &=3D ~(client->regs.la.mask << client->regs.la.shift); + value |=3D la_ticks << client->regs.la.shift; + mc_writel(mc, value, client->regs.la.reg); +} + +static int tegra114_mc_icc_set(struct icc_node *src, struct icc_node *dst) +{ + struct tegra_mc *mc =3D icc_provider_to_tegra_mc(src->provider); + const struct tegra_mc_client *client =3D &mc->soc->clients[src->id]; + u64 peak_bandwidth =3D icc_units_to_bps(src->peak_bw); + + /* + * Skip pre-initialization that is done by icc_node_add(), which sets + * bandwidth to maximum for all clients before drivers are loaded. + * + * This doesn't make sense for us because we don't have drivers for all + * clients and it's okay to keep configuration left from bootloader + * during boot, at least for today. + */ + if (src =3D=3D dst) + return 0; + + /* convert bytes/sec to megabytes/sec */ + do_div(peak_bandwidth, 1000000); + + tegra114_mc_tune_client_latency(mc, client, peak_bandwidth); + + return 0; +} + +static int tegra114_mc_icc_aggreate(struct icc_node *node, u32 tag, u32 av= g_bw, + u32 peak_bw, u32 *agg_avg, u32 *agg_peak) +{ + /* + * ISO clients need to reserve extra bandwidth up-front because + * there could be high bandwidth pressure during initial filling + * of the client's FIFO buffers. Secondly, we need to take into + * account impurities of the memory subsystem. + */ + if (tag & TEGRA_MC_ICC_TAG_ISO) + peak_bw =3D tegra_mc_scale_percents(peak_bw, 400); + + *agg_avg +=3D avg_bw; + *agg_peak =3D max(*agg_peak, peak_bw); + + return 0; +} + +static struct icc_node_data * +tegra114_mc_of_icc_xlate_extended(const struct of_phandle_args *spec, void= *data) +{ + struct tegra_mc *mc =3D icc_provider_to_tegra_mc(data); + const struct tegra_mc_client *client; + unsigned int i, idx =3D spec->args[0]; + struct icc_node_data *ndata; + struct icc_node *node; + + list_for_each_entry(node, &mc->provider.nodes, node_list) { + if (node->id !=3D idx) + continue; + + ndata =3D kzalloc(sizeof(*ndata), GFP_KERNEL); + if (!ndata) + return ERR_PTR(-ENOMEM); + + client =3D &mc->soc->clients[idx]; + ndata->node =3D node; + + switch (client->swgroup) { + case TEGRA_SWGROUP_DC: + case TEGRA_SWGROUP_DCB: + case TEGRA_SWGROUP_PTC: + case TEGRA_SWGROUP_VI: + /* these clients are isochronous by default */ + ndata->tag =3D TEGRA_MC_ICC_TAG_ISO; + break; + + default: + ndata->tag =3D TEGRA_MC_ICC_TAG_DEFAULT; + break; + } + + return ndata; + } + + for (i =3D 0; i < mc->soc->num_clients; i++) { + if (mc->soc->clients[i].id =3D=3D idx) + return ERR_PTR(-EPROBE_DEFER); + } + + dev_err(mc->dev, "invalid ICC client ID %u\n", idx); + + return ERR_PTR(-EINVAL); +} + +static const struct tegra_mc_icc_ops tegra114_mc_icc_ops =3D { + .xlate_extended =3D tegra114_mc_of_icc_xlate_extended, + .aggregate =3D tegra114_mc_icc_aggreate, + .set =3D tegra114_mc_icc_set, +}; + +static const unsigned long tegra114_mc_emem_regs[] =3D { + MC_EMEM_ARB_CFG, + MC_EMEM_ARB_OUTSTANDING_REQ, + MC_EMEM_ARB_TIMING_RCD, + MC_EMEM_ARB_TIMING_RP, + MC_EMEM_ARB_TIMING_RC, + MC_EMEM_ARB_TIMING_RAS, + MC_EMEM_ARB_TIMING_FAW, + MC_EMEM_ARB_TIMING_RRD, + MC_EMEM_ARB_TIMING_RAP2PRE, + MC_EMEM_ARB_TIMING_WAP2PRE, + MC_EMEM_ARB_TIMING_R2R, + MC_EMEM_ARB_TIMING_W2W, + MC_EMEM_ARB_TIMING_R2W, + MC_EMEM_ARB_TIMING_W2R, + MC_EMEM_ARB_DA_TURNS, + MC_EMEM_ARB_DA_COVERS, + MC_EMEM_ARB_MISC0, + MC_EMEM_ARB_RING1_THROTTLE, +}; + const struct tegra_mc_soc tegra114_mc_soc =3D { .clients =3D tegra114_mc_clients, .num_clients =3D ARRAY_SIZE(tegra114_mc_clients), @@ -1172,10 +1362,13 @@ const struct tegra_mc_soc tegra114_mc_soc =3D { .atom_size =3D 32, .client_id_mask =3D 0x7f, .smmu =3D &tegra114_smmu_soc, + .emem_regs =3D tegra114_mc_emem_regs, + .num_emem_regs =3D ARRAY_SIZE(tegra114_mc_emem_regs), .intmask =3D MC_INT_INVALID_SMMU_PAGE | MC_INT_SECURITY_VIOLATION | MC_INT_DECERR_EMEM, .reset_ops =3D &tegra_mc_reset_ops_common, .resets =3D tegra114_mc_resets, .num_resets =3D ARRAY_SIZE(tegra114_mc_resets), + .icc_ops =3D &tegra114_mc_icc_ops, .ops =3D &tegra30_mc_ops, }; --=20 2.51.0 From nobody Mon Jan 26 22:53:15 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CE1A2797B5 for ; Mon, 26 Jan 2026 19:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454491; cv=none; b=e6i+3pIYHQDUxpN5vL8Qkxr7Gna/VMZK33z9B7aA7UVlrOFNuMPMTz2sy0SivWJ4ryEpQTxzqxFxOGl72UMTNXesJFr+Bavg/+3xiGg9xZt8SbVVd3wZLHu1Jiz+KPckX1kfG98iOS+NvVlSlLb6DryRcZTUJ/D3vY4GUrl3bMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454491; c=relaxed/simple; bh=EpZL32Jyo1zVK7iE7f/cCfj6bklP2cCKT0AbKLrFi34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ECNmeyJ2q8brXIdsa0bdzdc4Rh1tcKyY1S0BSxM81dhvtFov3v671acMBmJ/Qu4vOgYsl4nUAwKRsGCXsTl+Y/vvqsZINpjmCk9KdLKeQ9ITwzw1VPjkYzpkoRTY5c5e6+PQjNwdXgV25QHUprj9qmx6UBwzVaGGoGDfkcO7nEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KTQR7gpY; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KTQR7gpY" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-435a11957f6so4019512f8f.0 for ; Mon, 26 Jan 2026 11:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769454488; x=1770059288; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vVffN9Slo7nSA6jMy+HnfjnzdqrKlZ/cdmvcQBPmzT0=; b=KTQR7gpYu/RCD2MJ5rsMNPwDfvod7sDGilYSHHLM3B0VRhTObBTARnWRvvKj/YqOop U4uM7rir6hEQztda0U+v217aKZAcWmeGt81LxTyB7Ev0G1XL6gsVkKnUh9u56fyMQltI /5NFdYoPLINkyY6BDbYA6js7jrcmpBlZIGXim6x6813H7hHA5X7ManDbBmeYU1EU3c5S 1k3ef5vsYqDZ9cw5b8J5d96ekh/d0LpeS12gMidZzinO/7hK6OOFKK51a3u8qnAx66yL V/WowpUq+myeOboIM60df3Q27R2ONkYqhaBdEbwegX855V6D0zX4u26IxAgRjwa4IOQz KTbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769454488; x=1770059288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vVffN9Slo7nSA6jMy+HnfjnzdqrKlZ/cdmvcQBPmzT0=; b=TduJGsnr48X8edcC2RNw7UrGPEE4RV0tK2omh9Fqr2dqu55jLeXBEY4RK52tIID/k8 XI7c8y4YgHWClvybqkGafjUZwwecE77kIft5s+E+6ZNuJ360bO/dcdNqiqgKaamdfHx0 vMur3GAT6KFP+SvKs2Euo3oCfOXWjuNh4NoMgUd1TMGRWAjl5YqN46507MGU9G1eGDQn CaDO+SIOM33IVLeu2uHihAHNuhQMBTgc88BbtfgMzs7DGYvofzhe7zFi8sHI6rJaSHia 2ozpG1dh7aaiswP5D+9OVvvqG3sQctGvQ4sgzjNL0VZTIG8+873bK6YNxRySAez3d5fd Z/Sw== X-Gm-Message-State: AOJu0Yz17G5STEB4QOFpoj4X5LKionRCt4cgz2Jk4jImsEsw4d2lzS06 O2uBRntvpLAtPZBycMW30gWUMoVn11pZSSOUYMpr/yG6B8ZijzrC/M7EVjOYjA== X-Gm-Gg: AZuq6aK04RRNWxAUaW3ySoAKP8Kq0BoWbkTkchQUtx64AcNQhI/kviLQHJlZE3XN0+b TZW7ifMRYO1ku9VLhRJoHPvlS4ENPc6lCbtDRGUoOwSn3xlHglcm1b8pCrKwyAQ0zacfD1w9r8d suXBAHpppBI70GrcreqzfJ30eqrVK4koUdJt13XNIDkGRQBA5o2pA9M7ipNH23W5CJBiCw0G2ge fKfNwy4HWkfI/Gwgo6jbuKELh3WN/3uSnVr3w4/6pnHLS5I637D+IRxX0hxNaQ1SCZP0pr7MZrO hWHUT2Bn9bw5jAMIYNfQjfwGOCju8G0cxRXBB0VrGZRnASTyQlFSH8xLYEs55eMT7mH8JaNs2Lt PzqdjXKVPuKEFYxU/Q3MDEeCV2adTBPn3bWFxClDhAvP53baJjeljOj2JRRks6qT3NP3fV+qsOd sY X-Received: by 2002:a05:6000:250f:b0:435:9a2b:53d0 with SMTP id ffacd0b85a97d-435ca1aa82dmr8665439f8f.45.1769454487759; Mon, 26 Jan 2026 11:08:07 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c24bf8sm31802030f8f.11.2026.01.26.11.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 11:08:07 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Svyatoslav Ryhel , Sumit Gupta , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 3/5] dt-bindings: memory: Add Tegra114 memory client IDs Date: Mon, 26 Jan 2026 21:07:53 +0200 Message-ID: <20260126190755.78475-4-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126190755.78475-1-clamor95@gmail.com> References: <20260126190755.78475-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Each memory client has unique hardware ID, add these IDs. Signed-off-by: Svyatoslav Ryhel Acked-by: Rob Herring (Arm) Reviewed-by: Mikko Perttunen --- include/dt-bindings/memory/tegra114-mc.h | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/include/dt-bindings/memory/tegra114-mc.h b/include/dt-bindings= /memory/tegra114-mc.h index dfe99c8a5ba5..5e0d6a1b91f2 100644 --- a/include/dt-bindings/memory/tegra114-mc.h +++ b/include/dt-bindings/memory/tegra114-mc.h @@ -40,4 +40,71 @@ #define TEGRA114_MC_RESET_VDE 14 #define TEGRA114_MC_RESET_VI 15 =20 +#define TEGRA114_MC_PTCR 0 +#define TEGRA114_MC_DISPLAY0A 1 +#define TEGRA114_MC_DISPLAY0AB 2 +#define TEGRA114_MC_DISPLAY0B 3 +#define TEGRA114_MC_DISPLAY0BB 4 +#define TEGRA114_MC_DISPLAY0C 5 +#define TEGRA114_MC_DISPLAY0CB 6 +#define TEGRA114_MC_DISPLAY1B 7 +#define TEGRA114_MC_DISPLAY1BB 8 +#define TEGRA114_MC_EPPUP 9 +#define TEGRA114_MC_G2PR 10 +#define TEGRA114_MC_G2SR 11 +#define TEGRA114_MC_MPEUNIFBR 12 +#define TEGRA114_MC_VIRUV 13 +#define TEGRA114_MC_AFIR 14 +#define TEGRA114_MC_AVPCARM7R 15 +#define TEGRA114_MC_DISPLAYHC 16 +#define TEGRA114_MC_DISPLAYHCB 17 +#define TEGRA114_MC_FDCDRD 18 +#define TEGRA114_MC_FDCDRD2 19 +#define TEGRA114_MC_G2DR 20 +#define TEGRA114_MC_HDAR 21 +#define TEGRA114_MC_HOST1XDMAR 22 +#define TEGRA114_MC_HOST1XR 23 +#define TEGRA114_MC_IDXSRD 24 +#define TEGRA114_MC_IDXSRD2 25 +#define TEGRA114_MC_MPE_IPRED 26 +#define TEGRA114_MC_MPEAMEMRD 27 +#define TEGRA114_MC_MPECSRD 28 +#define TEGRA114_MC_PPCSAHBDMAR 29 +#define TEGRA114_MC_PPCSAHBSLVR 30 +#define TEGRA114_MC_SATAR 31 +#define TEGRA114_MC_TEXSRD 32 +#define TEGRA114_MC_TEXSRD2 33 +#define TEGRA114_MC_VDEBSEVR 34 +#define TEGRA114_MC_VDEMBER 35 +#define TEGRA114_MC_VDEMCER 36 +#define TEGRA114_MC_VDETPER 37 +#define TEGRA114_MC_MPCORELPR 38 +#define TEGRA114_MC_MPCORER 39 +#define TEGRA114_MC_EPPU 40 +#define TEGRA114_MC_EPPV 41 +#define TEGRA114_MC_EPPY 42 +#define TEGRA114_MC_MPEUNIFBW 43 +#define TEGRA114_MC_VIWSB 44 +#define TEGRA114_MC_VIWU 45 +#define TEGRA114_MC_VIWV 46 +#define TEGRA114_MC_VIWY 47 +#define TEGRA114_MC_G2DW 48 +#define TEGRA114_MC_AFIW 49 +#define TEGRA114_MC_AVPCARM7W 50 +#define TEGRA114_MC_FDCDWR 51 +#define TEGRA114_MC_FDCDWR2 52 +#define TEGRA114_MC_HDAW 53 +#define TEGRA114_MC_HOST1XW 54 +#define TEGRA114_MC_ISPW 55 +#define TEGRA114_MC_MPCORELPW 56 +#define TEGRA114_MC_MPCOREW 57 +#define TEGRA114_MC_MPECSWR 58 +#define TEGRA114_MC_PPCSAHBDMAW 59 +#define TEGRA114_MC_PPCSAHBSLVW 60 +#define TEGRA114_MC_SATAW 61 +#define TEGRA114_MC_VDEBSEVW 62 +#define TEGRA114_MC_VDEDBGW 63 +#define TEGRA114_MC_VDEMBEW 64 +#define TEGRA114_MC_VDETPMW 65 + #endif --=20 2.51.0 From nobody Mon Jan 26 22:53:15 2026 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 684952737F9 for ; Mon, 26 Jan 2026 19:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454492; cv=none; b=cAQSKeL+X2AimJuZEis8+NxuNO2EruXD1J47i4NOW+bTPzX3f4tHqzg9KntrsHSMxokNUTqP2PL6lQS49dj2TNgqUlSGjbvCW3pHKfuVsl0kiZWWc7V0Tnvrpv3Pc1XnRm2onPTT/dwpTurIQNgsmQ8VXS5m3q4p8Qx8PTH7J2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769454492; c=relaxed/simple; bh=84Dqsd4+a5f1NKPye0gyTGquAHxSzQnz5E8L5x6vjSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ItpOFHrSTbhiD8XCaYg5yOxttQ8D4m5DLzzfzgEZiqPcCxOQ2RgAP9WC8q81IOlAnBeadlQ3wxVFZDwlD9pdxePgQ15CCwImIF9R/AjpgP2AZZe6DJoxM+u4i8e7T3LI4lEwSIZlH73ONwDudW8S9yLaaNCJLbqDCRO5eOhFvOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AGu57Lxw; arc=none smtp.client-ip=209.85.221.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AGu57Lxw" Received: by mail-wr1-f68.google.com with SMTP id ffacd0b85a97d-4359a16a400so4390081f8f.1 for ; Mon, 26 Jan 2026 11:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769454489; x=1770059289; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1CfO1Q8+JOBgDtlGnZkxxf2jPv4aks+RLJbYHeFtCGM=; b=AGu57LxwsRe5CiiCUxvF2rB05WInM1h5q98KyWHrH/yG9VLPdhGF1GLiEs9BLFhuo2 Z4QTtuSFckcoYLr9jjSFiQv0Ycc83+ss3+EKpHEyueeEyI9WadM2vKNr/u+quaTVauLb jbqgr+ZHkoEgtlk4uVWtcX6Y2RdrVOj7P3YCGsakm15qNHd0Zq5kERecYsgabjrk30DQ vCyHXdFsHyYGKwNnjovumeTWF9E586hnAhQzKLk629gZdYK1X1Ar7AguE2clBWna1yf1 KFdIDNu8hf4MRDtVvKgXLGZduKBbjP8dJvqqqvErClCkO1BRi+9bo7B1ZbDui2h3FJ6/ cCKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769454489; x=1770059289; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1CfO1Q8+JOBgDtlGnZkxxf2jPv4aks+RLJbYHeFtCGM=; b=MdLwhwvYkNvIGRygXTSb86TSz8M1/8Y21fjMW3grYeVbSQKDcLTYSUgp3nb9YgqyJ6 oqE0AyPT30SdUgpwA/66J+baHPieWS535MTeNsq5a+m5kwISjKFNFyZaDMr1scBKeovu HQDrUvbepn6TByuTJPcPlWs0cSxvOHmsfbn1+sW91r4EiuW0mjcIrvW3JySulvTQbjVV 6RcwlQEy2oZrtkkWbDlJPfV0v0O481zGne73ty81+sbeD2iAjRM/WEvbg+wzEtsVdQHZ Hc7elMH8Rs7gvxkz7b30z2jAv+p984bYvJwvw9FIpTOY18a3aiL3aKJP6Oq//1eGYFl/ uHzA== X-Gm-Message-State: AOJu0YyG+pEbCtLq25TDTXLl4BULNqhpiIl1bXL8xsa+pACwvSou1KMH I77Xpezjfuc6jn4ShcqTKE1G6teZXgrS2/QgHBydBj3g8uXRR0PHQdrF X-Gm-Gg: AZuq6aLPXooWxBghyliBs8OJQWV+WYGnPOIDMH7uwoRlR75h8IlKi1hGK233dLuWKP9 5W4vTRCkc3x9GHLHTQijFdJqg8h1wArSUfmcO0uiygUlTDJDlBvbYCxk5l9XdZuOIda/YR4+Wh2 PuQSJPORJMYYwccvG2UOyTIMiEdrW/5Y+a9FsIGfq7vn1epi6S76dk8SgUKqxTHwBbEzDktxSCg L37wMf87FRBRkg3LAsfQ6OX+bR2LkNkBIeNsGdROscXF71lIGdpXlY2ansnMYbhFTwDVbGKHovf /ulKT78SZVvNRWJ2/OU5dt1QBlqpWhzLkqA9mE7mUgWBGTfGNUlxj0av45vtOgmnW+w1PL1WfHd 6KICFKZiz+6llR6EsUWPm6keg1MOJmhLgcLH74LL3oRgzAdC55xKy+n0Hhe9zpQZyY+DmDbez0W RL X-Received: by 2002:a05:6000:290c:b0:42f:f627:3aa3 with SMTP id ffacd0b85a97d-435ca3a5816mr8945919f8f.56.1769454488774; Mon, 26 Jan 2026 11:08:08 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c24bf8sm31802030f8f.11.2026.01.26.11.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 11:08:08 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Svyatoslav Ryhel , Sumit Gupta , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 4/5] dt-bindings: memory: Document Tegra114 External Memory Controller Date: Mon, 26 Jan 2026 21:07:54 +0200 Message-ID: <20260126190755.78475-5-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126190755.78475-1-clamor95@gmail.com> References: <20260126190755.78475-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Include Tegra114 support into existing Tegra124 EMC schema with the most notable difference being the amount of EMC timings and a few SoC unique entries. Signed-off-by: Svyatoslav Ryhel Reviewed-by: Rob Herring (Arm) --- .../nvidia,tegra124-emc.yaml | 174 +++--------------- 1 file changed, 26 insertions(+), 148 deletions(-) diff --git a/Documentation/devicetree/bindings/memory-controllers/nvidia,te= gra124-emc.yaml b/Documentation/devicetree/bindings/memory-controllers/nvid= ia,tegra124-emc.yaml index f5f03bf36413..9398aae49093 100644 --- a/Documentation/devicetree/bindings/memory-controllers/nvidia,tegra124-= emc.yaml +++ b/Documentation/devicetree/bindings/memory-controllers/nvidia,tegra124-= emc.yaml @@ -16,7 +16,9 @@ description: | =20 properties: compatible: - const: nvidia,tegra124-emc + enum: + - nvidia,tegra114-emc + - nvidia,tegra124-emc =20 reg: maxItems: 1 @@ -29,6 +31,9 @@ properties: items: - const: emc =20 + interrupts: + maxItems: 1 + "#interconnect-cells": const: 0 =20 @@ -164,153 +169,12 @@ patternProperties: nvidia,emc-configuration: description: EMC timing characterization data. These are the registers (s= ee - section "15.6.2 EMC Registers" in the TRM) whose values need= to + section "20.11.2 EMC Registers" in the Tegra114 TRM or secti= on + "15.6.2 EMC Registers" in the Tegra124 TRM) whose values nee= d to be specified, according to the board documentation. $ref: /schemas/types.yaml#/definitions/uint32-array - items: - - description: EMC_RC - - description: EMC_RFC - - description: EMC_RFC_SLR - - description: EMC_RAS - - description: EMC_RP - - description: EMC_R2W - - description: EMC_W2R - - description: EMC_R2P - - description: EMC_W2P - - description: EMC_RD_RCD - - description: EMC_WR_RCD - - description: EMC_RRD - - description: EMC_REXT - - description: EMC_WEXT - - description: EMC_WDV - - description: EMC_WDV_MASK - - description: EMC_QUSE - - description: EMC_QUSE_WIDTH - - description: EMC_IBDLY - - description: EMC_EINPUT - - description: EMC_EINPUT_DURATION - - description: EMC_PUTERM_EXTRA - - description: EMC_PUTERM_WIDTH - - description: EMC_PUTERM_ADJ - - description: EMC_CDB_CNTL_1 - - description: EMC_CDB_CNTL_2 - - description: EMC_CDB_CNTL_3 - - description: EMC_QRST - - description: EMC_QSAFE - - description: EMC_RDV - - description: EMC_RDV_MASK - - description: EMC_REFRESH - - description: EMC_BURST_REFRESH_NUM - - description: EMC_PRE_REFRESH_REQ_CNT - - description: EMC_PDEX2WR - - description: EMC_PDEX2RD - - description: EMC_PCHG2PDEN - - description: EMC_ACT2PDEN - - description: EMC_AR2PDEN - - description: EMC_RW2PDEN - - description: EMC_TXSR - - description: EMC_TXSRDLL - - description: EMC_TCKE - - description: EMC_TCKESR - - description: EMC_TPD - - description: EMC_TFAW - - description: EMC_TRPAB - - description: EMC_TCLKSTABLE - - description: EMC_TCLKSTOP - - description: EMC_TREFBW - - description: EMC_FBIO_CFG6 - - description: EMC_ODT_WRITE - - description: EMC_ODT_READ - - description: EMC_FBIO_CFG5 - - description: EMC_CFG_DIG_DLL - - description: EMC_CFG_DIG_DLL_PERIOD - - description: EMC_DLL_XFORM_DQS0 - - description: EMC_DLL_XFORM_DQS1 - - description: EMC_DLL_XFORM_DQS2 - - description: EMC_DLL_XFORM_DQS3 - - description: EMC_DLL_XFORM_DQS4 - - description: EMC_DLL_XFORM_DQS5 - - description: EMC_DLL_XFORM_DQS6 - - description: EMC_DLL_XFORM_DQS7 - - description: EMC_DLL_XFORM_DQS8 - - description: EMC_DLL_XFORM_DQS9 - - description: EMC_DLL_XFORM_DQS10 - - description: EMC_DLL_XFORM_DQS11 - - description: EMC_DLL_XFORM_DQS12 - - description: EMC_DLL_XFORM_DQS13 - - description: EMC_DLL_XFORM_DQS14 - - description: EMC_DLL_XFORM_DQS15 - - description: EMC_DLL_XFORM_QUSE0 - - description: EMC_DLL_XFORM_QUSE1 - - description: EMC_DLL_XFORM_QUSE2 - - description: EMC_DLL_XFORM_QUSE3 - - description: EMC_DLL_XFORM_QUSE4 - - description: EMC_DLL_XFORM_QUSE5 - - description: EMC_DLL_XFORM_QUSE6 - - description: EMC_DLL_XFORM_QUSE7 - - description: EMC_DLL_XFORM_ADDR0 - - description: EMC_DLL_XFORM_ADDR1 - - description: EMC_DLL_XFORM_ADDR2 - - description: EMC_DLL_XFORM_ADDR3 - - description: EMC_DLL_XFORM_ADDR4 - - description: EMC_DLL_XFORM_ADDR5 - - description: EMC_DLL_XFORM_QUSE8 - - description: EMC_DLL_XFORM_QUSE9 - - description: EMC_DLL_XFORM_QUSE10 - - description: EMC_DLL_XFORM_QUSE11 - - description: EMC_DLL_XFORM_QUSE12 - - description: EMC_DLL_XFORM_QUSE13 - - description: EMC_DLL_XFORM_QUSE14 - - description: EMC_DLL_XFORM_QUSE15 - - description: EMC_DLI_TRIM_TXDQS0 - - description: EMC_DLI_TRIM_TXDQS1 - - description: EMC_DLI_TRIM_TXDQS2 - - description: EMC_DLI_TRIM_TXDQS3 - - description: EMC_DLI_TRIM_TXDQS4 - - description: EMC_DLI_TRIM_TXDQS5 - - description: EMC_DLI_TRIM_TXDQS6 - - description: EMC_DLI_TRIM_TXDQS7 - - description: EMC_DLI_TRIM_TXDQS8 - - description: EMC_DLI_TRIM_TXDQS9 - - description: EMC_DLI_TRIM_TXDQS10 - - description: EMC_DLI_TRIM_TXDQS11 - - description: EMC_DLI_TRIM_TXDQS12 - - description: EMC_DLI_TRIM_TXDQS13 - - description: EMC_DLI_TRIM_TXDQS14 - - description: EMC_DLI_TRIM_TXDQS15 - - description: EMC_DLL_XFORM_DQ0 - - description: EMC_DLL_XFORM_DQ1 - - description: EMC_DLL_XFORM_DQ2 - - description: EMC_DLL_XFORM_DQ3 - - description: EMC_DLL_XFORM_DQ4 - - description: EMC_DLL_XFORM_DQ5 - - description: EMC_DLL_XFORM_DQ6 - - description: EMC_DLL_XFORM_DQ7 - - description: EMC_XM2CMDPADCTRL - - description: EMC_XM2CMDPADCTRL4 - - description: EMC_XM2CMDPADCTRL5 - - description: EMC_XM2DQPADCTRL2 - - description: EMC_XM2DQPADCTRL3 - - description: EMC_XM2CLKPADCTRL - - description: EMC_XM2CLKPADCTRL2 - - description: EMC_XM2COMPPADCTRL - - description: EMC_XM2VTTGENPADCTRL - - description: EMC_XM2VTTGENPADCTRL2 - - description: EMC_XM2VTTGENPADCTRL3 - - description: EMC_XM2DQSPADCTRL3 - - description: EMC_XM2DQSPADCTRL4 - - description: EMC_XM2DQSPADCTRL5 - - description: EMC_XM2DQSPADCTRL6 - - description: EMC_DSR_VTTGEN_DRV - - description: EMC_TXDSRVTTGEN - - description: EMC_FBIO_SPARE - - description: EMC_ZCAL_WAIT_CNT - - description: EMC_MRS_WAIT_CNT2 - - description: EMC_CTT - - description: EMC_CTT_DURATION - - description: EMC_CFG_PIPE - - description: EMC_DYN_SELF_REF_CONTROL - - description: EMC_QPOP + minItems: 97 + maxItems: 143 =20 required: - clock-frequency @@ -318,9 +182,7 @@ patternProperties: - nvidia,emc-auto-cal-config2 - nvidia,emc-auto-cal-config3 - nvidia,emc-auto-cal-interval - - nvidia,emc-bgbias-ctl0 - nvidia,emc-cfg - - nvidia,emc-cfg-2 - nvidia,emc-ctt-term-ctrl - nvidia,emc-mode-1 - nvidia,emc-mode-2 @@ -344,6 +206,22 @@ required: - "#interconnect-cells" - operating-points-v2 =20 +allOf: + - if: + properties: + compatible: + contains: + enum: + - nvidia,tegra124-emc + then: + patternProperties: + "^emc-timings-[0-9]+$": + patternProperties: + "^timing-[0-9]+$": + required: + - nvidia,emc-bgbias-ctl0 + - nvidia,emc-cfg-2 + additionalProperties: false =20 examples: --=20 2.51.0 From nobody Mon Jan 26 22:53:15 2026 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 276712DA77F for ; Mon, 26 Jan 2026 21:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769461528; cv=none; b=sSnLJ9nG7GU0zknZxyOSnormXBWdA7ZYcxmkY+qdkfaUiVAYfqtwOdJwi7947vuUcd8IWkgAhhb4FiJbFjts6f3mCqXjS6HmybiDlyOKCR59CbI1B0Yd40wsLkSb0oJWDoJigsXc4B6H5jE+bjCgib3rwVQ0by5cXZyR9FcCUew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769461528; c=relaxed/simple; bh=6onIjw22FbocJxqLyOr6MKIExk1QfCkS7wXDyyPKeOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B+U6vvGhgnnXQOcpKIRCtYAuVl6aP50nLduonUH7ghsAwm6Br1fGLnOLYGuCZibQugm39Ta3nG5Yq+ORKqnP8VrK+EDPMYe+arOBwd2hbCsdyQIMqgbvfyO4d80sCFK5ohdWqaNCgKX7BvYB8SepfyK2vB7RV2ACnClLFLs9bqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RWXS+JM7; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RWXS+JM7" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-64c893f3a94so9626306a12.0 for ; Mon, 26 Jan 2026 13:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769461525; x=1770066325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M/6cQynHMRNT9mStzvoqsnJyS8wK/RE7XHifbrIZv2M=; b=RWXS+JM7umUpnLegARDTUJjkV7qwC1mH976usFV6GeSAwsy7NMnJP3uJQNrPByIsZ9 Trcn0EagjcX/NYXL6o+qGdVNLGoz+NRfXi9aZri3bi07w61nOh8PFtUPzt+UInSoeAeP iPMg2o+ENPwX2UU/XrlSwNzg4/eorinEo9kg9Ik38hX/zQr7ocEB/S8RltnfS11kUgRF anH+U646JnskXKlY2vPrt85KezTp5L+UrFz80rFSCPGEbVeteXhuB16R0lMyCkZjznfe DRSn4M44HSGHpH2c/oEswzzw55fDH7u7mFFvFs6ZVkyG0gLHk6S+cZVP8bySL9tGc0hy /C2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769461525; x=1770066325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=M/6cQynHMRNT9mStzvoqsnJyS8wK/RE7XHifbrIZv2M=; b=VEGDi8GCLFgVudhGlMzk08UcowfnwnK7fN1aH8CPiY5hmrQmGm26ILGIsmcM9019Yo gmFg+g50Dq7+zZ5Ie22rip/Putv1zcPsltIGLcmqITo6etUIcUJLsHNzpaXtGbZGbSS0 orUj50hostDH2QOrxduJmoTcIGsFxYWbSc3k+OpKUhdutxk3oLcBLRnmsFUfl+k4Dfxg UIe8zNzJO1HGMCtB90cw82Y/O5hk34EmsN90//7qVKCKUSms42KBf1bFvxG8mT05uOZh n4BgYBpXqeK/eOtr9TiAJjj2hXDEn1pcPZ/XRat0aeIzt0uiNQS4ddS1982rYeeVB8ph +Qew== X-Gm-Message-State: AOJu0YyNnqbRJn9YklM+3cqK7PwmHCZ8L654BIpVo8MxCXd2bj8bmZ3i aNE9v2H+fkya9/2Suyba0yxNOzF7WCy24MwPt23KWHNfqgwCyZsyyE3ZQ8iT/g== X-Gm-Gg: AZuq6aIdeoaSSw9x1Tnm2jFCUPNuiA+KYIpzUwk/v67goaNFZHSQWAtCCezMqgqfHhs 9SV3GJjsWIBUNghIkrprwLFznYXgb7jqFfKUhi5HBW3Oth2ELqFDep+dndArl2hnMptCkbAkxje Sj+1DFuhHZR6pNzGrVZXzVu31islC8WlLVAE/wATRHYebKAkspsxEScNHMOGpV1Re+2nQ03ITlX zAqJIp5inamR1yfLmj0yqF2+q8LFxJ5jf018SRnp+/bGdGp7J374DxTgAExrHDP/mytROZgxi4a /OK1kPdrhmfkm+IFAJs9CR58p6YonvMxOf40LUnnOU9Qnov4OLnkxrzIAb/4uRj+dD23Hw3VAwx zEqyd68piZKvirOdsZibE0SmkiqMRW4ikeDemmJYN/P3W0JrIRZU9PFPeVY8RVJ4jdPILFi1H5j zwhyvBky3cELg= X-Received: by 2002:a05:600c:5297:b0:477:a289:d854 with SMTP id 5b1f17b1804b1-4805cd2026amr97643285e9.5.1769454489966; Mon, 26 Jan 2026 11:08:09 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c24bf8sm31802030f8f.11.2026.01.26.11.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 11:08:09 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Mikko Perttunen , Svyatoslav Ryhel , Sumit Gupta , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 5/5] memory: tegra: Add Tegra114 EMC driver Date: Mon, 26 Jan 2026 21:07:55 +0200 Message-ID: <20260126190755.78475-6-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260126190755.78475-1-clamor95@gmail.com> References: <20260126190755.78475-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce driver for the External Memory Controller (EMC) found in Tegra114 SoC. It controls the external DRAM on the board. The purpose of this driver is to program memory timing for external memory on the EMC clock rate change. Signed-off-by: Svyatoslav Ryhel Reviewed-by: Mikko Perttunen --- drivers/memory/tegra/Kconfig | 12 + drivers/memory/tegra/Makefile | 1 + drivers/memory/tegra/tegra114-emc.c | 1463 +++++++++++++++++++++++++++ 3 files changed, 1476 insertions(+) create mode 100644 drivers/memory/tegra/tegra114-emc.c diff --git a/drivers/memory/tegra/Kconfig b/drivers/memory/tegra/Kconfig index fc5a27791826..11e7cc357d39 100644 --- a/drivers/memory/tegra/Kconfig +++ b/drivers/memory/tegra/Kconfig @@ -35,6 +35,18 @@ config TEGRA30_EMC This driver is required to change memory timings / clock rate for external memory. =20 +config TEGRA114_EMC + tristate "NVIDIA Tegra114 External Memory Controller driver" + default y + depends on ARCH_TEGRA_114_SOC || COMPILE_TEST + select TEGRA124_CLK_EMC if ARCH_TEGRA + select PM_OPP + help + This driver is for the External Memory Controller (EMC) found on + Tegra114 chips. The EMC controls the external DRAM on the board. + This driver is required to change memory timings / clock rate for + external memory. + config TEGRA124_EMC tristate "NVIDIA Tegra124 External Memory Controller driver" default ARCH_TEGRA_124_SOC diff --git a/drivers/memory/tegra/Makefile b/drivers/memory/tegra/Makefile index 6334601e6120..6b9156de4b66 100644 --- a/drivers/memory/tegra/Makefile +++ b/drivers/memory/tegra/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_TEGRA_MC) +=3D tegra-mc.o =20 obj-$(CONFIG_TEGRA20_EMC) +=3D tegra20-emc.o obj-$(CONFIG_TEGRA30_EMC) +=3D tegra30-emc.o +obj-$(CONFIG_TEGRA114_EMC) +=3D tegra114-emc.o obj-$(CONFIG_TEGRA124_EMC) +=3D tegra124-emc.o obj-$(CONFIG_TEGRA210_EMC_TABLE) +=3D tegra210-emc-table.o obj-$(CONFIG_TEGRA210_EMC) +=3D tegra210-emc.o diff --git a/drivers/memory/tegra/tegra114-emc.c b/drivers/memory/tegra/teg= ra114-emc.c new file mode 100644 index 000000000000..789b8e959a68 --- /dev/null +++ b/drivers/memory/tegra/tegra114-emc.c @@ -0,0 +1,1463 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Tegra114 External Memory Controller driver + * + * Based on downstream driver from NVIDIA and tegra124-emc.c + * Copyright (C) 2011-2014 NVIDIA Corporation + * + * Copyright (C) 2024 Svyatoslav Ryhel + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mc.h" + +#define EMC_INTSTATUS 0x0 +#define EMC_INTSTATUS_REFRESH_OVERFLOW BIT(3) +#define EMC_INTSTATUS_CLKCHANGE_COMPLETE BIT(4) + +#define EMC_INTMASK 0x4 + +#define EMC_DBG 0x8 +#define EMC_DBG_READ_MUX_ASSEMBLY BIT(0) +#define EMC_DBG_WRITE_MUX_ACTIVE BIT(1) +#define EMC_DBG_FORCE_UPDATE BIT(2) +#define EMC_DBG_CFG_PRIORITY BIT(24) + +#define EMC_CFG 0xc +#define EMC_CFG_DSR_VTTGEN_DRV_EN BIT(18) +#define EMC_CFG_PWR_MASK ((0xF << 28) | BIT(18)) +#define EMC_CFG_DYN_SREF BIT(28) +#define EMC_CFG_DRAM_ACPD BIT(29) +#define EMC_CFG_DRAM_CLKSTOP_SR BIT(30) +#define EMC_CFG_DRAM_CLKSTOP_PD BIT(31) + +#define EMC_ADR_CFG 0x10 +#define EMC_ADR_CFG_EMEM_NUMDEV BIT(0) + +#define EMC_REFCTRL 0x20 +#define EMC_REFCTRL_DEV_SEL_SHIFT 0 +#define EMC_REFCTRL_ENABLE BIT(31) + +#define EMC_TIMING_CONTROL 0x28 +#define EMC_RC 0x2c +#define EMC_RFC 0x30 +#define EMC_RAS 0x34 +#define EMC_RP 0x38 +#define EMC_R2W 0x3c +#define EMC_W2R 0x40 +#define EMC_R2P 0x44 +#define EMC_W2P 0x48 +#define EMC_RD_RCD 0x4c +#define EMC_WR_RCD 0x50 +#define EMC_RRD 0x54 +#define EMC_REXT 0x58 +#define EMC_WDV 0x5c +#define EMC_QUSE 0x60 +#define EMC_QRST 0x64 +#define EMC_QSAFE 0x68 +#define EMC_RDV 0x6c +#define EMC_REFRESH 0x70 +#define EMC_BURST_REFRESH_NUM 0x74 +#define EMC_PDEX2WR 0x78 +#define EMC_PDEX2RD 0x7c +#define EMC_PCHG2PDEN 0x80 +#define EMC_ACT2PDEN 0x84 +#define EMC_AR2PDEN 0x88 +#define EMC_RW2PDEN 0x8c +#define EMC_TXSR 0x90 +#define EMC_TCKE 0x94 +#define EMC_TFAW 0x98 +#define EMC_TRPAB 0x9c +#define EMC_TCLKSTABLE 0xa0 +#define EMC_TCLKSTOP 0xa4 +#define EMC_TREFBW 0xa8 +#define EMC_QUSE_EXTRA 0xac +#define EMC_ODT_WRITE 0xb0 +#define EMC_ODT_READ 0xb4 +#define EMC_WEXT 0xb8 +#define EMC_CTT 0xbc +#define EMC_RFC_SLR 0xc0 +#define EMC_MRS_WAIT_CNT2 0xc4 + +#define EMC_MRS_WAIT_CNT 0xc8 +#define EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT 0 +#define EMC_MRS_WAIT_CNT_SHORT_WAIT_MASK \ + (0x3FF << EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT) +#define EMC_MRS_WAIT_CNT_LONG_WAIT_SHIFT 16 +#define EMC_MRS_WAIT_CNT_LONG_WAIT_MASK \ + (0x3FF << EMC_MRS_WAIT_CNT_LONG_WAIT_SHIFT) + +#define EMC_MRS 0xcc +#define EMC_MODE_SET_DLL_RESET BIT(8) +#define EMC_MODE_SET_LONG_CNT BIT(26) +#define EMC_EMRS 0xd0 +#define EMC_REF 0xd4 +#define EMC_PRE 0xd8 + +#define EMC_SELF_REF 0xe0 +#define EMC_SELF_REF_CMD_ENABLED BIT(0) +#define EMC_SELF_REF_DEV_SEL_SHIFT 30 + +#define EMC_MRW 0xe8 + +#define EMC_MRR 0xec +#define EMC_MRR_MA_SHIFT 16 +#define LPDDR2_MR4_TEMP_SHIFT 0 + +#define EMC_XM2DQSPADCTRL3 0xf8 +#define EMC_FBIO_SPARE 0x100 + +#define EMC_FBIO_CFG5 0x104 +#define EMC_FBIO_CFG5_DRAM_TYPE_MASK 0x3 +#define EMC_FBIO_CFG5_DRAM_TYPE_SHIFT 0 + +#define EMC_FBIO_CFG6 0x114 +#define EMC_EMRS2 0x12c +#define EMC_MRW2 0x134 +#define EMC_MRW4 0x13c +#define EMC_EINPUT 0x14c +#define EMC_EINPUT_DURATION 0x150 +#define EMC_PUTERM_EXTRA 0x154 +#define EMC_TCKESR 0x158 +#define EMC_TPD 0x15c + +#define EMC_AUTO_CAL_CONFIG 0x2a4 +#define EMC_AUTO_CAL_CONFIG_AUTO_CAL_START BIT(31) +#define EMC_AUTO_CAL_INTERVAL 0x2a8 +#define EMC_AUTO_CAL_STATUS 0x2ac +#define EMC_AUTO_CAL_STATUS_ACTIVE BIT(31) +#define EMC_STATUS 0x2b4 +#define EMC_STATUS_TIMING_UPDATE_STALLED BIT(23) + +#define EMC_CFG_2 0x2b8 +#define EMC_CFG_2_CLKCHANGE_REQ_ENABLE BIT(0) +#define EMC_CFG_2_CLKCHANGE_PD_ENABLE BIT(1) +#define EMC_CFG_2_CLKCHANGE_SR_ENABLE BIT(2) + +#define EMC_CFG_DIG_DLL 0x2bc +#define EMC_CFG_DIG_DLL_PERIOD 0x2c0 +#define EMC_RDV_MASK 0x2cc +#define EMC_WDV_MASK 0x2d0 +#define EMC_CTT_DURATION 0x2d8 +#define EMC_CTT_TERM_CTRL 0x2dc +#define EMC_ZCAL_INTERVAL 0x2e0 +#define EMC_ZCAL_WAIT_CNT 0x2e4 + +#define EMC_ZQ_CAL 0x2ec +#define EMC_ZQ_CAL_CMD BIT(0) +#define EMC_ZQ_CAL_LONG BIT(4) +#define EMC_ZQ_CAL_LONG_CMD_DEV0 \ + (DRAM_DEV_SEL_0 | EMC_ZQ_CAL_LONG | EMC_ZQ_CAL_CMD) +#define EMC_ZQ_CAL_LONG_CMD_DEV1 \ + (DRAM_DEV_SEL_1 | EMC_ZQ_CAL_LONG | EMC_ZQ_CAL_CMD) + +#define EMC_XM2CMDPADCTRL 0x2f0 +#define EMC_XM2DQSPADCTRL 0x2f8 +#define EMC_XM2DQSPADCTRL2 0x2fc +#define EMC_XM2DQSPADCTRL2_RX_FT_REC_ENABLE BIT(0) +#define EMC_XM2DQSPADCTRL2_VREF_ENABLE BIT(5) +#define EMC_XM2DQPADCTRL 0x300 +#define EMC_XM2DQPADCTRL2 0x304 +#define EMC_XM2CLKPADCTRL 0x308 +#define EMC_XM2COMPPADCTRL 0x30c +#define EMC_XM2VTTGENPADCTRL 0x310 +#define EMC_XM2VTTGENPADCTRL2 0x314 +#define EMC_XM2QUSEPADCTRL 0x318 +#define EMC_XM2DQSPADCTRL4 0x320 +#define EMC_DLL_XFORM_DQS0 0x328 +#define EMC_DLL_XFORM_DQS1 0x32c +#define EMC_DLL_XFORM_DQS2 0x330 +#define EMC_DLL_XFORM_DQS3 0x334 +#define EMC_DLL_XFORM_DQS4 0x338 +#define EMC_DLL_XFORM_DQS5 0x33c +#define EMC_DLL_XFORM_DQS6 0x340 +#define EMC_DLL_XFORM_DQS7 0x344 +#define EMC_DLL_XFORM_QUSE0 0x348 +#define EMC_DLL_XFORM_QUSE1 0x34c +#define EMC_DLL_XFORM_QUSE2 0x350 +#define EMC_DLL_XFORM_QUSE3 0x354 +#define EMC_DLL_XFORM_QUSE4 0x358 +#define EMC_DLL_XFORM_QUSE5 0x35c +#define EMC_DLL_XFORM_QUSE6 0x360 +#define EMC_DLL_XFORM_QUSE7 0x364 +#define EMC_DLL_XFORM_DQ0 0x368 +#define EMC_DLL_XFORM_DQ1 0x36c +#define EMC_DLL_XFORM_DQ2 0x370 +#define EMC_DLL_XFORM_DQ3 0x374 +#define EMC_DLI_TRIM_TXDQS0 0x3a8 +#define EMC_DLI_TRIM_TXDQS1 0x3ac +#define EMC_DLI_TRIM_TXDQS2 0x3b0 +#define EMC_DLI_TRIM_TXDQS3 0x3b4 +#define EMC_DLI_TRIM_TXDQS4 0x3b8 +#define EMC_DLI_TRIM_TXDQS5 0x3bc +#define EMC_DLI_TRIM_TXDQS6 0x3c0 +#define EMC_DLI_TRIM_TXDQS7 0x3c4 +#define EMC_STALL_THEN_EXE_AFTER_CLKCHANGE 0x3cc +#define EMC_SEL_DPD_CTRL 0x3d8 +#define EMC_SEL_DPD_CTRL_DATA_SEL_DPD BIT(8) +#define EMC_SEL_DPD_CTRL_ODT_SEL_DPD BIT(5) +#define EMC_SEL_DPD_CTRL_RESET_SEL_DPD BIT(4) +#define EMC_SEL_DPD_CTRL_CA_SEL_DPD BIT(3) +#define EMC_SEL_DPD_CTRL_CLK_SEL_DPD BIT(2) +#define EMC_SEL_DPD_CTRL_DDR3_MASK \ + ((0xf << 2) | BIT(8)) +#define EMC_SEL_DPD_CTRL_MASK \ + ((0x3 << 2) | BIT(5) | BIT(8)) +#define EMC_PRE_REFRESH_REQ_CNT 0x3dc +#define EMC_DYN_SELF_REF_CONTROL 0x3e0 +#define EMC_TXSRDLL 0x3e4 +#define EMC_CCFIFO_ADDR 0x3e8 +#define EMC_CCFIFO_DATA 0x3ec +#define EMC_CCFIFO_STATUS 0x3f0 +#define EMC_CDB_CNTL_1 0x3f4 +#define EMC_CDB_CNTL_2 0x3f8 +#define EMC_XM2CLKPADCTRL2 0x3fc +#define EMC_AUTO_CAL_CONFIG2 0x458 +#define EMC_AUTO_CAL_CONFIG3 0x45c +#define EMC_IBDLY 0x468 +#define EMC_DLL_XFORM_ADDR0 0x46c +#define EMC_DLL_XFORM_ADDR1 0x470 +#define EMC_DLL_XFORM_ADDR2 0x474 +#define EMC_DSR_VTTGEN_DRV 0x47c +#define EMC_TXDSRVTTGEN 0x480 +#define EMC_XM2CMDPADCTRL4 0x484 + +#define DRAM_DEV_SEL_ALL 0 +#define DRAM_DEV_SEL_0 BIT(31) +#define DRAM_DEV_SEL_1 BIT(30) + +#define EMC_CFG_POWER_FEATURES_MASK \ + (EMC_CFG_DYN_SREF | EMC_CFG_DRAM_ACPD | EMC_CFG_DRAM_CLKSTOP_SR | \ + EMC_CFG_DRAM_CLKSTOP_PD | EMC_CFG_DSR_VTTGEN_DRV_EN) +#define EMC_REFCTRL_DEV_SEL(n) ((((n) > 1) ? 0 : 2) << EMC_REFCTRL_DEV_SEL= _SHIFT) +#define EMC_DRAM_DEV_SEL(n) (((n) > 1) ? DRAM_DEV_SEL_ALL : DRAM_DEV_SEL_0) + +/* Maximum amount of time in us. to wait for changes to become effective */ +#define EMC_STATUS_UPDATE_TIMEOUT 1000 + +enum emc_dram_type { + DRAM_TYPE_DDR3, + DRAM_TYPE_DDR1, + DRAM_TYPE_LPDDR2, + DRAM_TYPE_DDR2 +}; + +enum emc_dll_change { + DLL_CHANGE_NONE, + DLL_CHANGE_ON, + DLL_CHANGE_OFF +}; + +static const unsigned long emc_burst_regs[] =3D { + EMC_RC, + EMC_RFC, + EMC_RAS, + EMC_RP, + EMC_R2W, + EMC_W2R, + EMC_R2P, + EMC_W2P, + EMC_RD_RCD, + EMC_WR_RCD, + EMC_RRD, + EMC_REXT, + EMC_WEXT, + EMC_WDV, + EMC_WDV_MASK, + EMC_QUSE, + EMC_IBDLY, + EMC_EINPUT, + EMC_EINPUT_DURATION, + EMC_PUTERM_EXTRA, + EMC_CDB_CNTL_1, + EMC_CDB_CNTL_2, + EMC_QRST, + EMC_QSAFE, + EMC_RDV, + EMC_RDV_MASK, + EMC_REFRESH, + EMC_BURST_REFRESH_NUM, + EMC_PRE_REFRESH_REQ_CNT, + EMC_PDEX2WR, + EMC_PDEX2RD, + EMC_PCHG2PDEN, + EMC_ACT2PDEN, + EMC_AR2PDEN, + EMC_RW2PDEN, + EMC_TXSR, + EMC_TXSRDLL, + EMC_TCKE, + EMC_TCKESR, + EMC_TPD, + EMC_TFAW, + EMC_TRPAB, + EMC_TCLKSTABLE, + EMC_TCLKSTOP, + EMC_TREFBW, + EMC_QUSE_EXTRA, + EMC_FBIO_CFG6, + EMC_ODT_WRITE, + EMC_ODT_READ, + EMC_FBIO_CFG5, + EMC_CFG_DIG_DLL, + EMC_CFG_DIG_DLL_PERIOD, + EMC_DLL_XFORM_DQS0, + EMC_DLL_XFORM_DQS1, + EMC_DLL_XFORM_DQS2, + EMC_DLL_XFORM_DQS3, + EMC_DLL_XFORM_DQS4, + EMC_DLL_XFORM_DQS5, + EMC_DLL_XFORM_DQS6, + EMC_DLL_XFORM_DQS7, + EMC_DLL_XFORM_QUSE0, + EMC_DLL_XFORM_QUSE1, + EMC_DLL_XFORM_QUSE2, + EMC_DLL_XFORM_QUSE3, + EMC_DLL_XFORM_QUSE4, + EMC_DLL_XFORM_QUSE5, + EMC_DLL_XFORM_QUSE6, + EMC_DLL_XFORM_QUSE7, + EMC_DLI_TRIM_TXDQS0, + EMC_DLI_TRIM_TXDQS1, + EMC_DLI_TRIM_TXDQS2, + EMC_DLI_TRIM_TXDQS3, + EMC_DLI_TRIM_TXDQS4, + EMC_DLI_TRIM_TXDQS5, + EMC_DLI_TRIM_TXDQS6, + EMC_DLI_TRIM_TXDQS7, + EMC_DLL_XFORM_DQ0, + EMC_DLL_XFORM_DQ1, + EMC_DLL_XFORM_DQ2, + EMC_DLL_XFORM_DQ3, + EMC_XM2CMDPADCTRL, + EMC_XM2CMDPADCTRL4, + EMC_XM2DQPADCTRL2, + EMC_XM2CLKPADCTRL, + EMC_XM2COMPPADCTRL, + EMC_XM2VTTGENPADCTRL, + EMC_XM2VTTGENPADCTRL2, + EMC_XM2DQSPADCTRL3, + EMC_XM2DQSPADCTRL4, + EMC_DSR_VTTGEN_DRV, + EMC_TXDSRVTTGEN, + EMC_FBIO_SPARE, + EMC_ZCAL_WAIT_CNT, + EMC_MRS_WAIT_CNT2, + EMC_CTT, + EMC_CTT_DURATION, + EMC_DYN_SELF_REF_CONTROL, +}; + +struct emc_timing { + unsigned long rate; + + u32 emc_burst_data[ARRAY_SIZE(emc_burst_regs)]; + + u32 emc_auto_cal_config; + u32 emc_auto_cal_config2; + u32 emc_auto_cal_config3; + u32 emc_auto_cal_interval; + u32 emc_cfg; + u32 emc_ctt_term_ctrl; + u32 emc_mode_1; + u32 emc_mode_2; + u32 emc_mode_4; + u32 emc_mode_reset; + u32 emc_mrs_wait_cnt; + u32 emc_sel_dpd_ctrl; + u32 emc_xm2dqspadctrl2; + u32 emc_zcal_cnt_long; + u32 emc_zcal_interval; +}; + +enum emc_rate_request_type { + EMC_RATE_DEBUG, + EMC_RATE_ICC, + EMC_RATE_TYPE_MAX, +}; + +struct emc_rate_request { + unsigned long min_rate; + unsigned long max_rate; +}; + +struct tegra_emc { + struct device *dev; + struct tegra_mc *mc; + void __iomem *regs; + unsigned int irq; + struct clk *clk; + + enum emc_dram_type dram_type; + unsigned int dram_num; + + struct emc_timing last_timing; + struct emc_timing *timings; + unsigned int num_timings; + + struct { + struct dentry *root; + unsigned long min_rate; + unsigned long max_rate; + } debugfs; + + struct icc_provider provider; + + /* + * There are multiple sources in the EMC driver which could request + * a min/max clock rate, these rates are contained in this array. + */ + struct emc_rate_request requested_rate[EMC_RATE_TYPE_MAX]; + + /* protect shared rate-change code path */ + struct mutex rate_lock; +}; + +static irqreturn_t tegra_emc_isr(int irq, void *data) +{ + struct tegra_emc *emc =3D data; + u32 intmask =3D EMC_INTSTATUS_REFRESH_OVERFLOW; + u32 status; + + status =3D readl_relaxed(emc->regs + EMC_INTSTATUS) & intmask; + if (!status) + return IRQ_NONE; + + /* notify about HW problem */ + if (status & EMC_INTSTATUS_REFRESH_OVERFLOW) + dev_err_ratelimited(emc->dev, + "refresh request overflow timeout\n"); + + /* clear interrupts */ + writel_relaxed(status, emc->regs + EMC_INTSTATUS); + + return IRQ_HANDLED; +} + +/* Timing change sequence functions */ + +static void emc_ccfifo_writel(struct tegra_emc *emc, u32 value, + unsigned long offset) +{ + writel(value, emc->regs + EMC_CCFIFO_DATA); + writel(offset, emc->regs + EMC_CCFIFO_ADDR); +} + +static void emc_seq_update_timing(struct tegra_emc *emc) +{ + int ret; + u32 value; + + writel(1, emc->regs + EMC_TIMING_CONTROL); + + ret =3D readl_poll_timeout_atomic(emc->regs + EMC_STATUS, value, + !(value & EMC_STATUS_TIMING_UPDATE_STALLED), + 1, EMC_STATUS_UPDATE_TIMEOUT); + if (ret) + dev_err(emc->dev, "timing update timed out\n"); +} + +static void emc_seq_disable_auto_cal(struct tegra_emc *emc) +{ + int ret; + u32 value; + + writel(0, emc->regs + EMC_AUTO_CAL_INTERVAL); + + ret =3D readl_poll_timeout_atomic(emc->regs + EMC_AUTO_CAL_STATUS, value, + !(value & EMC_AUTO_CAL_STATUS_ACTIVE), + 1, EMC_STATUS_UPDATE_TIMEOUT); + if (ret) + dev_err(emc->dev, "auto cal disable timed out\n"); +} + +static void emc_seq_wait_clkchange(struct tegra_emc *emc) +{ + int ret; + u32 value; + + ret =3D readl_poll_timeout_atomic(emc->regs + EMC_INTSTATUS, value, + value & EMC_INTSTATUS_CLKCHANGE_COMPLETE, + 1, EMC_STATUS_UPDATE_TIMEOUT); + if (ret) + dev_err(emc->dev, "clock change timed out\n"); +} + +static struct emc_timing *tegra_emc_find_timing(struct tegra_emc *emc, + unsigned long rate) +{ + struct emc_timing *timing =3D NULL; + unsigned int i; + + for (i =3D 0; i < emc->num_timings; i++) { + if (emc->timings[i].rate =3D=3D rate) { + timing =3D &emc->timings[i]; + break; + } + } + + if (!timing) { + dev_err(emc->dev, "no timing for rate %lu\n", rate); + return NULL; + } + + return timing; +} + +static int tegra_emc_prepare_timing_change(struct tegra_emc *emc, + unsigned long rate) +{ + struct emc_timing *timing =3D tegra_emc_find_timing(emc, rate); + struct emc_timing *last =3D &emc->last_timing; + enum emc_dll_change dll_change; + unsigned int pre_wait =3D 0; + u32 val, mask; + bool next_dll_enabled =3D !(timing->emc_mode_1 & 0x1); + bool last_dll_enabled =3D !(last->emc_mode_1 & 0x1); + bool update =3D false; + unsigned int i; + + if (!timing) + return -ENOENT; + + if (next_dll_enabled =3D=3D last_dll_enabled) + dll_change =3D DLL_CHANGE_NONE; + else if (next_dll_enabled) + dll_change =3D DLL_CHANGE_ON; + else + dll_change =3D DLL_CHANGE_OFF; + + /* Clear CLKCHANGE_COMPLETE interrupts */ + writel(EMC_INTSTATUS_CLKCHANGE_COMPLETE, emc->regs + EMC_INTSTATUS); + + /* Disable dynamic self-refresh */ + val =3D readl(emc->regs + EMC_CFG); + if (val & EMC_CFG_PWR_MASK) { + val &=3D ~EMC_CFG_POWER_FEATURES_MASK; + writel(val, emc->regs + EMC_CFG); + + pre_wait =3D 5; + } + + /* Disable SEL_DPD_CTRL for clock change */ + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3) + mask =3D EMC_SEL_DPD_CTRL_DDR3_MASK; + else + mask =3D EMC_SEL_DPD_CTRL_MASK; + + val =3D readl(emc->regs + EMC_SEL_DPD_CTRL); + if (val & mask) { + val &=3D ~mask; + writel(val, emc->regs + EMC_SEL_DPD_CTRL); + } + + /* Prepare DQ/DQS for clock change */ + val =3D readl(emc->regs + EMC_XM2DQSPADCTRL2); + if (timing->emc_xm2dqspadctrl2 & EMC_XM2DQSPADCTRL2_VREF_ENABLE && + !(val & EMC_XM2DQSPADCTRL2_VREF_ENABLE)) { + val |=3D EMC_XM2DQSPADCTRL2_VREF_ENABLE; + update =3D true; + } + + if (timing->emc_xm2dqspadctrl2 & EMC_XM2DQSPADCTRL2_RX_FT_REC_ENABLE && + !(val & EMC_XM2DQSPADCTRL2_RX_FT_REC_ENABLE)) { + val |=3D EMC_XM2DQSPADCTRL2_RX_FT_REC_ENABLE; + update =3D true; + } + + if (update) { + writel(val, emc->regs + EMC_XM2DQSPADCTRL2); + if (pre_wait < 30) + pre_wait =3D 30; + } + + /* Wait to settle */ + if (pre_wait) { + emc_seq_update_timing(emc); + udelay(pre_wait); + } + + /* Program CTT_TERM control */ + if (last->emc_ctt_term_ctrl !=3D timing->emc_ctt_term_ctrl) { + emc_seq_disable_auto_cal(emc); + writel(timing->emc_ctt_term_ctrl, + emc->regs + EMC_CTT_TERM_CTRL); + emc_seq_update_timing(emc); + } + + /* Program burst shadow registers */ + for (i =3D 0; i < ARRAY_SIZE(timing->emc_burst_data); ++i) + writel(timing->emc_burst_data[i], + emc->regs + emc_burst_regs[i]); + + writel(timing->emc_xm2dqspadctrl2, emc->regs + EMC_XM2DQSPADCTRL2); + writel(timing->emc_zcal_interval, emc->regs + EMC_ZCAL_INTERVAL); + + tegra_mc_write_emem_configuration(emc->mc, timing->rate); + + val =3D timing->emc_cfg & ~EMC_CFG_POWER_FEATURES_MASK; + emc_ccfifo_writel(emc, val, EMC_CFG); + + /* Program AUTO_CAL_CONFIG */ + if (timing->emc_auto_cal_config2 !=3D last->emc_auto_cal_config2) + emc_ccfifo_writel(emc, timing->emc_auto_cal_config2, + EMC_AUTO_CAL_CONFIG2); + + if (timing->emc_auto_cal_config3 !=3D last->emc_auto_cal_config3) + emc_ccfifo_writel(emc, timing->emc_auto_cal_config3, + EMC_AUTO_CAL_CONFIG3); + + if (timing->emc_auto_cal_config !=3D last->emc_auto_cal_config) { + val =3D timing->emc_auto_cal_config; + val &=3D EMC_AUTO_CAL_CONFIG_AUTO_CAL_START; + emc_ccfifo_writel(emc, val, EMC_AUTO_CAL_CONFIG); + } + + /* DDR3: predict MRS long wait count */ + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3 && + dll_change =3D=3D DLL_CHANGE_ON) { + u32 cnt =3D 512; + + if (timing->emc_zcal_interval !=3D 0 && + last->emc_zcal_interval =3D=3D 0) + cnt -=3D emc->dram_num * 256; + + val =3D (timing->emc_mrs_wait_cnt + & EMC_MRS_WAIT_CNT_SHORT_WAIT_MASK) + >> EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT; + if (cnt < val) + cnt =3D val; + + val =3D timing->emc_mrs_wait_cnt + & ~EMC_MRS_WAIT_CNT_LONG_WAIT_MASK; + val |=3D (cnt << EMC_MRS_WAIT_CNT_LONG_WAIT_SHIFT) + & EMC_MRS_WAIT_CNT_LONG_WAIT_MASK; + + writel(val, emc->regs + EMC_MRS_WAIT_CNT); + } + + /* DDR3: Turn off DLL and enter self-refresh */ + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3 && dll_change =3D=3D DLL_CHANGE_= OFF) + emc_ccfifo_writel(emc, timing->emc_mode_1, EMC_EMRS); + + /* Disable refresh controller */ + emc_ccfifo_writel(emc, EMC_REFCTRL_DEV_SEL(emc->dram_num), + EMC_REFCTRL); + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3) + emc_ccfifo_writel(emc, EMC_DRAM_DEV_SEL(emc->dram_num) | + EMC_SELF_REF_CMD_ENABLED, + EMC_SELF_REF); + + /* Flow control marker */ + emc_ccfifo_writel(emc, 1, EMC_STALL_THEN_EXE_AFTER_CLKCHANGE); + + /* DDR3: Exit self-refresh */ + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3) + emc_ccfifo_writel(emc, EMC_DRAM_DEV_SEL(emc->dram_num), + EMC_SELF_REF); + emc_ccfifo_writel(emc, EMC_REFCTRL_DEV_SEL(emc->dram_num) | + EMC_REFCTRL_ENABLE, + EMC_REFCTRL); + + /* Set DRAM mode registers */ + if (emc->dram_type =3D=3D DRAM_TYPE_DDR3) { + if (timing->emc_mode_1 !=3D last->emc_mode_1) + emc_ccfifo_writel(emc, timing->emc_mode_1, EMC_EMRS); + if (timing->emc_mode_2 !=3D last->emc_mode_2) + emc_ccfifo_writel(emc, timing->emc_mode_2, EMC_EMRS2); + + if (timing->emc_mode_reset !=3D last->emc_mode_reset || + dll_change =3D=3D DLL_CHANGE_ON) { + val =3D timing->emc_mode_reset; + if (dll_change =3D=3D DLL_CHANGE_ON) { + val |=3D EMC_MODE_SET_DLL_RESET; + val |=3D EMC_MODE_SET_LONG_CNT; + } else { + val &=3D ~EMC_MODE_SET_DLL_RESET; + } + emc_ccfifo_writel(emc, val, EMC_MRS); + } + } else { + if (timing->emc_mode_2 !=3D last->emc_mode_2) + emc_ccfifo_writel(emc, timing->emc_mode_2, EMC_MRW2); + if (timing->emc_mode_1 !=3D last->emc_mode_1) + emc_ccfifo_writel(emc, timing->emc_mode_1, EMC_MRW); + if (timing->emc_mode_4 !=3D last->emc_mode_4) + emc_ccfifo_writel(emc, timing->emc_mode_4, EMC_MRW4); + } + + /* Issue ZCAL command if turning ZCAL on */ + if (timing->emc_zcal_interval !=3D 0 && last->emc_zcal_interval =3D=3D 0)= { + emc_ccfifo_writel(emc, EMC_ZQ_CAL_LONG_CMD_DEV0, EMC_ZQ_CAL); + if (emc->dram_num > 1) + emc_ccfifo_writel(emc, EMC_ZQ_CAL_LONG_CMD_DEV1, + EMC_ZQ_CAL); + } + + /* Write to RO register to remove stall after change */ + emc_ccfifo_writel(emc, 0, EMC_CCFIFO_STATUS); + + /* Disable AUTO_CAL for clock change */ + emc_seq_disable_auto_cal(emc); + + /* Read register to wait until programming has settled */ + mc_readl(emc->mc, MC_EMEM_ADR_CFG); + + return 0; +} + +static void tegra_emc_complete_timing_change(struct tegra_emc *emc, + unsigned long rate) +{ + struct emc_timing *timing =3D tegra_emc_find_timing(emc, rate); + struct emc_timing *last =3D &emc->last_timing; + + if (!timing) + return; + + /* Wait until the state machine has settled */ + emc_seq_wait_clkchange(emc); + + /* Restore AUTO_CAL */ + if (timing->emc_ctt_term_ctrl !=3D last->emc_ctt_term_ctrl) + writel(timing->emc_auto_cal_interval, + emc->regs + EMC_AUTO_CAL_INTERVAL); + + /* Restore dynamic self-refresh */ + if (timing->emc_cfg & EMC_CFG_PWR_MASK) + writel(timing->emc_cfg, emc->regs + EMC_CFG); + + /* Set ZCAL wait count */ + writel(timing->emc_zcal_cnt_long, emc->regs + EMC_ZCAL_WAIT_CNT); + + /* Wait for timing to settle */ + udelay(2); + + /* Reprogram SEL_DPD_CTRL */ + writel(timing->emc_sel_dpd_ctrl, emc->regs + EMC_SEL_DPD_CTRL); + emc_seq_update_timing(emc); + + emc->last_timing =3D *timing; +} + +/* Initialization and deinitialization */ + +static void emc_read_current_timing(struct tegra_emc *emc, + struct emc_timing *timing) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(emc_burst_regs); ++i) + timing->emc_burst_data[i] =3D + readl(emc->regs + emc_burst_regs[i]); + + timing->emc_cfg =3D readl(emc->regs + EMC_CFG); + + timing->emc_auto_cal_interval =3D 0; + timing->emc_zcal_cnt_long =3D 0; + timing->emc_mode_1 =3D 0; + timing->emc_mode_2 =3D 0; + timing->emc_mode_4 =3D 0; + timing->emc_mode_reset =3D 0; +} + +static int emc_init(struct tegra_emc *emc) +{ + u32 emc_cfg, emc_dbg; + u32 intmask =3D EMC_INTSTATUS_REFRESH_OVERFLOW; + const char *dram_type_str; + + emc->dram_type =3D readl(emc->regs + EMC_FBIO_CFG5); + + emc->dram_type &=3D EMC_FBIO_CFG5_DRAM_TYPE_MASK; + emc->dram_type >>=3D EMC_FBIO_CFG5_DRAM_TYPE_SHIFT; + + emc->dram_num =3D tegra_mc_get_emem_device_count(emc->mc); + + emc_cfg =3D readl_relaxed(emc->regs + EMC_CFG_2); + + /* enable EMC and CAR to handshake on PLL divider/source changes */ + emc_cfg |=3D EMC_CFG_2_CLKCHANGE_REQ_ENABLE; + + /* configure clock change mode accordingly to DRAM type */ + if (emc->dram_type =3D=3D DRAM_TYPE_LPDDR2) + emc_cfg |=3D EMC_CFG_2_CLKCHANGE_PD_ENABLE; + else + emc_cfg &=3D ~EMC_CFG_2_CLKCHANGE_PD_ENABLE; + + writel_relaxed(emc_cfg, emc->regs + EMC_CFG_2); + + /* initialize interrupt */ + writel_relaxed(intmask, emc->regs + EMC_INTMASK); + writel_relaxed(0xffffffff, emc->regs + EMC_INTSTATUS); + + /* ensure that unwanted debug features are disabled */ + emc_dbg =3D readl_relaxed(emc->regs + EMC_DBG); + emc_dbg |=3D EMC_DBG_CFG_PRIORITY; + emc_dbg &=3D ~EMC_DBG_READ_MUX_ASSEMBLY; + emc_dbg &=3D ~EMC_DBG_WRITE_MUX_ACTIVE; + emc_dbg &=3D ~EMC_DBG_FORCE_UPDATE; + writel_relaxed(emc_dbg, emc->regs + EMC_DBG); + + switch (emc->dram_type) { + case DRAM_TYPE_DDR1: + dram_type_str =3D "DDR1"; + break; + case DRAM_TYPE_LPDDR2: + dram_type_str =3D "LPDDR2"; + break; + case DRAM_TYPE_DDR2: + dram_type_str =3D "DDR2"; + break; + case DRAM_TYPE_DDR3: + dram_type_str =3D "DDR3"; + break; + } + + dev_info_once(emc->dev, "%u %s %s attached\n", emc->dram_num, + dram_type_str, emc->dram_num =3D=3D 2 ? "devices" : "device"); + + emc_read_current_timing(emc, &emc->last_timing); + + return 0; +} + +static int load_one_timing_from_dt(struct tegra_emc *emc, + struct emc_timing *timing, + struct device_node *node) +{ + u32 value; + int err; + + err =3D of_property_read_u32(node, "clock-frequency", &value); + if (err) { + dev_err(emc->dev, "timing %pOFn: failed to read rate: %d\n", + node, err); + return err; + } + + timing->rate =3D value; + + err =3D of_property_read_u32_array(node, "nvidia,emc-configuration", + timing->emc_burst_data, + ARRAY_SIZE(timing->emc_burst_data)); + if (err) { + dev_err(emc->dev, + "timing %pOFn: failed to read emc burst data: %d\n", + node, err); + return err; + } + +#define EMC_READ_PROP(prop, dtprop) { \ + err =3D of_property_read_u32(node, dtprop, &timing->prop); \ + if (err) { \ + dev_err(emc->dev, "timing %pOFn: failed to read " #prop ": %d\n", \ + node, err); \ + return err; \ + } \ +} + + EMC_READ_PROP(emc_auto_cal_config, "nvidia,emc-auto-cal-config") + EMC_READ_PROP(emc_auto_cal_config2, "nvidia,emc-auto-cal-config2") + EMC_READ_PROP(emc_auto_cal_config3, "nvidia,emc-auto-cal-config3") + EMC_READ_PROP(emc_auto_cal_interval, "nvidia,emc-auto-cal-interval") + EMC_READ_PROP(emc_cfg, "nvidia,emc-cfg") + EMC_READ_PROP(emc_ctt_term_ctrl, "nvidia,emc-ctt-term-ctrl") + EMC_READ_PROP(emc_mode_1, "nvidia,emc-mode-1") + EMC_READ_PROP(emc_mode_2, "nvidia,emc-mode-2") + EMC_READ_PROP(emc_mode_4, "nvidia,emc-mode-4") + EMC_READ_PROP(emc_mode_reset, "nvidia,emc-mode-reset") + EMC_READ_PROP(emc_mrs_wait_cnt, "nvidia,emc-mrs-wait-cnt") + EMC_READ_PROP(emc_sel_dpd_ctrl, "nvidia,emc-sel-dpd-ctrl") + EMC_READ_PROP(emc_xm2dqspadctrl2, "nvidia,emc-xm2dqspadctrl2") + EMC_READ_PROP(emc_zcal_cnt_long, "nvidia,emc-zcal-cnt-long") + EMC_READ_PROP(emc_zcal_interval, "nvidia,emc-zcal-interval") + +#undef EMC_READ_PROP + + return 0; +} + +static int cmp_timings(const void *_a, const void *_b) +{ + const struct emc_timing *a =3D _a; + const struct emc_timing *b =3D _b; + + if (a->rate < b->rate) + return -1; + else if (a->rate =3D=3D b->rate) + return 0; + else + return 1; +} + +static int emc_check_mc_timings(struct tegra_emc *emc) +{ + struct tegra_mc *mc =3D emc->mc; + unsigned int i; + + if (emc->num_timings !=3D mc->num_timings) { + dev_err(emc->dev, "emc/mc timings number mismatch: %u %u\n", + emc->num_timings, mc->num_timings); + return -EINVAL; + } + + for (i =3D 0; i < mc->num_timings; i++) { + if (emc->timings[i].rate !=3D mc->timings[i].rate) { + dev_err(emc->dev, + "emc/mc timing rate mismatch: %lu %lu\n", + emc->timings[i].rate, mc->timings[i].rate); + return -EINVAL; + } + } + + return 0; +} + +static int tegra_emc_load_timings_from_dt(struct tegra_emc *emc, + struct device_node *node) +{ + int child_count =3D of_get_child_count(node); + struct emc_timing *timing; + unsigned int i =3D 0; + int err; + + emc->timings =3D devm_kcalloc(emc->dev, child_count, sizeof(*timing), + GFP_KERNEL); + if (!emc->timings) + return -ENOMEM; + + emc->num_timings =3D child_count; + + for_each_child_of_node_scoped(node, child) { + timing =3D &emc->timings[i++]; + + err =3D load_one_timing_from_dt(emc, timing, child); + if (err) + return err; + } + + sort(emc->timings, emc->num_timings, sizeof(*timing), cmp_timings, + NULL); + + err =3D emc_check_mc_timings(emc); + if (err) + return err; + + dev_info_once(emc->dev, + "got %u timings for RAM code %u (min %luMHz max %luMHz)\n", + emc->num_timings, + tegra_read_ram_code(), + emc->timings[0].rate / 1000000, + emc->timings[emc->num_timings - 1].rate / 1000000); + + return 0; +} + +static struct device_node * +tegra_emc_find_node_by_ram_code(struct device_node *node, u32 ram_code) +{ + struct device_node *np; + int err; + + for_each_child_of_node(node, np) { + u32 value; + + err =3D of_property_read_u32(np, "nvidia,ram-code", &value); + if (err || value !=3D ram_code) + continue; + + return np; + } + + return NULL; +} + +static void tegra_emc_rate_requests_init(struct tegra_emc *emc) +{ + unsigned int i; + + for (i =3D 0; i < EMC_RATE_TYPE_MAX; i++) { + emc->requested_rate[i].min_rate =3D 0; + emc->requested_rate[i].max_rate =3D ULONG_MAX; + } +} + +static int emc_request_rate(struct tegra_emc *emc, + unsigned long new_min_rate, + unsigned long new_max_rate, + enum emc_rate_request_type type) +{ + struct emc_rate_request *req =3D emc->requested_rate; + unsigned long min_rate =3D 0, max_rate =3D ULONG_MAX; + unsigned int i; + int err; + + /* select minimum and maximum rates among the requested rates */ + for (i =3D 0; i < EMC_RATE_TYPE_MAX; i++, req++) { + if (i =3D=3D type) { + min_rate =3D max(new_min_rate, min_rate); + max_rate =3D min(new_max_rate, max_rate); + } else { + min_rate =3D max(req->min_rate, min_rate); + max_rate =3D min(req->max_rate, max_rate); + } + } + + if (min_rate > max_rate) { + dev_err_ratelimited(emc->dev, "%s: type %u: out of range: %lu %lu\n", + __func__, type, min_rate, max_rate); + return -ERANGE; + } + + /* + * EMC rate-changes should go via OPP API because it manages voltage + * changes. + */ + err =3D dev_pm_opp_set_rate(emc->dev, min_rate); + if (err) + return err; + + emc->requested_rate[type].min_rate =3D new_min_rate; + emc->requested_rate[type].max_rate =3D new_max_rate; + + return 0; +} + +static int emc_set_min_rate(struct tegra_emc *emc, unsigned long rate, + enum emc_rate_request_type type) +{ + struct emc_rate_request *req =3D &emc->requested_rate[type]; + int ret; + + mutex_lock(&emc->rate_lock); + ret =3D emc_request_rate(emc, rate, req->max_rate, type); + mutex_unlock(&emc->rate_lock); + + return ret; +} + +static int emc_set_max_rate(struct tegra_emc *emc, unsigned long rate, + enum emc_rate_request_type type) +{ + struct emc_rate_request *req =3D &emc->requested_rate[type]; + int ret; + + mutex_lock(&emc->rate_lock); + ret =3D emc_request_rate(emc, req->min_rate, rate, type); + mutex_unlock(&emc->rate_lock); + + return ret; +} + +/* + * debugfs interface + * + * The memory controller driver exposes some files in debugfs that can be = used + * to control the EMC frequency. The top-level directory can be found here: + * + * /sys/kernel/debug/emc + * + * It contains the following files: + * + * - available_rates: This file contains a list of valid, space-separated + * EMC frequencies. + * + * - min_rate: Writing a value to this file sets the given frequency as = the + * floor of the permitted range. If this is higher than the currently + * configured EMC frequency, this will cause the frequency to be + * increased so that it stays within the valid range. + * + * - max_rate: Similarily to the min_rate file, writing a value to this = file + * sets the given frequency as the ceiling of the permitted range. If + * the value is lower than the currently configured EMC frequency, t= his + * will cause the frequency to be decreased so that it stays within = the + * valid range. + */ + +static bool tegra_emc_validate_rate(struct tegra_emc *emc, unsigned long r= ate) +{ + unsigned int i; + + for (i =3D 0; i < emc->num_timings; i++) + if (rate =3D=3D emc->timings[i].rate) + return true; + + return false; +} + +static int tegra_emc_debug_available_rates_show(struct seq_file *s, + void *data) +{ + struct tegra_emc *emc =3D s->private; + const char *prefix =3D ""; + unsigned int i; + + for (i =3D 0; i < emc->num_timings; i++) { + seq_printf(s, "%s%lu", prefix, emc->timings[i].rate); + prefix =3D " "; + } + + seq_puts(s, "\n"); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(tegra_emc_debug_available_rates); + +static int tegra_emc_debug_min_rate_get(void *data, u64 *rate) +{ + struct tegra_emc *emc =3D data; + + *rate =3D emc->debugfs.min_rate; + + return 0; +} + +static int tegra_emc_debug_min_rate_set(void *data, u64 rate) +{ + struct tegra_emc *emc =3D data; + int err; + + if (!tegra_emc_validate_rate(emc, rate)) + return -EINVAL; + + err =3D emc_set_min_rate(emc, rate, EMC_RATE_DEBUG); + if (err < 0) + return err; + + emc->debugfs.min_rate =3D rate; + + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(tegra_emc_debug_min_rate_fops, + tegra_emc_debug_min_rate_get, + tegra_emc_debug_min_rate_set, "%llu\n"); + +static int tegra_emc_debug_max_rate_get(void *data, u64 *rate) +{ + struct tegra_emc *emc =3D data; + + *rate =3D emc->debugfs.max_rate; + + return 0; +} + +static int tegra_emc_debug_max_rate_set(void *data, u64 rate) +{ + struct tegra_emc *emc =3D data; + int err; + + if (!tegra_emc_validate_rate(emc, rate)) + return -EINVAL; + + err =3D emc_set_max_rate(emc, rate, EMC_RATE_DEBUG); + if (err < 0) + return err; + + emc->debugfs.max_rate =3D rate; + + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(tegra_emc_debug_max_rate_fops, + tegra_emc_debug_max_rate_get, + tegra_emc_debug_max_rate_set, "%llu\n"); + +static void emc_debugfs_init(struct device *dev, struct tegra_emc *emc) +{ + unsigned int i; + int err; + + emc->debugfs.min_rate =3D ULONG_MAX; + emc->debugfs.max_rate =3D 0; + + for (i =3D 0; i < emc->num_timings; i++) { + if (emc->timings[i].rate < emc->debugfs.min_rate) + emc->debugfs.min_rate =3D emc->timings[i].rate; + + if (emc->timings[i].rate > emc->debugfs.max_rate) + emc->debugfs.max_rate =3D emc->timings[i].rate; + } + + if (!emc->num_timings) { + emc->debugfs.min_rate =3D clk_get_rate(emc->clk); + emc->debugfs.max_rate =3D emc->debugfs.min_rate; + } + + err =3D clk_set_rate_range(emc->clk, emc->debugfs.min_rate, + emc->debugfs.max_rate); + if (err < 0) { + dev_err(dev, "failed to set rate range [%lu-%lu] for %pC\n", + emc->debugfs.min_rate, emc->debugfs.max_rate, + emc->clk); + return; + } + + emc->debugfs.root =3D debugfs_create_dir("emc", NULL); + + debugfs_create_file("available_rates", 0444, emc->debugfs.root, emc, + &tegra_emc_debug_available_rates_fops); + debugfs_create_file("min_rate", 0644, emc->debugfs.root, + emc, &tegra_emc_debug_min_rate_fops); + debugfs_create_file("max_rate", 0644, emc->debugfs.root, + emc, &tegra_emc_debug_max_rate_fops); +} + +static inline struct tegra_emc * +to_tegra_emc_provider(struct icc_provider *provider) +{ + return container_of(provider, struct tegra_emc, provider); +} + +static struct icc_node_data * +emc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data) +{ + struct icc_provider *provider =3D data; + struct icc_node_data *ndata; + struct icc_node *node; + + /* External Memory is the only possible ICC route */ + list_for_each_entry(node, &provider->nodes, node_list) { + if (node->id !=3D TEGRA_ICC_EMEM) + continue; + + ndata =3D kzalloc(sizeof(*ndata), GFP_KERNEL); + if (!ndata) + return ERR_PTR(-ENOMEM); + + /* + * SRC and DST nodes should have matching TAG in order to have + * it set by default for a requested path. + */ + ndata->tag =3D TEGRA_MC_ICC_TAG_ISO; + ndata->node =3D node; + + return ndata; + } + + return ERR_PTR(-EPROBE_DEFER); +} + +static int emc_icc_set(struct icc_node *src, struct icc_node *dst) +{ + struct tegra_emc *emc =3D to_tegra_emc_provider(dst->provider); + unsigned long long peak_bw =3D icc_units_to_bps(dst->peak_bw); + unsigned long long avg_bw =3D icc_units_to_bps(dst->avg_bw); + unsigned long long rate =3D max(avg_bw, peak_bw); + unsigned int dram_data_bus_width_bytes =3D 4; + const unsigned int ddr =3D 2; + int err; + + /* + * Tegra114 EMC runs on a clock rate of SDRAM bus. This means that + * EMC clock rate is twice smaller than the peak data rate because + * data is sampled on both EMC clock edges. + */ + do_div(rate, ddr * dram_data_bus_width_bytes); + rate =3D min_t(u64, rate, U32_MAX); + + err =3D emc_set_min_rate(emc, rate, EMC_RATE_ICC); + if (err) + return err; + + return 0; +} + +static int tegra_emc_interconnect_init(struct tegra_emc *emc) +{ + const struct tegra_mc_soc *soc =3D emc->mc->soc; + struct icc_node *node; + int err; + + emc->provider.dev =3D emc->dev; + emc->provider.set =3D emc_icc_set; + emc->provider.data =3D &emc->provider; + emc->provider.aggregate =3D soc->icc_ops->aggregate; + emc->provider.xlate_extended =3D emc_of_icc_xlate_extended; + + icc_provider_init(&emc->provider); + + /* create External Memory Controller node */ + node =3D icc_node_create(TEGRA_ICC_EMC); + if (IS_ERR(node)) { + err =3D PTR_ERR(node); + goto err_msg; + } + + node->name =3D "External Memory Controller"; + icc_node_add(node, &emc->provider); + + /* link External Memory Controller to External Memory (DRAM) */ + err =3D icc_link_create(node, TEGRA_ICC_EMEM); + if (err) + goto remove_nodes; + + /* create External Memory node */ + node =3D icc_node_create(TEGRA_ICC_EMEM); + if (IS_ERR(node)) { + err =3D PTR_ERR(node); + goto remove_nodes; + } + + node->name =3D "External Memory (DRAM)"; + icc_node_add(node, &emc->provider); + + err =3D icc_provider_register(&emc->provider); + if (err) + goto remove_nodes; + + return 0; + +remove_nodes: + icc_nodes_remove(&emc->provider); +err_msg: + dev_err(emc->dev, "failed to initialize ICC: %d\n", err); + + return err; +} + +static void devm_tegra_emc_unset_callback(void *data) +{ + tegra124_clk_set_emc_callbacks(NULL, NULL); +} + +static int tegra_emc_probe(struct platform_device *pdev) +{ + struct tegra_core_opp_params opp_params =3D {}; + struct device_node *np; + struct tegra_emc *emc; + u32 ram_code; + int err; + + emc =3D devm_kzalloc(&pdev->dev, sizeof(*emc), GFP_KERNEL); + if (!emc) + return -ENOMEM; + + mutex_init(&emc->rate_lock); + emc->dev =3D &pdev->dev; + + emc->regs =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(emc->regs)) + return PTR_ERR(emc->regs); + + emc->mc =3D devm_tegra_memory_controller_get(&pdev->dev); + if (IS_ERR(emc->mc)) + return PTR_ERR(emc->mc); + + ram_code =3D tegra_read_ram_code(); + + np =3D tegra_emc_find_node_by_ram_code(pdev->dev.of_node, ram_code); + if (np) { + err =3D tegra_emc_load_timings_from_dt(emc, np); + of_node_put(np); + if (err) + return err; + } else { + dev_info_once(&pdev->dev, + "no memory timings for RAM code %u found in DT\n", + ram_code); + } + + err =3D emc_init(emc); + if (err) { + dev_err(&pdev->dev, "EMC initialization failed: %d\n", err); + return err; + } + + platform_set_drvdata(pdev, emc); + + tegra124_clk_set_emc_callbacks(tegra_emc_prepare_timing_change, + tegra_emc_complete_timing_change); + + err =3D devm_add_action_or_reset(&pdev->dev, devm_tegra_emc_unset_callbac= k, + NULL); + if (err) + return err; + + err =3D platform_get_irq(pdev, 0); + if (err < 0) + return err; + + emc->irq =3D err; + + err =3D devm_request_irq(&pdev->dev, emc->irq, tegra_emc_isr, 0, + dev_name(&pdev->dev), emc); + if (err) { + dev_err(&pdev->dev, "failed to request irq: %d\n", err); + return err; + } + + emc->clk =3D devm_clk_get(&pdev->dev, "emc"); + if (IS_ERR(emc->clk)) { + err =3D PTR_ERR(emc->clk); + dev_err(&pdev->dev, "failed to get EMC clock: %d\n", err); + return err; + } + + opp_params.init_state =3D true; + + err =3D devm_tegra_core_dev_init_opp_table(&pdev->dev, &opp_params); + if (err) + return err; + + tegra_emc_rate_requests_init(emc); + + if (IS_ENABLED(CONFIG_DEBUG_FS)) + emc_debugfs_init(&pdev->dev, emc); + + tegra_emc_interconnect_init(emc); + + /* + * Don't allow the kernel module to be unloaded. Unloading adds some + * extra complexity which doesn't really worth the effort in a case of + * this driver. + */ + try_module_get(THIS_MODULE); + + return 0; +}; + +static const struct of_device_id tegra_emc_of_match[] =3D { + { .compatible =3D "nvidia,tegra114-emc" }, + {} +}; +MODULE_DEVICE_TABLE(of, tegra_emc_of_match); + +static struct platform_driver tegra_emc_driver =3D { + .probe =3D tegra_emc_probe, + .driver =3D { + .name =3D "tegra114-emc", + .of_match_table =3D tegra_emc_of_match, + .suppress_bind_attrs =3D true, + .sync_state =3D icc_sync_state, + }, +}; +module_platform_driver(tegra_emc_driver); + +MODULE_AUTHOR("Svyatoslav Ryhel "); +MODULE_DESCRIPTION("NVIDIA Tegra114 EMC driver"); +MODULE_LICENSE("GPL"); --=20 2.51.0