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: 1325911 X-Patchwork-Delegate: trini@ti.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=GBbvuvVZ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4B2Yb40LPhz9s1x for ; Thu, 9 Jul 2020 21:18:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 38687821F0; Thu, 9 Jul 2020 13:18:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.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=amarulasolutions.com header.i=@amarulasolutions.com header.b="GBbvuvVZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F24C7821F6; Thu, 9 Jul 2020 13:18:51 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 18469821F0 for ; Thu, 9 Jul 2020 13:18:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jagan@amarulasolutions.com Received: by mail-pj1-x1041.google.com with SMTP id gc9so974204pjb.2 for ; Thu, 09 Jul 2020 04:18:49 -0700 (PDT) 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:content-transfer-encoding; bh=E8MraylLf+bM1MLkozuNPGY4jENjgogx+SpV3wdeM8g=; b=GBbvuvVZ0z5PmiFNWNfdd4kdPhBJcRBzRgvZ7oqUpmKHUG03b+3Vy2nw+XaXMaxG3U 8XviukeLgi2I4WJSD86sBvb7PIUSp9U9jB/vUzpFEzbHInflKUj2cSUiPw7TApDSQu5x 6BMUEUz2TrdEXT+UoefplSy6ln6Dc8vY2r5CU= 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:content-transfer-encoding; bh=E8MraylLf+bM1MLkozuNPGY4jENjgogx+SpV3wdeM8g=; b=a9835ZMdtaVtixTqeyS9cgZ9dI2IrNEhbmgoIkxHROork9QbewwQfshY7GIQrDN8qS FMIN39GJLYXD8XTz6U4VTO8tc2XL2c1vBaURmSmcYzZ/1VB05gfBz/9iYTpNsbVQFYJn zGNPzwINc2FVNmhTqv6nlJNpC5LQGhSwgJyIEq7mM1zVdRODPnU4cQXH0ZDwN0PAugmv ucMVQ5CWU7vMgyaV7DxrnNkIFfFU2GFMaUdTdpzItpdUv/fgtLG99KcqTGRKg7NyQwWk zFmpAgavZCy/edx1jr+wjyE+t5nk28+3epzzDjgONldQ7O96dg+OYhIYrscWaSkpdbh0 bNCg== X-Gm-Message-State: AOAM5310Ag14RrgTEiPmuCz6bw4tczbLc6wexKQfvrXY3iHAfM2kffDs f/ERgBnmWAaqAkpFIOK8E2SlMBZojUg= X-Google-Smtp-Source: ABdhPJzLlnNiR8HergkM4ZHX8y77cfIWv4EYTElnFfXLpIJVZ8kSemWXJjF6cstO4tmxRDxGeI4xEQ== 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-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.3 at phobos.denx.de X-Virus-Status: Clean - 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);