From patchwork Fri Nov 29 12:18:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21868 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B3EB623FC4 for ; Fri, 29 Nov 2013 12:19:56 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id f64sf22281377yha.10 for ; Fri, 29 Nov 2013 04:19:56 -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=agEttVPtSR+l5zgooSDhfdzmWwZiaO/RFybTY93yl1E=; b=e+lzbQjacZX4OdMxgcvoO1Grj3gOXrpB/h3ccd7upFj3vu4GYPCNolerhtTIG7BBvS MdxsaEOuCV6N9pS2oxV662l/YgBlbX/EyeW7+btXphln37LGtc6vFSlG1U8DCnV+dBVB Kk9BcJIAenUviG6vX0nBV3ffqR9pmrNV954oqPeKv9RH5wJHwNDygUpw0/ClvaF7EC3F tyM+weo/9cRIKkpz1YvIzAVfliC2H/5gz1mMFOBkYKcQKZOb4yrSST0HL6HrBxgn65Dj pJhfiZ6HFNVxRDJN35w9dyOIvOfP7KmR7HTKg0NOWXQIgjzzFdp7DxGsoAHBmYn+hNFK /raA== X-Gm-Message-State: ALoCoQl1DAVCa5I1Q+MUlUkvdERZ0zpcoG7d/0yawmUdmNOvHM6TBLbZUzyF+IrL296lGMazeMqK X-Received: by 10.58.181.69 with SMTP id du5mr16758379vec.7.1385727596523; Fri, 29 Nov 2013 04:19:56 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.48.82 with SMTP id j18ls2749856qen.49.gmail; Fri, 29 Nov 2013 04:19:56 -0800 (PST) X-Received: by 10.52.233.197 with SMTP id ty5mr1565851vdc.48.1385727596264; Fri, 29 Nov 2013 04:19:56 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id 1si24769362vel.150.2013.11.29.04.19.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.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.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so7167609vea.28 for ; Fri, 29 Nov 2013 04:19:56 -0800 (PST) X-Received: by 10.58.207.15 with SMTP id ls15mr42237866vec.17.1385727596178; Fri, 29 Nov 2013 04:19:56 -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 u4csp87402vcz; Fri, 29 Nov 2013 04:19:55 -0800 (PST) X-Received: by 10.236.28.162 with SMTP id g22mr2017671yha.52.1385727595468; Fri, 29 Nov 2013 04:19:55 -0800 (PST) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by mx.google.com with ESMTPS id a8si20241668qch.1.2013.11.29.04.19.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.43 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.213.43; Received: by mail-yh0-f43.google.com with SMTP id a41so6176528yho.30 for ; Fri, 29 Nov 2013 04:19:55 -0800 (PST) X-Received: by 10.236.199.81 with SMTP id w57mr829711yhn.139.1385727595184; Fri, 29 Nov 2013 04:19:55 -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 m29sm101911689yho.14.2013.11.29.04.19.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:19:54 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org Cc: linus.walleij@linaro.org, linux-mtd@lists.infradead.org, angus.clark@st.com, Lee Jones Subject: [PATCH v3 10/36] mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID Date: Fri, 29 Nov 2013 12:18:59 +0000 Message-Id: <1385727565-25794-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> References: <1385727565-25794-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.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 71b6188..ef177e5 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -140,6 +140,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]; @@ -157,6 +158,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 fd1472e..0a6272c 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; };