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) {