From patchwork Sun Mar 29 17:05:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pragnesh Patel X-Patchwork-Id: 1263482 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=selector1 header.b=SsCxvbPM; 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 48r27m29QQz9sQt for ; Mon, 30 Mar 2020 04:07:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A7B6818EC; Sun, 29 Mar 2020 19:06:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.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=sifive.com header.i=@sifive.com header.b="SsCxvbPM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D4714818E0; Sun, 29 Mar 2020 19:06:32 +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=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060e.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::60e]) (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 526C1818C6 for ; Sun, 29 Mar 2020 19:06:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pragnesh.patel@sifive.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U5VfLfFNyc4GUcBzUO89lumt9tjezm7JJSt9hFOKWwa2KlYSQsfM3RNhwIV7lAqGFi2cQnJ8R0zgI4SnHFMUvsNqMtEGHH0pV2jEok7kHS5AOT2rWbdV8e++3Qhdss5Hp/nKHCt+575RzVegtJXCgb8AusUco7i0QzSfNHR5GTbHqfUOMCcBAd1BeGFbD/5fSkCHGXKQlOa6pynRodBYHu2W0nrHi3YOq8M57b0q8yh95e85CCtbcX7bavVDhLjxjRLCyW3maA27YBgBViTtqb3Jn1y7qIzGe3NMRF+3FPAkIoC2bHRMNjPpWIxcb0JC3XsZqgYD37UmWikg7JpLWw== 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=Rzm6R5Qgk/8s1x0BMo6JuwZxThQ3hlXKi10S/4Fmkdw=; b=TvYr23AcGh47EJNHUpQqevkH0IpWZbf01aZ9dTq8+4loCvfKj+BxxYkxOGQ1hoWnDWHiupNIbxwEO/UXkPDLvAJArW1io0V5acICKAIt01MCxej3RV8KUYBO/g/azEsm4Jcv3t9ntEzn6fALfS1/cQkx+sEMYiLVKO4sCSSYFeZMRIUGLzzjeXxVg78gW8sVbYSy4/nPb7Gr3HQyc8EW7Keo9GaKUmXdMVZW9yxShxwTNBh45q+fZ0fZeGyJLfzlVO4sUgFsra1HqgWaV329dO3qFkU7mvhuv1Ar9PW/TAdlpXleZyIX6i6xNS6fgcAOzJtdx1QDlaudJcozlc3LFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sifive.com; dmarc=pass action=none header.from=sifive.com; dkim=pass header.d=sifive.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rzm6R5Qgk/8s1x0BMo6JuwZxThQ3hlXKi10S/4Fmkdw=; b=SsCxvbPMXhEqTo/qGiAh6vjeKNW8HSrifJY1upt7240D4XiJ2P/qZLWSTho/YHNQdiKnDyqik2CRyBEULF/B/XG0uMjWWDnF5NYI186pqNkjj/X01GCtZatKvGmJ12d9RCcDmuhoUU0o0qCV0/H1ZYJE3n+la1GNrU8rUcf7nA4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pragnesh.patel@sifive.com; Received: from MWHPR13MB0944.namprd13.prod.outlook.com (2603:10b6:300:15::19) by MWHPR13MB1293.namprd13.prod.outlook.com (2603:10b6:300:9a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.12; Sun, 29 Mar 2020 17:06:24 +0000 Received: from MWHPR13MB0944.namprd13.prod.outlook.com ([fe80::d1e5:a0aa:836d:d5a3]) by MWHPR13MB0944.namprd13.prod.outlook.com ([fe80::d1e5:a0aa:836d:d5a3%7]) with mapi id 15.20.2878.012; Sun, 29 Mar 2020 17:06:24 +0000 From: Pragnesh Patel To: u-boot@lists.denx.de Cc: atish.patra@wdc.com, palmerdabbelt@google.com, bmeng.cn@gmail.com, paul.walmsley@sifive.com, jagan@amarulasolutions.com, troy.benjegerdes@sifive.com, anup.patel@wdc.com, sagar.kadam@sifive.com, rick@andestech.com, Pragnesh Patel , Palmer Dabbelt Subject: [PATCH v6 02/17] riscv: sifive: fu540: Use OTP DM driver for serial environment variable Date: Sun, 29 Mar 2020 22:35:23 +0530 Message-Id: <20200329170538.25449-3-pragnesh.patel@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329170538.25449-1-pragnesh.patel@sifive.com> References: <20200329170538.25449-1-pragnesh.patel@sifive.com> X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) To MWHPR13MB0944.namprd13.prod.outlook.com (2603:10b6:300:15::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sachinj2-OptiPlex-7010.open-silicon.com (114.143.65.226) by LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.19 via Frontend Transport; Sun, 29 Mar 2020 17:06:20 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [114.143.65.226] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 29003e37-b778-449b-ec41-08d7d40382c6 X-MS-TrafficTypeDiagnostic: MWHPR13MB1293: X-LD-Processed: 22f88e9d-ae0d-4ed9-b984-cdc9be1529f1,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:220; X-Forefront-PRVS: 035748864E X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR13MB0944.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(136003)(376002)(39840400004)(396003)(346002)(366004)(1006002)(6512007)(52116002)(44832011)(956004)(2616005)(4326008)(6506007)(6916009)(66476007)(186003)(36756003)(26005)(16526019)(66556008)(8936002)(8676002)(316002)(2906002)(86362001)(66946007)(54906003)(5660300002)(6486002)(478600001)(81156014)(81166006)(1076003); DIR:OUT; SFP:1101; Received-SPF: None (protection.outlook.com: sifive.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6gHfWb4yeZra89njKIZuBD89mNXpBQgHaGHmrVpA7WNm6JrAElW5wnO3dvpleSZoW85ryVGT2kfn7HH99ORtYq7FwUnMSQ3XQbtyFvtqQQlvOAVMGJQmNR/euEYGILPoecCux+UNSQOI0FGjkcRE/mQuinsABKr8uP3VUVH41a7Mg/w0SxCg5csoNrZ5L3Y+C7NsqWjTw0w86qlGsWx9lp65a7nr6XyRWs6K5c874j0WbaGhu6CvwYCfY0Sgz9oTGwRgPU3pCJzCUETEtYZA8HPphNYNheBrKVMFXhdg5vaoT9foLRlT6iLDAwxz1Ri4Yiteh71OlpodeBE47xramxRZeRc3HXVGrFHOYzJVfDk8guw/RfD+UHNauvb8Pm9Dr4/yGb11gK+ZGY22TStqLvn5pPQkv8nEKkPrBnrPliDki2CyDI8lEZN9mjwVWj71 X-MS-Exchange-AntiSpam-MessageData: hOBj5iSmA7XTrBP5m9gTB8itFJy+dSCXZaWBInjJa4ATZiwZDsFuX6A1mIne4/AKha4V40VkCRZHd6/heE6jO93Ukp0YeEFt+7LjEHLbnUHNcgCy8qEFjL782c1dO+M0kKM84eWy/OGTfMN2CekJtA== X-OriginatorOrg: sifive.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29003e37-b778-449b-ec41-08d7d40382c6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2020 17:06:24.3228 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 22f88e9d-ae0d-4ed9-b984-cdc9be1529f1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: v/oYDLAh4rs9t1DzTsBVa/QoE4CaolmV3KqHf0iSH0y4zy7Rb+EWG3QhCjxzi670//POdSzb1KEB2IA0fxEu0gvEjowP84oyJwjp+sBwGDw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR13MB1293 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean Use the OTP DM driver to set the serial environment variable. Signed-off-by: Pragnesh Patel Reviewed-by: Bin Meng --- arch/riscv/dts/fu540-c000-u-boot.dtsi | 14 +++ .../dts/hifive-unleashed-a00-u-boot.dtsi | 6 + board/sifive/fu540/Kconfig | 2 + board/sifive/fu540/fu540.c | 111 ++++++------------ 4 files changed, 61 insertions(+), 72 deletions(-) create mode 100644 arch/riscv/dts/fu540-c000-u-boot.dtsi create mode 100644 arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi diff --git a/arch/riscv/dts/fu540-c000-u-boot.dtsi b/arch/riscv/dts/fu540-c000-u-boot.dtsi new file mode 100644 index 0000000000..db55773bd2 --- /dev/null +++ b/arch/riscv/dts/fu540-c000-u-boot.dtsi @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * (C) Copyright 2019 SiFive, Inc + */ + +/ { + soc { + otp: otp@10070000 { + compatible = "sifive,fu540-c000-otp"; + reg = <0x0 0x10070000 0x0 0x0FFF>; + fuse-count = <0x1000>; + }; + }; +}; diff --git a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi new file mode 100644 index 0000000000..f1735c1385 --- /dev/null +++ b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * Copyright (C) 2019 SiFive, Inc + */ + +#include "fu540-c000-u-boot.dtsi" diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig index 5ca21474de..900197bbb2 100644 --- a/board/sifive/fu540/Kconfig +++ b/board/sifive/fu540/Kconfig @@ -48,5 +48,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply SIFIVE_GPIO imply CMD_GPIO imply SMP + imply MISC + imply SIFIVE_OTP endif diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c index 47a2090251..540638c919 100644 --- a/board/sifive/fu540/fu540.c +++ b/board/sifive/fu540/fu540.c @@ -10,94 +10,61 @@ #include #include #include +#include + +/* + * This define is a value used for error/unknown serial. + * If we really care about distinguishing errors and 0 is + * valid, we'll need a different one. + */ +#define ERROR_READING_SERIAL_NUMBER 0 #ifdef CONFIG_MISC_INIT_R -#define FU540_OTP_BASE_ADDR 0x10070000 - -struct fu540_otp_regs { - u32 pa; /* Address input */ - u32 paio; /* Program address input */ - u32 pas; /* Program redundancy cell selection input */ - u32 pce; /* OTP Macro enable input */ - u32 pclk; /* Clock input */ - u32 pdin; /* Write data input */ - u32 pdout; /* Read data output */ - u32 pdstb; /* Deep standby mode enable input (active low) */ - u32 pprog; /* Program mode enable input */ - u32 ptc; /* Test column enable input */ - u32 ptm; /* Test mode enable input */ - u32 ptm_rep;/* Repair function test mode enable input */ - u32 ptr; /* Test row enable input */ - u32 ptrim; /* Repair function enable input */ - u32 pwe; /* Write enable input (defines program cycle) */ -} __packed; - -#define BYTES_PER_FUSE 4 -#define NUM_FUSES 0x1000 - -static int fu540_otp_read(int offset, void *buf, int size) +#if CONFIG_IS_ENABLED(SIFIVE_OTP) +static u32 otp_read_serialnum(struct udevice *dev) { - struct fu540_otp_regs *regs = (void __iomem *)FU540_OTP_BASE_ADDR; - unsigned int i; - int fuseidx = offset / BYTES_PER_FUSE; - int fusecount = size / BYTES_PER_FUSE; - u32 fusebuf[fusecount]; - - /* check bounds */ - if (offset < 0 || size < 0) - return -EINVAL; - if (fuseidx >= NUM_FUSES) - return -EINVAL; - if ((fuseidx + fusecount) > NUM_FUSES) - return -EINVAL; + int ret; + u32 serial[2] = {0}; - /* init OTP */ - writel(0x01, ®s->pdstb); /* wake up from stand-by */ - writel(0x01, ®s->ptrim); /* enable repair function */ - writel(0x01, ®s->pce); /* enable input */ - - /* read all requested fuses */ - for (i = 0; i < fusecount; i++, fuseidx++) { - writel(fuseidx, ®s->pa); - - /* cycle clock to read */ - writel(0x01, ®s->pclk); - mdelay(1); - writel(0x00, ®s->pclk); - mdelay(1); - - /* read the value */ - fusebuf[i] = readl(®s->pdout); - } + for (int i = 0xfe * 4; i > 0; i -= 8) { + ret = misc_read(dev, i, serial, sizeof(serial)); - /* shut down */ - writel(0, ®s->pce); - writel(0, ®s->ptrim); - writel(0, ®s->pdstb); + if (ret != sizeof(serial)) { + printf("%s: error reading serial from OTP\n", __func__); + break; + } - /* copy out */ - memcpy(buf, fusebuf, size); + if (serial[0] == ~serial[1]) + return serial[0]; + } - return 0; + return ERROR_READING_SERIAL_NUMBER; } +#endif static u32 fu540_read_serialnum(void) { + u32 serial = ERROR_READING_SERIAL_NUMBER; + +#if CONFIG_IS_ENABLED(SIFIVE_OTP) + struct udevice *dev; int ret; - u32 serial[2] = {0}; - for (int i = 0xfe * 4; i > 0; i -= 8) { - ret = fu540_otp_read(i, serial, sizeof(serial)); - if (ret) { - printf("%s: error reading from OTP\n", __func__); - break; - } - if (serial[0] == ~serial[1]) - return serial[0]; + /* init OTP */ + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_GET_DRIVER(sifive_otp), &dev); + + if (ret) { + debug("%s: could not find otp device\n", __func__); + return serial; } - return 0; + /* read serial from OTP and set env var */ + serial = otp_read_serialnum(dev); +#endif + + return serial; } static void fu540_setup_macaddr(u32 serialnum)