From patchwork Mon Oct 19 16:09:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 532434 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8C0D51401F6 for ; Tue, 20 Oct 2015 03:10:17 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B8FA84B70B; Mon, 19 Oct 2015 18:10:13 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jFegj1lrxBzn; Mon, 19 Oct 2015 18:10:13 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 33E874B6BD; Mon, 19 Oct 2015 18:10:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 869004B6BD for ; Mon, 19 Oct 2015 18:10:10 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1-i4G2TdUnbi for ; Mon, 19 Oct 2015 18:10:10 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by theia.denx.de (Postfix) with ESMTPS id 183AE4B6A7 for ; Mon, 19 Oct 2015 18:10:06 +0200 (CEST) Received: by padhk11 with SMTP id hk11so33821833pad.1 for ; Mon, 19 Oct 2015 09:10:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id; bh=rtf75zehA15aqS0DvRwxR+JDVdn/kw1512+MRu2B0/0=; b=gyo79WuCbakNLaFgUOR1Dhpaj9R6lqAbRtLFYCoi1pf2masoeBfON+ruzNuQX3xez1 fNm/l7iGw+GlPVAwawL4ZLF/gSt6RVWMtUtABNCDgJY8FXTQghxz1n53abxQbcyTqXlk f4u/mYIuJRYag/OazuH/MQtFE379WYNi3o0YvRtmwGQr/WSW71Kl0RxN3HQHnlovgypI MpHZLiUA68q4fyknJQ+t8lhT604vJgzrJOibWVnO7ZwaQ6lZCfdYiKaDT6SkUeoPRJP5 p4Ao+P8Sa76tEr9+zpFgapA/CScabuNR6HaPI2q1olOVGHoSF8f5gFeSryE7D0bUMV5l YKPw== X-Received: by 10.68.253.42 with SMTP id zx10mr32399449pbc.99.1445271005217; Mon, 19 Oct 2015 09:10:05 -0700 (PDT) Received: from localhost.localdomain ([123.236.183.133]) by smtp.gmail.com with ESMTPSA id sz9sm5711890pab.13.2015.10.19.09.10.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Oct 2015 09:10:04 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Mon, 19 Oct 2015 21:39:06 +0530 Message-Id: <1445270948-3747-1-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 Cc: Jagan Teki Subject: [U-Boot] [PATCH 1/3] sf: Add dm_spi_flash_probe X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Updated dm-spi-flash probe using dm_spi_flash_probe. Signed-off-by: Jagan Teki Cc: Simon Glass --- common/cmd_sf.c | 23 ++++------------------- drivers/mtd/spi/sf-uclass.c | 27 ++++++++++++++++++++++++++- include/spi_flash.h | 5 ++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/common/cmd_sf.c b/common/cmd_sf.c index ac7f5df..f1926e3 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -17,7 +16,6 @@ #include #include -#include static struct spi_flash *flash; @@ -85,10 +83,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 +#ifndef CONFIG_DM_SPI_FLASH struct spi_flash *new; #endif @@ -119,21 +114,11 @@ static int do_spi_flash_probe(int argc, char * const argv[]) } #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); - device_unbind(new); - } - 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); + flash = dm_spi_flash_probe(bus, cs, speed, mode); + if (!flash) { + printf("Failed to initialize SPI flash at %u:%u\n", bus, cs); return 1; } - - flash = dev_get_uclass_priv(new); #else if (flash) spi_flash_free(flash); diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index 350e21a..9c109fa 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -47,7 +47,7 @@ void spi_flash_free(struct spi_flash *flash) spi_flash_remove(flash->spi->dev); } -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, +static int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, unsigned int max_hz, unsigned int spi_mode, struct udevice **devp) { @@ -67,6 +67,31 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, return 0; } +struct spi_flash *dm_spi_flash_probe(unsigned int busnum, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode) +{ + struct udevice *bus, *new; + struct spi_flash *flash; + int ret; + + /* Remove the old device, otherwise probe will just be a nop */ + ret = spi_find_bus_and_cs(busnum, cs, &bus, &new); + if (!ret) { + device_remove(new); + device_unbind(new); + } + flash = NULL; + + ret = spi_flash_probe_bus_cs(busnum, cs, max_hz, spi_mode, &new); + if (ret) { + printf("Failed to initialize SPI flash at %u:%u (error %d)\n", + busnum, cs, ret); + return flash; + } + + return dev_get_uclass_priv(new); +} + int spi_flash_remove(struct udevice *dev) { return device_remove(dev); diff --git a/include/spi_flash.h b/include/spi_flash.h index 3b2d555..5abbf99 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -154,9 +154,8 @@ 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); +struct spi_flash *dm_spi_flash_probe(unsigned int busnum, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode); /* Compatibility function - this is the old U-Boot API */ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,