From patchwork Thu Nov 14 14:22:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21506 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 52A0D23FDD for ; Thu, 14 Nov 2013 14:23:14 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id w5sf4231252qac.2 for ; Thu, 14 Nov 2013 06:23:14 -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=vDJvfyPIzpSG/1qVuEebV/59Zyb8OStaUSiZ+DCaZqU=; b=k5Vhx1FOGT3F0Rd4IXl3BvyyDwewBRx+yYTDeMsOrLKviBiM4fkChwBNbS08K7l3Ya R/srzmjclcY6kW4nzXmVjMuUaMCrYtqNF1iq8YT04spbq3w6ZaKPdzl/k6xSWHIlJYA2 xR+AXFkGHAIrbshB2LDOe0W7StpXyix2y9NloMivnP/ZdluSaXp9yWzGmrHfYz2Zz47d 4pMa0vfuLGGSH3Af96/q8UXsn15mM+bFRw2Al10mICwvnGqeoVuGmc0c5/wB+xhja+He gZ3pdHzaEp1Bam1mPr6FPOc+q3JNKMUeJALf+PKarEyaXRYiSimhbfz6g6LGIfvZZVhs kGPA== X-Gm-Message-State: ALoCoQk+JFLn82oWGtGhi7YvcGQusS4vXFpTEcLJoGUCoDLLBhMBjVTEyDjdQbdXbyf3TEASeOZi X-Received: by 10.58.88.2 with SMTP id bc2mr582298veb.37.1384438994062; Thu, 14 Nov 2013 06:23:14 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.29.200 with SMTP id m8ls989650qeh.1.gmail; Thu, 14 Nov 2013 06:23:14 -0800 (PST) X-Received: by 10.58.6.239 with SMTP id e15mr925817vea.29.1384438993970; Thu, 14 Nov 2013 06:23:13 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id t2si17196387vem.66.2013.11.14.06.23.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:13 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id q4so1758789vbe.27 for ; Thu, 14 Nov 2013 06:23:13 -0800 (PST) X-Received: by 10.58.143.17 with SMTP id sa17mr1008054veb.14.1384438993772; Thu, 14 Nov 2013 06:23:13 -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 u4csp319820vcz; Thu, 14 Nov 2013 06:23:13 -0800 (PST) X-Received: by 10.182.237.75 with SMTP id va11mr1644309obc.5.1384438993047; Thu, 14 Nov 2013 06:23:13 -0800 (PST) Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179]) by mx.google.com with ESMTPS id ds9si30433830obc.60.2013.11.14.06.23.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.179 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.214.179; Received: by mail-ob0-f179.google.com with SMTP id wn1so2202985obc.38 for ; Thu, 14 Nov 2013 06:23:10 -0800 (PST) X-Received: by 10.182.254.2 with SMTP id ae2mr1546112obd.105.1384438990820; Thu, 14 Nov 2013 06:23:10 -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 z5sm5585965obg.13.2013.11.14.06.23.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 06:23:10 -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, angus.clark@st.com, Lee Jones Subject: [PATCH 09/10] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Thu, 14 Nov 2013 14:22:35 +0000 Message-Id: <1384438956-31153-10-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1384438956-31153-1-git-send-email-lee.jones@linaro.org> References: <1384438956-31153-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.212.54 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 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 230024c..42dd4d9 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -357,6 +357,7 @@ static int 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]; @@ -380,6 +381,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; } @@ -490,6 +500,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; @@ -536,7 +547,9 @@ 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; platform_set_drvdata(pdev, fsm); @@ -545,6 +558,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); }