From patchwork Mon Jun 22 23:09:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 6658301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8A318C05AC for ; Mon, 22 Jun 2015 23:13:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CE50205B4 for ; Mon, 22 Jun 2015 23:13:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47893205B3 for ; Mon, 22 Jun 2015 23:13:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z7Arq-00072I-Eq; Mon, 22 Jun 2015 23:11:06 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z7AqL-0004yA-WB for linux-arm-kernel@lists.infradead.org; Mon, 22 Jun 2015 23:09:35 +0000 Received: by wguu7 with SMTP id u7so81556174wgu.3 for ; Mon, 22 Jun 2015 16:09:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9+r9zC3QhshpBOEpI4Vromyn0o9LYBLX4GI/LgSG95E=; b=mHSc6b+OyPZRYRakXXat+VnyHRnsjxzvFvYdbY8qyEWS5KVDeFsXSgD5BibGiRxFnU mbKdxMZ/Qt10+CcdLczBxOnA67XZe5h5wYGXitA/5eqSoJ9/8X9s9d2B+UurRaKL2bM6 rj5juBledDVWkxPmmqEjimGF0xuW7ODdtIU3uh682NYf5CacsPcKDPo+gmcoKiexAazk 4D/EqBBoVqqWrZsU5PIjko8NApMBLdO2htKwUcYoe+Q3iV3nNyeBD9x6GLu69Xq+AlXr DnXf37eqkQQ0QZlPRtFPu5tQYv33DV/tUIK7QoElGFwDR1gdQTdysaD7MFLHlz8mvKtu dmuQ== X-Gm-Message-State: ALoCoQkkG/+WM+BQdFOqviaTXnhyUfYtkRpX/AwpsVkAXVL1muPO8lhMIyv1dPgx6RkCUrQ2Mlq4 X-Received: by 10.194.200.73 with SMTP id jq9mr55743630wjc.52.1435014551905; Mon, 22 Jun 2015 16:09:11 -0700 (PDT) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-2-98-208-65.as13285.net. [2.98.208.65]) by mx.google.com with ESMTPSA id tl3sm32717381wjc.20.2015.06.22.16.09.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Jun 2015 16:09:11 -0700 (PDT) From: Srinivas Kandagatla To: linux-arm-kernel@lists.infradead.org, Greg Kroah-Hartman Subject: [PATCH v6 5/9] Documentation: nvmem: add nvmem api level and how-to doc Date: Tue, 23 Jun 2015 00:09:07 +0100 Message-Id: <1435014547-26350-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435014459-26138-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1435014459-26138-1-git-send-email-srinivas.kandagatla@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150622_160934_370110_DB35E1D3 X-CRM114-Status: GOOD ( 19.47 ) X-Spam-Score: -2.6 (--) Cc: stefan.wahren@i2se.com, devicetree@vger.kernel.org, arnd@arndb.de, linux-api@vger.kernel.org, s.hauer@pengutronix.de, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, pantelis.antoniou@konsulko.com, Rob Herring , Srinivas Kandagatla , Mark Brown , Kumar Gala , mporter@konsulko.com, Maxime Ripard , linux-arm-msm@vger.kernel.org, wxt@rock-chips.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add basic how-to and api summary documentation for simple NVMEM framework. Signed-off-by: Srinivas Kandagatla --- Documentation/nvmem/nvmem.txt | 151 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 Documentation/nvmem/nvmem.txt diff --git a/Documentation/nvmem/nvmem.txt b/Documentation/nvmem/nvmem.txt new file mode 100644 index 0000000..28b3579 --- /dev/null +++ b/Documentation/nvmem/nvmem.txt @@ -0,0 +1,151 @@ + NVMEM SUBSYSTEM + Srinivas Kandagatla + +This document explains the Simple NVMEM Framework along with the APIs provided, +and how-to-use. + +1. Introduction +=============== +*NVMEM* is the abbreviation for Non Volatile Memory layer. It is used to +retrieve configuration or SOC or Device specific data from a non volatile memories +like eeprom, efuses and so on. + +Up until now, NVMEM drivers like eeprom were stored in drivers/misc, where they +all had to duplicate pretty much the same code to register a sysfs file, allow +in-kernel users to access the content of the devices they were driving, etc. + +This was also a problem as far as other in-kernel users were involved, since +the solutions used were pretty much different from on driver to another, there +was a rather big abstraction leak. + +Introduction of this framework aims at solving this. It also introduces DT +representation for consumer devices to go get the data they require (MAC +Addresses, SoC/Revision ID, part numbers, and so on) from the NVMEMs. +This framework is based on regmap, so that most of the abstraction +available in regmap can be reused, across multiple types of buses. + +NVMEM Providers ++++++++++++++++ + +NVMEM provider refers to an entity that implements methods to initialize, read +and write the non-volatile memory. + +2. Registering/Unregistering the NVMEM provider +=============================================== + +A NVMEM provider can register with NVMEM core by suppling relevant +nvmem configuration to nvmem_register(), on success core would return a valid +nvmem_device pointer. + +nvmem_unregister(nvmem) is used to unregister the already registered provider. + +For example for simple qfprom case: + +static struct nvmem_config econfig = { + .name = "qfprom", + .owner = THIS_MODULE, +}; + +static int qfprom_probe(struct platform_device *pdev) +{ + ... + econfig.dev = &pdev->dev; + nvmem = nvmem_register(&econfig); + ... +} + +It is mandatory that the NVMEM provider has a regmap associated with its +struct device. + +NVMEM Consumers ++++++++++++++++ + +NVMEM consumers are the entities which make use of the NVMEM provider to +read/write into NVMEM. + +3. NVMEM cell based consumer APIs. +================================= + +NVMEM cells are the data entries/fields in the NVMEM. +The NVMEM framework provides 3 APIs to read/write NVMEM cells. + +struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); +struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); + +void nvmem_cell_put(struct nvmem_cell *cell); +void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); + +void *nvmem_cell_read(struct nvmem_cell *cell, ssize_t *len); +int nvmem_cell_write(struct nvmem_cell *cell, void *buf, ssize_t len); + +*nvmem_cell_get() apis will get a reference to nvmem cell for a given id, +and nvmem_cell_read/write() can then directly read or write to the cell. +Once the usage of the cell is finished the consumer should call *nvmem_cell_put() +to free all the allocation memory for the cell. + +4. Direct NVMEM device based consumer APIs. +========================================== + +In some instances it is necessary to directly read/write the NVMEM. +To facilitate such consumers NVMEM framework provides below apis. + +struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); +struct nvmem_device *devm_nvmem_device_get(struct device *dev, + const char *name); +void nvmem_device_put(struct nvmem_device *nvmem); +int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, + size_t bytes, void *buf); +int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, + size_t bytes, void *buf); +int nvmem_device_cell_read(struct nvmem_device *nvmem, + struct nvmem_cell_info *info, void *buf); +int nvmem_device_cell_write(struct nvmem_device *nvmem, + struct nvmem_cell_info *info, void *buf); + +Before the consumers can read/write NVMEM directly, it should get hold +of nvmem_controller from one of the *nvmem_device_get() api. + +Difference between these apis and cell based apis is that these apis +always take nvmem_device as parameter. + +5. Releasing a reference to the NVMEM +===================================== + +When the consumers no longer needs the NVMEM, it has to release the reference +to the NVMEM it has obtained using the APIs mentioned in the above section. +NVMEM framework provides 2 APIs to release a reference to the NVMEM. + +void nvmem_cell_put(struct nvmem_cell *cell); +void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); +void nvmem_device_put(struct nvmem_device *nvmem); +void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); + +Both these APIs are used to release a reference to the NVMEM and +devm_nvmem_cell_put and devm_nvmem_device_put destroys the devres associated +with this NVMEM. + +Userspace ++++++++++ + +6. Userspace binary interface. +============================== + +Userspace can read/write the raw NVMEM file located at /sys/class/nvmem/*/nvmem + +ex: + +hexdump /sys/class/nvmem/qfprom0/nvmem + +0000000 0000 0000 0000 0000 0000 0000 0000 0000 +* +00000a0 db10 2240 0000 e000 0c00 0c00 0000 0c00 +0000000 0000 0000 0000 0000 0000 0000 0000 0000 +... +* +0001000 + +7. DeviceTree Binding +===================== + +The documentation for NVMEM dt binding can be found @ +Documentation/devicetree/bindings/nvmem/nvmem.txt