From patchwork Thu Sep 30 08:00:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Mingkai-B21284 X-Patchwork-Id: 219212 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8U8ggCJ015752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 30 Sep 2010 08:43:06 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1P1Eiv-0004Cm-Sg; Thu, 30 Sep 2010 08:42:41 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1P1Eiv-0004Ch-DO for spi-devel-general@lists.sourceforge.net; Thu, 30 Sep 2010 08:42:41 +0000 X-ACL-Warn: Received: from va3ehsobe003.messaging.microsoft.com ([216.32.180.13] helo=VA3EHSOBE003.bigfish.com) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-MD5:128) (Exim 4.69) id 1P1Eiu-00074Z-Ir for spi-devel-general@lists.sourceforge.net; Thu, 30 Sep 2010 08:42:41 +0000 Received: from mail155-va3-R.bigfish.com (10.7.14.247) by VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id 8.1.340.0; Thu, 30 Sep 2010 08:27:27 +0000 Received: from mail155-va3 (localhost.localdomain [127.0.0.1]) by mail155-va3-R.bigfish.com (Postfix) with ESMTP id 105BF9102A2 for ; Thu, 30 Sep 2010 08:27:27 +0000 (UTC) X-SpamScore: -3 X-BigFish: VS-3(zzbb2cKzz1202hzz8275bh84d07hz2dh2a8h61h) X-Spam-TCS-SCL: 0:0 Received: from mail155-va3 (localhost.localdomain [127.0.0.1]) by mail155-va3 (MessageSwitch) id 1285835220760729_14523; Thu, 30 Sep 2010 08:27:00 +0000 (UTC) Received: from VA3EHSMHS020.bigfish.com (unknown [10.7.14.242]) by mail155-va3.bigfish.com (Postfix) with ESMTP id 03F5E670079 for ; Thu, 30 Sep 2010 08:26:02 +0000 (UTC) Received: from az33egw02.freescale.net (192.88.158.103) by VA3EHSMHS020.bigfish.com (10.7.99.30) with Microsoft SMTP Server (TLS) id 14.0.482.44; Thu, 30 Sep 2010 08:26:00 +0000 Received: from de01smr01.freescale.net (de01smr01.freescale.net [10.208.0.31]) by az33egw02.freescale.net (8.14.3/8.14.3) with ESMTP id o8U8Pxu5016521 for ; Thu, 30 Sep 2010 01:25:59 -0700 (MST) Received: from zch01exm21.fsl.freescale.net (zch01exm21.ap.freescale.net [10.192.129.205]) by de01smr01.freescale.net (8.13.1/8.13.0) with ESMTP id o8U8eU0C025766 for ; Thu, 30 Sep 2010 03:40:40 -0500 (CDT) Received: from localhost ([10.193.20.106]) by zch01exm21.fsl.freescale.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 30 Sep 2010 16:25:49 +0800 From: Mingkai Hu To: linuxppc-dev@ozlabs.org, spi-devel-general@lists.sourceforge.net, linux-mtd@lists.infradead.org Subject: [PATCH v3 5/7] mtd: m25p80: add support to parse the SPI flash's partitions Date: Thu, 30 Sep 2010 16:00:44 +0800 Message-ID: <1285833646-12006-6-git-send-email-Mingkai.hu@freescale.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1285833646-12006-5-git-send-email-Mingkai.hu@freescale.com> References: <1285833646-12006-1-git-send-email-Mingkai.hu@freescale.com> <1285833646-12006-2-git-send-email-Mingkai.hu@freescale.com> <1285833646-12006-3-git-send-email-Mingkai.hu@freescale.com> <1285833646-12006-4-git-send-email-Mingkai.hu@freescale.com> <1285833646-12006-5-git-send-email-Mingkai.hu@freescale.com> X-OriginalArrivalTime: 30 Sep 2010 08:25:49.0569 (UTC) FILETIME=[168AB710:01CB6079] MIME-Version: 1.0 X-Reverse-DNS: az33egw02.freescale.net X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1P1Eiu-00074Z-Ir Cc: kumar.gala@freescale.com, tie-fei.zang@freescale.com, Mingkai Hu X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 30 Sep 2010 08:43:07 +0000 (UTC) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 6f512b5..47d53c7 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -772,7 +772,7 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi) static int __devinit m25p_probe(struct spi_device *spi) { const struct spi_device_id *id = spi_get_device_id(spi); - struct flash_platform_data *data; + struct flash_platform_data data, *pdata; struct m25p *flash; struct flash_info *info; unsigned i; @@ -782,13 +782,27 @@ static int __devinit m25p_probe(struct spi_device *spi) * a chip ID, try the JEDEC id commands; they'll work for most * newer chips, even if we don't recognize the particular chip. */ - data = spi->dev.platform_data; - if (data && data->type) { + pdata = spi->dev.platform_data; + if (!pdata && spi->dev.of_node) { + int nr_parts; + struct mtd_partition *parts; + struct device_node *np = spi->dev.of_node; + + nr_parts = of_mtd_parse_partitions(&spi->dev, np, &parts); + if (nr_parts) { + pdata = &data; + memset(pdata, 0, sizeof(*pdata)); + pdata->parts = parts; + pdata->nr_parts = nr_parts; + } + } + + if (pdata && pdata->type) { const struct spi_device_id *plat_id; for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) { plat_id = &m25p_ids[i]; - if (strcmp(data->type, plat_id->name)) + if (strcmp(pdata->type, plat_id->name)) continue; break; } @@ -796,7 +810,8 @@ static int __devinit m25p_probe(struct spi_device *spi) if (i < ARRAY_SIZE(m25p_ids) - 1) id = plat_id; else - dev_warn(&spi->dev, "unrecognized id %s\n", data->type); + dev_warn(&spi->dev, "unrecognized id %s\n", + pdata->type); } info = (void *)id->driver_data; @@ -847,8 +862,8 @@ static int __devinit m25p_probe(struct spi_device *spi) write_sr(flash, 0); } - if (data && data->name) - flash->mtd.name = data->name; + if (pdata && pdata->name) + flash->mtd.name = pdata->name; else flash->mtd.name = dev_name(&spi->dev); @@ -919,9 +934,9 @@ static int __devinit m25p_probe(struct spi_device *spi) part_probes, &parts, 0); } - if (nr_parts <= 0 && data && data->parts) { - parts = data->parts; - nr_parts = data->nr_parts; + if (nr_parts <= 0 && pdata && pdata->parts) { + parts = pdata->parts; + nr_parts = pdata->nr_parts; } if (nr_parts > 0) { @@ -937,9 +952,9 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->partitioned = 1; return add_mtd_partitions(&flash->mtd, parts, nr_parts); } - } else if (data && data->nr_parts) + } else if (pdata && pdata->nr_parts) dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", - data->nr_parts, data->name); + pdata->nr_parts, pdata->name); return add_mtd_device(&flash->mtd) == 1 ? -ENODEV : 0; }