From patchwork Thu Jul 9 11:17:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1469 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id A980A3F062 for ; Thu, 9 Jul 2020 13:18:19 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id o5sf1098175pfg.10 for ; Thu, 09 Jul 2020 04:18:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594293498; cv=pass; d=google.com; s=arc-20160816; b=LPwGk5+aMooYJBi79z5yTPW28rbJEmwCOJoJ6lB7YqVWqPGU9suhUz/K4qFki+EzBR U6J/5GQ5+M0y1Hv1sRoSl6Fn98d1hgNhV83owp367L37OC4gtK12MgBptrt7dhHY2r0i E9KF4huXu2cfL6q5MafzjCAggUT1syHo06HaXB72ulE4lhqFDyDYAsP1TZ94Lp1Q8zGR k/n6dQJHaMj46WMAUTupB22Awt8Yoc43QTWzswX0NR8T4VirwnEnXvM9F09wQSfKlj13 4Vsb6RIn7sNG5tNlI0LY7KZBC5TiOQ4Dko89dBZ42mWQ7z3PvDppFyBf/5okGi7zfCWa rJZQ== 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=2rBawJtUGXZCNzjKETlUKM0bGE+qnYWQfcmcTnvwrkw=; b=FDMFTkwCWCBywYVmHljj7jeoXDwUW12vFD7VbTWpm3dH8QFT/3pditvYTYTvUHUeze zOMRugvVFKcbN11i0H6YB7VJooe87f3rXrKxHk/CtyHG+GuHzHk/IUyLzAUr1aHJzjVm ObrycSGzVW7QdnRkAmoJpUZj4rcMF1fst2VfAIodaLLlHTOxlDVIGMjRhLlUAqgH3eTb 66/qVpYMgyFAv5PbHyIW0TbwuYDjH6R6m1Mg7R4qFPywrAmjKCGPA9RevTgDfkHiu0BY m6/ZjX0k3ZJC6t2jREPxdnnMk2Oc6EZb7TIRArvexJi2+gS22vQ+dLG46rjlhMZo3Ycu 1kXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="gDjgWME/"; 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=2rBawJtUGXZCNzjKETlUKM0bGE+qnYWQfcmcTnvwrkw=; b=GPnNslthWn8kEruv4Gt1HckqoL7a0ysqZGDDp7odgYvSKydLwAZxlni5hWK0EurI0u Z9UFvcE9e67zS/9dCQajpPk1RCsB2Ulvruws3jvunDThYCzg8yNBxeWYjNvir9ZAoFxD 5J7LUhst99KRsdvgGXVj6pVZ2KMDrJCPc7KqQ= 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=2rBawJtUGXZCNzjKETlUKM0bGE+qnYWQfcmcTnvwrkw=; b=YNsO7fq0Bz9/VBEmq+zhL8KB+h3lrCO0YVYqTZ6zOWsE2lRJbiItIVe03ITQgZ7FkM R/5/YroNDksAiLoHNQkN++jVRM8i2gYScjiuLx2kF1rBunsGU8jnUSIdVJEkeSPVXZ+a jMsiVVutMXD/muyMFsT1Mt8kxtFkE6yCfN1TJyD1iFHXeDdlztExV6YX+MHxDgiP4pd0 O2hL8SjMbo4K4ssdHSR5tKjkJ3toq18Q3U6jfKR6VFJIDqP3C41q0+25jRc2kQ7w86b6 TUIruIQ67RgmRd9V+NrgpJwG4Cjkji/ZPb5cJbESZbsIjOlWV1t0xKwKLInRkF/XT9mH tpIQ== X-Gm-Message-State: AOAM530Oe1de2Xe8EVwog8hdXikfGpLNLNysRpm8QtyILgHPDheMJlXz XDy/tNHnAqKyWSq8YzOPUn1t4YyJ X-Google-Smtp-Source: ABdhPJypQvtSdW/l1NLQrNKhDoolaRDNA7FIqvxBOKKbmoBWI6dJYS3ycYQ9VJvuGKon/RhGnG9dgA== X-Received: by 2002:a17:90a:17ad:: with SMTP id q42mr15000850pja.31.1594293498073; Thu, 09 Jul 2020 04:18:18 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:8a16:: with SMTP id w22ls2489420pjn.1.canary-gmail; Thu, 09 Jul 2020 04:18:17 -0700 (PDT) X-Received: by 2002:a17:90a:21c3:: with SMTP id q61mr14528985pjc.207.1594293497596; Thu, 09 Jul 2020 04:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594293497; cv=none; d=google.com; s=arc-20160816; b=w4Aqty7jrU6PhAMSq6+yG10+9kmUAdp1QHgJSqXNEfh1zqjBTCeAsvpkTVgFmbgET5 EvKUth4iD83Zsmfi3h66HgS9DtKKrmqIbb/VFFRvvZboD3zmQ7AGDbWE0LGE1PdkbyF/ PVJ+eGobWkE3hjPJdbOU8f5gBnLrice8EX8r6Fs68ORwFwZWy99D9nNwxQZ1tjKsbF72 yZpd/464v1r9rocaUuz24OUES/6F7cXP8YFtyab08ek7qpl/CIKnPDbXFmLmJDrbRA9K f/7lp8OmHX2OPEeWtb7XbYe1EpPWnqszV56qoPClpRqJ4WY9Cki2SFiR4VS8J6ZIBFpJ ayAA== 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=dWTXPgVcuQSIilDx5HVDf1BAigwkOdvROZZ9CY6KGEE=; b=YkGJs2maExZFaoEClfEOcUjGpUNsAfY1i5JMwGmneaeNuz65L5WwkOqZ1vNFGEjX9T lTrgSYLX66V+VfR/nl0ZTu1AxSvlkSuEG20x2JRHhTD9Kzx841QKqvDJ2/zqtGY1QgAg MP4++J1EOrjAJDZF0eFuH83Cbu8VvyJl1cR67TL0pQFZMgG8ZGaf/m7txRzUVOh6MH14 NPBwib4SiZoR+q/nIz86hVe3IFHGnYRHMiMTzkdLcvtVp+rMK/YKH/R2NcQC4NqJ7yhz Xbpc/D8dd6czyXh0pcQo/A9CjfniAXCT33Q1ZIOZ3YVUVKW7h394jgWRBbqYhdr6SP+D ef9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="gDjgWME/"; 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 f13sor3161235pgj.33.2020.07.09.04.18.17 for (Google Transport Security); Thu, 09 Jul 2020 04:18:17 -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:a63:ba5e:: with SMTP id l30mr37870159pgu.297.1594293497316; Thu, 09 Jul 2020 04:18:17 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:18:16 -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 , Bin Meng Subject: [PATCH 1/5] mtd: spi: Drop redundent SPI flash driver Date: Thu, 9 Jul 2020 16:47:05 +0530 Message-Id: <20200709111709.68904-2-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="gDjgWME/"; 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: , UCLASS_SPI_FLASH driver at driver/mtd/spi is a generic spi flash driver to probe jedec,spi-nor flash chips. Technically a probe call in U_BOOT_DRIVER is local to that driver and not applicable to use it another driver or in another code. The apollolake SPL code using the generic probe by adding extra SPI flash driver, which make more confusion in terms of code readability and driver model structure. The fact that apollolake SPL requires a separate SPI flash driver to handle of-platdata via bind call, so move the bind call in the generic flash driver and drop the driver from apollolake code. I hope this wouldn't break generic code usage flash chips otherwise, we can handle this via driver data or a separate spi driver in drivers/mtd/spi. Cc: Bin Meng Cc: Simon Glass Cc: Vignesh R Signed-off-by: Jagan Teki --- arch/x86/cpu/apollolake/spl.c | 60 ----------------------------------- drivers/mtd/spi/sf-uclass.c | 29 ++++++++++++++++- include/spi_flash.h | 12 ------- 3 files changed, 28 insertions(+), 73 deletions(-) diff --git a/arch/x86/cpu/apollolake/spl.c b/arch/x86/cpu/apollolake/spl.c index 5a53831dc6..e1ee1e0624 100644 --- a/arch/x86/cpu/apollolake/spl.c +++ b/arch/x86/cpu/apollolake/spl.c @@ -68,66 +68,6 @@ SPL_LOAD_IMAGE_METHOD("Mapped SPI", 2, BOOT_DEVICE_SPI_MMAP, rom_load_image); #if CONFIG_IS_ENABLED(SPI_FLASH_SUPPORT) -static int apl_flash_std_read(struct udevice *dev, u32 offset, size_t len, - void *buf) -{ - struct spi_flash *flash = dev_get_uclass_priv(dev); - struct mtd_info *mtd = &flash->mtd; - size_t retlen; - - return log_ret(mtd->_read(mtd, offset, len, &retlen, buf)); -} - -static int apl_flash_probe(struct udevice *dev) -{ - return spi_flash_std_probe(dev); -} - -/* - * Manually set the parent of the SPI flash to SPI, since dtoc doesn't. We also - * need to allocate the parent_platdata since by the time this function is - * called device_bind() has already gone past that step. - */ -static int apl_flash_bind(struct udevice *dev) -{ - if (CONFIG_IS_ENABLED(OF_PLATDATA)) { - struct dm_spi_slave_platdata *plat; - struct udevice *spi; - int ret; - - ret = uclass_first_device_err(UCLASS_SPI, &spi); - if (ret) - return ret; - dev->parent = spi; - - plat = calloc(sizeof(*plat), 1); - if (!plat) - return -ENOMEM; - dev->parent_platdata = plat; - } - - return 0; -} - -static const struct dm_spi_flash_ops apl_flash_ops = { - .read = apl_flash_std_read, -}; - -static const struct udevice_id apl_flash_ids[] = { - { .compatible = "jedec,spi-nor" }, - { } -}; - -U_BOOT_DRIVER(winbond_w25q128fw) = { - .name = "winbond_w25q128fw", - .id = UCLASS_SPI_FLASH, - .of_match = apl_flash_ids, - .bind = apl_flash_bind, - .probe = apl_flash_probe, - .priv_auto_alloc_size = sizeof(struct spi_flash), - .ops = &apl_flash_ops, -}; - /* This uses a SPI flash device to read the next phase */ static int spl_fast_spi_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index b09046fec3..44cdb3151d 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -122,7 +122,7 @@ static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len) return mtd->_erase(mtd, &instr); } -int spi_flash_std_probe(struct udevice *dev) +static int spi_flash_std_probe(struct udevice *dev) { struct spi_slave *slave = dev_get_parent_priv(dev); struct spi_flash *flash; @@ -164,6 +164,32 @@ static int spi_flash_std_remove(struct udevice *dev) return 0; } +/* + * Manually set the parent of the SPI flash to SPI, since dtoc doesn't. We also + * need to allocate the parent_platdata since by the time this function is + * called device_bind() has already gone past that step. + */ +static int spi_flash_std_bind(struct udevice *dev) +{ + if (CONFIG_IS_ENABLED(OF_PLATDATA)) { + struct dm_spi_slave_platdata *plat; + struct udevice *spi; + int ret; + + ret = uclass_first_device_err(UCLASS_SPI, &spi); + if (ret) + return ret; + dev->parent = spi; + + plat = calloc(sizeof(*plat), 1); + if (!plat) + return -ENOMEM; + dev->parent_platdata = plat; + } + + return 0; +} + static const struct dm_spi_flash_ops spi_flash_std_ops = { .read = spi_flash_std_read, .write = spi_flash_std_write, @@ -180,6 +206,7 @@ U_BOOT_DRIVER(spi_flash_std) = { .id = UCLASS_SPI_FLASH, .of_match = spi_flash_std_ids, .probe = spi_flash_std_probe, + .bind = spi_flash_std_bind, .remove = spi_flash_std_remove, .priv_auto_alloc_size = sizeof(struct spi_flash), .ops = &spi_flash_std_ops, diff --git a/include/spi_flash.h b/include/spi_flash.h index 41cf4b0670..24759944eb 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -75,18 +75,6 @@ int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len, */ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len); -/** - * spi_flash_std_probe() - Probe a SPI flash device - * - * This is the standard internal method for probing a SPI flash device to - * determine its type. It can be used in chip-specific drivers which need to - * do this, typically with of-platdata - * - * @dev: SPI-flash device to probe - * @return 0 if OK, -ve on error - */ -int spi_flash_std_probe(struct udevice *dev); - static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf) { 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); From patchwork Thu Jul 9 11:17:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1471 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 879313F06D for ; Thu, 9 Jul 2020 13:19:19 +0200 (CEST) Received: by mail-pf1-f198.google.com with SMTP id v22sf1081291pfu.22 for ; Thu, 09 Jul 2020 04:19:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594293558; cv=pass; d=google.com; s=arc-20160816; b=Z6E/EOQ+DfhdwZNcxKm0O9xJ2FFOPQ7dtF33hCt2FsGjuUKWTAZ4vvtxNnmaNeYFyI 4SXpsjJsImgE1oUBv/uL3p32oHeZaXrHYr6m1XYcBodcUfT+A3kqK985HehSfZ0VdplS BOeYyZ3lWTDZpM8pg2yDFI06MfyOnxmL9RnRyHxPczcbHTO6SXNGK3fvY7IuD7o2rQhd BsqTCYgJDG9yBxO7mix3laOtwrrHCU/QQuXPeq1GbfBfO5h5ljeqCNFwZGkagXQ4Jfmk uKk5H4dDRiw5MbQH+eM7x1pY0hZUKmxNqN8RQnuDoyvLCHq+AqFZaT+HcdXa85BcUMcN P7Pg== 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=M9CsHKdOS13c4GmLbbEDeE2DEN0Noun6KjeNjq0jgkM=; b=uzzX/zYZGnu36RD2vuwOxFU3cQNCag8c7pzr3fJ1egIOAgiWSKGA6zk86vXMcXXmCg +pIr5yMgcDUTgOL8v1Gv6jM6zZU+DIsbvReEm0yIL9S6GEYuLIZ6ADzHX0cA/MWhA3/j mTpZIZfN7jGlaF2FgeVFYorT3rzIWmQTyWTnHc7byq/zqMwtCb6OnJSipLn/ZjsanJdj egHhICKEJaFbefXKMdPRCLlpY8QYDS3+9xlCj7/+n5q+W+9oOmH1PyqL675Q8Rp4Gu6U 5s4e+KrowmnXJvJnS/OY/hUHgjFQNAPJJAj9P2XsOJOUBbY+TeZMpROrNwK13DAwSvyV invw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CFsnb00R; 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=M9CsHKdOS13c4GmLbbEDeE2DEN0Noun6KjeNjq0jgkM=; b=ey5wO0uxa5GtdU3dVlhPZdkFWt2XEdALgE3uNzA/lkNuCkqZ0obMGIniSMnFl0FWkK a+mKS8Z/9aCcnTMZImotSZLpXBGWWyJX0mqhoYHw9IotxpzZmQwJ+03iHTb53v2+8951 jnUa+HjnF+whRxVsV/6s4xxblQtd1W4ona6mo= 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=M9CsHKdOS13c4GmLbbEDeE2DEN0Noun6KjeNjq0jgkM=; b=m+4Ou2ZJpnw9JoW2w33YaWSa44JP0cSohIe/TH4fkBB5VCMGRx8yc2urHvkjAML9AK 2/btrl8iwmR4cLH6e/r4ORLg/ZIBDEYirG6yMjZtXxaK0MR3tSRnobiLk0b799ndIxYu q8hp2xdEGHvdCnPQ8QYBkN/VDZpVnsvLvPyJQwcG7u5P9aWN3UIDsRcYEDTNB0s5ntiL rtnRjVT7wTNF3vHTv8xEect44F2uKrg5V0P8hQ16ljgu2nOUIcw7D9SkdfImx2oj+dO1 m3SHUFCGMyrohSEhs02ZGBTy8YVUAbRuZr8xzQsRlYyDuz+uP/HdHGjL8RJrTqoQlQ/7 AUSQ== X-Gm-Message-State: AOAM5327gIzw0paJiKOSS8h8IIrkUdzhNSmpKAjrZg6HgiPYC/z5prhg iGFDeHGvFklhxV9gE6UOCzBr/lv1 X-Google-Smtp-Source: ABdhPJxIMtrPIqYcwNY/D0vFnZ+KavS0sIY5Jf5VzP9T1W2y7nRx4QfPRrTD1kVW/LBqlrFo1frpCw== X-Received: by 2002:aa7:8513:: with SMTP id v19mr48956587pfn.74.1594293558261; Thu, 09 Jul 2020 04:19:18 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a65:52ca:: with SMTP id z10ls1718672pgp.10.gmail; Thu, 09 Jul 2020 04:19:18 -0700 (PDT) X-Received: by 2002:a63:745:: with SMTP id 66mr55396266pgh.316.1594293557672; Thu, 09 Jul 2020 04:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594293557; cv=none; d=google.com; s=arc-20160816; b=GyX+HTM6s9vLtOfOoXlKBaRp7WA+OxyZRXC2pHZ42e6seg7iXFb17nzS9QR7pzvp6a 9mqM3mP8AKY4IajssfSS8NK1+CJe4TmrEfBtK0zKvXaqsiV57YzFfHRz0OKkCjWYovuG EK2AxwaMMh1xfxE+tPoSOqGeI48E3cdouLNEBw/QKrguwvvAcoe47V2+/WAnPgMuSW+I zP7zOMcqGYaAvRCwtfRYnIrbsKedvVYuw2tiB781i2hKsgXDQLpaMfYg4kH28Y/GZPpF ndRQJGQ59PP/uJZmum02NhKXZjgt0T4KiHFC511E/cfC0Efq/mUqUDm9hAU7peK+pBkg jy2w== 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=+WPrI6b4YjyGQk7j34oEc307pgHblhnSEDd3lM76efM=; b=PRN7KVpbv3lLPCJgTyIFW9O17UUKpAWEfv8Z1a0D3v3R0IsYDMeywRU850Jy9XxCW5 ZrW21kC+tyTlX7b33ifzUwTG+4OofYgTnjfZa3Se+Pu6+JpRUNQccfaLb4kmi6mwrcQM Mt6uWJaJAtXhXgXPcHcjWWPlZpSthGFaoztTRIqDtlMrhZX2ysOOE1Ev6rpGSqog5+/z K7xx6Eu7EzBvtwoOCeF181Tj3uTMd0aJOQDjjxVOFPcRGhVXUZJOZ97vxJ8BQGlF8Klc e4HTzH3N0qAp1hjHNiihdJBtxX+xLPYLIKgwdcD4AvMftiFSz0RXnMIzrbCQ97Zfqz98 lU3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CFsnb00R; 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 q6sor3192050pgp.48.2020.07.09.04.19.17 for (Google Transport Security); Thu, 09 Jul 2020 04:19:17 -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:a63:a843:: with SMTP id i3mr54624622pgp.190.1594293557406; Thu, 09 Jul 2020 04:19:17 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:19:16 -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 3/5] mtd: Add SPL_DM_MTD option Date: Thu, 9 Jul 2020 16:47:07 +0530 Message-Id: <20200709111709.68904-4-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=CFsnb00R; 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 SPL option for DM_MTD. Cc: Simon Glass Cc: Vignesh R Signed-off-by: Jagan Teki --- drivers/mtd/Kconfig | 8 ++++++++ drivers/mtd/Makefile | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 348b43e653..3feedf311f 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -17,6 +17,14 @@ config DM_MTD flash, RAM and similar chips, often used for solid state file systems on embedded devices. +config SPL_DM_MTD + bool "Enable Driver Model for MTD drivers in SPL" + depends on SPL_DM + help + Enable driver model for Memory Technology Devices (MTD), such as + flash, RAM and similar chips, often used for solid state file + systems on embedded devices. + config MTD_NOR_FLASH bool "Enable parallel NOR flash support" help diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index 318788c5e2..f6b0719746 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile @@ -4,7 +4,7 @@ # Wolfgang Denk, DENX Software Engineering, wd@denx.de. mtd-$(CONFIG_MTD) += mtdcore.o mtd_uboot.o -mtd-$(CONFIG_DM_MTD) += mtd-uclass.o +mtd-$(CONFIG_$(SPL_)DM_MTD) += mtd-uclass.o mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o mtd-$(CONFIG_MTD_CONCAT) += mtdconcat.o mtd-$(CONFIG_ALTERA_QSPI) += altera_qspi.o From patchwork Thu Jul 9 11:17:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1472 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 543443F06D for ; Thu, 9 Jul 2020 13:19:40 +0200 (CEST) Received: by mail-pj1-f72.google.com with SMTP id q5sf1286097pjd.3 for ; Thu, 09 Jul 2020 04:19:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594293579; cv=pass; d=google.com; s=arc-20160816; b=dSEjDoiv0pO3GHtsNu9Ixwg5P16OGv5Cuguh/oxWXXCrpKKeoowlVRuNomADqaQWTd 1p/GsB7npOcS3UjOw9VAG0IOjrxkW7tZ9oEdq//wdTSOps99j62mJtwJOXgpuvOX/6Qk QC2mdhIkECMySftLDn74suHj/9H2ITwb+xj+bibQhEcK39d9kyV6QmXtOU07Xxujurp9 QT78GXT3Wri4tLr9ZXr2/QpUvEidQWfF5GJL6wY2b0euOds9HgRiSFLuNORu+EJBLCmR qPjMmsoXugH3GhoVZW0DLvq/aTruJD1SxfMTo4zngrULZB4dyvwk2UgSYLHViG+TafQF 67EA== 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=N5Vh0fUKnd6B5gH1mpTJOdJs+vOFtm5RvXUQkY6j5yU=; b=utHuzwFkz+m9Kznikx60NVXCn2Hz7+LcwUA0Wmwo0Mu0Ym7n9jzmNZt1BuDZMhQwEq SZ9Rx1vobde5t/wOwyEURw0wMzMZ+8lMRRb/XWSH6TQu6Eq+0EMAs2BikYmWagtAw+hf Q1eVuVnAisfrjbyeuWiSMScPWCCCC7irxtoa8CAHAnAP8Wu6eD7fFuJWC29oBKUMVER7 PpLQMUYuum4G19XoQXvQrNCst+RoPEXTriMLOQIHTeZO9ni3EHxUas1zfIrQn5YYddRx AkZOyejH6uxo81Ygvimk0Cf2RI/ENZ8482kYFo0KnMMWjaxkS2Njko+5Ropqi15vADIZ U93w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="R/XKFyXv"; 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=N5Vh0fUKnd6B5gH1mpTJOdJs+vOFtm5RvXUQkY6j5yU=; b=As7b3OISIjtPF1hqy0DmbADzQE3dRCCT47IkaB/ROlDw5XNPRpK5oCeaVTiJQx1Suf +8vb0YZ1U1SLVuXxQCwXt0oF+ZxfzR4ZfNYYL9LkIDt2JGdk312S9vg0jIzroXned4jo ZOBnl9wFBH0BEe5k4sa6+87ts7RAv+BYb4rhY= 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=N5Vh0fUKnd6B5gH1mpTJOdJs+vOFtm5RvXUQkY6j5yU=; b=QSk7xFHsWTm0SnC0Dp4fRJOCtrgIz1f14SYYgTv/pKipFF1SAfRk8HGBQpQ7Ytze6p Jon/aqOnrpoRVEeiIKi7DjYrdY66sd5NWkboSdggpWcoZ42e7se0XRBeIaRXQN4G8Fjl flsGHTlTtNhA/a7zxgD9Ewg7WLmjpHA2VLb6534pkpQRNOSYBRC2bD0IHIkuHS+1fmbK 8jgvh+1anCq/o+KHT9cKoz6fkmpdA+56xxUg+ANP5JkuS/suRujGiWVEud9iemorbB2u Q2F4lrZOIzDPdBuq1D7fdToXmEhPOgAc42XqjxLuHVNh3s0zzCvophTu1U2g4Kv38N+j TtYw== X-Gm-Message-State: AOAM533iJzL1RH0xFslbj2Ou79ZZz3yimG2JMQLXGjj4FWC7BszC39r6 cP97ZzbWyixg7tmPt7c7l8M/aHUa X-Google-Smtp-Source: ABdhPJyqL8QYEjV7bpAKIbCRF+mF6C1HqMHQzcZoohwv/h+Xz7cBlDBvrnD3+h8mBmjbJAA4gafdvg== X-Received: by 2002:a63:5004:: with SMTP id e4mr31503240pgb.208.1594293579136; Thu, 09 Jul 2020 04:19:39 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:565:: with SMTP id 92ls2245669plf.2.gmail; Thu, 09 Jul 2020 04:19:38 -0700 (PDT) X-Received: by 2002:a17:902:7:: with SMTP id 7mr49219156pla.209.1594293578669; Thu, 09 Jul 2020 04:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594293578; cv=none; d=google.com; s=arc-20160816; b=EglZPGF5TXe/pQj+qM8qTNlF6hmzDGPCorQEArIrsCTGvuhETlqvOgPInELVIzbThb ElM8NQtLi8Z9duzg5q7NoODOTSsX9Kl5wOI/tHK0Tat5spAaYNZ6YK/25oATB99MKrch AlADUniiZah7xgYl2sEQcbxRJ7PG2tHdpZNVqGFjWzIfI5n104db4ohNGf/pTS54BB+F EaaMCGCNHpvIypEss9g6KlNj9pJ0jZIOXDDBjvmsXo5gEOgMWqO+a29ocEWZYd6Uf2R3 Qv+B9r56KdQ3q+EWPrxz/RxR1XTjBW43NPOo3ywWh8LNM/f+SvIlJTxkPhYvWOAEPk8k jIgw== 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=sUcsFKI2tm1KjE+Yk+MUTXdT4e6qPu2mWFjL/eRKg0E=; b=OK6gDuiw3FKWOikwXspgtzIhTIzrgtO2qFHBQwLRMPpVB2E14u76n/8+o39TgMWAL5 D2C+el+2zNL2Q17L60wlwk3Wr/1x5SDf2/UmaMbFJHI1QDSCZi2QQNy5X1TrLlqGxPp9 0LJHkgbaQdRdnKLbUSDQfs9xOR9wvK8+IwAFu1d2wz2o1b3g3HbWJeN8s/0i/sBApS+1 mgthQJJUGljkUM66y3qqMrq/nTzdqVsR8pTKzOj0GLBX8hLqi0GS2yI8GERIh3XzZVkw W0JrYWFmSOIZfGeAC3SiyYKPFwy23Fc35J+9XS8a2oqjP68CZ+lyrt/FK4z7EjpZ3/4a taxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="R/XKFyXv"; 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 d4sor3404986plo.37.2020.07.09.04.19.38 for (Google Transport Security); Thu, 09 Jul 2020 04:19:38 -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:8d86:: with SMTP id v6mr29938571plo.200.1594293578404; Thu, 09 Jul 2020 04:19:38 -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.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:19:37 -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 4/5] mtd: Build mtd-uclass as obj Date: Thu, 9 Jul 2020 16:47:08 +0530 Message-Id: <20200709111709.68904-5-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="R/XKFyXv"; 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: , Technically dm and nodm codebases have to build separately since the SPL and U-Boot proper will enable based on the requirements and foot-print sizes. Till now there is no usage of SPL DM_MTD, but if we enable it can't build since the mtd-uclass is linked with nodm MTD code. So move the build link from mtd to obj so-that it can make compatible with all build types. Cc: Simon Glass Cc: Vignesh R Signed-off-by: Jagan Teki --- drivers/mtd/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index f6b0719746..baab7b8657 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile @@ -4,7 +4,6 @@ # Wolfgang Denk, DENX Software Engineering, wd@denx.de. mtd-$(CONFIG_MTD) += mtdcore.o mtd_uboot.o -mtd-$(CONFIG_$(SPL_)DM_MTD) += mtd-uclass.o mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o mtd-$(CONFIG_MTD_CONCAT) += mtdconcat.o mtd-$(CONFIG_ALTERA_QSPI) += altera_qspi.o @@ -18,6 +17,9 @@ mtd-$(CONFIG_STM32_FLASH) += stm32_flash.o mtd-$(CONFIG_RENESAS_RPC_HF) += renesas_rpc_hf.o mtd-$(CONFIG_HBMC_AM654) += hbmc-am654.o +# dm-mtd +obj-$(CONFIG_$(SPL_)DM_MTD) += mtd-uclass.o + # U-Boot build ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) From patchwork Thu Jul 9 11:17:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1473 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 347BA3F06D for ; Thu, 9 Jul 2020 13:19:58 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id u128sf1097441pfu.12 for ; Thu, 09 Jul 2020 04:19:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594293597; cv=pass; d=google.com; s=arc-20160816; b=kvdxxqndUTEswvKFtS9++A33EPoOZ8Xy+eVW2MfcI5918dwSb+dddU+mIsBVVoVpkb QLW87/lJdQXhX//YEWnxJdWBEu8AzWn0JeY4p3fXiMHAvVy8TC63qyKJ67wXYBvSVeDG WbGQzJJ+jOoiQlhcITJ7djZu1tVKC/O45ftiK2Q47pUVQ3xWk4ZYdw+Fufd+3HLZ8QYM 5TiNg02rxh26FIo9+eJKNb3KWoTxbvBH9DlZ7NjF+UDO2NfICknLY7iBry1RCw4+FOCN jofWQF/haQRyiS87bpMTmrnVfCfRbkJQEZDhx7fze3ZUXMl4mxj8gmGMkwTKQq0vXqFg Paaw== 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:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ox9cq7axFm0rqUJfxfqZ8QNj+07ujMWhyL2ndB9utJc=; b=XWd6pluARwuEwJ1UQM5zajHnqU9OFqyx3n54gUdrKNWpIBwkWxA3QV/s6pI7MY7cNS nn8YE1QA5coSD8uQQqluVx9q3qs7c2ENRi/BcgLPZqeBsIbLYKSiWzr2ZuOkb6cImdj+ qdu/o69wEYtdS3fq0t7T0vvHqIsuf7JnOQp1/zeyihlC9d3bsaShewA7RLUBk1h1QWlz Kd9V1LVjXXhHaDzPp7L9byz1+fY5ADo8uaLTotu0HbjgMyjy1mo9Ja0/iMYiT09SJoCX GqKUtYTPbvsbIC1V33RWIrH827mpWheIlTYHMHkiC7LqsCRBqo0rTT3lFQ+ke6o1/xMz 0rsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CqjXrZ7v; 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:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Ox9cq7axFm0rqUJfxfqZ8QNj+07ujMWhyL2ndB9utJc=; b=ANEfkd3SGrM9naVHvUoj8LcyBIPOKbGmhc3Y9OeHIgctwf4wHPAhMpGQaEtXeSAAOi 5wIszg6mfMWkM9N4Ed+eA9cE7vgFmhvuLJTxGum/SPA7p/sBkWIb68CgsuL4TPGds7B1 QMVaEtLB/NOvW7+JyB8mXlzvgW/XUiKmoHqqo= 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: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=Ox9cq7axFm0rqUJfxfqZ8QNj+07ujMWhyL2ndB9utJc=; b=ujWhW7emFV4rvWYJnms4dyY4MVmBVHgVK2QM8NQKDmxDLQZr+RgmY639lxZFAebQ8o xvzHHj+yHz1IjhurbVjQQBH7mFgwGqU4wPICP7oGvAdaBKQjF9IHi3Yetm976GkQg5B6 x3nfzkpChY90bYqQ/p6gvomu2ISj/GKMfKf2RVsir46IoO+9heBmp8WK/nMegJPYV0w/ nfM/DrzPN2FfIL3C9MHVHczosFRtfoSLaXPW7501VsqblDGKaMmRNbXtWEOMKH4criPp qEKxx5NHNsg7n3IaAJntCsJXMjV6zvzRDodXj8rGcX8rjbmxJbzexLlbmgfoBPz7dbsi 8NWA== X-Gm-Message-State: AOAM532vpRtQbsV/+V87QBj6cIC1IeBufLcAb1fXSoAe3+d4UzvX/3KW RU3a96yPNcJkochmjpT0xYZBuNJm X-Google-Smtp-Source: ABdhPJzh+xq5uPc+r53H+EFbR+rW2Sn0bb31IeK7KRhh+4schXjmhbXjTlJVD2ycqirwaoqiElA3qw== X-Received: by 2002:a17:90b:46c1:: with SMTP id jx1mr15106798pjb.157.1594293596913; Thu, 09 Jul 2020 04:19:56 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:380c:: with SMTP id mq12ls2491100pjb.1.gmail; Thu, 09 Jul 2020 04:19:56 -0700 (PDT) X-Received: by 2002:a17:90a:ba86:: with SMTP id t6mr14882111pjr.10.1594293596207; Thu, 09 Jul 2020 04:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594293596; cv=none; d=google.com; s=arc-20160816; b=sQ7Yn/sye4ikYnlgDKzZ1HQ7YOP5h1veCWzIzZcCDqIHqsS0alIee4gqWKJZonP9Ou b3+NUmx3cr6u5LStqyO9/i2dzzu5eSiDuMgymtR1LAf9ncQLbAv2Cdsv6homEbggcsCA 0rwZ+eezmbkesv5DMphRMHNNb1z619/24MjcVmLRUSuFw3ZZqPvaJi3eQFiUwvWnUfn9 LvFamu4aTPWAvT7mJCnAFA14BMJFAumxKhqt1MIIdiTNRc1WDnYwU98TmGthL37k8u1o aora/TmUldcVAsRQ7zMe+BrwT8t/VbeBl4jkX7PxKlcs2aN5NbdqhIbraVu4qHTf0GJv zqXA== 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=O8LKNIwpFRsyT+02guzQQAUak77g9WaWu/0yafShqa8=; b=goMlt/IRWNWzVJFQCpFWoTbHunZaLwzUl5Ocj1AKdY3WvMkr/K8227SBdqGAhHaesu l9idusRpCi1LHJ60Egz1ZbPI7u7mRDiRk8D+2qcCc2BKq3COJdXmQ9zp6rXQ9MWrBso7 eoGWsMRuU/tvdTIsapN9qUxfpHIaIrCwiLasnIVh+8W5b9yP/De+ZnTnZYdKXtOXECty hRKm4djOhtO/cRN3PTPnvq0bumIq+jqmcyQusGnWcf9Y+nJ6srnx1Sg7MaDDST7SZl1H oMOZs4/tpUg3tqzVQmBzSDd/+9k0E9aFqSQ8+d+opCzchQO9v0K4slRvfnFx1iP8Hidw Sc6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CqjXrZ7v; 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 q16sor3572907pjp.33.2020.07.09.04.19.56 for (Google Transport Security); Thu, 09 Jul 2020 04:19:56 -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:90a:db8a:: with SMTP id h10mr14736137pjv.58.1594293595681; Thu, 09 Jul 2020 04:19:55 -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.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:19:54 -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 5/5] mtd: spi: Switch to MTD uclass (absolute UCLASS_SPI_FLASH) Date: Thu, 9 Jul 2020 16:47:09 +0530 Message-Id: <20200709111709.68904-6-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 Content-Type: text/plain; charset="UTF-8" X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CqjXrZ7v; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com 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: , Why MTD UCLASS switch? From a nutshell, all the memory-related flash devices like Parallel NOR, Raw NAND, SPI NOR/NAND stacks should be part of the MTD layer. The same theory applies to incase of MTD UCLASS in U-Boot. Unfortunately, no flash drivers are using the MTD UCLASS in the fully functional driver model. There are several reasons behind it like - MTD code always copies/sync from Linux to support the latest   flash features. - So no special interest to touch since flash code is much bigger   than usual and a lot of features are tested with existing code. - No real taker to implement it. So, this patch is trying to move further to use a common flash interface layer called MTD in the driver model way. As initial support it supporting spinor flash device drivers would be written as UCLASS_MTD. What happened to UCLASS_SPI_FLASH, why it is absolute now? Due to the effect of Linux MTD/SPI_NOR sync the existing spi_flash the structure has been affected such a way that it was dead and typedefs to spi_nor. What happened with this patch then? With this patch, the UCLASS_SPI_FLASH will be replaced with UCLASS_MTD by using dm-driven mtd_ops. absolute link: sf.c => sf uclass => sf driver => spi-nor-core - flash operations via dm_spi_flash_ops updated link: sf.c => mtd uclass => mtd driver => spi-nor-core - flash operations via mtd_ops (dm variant) Future work? - cleanup of spi_flash with spinor - renaming of CONFIG option changes - implement common mtd probe - implement mtd flash interface types so that the respective   commands like sf, mtd can make use of dm-mtd in the proper way. Signed-off-by: Jagan Teki --- arch/arm/mach-rockchip/spl-boot-order.c | 4 +- arch/x86/cpu/apollolake/spl.c | 8 +- arch/x86/lib/fsp2/fsp_init.c | 2 +- arch/x86/lib/fsp2/fsp_support.c | 7 +- arch/x86/lib/mrccache.c | 8 +- board/atmel/common/mac-spi-nor.c | 4 +- drivers/mtd/spi/Kconfig | 2 + drivers/mtd/spi/sandbox.c | 2 +- drivers/mtd/spi/sf-uclass.c | 106 ++++++------------------ drivers/mtd/spi/sf_dataflash.c | 25 +++--- include/dm/uclass-id.h | 1 - include/spi_flash.h | 53 +----------- test/dm/sf.c | 12 +-- 13 files changed, 71 insertions(+), 163 deletions(-) diff --git a/arch/arm/mach-rockchip/spl-boot-order.c b/arch/arm/mach-rockchip/spl-boot-order.c index 94673f34c9..64a745d189 100644 --- a/arch/arm/mach-rockchip/spl-boot-order.c +++ b/arch/arm/mach-rockchip/spl-boot-order.c @@ -62,7 +62,7 @@ static int spl_node_to_boot_device(int node) default: return -ENOSYS; } - } else if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node, + } else if (!uclass_get_device_by_of_offset(UCLASS_MTD, node, &parent)) { return BOOT_DEVICE_SPI; } @@ -73,7 +73,7 @@ static int spl_node_to_boot_device(int node) * extended with awareness of the BLK layer (and matching OF_CONTROL) * soon. */ - if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node, &parent)) + if (!uclass_get_device_by_of_offset(UCLASS_MTD, node, &parent)) return BOOT_DEVICE_SPI; return -1; diff --git a/arch/x86/cpu/apollolake/spl.c b/arch/x86/cpu/apollolake/spl.c index e1ee1e0624..9c80440bbb 100644 --- a/arch/x86/cpu/apollolake/spl.c +++ b/arch/x86/cpu/apollolake/spl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,7 @@ static int rom_load_image(struct spl_image_info *spl_image, debug("Reading from mapped SPI %lx, size %lx", spl_pos, spl_size); if (CONFIG_IS_ENABLED(SPI_FLASH_SUPPORT)) { - ret = uclass_find_first_device(UCLASS_SPI_FLASH, &dev); + ret = uclass_find_first_device(UCLASS_MTD, &dev); if (ret) return log_msg_ret("spi_flash", ret); if (!dev) @@ -77,7 +78,7 @@ static int spl_fast_spi_load_image(struct spl_image_info *spl_image, struct udevice *dev; int ret; - ret = uclass_first_device_err(UCLASS_SPI_FLASH, &dev); + ret = uclass_first_device_err(UCLASS_MTD, &dev); if (ret) return ret; @@ -89,8 +90,7 @@ static int spl_fast_spi_load_image(struct spl_image_info *spl_image, spl_image->name = "U-Boot"; spl_pos &= ~0xff000000; debug("Reading from flash %lx, size %lx\n", spl_pos, spl_size); - ret = spi_flash_read_dm(dev, spl_pos, spl_size, - (void *)spl_image->load_addr); + ret = mtd_dread(dev, spl_pos, spl_size, (void *)spl_image->load_addr); cpu_flush_l1d_to_l2(); if (ret) return ret; diff --git a/arch/x86/lib/fsp2/fsp_init.c b/arch/x86/lib/fsp2/fsp_init.c index 85cae54a0c..61af45d239 100644 --- a/arch/x86/lib/fsp2/fsp_init.c +++ b/arch/x86/lib/fsp2/fsp_init.c @@ -124,7 +124,7 @@ int fsp_locate_fsp(enum fsp_type_t type, struct binman_entry *entry, struct udevice *sf; /* Just use the SPI driver to get the memory map */ - ret = uclass_find_first_device(UCLASS_SPI_FLASH, &sf); + ret = uclass_find_first_device(UCLASS_MTD, &sf); if (ret) return log_msg_ret("Cannot get SPI flash", ret); ret = dm_spi_get_mmap(sf, &map_base, &map_size, &offset); diff --git a/arch/x86/lib/fsp2/fsp_support.c b/arch/x86/lib/fsp2/fsp_support.c index 3f2ca840dc..434bfdbc0e 100644 --- a/arch/x86/lib/fsp2/fsp_support.c +++ b/arch/x86/lib/fsp2/fsp_support.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -37,10 +38,10 @@ int fsp_get_header(ulong offset, ulong size, bool use_spi_flash, */ debug("offset=%x buf=%x\n", (uint)offset, (uint)buf); if (use_spi_flash) { - ret = uclass_first_device_err(UCLASS_SPI_FLASH, &dev); + ret = uclass_first_device_err(UCLASS_MTD, &dev); if (ret) return log_msg_ret("Cannot find flash device", ret); - ret = spi_flash_read_dm(dev, offset, PROBE_BUF_SIZE, buf); + ret = mtd_dread(dev, offset, PROBE_BUF_SIZE, buf); if (ret) return log_msg_ret("Cannot read flash", ret); } else { @@ -88,7 +89,7 @@ int fsp_get_header(ulong offset, ulong size, bool use_spi_flash, debug("Image base %x\n", (uint)base); debug("Image addr %x\n", (uint)fsp->fsp_mem_init); if (use_spi_flash) { - ret = spi_flash_read_dm(dev, offset, size, base); + ret = mtd_dread(dev, offset, size, base); if (ret) return log_msg_ret("Could not read FPS-M", ret); } else { diff --git a/arch/x86/lib/mrccache.c b/arch/x86/lib/mrccache.c index f181e8100c..30eb5cf669 100644 --- a/arch/x86/lib/mrccache.c +++ b/arch/x86/lib/mrccache.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -167,7 +168,7 @@ static int mrccache_update(struct udevice *sf, struct mrc_region *entry, debug("Erasing the MRC cache region of %x bytes at %x\n", entry->length, entry->offset); - ret = spi_flash_erase_dm(sf, entry->offset, entry->length); + ret = mtd_derase(sf, entry->offset, entry->length); if (ret) { debug("Failed to erase flash region\n"); return ret; @@ -178,8 +179,7 @@ static int mrccache_update(struct udevice *sf, struct mrc_region *entry, /* Write the data out */ offset = (ulong)cache - base_addr + entry->offset; debug("Write MRC cache update to flash at %lx\n", offset); - ret = spi_flash_write_dm(sf, offset, cur->data_size + sizeof(*cur), - cur); + ret = mtd_dwrite(sf, offset, cur->data_size + sizeof(*cur), cur); if (ret) { debug("Failed to write to SPI flash\n"); return log_msg_ret("Cannot update mrccache", ret); @@ -242,7 +242,7 @@ int mrccache_get_region(enum mrc_type_t type, struct udevice **devp, * the device here since it may put it into a strange state where the * memory map cannot be read. */ - ret = uclass_find_first_device(UCLASS_SPI_FLASH, &dev); + ret = uclass_find_first_device(UCLASS_MTD, &dev); if (ret || !dev) { /* * Fall back to searching the device tree since driver model diff --git a/board/atmel/common/mac-spi-nor.c b/board/atmel/common/mac-spi-nor.c index ced27b65e6..0b3f1b1340 100644 --- a/board/atmel/common/mac-spi-nor.c +++ b/board/atmel/common/mac-spi-nor.c @@ -107,10 +107,10 @@ void at91_spi_nor_set_ethaddr(void) if (env_get(ethaddr_name)) return; - if (uclass_first_device_err(UCLASS_SPI_FLASH, &dev)) + if (uclass_first_device_err(UCLASS_MTD, &dev)) return; - nor = dev_get_uclass_priv(dev); + nor = dev_get_priv(dev); if (!nor) return; diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig index 018e8c597e..9de0484b29 100644 --- a/drivers/mtd/spi/Kconfig +++ b/drivers/mtd/spi/Kconfig @@ -3,6 +3,8 @@ menu "SPI Flash Support" config DM_SPI_FLASH bool "Enable Driver Model for SPI flash" depends on DM && DM_SPI + select DM_MTD + imply SPL_DM_MTD imply SPI_FLASH help Enable driver model for SPI flash. This SPI flash interface diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index 8cbe97ee20..0b04f14b16 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -8,7 +8,7 @@ * Licensed under the GPL-2 or later. */ -#define LOG_CATEGORY UCLASS_SPI_FLASH +#define LOG_CATEGORY UCLASS_MTD #include #include diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index 44cdb3151d..9cab08f49b 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,22 +15,6 @@ DECLARE_GLOBAL_DATA_PTR; -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf) -{ - return log_ret(sf_get_ops(dev)->read(dev, offset, len, buf)); -} - -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len, - const void *buf) -{ - return log_ret(sf_get_ops(dev)->write(dev, offset, len, buf)); -} - -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len) -{ - return log_ret(sf_get_ops(dev)->erase(dev, offset, len)); -} - void spi_flash_free(struct spi_flash *flash) { device_remove(flash->spi->dev, DM_REMOVE_NORMAL); @@ -57,108 +42,78 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, str = strdup(name); #endif ret = spi_get_bus_and_cs(bus, cs, max_hz, spi_mode, - "spi_flash_std", str, &bus_dev, &slave); + "spi_flash_std", str, &bus_dev, &slave); if (ret) return NULL; - return dev_get_uclass_priv(slave->dev); + return dev_get_priv(slave->dev); } -static int spi_flash_post_bind(struct udevice *dev) +static int spi_flash_std_read(struct udevice *dev, loff_t from, size_t len, + u_char *buf) { -#if defined(CONFIG_NEEDS_MANUAL_RELOC) - struct dm_spi_flash_ops *ops = sf_get_ops(dev); - static int reloc_done; - - if (!reloc_done) { - if (ops->read) - ops->read += gd->reloc_off; - if (ops->write) - ops->write += gd->reloc_off; - if (ops->erase) - ops->erase += gd->reloc_off; - - reloc_done++; - } -#endif - return 0; -} - -static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len, - void *buf) -{ - struct spi_flash *flash = dev_get_uclass_priv(dev); + struct spi_flash *flash = dev_get_priv(dev); struct mtd_info *mtd = &flash->mtd; size_t retlen; - return log_ret(mtd->_read(mtd, offset, len, &retlen, buf)); + return log_ret(mtd->_read(mtd, from, len, &retlen, buf)); } -static int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len, - const void *buf) +static int spi_flash_std_write(struct udevice *dev, loff_t to, size_t len, + const u_char *buf) { - struct spi_flash *flash = dev_get_uclass_priv(dev); + struct spi_flash *flash = dev_get_priv(dev); struct mtd_info *mtd = &flash->mtd; size_t retlen; - return mtd->_write(mtd, offset, len, &retlen, buf); + return mtd->_write(mtd, to, len, &retlen, buf); } -static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len) +static int spi_flash_std_erase(struct udevice *dev, struct erase_info *instr) { - struct spi_flash *flash = dev_get_uclass_priv(dev); + struct spi_flash *flash = dev_get_priv(dev); struct mtd_info *mtd = &flash->mtd; - struct erase_info instr; - if (offset % mtd->erasesize || len % mtd->erasesize) { - printf("SF: Erase offset/length not multiple of erase size\n"); + if (instr->addr % mtd->erasesize || instr->len % mtd->erasesize) { + dev_err(dev, "Erase offset/length not multiple of erasesize\n"); return -EINVAL; } - memset(&instr, 0, sizeof(instr)); - instr.addr = offset; - instr.len = len; - - return mtd->_erase(mtd, &instr); + return mtd->_erase(mtd, instr); } static int spi_flash_std_probe(struct udevice *dev) { + struct spi_flash *flash = dev_get_priv(dev); struct spi_slave *slave = dev_get_parent_priv(dev); - struct spi_flash *flash; int ret; - if (!slave) { - printf("SF: Failed to set up slave\n"); - return -ENODEV; - } - - flash = dev_get_uclass_priv(dev); flash->dev = dev; flash->spi = slave; - /* Claim spi bus */ ret = spi_claim_bus(slave); if (ret) { - debug("SF: Failed to claim SPI bus: %d\n", ret); + dev_err(dev, "failed to claim bus (ret=%d)\n", ret); return ret; } ret = spi_nor_scan(flash); - if (ret) - goto err_read_id; + if (ret) { + dev_err(dev, "failed to scan spinor (ret=%d)\n", ret); + goto err_claim_bus; + } - if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) ret = spi_flash_mtd_register(flash); -err_read_id: +err_claim_bus: spi_release_bus(slave); return ret; } static int spi_flash_std_remove(struct udevice *dev) { - if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) + if (IS_ENABLED(CONFIG_SPI_FLASH_MTD)) spi_flash_mtd_unregister(); return 0; @@ -190,7 +145,7 @@ static int spi_flash_std_bind(struct udevice *dev) return 0; } -static const struct dm_spi_flash_ops spi_flash_std_ops = { +static const struct mtd_ops spi_flash_std_ops = { .read = spi_flash_std_read, .write = spi_flash_std_write, .erase = spi_flash_std_erase, @@ -203,7 +158,7 @@ static const struct udevice_id spi_flash_std_ids[] = { U_BOOT_DRIVER(spi_flash_std) = { .name = "spi_flash_std", - .id = UCLASS_SPI_FLASH, + .id = UCLASS_MTD, .of_match = spi_flash_std_ids, .probe = spi_flash_std_probe, .bind = spi_flash_std_bind, @@ -211,10 +166,3 @@ U_BOOT_DRIVER(spi_flash_std) = { .priv_auto_alloc_size = sizeof(struct spi_flash), .ops = &spi_flash_std_ops, }; - -UCLASS_DRIVER(spi_flash) = { - .id = UCLASS_SPI_FLASH, - .name = "spi_flash", - .post_bind = spi_flash_post_bind, - .per_device_auto_alloc_size = sizeof(struct spi_flash), -}; diff --git a/drivers/mtd/spi/sf_dataflash.c b/drivers/mtd/spi/sf_dataflash.c index 27d847d421..5c73b54cbc 100644 --- a/drivers/mtd/spi/sf_dataflash.c +++ b/drivers/mtd/spi/sf_dataflash.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -117,7 +118,7 @@ static int dataflash_waitready(struct spi_slave *spi) } /* Erase pages of flash */ -static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) +static int spi_dataflash_erase(struct udevice *dev, struct erase_info *instr) { struct dataflash *dataflash; struct spi_flash *spi_flash; @@ -125,6 +126,8 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) unsigned blocksize; uint8_t *command; uint32_t rem; + loff_t offset = instr->addr; + size_t len = instr->len; int status; dataflash = dev_get_priv(dev); @@ -136,7 +139,7 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) memset(dataflash->command, 0 , sizeof(dataflash->command)); command = dataflash->command; - debug("%s: erase addr=0x%x len 0x%x\n", dev->name, offset, len); + debug("%s: erase addr=0x%llx len 0x%x\n", dev->name, offset, len); div_u64_rem(len, spi_flash->page_size, &rem); if (rem) { @@ -146,7 +149,7 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) } div_u64_rem(offset, spi_flash->page_size, &rem); if (rem) { - printf("%s: offset(0x%x) isn't the multiple of page size(0x%x)\n", + printf("%s: offset(0x%llx) isn't the multiple of page size(0x%x)\n", dev->name, offset, spi_flash->page_size); return -EINVAL; } @@ -210,8 +213,8 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len) * len : Amount to read * buf : Buffer containing the data */ -static int spi_dataflash_read(struct udevice *dev, u32 offset, size_t len, - void *buf) +static int spi_dataflash_read(struct udevice *dev, loff_t offset, size_t len, + u_char *buf) { struct dataflash *dataflash; struct spi_flash *spi_flash; @@ -227,7 +230,7 @@ static int spi_dataflash_read(struct udevice *dev, u32 offset, size_t len, memset(dataflash->command, 0 , sizeof(dataflash->command)); command = dataflash->command; - debug("%s: erase addr=0x%x len 0x%x\n", dev->name, offset, len); + debug("%s: erase addr=0x%llx len 0x%x\n", dev->name, offset, len); debug("READ: (%x) %x %x %x\n", command[0], command[1], command[2], command[3]); @@ -266,8 +269,8 @@ static int spi_dataflash_read(struct udevice *dev, u32 offset, size_t len, * len : Amount to write * buf : Buffer containing the data */ -int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len, - const void *buf) +int spi_dataflash_write(struct udevice *dev, loff_t offset, size_t len, + const u_char *buf) { struct dataflash *dataflash; struct spi_flash *spi_flash; @@ -285,7 +288,7 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len, memset(dataflash->command, 0 , sizeof(dataflash->command)); command = dataflash->command; - debug("%s: write 0x%x..0x%x\n", dev->name, offset, (offset + len)); + debug("%s: write 0x%llx..0x%llx\n", dev->name, offset, (offset + len)); pageaddr = ((unsigned)offset / spi_flash->page_size); to = ((unsigned)offset % spi_flash->page_size); @@ -676,7 +679,7 @@ err_jedec_probe: return status; } -static const struct dm_spi_flash_ops spi_dataflash_ops = { +static const struct mtd_ops spi_dataflash_ops = { .read = spi_dataflash_read, .write = spi_dataflash_write, .erase = spi_dataflash_erase, @@ -690,7 +693,7 @@ static const struct udevice_id spi_dataflash_ids[] = { U_BOOT_DRIVER(spi_dataflash) = { .name = "spi_dataflash", - .id = UCLASS_SPI_FLASH, + .id = UCLASS_MTD, .of_match = spi_dataflash_ids, .probe = spi_dataflash_probe, .priv_auto_alloc_size = sizeof(struct dataflash), diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 7837d459f1..1f56f7f48a 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -99,7 +99,6 @@ enum uclass_id { UCLASS_SMEM, /* Shared memory interface */ UCLASS_SOUND, /* Playing simple sounds */ UCLASS_SPI, /* SPI bus */ - UCLASS_SPI_FLASH, /* SPI flash */ UCLASS_SPI_GENERIC, /* Generic SPI flash target */ UCLASS_SPMI, /* System Power Management Interface bus */ UCLASS_SYSCON, /* System configuration device */ diff --git a/include/spi_flash.h b/include/spi_flash.h index 24759944eb..f4852fc5c1 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -10,6 +10,7 @@ #define _SPI_FLASH_H_ #include /* Because we dereference struct udevice here */ +#include #include #include @@ -27,70 +28,24 @@ # define CONFIG_ENV_SPI_MODE CONFIG_SF_DEFAULT_MODE #endif -struct spi_slave; - -struct dm_spi_flash_ops { - int (*read)(struct udevice *dev, u32 offset, size_t len, void *buf); - int (*write)(struct udevice *dev, u32 offset, size_t len, - const void *buf); - int (*erase)(struct udevice *dev, u32 offset, size_t len); -}; - -/* Access the serial operations for a device */ -#define sf_get_ops(dev) ((struct dm_spi_flash_ops *)(dev)->driver->ops) - #if CONFIG_IS_ENABLED(DM_SPI_FLASH) -/** - * spi_flash_read_dm() - Read data from SPI flash - * - * @dev: SPI flash device - * @offset: Offset into device in bytes to read from - * @len: Number of bytes to read - * @buf: Buffer to put the data that is read - * @return 0 if OK, -ve on error - */ -int spi_flash_read_dm(struct udevice *dev, u32 offset, size_t len, void *buf); - -/** - * spi_flash_write_dm() - Write data to SPI flash - * - * @dev: SPI flash device - * @offset: Offset into device in bytes to write to - * @len: Number of bytes to write - * @buf: Buffer containing bytes to write - * @return 0 if OK, -ve on error - */ -int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len, - const void *buf); - -/** - * spi_flash_erase_dm() - Erase blocks of the SPI flash - * - * Note that @len must be a muiltiple of the flash sector size. - * - * @dev: SPI flash device - * @offset: Offset into device in bytes to start erasing - * @len: Number of bytes to erase - * @return 0 if OK, -ve on error - */ -int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len); static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf) { - return spi_flash_read_dm(flash->dev, offset, len, buf); + return mtd_dread(flash->dev, offset, len, buf); } static inline int spi_flash_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf) { - return spi_flash_write_dm(flash->dev, offset, len, buf); + return mtd_dwrite(flash->dev, offset, len, buf); } static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, size_t len) { - return spi_flash_erase_dm(flash->dev, offset, len); + return mtd_derase(flash->dev, offset, len); } struct sandbox_state; diff --git a/test/dm/sf.c b/test/dm/sf.c index 9e7dead684..a675923dc5 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -31,23 +31,23 @@ static int dm_test_spi_flash(struct unit_test_state *uts) src = map_sysmem(0x20000, full_size); ut_assertok(os_write_file("spi.bin", src, full_size)); - ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev)); + ut_assertok(uclass_first_device_err(UCLASS_MTD, &dev)); dst = map_sysmem(0x20000 + full_size, full_size); - ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + ut_assertok(mtd_dread(dev, 0, size, dst)); ut_asserteq_mem(src, dst, size); /* Erase */ - ut_assertok(spi_flash_erase_dm(dev, 0, size)); - ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + ut_assertok(mtd_derase(dev, 0, size)); + ut_assertok(mtd_dread(dev, 0, size, dst)); for (i = 0; i < size; i++) ut_asserteq(dst[i], 0xff); /* Write some new data */ for (i = 0; i < size; i++) src[i] = i; - ut_assertok(spi_flash_write_dm(dev, 0, size, src)); - ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + ut_assertok(mtd_dwrite(dev, 0, size, src)); + ut_assertok(mtd_dread(dev, 0, size, dst)); ut_asserteq_mem(src, dst, size); /* Check mapping */