From patchwork Thu May 14 13:19:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1207 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 99EBF3F077 for ; Thu, 14 May 2020 15:19:50 +0200 (CEST) Received: by mail-pg1-f198.google.com with SMTP id k15sf2234045pgt.21 for ; Thu, 14 May 2020 06:19:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589462389; cv=pass; d=google.com; s=arc-20160816; b=M4fukfMv0PxLiy9RDisu7H76WCQkDwtxjg+GP09ntSbDCLnfEHq9UAhToxuve4hZC4 jNBXmKgcQU9xqiAr3HUM5ZVwPdP00V8GqE15Ef/NGm9LHlmCpB6VMimrLP0iMDXd/AUr mdlQEh5l4Azj7sya73QtQaZ3mS2NVUXW6CJsQVn/Cs50djFxHf22WNGJEQZ3iVGEbh4f 3M10wwySBvjdaH7QgfRyYC4soXkaTlHf0KZWbQOcTcThbpBsbhES2oaEhBxp0BjvNleq CTphwjGseyotid6d3sjvrU9gvIvH1aTpMqImpPzVrUPBi65DkmEDJOtgNpOL+G7hpP10 wJHQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=a0l4m78gUpbtGo4i4bO6NXNuePcMLKfB4eAcB5vzl74=; b=VJgysOVjfcr8viTud/wNWqgqFupWt/tf/G8s2hVU6ov3qQOK24k7Fx1TESs5ZB57C4 doYo/hcVI+XDzfk3KpKOzVoOdAoXyZg7kUaV9rQMQ/kCmkJIXniql+QXRconn3mn5pOS QKKgkaYK/YLtaMrVrDCLWvwTZs779ozOrWl/VcSYmhVyvfM8ZQvEufBo7jtp7iuNsWMF HGl+4kMX3pNx2dmoRGvx8aI6XQXn9OK3vzu/n3agbT4/U1AFyc//GxaD7rvc7nDDkPUr 77FktvT2W7DgAgbXUdhaOfBsgJqJdCGZwGzVTxvbhQAN/6DL9O4fi3RtHgPX7awFCcXP 9TMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VuME8mU7; 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:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=a0l4m78gUpbtGo4i4bO6NXNuePcMLKfB4eAcB5vzl74=; b=icE/zcbf8Jk3i4pUEkrS1bz1FMJbpDJglM+t3SDwq6Sh/T/pDq0exw/sJh4iDWpc7C 0R9RGciy5lUtQEQbueO8IHWWpupDnC5V6Ff9UEZ7E8XDr7IQceD9xYcwd5AG3s0rQ+IZ QeY/v78Tr24kpCSJ/+iqWmjwmdDfhVtawSqpo= 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: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=a0l4m78gUpbtGo4i4bO6NXNuePcMLKfB4eAcB5vzl74=; b=iJKVeWbFwv0RUJ+MH9LzzQlkOuyywGxEEn1a2Klc09dIIQKtR4186NFJSv5si7Lf3R bpYAEjug+dXoI5x5FouSJjHI0SLzqtZ6U+MSBMGZp6ovm0ZFkCvjpnu89UHmyewHcGlh XO08M4dLju9IqfQv2kj9iGG5Unjk3VHu12QYD5ucwv4WiNYyynLqkS1axTvIBCQ7jQLy h4sjP3lIdMc7IWxTQIeN7A9ZqUXPkJvyu+UoCCSSSjY/jyuPKENuW6xuUVbk0hDZxBQC QIh+0VroTnQHKgsnzHi3QlmnRfF9x4Vhpa4k9iQCCCFA39g0an7HETMNR9+PukMGqKRs QdFA== X-Gm-Message-State: AOAM5327oJK5+Vpwbl8gfaYl52bHDTQsToiSR6q07q+Bdu5ozrSaoL7d p0a+WA5MFyGcex2zYpaqYeYsjgsB X-Google-Smtp-Source: ABdhPJxdvs7DwQ7yW8vwc0CgOBKgo3r5Iz63PUg02Fx2plLOas4GriA+TJGRiyb6GkQ7YDogzO3IAg== X-Received: by 2002:a17:90a:1b6c:: with SMTP id q99mr2357581pjq.214.1589462388549; Thu, 14 May 2020 06:19:48 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:8a8a:: with SMTP id p10ls1057567plo.11.gmail; Thu, 14 May 2020 06:19:48 -0700 (PDT) X-Received: by 2002:a17:902:bd09:: with SMTP id p9mr4173532pls.214.1589462388088; Thu, 14 May 2020 06:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589462388; cv=none; d=google.com; s=arc-20160816; b=P0oDDiA/VhMARi9e79LzhG7JUmIzFIgxsNO8DIO0Tk7GmS+5V0zo2BtAIPpz8ExgFE V+BDPQz29GPsRx/PDQ2x+fV6bxxIztVlmyEYpie45By72+3xs6VzOUTvquegfGzYXQhx AXf643VO7IIXJW4PEnfjO8xpSKlHJiqKHqHHRJtGFO6t7s+e0bLWpnT9rpb0v5pKYDrF fLdVWXA+WBCQpULR5ANug1DM6i4e+3rGAfWu93CSPciWVcPuEFC6rAYJBjIB+fqslzYU Km2rMZH/G9Ub9lEazWoDBimsUUtV9enZAfGzAUCpav04sErxNPJyZSwsm0WglMPuFaBe SHbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=egRRCPblyxV5eGORmtyYxiq6cdrqUlO2xNXEpqcC0VA=; b=l4hQfx2e933Slpf5RaXlx+utDGrnRHB7jh11dMJFQoNsNVtIu7TfShKSBh/WF79W+t rDZd8wDlyqRRsVD/rQPOaO6UgNfVEnounmfglADGSOjsD6sNHJwTUQS6LLJEiYVQb2PS +E7kEXs7tp+NhtdT6FUXaZh1YHUOA2cOx3BPd+beRkjlZBM9GsxulSsIdXji3qBhkz/4 G0u+9ybhjN9MHhmQd/qFmQMxlo+uVGC72Clnvxp3j7s0/nZLmt3HKlfeabJSmXnl3oHm scAuwt3vjrcDJiW1vtDpNV4xljVkjXpp8ChRo4R7Ui11XyCsCYz7mRT3TwaUT6lutALN XRFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VuME8mU7; 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 16sor28735473pjb.30.2020.05.14.06.19.47 for (Google Transport Security); Thu, 14 May 2020 06:19: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:90a:e389:: with SMTP id b9mr41274030pjz.141.1589462387100; Thu, 14 May 2020 06:19:47 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:713c:4a0a:47eb:ffcd]) by smtp.gmail.com with ESMTPSA id h26sm2376366pfk.35.2020.05.14.06.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 06:19:46 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Cc: linux-amarula@amarulasolutions.com, Jagan Teki , Bin Meng , Simon Glass , Vignesh R Subject: [RFC PATCH] mtd: spi: Drop redundent SPI flash driver Date: Thu, 14 May 2020 18:49:35 +0530 Message-Id: <20200514131935.8583-1-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.20.1 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=VuME8mU7; 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_probe.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 d32f2a9898..2e6013d04c 100644 --- a/arch/x86/cpu/apollolake/spl.c +++ b/arch/x86/cpu/apollolake/spl.c @@ -65,66 +65,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_probe.c b/drivers/mtd/spi/sf_probe.c index f167bfab8a..06dac57daf 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -129,7 +129,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; @@ -154,6 +154,32 @@ static const struct dm_spi_flash_ops spi_flash_std_ops = { .erase = spi_flash_std_erase, }; +/* + * 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_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 udevice_id spi_flash_std_ids[] = { { .compatible = "jedec,spi-nor" }, { } @@ -163,6 +189,7 @@ U_BOOT_DRIVER(spi_flash_std) = { .name = "spi_flash_std", .id = UCLASS_SPI_FLASH, .of_match = spi_flash_std_ids, + .bind = spi_flash_bind, .probe = spi_flash_std_probe, .remove = spi_flash_std_remove, .priv_auto_alloc_size = sizeof(struct spi_flash), diff --git a/include/spi_flash.h b/include/spi_flash.h index d9b2af856c..3b33b970ef 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); - int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, unsigned int max_hz, unsigned int spi_mode, struct udevice **devp);