From patchwork Thu May 14 18:09:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1208 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B004F3F077 for ; Thu, 14 May 2020 20:09:54 +0200 (CEST) Received: by mail-pl1-f198.google.com with SMTP id b1sf2999030plm.10 for ; Thu, 14 May 2020 11:09:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589479792; cv=pass; d=google.com; s=arc-20160816; b=SjKMNF8UBIOkSXCA5Hl8UZwQMfQyEx2WMl/qvTJ5ZLjDQTiLTar2FLJX+wRnu0WZ4D 1PL+c2aNiQFL/4qPCvGep4larQHaDQ4K1FynComb/RiE/mbmf/CCJxjapp/vGqMOn+et jYscCi19i2gdgy3CT0BotmRFOmweEHQ4zBt5k1KAXm1R+O35mtV5ckttnAhN/dLSpDZm mteSH8MQuY8VnUrVJP6M3x1EkUrMkcvCxuWg3jl1RVkYGJ4saj/VtE1WNumem26lVVXH E2PwiO+VdK1iSmF6HIe5lOUXMRIHmhBwtUtuIVKF79uypSwH7LS+npKZ5Pm8zAq63VFj JDqg== 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=e4sM9JofI0gc1jVW3bgaIAmSF5R2JkPDgrc+aVXP1Bw=; b=ZEXreV0VWNrPrLztqwhSFwymxQd8E/zfLSaLHARjLxRePBWWvjr+2lg1jgdf57ttDh PBW9DBqMqNpnoAb60HgSooF2BRFaJ6t9+dG5V7cnIRsVcjGz3RKMN6mAJAlk01sRy42k 3v+/qZws5anPoD0bnxRpYQ+bC8hLk2bKiu3+gBZSD0Ekn0zCJUDOsoct527DVGBBCVAv FgRgtJbilbhvrIb32rIcFL+lAb0aNulwE1/UpingFUwNSVUB7AwO7sRMJxyB4kuIZWfc Ianu3+JBn0WZko20S/oYYUdWhDqmZBsBRJJBLGhcqHDiYd8WdpZBdfBozrIfvkQPSTAp cnHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="GgO/Y2ug"; 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=e4sM9JofI0gc1jVW3bgaIAmSF5R2JkPDgrc+aVXP1Bw=; b=HCceUUD3v/fYNsFc4BjWueoYqbbbyezPDyhZCG48jeblOZsiebDo1PAWlUH+Lb/Kmt iMbbpxTzoD1dZVUOEcCYAaIVIgMZu9K3qLJWS2UrT279lSg/0h7ABJSacozo9XmvhwoF +MKcVodnKB7PZpUS7mNXWNNexGFrQLvWOf5Vo= 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=e4sM9JofI0gc1jVW3bgaIAmSF5R2JkPDgrc+aVXP1Bw=; b=iKEIDXNcmbdoMxC4fKJbBr3fvjdMtKIjV1yPZpVLXF1ter7wpZ0c2yThDwDKWVnQCm HhA3+S3CT/8rvE1bEG9kGUDSXCtPpO5IbMwW60d0CJVIN9GDWdcDfMHvJGQB22DFmCAf 67GX6oW2nJWOVma8I/06ViypQVPmZut1HWvXh+qCSBiY1WIGzAeb93IcS3NfWiwt9R52 bclvdCneDq4JNmHvDHX67UZZJpVHPkM23CA1jKMV6xln3Vhb0mM5a9ZiOey6Ml42V1vK zQz6t1e7besDyS8s5OeWhN89PflG3KS19BeG00DUI4biv2cQTHTPLa2nAXsc4E7XBYcg p8dA== X-Gm-Message-State: AOAM532PTeoGnRVUxtmCYR7CCCF3hiKV/xEwFtQKl013NvETHphWayXp +AlMoo+YAUHY1zpnamTCuf+6NB6b X-Google-Smtp-Source: ABdhPJz+Dd8X7xx/sJK0YQliVC/MbN7e8SUjxWJfggRLyF0CFMQnUstpSZ9b6q00KMjQrTpKEKagsw== X-Received: by 2002:aa7:97b2:: with SMTP id d18mr5744701pfq.89.1589479792217; Thu, 14 May 2020 11:09:52 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:1703:: with SMTP id 3ls1186229pfx.8.gmail; Thu, 14 May 2020 11:09:51 -0700 (PDT) X-Received: by 2002:a63:c308:: with SMTP id c8mr4772660pgd.398.1589479791652; Thu, 14 May 2020 11:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589479791; cv=none; d=google.com; s=arc-20160816; b=kc8nVp7pTcphNrVm+wAY8PAADhuvoqtDSfX+SwLALkKDbLuNRVIIQFsIQXZ9CiO/aq BaHfLJj5++ArRxkR/SlI3BwicuiU6N4M7jwwH5cFH6fBY8bhOw4sKZqsk3soJy5M6ZbY WsZy2/dCZjeAYQ9ZSMaaC62urvIMfPL2TyTWOe8crn850KG/JjLbhB3+5jyvfcRo5egz bRzOy+Mlq+pAlDL017BbQjm4HFEn2INDLwL/KKssMsQBv7sJYFWpzLgv4Pv4RkSy/hBo ml3W+h6+Jew6yuDEXEuRQO48CMyTxvm9ZYdRtPi78MBGIGoBg19rqZ28oJ6jxp1yaIIm GkzQ== 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=pGDZHmajGj0mdzbEMHMCgOSJ9o4iuwScbh1hKoIL1rI=; b=kNg5Qkr74Db+BNGzy2i5kgVONISRtD0jeEQHpfKF1yvwD4Z3UraRIG+/r35tC0O7+0 M/VWp+/57h0k3xRFtb4xiBOrObEGHCUSLuMT6mdaSjUtHqlzZ4IKOL+5FfU5vmE9eVCn v3KFR9swP3aSOHGUt5kCEvXQ2wEunQPz1nLvzZf8pCyknMfRXO5XpVE80WIWxyGtz8/E RCMlDQl/2yeiQfXmHncLfvJ59nHMTFSqdkFv2yNk8ZxF2O+uxO3uz6Dh0GmzNBq5CsO1 nk9y8wXV4vfhRqediJhppCTeZ0EioPCCAIZ8ESkr+QgUlkQ/mrsj3VB075wS3LQKoErP wjWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="GgO/Y2ug"; 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 f60sor29608808pje.21.2020.05.14.11.09.51 for (Google Transport Security); Thu, 14 May 2020 11:09:51 -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:d0c3:: with SMTP id y3mr38433090pjw.133.1589479790530; Thu, 14 May 2020 11:09:50 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:713c:4a0a:47eb:ffcd]) by smtp.gmail.com with ESMTPSA id m63sm2904117pfb.101.2020.05.14.11.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 11:09:49 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Cc: linux-amarula@amarulasolutions.com, Jagan Teki , Simon Glass , Vignesh R , Daniel Schwierzeck Subject: [PATCH 1/2] mtd: spi: Separate dm vs nodm SF code Date: Thu, 14 May 2020 23:39:40 +0530 Message-Id: <20200514180941.21542-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="GgO/Y2ug"; 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: , Right now, the sf have common driver to handle both dm and nodm code, where nondm has spi_flash probe and dm has U_BOOT_DRIVER for dm spi flash. Having a common code base for dm and nodm with ifdef make it difficult to extend functionalities and also difficult to read. So, keep them separate and give scope to dm code for further enhancements. Cc: Simon Glass Cc: Vignesh R Cc: Daniel Schwierzeck Signed-off-by: Jagan Teki --- drivers/mtd/spi/Makefile | 8 ++- drivers/mtd/spi/sf-nodm.c | 76 +++++++++++++++++++++ drivers/mtd/spi/sf-uclass.c | 128 ++++++++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 drivers/mtd/spi/sf-nodm.c diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile index b5dfa300de..b3ae74dbe8 100644 --- a/drivers/mtd/spi/Makefile +++ b/drivers/mtd/spi/Makefile @@ -3,8 +3,12 @@ # (C) Copyright 2006 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. -obj-$(CONFIG_DM_SPI_FLASH) += sf-uclass.o -spi-nor-y := sf_probe.o spi-nor-ids.o +ifdef CONFIG_DM_SPI_FLASH +spi-nor-y += sf-uclass.o +else +spi-nor-y += sf-nodm.o +endif +spi-nor-y += spi-nor-ids.o ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_SPI_BOOT) += fsl_espi_spl.o diff --git a/drivers/mtd/spi/sf-nodm.c b/drivers/mtd/spi/sf-nodm.c new file mode 100644 index 0000000000..b23014c2a8 --- /dev/null +++ b/drivers/mtd/spi/sf-nodm.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SPI flash probing + * + * Copyright (C) 2008 Atmel Corporation + * Copyright (C) 2010 Reinhard Meyer, EMK Elektronik + * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. + */ + +#include +#include +#include +#include +#include +#include + +#include "sf_internal.h" + +struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode) +{ + struct spi_slave *bus; + struct spi_flash *flash; + int ret; + + /* Allocate space if needed (not used by sf-uclass) */ + flash = calloc(1, sizeof(*flash)); + if (!flash) { + debug("SF: Failed to allocate spi_flash\n"); + return NULL; + } + + bus = spi_setup_slave(busnum, cs, max_hz, spi_mode); + if (!bus) { + printf("SF: Failed to set up slave\n"); + goto err_free; + } + + flash->spi = bus; + + /* Claim spi bus */ + ret = spi_claim_bus(bus); + if (ret) { + debug("SF: Failed to claim SPI bus: %d\n", ret); + goto err_free_slave; + } + + ret = spi_nor_scan(flash); + if (ret) + goto err_read_id; + + if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) { + ret = spi_flash_mtd_register(flash); + if (ret) + goto err_read_id; + } + + return flash; + +err_read_id: + spi_release_bus(bus); +err_free_slave: + spi_free_slave(bus); +err_free: + free(flash); + return NULL; +} + +void spi_flash_free(struct spi_flash *flash) +{ + if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) + spi_flash_mtd_unregister(); + + spi_free_slave(flash->spi); + free(flash); +} diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index 5a42ab83c8..97a3f5d2c7 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -95,6 +95,134 @@ static int spi_flash_post_bind(struct udevice *dev) 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 mtd_info *mtd = &flash->mtd; + size_t retlen; + + return log_ret(mtd->_read(mtd, offset, len, &retlen, buf)); +} + +static int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len, + const void *buf) +{ + struct spi_flash *flash = dev_get_uclass_priv(dev); + struct mtd_info *mtd = &flash->mtd; + size_t retlen; + + return mtd->_write(mtd, offset, len, &retlen, buf); +} + +static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len) +{ + struct spi_flash *flash = dev_get_uclass_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"); + return -EINVAL; + } + + memset(&instr, 0, sizeof(instr)); + instr.addr = offset; + instr.len = len; + + return mtd->_erase(mtd, &instr); +} + +int spi_flash_std_probe(struct udevice *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); + return ret; + } + + ret = spi_nor_scan(flash); + if (ret) + goto err_read_id; + + if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) + ret = spi_flash_mtd_register(flash); + +err_read_id: + spi_release_bus(slave); + return ret; +} + +static int spi_flash_std_remove(struct udevice *dev) +{ + if (CONFIG_IS_ENABLED(SPI_FLASH_MTD)) + spi_flash_mtd_unregister(); + + return 0; +} + +static const struct dm_spi_flash_ops spi_flash_std_ops = { + .read = spi_flash_std_read, + .write = spi_flash_std_write, + .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" }, + { } +}; + +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), + .ops = &spi_flash_std_ops, +}; + UCLASS_DRIVER(spi_flash) = { .id = UCLASS_SPI_FLASH, .name = "spi_flash", From patchwork Thu May 14 18:09:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1209 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 A2B2B3F077 for ; Thu, 14 May 2020 20:09:56 +0200 (CEST) Received: by mail-pg1-f198.google.com with SMTP id 14sf2941600pgm.3 for ; Thu, 14 May 2020 11:09:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589479794; cv=pass; d=google.com; s=arc-20160816; b=eXMH27Ooo9lN9jwDW5cruKW6JBPWXgorcSnXNKNpp68scazaUbc+lmw2HoBFSiZxeG JvD1yKkZAQVIMv5W07UNFnFUMXUIaMGKg88Fc4x+vWSLfLCQqHFXZAYf+/qiaD+TaraG CWMBJNvzS6iCHsFr9kp1czVR0fm+yQKIHL/OFEZKmCGln0hL3goOIWzhrugM3qzCaMUH mTnrICZzcn2x20+2UHTIKGR5ORPhvynKFq/vupBx66gk4n8MLi2m8KdSXviTMAxN3LU6 pCWuTr4XH5/HN/R4/I/nKhatSgy4QBL/KpMaD+UVDcaSee0uCGTefCqGTQ/rkTAdd7jV J+SA== 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=g893TPNDudBH5BN3sMLfKNXSTaV3IpqpdZbkvBNZcjM=; b=Iw/gks0vyPK+xWpagIxRw/xtX41lHXFqIrCmiYQSc4Xtxw+CmlpVsh1yHsmtRg37Ez Dl3Jv/hyYXYt3knUcLMat9jU5sUrvgdZQZxVjrJ6UzYn5MzoleXSIusdRpG1xxAiARw0 kEOLm/qvfM33sEWMx8uQJNMGuM0ZCkW2/qo3XKcvdecXFUO2Yw8DTr6YeiMVhefMxIEw ic2k1yOTHNn4bYt/NEbk0KMRGrAkkSSoGJFrGBdKCvEdQn8dFkJO/j8ZY/Kmytt+xGw2 V8tE2tsGb2kaJ2xJCasO3xtWX0Wd1PJi96MkDRY4IiTdlhLjKQQeINCi1fIYtTtOf+vx 9Iuw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=LxUcPN83; 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=g893TPNDudBH5BN3sMLfKNXSTaV3IpqpdZbkvBNZcjM=; b=AkXgGLqvfwItZxIOBb+BScw9w7xKdANp/BwyXPAtJ/AONlDuh+6XHRy0QMZaGdN/uB r8CScB2zGE9CL8prwA55Da3gQ0BVwyENiPnNI5OVjudYuhq8MhVVD0MCEwTYy0Ogtz0z y+I14c4gImuCz2iiv6Cct3qknOEySSKS42UhQ= 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=g893TPNDudBH5BN3sMLfKNXSTaV3IpqpdZbkvBNZcjM=; b=le+lRDWREawQnDrXvW+xBjTxly9CkjoVAk7GbypL8AADXl1e23VpfpDxDRxkZ1uXqy n7zzzQKH4G2buVrvV/iVIzLuuyt5ErEzcex/eyGUIMsa9Kt+MUMKG5A4KeSJcMc2utdJ FMvakb+eUQXbeb2Lkmwsmq3xMcYNNdeQ6iN2GAxGOoK6Dz9fdX9bkjzOCX4fxmrOFh00 O0ckel4GGY33UGolHjR4RVVWnBHj3f+TZfQblW+QHEgrF4fPZZ+GWM8i7f5sxv4p/TJ0 JL5iJU8VR51E7PWmEXKf3C9+wCOuh7UULUAb05yMJQVX5U+YT6Q5Uc/t2OZukJ0t9FKT GukA== X-Gm-Message-State: AGi0PuYqhRV/4EmJZ7HEmxsOOuAhJkDOLdl5N0K7hWTgVmIAN0Cj0/rj W/7nREavaOk3CmRGxBZuPMjpRfO7 X-Google-Smtp-Source: APiQypLFS8VOz3Ju8sf0zb2F1qJR7WW1UsJSuyGUb8pQ/9IRJwm6l8FEaLZEXEhTLS9nhdd5ElUG+A== X-Received: by 2002:a17:90a:6283:: with SMTP id d3mr43225972pjj.18.1589479794296; Thu, 14 May 2020 11:09:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:e283:: with SMTP id d3ls3083270pjz.2.gmail; Thu, 14 May 2020 11:09:54 -0700 (PDT) X-Received: by 2002:a17:902:bd0a:: with SMTP id p10mr5234238pls.102.1589479793723; Thu, 14 May 2020 11:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589479793; cv=none; d=google.com; s=arc-20160816; b=lGJUqUUZ6H09p7ZhiIvlRITDDtd6knuWzBJcOa8NbRyNnRjdq5MaMzAe2K/yTgYbQN nyUX97J2GBtikUl20dH31pPi0SGS3FTOeZuUk+A61T+IwBGPjFzdHvdyz5gdJUM65bUq 8qkq2uMPNj9S9uYN6SaF0AODlOo5wTzUjLGbkJ+7I8AsdA0SccBa5JahlNDJRRWn18co yFPQFC6thBCx5NLGGIrpZwmBo9IKvV9GXei9+zjWZdD4NADyasALbJx+UT1Xj1VuBUh2 sKRg7LF3ghp/IaRzNgf+8nkQqivSYC9/G2eBpDzadlX/vQOY2UBkFn2fnrZMPpIpSwsX zjxA== 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=tcLLIUEKBYC2Ne3c29IiQz02OxDeCU6laymgkXSNrws=; b=MbKV9M3JapOEGM2BkvC+FfEHqqX8jvc6yI058V16A4Uo7JRMndKhwSCCbxicKvwig1 yjzKbrR9Dj/8C23B1ePQ5b/bLglHCW3o/LEBiswwR7niojvozE61P7uDcf3u+2lKDLxj yDBKzMgvw+ku3cZPM9gBgQjemvZJV8jwVtxVZVTByoQfJE2kbpAyV2y9+j6dvtieYHnm Dx/bFnliSrmJJ/rKaRl4jJrM1izWj+rXfATX3gfb9AEpQc9Wr0UTpGxMmEBx/PvDOHOV c3xeL4kmHF1br9+Cj7WVQDe1to8SDxVY2vRAXr5ltwRPp3lDxpabY6Z5/eGJldtBB8Aj cRbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=LxUcPN83; 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 ce17sor29790738pjb.28.2020.05.14.11.09.53 for (Google Transport Security); Thu, 14 May 2020 11:09:53 -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:90b:14ce:: with SMTP id jz14mr42804788pjb.30.1589479793407; Thu, 14 May 2020 11:09:53 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:713c:4a0a:47eb:ffcd]) by smtp.gmail.com with ESMTPSA id m63sm2904117pfb.101.2020.05.14.11.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 11:09:52 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Cc: linux-amarula@amarulasolutions.com, Jagan Teki , Simon Glass , Vignesh R , Daniel Schwierzeck Subject: [PATCH 2/2] sf: Simplify probe for dm code Date: Thu, 14 May 2020 23:39:41 +0530 Message-Id: <20200514180941.21542-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514180941.21542-1-jagan@amarulasolutions.com> References: <20200514180941.21542-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=LxUcPN83; 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: , Handling probing code for a particular uclass between dm vs nodm always confusing and requires additional ifdefs to handle them properly. But, having separate low-level code bases for dm and nodm can make it easy for the command level to use same function name to probe the devices. This would indeed avoid extra ifdef call in source code. So, this patch probes the spi flash in common legacy call spi_flash_probe for both dm and nodm devices and give a chance to handle on respective code bases based on the build files. Cc: Simon Glass Cc: Vignesh R Cc: Daniel Schwierzeck Signed-off-by: Jagan Teki --- cmd/sf.c | 22 --------------------- drivers/mtd/spi/sf-uclass.c | 38 +++++++++++++------------------------ drivers/net/fm/fm.c | 20 ------------------- env/sf.c | 17 +---------------- include/spi_flash.h | 20 +++++-------------- 5 files changed, 19 insertions(+), 98 deletions(-) diff --git a/cmd/sf.c b/cmd/sf.c index 302201c2b0..3835dd857d 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -87,12 +87,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; -#ifdef CONFIG_DM_SPI_FLASH - struct udevice *new, *bus_dev; - int ret; -#else struct spi_flash *new; -#endif if (argc >= 2) { cs = simple_strtoul(argv[1], &endp, 0); @@ -120,22 +115,6 @@ static int do_spi_flash_probe(int argc, char * const argv[]) return -1; } -#ifdef CONFIG_DM_SPI_FLASH - /* Remove the old device, otherwise probe will just be a nop */ - ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new); - if (!ret) { - device_remove(new, DM_REMOVE_NORMAL); - } - flash = NULL; - ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new); - if (ret) { - printf("Failed to initialize SPI flash at %u:%u (error %d)\n", - bus, cs, ret); - return 1; - } - - flash = dev_get_uclass_priv(new); -#else if (flash) spi_flash_free(flash); @@ -145,7 +124,6 @@ static int do_spi_flash_probe(int argc, char * const argv[]) printf("Failed to initialize SPI flash at %u:%u\n", bus, cs); return 1; } -#endif return 0; } diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index 97a3f5d2c7..4993f7cd02 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -29,50 +29,38 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len) return log_ret(sf_get_ops(dev)->erase(dev, offset, len)); } -/* - * TODO(sjg@chromium.org): This is an old-style function. We should remove - * it when all SPI flash drivers use dm - */ -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode) -{ - struct udevice *dev; - - if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev)) - return NULL; - - return dev_get_uclass_priv(dev); -} - void spi_flash_free(struct spi_flash *flash) { device_remove(flash->spi->dev, DM_REMOVE_NORMAL); } -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, - struct udevice **devp) +struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode) { struct spi_slave *slave; - struct udevice *bus; + struct udevice *new, *bus_dev; char *str; int ret; + /* Remove the old device, otherwise probe will just be a nop */ + ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new); + if (!ret) + device_remove(new, DM_REMOVE_NORMAL); + #if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USE_TINY_PRINTF) str = "spi_flash"; #else char name[30]; - snprintf(name, sizeof(name), "spi_flash@%d:%d", busnum, cs); + snprintf(name, sizeof(name), "spi_flash@%d:%d", bus, cs); str = strdup(name); #endif - ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, - "spi_flash_std", str, &bus, &slave); + ret = spi_get_bus_and_cs(bus, cs, max_hz, spi_mode, + "spi_flash_std", str, &bus_dev, &slave); if (ret) - return ret; + return NULL; - *devp = slave->dev; - return 0; + return dev_get_uclass_priv(slave->dev); } static int spi_flash_post_bind(struct udevice *dev) diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c index 8ab1816395..811d1cd4fa 100644 --- a/drivers/net/fm/fm.c +++ b/drivers/net/fm/fm.c @@ -383,20 +383,10 @@ int fm_init_common(int index, struct ccsr_fman *reg) addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); int ret = 0; -#ifdef CONFIG_DM_SPI_FLASH - struct udevice *new; - - /* speed and mode will be read from DT */ - ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, - CONFIG_ENV_SPI_CS, 0, 0, &new); - - ucode_flash = dev_get_uclass_priv(new); -#else ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); -#endif if (!ucode_flash) { printf("SF: probe for ucode failed\n"); } else { @@ -470,18 +460,8 @@ int fm_init_common(int index, struct ccsr_fman *reg) void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); int ret = 0; -#ifdef CONFIG_DM_SPI_FLASH - struct udevice *new; - - /* speed and mode will be read from DT */ - ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - 0, 0, &new); - - ucode_flash = dev_get_uclass_priv(new); -#else ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); -#endif if (!ucode_flash) printf("SF: probe for ucode failed\n"); else { diff --git a/env/sf.c b/env/sf.c index af59c8375c..253f467832 100644 --- a/env/sf.c +++ b/env/sf.c @@ -35,21 +35,6 @@ static struct spi_flash *env_flash; static int setup_flash_device(void) { -#ifdef CONFIG_DM_SPI_FLASH - struct udevice *new; - int ret; - - /* speed and mode will be read from DT */ - ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, - &new); - if (ret) { - env_set_default("spi_flash_probe_bus_cs() failed", 0); - return ret; - } - - env_flash = dev_get_uclass_priv(new); -#else struct spi_flash *new; if (env_flash) @@ -62,7 +47,7 @@ static int setup_flash_device(void) env_set_default("spi_flash_probe() failed", 0); return -EIO; } -#endif + return 0; } diff --git a/include/spi_flash.h b/include/spi_flash.h index 3b33b970ef..c270c6eff7 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -75,17 +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); -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, - struct udevice **devp); - -/* Compatibility function - this is the old U-Boot API */ -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode); - -/* Compatibility function - this is the old U-Boot API */ -void spi_flash_free(struct spi_flash *flash); - static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf) { @@ -112,10 +101,6 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs, void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs); #else -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode); - -void spi_flash_free(struct spi_flash *flash); static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf) @@ -154,6 +139,11 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, } #endif +struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode); + +void spi_flash_free(struct spi_flash *flash); + static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len, bool prot) {