From patchwork Thu Jul 16 15:27:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrille Pitchen X-Patchwork-Id: 6808141 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 195A4C05AC for ; Thu, 16 Jul 2015 15:28:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38F96205B8 for ; Thu, 16 Jul 2015 15:28:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B5A420663 for ; Thu, 16 Jul 2015 15:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755328AbbGPP1x (ORCPT ); Thu, 16 Jul 2015 11:27:53 -0400 Received: from eusmtp01.atmel.com ([212.144.249.243]:20608 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755177AbbGPP1v (ORCPT ); Thu, 16 Jul 2015 11:27:51 -0400 Received: from tenerife.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server id 14.3.235.1; Thu, 16 Jul 2015 17:27:45 +0200 From: Cyrille Pitchen To: , , , , , , , , , , CC: , , , , , , , , , Cyrille Pitchen Subject: [PATCH 5/7] mtd: spi-nor: allow the set the latency code on Spansion memories Date: Thu, 16 Jul 2015 17:27:52 +0200 Message-ID: <12f0bceb57e1bf25279a995f76103b4e75091e82.1437059658.git.cyrille.pitchen@atmel.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both the SPI controller and the flash memory must agree on the number of dummy cycles to use for Fast Read commands. For Spansion memories, this number of dummy cycles is configured through a so called latency code in their Control Register. The right latency code can be found in the memory datasheet and depends on the SPI clock frequency, the op code of the Fast Read command and the Single/Dual Data Rate mode. Signed-off-by: Cyrille Pitchen --- drivers/mtd/spi-nor/spi-nor.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 5df6e4712a9e..32fddf06da3f 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -989,6 +989,50 @@ static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) } } +static int spansion_set_latency_code(struct spi_nor *nor) +{ + struct device_node *np = nor->dev->of_node; + u8 cr, mask = GENMASK(7, 6); + u32 lc; + int ret; + + if (!np || of_property_read_u32(np, "spansion,latency-code", &lc)) + return 0; + + if (lc & ~(mask >> 6)) { + dev_err(nor->dev, "invalid latency code: %u\n", lc); + return -EINVAL; + } + + ret = read_cr(nor); + if (ret < 0) { + dev_err(nor->dev, + "error while reading configuration register\n"); + return ret; + } + + write_enable(nor); + + cr = ret; + cr &= ~mask; + cr |= (lc << 6); + ret = write_sr_cr(nor, cr << 8); + if (ret < 0) { + dev_err(nor->dev, + "error while updating configuration register\n"); + return -EINVAL; + } + + /* read back and check it */ + ret = read_cr(nor); + if (!(ret >= 0 && (ret & mask) == (lc << 6))) { + dev_err(nor->dev, "Spansion latency code not set\n"); + return -EINVAL; + } + + return 0; +} + static int micron_set_dummy_cycles(struct spi_nor *nor) { int ret; @@ -1045,6 +1089,8 @@ static int spi_nor_read_dummy_cycles(struct spi_nor *nor, * backward compatibility. */ switch (JEDEC_MFR(info)) { + case CFI_MFR_AMD: + return spansion_set_latency_code(nor); case CFI_MFR_ST: return micron_set_dummy_cycles(nor); default: