From patchwork Thu Jul 9 11:17:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1470 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C97533F062 for ; Thu, 9 Jul 2020 13:18:49 +0200 (CEST) Received: by mail-pl1-f199.google.com with SMTP id c15sf1017540plz.15 for ; Thu, 09 Jul 2020 04:18:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594293528; cv=pass; d=google.com; s=arc-20160816; b=tsaPTQIybYpnsSq0YfssbBtCMvjfz+oDNJeYD056uaG3ZzOKdMh3gBIV8QJS5jOehr czh8FSuXcjkaJoR8JZzU/fFGvp9GVsqD9+xYk92JvtOqtr8EMuOtCh28RxOxxu0QdsVb +/wZJgBtIQJ8cbaqPZhQ/3tYdvisvEvbRBHIbjET1JHB4rve6uHXUFsd3qS+IuNlOyLS m6N7+NlNVYtfHHObfujOPzVYfmPPW5Z1Dh4PL3XzExgvR0wYMhPUPfDpViR721OxxsGF gYjJfhAzjYKk8RsI68r5bhyQCKuHzj7z5OWlwh0/20EobkFWs9j8ga+gyrR9OySafY09 elIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=PDyVQZccKp3eg6Y4PBguJ69R7Lci7ehh3MkBlBRblwE=; b=R8aGkh+IptczbYSmv+TgLbe0NZyBewYwIGzng2YbuG82Qs5BzCk25IaaSnV84uDOFO 6U8z0L2L4VhUsppcTLza7p9+r7jGnFe9tEGFLivjQf4Hg4c+IIe7o1Rjqmtd8iLinU0Z j/uHGIRrt7QAqBWX8ek4kBBnrlkzcx1J9q8eV5eI/m1AfBur241QxA+g+Fu96ykDH/gd QbqRA9TOIt8ThMITJ+nxfXFBTINVVNTIenkUmlMQuoXQHzJCUIro6VS14Myc9Mhzn4Qz j17JkIyI9XDV/Ak14CTIDq4SJNMW0eEHrUHNirlOR6PpbHDIYww7fhFOqQGHxKcGoa+S iEAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GBbvuvVZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=PDyVQZccKp3eg6Y4PBguJ69R7Lci7ehh3MkBlBRblwE=; b=KA9HWRLv5ug9fElTSq/8+rsvzcjH3f12M4u0o6cPPmSJV1p3rKyVg4hM3P9jsbx7G9 vQqKCBvNwxvbQpDMkQhq9X7rLT0wnjNBsOoFyv3keUvIz0I3AMT3H+Pm/V9yE6RyLc24 vg2CGqXCYMohi9EZaoiQj7ou/89sVzzNMDQak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=PDyVQZccKp3eg6Y4PBguJ69R7Lci7ehh3MkBlBRblwE=; b=ReLYzza4GwekL826f6QuebhgbPz+oPYD6819gd6GLzXQx9cAHlqNyxGbBlPDgdNvmE A86t6PyaJdP1uF3ROuItWDliRGLxN93wNx/vI0pB5qqnQzJ5Y5Nf7o8cegS1CpYrIEh6 TCfHVbO8Ug+EdzMB2r2kvRCIFtGUjmMALqwXe5zNghz6UL2J2dxHgndxxlBERuEfu5WN DhEvwe5n4WxpUHAJKatBfrjZDSEQR/A8rletNTgk2BkypDX67jrD/wwW/70Qc+mVwVEZ GdurrXCroNAd+A0JOfT/s3EugoR5kBIh4xveynY1KFtisiWf0v81ekwNUhong9SuwDua HOYQ== X-Gm-Message-State: AOAM53239XStWpQW4fRag6renAS74E6GSfskJRB8LYd3riK3Yb7MkESJ ooRV2cwBY1RF/W0RzgG/MRip0pgQ X-Google-Smtp-Source: ABdhPJy0459r+ZfCEcfmdrrewbBhgmUbc27WGIwiz21eWCmtjAMzU5vszurfRX8CikYFJE+95TNc+A== X-Received: by 2002:a17:902:d352:: with SMTP id l18mr11081445plk.56.1594293528252; Thu, 09 Jul 2020 04:18:48 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:d917:: with SMTP id c23ls2495310pjv.0.canary-gmail; Thu, 09 Jul 2020 04:18:48 -0700 (PDT) X-Received: by 2002:a17:90a:e60b:: with SMTP id j11mr14720726pjy.189.1594293527772; Thu, 09 Jul 2020 04:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594293527; cv=none; d=google.com; s=arc-20160816; b=zrx+B+5hr7W3trcE7uXL5THgP5ptGVR6GePe9KuYgsYxtbo0lSaAV/3qqYh/rH87fn tD5FYkhUVULwt1iRRoe6eFbcFrbDuiCJx3i9HaN0ECjUq0D0bSFVMZiS9IxgOCVzAh3O 28wbS3b4xExBpvCIhnSrQwQSeu0eW9b1EHZltY3Ywpvy/MGk3bBhKP/16+d0p+G8ZFm3 DAiXQp45LTuzhBpx6SJFdPDPVJ+61EC7sjkvHppJv+2B7dbv3mI2VVc4gepY/oreoYM0 wcUHHlfImIdsm4N5DSUbEtvY+3FF2Al0FChfT5iekKgLBPrxp3djsS49kz/tv2dxnB/x XBvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=E8MraylLf+bM1MLkozuNPGY4jENjgogx+SpV3wdeM8g=; b=LKdufscJQLLM5IWcaPVhnnRUyNRTmz+dePfpxFwmdIqvTRyTjlXcEQLivKCmA7MV5g fDSd5r9SNvQK+HeZY0JEsZZE5hbEGwzlX4SXrX8YV/8AE0SgTnBeLEkyDfhjRRmewvOO MO1ZIQd57m6YGGzBl5meKMnv+mxmoRcVKjPLNYjtXM6SiL/M9/tRkRQg15G66i/hPVu2 rf/KumP01bGD2hvDpbbgKmus3xCZEniEo4EGrjCD04fCxOfJx5iEs88xXNwmUU6B6cBp /NwVC7FvhglByj2z/ejSOrj8w7MnuVSIJ8rSA6kkDnMzk1HrhC7QMSGkBuG6PddHVqC9 SLPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GBbvuvVZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x7sor3403726pla.17.2020.07.09.04.18.47 for (Google Transport Security); Thu, 09 Jul 2020 04:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:854c:: with SMTP id d12mr54740284plo.343.1594293527329; Thu, 09 Jul 2020 04:18:47 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:24b9:69b0:e917:1d11]) by smtp.gmail.com with ESMTPSA id o23sm2608130pfd.126.2020.07.09.04.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:18:46 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Cc: Simon Glass , Vignesh R , Tom Rini , Peng Fan , Daniel Schwierzeck , linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH 2/5] mtd: Add dm-mtd core ops Date: Thu, 9 Jul 2020 16:47:06 +0530 Message-Id: <20200709111709.68904-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200709111709.68904-1-jagan@amarulasolutions.com> References: <20200709111709.68904-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GBbvuvVZ; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , - Add generic mtd operations for UCLASS_MTD - Add mtd_dread|derase|dwrite The respetive MTD_UCLASS drivers must install the hooks to these mtd_ops and other core ops are act as a interface b/w drivers vs command code. Cc: Simon Glass Cc: Vignesh R Signed-off-by: Jagan Teki --- drivers/mtd/mtd-uclass.c | 38 +++++++++++++++++++++++++++++++++++++ include/mtd.h | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c index 5418217431..bb00336a60 100644 --- a/drivers/mtd/mtd-uclass.c +++ b/drivers/mtd/mtd-uclass.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Copyright (c) 2020 Amarula Solutions(India) + * Copyright (c) 2020 Jagan Teki * Copyright (C) 2015 Thomas Chou */ @@ -8,6 +10,42 @@ #include #include #include +#include + +int mtd_dread(struct udevice *dev, loff_t from, size_t len, u_char *buf) +{ + const struct mtd_ops *ops = mtd_get_ops(dev); + + if (!ops->read) + return -EOPNOTSUPP; + + return ops->read(dev, from, len, buf); +} + +int mtd_derase(struct udevice *dev, loff_t off, size_t len) +{ + const struct mtd_ops *ops = mtd_get_ops(dev); + struct erase_info instr; + + if (!ops->erase) + return -EOPNOTSUPP; + + memset(&instr, 0, sizeof(instr)); + instr.addr = off; + instr.len = len; + + return ops->erase(dev, &instr); +} + +int mtd_dwrite(struct udevice *dev, loff_t to, size_t len, const u_char *buf) +{ + const struct mtd_ops *ops = mtd_get_ops(dev); + + if (!ops->write) + return -EOPNOTSUPP; + + return ops->write(dev, to, len, buf); +} /** * mtd_probe - Probe the device @dev if not already done diff --git a/include/mtd.h b/include/mtd.h index b0f8693386..b94afe8945 100644 --- a/include/mtd.h +++ b/include/mtd.h @@ -8,6 +8,47 @@ #include +struct mtd_ops { + int (*erase)(struct udevice *dev, struct erase_info *instr); + int (*read)(struct udevice *dev, loff_t from, size_t len, + u_char *buf); + int (*write)(struct udevice *dev, loff_t to, size_t len, + const u_char *buf); +}; + +#define mtd_get_ops(dev) ((struct mtd_ops *)(dev)->driver->ops) + +/** + * mtd_dread() - Read data from mtd device + * + * @dev: mtd udevice + * @from: Offset into device in bytes to read from + * @len: Length of bytes to read + * @buf: Buffer to put the data that is read + * @return 0 if OK, -ve on error + */ +int mtd_dread(struct udevice *dev, loff_t from, size_t len, u_char *buf); + +/** + * mtd_dwrite() - Write data to mtd device + * + * @dev: mtd udevice + * @to: Offset into device in bytes to write to + * @len: Length of bytes to write + * @buf: Buffer containing bytes to write + * @return 0 if OK, -ve on error + */ +int mtd_dwrite(struct udevice *dev, loff_t to, size_t len, const u_char *buf); + +/** + * mtd_derase() - Erase blocks of the mtd device + * + * @dev: mtd udevice + * @instr: Erase info details of mtd device + * @return 0 if OK, -ve on error + */ +int mtd_derase(struct udevice *dev, loff_t off, size_t len); + int mtd_probe(struct udevice *dev); int mtd_probe_devices(void);