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: 21690 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 65BEB23FDC for ; Fri, 22 Nov 2013 16:23:50 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id e14sf4446030iej.8 for ; Fri, 22 Nov 2013 08:23:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=qm9+uQQyEAzC61Kvz5A2Fx39EQGcrRK/zmEt/iYf5NY=; b=FOUGKCf6xKfeo+ulDLyQ2CxYGc7LjRyNfbUV6+0flplpoZ30NZK2+Cce0+zFf/yFVn W0BXNg1SEcRoakWgD1dG82EZv+2nFvRlD+CZFTmlUhDPTguyouznL20gfnQkM2MNpff7 2tfdihgasOgImGtUkPLwYBj3h238lp55OnwZ9ns4duf3xkTCC2sTB0784ywsIU3hnWF/ QjKs2mq/PO4dd4Qd7Imy0CwzP7xv3ZMrYYirEs7PDlk7tsKxT4J5yfc4TQ/6/YoBXw1f xgvhN0zQ1BfBnpFHzUPHGawNiig1fuQqJ8jWx5sWoMC72HpeykYwY8pZWb4yADAZ6XoT pxJA== X-Gm-Message-State: ALoCoQkZQXNhEJCxHOuAwsUyleuFexPpH/Tbl5ck0BrJUJebbChlIpwkqrlQPsBJLRpSoRFxuY6C X-Received: by 10.42.29.5 with SMTP id p5mr3973489icc.19.1385137430000; Fri, 22 Nov 2013 08:23:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.81.199 with SMTP id c7ls1136791qey.23.gmail; Fri, 22 Nov 2013 08:23:49 -0800 (PST) X-Received: by 10.58.178.239 with SMTP id db15mr12258225vec.9.1385137429888; Fri, 22 Nov 2013 08:23:49 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id hs8si12862930veb.136.2013.11.22.08.23.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hu19so994610vcb.14 for ; Fri, 22 Nov 2013 08:23:49 -0800 (PST) X-Received: by 10.220.192.198 with SMTP id dr6mr11971249vcb.19.1385137429806; Fri, 22 Nov 2013 08:23:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp51522vcz; Fri, 22 Nov 2013 08:23:49 -0800 (PST) X-Received: by 10.68.216.132 with SMTP id oq4mr12685511pbc.50.1385137428880; Fri, 22 Nov 2013 08:23:48 -0800 (PST) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by mx.google.com with ESMTPS id ob10si20194302pbb.37.2013.11.22.08.23.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Nov 2013 08:23:48 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.44 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.220.44; Received: by mail-pa0-f44.google.com with SMTP id fa1so1520112pad.3 for ; Fri, 22 Nov 2013 08:23:48 -0800 (PST) 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 Cc: linus.walleij@linaro.org, Lee Jones 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; };