From patchwork Wed Jan 8 13:46:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 22946 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 05C9F202E2 for ; Wed, 8 Jan 2014 13:48:40 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id lx4sf7209623iec.10 for ; Wed, 08 Jan 2014 05:48:40 -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=I/hTVx5eUyQozOqZL8KfsWhT8IGGLeTGnhCKb2tk1VoX8Z5tdd+oMefvbE4xq0unUG mSIHEq7MyFBWrbi2xqU0s4PYtzEFO4nK020P+lKjVBswd4JFuMr0Drr2nM1wYHgFnnij hgEhEas9fajnDaSHLnXkRTwTrxlztWL94eYAubt3WUgFM7vA/k+osX22AS0DvfgjOfye trsh17cZnD5NBm1/AWzGmYXBZ3N9PbuFW7oE+uhNc/Ey3qDbr6t/ERxX+1yuoR1fB0ir 6jKlSPT/yuhiwZlRUy+KetsoHU6z38X0RhZHC5gJIpmK74QcelEYlbxvEnWPMswHN0PP +CIA== X-Gm-Message-State: ALoCoQlWq3O2M5Ow/6yEkvg6+5hyzgSI9zWvsrN/AK5J85gT5rgml75PgvRl4VE8tBM+bIn7Vi0F X-Received: by 10.42.81.84 with SMTP id y20mr46670353ick.10.1389188920341; Wed, 08 Jan 2014 05:48:40 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.9 with SMTP id z9ls583691qem.79.gmail; Wed, 08 Jan 2014 05:48:40 -0800 (PST) X-Received: by 10.53.7.193 with SMTP id de1mr1253573vdd.91.1389188920214; Wed, 08 Jan 2014 05:48:40 -0800 (PST) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id sp7si594342vdc.112.2014.01.08.05.48.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:40 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.181 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.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so1242225veb.26 for ; Wed, 08 Jan 2014 05:48:40 -0800 (PST) X-Received: by 10.52.116.200 with SMTP id jy8mr23582829vdb.15.1389188920089; Wed, 08 Jan 2014 05:48:40 -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.59.13.131 with SMTP id ey3csp226605ved; Wed, 8 Jan 2014 05:48:39 -0800 (PST) X-Received: by 10.194.185.205 with SMTP id fe13mr50329696wjc.23.1389188918967; Wed, 08 Jan 2014 05:48:38 -0800 (PST) Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by mx.google.com with ESMTPS id mv9si2649122wic.0.2014.01.08.05.48.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:38 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.177 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.177; Received: by mail-we0-f177.google.com with SMTP id u56so1427213wes.22 for ; Wed, 08 Jan 2014 05:48:38 -0800 (PST) X-Received: by 10.180.38.8 with SMTP id c8mr21695739wik.48.1389188918559; Wed, 08 Jan 2014 05:48:38 -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 j9sm48125217wjx.18.2014.01.08.05.48.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:48:37 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, angus.clark@st.com, Lee Jones Subject: [PATCH v4 10/37] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Wed, 8 Jan 2014 13:46:53 +0000 Message-Id: <1389188840-14306-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389188840-14306-1-git-send-email-lee.jones@linaro.org> References: <1389188840-14306-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.181 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); }