2006-05-22 01:11:55 +08:00
|
|
|
/*
|
|
|
|
* drivers/mtd/nand/ams-delta.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
|
|
|
|
*
|
|
|
|
* Derived from drivers/mtd/toto.c
|
2010-12-15 04:09:40 +08:00
|
|
|
* Converted to platform driver by Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
|
2010-12-15 22:43:44 +08:00
|
|
|
* Partially stolen from drivers/mtd/nand/plat_nand.c
|
2006-05-22 01:11:55 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Overview:
|
|
|
|
* This is a device driver for the NAND flash device found on the
|
|
|
|
* Amstrad E3 (Delta).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/nand.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
2012-08-31 06:37:24 +08:00
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/platform_data/gpio-omap.h>
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/sizes.h>
|
2012-08-31 06:37:24 +08:00
|
|
|
|
2012-09-20 01:33:43 +08:00
|
|
|
#include <mach/board-ams-delta.h>
|
2006-05-22 01:11:55 +08:00
|
|
|
|
2012-08-31 06:37:24 +08:00
|
|
|
#include <mach/hardware.h>
|
2006-05-22 01:11:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MTD structure for E3 (Delta)
|
|
|
|
*/
|
|
|
|
static struct mtd_info *ams_delta_mtd = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define partitions for flash devices
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct mtd_partition partition_info[] = {
|
|
|
|
{ .name = "Kernel",
|
|
|
|
.offset = 0,
|
|
|
|
.size = 3 * SZ_1M + SZ_512K },
|
|
|
|
{ .name = "u-boot",
|
|
|
|
.offset = 3 * SZ_1M + SZ_512K,
|
|
|
|
.size = SZ_256K },
|
|
|
|
{ .name = "u-boot params",
|
|
|
|
.offset = 3 * SZ_1M + SZ_512K + SZ_256K,
|
|
|
|
.size = SZ_256K },
|
|
|
|
{ .name = "Amstrad LDR",
|
|
|
|
.offset = 4 * SZ_1M,
|
|
|
|
.size = SZ_256K },
|
|
|
|
{ .name = "File system",
|
|
|
|
.offset = 4 * SZ_1M + 1 * SZ_256K,
|
|
|
|
.size = 27 * SZ_1M },
|
|
|
|
{ .name = "PBL reserved",
|
|
|
|
.offset = 32 * SZ_1M - 3 * SZ_256K,
|
|
|
|
.size = 3 * SZ_256K },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte)
|
|
|
|
{
|
2015-12-01 19:03:04 +08:00
|
|
|
struct nand_chip *this = mtd_to_nand(mtd);
|
2015-12-10 16:00:41 +08:00
|
|
|
void __iomem *io_base = (void __iomem *)nand_get_controller_data(this);
|
2006-05-22 01:11:55 +08:00
|
|
|
|
2010-12-15 22:43:44 +08:00
|
|
|
writew(0, io_base + OMAP_MPUIO_IO_CNTL);
|
|
|
|
writew(byte, this->IO_ADDR_W);
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NWE, 0);
|
2006-05-22 01:11:55 +08:00
|
|
|
ndelay(40);
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NWE, 1);
|
2006-05-22 01:11:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u_char ams_delta_read_byte(struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
u_char res;
|
2015-12-01 19:03:04 +08:00
|
|
|
struct nand_chip *this = mtd_to_nand(mtd);
|
2015-12-10 16:00:41 +08:00
|
|
|
void __iomem *io_base = (void __iomem *)nand_get_controller_data(this);
|
2006-05-22 01:11:55 +08:00
|
|
|
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE, 0);
|
2006-05-22 01:11:55 +08:00
|
|
|
ndelay(40);
|
2010-12-15 22:43:44 +08:00
|
|
|
writew(~0, io_base + OMAP_MPUIO_IO_CNTL);
|
|
|
|
res = readw(this->IO_ADDR_R);
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE, 1);
|
2006-05-22 01:11:55 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ams_delta_write_buf(struct mtd_info *mtd, const u_char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<len; i++)
|
|
|
|
ams_delta_write_byte(mtd, buf[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ams_delta_read_buf(struct mtd_info *mtd, u_char *buf, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<len; i++)
|
|
|
|
buf[i] = ams_delta_read_byte(mtd);
|
|
|
|
}
|
|
|
|
|
2006-05-24 05:25:53 +08:00
|
|
|
/*
|
|
|
|
* Command control function
|
|
|
|
*
|
|
|
|
* ctrl:
|
|
|
|
* NAND_NCE: bit 0 -> bit 2
|
|
|
|
* NAND_CLE: bit 1 -> bit 7
|
|
|
|
* NAND_ALE: bit 2 -> bit 6
|
|
|
|
*/
|
|
|
|
static void ams_delta_hwcontrol(struct mtd_info *mtd, int cmd,
|
|
|
|
unsigned int ctrl)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ctrl & NAND_CTRL_CHANGE) {
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NCE,
|
|
|
|
(ctrl & NAND_NCE) == 0);
|
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_CLE,
|
|
|
|
(ctrl & NAND_CLE) != 0);
|
|
|
|
gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_ALE,
|
|
|
|
(ctrl & NAND_ALE) != 0);
|
2006-05-24 05:25:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd != NAND_CMD_NONE)
|
|
|
|
ams_delta_write_byte(mtd, cmd);
|
|
|
|
}
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
static int ams_delta_nand_ready(struct mtd_info *mtd)
|
|
|
|
{
|
2008-10-16 13:03:15 +08:00
|
|
|
return gpio_get_value(AMS_DELTA_GPIO_PIN_NAND_RB);
|
2006-05-22 01:11:55 +08:00
|
|
|
}
|
|
|
|
|
2012-02-11 00:48:43 +08:00
|
|
|
static const struct gpio _mandatory_gpio[] = {
|
2011-12-20 07:08:55 +08:00
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_NCE,
|
|
|
|
.flags = GPIOF_OUT_INIT_HIGH,
|
|
|
|
.label = "nand_nce",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_NRE,
|
|
|
|
.flags = GPIOF_OUT_INIT_HIGH,
|
|
|
|
.label = "nand_nre",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_NWP,
|
|
|
|
.flags = GPIOF_OUT_INIT_HIGH,
|
|
|
|
.label = "nand_nwp",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_NWE,
|
|
|
|
.flags = GPIOF_OUT_INIT_HIGH,
|
|
|
|
.label = "nand_nwe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_ALE,
|
|
|
|
.flags = GPIOF_OUT_INIT_LOW,
|
|
|
|
.label = "nand_ale",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.gpio = AMS_DELTA_GPIO_PIN_NAND_CLE,
|
|
|
|
.flags = GPIOF_OUT_INIT_LOW,
|
|
|
|
.label = "nand_cle",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/*
|
|
|
|
* Main initialization routine
|
|
|
|
*/
|
2012-11-20 02:23:07 +08:00
|
|
|
static int ams_delta_init(struct platform_device *pdev)
|
2006-05-22 01:11:55 +08:00
|
|
|
{
|
|
|
|
struct nand_chip *this;
|
2010-12-15 22:43:44 +08:00
|
|
|
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
void __iomem *io_base;
|
2006-05-22 01:11:55 +08:00
|
|
|
int err = 0;
|
|
|
|
|
2010-12-15 22:43:44 +08:00
|
|
|
if (!res)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/* Allocate memory for MTD device structure and private data */
|
2015-12-10 15:59:49 +08:00
|
|
|
this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
|
|
|
|
if (!this) {
|
2006-05-22 01:11:55 +08:00
|
|
|
printk (KERN_WARNING "Unable to allocate E3 NAND MTD device structure.\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-12-10 15:59:49 +08:00
|
|
|
ams_delta_mtd = nand_to_mtd(this);
|
2006-05-22 01:11:55 +08:00
|
|
|
ams_delta_mtd->owner = THIS_MODULE;
|
|
|
|
|
mtd: ams-delta: fix request_mem_region() failure
A call to request_mem_region() has been introduced in the omap-gpio
driver recently (commit 96751fcbe5438e95514b025e9cee7a6d38038f40,
"gpio/omap: Use devm_ API and add request_mem_region"). This change
prevented the Amstrad Delta NAND driver, which was doing the same in
order to take control over OMAP MPU I/O lines that the NAND device hangs
off, from loading successfully.
The I/O lines and corresponding registers used by the NAND driver are a
subset of those used for the GPIO function. Then, to avoid run time
collisions, all MPUIO GPIO lines should be marked as requested while
initializing the NAND driver, and vice versa, a single MPUIO GPIO line
already requested before the NAND driver initialization is attempted
should prevent the NAND device from being started successfully.
There is another driver, omap-keypad, which also manipulates MPUIO
registers, but has never been calling request_mem_region() on startup,
so it's not affected by the change in the gpio-omap and works correctly.
It uses the depreciated omap_read/write functions for accessing MPUIO
registers. Unlike the NAND driver, these I/O lines and registers are
separate from those used by the GPIO driver. However, both register sets
are non-contiguous and overlapping, so it would be impractical to
request the two sets separately, one from the gpio-omap, the other form
the omap-keypad driver.
In order to solve all these issues correctly, a solution first suggested
by Artem Bityutskiy, then closer specified by Tony Lindgren while they
commented the initial version of this fix, should be implemented. The
gpio-omap driver should export a few functions which would allow the
other two drivers to access MPUIO registers in a safe manner instead of
trying to manage them in parallel to the GPIO driver. However, such a
big change, affecting 3 drivers all together, is not suitable for the rc
cycle, and should be prepared for the merge window. Then, an
alternative solution is proposed as a regression fix.
For the ams-delta NAND driver to initialize correctly in coexistence
with the changed GPIO driver, drop the request_mem_region() call from
the former, especially as this call is going to be removed while the
long-term solution is implemented.
Tested on Amstrad Delta.
Signed-off-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2012-05-08 04:51:37 +08:00
|
|
|
/*
|
|
|
|
* Don't try to request the memory region from here,
|
|
|
|
* it should have been already requested from the
|
|
|
|
* gpio-omap driver and requesting it again would fail.
|
|
|
|
*/
|
2010-12-15 22:43:44 +08:00
|
|
|
|
|
|
|
io_base = ioremap(res->start, resource_size(res));
|
|
|
|
if (io_base == NULL) {
|
|
|
|
dev_err(&pdev->dev, "ioremap failed\n");
|
|
|
|
err = -EIO;
|
mtd: ams-delta: fix request_mem_region() failure
A call to request_mem_region() has been introduced in the omap-gpio
driver recently (commit 96751fcbe5438e95514b025e9cee7a6d38038f40,
"gpio/omap: Use devm_ API and add request_mem_region"). This change
prevented the Amstrad Delta NAND driver, which was doing the same in
order to take control over OMAP MPU I/O lines that the NAND device hangs
off, from loading successfully.
The I/O lines and corresponding registers used by the NAND driver are a
subset of those used for the GPIO function. Then, to avoid run time
collisions, all MPUIO GPIO lines should be marked as requested while
initializing the NAND driver, and vice versa, a single MPUIO GPIO line
already requested before the NAND driver initialization is attempted
should prevent the NAND device from being started successfully.
There is another driver, omap-keypad, which also manipulates MPUIO
registers, but has never been calling request_mem_region() on startup,
so it's not affected by the change in the gpio-omap and works correctly.
It uses the depreciated omap_read/write functions for accessing MPUIO
registers. Unlike the NAND driver, these I/O lines and registers are
separate from those used by the GPIO driver. However, both register sets
are non-contiguous and overlapping, so it would be impractical to
request the two sets separately, one from the gpio-omap, the other form
the omap-keypad driver.
In order to solve all these issues correctly, a solution first suggested
by Artem Bityutskiy, then closer specified by Tony Lindgren while they
commented the initial version of this fix, should be implemented. The
gpio-omap driver should export a few functions which would allow the
other two drivers to access MPUIO registers in a safe manner instead of
trying to manage them in parallel to the GPIO driver. However, such a
big change, affecting 3 drivers all together, is not suitable for the rc
cycle, and should be prepared for the merge window. Then, an
alternative solution is proposed as a regression fix.
For the ams-delta NAND driver to initialize correctly in coexistence
with the changed GPIO driver, drop the request_mem_region() call from
the former, especially as this call is going to be removed while the
long-term solution is implemented.
Tested on Amstrad Delta.
Signed-off-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2012-05-08 04:51:37 +08:00
|
|
|
goto out_free;
|
2010-12-15 22:43:44 +08:00
|
|
|
}
|
|
|
|
|
2015-12-10 16:00:41 +08:00
|
|
|
nand_set_controller_data(this, (void *)io_base);
|
2010-12-15 22:43:44 +08:00
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/* Set address of NAND IO lines */
|
2010-12-15 22:43:44 +08:00
|
|
|
this->IO_ADDR_R = io_base + OMAP_MPUIO_INPUT_LATCH;
|
|
|
|
this->IO_ADDR_W = io_base + OMAP_MPUIO_OUTPUT;
|
2006-05-22 01:11:55 +08:00
|
|
|
this->read_byte = ams_delta_read_byte;
|
|
|
|
this->write_buf = ams_delta_write_buf;
|
|
|
|
this->read_buf = ams_delta_read_buf;
|
2006-05-24 05:25:53 +08:00
|
|
|
this->cmd_ctrl = ams_delta_hwcontrol;
|
2008-10-16 13:03:15 +08:00
|
|
|
if (gpio_request(AMS_DELTA_GPIO_PIN_NAND_RB, "nand_rdy") == 0) {
|
2006-05-22 01:11:55 +08:00
|
|
|
this->dev_ready = ams_delta_nand_ready;
|
|
|
|
} else {
|
|
|
|
this->dev_ready = NULL;
|
|
|
|
printk(KERN_NOTICE "Couldn't request gpio for Delta NAND ready.\n");
|
|
|
|
}
|
|
|
|
/* 25 us command delay time */
|
|
|
|
this->chip_delay = 30;
|
2006-05-23 18:00:46 +08:00
|
|
|
this->ecc.mode = NAND_ECC_SOFT;
|
2016-04-08 18:23:44 +08:00
|
|
|
this->ecc.algo = NAND_ECC_HAMMING;
|
2006-05-22 01:11:55 +08:00
|
|
|
|
2010-12-15 22:43:44 +08:00
|
|
|
platform_set_drvdata(pdev, io_base);
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/* Set chip enabled, but */
|
2011-12-20 07:08:55 +08:00
|
|
|
err = gpio_request_array(_mandatory_gpio, ARRAY_SIZE(_mandatory_gpio));
|
|
|
|
if (err)
|
|
|
|
goto out_gpio;
|
2006-05-22 01:11:55 +08:00
|
|
|
|
2011-03-31 09:57:33 +08:00
|
|
|
/* Scan to find existence of the device */
|
2006-05-22 01:11:55 +08:00
|
|
|
if (nand_scan(ams_delta_mtd, 1)) {
|
|
|
|
err = -ENXIO;
|
|
|
|
goto out_mtd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the partitions */
|
2011-05-23 17:23:40 +08:00
|
|
|
mtd_device_register(ams_delta_mtd, partition_info,
|
|
|
|
ARRAY_SIZE(partition_info));
|
2006-05-22 01:11:55 +08:00
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out_mtd:
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_free_array(_mandatory_gpio, ARRAY_SIZE(_mandatory_gpio));
|
|
|
|
out_gpio:
|
|
|
|
gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB);
|
2010-12-15 22:43:44 +08:00
|
|
|
iounmap(io_base);
|
|
|
|
out_free:
|
2015-12-10 15:59:49 +08:00
|
|
|
kfree(this);
|
2006-05-22 01:11:55 +08:00
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up routine
|
|
|
|
*/
|
2012-11-20 02:26:04 +08:00
|
|
|
static int ams_delta_cleanup(struct platform_device *pdev)
|
2006-05-22 01:11:55 +08:00
|
|
|
{
|
2010-12-15 22:43:44 +08:00
|
|
|
void __iomem *io_base = platform_get_drvdata(pdev);
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/* Release resources, unregister device */
|
|
|
|
nand_release(ams_delta_mtd);
|
|
|
|
|
2011-12-20 07:08:55 +08:00
|
|
|
gpio_free_array(_mandatory_gpio, ARRAY_SIZE(_mandatory_gpio));
|
|
|
|
gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB);
|
2010-12-15 22:43:44 +08:00
|
|
|
iounmap(io_base);
|
|
|
|
|
2006-05-22 01:11:55 +08:00
|
|
|
/* Free the MTD device structure */
|
2015-12-10 15:59:49 +08:00
|
|
|
kfree(mtd_to_nand(ams_delta_mtd));
|
2010-12-15 04:09:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ams_delta_nand_driver = {
|
|
|
|
.probe = ams_delta_init,
|
2012-11-20 02:21:24 +08:00
|
|
|
.remove = ams_delta_cleanup,
|
2010-12-15 04:09:40 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "ams-delta-nand",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-27 20:45:03 +08:00
|
|
|
module_platform_driver(ams_delta_nand_driver);
|
2006-05-22 01:11:55 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
|
|
|
|
MODULE_DESCRIPTION("Glue layer for NAND flash on Amstrad E3 (Delta)");
|