From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91513C433EF for ; Mon, 25 Apr 2022 15:24:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0A3E583B4C; Mon, 25 Apr 2022 17:24:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="efUKUlDo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3A7083BBF; Mon, 25 Apr 2022 17:24:18 +0200 (CEST) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03on062c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe09::62c]) (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 506548331B for ; Mon, 25 Apr 2022 17:24:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TQPUtzLnnfqCZ4WgeR5/MtP/wn5kUOjg8RmXuIVn5hNNkKewjXARU2t+b7r8VNzOpHu6ke61g0AVri2Uru+7wwbLf6yZhqV1PjNn4qhr+x5qsPHjp2bjK9W6R9r64JXYEZus7WDZoWfIMKgw3Xel7VypZVL58LNdTLifU2gj2kXgXXJiIrac7Unxb1SNTsrUCFDYiD8YpIaOaXHA9HgKEfBsu+E9yI2GF0Bb7pnSt3eIB/0y/LBjkncFdtFgLThcqtJj6JqITJWllnJKeE0EEW1x1EjrwohEmrfpzWEOqcCNaPUe3mgBfm4mySbWtqW5d8G0HpDll0iflYozJjHr9Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JRjkENXujibU97LZs2nlQf1xOIZOpj9g3ce16YsMNjs=; b=dydYwIRZeEQw+/4YWdH/jDZubAeuaKjDw7oyWiCczJKLC0VLpNGN0W57fM0Q+sLwcvv3cOXY0DfM70/0G6Ngnq69NFAqveSwoljckeSbvnDF64WTXxl2a2or28aTnuleyZEemQGFp9oiPeDBx2rmQEM2xGMm5V9se7NQs3DjgjSPuVAP+tPrs55HZZ15jfde+oG5JVw35toOy/3t74bZIX7FtTpGuC07NqvxdqgkNCetHVYaq1KjS/DiV7fbGKynNFZDZgy1tWKy0FQ4kvOH37swgo0FKaFo37hpGAxb31yEYyjoAKsZwh1FAopy3y7lQ/6c4lbHvJLzEibDEu3zfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JRjkENXujibU97LZs2nlQf1xOIZOpj9g3ce16YsMNjs=; b=efUKUlDot/F45rPyZMLn6inyj3eELrDodqaLs5PiXoW46MMWlJo750SwXPbXPePeAbeOqmyDF+l8FlpdLTvBBVNAUUacnt8RzkEZslSyq8hLE/u/UoBIqGUmgpFuKFMZFmcYtLxk+Cf0Cz+wzrNdpuesthSfqnUAhHNfMnkjbO5TeJVUq5d8TzIpiD65tM9gEkpx/y4KYTRWQJ7pQwUdwWBPtJ37JYIa+qyYoZKTjIxUKBHRiD0t9zVAZEQPx2qcNhmZUMGndkjAufSrX4L9IG80V0yBxk5hoYqCZUgWlmVWFXGXp2ER2OI0mhPt+PQGeNV5nArvOjW+wPD6CVBmgQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by VE1PR03MB5248.eurprd03.prod.outlook.com (2603:10a6:802:ac::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.21; Mon, 25 Apr 2022 15:24:13 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::714d:2b6:a995:51bd]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::714d:2b6:a995:51bd%4]) with mapi id 15.20.5186.021; Mon, 25 Apr 2022 15:24:13 +0000 Subject: Re: [PATCH v3 08/13] misc: Add support for nvmem cells To: Simon Glass Cc: U-Boot Mailing List , Mario Six , Ramon Fried , Heinrich Schuchardt , Tom Rini , Joe Hershberger References: <20220418193659.3677824-1-sean.anderson@seco.com> <20220418193659.3677824-9-sean.anderson@seco.com> From: Sean Anderson Message-ID: <32a295f1-f2c8-080e-b3f6-30f0dee6e25d@seco.com> Date: Mon, 25 Apr 2022 11:24:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL0PR1501CA0036.namprd15.prod.outlook.com (2603:10b6:207:17::49) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d455834f-7b08-4044-9c49-08da26cfa74e X-MS-TrafficTypeDiagnostic: VE1PR03MB5248:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kPXuCYV0K1t1QNDJyoDN/P8W/oRFy5YjapB4SOoRIDI9mK3SM3I8NawlYMSoxT0BUQg4gzQeWXxfzSo2P2hEpBaRLQUfA4TVLwbD1lju1td+sfAYMG9ldFhkaJMINrvCZWxNl415EqnBmSqpPErg/Zq0djVj/KH0FNlFh9fKa5VAoBLz9XJBg/x0ltzHgk6z/gynez/tbxppiFogN7Jr+3NU4Z2FYzJP+9dNORwpsFZi/X/sta2HEtzu9SlUbAqRI5DFyA1xsyhQr3zBUGC6s99vwMDA4us81RNklyX6YD+lmKPyQpS9DcQU72OR+pxatLuXXlOqw9cTHE63/hXrXbDK1zbIuD9MmzJJ7r5xSUZyNenS6FCCPa7doyvLx1d1yzXHRY9JyJ/WK4FCBOvZiWqXGLinpGFhBu89NyOGRtxwlINSWFU4F7xe4gD9Sm+qZl6jgcyB1QAkSCtlaKJapWtV81BdEVBjf8zS0wPYW1hF4JxxNT9rIloZaUpwV5AgVG90Mv0vSs8g3eIrlR9LKhNusrOClkZClVY+30nN90XimW2PHuMVPdOdALba7hjp4QdmgNu9zLK8H14XHtKK1TY+Cj9Mj21W2bIGvwm8lpvB+50wzNT7eQHWuWTPHvF0U2+BJUyicFYjMrZjSVColCCYO1Q1x2apOFIx9D6gbke5VTLyTU1GwZjedOJDV5dDguxlrgQpaLvxJjRkRY3IquOGz+mMcYYCmC3ewuBiiy/xYCeCOjoN0RPhDS2oRbDv2G6a6qlgVCW5c2D7sN0bYA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(2616005)(66946007)(66556008)(6512007)(8676002)(52116002)(66476007)(26005)(6506007)(4326008)(6916009)(54906003)(31696002)(316002)(6486002)(6666004)(86362001)(508600001)(53546011)(186003)(38100700002)(83380400001)(38350700002)(2906002)(44832011)(31686004)(8936002)(5660300002)(36756003)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aUJiUXRJWTZtZ0wzbFRMRjhheDJCRER4Vm9YYUpDTVo2NklpUmxsZWhZVUE0?= =?utf-8?B?UkVlYURRMUNkREFEY3BUQ1RQS3FvcUJDcmd1THFhTW9CWlN0SzBsMDdESHVw?= =?utf-8?B?YWYxYXV3ZE9lOFNCc0twYytuY2g0WnlkWk9xN0ZuUS9yUytkWFpVVUxpQXV6?= =?utf-8?B?WjFJTlFZdy8rb0hraHg3TmRJVyt3MEQ4bTUxRU9keTB2OEs0VUl1Tm43V0pv?= =?utf-8?B?YW1GOWFvWXR4aExLeDhrM0hBUVRVeUJpLzFJUmMrdWJmaDlnRjM2ZVoxQTNF?= =?utf-8?B?NU5TaFVlRHhCSlBibEc5c2I5dUNWQ3o3TTlEVjY5WHU2TlBhNytROUxIQzNB?= =?utf-8?B?UHFzSkVRNE5kWUtsUGRJeTJVb3dDb25QK3VwTGdJTER3aXNKZlJSUkVmOUJ6?= =?utf-8?B?WVBQZ2FVK3cxdlFOdkFzcVVHbytpbnFIVHdhYk1uNktCQm5DUHczbzl4ZE1O?= =?utf-8?B?WFdFazBOM01FYXJ0ajlZRTNPOGVpWllBaldHWC9mT3h0S1VvS1lWS0JUUk5D?= =?utf-8?B?QW5aQUZpbUxNc0ZtVUZrMmxsd04zcmVzeUVmc0c3Qmd6Y0dlME1VL08rUUpC?= =?utf-8?B?QkdrMzA0Rzh2ZmRNU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Message-Id: d455834f-7b08-4044-9c49-08da26cfa74e X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2022 15:24:13.6191 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cNlA6PNgl5B7p8V8M/VduJED8dLb7rPGpBKdfb2elxxZWy2U6UegaFWqLyojdeZffP9U3+Kw4BQmMFNbcFnB7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5248 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean On 4/25/22 1:48 AM, Simon Glass wrote: > Hi Sean, > > On Mon, 18 Apr 2022 at 13:37, Sean Anderson wrote: >> >> This adds support for "nvmem cells" as seen in Linux. The nvmem device >> class in Linux is used for various assorted ROMs and EEPROMs. In this >> sense, it is similar to UCLASS_MISC, but also includes >> UCLASS_I2C_EEPROM, UCLASS_RTC, and UCLASS_MTD. New drivers corresponding >> to a Linux-style nvmem device should be implemented as one of the >> previously-mentioned uclasses. The nvmem API acts as a compatibility >> layer to adapt the (slightly different) APIs of these uclasses. It also >> handles the lookup of nvmem cells. >> >> While nvmem devices can be accessed directly, they are most often used >> by reading/writing contiguous values called "cells". Cells typically >> hold information like calibration, versions, or configuration (such as >> mac addresses). >> >> nvmem devices can specify "cells" in their device tree: >> >> qfprom: eeprom@700000 { >> #address-cells = <1>; >> #size-cells = <1>; >> reg = <0x00700000 0x100000>; >> >> /* ... */ >> >> tsens_calibration: calib@404 { >> reg = <0x404 0x10>; >> }; >> }; >> >> which can then be referenced like: >> >> tsens { >> /* ... */ >> nvmem-cells = <&tsens_calibration>; >> nvmem-cell-names = "calibration"; >> }; >> >> The tsens driver could then read the calibration value like: >> >> struct nvmem_cell cal_cell; >> u8 cal[16]; >> nvmem_cell_get_by_name(dev, "calibration", &cal_cell); >> nvmem_cell_read(&cal_cell, cal, sizeof(cal)); >> >> Because nvmem devices are not all of the same uclass, supported uclasses >> must register a nvmem_interface struct. This allows CONFIG_NVMEM to be >> enabled without depending on specific uclasses. At the moment, >> nvmem_interface is very bare-bones, and assumes that no initialization >> is necessary. However, this could be amended in the future. >> >> Although I2C_EEPROM and MISC are quite similar (and could likely be >> unified), they present different read/write function signatures. To >> abstract over this, NVMEM uses the same read/write signature as Linux. >> In particular, short read/writes are not allowed, which is allowed by >> MISC. >> >> The functionality implemented by nvmem cells is very similar to that >> provided by i2c_eeprom_partition. "fixed-partition"s for eeproms does >> not seem to have made its way into Linux or into any device tree other >> than sandbox. It is possible that with the introduction of this API it >> would be possible to remove it. > > I still think this would be better as a separate uclass, with child > devices created at bind time in each of the respective uclasses, like > mmc_bind() does. Then you will see the nvmem devices in the DM tree. > Wouldn't we want to add a command to access the nvmem devices? We already do. E.g. the misc/rtc/eeprom commands. The problem is that for software to access them, they would have to use misc_read/dm_rtc_read/ i2c_eeprom_read. > This patch feels like a shortcut to me and I'm not sure of the > benefit of that shortcut. Well, I suppose it's because "nvmem" devices are strict subsets of existing devices. There is no new functionality here (except adapting between semantics like for misc). We should always be able to use the existing API to implement support for a new underlying uclass. There should never be device-specific read/write methods, because we can use the existing read/write uclass methods. What I'm trying to get at is that we sort of already have an nvmem uclass with nvmem devices, they're just not accessible in a uniform way. This series is trying to address the uniformity aspect. But I don't think we need new devices for each nvmem interface, because all they would do would take up ram/rom. --Sean PS. In an ideal world we'd have something like struct nvmem_ops { read(); write(); }; struct dm_rtc_ops { nvmem_ops nvmem; /* the other ops minus read/write */ }; int nvmem_read (...) { struct nvmem_ops *ops = cell->nvmem->ops; /* ... */ return ops->read(...); } but unfortunately, we already have fragmented implementations.