From patchwork Mon Apr 12 12:13:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 1465185 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-NXP1-onmicrosoft-com header.b=bcT4nyXU; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FJn5d19Smz9sSC for ; Mon, 12 Apr 2021 21:47:01 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 56B4C820C3; Mon, 12 Apr 2021 13:46:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="bcT4nyXU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3175820AA; Mon, 12 Apr 2021 13:45:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0629.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::629]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C8CA681E84 for ; Mon, 12 Apr 2021 13:43:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ncJh7ubax6UsdMPQR4GK+zfnNR+hIaRhiaI2QBdPwhB8uJWF5O8L9TNmrGb1aSpfuLifvqwGlrwZp2I/yM9g+xKB3XwNnXYxLGzR3cp5qWPzq6tAkgxua0CCyPDrKKEt2pLwvTvTdtGQI+ZgdzhYnqyYrDAwy4zxmI/nATy/b0owmBiLMOs4YB0lvJ/KGDbvwjOnPyTDzdfeoqdH7ZfNuJ/DBV4YQvL6jbULvJOKJkCYqefmbkzc2XjNZwsiKMH8iJUh0W16O4cnGmRPlzmCCXX4WbQ0Dqakd2B2yeuSS8qZR59hoBCjvZryEu85dPOXJNaz3rxk6pIlX62Z9MZScQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CnXNqI2Wf+11PWj/KT2GtXZbcvNYvDld5hGLtdnLE3k=; b=d0qxJKP+OPkw0HIsP9BkjNYJwAKDNlzIpCcAeZzRhqftVu+c68gSBKuBX2lJm0/fCI4Q3cbDkQQVgDFMi4Cni8FBfTU1YvCV+1+7d2rMtyIvyDJmH1u/gaVskdSV5udJ7lvpUJkcVNs65IeUOj/XwB+4cP+U9wW6hL7+BI/dgLoLKniL/+QS5EezsL4qr97Mxv1NJC5jZ+5sjUEhn0UG/afLpOJZVRV+jqyoKWbkpSQH7+nMKPrpFbQJNGkAIA3YV2m3SU3Xsomix0mabzJvTqdWY1GVTE7axSHgIgOO1YhEl17+vQ05VjHgzat/82nlFNldTAVRtoxYc/UZBWT4AQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CnXNqI2Wf+11PWj/KT2GtXZbcvNYvDld5hGLtdnLE3k=; b=bcT4nyXUXwJKpgVSmN+T4WTD9Hc4Azi9O/zV1Q63IPLbV0SguX/ykaZ8Nl8XgFxAfc0NSUO3JYO/aAObhrtWGAZAxNsc0BSul5QEeGSNI76anUkMkwUp9ukVMI8j6n+z8teOG2XtkessokIy5PeeGu6TglccCxoEU5KCPI9cX1I= Authentication-Results: denx.de; dkim=none (message not signed) header.d=none;denx.de; dmarc=none action=none header.from=oss.nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DBBPR04MB7595.eurprd04.prod.outlook.com (2603:10a6:10:20d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Mon, 12 Apr 2021 11:43:00 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c57a:6964:f72c:21cf]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c57a:6964:f72c:21cf%11]) with mapi id 15.20.3999.032; Mon, 12 Apr 2021 11:43:00 +0000 From: "Peng Fan (OSS)" To: sbabic@denx.de, festevam@gmail.com Cc: u-boot@lists.denx.de, uboot-imx@nxp.com, Ye Li Subject: [PATCH 35/37] driver: misc: imx8ulp: Add fuse driver for imx8ulp Date: Mon, 12 Apr 2021 20:13:04 +0800 Message-Id: <20210412121306.11484-36-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210412121306.11484-1-peng.fan@oss.nxp.com> References: <20210412121306.11484-1-peng.fan@oss.nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: HK2PR0401CA0009.apcprd04.prod.outlook.com (2603:1096:202:2::19) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by HK2PR0401CA0009.apcprd04.prod.outlook.com (2603:1096:202:2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Mon, 12 Apr 2021 11:42:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 56cddcde-f2b0-446a-cc0d-08d8fda81f74 X-MS-TrafficTypeDiagnostic: DBBPR04MB7595: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d1NFgcQsV1O/8vO4WEkgAHv1+U6b8pRfLwgLnWQhXqUh695FoFquvmqrr+UifDYRMHliu+BSvoreqH4dw7sP8N0RXrCxd0Y4IUIkJwe7NqVcLNde5Lgu4YESm6NLIOiG3Pb1X314GFmvOibfocah0eLvlxgsrNj9APMzKFewgWm1EdIzcXZoemIw9jR8bhID+/U4gqqshLccrMj39ol3xOOKT/fcDmp8jAeTnh9oUDw3332+CQw6aExFoBe2WhDQYoAlrzKZvHBeLlr5og7onjvgabooElVgXuUJi+EANYdGe7VL42TARr1lAw7RYf+q+Hp1Ru8CWm6f7i5vLzNj3AeR6dLuhcMR9LwQE3gJjkb4gQ8FdjYPIqX+9zIlROsqFGeNaHmA0fzZ707NZxecV59mPJjNfjcTOGET35/SAlehE4fdLjPnuaV9BRPXLeoEJrfE6Sq2IlqtSUzsZlAOcPKSEBLl5B5ZUK5yWz/TmbVmr5cP4mAfKeMpR2FuC0oMcGf34OLBxw0NWDdHfoM5Dyt3U5rrb31LFZ9bbKNkQ0eKAUtu3siQf2qARXGYE9jYHzoxXMqorQGEK4NDo8WonrWcFTs3m5hwKIgvWnECplhiaFIrEh+lYp8CPQAxAbSQg6CzZLchhTv6MmfAn/rWtYnhOxJ6kc1NxP9Tj9Q2su8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(366004)(136003)(376002)(346002)(39860400002)(38100700002)(4326008)(6506007)(38350700002)(316002)(26005)(2616005)(86362001)(186003)(956004)(52116002)(478600001)(2906002)(8676002)(1076003)(6512007)(83380400001)(66476007)(5660300002)(66556008)(8936002)(6666004)(16526019)(66946007)(6486002)(32563001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0lzPZvT/84/iG4Rnsau2cXOZMROffRyEAdtGR+4QeekHMzwqUSxOLvDImT8X6jQw3oVxD0PMx4LeONNsy3Swaze+z1V4q7QCvw1FT09LO4C4ziE+HQ0jz91CTHn7gjx3DBTDaEwyuXoMkTEztuaEZ9UT+E5eYJrm7PiyJyoNyrEGwpsgred4dYLS89fcFzvXMlFcapTTfEXpNYOBGNbvBF2PAwsQ7QzwSHEyp81HIloMC1dbnoXpiX/szB962pUIi7mdCImFJsuXU6Zv7gP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oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56cddcde-f2b0-446a-cc0d-08d8fda81f74 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2021 11:42:59.8735 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eOWdSNrgyUKwrYH82H59VAhWdGKBzs6zdxwTV8BY2EmoSt8xSiEeaSw3u0vqevvc4jYKyYKVtAvNN4DyuXqQzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7595 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean From: Ye Li This driver uses FSB to read some fuses, but not support program fuse. It only works in SPL (secure mode), u-boot needs traps to ATF to read them. Some fuses can read from S400 API and others are from FSB. Also support program some fuses via S400 API Signed-off-by: Ye Li --- drivers/misc/imx8ulp/Makefile | 1 + drivers/misc/imx8ulp/fuse.c | 198 ++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 drivers/misc/imx8ulp/fuse.c diff --git a/drivers/misc/imx8ulp/Makefile b/drivers/misc/imx8ulp/Makefile index 1d792415d2..927cc55216 100644 --- a/drivers/misc/imx8ulp/Makefile +++ b/drivers/misc/imx8ulp/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += s400_api.o imx8ulp_mu.o +obj-$(CONFIG_CMD_FUSE) += fuse.o diff --git a/drivers/misc/imx8ulp/fuse.c b/drivers/misc/imx8ulp/fuse.c new file mode 100644 index 0000000000..d1feb62ab5 --- /dev/null +++ b/drivers/misc/imx8ulp/fuse.c @@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2020 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#define FUSE_BANKS 64 +#define WORDS_PER_BANKS 8 + +struct fsb_map_entry { + s32 fuse_bank; + u32 fuse_words; + bool redundancy; +}; + +struct s400_map_entry { + s32 fuse_bank; + u32 fuse_words; + u32 fuse_offset; + u32 s400_index; +}; + +struct fsb_map_entry fsb_mapping_table[] = { + { 3, 8 }, + { 4, 8 }, + { 5, 8 }, + { 6, 8 }, + { -1, 48 }, /* Reserve 48 words */ + { 8, 4, true }, + { 24, 4, true }, + { 26, 4, true }, + { 27, 4, true }, + { 28, 8 }, + { 29, 8 }, + { 30, 8 }, + { 31, 8 }, + { 37, 8 }, + { 38, 8 }, + { 39, 8 }, + { 40, 8 }, + { 41, 8 }, + { 42, 8 }, + { 43, 8 }, + { 44, 8 }, + { 45, 8 }, + { 46, 8 }, +}; + +struct s400_map_entry s400_api_mapping_table[] = { + { 1, 8 }, /* LOCK */ + { 2, 8 }, /* ECID */ + { 7, 4, 0, 1 }, /* OTP_UNIQ_ID */ + { 23, 1, 4, 2 }, /* OTFAD */ +}; + +static s32 map_fsb_fuse_index(u32 bank, u32 word, bool *redundancy) +{ + s32 size = ARRAY_SIZE(fsb_mapping_table); + s32 i, word_pos = 0; + + /* map the fuse from ocotp fuse map to FSB*/ + for (i = 0; i < size; i++) { + if (fsb_mapping_table[i].fuse_bank != -1 && + fsb_mapping_table[i].fuse_bank == bank) { + break; + } + + word_pos += fsb_mapping_table[i].fuse_words; + } + + if (i == size) + return -1; /* Failed to find */ + + if (fsb_mapping_table[i].redundancy) { + *redundancy = true; + return (word >> 1) + word_pos; + } + + *redundancy = false; + return word + word_pos; +} + +static s32 map_s400_fuse_index(u32 bank, u32 word) +{ + s32 size = ARRAY_SIZE(s400_api_mapping_table); + s32 i; + + /* map the fuse from ocotp fuse map to FSB*/ + for (i = 0; i < size; i++) { + if (s400_api_mapping_table[i].fuse_bank != -1 && + s400_api_mapping_table[i].fuse_bank == bank) { + if (word >= s400_api_mapping_table[i].fuse_offset && + word < (s400_api_mapping_table[i].fuse_offset + + s400_api_mapping_table[i].fuse_words)) + break; + } + } + + if (i == size) + return -1; /* Failed to find */ + + if (s400_api_mapping_table[i].s400_index != 0) + return s400_api_mapping_table[i].s400_index; + + return s400_api_mapping_table[i].fuse_bank * 8 + word; +} + +int fuse_sense(u32 bank, u32 word, u32 *val) +{ + s32 word_index; + bool redundancy; + + if (bank >= FUSE_BANKS || word >= WORDS_PER_BANKS || !val) + return -EINVAL; + + word_index = map_fsb_fuse_index(bank, word, &redundancy); + if (word_index >= 0) { + *val = readl((ulong)FSB_BASE_ADDR + 0x800 + (word_index << 2)); + if (redundancy) + *val = (*val >> ((word % 2) * 16)) & 0xFFFF; + + return 0; + } + + word_index = map_s400_fuse_index(bank, word); + if (word_index >= 0) { + u32 data[4]; + u32 res, size = 4; + int ret; + + /* Only UID return 4 words */ + if (word_index != 1) + size = 1; + + ret = ahab_read_common_fuse(word_index, data, size, &res); + if (ret) { + printf("ahab read fuse failed %d, 0x%x\n", ret, res); + return ret; + } + + if (word_index == 1) { + *val = data[word]; /* UID */ + } else if (word_index == 2) { + /* + * OTFAD 3 bits as follow: + * bit 0: OTFAD_ENABLE + * bit 1: OTFAD_DISABLE_OVERRIDE + * bit 2: KEY_BLOB_EN + */ + *val = data[0] << 3; + } else { + *val = data[0]; + } + + return 0; + } + + return -ENOENT; +} + +int fuse_read(u32 bank, u32 word, u32 *val) +{ + return fuse_sense(bank, word, val); +} + +int fuse_prog(u32 bank, u32 word, u32 val) +{ + u32 res; + int ret; + + if (bank >= FUSE_BANKS || word >= WORDS_PER_BANKS || !val) + return -EINVAL; + + ret = ahab_write_fuse((bank * 8 + word), val, false, &res); + if (ret) { + printf("ahab write fuse failed %d, 0x%x\n", ret, res); + return ret; + } + + return 0; +} + +int fuse_override(u32 bank, u32 word, u32 val) +{ + printf("Override fuse to i.MX8ULP in u-boot is forbidden\n"); + return -EPERM; +}