From patchwork Mon Aug 3 21:02:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rajashekhara, Sudhakar" X-Patchwork-Id: 38871 Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n73BZlTM003972 for ; Mon, 3 Aug 2009 11:35:47 GMT Received: from dlep35.itg.ti.com ([157.170.170.118]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id n73BY1ID015974; Mon, 3 Aug 2009 06:34:06 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep35.itg.ti.com (8.13.7/8.13.7) with ESMTP id n73BY1Zr014355; Mon, 3 Aug 2009 06:34:01 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id DCD7D80627; Mon, 3 Aug 2009 06:34:00 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id CFF1080626 for ; Mon, 3 Aug 2009 06:33:59 -0500 (CDT) Received: from tidmzi-ftp.india.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with SMTP id n73BXvn5013170; Mon, 3 Aug 2009 06:33:58 -0500 (CDT) Received: from symphonyindia.ti.com (symphony-ftp [192.168.247.11]) by tidmzi-ftp.india.ext.ti.com (Postfix) with SMTP id 8CF3A3886B; Mon, 3 Aug 2009 17:01:06 +0530 (IST) Received: from localhost.localdomain ([192.168.247.76]) by symphonyindia.ti.com (8.13.1/8.12.10) with ESMTP id n73BPqxp026477; Mon, 3 Aug 2009 16:55:52 +0530 From: Sudhakar Rajashekhara To: linux-mtd@lists.infradead.org Date: Mon, 3 Aug 2009 17:02:05 -0400 Message-Id: <1249333325-16750-1-git-send-email-sudhakar.raj@ti.com> X-Mailer: git-send-email 1.5.6 Cc: davinci-linux-open-source@linux.davincidsp.com, dwmw2@infradead.org Subject: [PATCH] [MTD] m25p80: memory accessor interface for SPI MTD driver X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.4 Precedence: list List-Id: davinci-linux-open-source.linux.davincidsp.com List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com On TI's da850/omap-l138 EVM, MAC address is stored in SPI flash. This patch implements memory accessor interface for SPI MTD driver which enables the kernel to access flash data. This patch also changes the initialization sequence of the drivers by moving mtd and spi ahead of net in drivers/Makefile thereby enabling da850/omap-l138 ethernet driver to read the MAC address while booting. Signed-off-by: Sudhakar Rajashekhara --- drivers/Makefile | 4 ++-- drivers/mtd/devices/m25p80.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/spi/flash.h | 2 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/Makefile b/drivers/Makefile index bc4205d..2a1d41f 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -42,6 +42,8 @@ obj-y += macintosh/ obj-$(CONFIG_IDE) += ide/ obj-$(CONFIG_SCSI) += scsi/ obj-$(CONFIG_ATA) += ata/ +obj-$(CONFIG_MTD) += mtd/ +obj-$(CONFIG_SPI) += spi/ obj-y += net/ obj-$(CONFIG_ATM) += atm/ obj-$(CONFIG_FUSION) += message/ @@ -50,8 +52,6 @@ obj-y += ieee1394/ obj-$(CONFIG_UIO) += uio/ obj-y += cdrom/ obj-y += auxdisplay/ -obj-$(CONFIG_MTD) += mtd/ -obj-$(CONFIG_SPI) += spi/ obj-$(CONFIG_PCCARD) += pcmcia/ obj-$(CONFIG_DIO) += dio/ obj-$(CONFIG_SBUS) += sbus/ diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index ae5fe91..9b0f409 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,7 @@ struct m25p { struct spi_device *spi; + struct memory_accessor macc; struct mutex lock; struct mtd_info mtd; unsigned partitioned:1; @@ -548,6 +550,38 @@ static struct flash_info __devinitdata m25p_data [] = { { "w25x64", 0xef3017, 0, 64 * 1024, 128, SECT_4K, }, }; +/* + * This lets other kernel code access the flash data. For example, it + * might hold a board's Ethernet address, or board-specific calibration + * data generated on the manufacturing floor. + */ + +static ssize_t m25p_macc_read(struct memory_accessor *macc, char *buf, + off_t offset, size_t count) +{ + struct m25p *info = container_of(macc, struct m25p, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (m25p80_read(&info->mtd, offset, count, &retlen, buf) == 0) + ret = retlen; + + return ret; +} + +static ssize_t m25p_macc_write(struct memory_accessor *macc, const char *buf, + off_t offset, size_t count) +{ + struct m25p *info = container_of(macc, struct m25p, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (m25p80_write(&info->mtd, offset, count, &retlen, buf) == 0) + ret = retlen; + + return ret; +} + static struct flash_info *__devinit jedec_probe(struct spi_device *spi) { int tmp; @@ -669,6 +703,9 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.read = m25p80_read; flash->mtd.write = m25p80_write; + flash->macc.read = m25p_macc_read; + flash->macc.write = m25p_macc_write; + /* prefer "small sector" erase if possible */ if (info->flags & SECT_4K) { flash->erase_opcode = OPCODE_BE_4K; @@ -691,6 +728,9 @@ static int __devinit m25p_probe(struct spi_device *spi) flash->mtd.erasesize, flash->mtd.erasesize / 1024, flash->mtd.numeraseregions); + if (data->setup) + data->setup(&flash->macc, data->context); + if (flash->mtd.numeraseregions) for (i = 0; i < flash->mtd.numeraseregions; i++) DEBUG(MTD_DEBUG_LEVEL2, diff --git a/include/linux/spi/flash.h b/include/linux/spi/flash.h index 3f22932..5e3cbea 100644 --- a/include/linux/spi/flash.h +++ b/include/linux/spi/flash.h @@ -24,6 +24,8 @@ struct flash_platform_data { unsigned int nr_parts; char *type; + void (*setup)(struct memory_accessor *, void *context); + void *context; /* we'll likely add more ... use JEDEC IDs, etc */ };