From patchwork Fri Nov 22 16:22:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 293569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A4E652C00A8 for ; Sat, 23 Nov 2013 04:50:22 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vjtpz-0004kp-Ig; Fri, 22 Nov 2013 16:44:12 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjtpP-00041a-Nb; Fri, 22 Nov 2013 16:43:35 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjtoZ-0003t8-18 for linux-mtd@merlin.infradead.org; Fri, 22 Nov 2013 16:42:43 +0000 Received: from mail-pa0-f51.google.com ([209.85.220.51]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjtWc-0004mK-Gy for linux-mtd@lists.infradead.org; Fri, 22 Nov 2013 16:24:11 +0000 Received: by mail-pa0-f51.google.com with SMTP id fa1so1501756pad.24 for ; Fri, 22 Nov 2013 08:23:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qm9+uQQyEAzC61Kvz5A2Fx39EQGcrRK/zmEt/iYf5NY=; b=WyddqfFiofl8h+6VnraPbZQEoDA506DQth4GWoMxOE54EHL4yzggZbU0wRXWGXBTAh 34gSIM2tfYb40lwXKiGAgCg7l1l3mfeV2lOfaSQe6ZhwGzPdeOJYViZE/rQV3QJrzaJ2 8U8JsMj+HU9TS9+rr2uONEQFUTBJ9BvuPTl8wa2N9olw2ahOQgDFt60rWWVQQ5mvZFrq wjttoGiG8OmhiG6ls4ZziSljnNkiXAeEpdgxD6wpvzfRa2DKQkO+Nzfdg21eoEzYh6Jw mgsgY6MHDSNBhWzFzyfVvvaUsEJm2cCJYKyX8UgjyrZJ1JVP/lQGafh3CCvbPvTzDL2P hqNA== X-Gm-Message-State: ALoCoQn4TKLHtZ3kVnRC0kne47umlvAS/0xxdzTzvYtZlseq35GGt6y+E+q80973pzcpAe7uejB+ X-Received: by 10.66.190.10 with SMTP id gm10mr12848213pac.126.1385137428464; Fri, 22 Nov 2013 08:23:48 -0800 (PST) Received: from localhost.localdomain (cpc15-aztw25-2-0-cust493.aztw.cable.virginm.net. [92.233.57.238]) by mx.google.com with ESMTPSA id qz9sm52962938pbc.3.2013.11.22.08.23.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:47 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, angus.clark@st.com Subject: [PATCH 10/23] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Fri, 22 Nov 2013 16:22:47 +0000 Message-Id: <1385137380-28968-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1385137380-28968-1-git-send-email-lee.jones@linaro.org> References: <1385137380-28968-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131122_162410_719928_F6B2FAF3 X-CRM114-Status: GOOD ( 14.78 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.51 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linus.walleij@linaro.org, Lee Jones X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Using previously added infrastructure we can now extract a device's JEDEC ID, compare it to a list of known and supported devices and make assumptions based on known characteristics of a given chip. Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 26 +++++++++++++++++++++++++- drivers/mtd/devices/st_spi_fsm.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index ddab76f..a66dbac 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -124,6 +124,7 @@ static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec) static struct flash_info * stfsm_jedec_probe(struct stfsm *fsm) { + struct flash_info *info; u16 ext_jedec; u32 jedec; u8 id[5]; @@ -141,6 +142,15 @@ static struct flash_info * stfsm_jedec_probe(struct stfsm *fsm) dev_dbg(fsm->dev, "JEDEC = 0x%08x [%02x %02x %02x %02x %02x]\n", jedec, id[0], id[1], id[2], id[3], id[4]); + for (info = flash_types; info->name; info++) { + if (info->jedec_id == jedec) { + if (info->ext_id && info->ext_id != ext_jedec) + continue; + return info; + } + } + dev_err(fsm->dev, "Unrecognized JEDEC id %06x\n", jedec); + return NULL; } @@ -251,6 +261,7 @@ static int stfsm_init(struct stfsm *fsm) static int stfsm_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; + struct flash_info *info; struct resource *res; struct stfsm *fsm; int ret; @@ -297,7 +308,11 @@ static int stfsm_probe(struct platform_device *pdev) } /* Detect SPI FLASH device */ - stfsm_jedec_probe(fsm); + info = stfsm_jedec_probe(fsm); + if (!info) + return -ENODEV; + + fsm->info = info; platform_set_drvdata(pdev, fsm); @@ -306,6 +321,15 @@ static int stfsm_probe(struct platform_device *pdev) fsm->mtd.writesize = 4; fsm->mtd.writebufsize = fsm->mtd.writesize; fsm->mtd.flags = MTD_CAP_NORFLASH; + fsm->mtd.size = info->sector_size * info->n_sectors; + fsm->mtd.erasesize = info->sector_size; + + dev_err(&pdev->dev, + "Found serial flash device: %s\n" + " size = %llx (%lldMiB) erasesize = 0x%08x (%uKiB)\n", + info->name, + (long long)fsm->mtd.size, (long long)(fsm->mtd.size >> 20), + fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10)); return mtd_device_parse_register(&fsm->mtd, NULL, NULL, NULL, 0); } diff --git a/drivers/mtd/devices/st_spi_fsm.h b/drivers/mtd/devices/st_spi_fsm.h index e4e5bfa..60341f2 100644 --- a/drivers/mtd/devices/st_spi_fsm.h +++ b/drivers/mtd/devices/st_spi_fsm.h @@ -235,6 +235,7 @@ struct stfsm { struct resource *region; struct mtd_info mtd; struct mutex lock; + struct flash_info *info; uint32_t fifo_dir_delay; };