From patchwork Thu Mar 20 09:20:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26642 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D4524202E0 for ; Thu, 20 Mar 2014 09:21:40 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id lh14sf1428394vcb.2 for ; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) 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=YSxc7bY2L87EiW78YuqUgCH7ZbwfqR+FnQYvTXDU0Cw=; b=SUxmUheQP55MUDKicOtq3Kzntv0Xy1gO2wbZwf3PxM30wSLPoVgdw4MJprsKgrEXsf wSIqynEML8xRMkHmCwTP4iI/pK4y1j3IaPDN6vPwYsLw6unmkLo7Qzy5JPXPoWw3Maaa Qyy+Fmds1RexOnhQkaq2ZDC5du8KEFUIyUmjurftdtTvZNI+h8CPwMkNfxx2U214jcUA CtgytLzIUFH9pjvKdXeUj6euOv1Ai/K9B9OFw5dFnf7bFPsKgkPEwAa3aAFqFIoNZStU qQO3tMCnQU0KC0qTTIi961JCZPVDpWWKLUp7Qdf049DpD+Oy165ppYqfGwzbZkvyYT4f M7PA== X-Gm-Message-State: ALoCoQmh2xPOK4vtoHm3XAEaiave7M0QXaHP7QYx+t4auuqtq4NTWbKCMKAkQOZv00Xh7qfpvBPd X-Received: by 10.236.175.66 with SMTP id y42mr9621420yhl.38.1395307300488; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.14 with SMTP id 14ls152437qgs.58.gmail; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) X-Received: by 10.221.27.8 with SMTP id ro8mr3907555vcb.30.1395307300356; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id rx10si304743vdc.60.2014.03.20.02.21.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:40 -0700 (PDT) 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 cz12so601684veb.2 for ; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) X-Received: by 10.58.162.168 with SMTP id yb8mr12681468veb.9.1395307300278; Thu, 20 Mar 2014 02:21:40 -0700 (PDT) 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.78.9 with SMTP id i9csp372510vck; Thu, 20 Mar 2014 02:21:39 -0700 (PDT) X-Received: by 10.194.109.68 with SMTP id hq4mr33324494wjb.12.1395307299019; Thu, 20 Mar 2014 02:21:39 -0700 (PDT) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by mx.google.com with ESMTPS id rz17si843752wjb.88.2014.03.20.02.21.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:39 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.45 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.45; Received: by mail-wg0-f45.google.com with SMTP id l18so375690wgh.16 for ; Thu, 20 Mar 2014 02:21:38 -0700 (PDT) X-Received: by 10.180.126.38 with SMTP id mv6mr23277130wib.46.1395307298447; Thu, 20 Mar 2014 02:21:38 -0700 (PDT) Received: from lee--X1.home (host109-148-116-196.range109-148.btcentralplus.com. [109.148.116.196]) by mx.google.com with ESMTPSA id di9sm4735120wid.6.2014.03.20.02.21.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 02:21:33 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, computersforpeace@gmail.com Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org, Angus.Clark@st.com, Lee Jones Subject: [PATCH v6 09/36] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Thu, 20 Mar 2014 09:20:41 +0000 Message-Id: <1395307268-12721-10-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395307268-12721-1-git-send-email-lee.jones@linaro.org> References: <1395307268-12721-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. Acked-by Angus Clark Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 29da522..9467585 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -204,6 +204,7 @@ struct stfsm { struct resource *region; struct mtd_info mtd; struct mutex lock; + struct flash_info *info; uint32_t fifo_dir_delay; }; @@ -477,6 +478,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]; @@ -494,6 +496,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; } @@ -588,6 +599,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; @@ -627,13 +639,25 @@ 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; fsm->mtd.dev.parent = &pdev->dev; fsm->mtd.type = MTD_NORFLASH; 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); }