From patchwork Thu Aug 25 13:29:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 1096372 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7PDmivr007315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 25 Aug 2011 13:49:05 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.76) (envelope-from ) id 1QwaIW-0001Bp-2U; Thu, 25 Aug 2011 13:48:44 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QwaIU-0001Bc-NA for spi-devel-general@lists.sourceforge.net; Thu, 25 Aug 2011 13:48:42 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of mm-sol.com designates 213.240.235.226 as permitted sender) client-ip=213.240.235.226; envelope-from=svarbanov@mm-sol.com; helo=extserv.mm-sol.com; Received: from ns.mm-sol.com ([213.240.235.226] helo=extserv.mm-sol.com) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1QwaIT-0007qb-7U for spi-devel-general@lists.sourceforge.net; Thu, 25 Aug 2011 13:48:42 +0000 Received: from intsrv.int.mm-sol.com (unknown [172.18.0.2]) by extserv.mm-sol.com (Postfix) with ESMTP id 5B10AC3F6; Thu, 25 Aug 2011 16:29:42 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by intsrv.int.mm-sol.com (Postfix) with ESMTP id 50E20D26020; Thu, 25 Aug 2011 16:29:42 +0300 (EEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from intsrv.int.mm-sol.com ([127.0.0.1]) by localhost (mail.mm-sol.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MIiGtwh9HGmi; Thu, 25 Aug 2011 16:29:32 +0300 (EEST) Received: from localhost (svarbanov.int.mm-sol.com [172.20.4.186]) by intsrv.int.mm-sol.com (Postfix) with ESMTP id B2EAED2601D; Thu, 25 Aug 2011 16:29:32 +0300 (EEST) From: Stanimir Varbanov To: spi-devel-general@lists.sourceforge.net, linux-mtd@lists.infradead.org Subject: [PATCH/RFC 2/2] mtd: m25p80: Call a platform power method in the driver Date: Thu, 25 Aug 2011 16:29:12 +0300 Message-Id: X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: In-Reply-To: References: X-Spam-Score: -2.0 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1QwaIT-0007qb-7U Cc: Stanimir Varbanov , artem.bityutskiy@intel.com, dwmw2@infradead.org 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: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 25 Aug 2011 13:49:06 +0000 (UTC) On some devices the flash chip could be powered off when m25p driver is probed. To avoid erroneous detection the power of the chip must be turn on, add a power function in m25p_probe to switch on the power by platform data. The power will be turned off at the probe end. Also implement a get/put_device callbacks to power on/off the flash chip. Signed-off-by: Stanimir Varbanov --- drivers/mtd/devices/m25p80.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index e6ba034..6ab5896 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -806,6 +806,27 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi) return ERR_PTR(-ENODEV); } +static void m25p_power(struct flash_platform_data *pdata, int on) +{ + if (pdata && pdata->power) + pdata->power(on); +} + +static int m25p_get_device(struct mtd_info *mtd) +{ + struct flash_platform_data *pdata = mtd->dev.parent->platform_data; + + m25p_power(pdata, 1); + + return 0; +} + +static void m25p_put_device(struct mtd_info *mtd) +{ + struct flash_platform_data *pdata = mtd->dev.parent->platform_data; + + m25p_power(pdata, 0); +} /* * board specific setup should have ensured the SPI clock used here @@ -820,6 +841,7 @@ static int __devinit m25p_probe(struct spi_device *spi) struct flash_info *info; unsigned i; struct mtd_part_parser_data ppdata; + int ret; /* Platform data helps sort out which chip type we have, as * well as how this board partitions it. If we don't have @@ -845,12 +867,16 @@ static int __devinit m25p_probe(struct spi_device *spi) info = (void *)id->driver_data; + /* power on device while probing */ + m25p_power(data, 1); + if (info->jedec_id) { const struct spi_device_id *jid; jid = jedec_probe(spi); if (IS_ERR(jid)) { - return PTR_ERR(jid); + ret = PTR_ERR(jid); + goto out; } else if (jid != id) { /* * JEDEC knows better, so overwrite platform ID. We @@ -867,12 +893,15 @@ static int __devinit m25p_probe(struct spi_device *spi) } flash = kzalloc(sizeof *flash, GFP_KERNEL); - if (!flash) - return -ENOMEM; + if (!flash) { + ret = -ENOMEM; + goto out; + } flash->command = kmalloc(MAX_CMD_SIZE + FAST_READ_DUMMY_BYTE, GFP_KERNEL); if (!flash->command) { kfree(flash); - return -ENOMEM; + ret = -ENOMEM; + goto out; } flash->spi = spi; @@ -902,6 +931,8 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.size = info->sector_size * info->n_sectors; flash->mtd.erase = m25p80_erase; flash->mtd.read = m25p80_read; + flash->mtd.get_device = m25p_get_device; + flash->mtd.put_device = m25p_put_device; /* sst flash chips use AAI word program */ if (JEDEC_MFR(info->jedec_id) == CFI_MFR_SST) @@ -956,6 +987,8 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.eraseregions[i].erasesize / 1024, flash->mtd.eraseregions[i].numblocks); +out: + m25p_power(data, 0); /* partitions should match sector boundaries; and it may be good to * use readonly partitions for writeprotected sectors (BP2..BP0).