From patchwork Tue Apr 11 16:17:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 749556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2XKh2nYpz9sD5 for ; Wed, 12 Apr 2017 02:18:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="X8wp7kkT"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KY/MKKoZ"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=YuEGhNaQEq0njyNZ0efd+cShw4EitP7l3elKxCGgWTU=; b=X8w p7kkTDPEOJQM9+f8D7L3Ax2HWihy9QSXKGoa0yR9HoW62u/9Jf5sVsB+3HTt86RoXb7JW/ougj6Ff 5yz7+UQJkGQ6MX5I9P+pfLmSzW5jRe/UHuGJmn419ZrQ3/OCTmvksEEiBeMYaMa9P5kzRTkrWpkhj E+W9M0oHxH13PHT5sDIfhtJ6V/BwAJV+i7Yy987RAEVjp+on58taklCdjNl0nxL/E9opoa3ntlOX4 HpAGfYvKTcdJcGNh2kcv8hDliDunTRB7Ewcb7TJXfqlFkcN2ZdEl1zFrqfgGy0/unpKSWgLe/CiMl C8DxFMhEFCM/nAfn/WsyUD5+xurZQ5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cxyUs-0006XH-VM; Tue, 11 Apr 2017 16:18:26 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cxyUY-00069A-LP for linux-mtd@lists.infradead.org; Tue, 11 Apr 2017 16:18:08 +0000 Received: by mail-pf0-x242.google.com with SMTP id a188so306899pfa.2 for ; Tue, 11 Apr 2017 09:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=J5b3dy/lXfijLVBdbgduiNjVoccHsWDhU6yFmLOKLJw=; b=KY/MKKoZ43iPp++u8tH2kH5lUIUm2ZdM6p7NdtAkDv6lqXvnSKZmpXQv3ubDCOizvc RZaDxbpW5llt8GXJ+o4V1zv+Fiiukb0SRxc+J6AqwzupCk+nJpMRfBZ2JiCsMKHzToVX QVrFvz6ZfGSzHikQXypS2oACfNyc4opAuaKYGdfewO1WShTb5+2cgVGWdOLybRiFVPIe MWt3i3H6+slWKGo+Q+b5yZQmKVoJnahX1YVGPi2WTN71jnKJztFz5HRnlLMVEA+N26Rm Gd7ESz5U4IQBLKhdHn6ynttgxtzHoK5d6vXKboMihwz4ouGrA2303C0aG21qasmyZjsL gvww== 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; bh=J5b3dy/lXfijLVBdbgduiNjVoccHsWDhU6yFmLOKLJw=; b=K6GrdRq3U3Tu/T6HHw1aVnjrwg/Z53eFjieBVkRqHgE0oEKnZe9ryjNibrBQUUu9+r Zjn9Np/dRYfHxW/iHla0+1vh+KrVHlo7zJ+tl/qdgxdBngcB7LnjeTRx8cUQI3LIAaA3 bUG7UqEIsNx83G1W2BQhbB7WQ4PX1y3zk52j8VLyZ63Z6ZtLf2ytW8nNJOoAnHEjlwzY sUCJGmdqeTXhUdvqdp5JeJ6umkN9ren/ziD3hiacecTHCGGBAt3qKo1lBTN9BkoO5Ilu GSt5ZF+tXFjTrONuI18Jf2OJRbdp0yEF1sIsETcJA8/Q6Y3k/jRXibrTPWFyul+EPHqd 2tOg== X-Gm-Message-State: AFeK/H3PBJktsKSLkMJ85LPQe7hs4Z3u8eONhxXp2U7dDNi/YBhYirrF/3nMBmEIKzk3oA== X-Received: by 10.98.94.132 with SMTP id s126mr62060482pfb.133.1491927464466; Tue, 11 Apr 2017 09:17:44 -0700 (PDT) Received: from squirtle.lan (c-73-19-0-61.hsd1.wa.comcast.net. [73.19.0.61]) by smtp.gmail.com with ESMTPSA id c28sm13707975pfe.112.2017.04.11.09.17.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 09:17:43 -0700 (PDT) From: Andrey Smirnov To: linux-mtd@lists.infradead.org Subject: [PATCH 1/2] mtd: dataflash: Make use of "extened device information" Date: Tue, 11 Apr 2017 09:17:21 -0700 Message-Id: <20170411161722.11164-1-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170411_091806_751192_FA7E681B X-CRM114-Status: GOOD ( 20.14 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c00:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (andrew.smirnov[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Andrey Smirnov , Richard Weinberger , linux-kernel@vger.kernel.org, Marek Vasut , Cyrille Pitchen , Brian Norris , David Woodhouse , cphealy@gmail.com MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In anticipation of supporting chips that need it, extend the size of struct flash_info's 'jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data during jedec_probe(). Cc: cphealy@gmail.com Cc: David Woodhouse Cc: Brian Norris Cc: Boris Brezillon Cc: Marek Vasut Cc: Richard Weinberger Cc: Cyrille Pitchen Cc: linux-kernel@vger.kernel.org Signed-off-by: Andrey Smirnov --- drivers/mtd/devices/mtd_dataflash.c | 113 +++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 47 deletions(-) diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c index f9e9bd1..9a98cdc 100644 --- a/drivers/mtd/devices/mtd_dataflash.c +++ b/drivers/mtd/devices/mtd_dataflash.c @@ -689,7 +689,7 @@ struct flash_info { /* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ - uint32_t jedec_id; + uint64_t jedec_id; /* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages; @@ -712,61 +712,35 @@ static struct flash_info dataflash_data[] = { * These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe(struct spi_device *spi) +static struct flash_info *jedec_lookup(struct spi_device *spi, + uint64_t jedec) { - int tmp; - uint8_t code = OP_READ_ID; - uint8_t id[3]; - uint32_t jedec; - struct flash_info *info; - int status; - - /* JEDEC also defines an optional "extended device information" - * string for after vendor-specific data, after the three bytes - * we use here. Supporting some chips might require using it. - * - * If the vendor ID isn't Atmel's (0x1f), assume this call failed. - * That's not an error; only rev C and newer chips handle it, and - * only Atmel sells these chips. - */ - tmp = spi_write_then_read(spi, &code, 1, id, 3); - if (tmp < 0) { - pr_debug("%s: error %d reading JEDEC ID\n", - dev_name(&spi->dev), tmp); - return ERR_PTR(tmp); - } - if (id[0] != 0x1f) - return NULL; - - jedec = id[0]; - jedec = jedec << 8; - jedec |= id[1]; - jedec = jedec << 8; - jedec |= id[2]; + int tmp, status; + struct flash_info *info; for (tmp = 0, info = dataflash_data; tmp < ARRAY_SIZE(dataflash_data); @@ -796,12 +770,57 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } + return NULL; +} + +static struct flash_info *jedec_probe(struct spi_device *spi) +{ + int tmp; + uint8_t code = OP_READ_ID; + uint8_t id[8] = {0}; + const unsigned int id_size = 5; + const unsigned int first_byte = sizeof(id) - id_size; + const uint64_t eid_mask = GENMASK_ULL(63, 16); + uint64_t jedec; + struct flash_info *info; + + /* JEDEC also defines an optional "extended device information" + * string for after vendor-specific data, after the three bytes + * we use here. Supporting some chips might require using it. + * + * If the vendor ID isn't Atmel's (0x1f), assume this call failed. + * That's not an error; only rev C and newer chips handle it, and + * only Atmel sells these chips. + */ + tmp = spi_write_then_read(spi, &code, 1, &id[first_byte], id_size); + if (tmp < 0) { + pr_debug("%s: error %d reading JEDEC ID\n", + dev_name(&spi->dev), tmp); + return ERR_PTR(tmp); + } + if (id[first_byte] != 0x1f) + return NULL; + + jedec = be64_to_cpup((__be64 *)id); + + info = jedec_lookup(spi, jedec); + if (info) + return info; + /* + * Clear extended id bits and try to find a match again + */ + jedec &= eid_mask; + + info = jedec_lookup(spi, jedec); + if (info) + return info; + /* * Treat other chips as errors ... we won't know the right page * size (it might be binary) even when we can tell which density * class is involved (legacy chip id scheme). */ - dev_warn(&spi->dev, "JEDEC id %06x not handled\n", jedec); + dev_warn(&spi->dev, "JEDEC id %010llx not handled\n", jedec); return ERR_PTR(-ENODEV); }