Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4474329rwd; Sun, 11 Jun 2023 08:12:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wWTRPZK8Rjtz6jL06p12g1yXBjQCShxqqjfqVvT4/3o21i83GQuXHpAb0x3LiOMJaTPoF X-Received: by 2002:a05:6402:1ace:b0:514:94c1:d06a with SMTP id ba14-20020a0564021ace00b0051494c1d06amr3139080edb.30.1686496365406; Sun, 11 Jun 2023 08:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686496365; cv=none; d=google.com; s=arc-20160816; b=wFrQsCU81uhKTPSldW3cklZw5vsrxycEG4HKeCrS8Q3GlmnTPumFMiBGPkMuypBnCL R2guVOGOwklAqOVAgSm26+JlNE0OATnn/wZsNQuMhHhq3knCOOFLuxJys9WbWPIjtpsx T0Y++eJslcsYfjIZxa0fvL11W5ruNnZIfLMiHv+2MiaAm9N8GXqS6giNJ6iG7VZZGsrD iagZsapfGf1n+u9YchbBcCnXJngt7bjsBAxrzxQsSKLpt4WVF2y6sZ/kbiAwQ6krv5xY kW9uMqqSTOwMeb7ZxduwIbcHn/JCyGKc4WqP6Mkz6oWcBUY/Qd/kllpOEgNmRBmfandA s+bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+eAfucaCV2o24HzyudEWTZ4yFqPF9x8yujUzoQbLFp8=; b=ghKRV+bvba+65zPjr6mtmII13xv5FRDotTLlyiUGI4pQoVvPxQ3qXrIkfIWh3QwvgO h+BTVEGYStYxGI1NVFGZIHJ/EiU1Cn20OIfuw1W8Q2MSBVqLqY5WqNgDAbNfnri3nMhS 3F6j0nNDqBI4IXN4tMTUn5jLnRCz1+XZLT5pPYEOKp3jGzTcDfJQDS3iI2mm98/5Rvvi UV7lUzfrlsAFDgOgzRX+ChzTI378cPfDuzmRuLKN10qIhlyioXDDYtPR0HOrOBctM46q XeyS/QTbKxz8BqyQ/5X+mRIfS5z7H2fgEVoM5iVPydtGIwfsa/QIEgNU2b5cMQCE6hV2 G9zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEQivJZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020aa7c317000000b005163b869809si4872326edq.98.2023.06.11.08.12.21; Sun, 11 Jun 2023 08:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEQivJZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234099AbjFKOFS (ORCPT + 99 others); Sun, 11 Jun 2023 10:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233744AbjFKOEd (ORCPT ); Sun, 11 Jun 2023 10:04:33 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B54210C for ; Sun, 11 Jun 2023 07:04:03 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f6e1393f13so24968795e9.0 for ; Sun, 11 Jun 2023 07:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686492241; x=1689084241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+eAfucaCV2o24HzyudEWTZ4yFqPF9x8yujUzoQbLFp8=; b=wEQivJZApWNBHK7qtEC57YnEQg2qLtTGLneD1L32jIF4BAicXn5dUdhOFKwieipuWX mFYGyd31M4C9JMGuJdIPYY9kme0sPDxPyBF+gDrER88fkatXqdJibWEhJfBBN5eLwtDw YSdNRaJgdfYC9FDCOVwZrLRfo+/6OhuXePxGlp/uQoH502j4UqTMMq00ATBPKo2ONjtT 3VFukMfMO2hAHzIF7Uny6G2mfxhYaZTXFgD+EjBW8BU6VyJxXDH0YDB19CLkBGxa4b6+ d+wHARJrrIfjPfgNbV/VFdTzFlNDRrGez86GWIxVEMs+8KxJrvqdxouyClucEucAIO2H 6DYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686492241; x=1689084241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+eAfucaCV2o24HzyudEWTZ4yFqPF9x8yujUzoQbLFp8=; b=Q/pSfBcmNUfDEk4dXAl3WZh/6mMKNDMz9EtRT7A7QFM6IXVq77wu8W2grce+yLL00o fT7Qx+DnrEWybsHTVgvA5oIrnYn6+f/W8Z9+Smwdu540eRHpc0uIoHxJXgYgUC/g2fID PcN0avjooagVkCURqPSfjdBtQRx760ZepJGHIkj2nAp09/TLjZZc02IfacrH8itaze3M 2cylPIKjmpeLHmr9ThbDfBh8RydegtA7l+cVtNedpRi6f2rbsrNVCVrX+dQgxIO90yEX p24s+hx8u7k/ZD6+uvR3iVNb5ebrTTyLfdFmANHydyIxxLfSqhVgo4RLnPDJLfXVl/PQ Y/RQ== X-Gm-Message-State: AC+VfDxmA9Vi6P4xNrIzEkAGW04wTWAMiixa7Z8FzaG2uZp8iBZcfrOz u26aZzhCgnOY6KXu6Czw8/bRgw== X-Received: by 2002:a7b:c8da:0:b0:3f7:e8fc:678d with SMTP id f26-20020a7bc8da000000b003f7e8fc678dmr4914215wml.13.1686492241496; Sun, 11 Jun 2023 07:04:01 -0700 (PDT) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id h17-20020a05600c28d100b003f080b2f9f4sm8567222wmd.27.2023.06.11.07.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 07:04:00 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Cristian Ciocaltea , Finley Xiao , Vincent Legoll , Heiko Stuebner , Srinivas Kandagatla Subject: [PATCH 13/26] nvmem: rockchip-otp: Add support for RK3588 Date: Sun, 11 Jun 2023 15:03:17 +0100 Message-Id: <20230611140330.154222-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230611140330.154222-1-srinivas.kandagatla@linaro.org> References: <20230611140330.154222-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cristian Ciocaltea Add support for the OTP memory device found on the Rockchip RK3588 SoC. While here, remove the unnecessary 'void *' casts in the OF device ID table. Co-developed-by: Finley Xiao Signed-off-by: Finley Xiao Signed-off-by: Cristian Ciocaltea Tested-by: Vincent Legoll Reviewed-by: Heiko Stuebner Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/rockchip-otp.c | 78 +++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/rockchip-otp.c b/drivers/nvmem/rockchip-otp.c index 84bf956cc4e1..cb9aa5428350 100644 --- a/drivers/nvmem/rockchip-otp.c +++ b/drivers/nvmem/rockchip-otp.c @@ -54,6 +54,19 @@ #define OTPC_TIMEOUT 10000 +/* RK3588 Register */ +#define RK3588_OTPC_AUTO_CTRL 0x04 +#define RK3588_OTPC_AUTO_EN 0x08 +#define RK3588_OTPC_INT_ST 0x84 +#define RK3588_OTPC_DOUT0 0x20 +#define RK3588_NO_SECURE_OFFSET 0x300 +#define RK3588_NBYTES 4 +#define RK3588_BURST_NUM 1 +#define RK3588_BURST_SHIFT 8 +#define RK3588_ADDR_SHIFT 16 +#define RK3588_AUTO_EN BIT(0) +#define RK3588_RD_DONE BIT(1) + struct rockchip_data { int size; const char * const *clks; @@ -171,6 +184,52 @@ static int px30_otp_read(void *context, unsigned int offset, return ret; } +static int rk3588_otp_read(void *context, unsigned int offset, + void *val, size_t bytes) +{ + struct rockchip_otp *otp = context; + unsigned int addr_start, addr_end, addr_len; + int ret, i = 0; + u32 data; + u8 *buf; + + addr_start = round_down(offset, RK3588_NBYTES) / RK3588_NBYTES; + addr_end = round_up(offset + bytes, RK3588_NBYTES) / RK3588_NBYTES; + addr_len = addr_end - addr_start; + addr_start += RK3588_NO_SECURE_OFFSET; + + buf = kzalloc(array_size(addr_len, RK3588_NBYTES), GFP_KERNEL); + if (!buf) + return -ENOMEM; + + while (addr_len--) { + writel((addr_start << RK3588_ADDR_SHIFT) | + (RK3588_BURST_NUM << RK3588_BURST_SHIFT), + otp->base + RK3588_OTPC_AUTO_CTRL); + writel(RK3588_AUTO_EN, otp->base + RK3588_OTPC_AUTO_EN); + + ret = rockchip_otp_wait_status(otp, RK3588_OTPC_INT_ST, + RK3588_RD_DONE); + if (ret < 0) { + dev_err(otp->dev, "timeout during read setup\n"); + goto read_end; + } + + data = readl(otp->base + RK3588_OTPC_DOUT0); + memcpy(&buf[i], &data, RK3588_NBYTES); + + i += RK3588_NBYTES; + addr_start++; + } + + memcpy(val, buf + offset % RK3588_NBYTES, bytes); + +read_end: + kfree(buf); + + return ret; +} + static int rockchip_otp_read(void *context, unsigned int offset, void *val, size_t bytes) { @@ -213,14 +272,29 @@ static const struct rockchip_data px30_data = { .reg_read = px30_otp_read, }; +static const char * const rk3588_otp_clocks[] = { + "otp", "apb_pclk", "phy", "arb", +}; + +static const struct rockchip_data rk3588_data = { + .size = 0x400, + .clks = rk3588_otp_clocks, + .num_clks = ARRAY_SIZE(rk3588_otp_clocks), + .reg_read = rk3588_otp_read, +}; + static const struct of_device_id rockchip_otp_match[] = { { .compatible = "rockchip,px30-otp", - .data = (void *)&px30_data, + .data = &px30_data, }, { .compatible = "rockchip,rk3308-otp", - .data = (void *)&px30_data, + .data = &px30_data, + }, + { + .compatible = "rockchip,rk3588-otp", + .data = &rk3588_data, }, { /* sentinel */ }, }; -- 2.25.1