From patchwork Thu Apr 30 07:04:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1132 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 0A0143F0D3 for ; Thu, 30 Apr 2020 09:04:30 +0200 (CEST) Received: by mail-pj1-f72.google.com with SMTP id l40sf729764pjb.8 for ; Thu, 30 Apr 2020 00:04:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230268; cv=pass; d=google.com; s=arc-20160816; b=Y72O/gA/SlTN7hjtBGkxNtSlfsEcAOzJ7FxtIkKtZCjRMbGIc/2ehfUrfQmZ02z6H8 qekQiGWk2iEnhlKncDQKRYKQa5GsHj0L6urQBR11yRX4UMyJsPBpaov99KJcu7DoSqW/ UDFnqTSOHxIMqxtvTKYAymso4X8BCnVxdQQQ/hSypNIUw/aTn9d0iNnxIhgNIiyWYxQl w8NvC+BIu9DyCeT+Q2TYnRXHAj2JfYs7sFG2HC2DBuxunBwMe9vRwu6CpVgVPRUKKvzt Tn0k3yF6zrnfYv3UWKq0ZId+TvVCIiawlw5I5kjiGorH1UDh3Px99GtZLJ8S80WxqaAf t2FQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=0z5t+1DqXG7NePlBljcWxleqB0wSmvt5+4pFLXh1mWQ=; b=Yi0de9z1RasLvBAHpqr8pL7KXAvQYGu7UZPrdonvyGemLgHW6z90vRJehMNMN4KbKh cN4uYJi6js2ZornW/8DGfUPIwiyIb2+izmcU8y1UvGPWlobOPCJAKcmSXsw/A821uj81 Xb0XSzKB0c+DNnnt/dnrXgxsOFEbCN7QxK74ZX276W0n3Ljbe8kjscsTGTHvlNMzUhtt +u4XLTi9EtNPeCbvc05QI5vaHiVLgd9nwaeUm7owaDfHwKHm/qkQLvhoJNTy0LdBs/cO Su8wpKHwRxqgh0rmz/7I53knGOB9lVfYHZMWuJ+UgomZgJsScbfSCZwc/HV5VCsPjlhV JOYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iY+ebA4C; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=0z5t+1DqXG7NePlBljcWxleqB0wSmvt5+4pFLXh1mWQ=; b=W539/RMaS9sRuBzEqh8EaUn5r86pkv43qlVApih8LX7109lINdznavrr6ZHBJW57pS S9ErrQggnxyd21sRdH3RUm3L7t2O30i7WfuVjmrHU42Yxp9YozCZYxDtlSg6NafDLaX3 LqkEiE3qzVIFL1T3SYDUYvS9bttPzee87Oe3I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=0z5t+1DqXG7NePlBljcWxleqB0wSmvt5+4pFLXh1mWQ=; b=NQUjWnZ7zY0vk+WRVlHujoqu1Y7n09OzIUMWoG2iDiuGPFW9kkkHByqpi4NDUC03oC 2ZV+gLKCjTT9lcJBWPbqGRlusUnNaTCpUUsZKFnfpls0fsg/TbkL0S4X3M4WP9SZsZrS tnPDRF2APqYOHFqgN/WXYBmsXMWmq73+9RxWbcO0mFkVdac9285y9nF+oQK5lwJp8IzB P9Y8GRVSGIt2mynHMLezPUvb7ojDiKj+k0R9nn36tUdpbdf7OiwUB2B+ZUWCShxzJ/Sf /PM9gc3RdkFey4tv+SNXVSD6ahKC7q3H+AOg+/ZZQAxfxcyKa1JzqDPiAm3mghTEO4Ko oTIg== X-Gm-Message-State: AGi0PubU371/vK+AQd1BDJZVVfEsBmEGetMpsNu+2lE5y5ek439JEsKn d77iOfAMSS2dIlena6XoapMziuWv X-Google-Smtp-Source: APiQypJzrvmv7RmnjdF7rU1mVqmdjmY24qXa3hqY2oXNpUSlOMZiTgGXCFijpaxJLpYY/1qW2jT1aQ== X-Received: by 2002:a17:902:a413:: with SMTP id p19mr2351975plq.1.1588230268047; Thu, 30 Apr 2020 00:04:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:224f:: with SMTP id c73ls1620747pje.3.canary-gmail; Thu, 30 Apr 2020 00:04:27 -0700 (PDT) X-Received: by 2002:a17:90a:8c85:: with SMTP id b5mr1276667pjo.187.1588230267568; Thu, 30 Apr 2020 00:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230267; cv=none; d=google.com; s=arc-20160816; b=pS1pXquS4qhSqQ2PbBhWyok0FapvlrtCQLqSzlxFnNc54GdSaCi7DiZlIiX8u03EMQ EDOfsyJXLt+cSC4JhZm9CghDD5v8/Hc2MNuk7rY4nieQl3K87Gxe4LBpT852jMcNjgeU R8sDjdx7oje+C8SnBJk+AA8KVNBv0FIZpa3xIWNkWxcaDu6S6V7KsjZVG+izCqWcOMRF RKaP7MuMj1rdRpFrDA0ijs9Evf6ZdAZSugGy7xrDTj5T4eyIH7/q1BrrTckpIYBxLWiR oy/Ba2Ek8B5zw8+HeFtXqmI8M5K1iISDo1TL3DTfOalTxEdztsKGVfRKJhRaLHlGbZaT qZQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QZQxIM9Lp5gBpYd0vuqexfM8OFH70HyOZiX2o76/vfc=; b=xZfcV57ZtX0V16cTDGHy1Yh9qJAPeC72+loj2eSv+JfFmNdiAUq9wBMnfARuUlXtIb IQlreuQqs7i3yM5JT+4ri8Ce0gnJLWoUDO3VnieRK9VRg+2wjCuDozlM8FZzbiRC9Mmp d538V5rJnh4UWmBHkW9GMXhA1VobVTrdxHXo6SJ4WhQ2TfvQrN+tHQ96VDRfNganXsx5 OFISsfrNiay0lwGMw9i2qRB0T4emy1tZdM4XL9guZQXsHWESOKjWrqwRlpZr1GMyxMat QDYT3xKLaKoe4yFOKBRxQAVfljhNV9fKn6Jfnmu4A3wKYRrCu3+tum1PQ5YX1Yp9mgV2 gTrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iY+ebA4C; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q15sor975596pjl.0.2020.04.30.00.04.27 for (Google Transport Security); Thu, 30 Apr 2020 00:04:27 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:fc8a:: with SMTP id ci10mr1307246pjb.152.1588230267082; Thu, 30 Apr 2020 00:04:27 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:25 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Tom Rini Subject: [PATCH v2 1/8] iopoll: Add dealy to read poll Date: Thu, 30 Apr 2020 12:34:05 +0530 Message-Id: <20200430070412.12499-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iY+ebA4C; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some drivers and other bsp code not only poll the register with timeout but also required to delay on each transaction. This patch add that requirement by adding sleep_us variable so-that read_poll_timeout now support delay as well. Cc: Tom Rini Signed-off-by: Jagan Teki --- Changes for v2: - none include/linux/iopoll.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index ab0ae1969a..0bbd757939 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -16,6 +16,7 @@ * @addr: Address to poll * @val: Variable to read the value into * @cond: Break condition (usually involving @val) + * @sleep_us: Maximum time to sleep in us * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout. In either @@ -24,7 +25,7 @@ * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. */ -#define readx_poll_timeout(op, addr, val, cond, timeout_us) \ +#define readx_poll_timeout(op, addr, val, cond, sleep_us, timeout_us) \ ({ \ unsigned long timeout = timer_get_us() + timeout_us; \ for (;;) { \ @@ -35,33 +36,34 @@ (val) = op(addr); \ break; \ } \ + if (sleep_us) \ + udelay(sleep_us); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) - #define readb_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readb, addr, val, cond, timeout_us) + readx_poll_timeout(readb, addr, val, cond, false, timeout_us) #define readw_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readw, addr, val, cond, timeout_us) + readx_poll_timeout(readw, addr, val, cond, false, timeout_us) #define readl_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readl, addr, val, cond, timeout_us) + readx_poll_timeout(readl, addr, val, cond, false, timeout_us) #define readq_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readq, addr, val, cond, timeout_us) + readx_poll_timeout(readq, addr, val, cond, false, timeout_us) #define readb_relaxed_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readb_relaxed, addr, val, cond, timeout_us) + readx_poll_timeout(readb_relaxed, addr, val, cond, false, timeout_us) #define readw_relaxed_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readw_relaxed, addr, val, cond, timeout_us) + readx_poll_timeout(readw_relaxed, addr, val, cond, false, timeout_us) #define readl_relaxed_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readl_relaxed, addr, val, cond, timeout_us) + readx_poll_timeout(readl_relaxed, addr, val, cond, false, timeout_us) #define readq_relaxed_poll_timeout(addr, val, cond, timeout_us) \ - readx_poll_timeout(readq_relaxed, addr, val, cond, timeout_us) + readx_poll_timeout(readq_relaxed, addr, val, cond, false, timeout_us) #endif /* _LINUX_IOPOLL_H */ From patchwork Thu Apr 30 07:04:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1133 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B1FC83F0D3 for ; Thu, 30 Apr 2020 09:04:33 +0200 (CEST) Received: by mail-pf1-f198.google.com with SMTP id y16sf4555767pfe.16 for ; Thu, 30 Apr 2020 00:04:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230272; cv=pass; d=google.com; s=arc-20160816; b=RQXaxXiVDa127EMe0TuOOByv1nPhq0w5i5VH3Zm5fX9WVyxm9mYZcVA6sNfGC1DSYK DDBco15A2dZVCPPj+kkKsap04hDaPCpFZnBFNMrvjQ4YywFRxF+8vMy0hoBsVbSuEBg5 t/C+m3ZrORq06XX/sN7Fk18Te68/SA5meWsOAw8KzvdT3NS0yIBRhMZ7YUPE8xurI5k5 PkHo0+C9MFLqlI32ol72oKQdIMRQkM44q5DzNkVmbM1R6XAdKD6t/qClonsY5AppqYGq 69xrtItm1G7ek778FXogdZcG1+XG42jVaWF09NHDtp7KZnr4BNCvA8fF//FTDdvdDb0B llpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=pfa5aJPipl3FLMfiplthkasrbKIJXlBnFmnBpbz8drI=; b=PkKjSEjxTskdCKvFVF45YjuZK1zXRnOYorl3OzqvFFVUgPZxjhNAOITPp2Mn5P2OHZ B/+dHp7SnLeseMjrPNJKh3Onm1l1/pIRUGxV15iEverRRxPRaxIfubpT7E/CSyERzcXv jXAaRdQslpyaNzK+ZKQ/8+AEo67FC3MwSjbYaX23YzAMBY+DY36iI3pyM5iWuJo2vp2s 2Xlj8iCAScFcCXFno4Nn2B02htGNS3RFWMUNAvyQBlaNT5GG9zUdqcJoUgR0QP5nWKn7 34Oszv1OBYyTr4J8xvDdsdlDTh/NY4lS3p05IFoDy8VYWYi3HKec0Pu7ffyozYvuE3jJ jn0g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KwiLAQPZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=pfa5aJPipl3FLMfiplthkasrbKIJXlBnFmnBpbz8drI=; b=ZDJPJV6+2PX8UjI7iFj0ybgMvnMt3AJ+i2p8boKnLhccjmQ6sNXpAkFyU51ERvvy4s NnQ/LgGq8IRVezXjabLJRDLE3sO0GaL9nZp0zZpR/eJD0PVYKrGqhavlK4KLIYC/tJg+ tpVhrSO+zYe0NOXxPE0aoBa2lf2p3jh6Gul6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=pfa5aJPipl3FLMfiplthkasrbKIJXlBnFmnBpbz8drI=; b=BSptlHy/6aQYXsNQElvaxx19/6Q2Q23d8mj8ZXUnk400NcI3Xt65Vkd9sNXg+SKHid Myfddq1sC2k6/XVso39nT0qchdpZCMQjnU0S+QQGEt81ZMnpvK15m+zbkoP1xeitRYlr tU2lvBZQAxc5+P7lKWqpDtc+CMv3EZK4T+8FArSp7BYIi0U1mkqRZNOiJ99OKpj1Gjd3 UuVhxllGOYvD791xhP9BTRxPa+GzRFFPE2vVJI3MkMGuLMykGk1FF/MqjC36msKR4koy eHdQlbWdrge41/u9Y32tYh7yEz1wwomlg1fV4TTeXO1rZXzOah//2u2Cciq3VWUvTnl4 YWMA== X-Gm-Message-State: AGi0Pubsc7JjejGVutqQoENwmyRLRIekcwWcaQJ1EOpz+0EU07Vba+a/ /z4C3Q5aWO/PV6zey3n4lcvkG4po X-Google-Smtp-Source: APiQypIRsKXgnbkm/GPOF/ixefSTUCWibgYInPnPR/VWpFPuIDtvEqPWogL4kiSsDxGrcFWz6Dr5TA== X-Received: by 2002:a62:7d91:: with SMTP id y139mr2152181pfc.172.1588230272486; Thu, 30 Apr 2020 00:04:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:224f:: with SMTP id c73ls1620848pje.3.canary-gmail; Thu, 30 Apr 2020 00:04:32 -0700 (PDT) X-Received: by 2002:a17:90a:fb89:: with SMTP id cp9mr1319987pjb.40.1588230272062; Thu, 30 Apr 2020 00:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230272; cv=none; d=google.com; s=arc-20160816; b=IODxZveUUFmc/f0VY3Afyp0FoHn6Trkhn+qXIkYloMsvOsht7CZI6OA+U8PVGQa6bF 6uxcgFYp+58dJKr/mSE9/3XBZXgd8FETGsObVQAQb6uWm+vGYydjD6WxVkIZWsnZ+PEB uOfHY7Ej33xEBWYTXafsQregIBq9suDTZPat9cS7kbFL7Edh94NMuBUWFOYSFde+TjUK 7vEe0KN50zwe+CSzhBzLhL3Y0udjeqiCXIzR9sZExldxHBa49AHMwFyXAzU/y43LdrYo EtvPiE7b6FWEQ20CXdOgcBLfMxKo5iCAnx2rKB3ds+J1gsFhbd7vNPWzRO8WacxLiVou xJKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WWOeoV6bRuBvU+8GtDUel9zwEhNvk1uDDmzUorUI6o8=; b=eEg3k3sI4W4wAC1I77Sb10DaSKtBWL3OTArxcMq+953V6EWZKglfT3TYl5BVUIJHK4 KrYkVEhFY5pPM+Z4HnsBQLw8Wmz8QzNczGxUOi3hGpllmsy17IaTNZSEI6NL52qfP++b mfBnXmQB/GaAnLM/dte/AiQw1YSk+eTi1rxuZe/Oa0sSCS6uqGvyCnJ7Kvzpz9Iq63o/ H51aoj+capKDllwqRcIB8AsKnFL8F7EcgQAHEBmwl2Mzw35j2txS6V4GW+nYj1p2koxJ QUQbsEUlgIfUd5iGq3Kf5LjGQPyWrO5e8cg0JsXo9Nc3c7ljrQuC57oA/d8kIMGoA2x4 mQZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KwiLAQPZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z67sor4618728pfb.9.2020.04.30.00.04.31 for (Google Transport Security); Thu, 30 Apr 2020 00:04:31 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:aa7:957c:: with SMTP id x28mr2091592pfq.31.1588230271132; Thu, 30 Apr 2020 00:04:31 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:30 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Tom Rini Subject: [PATCH v2 2/8] iopoll: Add readl_poll_sleep_timeout Date: Thu, 30 Apr 2020 12:34:06 +0530 Message-Id: <20200430070412.12499-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=KwiLAQPZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add readl poll API with sleep and timeout support. Cc: Tom Rini Signed-off-by: Jagan Teki --- Changes for v2: - none include/linux/iopoll.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 0bbd757939..e087f23271 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -42,6 +42,9 @@ (cond) ? 0 : -ETIMEDOUT; \ }) +#define readl_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \ + readx_poll_timeout(readl, addr, val, cond, sleep_us, timeout_us) + #define readb_poll_timeout(addr, val, cond, timeout_us) \ readx_poll_timeout(readb, addr, val, cond, false, timeout_us) From patchwork Thu Apr 30 07:04:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1134 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 200F23F0D3 for ; Thu, 30 Apr 2020 09:04:37 +0200 (CEST) Received: by mail-pl1-f198.google.com with SMTP id c1sf4155188plz.14 for ; Thu, 30 Apr 2020 00:04:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230276; cv=pass; d=google.com; s=arc-20160816; b=Fnau68W0xY+n78buhu5cmgdnNtwzHPKvdq+mbPjbHalODJ5mV0zTDaPX4srm44zyeQ TSmwh6d7DOBdRXQ8GAXnc4QchQlcw0IKCgCKUE/h3M+uW2+4SyTikIQKyRHFmboJoLlS LCDO3sxVEIw9Tv6DjbYvgt4eh5jvOZImo6whVO6UjOdweCHxXz4gavBRbviUoPo4B/t2 nmd6tDivs05DNB5wOdDTu//h9HpW4Gz0w5kLFTKHZVPtSULj+sy+DK2l1zHufigBtsvg 95M7YP2PJ/qnthdd11AYEROhhT9F850R2SbScKukhBA/Stg3Vo1xB0DyD2UE1eEHKHAx aWww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=+Fhxijf99W67R9f0+iuN4zGiKF9bzhRfx7/g6NF6lsI=; b=NKD/araKzFsVEzn37E28mapyPpW/+1PFC7jno5tWmFz0pqQRdZ9m6I5DxffMK+Isdn zymPv8el31XDM0s3QXpDmiezGZDsNZOft5ASxmH/i3T6/TrDRmwcUQRCZsMzWbZxDFbN +PAVh8BJQfmGCly/RTwb+U3+OmxEfcxzkVG9Mmlq/CV7y/WLs3kVSFqA+v7ddayEhNFc ax8ko7+KBLmqoDsOeEiD50CiNA2Fdj6OJiyXuTdh+3O3ZBaqixSfoN7V3oPVyUEWb+Cs W1e8yv3H9yHw7jpkycyeZYz2ZwjmoxWg36mOC4YC45t9xOFSP8svrze8QCapzC8i8O9W 4KMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIWLUVZ5; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=+Fhxijf99W67R9f0+iuN4zGiKF9bzhRfx7/g6NF6lsI=; b=SrPr/nkLycaHMD2k6uG56It0oRP+x50ekZkDkz1EO2WPgSBY2ZUtyaN3Qj7HAYhU/L cxOICNzsu+2kVGP4ww4rFbf/S4HpcCoRlDQZ+i9jTYD9OB/txXmBdcEs4edDls7SUW4h LYT4OB2JohVNgQKMHAb8D21zjyZ3jPdL76mx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=+Fhxijf99W67R9f0+iuN4zGiKF9bzhRfx7/g6NF6lsI=; b=YLK0GlAEdr8q2u9cpRrY5EDqtbEvlCMB6chPwjTQCj9g4Bj8fpRvGudpFlh5Ry/L4N ag8bP3CH8D+h5+q6u46j9qcWHWQGJF8Ks7hjFK1M6DAwDu1EllFM1UQlf9I80AZbXa0g jBqh/BNYrP7Vdb8fgF/DP2wS7J/5J/CSnsSC6FqqxmzcpthRPv5APgCY2/uZTsRYptsx 9Z32ij8Kc4L5rribsdW66Y9j6kwBLzZ8fN9pwIlDkoItOT5/oJYrwt8wDHocVvB6isar iVcECCPLgQEtkhH0KbpIqmANgYPA67rUvqbhH1CVb/L3xhHngK/UMPh96S5TdR+28CBg wJXQ== X-Gm-Message-State: AGi0PuZmJC3c+ri2dPSCMBjjwb+w6jThdJUu5SkMDmSMZ5vNtyClxq+u CwYVkQ3uq5umcw4Kvjczok5LjTke X-Google-Smtp-Source: APiQypJprfkz5Nr6OYFaQL2adWtS4YcOSzfBlXjHCQ1vOJpAxixnBPfPVhjTrfurTgK7px1L8QgqgA== X-Received: by 2002:a63:8149:: with SMTP id t70mr1932148pgd.205.1588230275760; Thu, 30 Apr 2020 00:04:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:191c:: with SMTP id z28ls172767pgl.11.gmail; Thu, 30 Apr 2020 00:04:35 -0700 (PDT) X-Received: by 2002:a63:ef04:: with SMTP id u4mr2030093pgh.280.1588230275257; Thu, 30 Apr 2020 00:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230275; cv=none; d=google.com; s=arc-20160816; b=R+XMjWocw+jtosENVuSw9Tm+2S/SzabNP4OigmFzSsm+32auQb1piYWF++8z7vxhh1 WvyeI45mWpP+WHKB0h9Ovp9EckP517rAN9u8ND1fDkvTeBOMfPaUd609Zk1fje1998mp 7a4opSwr1jRT+1I8xNI1s74X4UNbxUBBRcZ9kheaDEEa3DUFdIbWEzwczlABUreE234o 7hZ0yIcFYEtdVx/lfD0KZW2H08B2rOQJb/85l1Ac9SVPQum2v8VVmff9dwxEmzPRUQ2w locuuysEC2B1k8u5KnAhpKWocmRL4gQJt2o+cay72ea5x/KrCpv3mAabbxAo51ARtcwv 5R6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kx3DvM6u34JnEdDKGfdUYWp2iOjqdjfvFB3xF13lJxo=; b=qzZcNeX3qz0JdZN9n1Xod7eXX6JDlI4tlGthrFcNxfUmto0K7IV8VCjj+r5GxJgO9S ySfNtHXRl7UEdVYkPIeC01SnYWlEfticvVTnF3/lsIvdUqI4plkjO/ZNEc/WdcDmOGKX m8eUxeezm9vGNJININlKFcylDeD8uuGYhngJ8MVVhpV5qeG9HPPw5usDS1q0x+HsXsJC yH0UJuXUHnVGSYCML4ZWx/m3qbPPDLalaLWDfcm+IVv3CDR8fEGvZse7CuhiXkxBNSHe wmf8l0ukz2loy16kprRqPMynzrApmWv94Ke9yNQ2RyDhaX6ZVcJpDU3JruNNPl74JIC4 5Svw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIWLUVZ5; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z4sor4634126pgn.15.2020.04.30.00.04.35 for (Google Transport Security); Thu, 30 Apr 2020 00:04:35 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a63:d804:: with SMTP id b4mr1938666pgh.127.1588230274920; Thu, 30 Apr 2020 00:04:34 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:34 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 3/8] clk: rk3399: Add enable/disable clks Date: Thu, 30 Apr 2020 12:34:07 +0530 Message-Id: <20200430070412.12499-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIWLUVZ5; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Yes, most of the high speed peripheral clocks in rk3399 enabled by default. But it would be better to handle them via clk enable/disable API for handling proper reset conditions like 'usb reset' over command line. So, enable USB, GMAC clock via enable/disable ops. Signed-off-by: Jagan Teki --- Changes for v2: - new patch drivers/clk/rockchip/clk_rk3399.c | 148 ++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/clk/rockchip/clk_rk3399.c b/drivers/clk/rockchip/clk_rk3399.c index d822acace1..df70e9fa88 100644 --- a/drivers/clk/rockchip/clk_rk3399.c +++ b/drivers/clk/rockchip/clk_rk3399.c @@ -1071,12 +1071,160 @@ static int __maybe_unused rk3399_clk_set_parent(struct clk *clk, return -ENOENT; } +static int rk3399_clk_enable(struct clk *clk) +{ + struct rk3399_clk_priv *priv = dev_get_priv(clk->dev); + + switch (clk->id) { + case SCLK_MAC: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(5)); + break; + case SCLK_MAC_RX: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(8)); + break; + case SCLK_MAC_TX: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(9)); + break; + case SCLK_MACREF: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(7)); + break; + case SCLK_MACREF_OUT: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(6)); + break; + case ACLK_GMAC: + rk_clrreg(&priv->cru->clkgate_con[32], BIT(0)); + break; + case PCLK_GMAC: + rk_clrreg(&priv->cru->clkgate_con[32], BIT(2)); + break; + case SCLK_USB3OTG0_REF: + rk_clrreg(&priv->cru->clksel_con[12], BIT(1)); + break; + case SCLK_USB3OTG1_REF: + rk_clrreg(&priv->cru->clksel_con[12], BIT(2)); + break; + case SCLK_USB3OTG0_SUSPEND: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(3)); + break; + case SCLK_USB3OTG1_SUSPEND: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(4)); + break; + case ACLK_USB3OTG0: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(1)); + break; + case ACLK_USB3OTG1: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(2)); + break; + case ACLK_USB3_RKSOC_AXI_PERF: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(3)); + break; + case ACLK_USB3: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(0)); + break; + case ACLK_USB3_GRF: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(4)); + break; + case HCLK_HOST0: + rk_clrreg(&priv->cru->clksel_con[20], BIT(5)); + break; + case HCLK_HOST0_ARB: + rk_clrreg(&priv->cru->clksel_con[20], BIT(6)); + break; + case HCLK_HOST1: + rk_clrreg(&priv->cru->clksel_con[20], BIT(7)); + break; + case HCLK_HOST1_ARB: + rk_clrreg(&priv->cru->clksel_con[20], BIT(8)); + break; + default: + debug("%s: unsupported clk %ld\n", __func__, clk->id); + return -ENOENT; + } + + return 0; +} + +static int rk3399_clk_disable(struct clk *clk) +{ + struct rk3399_clk_priv *priv = dev_get_priv(clk->dev); + + switch (clk->id) { + case SCLK_MAC: + rk_setreg(&priv->cru->clkgate_con[5], BIT(5)); + break; + case SCLK_MAC_RX: + rk_setreg(&priv->cru->clkgate_con[5], BIT(8)); + break; + case SCLK_MAC_TX: + rk_setreg(&priv->cru->clkgate_con[5], BIT(9)); + break; + case SCLK_MACREF: + rk_setreg(&priv->cru->clkgate_con[5], BIT(7)); + break; + case SCLK_MACREF_OUT: + rk_setreg(&priv->cru->clkgate_con[5], BIT(6)); + break; + case ACLK_GMAC: + rk_setreg(&priv->cru->clkgate_con[32], BIT(0)); + break; + case PCLK_GMAC: + rk_setreg(&priv->cru->clkgate_con[32], BIT(2)); + break; + case SCLK_USB3OTG0_REF: + rk_setreg(&priv->cru->clksel_con[12], BIT(1)); + break; + case SCLK_USB3OTG1_REF: + rk_setreg(&priv->cru->clksel_con[12], BIT(2)); + break; + case SCLK_USB3OTG0_SUSPEND: + rk_setreg(&priv->cru->clkgate_con[12], BIT(3)); + break; + case SCLK_USB3OTG1_SUSPEND: + rk_setreg(&priv->cru->clkgate_con[12], BIT(4)); + break; + case ACLK_USB3OTG0: + rk_setreg(&priv->cru->clkgate_con[30], BIT(1)); + break; + case ACLK_USB3OTG1: + rk_setreg(&priv->cru->clkgate_con[30], BIT(2)); + break; + case ACLK_USB3_RKSOC_AXI_PERF: + rk_setreg(&priv->cru->clkgate_con[30], BIT(3)); + break; + case ACLK_USB3: + rk_setreg(&priv->cru->clkgate_con[12], BIT(0)); + break; + case ACLK_USB3_GRF: + rk_setreg(&priv->cru->clkgate_con[30], BIT(4)); + break; + case HCLK_HOST0: + rk_setreg(&priv->cru->clksel_con[20], BIT(5)); + break; + case HCLK_HOST0_ARB: + rk_setreg(&priv->cru->clksel_con[20], BIT(6)); + break; + case HCLK_HOST1: + rk_setreg(&priv->cru->clksel_con[20], BIT(7)); + break; + case HCLK_HOST1_ARB: + rk_setreg(&priv->cru->clksel_con[20], BIT(8)); + break; + default: + debug("%s: unsupported clk %ld\n", __func__, clk->id); + return -ENOENT; + } + + return 0; +} + static struct clk_ops rk3399_clk_ops = { .get_rate = rk3399_clk_get_rate, .set_rate = rk3399_clk_set_rate, #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) .set_parent = rk3399_clk_set_parent, #endif + .enable = rk3399_clk_enable, + .disable = rk3399_clk_disable, }; #ifdef CONFIG_SPL_BUILD From patchwork Thu Apr 30 07:04:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1135 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id ED0673F0D3 for ; Thu, 30 Apr 2020 09:04:40 +0200 (CEST) Received: by mail-pg1-f200.google.com with SMTP id j21sf4580654pgh.12 for ; Thu, 30 Apr 2020 00:04:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230279; cv=pass; d=google.com; s=arc-20160816; b=eGgl+h9CfWX5Aa4f+Y01yeeYY99VpoUL1EueUHXri3tJftib5HJsdYDSNG4CeIbm4Q N2ComXymqV/dwsrSRq/wAi8X/QDu4VUTalS+mmmxPQAgddGGi3b0xVdU759JhXFD1qFq I8HIAuHxgvW+koDNxvPdq5ISEOsELP8bqRPslT5BV/w8/Pb/kYdYOgRmNvHiVxC/qQp6 /WKYoB8iyuJjIPa/hCTt2QOwuZl/fJdiavfwyiS5MEzDiN+V1BvCLe9EmFrkj7/AxERv gsPOzVU3xHQRuLDwKH0VUId8SDErNxh5bd5XdDOsBHuv8yxY6XhXmCV+NMShKxvIfZSc v0/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=f744WqrZmsevPButyARFnzh2/MLaFjRIuLcu+e/E6gs=; b=Q5T+7gNw2MTopaFyWP2geccVKBmbsd7V1hAwiXMiHDJ7uP1fGoxds5umzgUXHdUzVg opY8G6BGhaO8C7kI+B+2Xifr9OsTx/MvDgYLvAQIhrNvkTjL7EhrtooRX0E4aQkAy74+ XOkD7tuLyZsF+4lx9CboI2qIsfhHUwi5GTueb609LLIiLcT9TJwGj1BKBJpEfiDGpQxT hqa3eYuzc512wkUHiIjCSWcRaRQuGPqUtdDqVOKZ+oiILvbDAK9z35TvzomI9yEcPA04 a2b1FJHwdico3bdpYZOfdKXZxytZxfNLHNIHza5GRtbFxhl+fNJeX79yu7boideWIahH OtfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dOK6+5Ac; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=f744WqrZmsevPButyARFnzh2/MLaFjRIuLcu+e/E6gs=; b=DUNVxdiwryoUkMfmJk+xUzteNIwo+HypzNPrKP4aDcIaE0QTGAG8WhzWfZ/V+hw7qM YekRKmpFUAP0GfT7PouYsyr/2+pit1o6fepkjHFmwRX3XBjXWnleKRivlGCmmXTDPzPE 4DOHExSnXSrRT/2XcLBgkeB/rtSpaTHRAZIFk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=f744WqrZmsevPButyARFnzh2/MLaFjRIuLcu+e/E6gs=; b=RLqxgWR4s0EAxDlm6besBVrj6jO9MqePizvUeNYVEcBQlHKXUu3+pDnqMrY7V/VVsN 6JFmUEUPahwVbXyexbvAAJbv/SayYJoObA0KOdQBBO1eq2iBG6BciZ5vjU0f9c9eyAbE xwC/30oa5r9ZHqS6uPD061sTiCEx1Ivob9EWRS1N8fr/R6WHRCEDOaC1z1RspbZppcyJ 68ZfObuSMCBl6VUZOhfvB9KXwl8juW9MtIAyi6nBgIo/4WSsMd/lpFs7wJ1FgCCxyBS9 XQcShRCmHf8c3gaxmCgjItNHzAjA2rzDmPi1E9LHkhZbw4LoafKisRwIXwAsOdK2RlDT dp5A== X-Gm-Message-State: AGi0PuYv2XZGT2Kpr43EFDl/QCC5mi2LUjabh4EjVRJ78ZGhICU1fmjd Y/8BTfhrJ8A7R0PJ+iAaFhh5Mwqj X-Google-Smtp-Source: APiQypJTEQ7uBa6Qtk1Jij5z081zdFPo+krZnreYosEWl0oBdF8j8nwi/fFTfy6No6yjo9jbAvsPKQ== X-Received: by 2002:a17:90a:1da6:: with SMTP id v35mr1440748pjv.44.1588230279561; Thu, 30 Apr 2020 00:04:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:ff0f:: with SMTP id k15ls2443194pgi.3.gmail; Thu, 30 Apr 2020 00:04:39 -0700 (PDT) X-Received: by 2002:a63:ac43:: with SMTP id z3mr1889508pgn.324.1588230279064; Thu, 30 Apr 2020 00:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230279; cv=none; d=google.com; s=arc-20160816; b=P8wBmmQsKOdFsndiHnkfR30YW4/JJKom0FqD5J3DM5EMHnNiJjDVnP1gXUvhoKjcI7 re/+RW66RwBq7fbkpVrruKAWyYTPCrJNYwCOD+RToONic8B6CydIuK+HeUJTlijanUsR X33SX8mNsr/6fKiQCnrXFiN/L/exnH7clZojjPBwg8Qc0C5YFlZ/n9P2OSzPNbM22Grj Fli5wwXiynEZJwHc/wQfs4VUM3IF4T5yQS4ZV6XEe65QmicXIU1UxlvRFwl8AkXAIpaN bO2i1vkf5/aOulzmOUMqcvW0ZkQoeCl/jaH3EphF/cBA/JATljLDYY10nWljxzTy5575 NyHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GPV3Zk54Uc5uKzvhitTdYhJEIJtNWZE8p1htkX1ToAY=; b=gtZ2Lb6GmG6RzWQrhXsU/cohCAUomN7o3leOlVMzAnffWaye9TGM96KEuUO9abJPv3 tkToKVs9YbBCBsG1bxPLJ3xtxZceEhS2lrIQOA2cbEUejciCt6ZugCdyZLEGdgpJpDSX ewJHc8IhNZKKfTxqVEpeHlVephHYjjUTgAZfBZ8Q9FwMBhQiT38UjtLr7p3DWrvwAngV jTb3P9ggJJb5LrKeL3OiefKXn2LJL0ujHLP2IdalfefTu292vnQviklIB2qoN2pqReDG t5lYd0/7+RdANF1JzmDwHTLTR8BykMOE4yoOXLWOvc6zDxJrQG3O8GdC9ugwJm0RrCAg SPzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dOK6+5Ac; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t12sor961595pje.16.2020.04.30.00.04.39 for (Google Transport Security); Thu, 30 Apr 2020 00:04:39 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:cb86:: with SMTP id a6mr1306326pju.127.1588230278676; Thu, 30 Apr 2020 00:04:38 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:37 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 4/8] clk: rk3399: Enable/Disable the PCIEPHY clk Date: Thu, 30 Apr 2020 12:34:08 +0530 Message-Id: <20200430070412.12499-5-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dOK6+5Ac; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Enable/Disable the PCIEPHY clk for rk3399. CLK is clear in both enable and disable functionality. Signed-off-by: Jagan Teki --- Changes for v2: - clear the clk in enable drivers/clk/rockchip/clk_rk3399.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/clk/rockchip/clk_rk3399.c b/drivers/clk/rockchip/clk_rk3399.c index df70e9fa88..7feba92f9e 100644 --- a/drivers/clk/rockchip/clk_rk3399.c +++ b/drivers/clk/rockchip/clk_rk3399.c @@ -1136,6 +1136,9 @@ static int rk3399_clk_enable(struct clk *clk) case HCLK_HOST1_ARB: rk_clrreg(&priv->cru->clksel_con[20], BIT(8)); break; + case SCLK_PCIEPHY_REF: + rk_clrreg(&priv->cru->clksel_con[18], BIT(10)); + break; default: debug("%s: unsupported clk %ld\n", __func__, clk->id); return -ENOENT; @@ -1209,6 +1212,9 @@ static int rk3399_clk_disable(struct clk *clk) case HCLK_HOST1_ARB: rk_setreg(&priv->cru->clksel_con[20], BIT(8)); break; + case SCLK_PCIEPHY_REF: + rk_clrreg(&priv->cru->clksel_con[18], BIT(10)); + break; default: debug("%s: unsupported clk %ld\n", __func__, clk->id); return -ENOENT; From patchwork Thu Apr 30 07:04:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1136 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1664C3F0D3 for ; Thu, 30 Apr 2020 09:04:45 +0200 (CEST) Received: by mail-pj1-f69.google.com with SMTP id r3sf734269pjq.7 for ; Thu, 30 Apr 2020 00:04:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230284; cv=pass; d=google.com; s=arc-20160816; b=ie+EOLxFiWsQvkuHgS+R8tPLQtOvljzozuDzCA0upn53NL5/9mY7kEjmrX5KHVtRsX 5VJgnw9STN4z2IxfvKzVQUxUGoZMRl80TNoc7SUtEhPnF+GATIHHS+tDtZvZAmLAPkW8 xbqKxgQ79E2UnDcefiNF/sHTGSZJcj83+vvzKdx3jYLqh/CmIPgLJ72GwFK++bb8f1zO FJjk4i0JBxa64zPJfCvseFPjq4H2l8SBCoE4yP7yIlIqNIUPjfiTjuzAqTRoDaSOv05J 8MpEooolfLn2vLerd1W7QZ75tJiCWks1GCEQhDsB91X2xZhrsZ2RV15XXSO8lMYL8Hxm c6gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=E8+NWWDZsjoHgk9v2hQ6wzOU6XfhhwV5fsi3hIUtcoc=; b=nC8MrhPSh7czkuodmx0zYE8w8qbdEuf5QBomV499ShtiBhF5Et0jRn6sUSF3hRtw3s Jx2hZSgV+a2yHuH6841vdxHd/sBFtn99YtGBxtK6TLf+fZ1THWtkMk6eyWFJ/5hDS3ZC rF+W4uossl8klu2E9+o/g2WUewgKvz7c7CIRsscYahIDeVNf5Zhl7H2Ax5awFawxRdIR j1HkleFxkCjwDAX6ZQUWiJfzoBb4VOoMmCi9voNobT/rZxoqGqiF6qdEABg64t/m3uFP EaDS0d68m9W6yaOx6revEh4Cq7EF0lF6pSOYwrRm7jt1tcQW73jjFW4k0VeRHDXowoWs /oAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H651y+6l; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=E8+NWWDZsjoHgk9v2hQ6wzOU6XfhhwV5fsi3hIUtcoc=; b=Tt7act1y3ZECNQ+dHQojx18qx6NE+6YQaS5jdOHmVuW4c6mW5neSrZ40XQful8kyre XU3v3p+i2hYQxrEDIdw7+y0A83vp8LJPnvbjDTGlipBM9QRWVfZxWgc0ccp/sw/6WsXU jCXn/TbsGE4CIi7NQhkuvEAyQK/1aSbNoi7GM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=E8+NWWDZsjoHgk9v2hQ6wzOU6XfhhwV5fsi3hIUtcoc=; b=IRRK9mwQznb6FXYhGkNRdSp7+eDNWhN0xepx4dGA59gNl7/CqbgmDmQBv0ldJ4bUvb 4n3QFZ9CsL1IPpuljpzNNkFGP4ZadlcPCQCq8+Gb+brpnUkg0Re5TpBmBgbHpbMgfaSd iWSpNA6QhbF73DnpDj5f/1uEvjBknYo2speA1ayQKrj1gecv1zYriTTTWv1WSJ3sTjYY TYtqCDM8X6NJjaztmBt1aLlAKyjL7DWQc59WrDlehjJ5zDmovlycYFBBdy+G7W7IUl5G nqz5XZdFfmMwNSP4nM1xgKdKZAsO1gQp5ZiDbfvkCbmwy9hPUYHsyVi5tVk3wRCYxbBQ YGoQ== X-Gm-Message-State: AGi0PuYtf5R0OdiPWpC7CuQ7bw4lr1acWJyxrD+9oD5RonOV/27WRg1c E21re0Ny/mEpluiO/gpYeOxie8JH X-Google-Smtp-Source: APiQypLvX9VRnuUlOD+/WBz8fv7QkfthWuLRpfykS9wLQlxDX5R6JxKoAY//vvscFquSyJxh1ZFDRA== X-Received: by 2002:a62:1bc5:: with SMTP id b188mr2112551pfb.113.1588230283744; Thu, 30 Apr 2020 00:04:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:a701:: with SMTP id w1ls3101403plq.7.gmail; Thu, 30 Apr 2020 00:04:43 -0700 (PDT) X-Received: by 2002:a17:902:8608:: with SMTP id f8mr2330667plo.110.1588230283188; Thu, 30 Apr 2020 00:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230283; cv=none; d=google.com; s=arc-20160816; b=iJus/8K4qNl18iM+MFVDyfKdMuGzmQg5IZzQAumh20sedCxfTGHJb5tFXGcP0qblmS AH7xaPbax1vuDNs+WLyTDRYkp075Ro0OT/X23M3H7Aq+B3Q4doJ4kEl4VCGWNieYocgn sO9cuzr+pIyxtOR8reIoDJP74tnn0/VbC1DrVbvhKXnf6S75uEZ+GtFjzI45URhpWF8a g1rV8beGRiRviogdO64vCFmpk9Mox98BuTj21l4DFomL3SxaDQ5DurWYKAIsxyBq5vle 6qoe/Xd8C5Fxp0TIHl6pWl4GWdwc0heSqLL33unwAOfo/CpCs1UCckODPsCDwkqaEWmG XGFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qZLcgIkw6VsaZbMb9f7Jqm6DueQwtF2lpr91eQGAzIg=; b=F32UNLfnKSp7+QLTVZh0Q4oRW0VNNLQ9HxvLX7ivdcTz5cTyoS8OG5kJegESqBTUEr yjTJLA+xpkZryOQmAy/h+OTKmCvtW/Wx7D6AjSnd9wzInX8sFmWc5uvYBy1YYHrzQ2Mp 4kKoL0TzvcMXATRKZ+FXKhwNWsdHGi3jHgkBgVDfffIhaI4uHaaZhKOaqiwsv7xObJod NnMvqHEwe6OSCoTbd3oLBWQy6F7+VS6C6HQo8pHdZYLipVjLZwVWlsjWVPKMhRkeqGNa kl1xQMGztaNdlA4t0St/1tvjgtB/NhxE3x8Wj5eYUroa3I1G+eD3Bmz1y66TrX4TgW+S 5RhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H651y+6l; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c3sor4621312pfi.4.2020.04.30.00.04.43 for (Google Transport Security); Thu, 30 Apr 2020 00:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a63:fb14:: with SMTP id o20mr1980204pgh.144.1588230282614; Thu, 30 Apr 2020 00:04:42 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:41 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 5/8] pci: Add Rockchip PCIe controller driver Date: Thu, 30 Apr 2020 12:34:09 +0530 Message-Id: <20200430070412.12499-6-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H651y+6l; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add Rockchip PCIe controller driver for rk3399 platform. Driver support Gen1 by operating as a Root complex. Thanks to Patrick for initial work. Signed-off-by: Patrick Wildt Signed-off-by: Jagan Teki Reviewed-by: Kever Yang --- Changes for v2: - simplify bdf in rd_conf, wr_conf - collect kever r-o-b drivers/pci/Kconfig | 8 + drivers/pci/Makefile | 1 + drivers/pci/pcie_rockchip.c | 467 ++++++++++++++++++++++++++++++++++++ drivers/pci/pcie_rockchip.h | 79 ++++++ 4 files changed, 555 insertions(+) create mode 100644 drivers/pci/pcie_rockchip.c create mode 100644 drivers/pci/pcie_rockchip.h diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 437cd9a055..3dba84103b 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -197,4 +197,12 @@ config PCIE_MEDIATEK Say Y here if you want to enable Gen2 PCIe controller, which could be found on MT7623 SoC family. +config PCIE_ROCKCHIP + bool "Enable Rockchip PCIe driver" + select DM_PCI + default y if ROCKCHIP_RK3399 + help + Say Y here if you want to enable PCIe controller support on + Rockchip SoCs. + endif diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index c051ecc9f3..493e9354dd 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -43,3 +43,4 @@ obj-$(CONFIG_PCI_PHYTIUM) += pcie_phytium.o obj-$(CONFIG_PCIE_INTEL_FPGA) += pcie_intel_fpga.o obj-$(CONFIG_PCI_KEYSTONE) += pcie_dw_ti.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie_mediatek.o +obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o diff --git a/drivers/pci/pcie_rockchip.c b/drivers/pci/pcie_rockchip.c new file mode 100644 index 0000000000..3f06f783ca --- /dev/null +++ b/drivers/pci/pcie_rockchip.c @@ -0,0 +1,467 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Rockchip AXI PCIe host controller driver + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + * Copyright (c) 2020 Jagan Teki + * Copyright (c) 2019 Patrick Wildt + * Copyright (c) 2018 Mark Kettenis + * + * Bits taken from Linux Rockchip PCIe host controller. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie_rockchip.h" + +DECLARE_GLOBAL_DATA_PTR; + +static int rockchip_pcie_off_conf(pci_dev_t bdf, uint offset) +{ + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + unsigned int func = PCI_FUNC(bdf); + + return (bus << 20) | (dev << 15) | (func << 12) | (offset & ~0x3); +} + +static int rockchip_pcie_rd_conf(const struct udevice *udev, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) +{ + struct rockchip_pcie *priv = dev_get_priv(udev); + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + int where = rockchip_pcie_off_conf(bdf, offset); + ulong value; + + if (bus == priv->first_busno && dev == 0) { + value = readl(priv->apb_base + PCIE_RC_NORMAL_BASE + where); + *valuep = pci_conv_32_to_size(value, offset, size); + return 0; + } + + if ((bus == priv->first_busno + 1) && dev == 0) { + value = readl(priv->axi_base + where); + *valuep = pci_conv_32_to_size(value, offset, size); + return 0; + } + + *valuep = pci_get_ff(size); + + return 0; +} + +static int rockchip_pcie_wr_conf(struct udevice *udev, pci_dev_t bdf, + uint offset, ulong value, + enum pci_size_t size) +{ + struct rockchip_pcie *priv = dev_get_priv(udev); + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + int where = rockchip_pcie_off_conf(bdf, offset); + ulong old; + + if (bus == priv->first_busno && dev == 0) { + old = readl(priv->apb_base + PCIE_RC_NORMAL_BASE + where); + value = pci_conv_size_to_32(old, value, offset, size); + writel(value, priv->apb_base + PCIE_RC_NORMAL_BASE + where); + return 0; + } + + if ((bus == priv->first_busno + 1) && dev == 0) { + old = readl(priv->axi_base + where); + value = pci_conv_size_to_32(old, value, offset, size); + writel(value, priv->axi_base + where); + return 0; + } + + return 0; +} + +static int rockchip_pcie_atr_init(struct rockchip_pcie *priv) +{ + struct udevice *ctlr = pci_get_controller(priv->dev); + struct pci_controller *hose = dev_get_uclass_priv(ctlr); + u64 addr, size, offset; + u32 type; + int i, region; + + /* Use region 0 to map PCI configuration space. */ + writel(25 - 1, priv->apb_base + PCIE_ATR_OB_ADDR0(0)); + writel(0, priv->apb_base + PCIE_ATR_OB_ADDR1(0)); + writel(PCIE_ATR_HDR_CFG_TYPE0 | PCIE_ATR_HDR_RID, + priv->apb_base + PCIE_ATR_OB_DESC0(0)); + writel(0, priv->apb_base + PCIE_ATR_OB_DESC1(0)); + + for (i = 0; i < hose->region_count; i++) { + if (hose->regions[i].flags == PCI_REGION_SYS_MEMORY) + continue; + + if (hose->regions[i].flags == PCI_REGION_IO) + type = PCIE_ATR_HDR_IO; + else + type = PCIE_ATR_HDR_MEM; + + /* Only support identity mappings. */ + if (hose->regions[i].bus_start != + hose->regions[i].phys_start) + return -EINVAL; + + /* Only support mappings aligned on a region boundary. */ + addr = hose->regions[i].bus_start; + if (addr & (PCIE_ATR_OB_REGION_SIZE - 1)) + return -EINVAL; + + /* Mappings should lie between AXI and APB regions. */ + size = hose->regions[i].size; + if (addr < (u64)priv->axi_base + PCIE_ATR_OB_REGION0_SIZE) + return -EINVAL; + if (addr + size > (u64)priv->apb_base) + return -EINVAL; + + offset = addr - (u64)priv->axi_base - PCIE_ATR_OB_REGION0_SIZE; + region = 1 + (offset / PCIE_ATR_OB_REGION_SIZE); + while (size > 0) { + writel(32 - 1, + priv->apb_base + PCIE_ATR_OB_ADDR0(region)); + writel(0, priv->apb_base + PCIE_ATR_OB_ADDR1(region)); + writel(type | PCIE_ATR_HDR_RID, + priv->apb_base + PCIE_ATR_OB_DESC0(region)); + writel(0, priv->apb_base + PCIE_ATR_OB_DESC1(region)); + + addr += PCIE_ATR_OB_REGION_SIZE; + size -= PCIE_ATR_OB_REGION_SIZE; + region++; + } + } + + /* Passthrough inbound translations unmodified. */ + writel(32 - 1, priv->apb_base + PCIE_ATR_IB_ADDR0(2)); + writel(0, priv->apb_base + PCIE_ATR_IB_ADDR1(2)); + + return 0; +} + +static int rockchip_pcie_init_port(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + u32 cr, val, status; + int ret; + + if (dm_gpio_is_valid(&priv->ep_gpio)) + dm_gpio_set_value(&priv->ep_gpio, 0); + + ret = reset_assert(&priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to assert aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to assert pclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->pm_rst); + if (ret) { + dev_err(dev, "failed to assert pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->core_rst); + if (ret) { + dev_err(dev, "failed to assert core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to assert mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to assert mgmt-sticky reset (ret=%d)\n", + ret); + return ret; + } + + ret = reset_assert(&priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to assert pipe reset (ret=%d)\n", ret); + return ret; + } + + udelay(10); + + ret = reset_deassert(&priv->pm_rst); + if (ret) { + dev_err(dev, "failed to deassert pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to deassert aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to deassert pclk reset (ret=%d)\n", ret); + return ret; + } + + /* Select GEN1 for now */ + cr = PCIE_CLIENT_GEN_SEL_1; + /* Set Root complex mode */ + cr |= PCIE_CLIENT_CONF_ENABLE | PCIE_CLIENT_MODE_RC; + writel(cr, priv->apb_base + PCIE_CLIENT_CONFIG); + + ret = reset_deassert(&priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to deassert mgmt-sticky reset (ret=%d)\n", + ret); + return ret; + } + + ret = reset_deassert(&priv->core_rst); + if (ret) { + dev_err(dev, "failed to deassert core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to deassert mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to deassert pipe reset (ret=%d)\n", ret); + return ret; + } + + /* Enable Gen1 training */ + writel(PCIE_CLIENT_LINK_TRAIN_ENABLE, + priv->apb_base + PCIE_CLIENT_CONFIG); + + if (dm_gpio_is_valid(&priv->ep_gpio)) + dm_gpio_set_value(&priv->ep_gpio, 1); + + ret = readl_poll_sleep_timeout + (priv->apb_base + PCIE_CLIENT_BASIC_STATUS1, + status, PCIE_LINK_UP(status), 20, 500 * 1000); + if (ret) { + dev_err(dev, "PCIe link training gen1 timeout!\n"); + return ret; + } + + /* Initialize Root Complex registers. */ + writel(PCIE_LM_VENDOR_ROCKCHIP, priv->apb_base + PCIE_LM_VENDOR_ID); + writel(PCI_CLASS_BRIDGE_PCI << 16, + priv->apb_base + PCIE_RC_BASE + PCI_CLASS_REVISION); + writel(PCIE_LM_RCBARPIE | PCIE_LM_RCBARPIS, + priv->apb_base + PCIE_LM_RCBAR); + + if (dev_read_bool(dev, "aspm-no-l0s")) { + val = readl(priv->apb_base + PCIE_RC_PCIE_LCAP); + val &= ~PCIE_RC_PCIE_LCAP_APMS_L0S; + writel(val, priv->apb_base + PCIE_RC_PCIE_LCAP); + } + + /* Configure Address Translation. */ + ret = rockchip_pcie_atr_init(priv); + if (ret) { + dev_err(dev, "PCIE-%d: ATR init failed\n", dev->seq); + return ret; + } + + return 0; +} + +static int rockchip_pcie_set_vpcie(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + int ret; + + if (!IS_ERR(priv->vpcie3v3)) { + ret = regulator_set_enable(priv->vpcie3v3, true); + if (ret) { + dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", + ret); + return ret; + } + } + + ret = regulator_set_enable(priv->vpcie1v8, true); + if (ret) { + dev_err(dev, "failed to enable vpcie1v8 (ret=%d)\n", ret); + goto err_disable_3v3; + } + + ret = regulator_set_enable(priv->vpcie0v9, true); + if (ret) { + dev_err(dev, "failed to enable vpcie0v9 (ret=%d)\n", ret); + goto err_disable_1v8; + } + + return 0; + +err_disable_1v8: + regulator_set_enable(priv->vpcie1v8, false); +err_disable_3v3: + if (!IS_ERR(priv->vpcie3v3)) + regulator_set_enable(priv->vpcie3v3, false); + return ret; +} + +static int rockchip_pcie_parse_dt(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + int ret; + + priv->axi_base = dev_read_addr_name(dev, "axi-base"); + if (!priv->axi_base) + return -ENODEV; + + priv->apb_base = dev_read_addr_name(dev, "apb-base"); + if (!priv->axi_base) + return -ENODEV; + + ret = gpio_request_by_name(dev, "ep-gpios", 0, + &priv->ep_gpio, GPIOD_IS_OUT); + if (ret) { + dev_err(dev, "failed to find ep-gpios property\n"); + return ret; + } + + ret = reset_get_by_name(dev, "core", &priv->core_rst); + if (ret) { + dev_err(dev, "failed to get core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "mgmt", &priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to get mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "mgmt-sticky", &priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to get mgmt-sticky reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pipe", &priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to get pipe reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pm", &priv->pm_rst); + if (ret) { + dev_err(dev, "failed to get pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pclk", &priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to get pclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "aclk", &priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to get aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie3v3-supply", + &priv->vpcie3v3); + if (ret && ret != -ENOENT) { + dev_err(dev, "failed to get vpcie3v3 supply (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie1v8-supply", + &priv->vpcie1v8); + if (ret) { + dev_err(dev, "failed to get vpcie1v8 supply (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie0v9-supply", + &priv->vpcie0v9); + if (ret) { + dev_err(dev, "failed to get vpcie0v9 supply (ret=%d)\n", ret); + return ret; + } + + return 0; +} + +static int rockchip_pcie_probe(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + struct udevice *ctlr = pci_get_controller(dev); + struct pci_controller *hose = dev_get_uclass_priv(ctlr); + int ret; + + priv->first_busno = dev->seq; + priv->dev = dev; + + ret = rockchip_pcie_parse_dt(dev); + if (ret) + return ret; + + ret = rockchip_pcie_set_vpcie(dev); + if (ret) + return ret; + + ret = rockchip_pcie_init_port(dev); + if (ret) + return ret; + + dev_info(dev, "PCIE-%d: Link up (Bus%d)\n", + dev->seq, hose->first_busno); + + return 0; +} + +static const struct dm_pci_ops rockchip_pcie_ops = { + .read_config = rockchip_pcie_rd_conf, + .write_config = rockchip_pcie_wr_conf, +}; + +static const struct udevice_id rockchip_pcie_ids[] = { + { .compatible = "rockchip,rk3399-pcie" }, + { } +}; + +U_BOOT_DRIVER(rockchip_pcie) = { + .name = "rockchip_pcie", + .id = UCLASS_PCI, + .of_match = rockchip_pcie_ids, + .ops = &rockchip_pcie_ops, + .probe = rockchip_pcie_probe, + .priv_auto_alloc_size = sizeof(struct rockchip_pcie), +}; diff --git a/drivers/pci/pcie_rockchip.h b/drivers/pci/pcie_rockchip.h new file mode 100644 index 0000000000..6ded5c9553 --- /dev/null +++ b/drivers/pci/pcie_rockchip.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Rockchip PCIe Headers + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + * Copyright (c) 2020 Jagan Teki + * Copyright (c) 2019 Patrick Wildt + * + */ + +#define HIWORD_UPDATE(mask, val) (((mask) << 16) | (val)) +#define HIWORD_UPDATE_BIT(val) HIWORD_UPDATE(val, val) + +#define ENCODE_LANES(x) ((((x) >> 1) & 3) << 4) +#define PCIE_CLIENT_BASE 0x0 +#define PCIE_CLIENT_CONFIG (PCIE_CLIENT_BASE + 0x00) +#define PCIE_CLIENT_CONF_ENABLE HIWORD_UPDATE_BIT(0x0001) +#define PCIE_CLIENT_LINK_TRAIN_ENABLE HIWORD_UPDATE_BIT(0x0002) +#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040) +#define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0) +#define PCIE_CLIENT_BASIC_STATUS1 0x0048 +#define PCIE_CLIENT_LINK_STATUS_UP GENMASK(21, 20) +#define PCIE_CLIENT_LINK_STATUS_MASK GENMASK(21, 20) +#define PCIE_LINK_UP(x) \ + (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP) +#define PCIE_RC_NORMAL_BASE 0x800000 +#define PCIE_LM_BASE 0x900000 +#define PCIE_LM_VENDOR_ID (PCIE_LM_BASE + 0x44) +#define PCIE_LM_VENDOR_ROCKCHIP 0x1d87 +#define PCIE_LM_RCBAR (PCIE_LM_BASE + 0x300) +#define PCIE_LM_RCBARPIE BIT(19) +#define PCIE_LM_RCBARPIS BIT(20) +#define PCIE_RC_BASE 0xa00000 +#define PCIE_RC_CONFIG_DCR (PCIE_RC_BASE + 0x0c4) +#define PCIE_RC_CONFIG_DCR_CSPL_SHIFT 18 +#define PCIE_RC_CONFIG_DCR_CPLS_SHIFT 26 +#define PCIE_RC_PCIE_LCAP (PCIE_RC_BASE + 0x0cc) +#define PCIE_RC_PCIE_LCAP_APMS_L0S BIT(10) +#define PCIE_ATR_BASE 0xc00000 +#define PCIE_ATR_OB_ADDR0(i) (PCIE_ATR_BASE + 0x000 + (i) * 0x20) +#define PCIE_ATR_OB_ADDR1(i) (PCIE_ATR_BASE + 0x004 + (i) * 0x20) +#define PCIE_ATR_OB_DESC0(i) (PCIE_ATR_BASE + 0x008 + (i) * 0x20) +#define PCIE_ATR_OB_DESC1(i) (PCIE_ATR_BASE + 0x00c + (i) * 0x20) +#define PCIE_ATR_IB_ADDR0(i) (PCIE_ATR_BASE + 0x800 + (i) * 0x8) +#define PCIE_ATR_IB_ADDR1(i) (PCIE_ATR_BASE + 0x804 + (i) * 0x8) +#define PCIE_ATR_HDR_MEM 0x2 +#define PCIE_ATR_HDR_IO 0x6 +#define PCIE_ATR_HDR_CFG_TYPE0 0xa +#define PCIE_ATR_HDR_CFG_TYPE1 0xb +#define PCIE_ATR_HDR_RID BIT(23) + +#define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024) +#define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024) + +struct rockchip_pcie { + fdt_addr_t axi_base; + fdt_addr_t apb_base; + int first_busno; + struct udevice *dev; + + /* resets */ + struct reset_ctl core_rst; + struct reset_ctl mgmt_rst; + struct reset_ctl mgmt_sticky_rst; + struct reset_ctl pipe_rst; + struct reset_ctl pm_rst; + struct reset_ctl pclk_rst; + struct reset_ctl aclk_rst; + + /* gpio */ + struct gpio_desc ep_gpio; + + /* vpcie regulators */ + struct udevice *vpcie12v; + struct udevice *vpcie3v3; + struct udevice *vpcie1v8; + struct udevice *vpcie0v9; +}; From patchwork Thu Apr 30 07:04:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1137 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id EE93B3F0D3 for ; Thu, 30 Apr 2020 09:04:48 +0200 (CEST) Received: by mail-io1-f72.google.com with SMTP id m16sf405515ion.3 for ; Thu, 30 Apr 2020 00:04:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230287; cv=pass; d=google.com; s=arc-20160816; b=H5PL7o63/+3Kf4yxdTSQt0EJXJQV1yScfGo+EpbeT1KHxIc6fCCI0oBmgOhJtp41mE MZ+PZCXGQpQ2WUX6WIQNe0tT5yCauDtEoBSkiHhH2VxObvCloBTzeeH6kdldl/2apUX4 7HyCd9gLSh4GbvchfRH6vDrJlJZzb3haiCdXRNjeLZ5nASWUf78Y3RUbQOQfx4h7r2rK Cc0OI/hgijQCcA2a1t7VvcHywjyjiIec4D1+AnNjxpRQNf5O/vEoXjFfMw/jvK2a08i0 y0ynVNr1CKFrZlviQf+PJ04m4SAjausCLuRNUGi82bjtRU1K1oXesOndoZhjuK77Hjeu kYpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=/4NNTQNy/tJoPzQ6s0K3LR2BM7gp9CrMFq0Bikuasqg=; b=L2VcWncvnoAXQocPXkFll2/36lsRtEcnxfNsasQHW8FzPsVpS0zlUdH6maJyA2fFsk RDOX/0vMroj18dGwkEEGQCcWhARNtVd7Iqz8quizPUpMZbHB7UsW2X2PW2Ek/5Om25jM Pornv+QiK3r15kDkPTKbpb8cPO5gMkupiyFjtC1YwsfhxQGD8VZ6aRf2OnIEm9Nro1gL 1kM3DvbT/8DyYx4Eut+HnxnteGfkhIY/tutM0eJgdIa6wIdlX7egMUiM7b6wMwh6tUX1 tD8kAePeLjFEOMa5DqTgL38KnMnlBjC+6ULfgW2pIFe26sA8ihIgKVMjRr+MnzYoPAWV knGg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="jEg/dqfc"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=/4NNTQNy/tJoPzQ6s0K3LR2BM7gp9CrMFq0Bikuasqg=; b=P3Y+qal9r0bFqqmZ+bp7X4XhQhhpgL4UGWPjrrTPiLbliorbbeYeL4CNr91x5ZRSa3 tZ3Ny0XDNVwxyL/eFi3NuMpT76Nj7lKbbNyodsGFnt6D3pr13mCTuLCWMj8fj+m0/5te uUm4tvRnplt3FWeWFou6L7T8LhA+O8hmEcBDQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=/4NNTQNy/tJoPzQ6s0K3LR2BM7gp9CrMFq0Bikuasqg=; b=QP4j/DoY7MC1HhJyE9nYTVOk4GmILaW19YZvt9gxhbWd7xmwujf8KICnnHJ43ld8Zl xGjw/qhce9mjgqt8CaWGXKyUUD0K8KwXpKvbkpytycU6IW8Jwy6FHVvqQbNxksQPYnU1 ypueB7ngPwz1VVynNViiaq9q8t5Sp+EVanWFqEJ069/3LBSjCUxeSQi+/9NYfJpygG/g 75x9WpCy3Kir0T3pI/RU4zc/TCtXESJ/qdg6STiYsAonIpVQb50zR58in1Sgp/XB+Gc8 YevoQuwIU8HuIgqRj+TW60tWC0a0DhdF+QD8kYrxTHH2sAmIxhKtHUuaG3h+9DuK709F L7EA== X-Gm-Message-State: AGi0Puaheu8inyDrrWyWiDGTRtOkIbYw5Bbr/5XuGiPm3b26W566eI9z lmooxti1s1s0UxNHrsuh+ge1A0n8 X-Google-Smtp-Source: APiQypKeC8Yq2ccJt0/xDn1KpuvD5EjWGIeK+yhdhL/xkTVUAYn+br9TC7Wy5ZAPBp8u+Mw62NfDZQ== X-Received: by 2002:a6b:9346:: with SMTP id v67mr517393iod.154.1588230287417; Thu, 30 Apr 2020 00:04:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:8b14:: with SMTP id k20ls566695ion.11.gmail; Thu, 30 Apr 2020 00:04:47 -0700 (PDT) X-Received: by 2002:a5d:8c81:: with SMTP id g1mr489700ion.197.1588230286833; Thu, 30 Apr 2020 00:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230286; cv=none; d=google.com; s=arc-20160816; b=kcFZ4vN2hHEdJ7ECFnEJSmJO/+dFX7g8cQ8qbWDLgYAzULBo01tnTKFes61CMFXevp KJCnc7A/NSwIZGUyr4HxdLmHTPcj3yT/SoturmcZ6guR8uiP0JPdpDguVJh25kr0aCKi 51ROO5Uv6jzIfbqMn3TrCSG09dMY9eSw8pEHud+RvQudy07t7dq9ZdE6/4zusHoaA7E/ Qvy/3SmBC2VBbdzALcqDXBjpNrDmbOrFuqNRhZig2YYVNwjwfDXy2d4ip7jFKbyfRz+5 j7DJkWZqonEc3hMnYLCTDYBP5fHbDWm8qCM/BVAVbGn4vkyJz5GCz+z74JG+d777a7oi UBHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3PB9/Lxxz+cGsJU2T8MQ9IuyfeIW6USBPT5PntpYvig=; b=CwgTc1DHSbZWPKquGcrWw/i7xL7nF6fXpyZCvp4ndTyw7obZlk9RiP46XZomLV38ms iUwrVbsa83br3mYfdR4puff4J87L9ELfMNSNb26tzZngLwjb1CfkxmITB3Kfj7SpdbiX LkS5W9rMjI/RaxrsAYJGDeoCxIjJ7FiDa4sRFQG4c1m+nvDpqNwxwppg8wj3nHGKIypS WR6J8ZabP2eRpaWuU+klJcqUZLJhz/wyif5b5ItKf61w6/ikhdMzU1wbmwY6QJvvGh9p eocCNHqCsdGTU8PFj9+n2eJJTs15JRUpXeFRPQ3Wu4qfmimnzBxdmCpytBeXvoYRgVWp GvuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="jEg/dqfc"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i90sor4628695ill.123.2020.04.30.00.04.46 for (Google Transport Security); Thu, 30 Apr 2020 00:04:46 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr2242229plr.223.1588230286374; Thu, 30 Apr 2020 00:04:46 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:45 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 6/8] pci: Add Rockchip PCIe PHY controller driver Date: Thu, 30 Apr 2020 12:34:10 +0530 Message-Id: <20200430070412.12499-7-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="jEg/dqfc"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Yes, it is possible to have a dedicated UCLASS PHY driver for this Rockchip PCIe PHY but there are some issues on Generic PHY framework to support the same. The Generic PHY framework is unable to get the PHY if the PHY parent is of a different uclass. Say if we try to get the PCIe PHY then the phy-uclass will look for PHY in the first instance if it is not in the root node it will try to probe the parent by assuming that the actual PHY is inside the parent PHY of UCLASS_PHY. But, in rk3399 hardware representation PHY like emmc, usb and pcie are part of syscon which is completely a different of UCLASS_SYSCON. Example: grf: syscon@ff770000 { compatible = "rockchip,rk3399-grf", "syscon", "simple-mfd"; reg = <0x0 0xff770000 0x0 0x10000>; #address-cells = <1>; #size-cells = <1>; pcie_phy: pcie-phy { compatible = "rockchip,rk3399-pcie-phy"; clocks = <&cru SCLK_PCIEPHY_REF>; clock-names = "refclk"; #phy-cells = <1>; resets = <&cru SRST_PCIEPHY>; drive-impedance-ohm = <50>; reset-names = "phy"; status = "disabled"; }; }; Due to this limitation, this patch adds a separate PHY driver for Rockchip PCIe. This might be removed in future once Generic PHY supports this limitation. Signed-off-by: Jagan Teki --- Changes for v2: - none drivers/pci/Makefile | 2 +- drivers/pci/pcie_rockchip.c | 50 ++++++-- drivers/pci/pcie_rockchip.h | 63 ++++++++++ drivers/pci/pcie_rockchip_phy.c | 205 ++++++++++++++++++++++++++++++++ 4 files changed, 306 insertions(+), 14 deletions(-) create mode 100644 drivers/pci/pcie_rockchip_phy.c diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 493e9354dd..955351c5c2 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -43,4 +43,4 @@ obj-$(CONFIG_PCI_PHYTIUM) += pcie_phytium.o obj-$(CONFIG_PCIE_INTEL_FPGA) += pcie_intel_fpga.o obj-$(CONFIG_PCI_KEYSTONE) += pcie_dw_ti.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie_mediatek.o -obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o +obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o pcie_rockchip_phy.o diff --git a/drivers/pci/pcie_rockchip.c b/drivers/pci/pcie_rockchip.c index 3f06f783ca..82a8396e42 100644 --- a/drivers/pci/pcie_rockchip.c +++ b/drivers/pci/pcie_rockchip.c @@ -159,6 +159,8 @@ static int rockchip_pcie_atr_init(struct rockchip_pcie *priv) static int rockchip_pcie_init_port(struct udevice *dev) { struct rockchip_pcie *priv = dev_get_priv(dev); + struct rockchip_pcie_phy *phy = pcie_get_phy(priv); + struct rockchip_pcie_phy_ops *ops = phy_get_ops(phy); u32 cr, val, status; int ret; @@ -183,29 +185,35 @@ static int rockchip_pcie_init_port(struct udevice *dev) return ret; } + ret = ops->init(phy); + if (ret) { + dev_err(dev, "failed to init phy (ret=%d)\n", ret); + goto err_exit_phy; + } + ret = reset_assert(&priv->core_rst); if (ret) { dev_err(dev, "failed to assert core reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->mgmt_rst); if (ret) { dev_err(dev, "failed to assert mgmt reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->mgmt_sticky_rst); if (ret) { dev_err(dev, "failed to assert mgmt-sticky reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->pipe_rst); if (ret) { dev_err(dev, "failed to assert pipe reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } udelay(10); @@ -213,19 +221,19 @@ static int rockchip_pcie_init_port(struct udevice *dev) ret = reset_deassert(&priv->pm_rst); if (ret) { dev_err(dev, "failed to deassert pm reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_deassert(&priv->aclk_rst); if (ret) { dev_err(dev, "failed to deassert aclk reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_deassert(&priv->pclk_rst); if (ret) { dev_err(dev, "failed to deassert pclk reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } /* Select GEN1 for now */ @@ -234,29 +242,35 @@ static int rockchip_pcie_init_port(struct udevice *dev) cr |= PCIE_CLIENT_CONF_ENABLE | PCIE_CLIENT_MODE_RC; writel(cr, priv->apb_base + PCIE_CLIENT_CONFIG); + ret = ops->power_on(phy); + if (ret) { + dev_err(dev, "failed to power on phy (ret=%d)\n", ret); + goto err_power_off_phy; + } + ret = reset_deassert(&priv->mgmt_sticky_rst); if (ret) { dev_err(dev, "failed to deassert mgmt-sticky reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->core_rst); if (ret) { dev_err(dev, "failed to deassert core reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->mgmt_rst); if (ret) { dev_err(dev, "failed to deassert mgmt reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->pipe_rst); if (ret) { dev_err(dev, "failed to deassert pipe reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } /* Enable Gen1 training */ @@ -271,7 +285,7 @@ static int rockchip_pcie_init_port(struct udevice *dev) status, PCIE_LINK_UP(status), 20, 500 * 1000); if (ret) { dev_err(dev, "PCIe link training gen1 timeout!\n"); - return ret; + goto err_power_off_phy; } /* Initialize Root Complex registers. */ @@ -291,10 +305,16 @@ static int rockchip_pcie_init_port(struct udevice *dev) ret = rockchip_pcie_atr_init(priv); if (ret) { dev_err(dev, "PCIE-%d: ATR init failed\n", dev->seq); - return ret; + goto err_power_off_phy; } return 0; + +err_power_off_phy: + ops->power_off(phy); +err_exit_phy: + ops->exit(phy); + return ret; } static int rockchip_pcie_set_vpcie(struct udevice *dev) @@ -433,6 +453,10 @@ static int rockchip_pcie_probe(struct udevice *dev) if (ret) return ret; + ret = rockchip_pcie_phy_get(dev); + if (ret) + return ret; + ret = rockchip_pcie_set_vpcie(dev); if (ret) return ret; diff --git a/drivers/pci/pcie_rockchip.h b/drivers/pci/pcie_rockchip.h index 6ded5c9553..c3a0a2846d 100644 --- a/drivers/pci/pcie_rockchip.h +++ b/drivers/pci/pcie_rockchip.h @@ -53,11 +53,61 @@ #define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024) #define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024) +/* + * The higher 16-bit of this register is used for write protection + * only if BIT(x + 16) set to 1 the BIT(x) can be written. + */ +#define HIWORD_UPDATE_MASK(val, mask, shift) \ + ((val) << (shift) | (mask) << ((shift) + 16)) + +#define PHY_CFG_DATA_SHIFT 7 +#define PHY_CFG_ADDR_SHIFT 1 +#define PHY_CFG_DATA_MASK 0xf +#define PHY_CFG_ADDR_MASK 0x3f +#define PHY_CFG_RD_MASK 0x3ff +#define PHY_CFG_WR_ENABLE 1 +#define PHY_CFG_WR_DISABLE 1 +#define PHY_CFG_WR_SHIFT 0 +#define PHY_CFG_WR_MASK 1 +#define PHY_CFG_PLL_LOCK 0x10 +#define PHY_CFG_CLK_TEST 0x10 +#define PHY_CFG_CLK_SCC 0x12 +#define PHY_CFG_SEPE_RATE BIT(3) +#define PHY_CFG_PLL_100M BIT(3) +#define PHY_PLL_LOCKED BIT(9) +#define PHY_PLL_OUTPUT BIT(10) +#define PHY_LANE_IDLE_OFF 0x1 +#define PHY_LANE_IDLE_MASK 0x1 +#define PHY_LANE_IDLE_A_SHIFT 3 +#define PHY_LANE_IDLE_B_SHIFT 4 +#define PHY_LANE_IDLE_C_SHIFT 5 +#define PHY_LANE_IDLE_D_SHIFT 6 + +#define PCIE_PHY_CONF 0xe220 +#define PCIE_PHY_STATUS 0xe2a4 +#define PCIE_PHY_LANEOFF 0xe214 + +struct rockchip_pcie_phy { + void *reg_base; + struct clk refclk; + struct reset_ctl phy_rst; + struct rockchip_pcie_phy_ops *ops; +}; + +struct rockchip_pcie_phy_ops { + int (*init)(struct rockchip_pcie_phy *phy); + int (*exit)(struct rockchip_pcie_phy *phy); + int (*power_on)(struct rockchip_pcie_phy *phy); + int (*power_off)(struct rockchip_pcie_phy *phy); +}; + struct rockchip_pcie { fdt_addr_t axi_base; fdt_addr_t apb_base; int first_busno; struct udevice *dev; + struct rockchip_pcie_phy rk_phy; + struct rockchip_pcie_phy *phy; /* resets */ struct reset_ctl core_rst; @@ -77,3 +127,16 @@ struct rockchip_pcie { struct udevice *vpcie1v8; struct udevice *vpcie0v9; }; + +int rockchip_pcie_phy_get(struct udevice *dev); + +inline struct rockchip_pcie_phy *pcie_get_phy(struct rockchip_pcie *pcie) +{ + return pcie->phy; +} + +inline +struct rockchip_pcie_phy_ops *phy_get_ops(struct rockchip_pcie_phy *phy) +{ + return (struct rockchip_pcie_phy_ops *)phy->ops; +} diff --git a/drivers/pci/pcie_rockchip_phy.c b/drivers/pci/pcie_rockchip_phy.c new file mode 100644 index 0000000000..47f5d6c7e3 --- /dev/null +++ b/drivers/pci/pcie_rockchip_phy.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Rockchip PCIe PHY driver + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie_rockchip.h" + +DECLARE_GLOBAL_DATA_PTR; + +static void phy_wr_cfg(struct rockchip_pcie_phy *phy, u32 addr, u32 data) +{ + u32 reg; + + reg = HIWORD_UPDATE_MASK(data, PHY_CFG_DATA_MASK, PHY_CFG_DATA_SHIFT); + reg |= HIWORD_UPDATE_MASK(addr, PHY_CFG_ADDR_MASK, PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + udelay(1); + + reg = HIWORD_UPDATE_MASK(PHY_CFG_WR_ENABLE, + PHY_CFG_WR_MASK, + PHY_CFG_WR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + udelay(1); + + reg = HIWORD_UPDATE_MASK(PHY_CFG_WR_DISABLE, + PHY_CFG_WR_MASK, + PHY_CFG_WR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); +} + +static int rockchip_pcie_phy_power_on(struct rockchip_pcie_phy *phy) +{ + int ret = 0; + u32 reg, status; + + ret = reset_deassert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + return ret; + } + + reg = HIWORD_UPDATE_MASK(PHY_CFG_PLL_LOCK, + PHY_CFG_ADDR_MASK, + PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + reg = HIWORD_UPDATE_MASK(!PHY_LANE_IDLE_OFF, + PHY_LANE_IDLE_MASK, + PHY_LANE_IDLE_A_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_LANEOFF); + + ret = -EINVAL; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + status & PHY_PLL_LOCKED, + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll lock timeout!\n"); + goto err_pll_lock; + } + + phy_wr_cfg(phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE); + phy_wr_cfg(phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M); + + ret = -ETIMEDOUT; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + !(status & PHY_PLL_OUTPUT), + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll output enable timeout!\n"); + goto err_pll_lock; + } + + reg = HIWORD_UPDATE_MASK(PHY_CFG_PLL_LOCK, + PHY_CFG_ADDR_MASK, + PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + ret = -EINVAL; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + status & PHY_PLL_LOCKED, + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll relock timeout!\n"); + goto err_pll_lock; + } + + return 0; + +err_pll_lock: + reset_assert(&phy->phy_rst); + return ret; +} + +static int rockchip_pcie_phy_power_off(struct rockchip_pcie_phy *phy) +{ + int ret; + u32 reg; + + reg = HIWORD_UPDATE_MASK(PHY_LANE_IDLE_OFF, + PHY_LANE_IDLE_MASK, + PHY_LANE_IDLE_A_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_LANEOFF); + + ret = reset_assert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + return ret; + } + + return 0; +} + +static int rockchip_pcie_phy_init(struct rockchip_pcie_phy *phy) +{ + int ret; + + ret = clk_enable(&phy->refclk); + if (ret) { + dev_err(dev, "failed to enable refclk clock\n"); + return ret; + } + + ret = reset_assert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + goto err_reset; + } + + return 0; + +err_reset: + clk_disable(&phy->refclk); + return ret; +} + +static int rockchip_pcie_phy_exit(struct rockchip_pcie_phy *phy) +{ + clk_disable(&phy->refclk); + + return 0; +} + +static struct rockchip_pcie_phy_ops pcie_phy_ops = { + .init = rockchip_pcie_phy_init, + .power_on = rockchip_pcie_phy_power_on, + .power_off = rockchip_pcie_phy_power_off, + .exit = rockchip_pcie_phy_exit, +}; + +int rockchip_pcie_phy_get(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + struct rockchip_pcie_phy *phy_priv = &priv->rk_phy; + ofnode phy_node; + u32 phandle; + int ret; + + phandle = dev_read_u32_default(dev, "phys", 0); + phy_node = ofnode_get_by_phandle(phandle); + if (!ofnode_valid(phy_node)) { + dev_err(dev, "failed to found pcie-phy\n"); + return -ENODEV; + } + + phy_priv->reg_base = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + + ret = clk_get_by_index_nodev(phy_node, 0, &phy_priv->refclk); + if (ret) { + dev_err(dev, "failed to get refclk clock phandle\n"); + return ret; + } + + ret = reset_get_by_index_nodev(phy_node, 0, &phy_priv->phy_rst); + if (ret) { + dev_err(dev, "failed to get phy reset phandle\n"); + return ret; + } + + phy_priv->ops = &pcie_phy_ops; + priv->phy = phy_priv; + + return 0; +} From patchwork Thu Apr 30 07:04:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1138 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 714263F0D3 for ; Thu, 30 Apr 2020 09:04:52 +0200 (CEST) Received: by mail-pj1-f69.google.com with SMTP id x6sf807078pjg.5 for ; Thu, 30 Apr 2020 00:04:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230291; cv=pass; d=google.com; s=arc-20160816; b=aZM/CyWP6HUXliGGHvBLTO/ix/+aZuuwV6UGd83NVrKwKbqmh6Gvgw30iPvkoVPlvE sha/3j+yHR0TGQWp/uXgzPjh/csWZsNUusYZEYB2jPzfoS3NAKuni4YcyQalDkD/g8Fw l5QTlecTM4oMk4VAjS7ckTCyvzGK74xE8zL7hgGOEzXzNt/aop6Ndk2BdeNlbt6+phhk 2x0fYGHbxBZnMgl2IyetW7kzELcQhwiKxt9Cglgmvgg5MTNkWfW/m2evGwxnN4ZMYLP/ WiIZw/nKQNMw6ZyT/S3P1NYQXYftMYY0gWto3LdU+YV4RnBcUng1wbx02nIbYtSxpcqS 6Bbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=KRak8aSvNG4HxI8YmoL8bR4YpC8w922pEMFOyWMGyYU=; b=TQ7uRpsiJpdtc8LgYTrzTjwacKXrcqZoVPexWb8ap/s1Ex0KIyGc4ngts89uKPIhQk HvqJKlNUUCgSj02qLUDRbgz9j27TJ0lqf5MgqA7Gm/P9McHVLAXT0naH1f46xSCa8VWl 1RU68X4cCoiTVGIjBHEAKve9o++aFu2eAg4tVslgx8WAAD8YrvBPdGbJtBTIusxrkzoT q+a41fq4rVroVYzmwGQQCf8/Aw3Z6eTsNZpl3tzn186c95yOxVKIw7punQrV9a4LIqLk tpoy5wtT3QnJfAtubSN0qWlolU7q1cjQGDlVup/GLWc92HdZRuAKSDBVmwUNbEEseJae 1ULw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="HBucWF/W"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=KRak8aSvNG4HxI8YmoL8bR4YpC8w922pEMFOyWMGyYU=; b=Qx98BsbBE7QCTHu5WSxAhV6BvtfHCE6pl+StVvJ3MHgQvBD4DEm6WwvjzXXJdCY/ZW vBQkrwZ0/yjkNxjnYSnW0BD1uXY4s9MRoMLPM4+61tFihjj+kYxyqdOSem/wtsmRPVGt kHiWpDgPFw+qJC/hVbqScpfwINf808o6fQaQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=KRak8aSvNG4HxI8YmoL8bR4YpC8w922pEMFOyWMGyYU=; b=KKQV6OTiQHlSs2Qlbs9v2CnWjfy7FRwDIppkLAvxi2LChoQiptKSGrIQeE3lWAO0cq YaRkStTuW7efl3JHSb7krqOz6BzevFvC1J3yUycR9O4XCSBLH/ZPs/rlGQ46VAiZgDXb uh0GBxAY0K2a0y+fFc+8M6pkVor37qC7e9m6oB0amfZtZif1AwY46xWpronKHWldOrOL zQ5y63SxuCh5Gg9w2DNt+OkHr0x62EpaBkBUYpyhZhyanyV9VsMsXbV5X5VNjHXucEw+ M1XTmqZRjqw3UWToEmUXzHOp+9cHoO2k+U9YGN+9yZmyyEj1doAx+9aFlRJzuunk9xjc 7iGQ== X-Gm-Message-State: AGi0PuZSX2qAal/mNddN71g2ojCuY5wICinTYZ6+ZFhR1Q8USI/KscMs l660lTLFK7UhGIsq1RO4Hqzfsi9/ X-Google-Smtp-Source: APiQypLyjkT0wqwjT8+sPmeDMsRVOZluY6rcB+15stfton9zvYqVti3h3Y6ZNhrcMt5d6ePamsxzlA== X-Received: by 2002:a17:902:261:: with SMTP id 88mr2387864plc.152.1588230291196; Thu, 30 Apr 2020 00:04:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:ac91:: with SMTP id h17ls3116732plr.3.gmail; Thu, 30 Apr 2020 00:04:50 -0700 (PDT) X-Received: by 2002:a17:902:8a89:: with SMTP id p9mr2289225plo.286.1588230290755; Thu, 30 Apr 2020 00:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230290; cv=none; d=google.com; s=arc-20160816; b=BCn0yvIBiHg4BHc30ouH76IlKsJBtyc47kOw8Ij1xDENZW105gTmoC4hbz+9rSj3+/ B2FnmiQFysBiMgKDsLB114FaxZpc3vb3k47wchDNVDm9snKxUyKdmtyRajBOXHKipgYk ncH49t9iJk6MvzDH+nU8DCendhakoSebnWHinB05/k3KPdSGQiVZz+Jwl22KsIAGr7VV CoXrcEB/7D8mhFctplzfw2CkhkwGF+rcWSm4zKeJErOQ/ZY7G1iWmr3Wd9F7oO6GfNMV p/ajKnbMNDL/VnJpIZq2dxcqc8gZUH2qXTrT4fk2RtT8XFQ6Uk3ysu/vT7YK5f3+prS8 vf4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=btfRNFjDwjdUkMKeVi2RwLB4eJwmNgaGoIeOs3gZS+o=; b=uJc5WRepCryZ2PZhK1gQEzqE2rWh5uOVFTU3LFu7g2OGJP/QbUrBIr6s4/R5a/L82E mViYWbNf60V3sqiJIYQJdo3ifo1b8EFvxUshoL0IZROFs/kb2cUg4qkqBK2SSHacM9BV gnMffioaTemW87vim2AYGt2qd0hocLqyFaq1AMeEFjjWx7EOqTlg8CUjR95ZbhG94BsB wShEC+IMTzhbTR7QBjg2j+UyV6otcKcHkExRauNkt04nYm5C2d1szECT1tq6JEHErT0D EfMPyITgQ3MOALaIpbWdyJONm3shTwbJARfOv5Nrnfr0sTUQ8bSi7EkeEnGLHuamKNsc 6NJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="HBucWF/W"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a64sor4720084pfa.18.2020.04.30.00.04.50 for (Google Transport Security); Thu, 30 Apr 2020 00:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:aa7:81d1:: with SMTP id c17mr2163240pfn.58.1588230290418; Thu, 30 Apr 2020 00:04:50 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:49 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 7/8] rockchip: Enable PCIe/M.2 on rk3399 board w/ M.2 Date: Thu, 30 Apr 2020 12:34:11 +0530 Message-Id: <20200430070412.12499-8-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="HBucWF/W"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Enable PCIe/M.2 support on - NanoPC-T4 - ROC-RK3399-PC Mezzanine boards. Signed-off-by: Jagan Teki --- Changes for v2: - none arch/arm/dts/rk3399-u-boot.dtsi | 1 + configs/nanopc-t4-rk3399_defconfig | 4 ++++ configs/roc-pc-mezzanine-rk3399_defconfig | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/arch/arm/dts/rk3399-u-boot.dtsi b/arch/arm/dts/rk3399-u-boot.dtsi index ef57c36e73..a79a2d23d8 100644 --- a/arch/arm/dts/rk3399-u-boot.dtsi +++ b/arch/arm/dts/rk3399-u-boot.dtsi @@ -8,6 +8,7 @@ aliases { mmc0 = &sdhci; mmc1 = &sdmmc; + pci0 = &pcie0; }; cic: syscon@ff620000 { diff --git a/configs/nanopc-t4-rk3399_defconfig b/configs/nanopc-t4-rk3399_defconfig index 607a00dbf7..032256fd76 100644 --- a/configs/nanopc-t4-rk3399_defconfig +++ b/configs/nanopc-t4-rk3399_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_SPL_OF_CONTROL=y @@ -34,10 +35,13 @@ CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_DM_ETH=y CONFIG_ETH_DESIGNWARE=y CONFIG_GMAC_ROCKCHIP=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYSRESET=y diff --git a/configs/roc-pc-mezzanine-rk3399_defconfig b/configs/roc-pc-mezzanine-rk3399_defconfig index 5a694edc03..0b853805f3 100644 --- a/configs/roc-pc-mezzanine-rk3399_defconfig +++ b/configs/roc-pc-mezzanine-rk3399_defconfig @@ -19,6 +19,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_SPL_OF_CONTROL=y @@ -36,11 +37,14 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_ETH_DESIGNWARE=y CONFIG_GMAC_ROCKCHIP=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y CONFIG_RAM_RK3399_LPDDR4=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_ROCKCHIP_SPI=y From patchwork Thu Apr 30 07:04:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1139 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B33843F0D3 for ; Thu, 30 Apr 2020 09:04:56 +0200 (CEST) Received: by mail-pj1-f69.google.com with SMTP id bg6sf753106pjb.2 for ; Thu, 30 Apr 2020 00:04:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1588230295; cv=pass; d=google.com; s=arc-20160816; b=NLXkUThHy9k0UWyvpYjL+FiRmVG7amXUpnvpKuZn7BP5lp4QZ1YO0pdT+roCs+nfev FAPRLLESCAFZhLxNsa17gKwjizFKfrvannvj32TVwFsq+J8/x1Lqisv8yqfEd88hTvK8 Z2zxlu5wcGfmh5YhyGSluc+H+oB5ncZBM+GbsWWNHdH2YgJ6zvDPle7TlQyD4y8lSVuv jVTRj+qwZfjh2Dc2WF8MX9G13RL+zM8/p/I3hlTfXYpbepzR2/2ls9jIOjPJ4W2n9rfE wc6q5DOIV8BZPwIRTjZoKkAuKklrgJFge/QRFJQGjFcyzOZKTyqlkjBC02DwFNGUGW9s 7rJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=3uk7WbFwPnn5bSWx6grzL0bLvF6iawAkWU3My7DRDtM=; b=vKi3dW/pBvWomDajYd5ManN/G5lx6LblUWH8kdKszUM0M76MXAhLkmfwG/CrpHJxzz KU8t28T3LnCly5DYvViKfyatdz25At6FR2L5OLmAi+BKM6/ACJ/GNcfDOksryOA3s3Y6 WdDg8PpCw7NGIyMEfijZGp5oK7RYynlM3X6HcTD1cO9K+L7QWDvIm6G3m32XQUsDrqUu Langcr9KlCNkrP+BXwKp/WLIoYC78EhAMIlmsnCf/dm775YDIDytPIq7nEWskI12/712 2LgEhu03EN9zYj3argCRnhvppA0cOz6+w4ObNKijPErTCqVGDzdpfuQOJQOf81DcQwjK XYKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=S7DQppqD; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=3uk7WbFwPnn5bSWx6grzL0bLvF6iawAkWU3My7DRDtM=; b=W2P09PXeYmORV/bAc3qb53ZZ/17hZ3uqywoNGE0S/23Bmt1E8uPGy3+M8WBOduIoQR Q8EOsCem5kl/7ME3lMwYskkxJ5rMVlD/eZv6TSz6fbVXaC3Nf80zqrNjmpwJ2elj82mc jQluO7ulpXS80xWvuysWbo05QIAADurt6f1sc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=3uk7WbFwPnn5bSWx6grzL0bLvF6iawAkWU3My7DRDtM=; b=Rc3YvHp7pBZW7NtWToRyDKJ5C2BU3+4t4SMkrDUmMpIcH3shu9rv0S5sRr4IHRpcjv nOS8Ctie5FLH1ATBpiyBps3Kr5wBWFvMJUVCeq+tCvugg3kn4phgvEm33KJKMh+sNLFU TBdDdB9Rwgz2KSkONT9UQrumHZ25U9a7T3DCtgP3Xwrb5qA4jBDQfvBrVOpSw2mslL7U ghWXZ+Q/AFAAOq5KBPZncuj8JucH0MBZ2nkxzv5C8FlAHQm29R+oK59gs1jFFITaZEYG 9XFl0Tjy65RLWKRpjRGetMgV9CW2c6G/yJkgnH92K/BbpFFGTpPVHmMuJ/qOwltbeqGM xPtA== X-Gm-Message-State: AGi0PuaGVrhDBidWWSh7YMJvr0e0mWVO2FRMtPPepHQ3wTU0Flq2n4wU EtYco6/qiI1/ID+IMcvFrPVNbZgt X-Google-Smtp-Source: APiQypL9yJgb4slnbhoqnol3hFvp3JzJ1w534f0YLqMQn5c7eRBInwz+R/J4K3qtxofZiWJQKuf8IA== X-Received: by 2002:a17:90a:8a09:: with SMTP id w9mr1333955pjn.95.1588230295502; Thu, 30 Apr 2020 00:04:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:b58d:: with SMTP id a13ls3128562pls.0.gmail; Thu, 30 Apr 2020 00:04:55 -0700 (PDT) X-Received: by 2002:a17:90a:bf12:: with SMTP id c18mr1233413pjs.180.1588230295044; Thu, 30 Apr 2020 00:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588230295; cv=none; d=google.com; s=arc-20160816; b=PYwgPoyKXcxhC7SK3ErVCxitMxodhnXpiOT/mfPs18Gi5bEIT8Y7Ksv76rc62t4El5 JkDycrfUTzwQWndbduOXH2783ZqSa3GSrqZxH7C4syaibfKZr51+W57mscdi7AR1HSlv DFWC3G6mpSodEhf4AwEcGe8FUno/3xOfAkGXq8XMKWdwNAyf/GP0lc1Dcx+jjbuxm2Vp MIt8hiQ80g2bg9soAhO+c6Tj0s/PlbsmyrpzIDoYgQlcdnrBo1QJTxlaAs592GnrT8Cw u9Aw+I3eFsjxb0jiJqrLqMSeKKtBZvBgFvc8mBsNXfVeyHWR3zUSSWR5DnhZjEN6xGGP vRMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DwfpjIE8nKMsbRS0x/+1oo0yx+ro2f51EemJbqL5udQ=; b=qYgPbU+thD3ULC0IWBBP2AQ+/1GR/S/U162fAy8PtOzy4pjEger+jq4eFDUdB4m19X McmQOxt0u6UIcwT1XHfZMEgRDzkN04bRxz3ile3GnuAY07s9d9a4nJvJcHxOOk3YLqvB jDg1pmv4KflgoGzfqYv1uZeExxeeO9qJ1oHosQWHUmjq+J4evPIiyTMtqKB9IhsxI4w6 parF0B2KK4J7rBVvVtrYSIvPqW18KerDUJqSB1z+IvF+ICm19BXRggkwoxqsNPhhggyq 9B/GGIvtZVx76kECTpZvfSppowxphrnfGAEktfvIlpmUicr9K9KtkvcXS826VNIGRcUh NZDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=S7DQppqD; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y65sor4653546pfg.12.2020.04.30.00.04.55 for (Google Transport Security); Thu, 30 Apr 2020 00:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:aa7:9d84:: with SMTP id f4mr2089513pfq.290.1588230294757; Thu, 30 Apr 2020 00:04:54 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:6514:3619:d1af:85f6]) by smtp.gmail.com with ESMTPSA id p64sm964143pjp.7.2020.04.30.00.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 00:04:53 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Tom Cubie , Manivannan Sadhasivam Subject: [PATCH v2 8/8] rockchip: Enable PCIe/M.2 on rock960 board Date: Thu, 30 Apr 2020 12:34:12 +0530 Message-Id: <20200430070412.12499-9-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430070412.12499-1-jagan@amarulasolutions.com> References: <20200430070412.12499-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=S7DQppqD; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Due to some on board limitation rock960 PCIe works only with 1.8V IO domain. So, this patch enables grf io_sel explicitly to make PCIe/M.2 to work. Cc: Tom Cubie Cc: Manivannan Sadhasivam Signed-off-by: Jagan Teki Acked-by: Manivannan Sadhasivam --- Changes for v2: - none board/vamrs/rock960_rk3399/rock960-rk3399.c | 20 ++++++++++++++++++++ configs/rock960-rk3399_defconfig | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/board/vamrs/rock960_rk3399/rock960-rk3399.c b/board/vamrs/rock960_rk3399/rock960-rk3399.c index 68a127b9ac..98d62e89ca 100644 --- a/board/vamrs/rock960_rk3399/rock960-rk3399.c +++ b/board/vamrs/rock960_rk3399/rock960-rk3399.c @@ -2,3 +2,23 @@ /* * Copyright (C) 2018 Manivannan Sadhasivam */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_MISC_INIT_R +int misc_init_r(void) +{ + struct rk3399_grf_regs *grf = + syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + + /* BT565 is in 1.8v domain */ + rk_setreg(&grf->io_vsel, BIT(0)); + + return 0; +} +#endif diff --git a/configs/rock960-rk3399_defconfig b/configs/rock960-rk3399_defconfig index c4e954731a..cb1ec3c26b 100644 --- a/configs/rock960-rk3399_defconfig +++ b/configs/rock960-rk3399_defconfig @@ -9,6 +9,7 @@ CONFIG_DEBUG_UART_BASE=0xFF1A0000 CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART=y CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-rock960.dtb" +CONFIG_MISC_INIT_R=y CONFIG_DISPLAY_BOARDINFO_LATE=y # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set CONFIG_SPL_STACK_R=y @@ -19,6 +20,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_CMD_PMIC=y @@ -36,10 +38,13 @@ CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_DM_ETH=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYSRESET=y