From patchwork Thu Jan 23 10:30:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 23581 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 02D93218BD for ; Thu, 23 Jan 2014 10:32:07 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf4045652pab.2 for ; Thu, 23 Jan 2014 02:32:07 -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=M4vCr9HPSMruThkIf1AsipmfTlJbCdxS3zjOLo5GvZw=; b=csmo02tzU629BVL+20IIOvBUX2edG/gRPU4DO1sDhYKYQPytFSGXzJvFaVD7vRGmpM OhLyj7kYsE7fowd+r4fOuk/dCrHK2jYDKsdpi6caNm1kBlljcpC6aHeyLGa2OWNyk3jL VvoamBRg6UfhWHemBeNSv5N3/7D2W8qGIDB2oAj2eX5Y2MLwc0XppaFC10CLNojJSHwJ ytaV14+ID5w9twoljHu1X7+LXYtAMy+859shPOJvvxMHROlYQkbQFO7PjwfupFkARd8q GFBG2xlZB9s/By3sRzAOW+y9gSj3UMuYu0f8SuVFzmuQMiFU47s+m5Mk+N+fpDlAkLl5 B5Ag== X-Gm-Message-State: ALoCoQm0tG04w0DVBEBlLs1UnJYW94VKqPtUq1elzgVWf7Qo9/L3Gw7DCRoBUg6LohveMTwsMD5K X-Received: by 10.66.137.8 with SMTP id qe8mr422420pab.46.1390473127249; Thu, 23 Jan 2014 02:32:07 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.134 with SMTP id i6ls281652qge.2.gmail; Thu, 23 Jan 2014 02:32:07 -0800 (PST) X-Received: by 10.220.103.141 with SMTP id k13mr4075756vco.25.1390473127102; Thu, 23 Jan 2014 02:32:07 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id e5si6418196vcf.146.2014.01.23.02.32.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:07 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id pa12so972071veb.2 for ; Thu, 23 Jan 2014 02:32:07 -0800 (PST) X-Received: by 10.220.109.1 with SMTP id h1mr4137562vcp.20.1390473127019; Thu, 23 Jan 2014 02:32:07 -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 u4csp15928vcz; Thu, 23 Jan 2014 02:32:06 -0800 (PST) X-Received: by 10.180.189.211 with SMTP id gk19mr7102035wic.29.1390473126024; Thu, 23 Jan 2014 02:32:06 -0800 (PST) Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) by mx.google.com with ESMTPS id m13si8772170wjr.119.2014.01.23.02.32.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:06 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.176 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.176; Received: by mail-we0-f176.google.com with SMTP id t61so922292wes.21 for ; Thu, 23 Jan 2014 02:32:05 -0800 (PST) X-Received: by 10.194.170.133 with SMTP id am5mr6015782wjc.42.1390473125506; Thu, 23 Jan 2014 02:32:05 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id ay6sm21257831wjb.23.2014.01.23.02.32.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:04 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Angus.Clark@st.com, DCG_UPD_stlinux_kernel@list.st.com, olivier.clergeaud@st.com, Lee Jones Subject: [PATCH RESEND v4 10/37] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Thu, 23 Jan 2014 10:30:58 +0000 Message-Id: <1390473085-24626-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> References: <1390473085-24626-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.128.171 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 | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 455deef..a70e916 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -240,6 +240,7 @@ struct stfsm { struct resource *region; struct mtd_info mtd; struct mutex lock; + struct flash_info *info; uint32_t fifo_dir_delay; }; @@ -508,6 +509,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]; @@ -525,6 +527,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; } @@ -619,6 +630,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; @@ -665,7 +677,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); @@ -674,6 +690,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); }