* [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
@ 2009-01-19 11:27 Mike Rapoport
2009-01-19 11:40 ` Ben Dooks
0 siblings, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2009-01-19 11:27 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, Mike Rapoport
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
---
drivers/mtd/nand/Kconfig | 2 +-
drivers/mtd/nand/pxa3xx_nand.c | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 8b12e6e..d3966d0 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
endchoice
config MTD_NAND_PXA3xx
- bool "Support for NAND flash devices on PXA3xx"
+ tristate "Support for NAND flash devices on PXA3xx"
depends on MTD_NAND && PXA3xx
help
This enables the driver for the NAND flash device found on
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index cc55cbc..628ba08 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -123,6 +123,7 @@ struct pxa3xx_nand_info {
struct clk *clk;
void __iomem *mmio_base;
+ struct resource *res;
unsigned int buf_start;
unsigned int buf_count;
@@ -1079,6 +1080,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
this = &info->nand_chip;
mtd->priv = info;
+ mtd->owner = THIS_MODULE;
info->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
@@ -1125,6 +1127,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
goto fail_put_clk;
}
+ info->res = r;
info->mmio_base = ioremap(r->start, r->end - r->start + 1);
if (info->mmio_base == NULL) {
dev_err(&pdev->dev, "ioremap() failed\n");
@@ -1199,6 +1202,13 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
info->data_buff, info->data_buff_phys);
} else
kfree(info->data_buff);
+
+ iounmap(info->mmio_base);
+ release_mem_region(info->res->start, info->res->end - info->res->start + 1);
+
+ clk_disable(info->clk);
+ clk_put(info->clk);
+
kfree(mtd);
return 0;
}
--
1.5.6.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-19 11:27 [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
@ 2009-01-19 11:40 ` Ben Dooks
2009-01-20 3:16 ` Eric Miao
0 siblings, 1 reply; 13+ messages in thread
From: Ben Dooks @ 2009-01-19 11:40 UTC (permalink / raw)
To: Mike Rapoport; +Cc: linux-mtd, eric.miao, linux-arm-kernel
On Mon, Jan 19, 2009 at 01:27:11PM +0200, Mike Rapoport wrote:
>
> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
> ---
> drivers/mtd/nand/Kconfig | 2 +-
> drivers/mtd/nand/pxa3xx_nand.c | 10 ++++++++++
> 2 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 8b12e6e..d3966d0 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
> endchoice
>
> config MTD_NAND_PXA3xx
> - bool "Support for NAND flash devices on PXA3xx"
> + tristate "Support for NAND flash devices on PXA3xx"
> depends on MTD_NAND && PXA3xx
> help
> This enables the driver for the NAND flash device found on
> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
> index cc55cbc..628ba08 100644
> --- a/drivers/mtd/nand/pxa3xx_nand.c
> +++ b/drivers/mtd/nand/pxa3xx_nand.c
> @@ -123,6 +123,7 @@ struct pxa3xx_nand_info {
>
> struct clk *clk;
> void __iomem *mmio_base;
> + struct resource *res;
>
> unsigned int buf_start;
> unsigned int buf_count;
> @@ -1079,6 +1080,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
>
> this = &info->nand_chip;
> mtd->priv = info;
> + mtd->owner = THIS_MODULE;
>
> info->clk = clk_get(&pdev->dev, NULL);
> if (IS_ERR(info->clk)) {
> @@ -1125,6 +1127,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
> goto fail_put_clk;
> }
>
> + info->res = r;
> info->mmio_base = ioremap(r->start, r->end - r->start + 1);
> if (info->mmio_base == NULL) {
> dev_err(&pdev->dev, "ioremap() failed\n");
> @@ -1199,6 +1202,13 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
> info->data_buff, info->data_buff_phys);
> } else
> kfree(info->data_buff);
> +
> + iounmap(info->mmio_base);
> + release_mem_region(info->res->start, info->res->end - info->res->start + 1);
resource_size() is probably better for the second argument.
--
Ben
Q: What's a light-year?
A: One-third less calories than a regular year.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-19 11:40 ` Ben Dooks
@ 2009-01-20 3:16 ` Eric Miao
2009-01-20 7:21 ` Mike Rapoport
2009-01-20 7:33 ` Mike Rapoport
0 siblings, 2 replies; 13+ messages in thread
From: Eric Miao @ 2009-01-20 3:16 UTC (permalink / raw)
To: Ben Dooks; +Cc: linux-mtd, eric.miao, linux-arm-kernel, Mike Rapoport
On Mon, Jan 19, 2009 at 7:40 PM, Ben Dooks <ben-linux@fluff.org> wrote:
> On Mon, Jan 19, 2009 at 01:27:11PM +0200, Mike Rapoport wrote:
>>
>> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
>> ---
>> drivers/mtd/nand/Kconfig | 2 +-
>> drivers/mtd/nand/pxa3xx_nand.c | 10 ++++++++++
>> 2 files changed, 11 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
>> index 8b12e6e..d3966d0 100644
>> --- a/drivers/mtd/nand/Kconfig
>> +++ b/drivers/mtd/nand/Kconfig
>> @@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
>> endchoice
>>
>> config MTD_NAND_PXA3xx
>> - bool "Support for NAND flash devices on PXA3xx"
>> + tristate "Support for NAND flash devices on PXA3xx"
>> depends on MTD_NAND && PXA3xx
>> help
>> This enables the driver for the NAND flash device found on
>> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
>> index cc55cbc..628ba08 100644
>> --- a/drivers/mtd/nand/pxa3xx_nand.c
>> +++ b/drivers/mtd/nand/pxa3xx_nand.c
>> @@ -123,6 +123,7 @@ struct pxa3xx_nand_info {
>>
>> struct clk *clk;
>> void __iomem *mmio_base;
>> + struct resource *res;
>>
>> unsigned int buf_start;
>> unsigned int buf_count;
>> @@ -1079,6 +1080,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
>>
>> this = &info->nand_chip;
>> mtd->priv = info;
>> + mtd->owner = THIS_MODULE;
>>
>> info->clk = clk_get(&pdev->dev, NULL);
>> if (IS_ERR(info->clk)) {
>> @@ -1125,6 +1127,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
>> goto fail_put_clk;
>> }
>>
>> + info->res = r;
>> info->mmio_base = ioremap(r->start, r->end - r->start + 1);
>> if (info->mmio_base == NULL) {
>> dev_err(&pdev->dev, "ioremap() failed\n");
>> @@ -1199,6 +1202,13 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
>> info->data_buff, info->data_buff_phys);
>> } else
>> kfree(info->data_buff);
>> +
>> + iounmap(info->mmio_base);
>> + release_mem_region(info->res->start, info->res->end - info->res->start + 1);
>
> resource_size() is probably better for the second argument.
>
And maybe we don't even need to introduce the 'info->res', which is
always valid by platform_get_resource() again in _remove().
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-20 3:16 ` Eric Miao
@ 2009-01-20 7:21 ` Mike Rapoport
2009-01-20 7:33 ` Mike Rapoport
1 sibling, 0 replies; 13+ messages in thread
From: Mike Rapoport @ 2009-01-20 7:21 UTC (permalink / raw)
To: Eric Miao; +Cc: eric.miao, linux-mtd, linux-arm-kernel, Ben Dooks
Eric Miao wrote:
> On Mon, Jan 19, 2009 at 7:40 PM, Ben Dooks <ben-linux@fluff.org> wrote:
>> On Mon, Jan 19, 2009 at 01:27:11PM +0200, Mike Rapoport wrote:
>>> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
>>> ---
>>> drivers/mtd/nand/Kconfig | 2 +-
>>> drivers/mtd/nand/pxa3xx_nand.c | 10 ++++++++++
>>> 2 files changed, 11 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
>>> index 8b12e6e..d3966d0 100644
>>> --- a/drivers/mtd/nand/Kconfig
>>> +++ b/drivers/mtd/nand/Kconfig
>>> @@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
>>> endchoice
>>>
>>> config MTD_NAND_PXA3xx
>>> - bool "Support for NAND flash devices on PXA3xx"
>>> + tristate "Support for NAND flash devices on PXA3xx"
>>> depends on MTD_NAND && PXA3xx
>>> help
>>> This enables the driver for the NAND flash device found on
>>> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
>>> index cc55cbc..628ba08 100644
>>> --- a/drivers/mtd/nand/pxa3xx_nand.c
>>> +++ b/drivers/mtd/nand/pxa3xx_nand.c
>>> @@ -123,6 +123,7 @@ struct pxa3xx_nand_info {
>>>
>>> struct clk *clk;
>>> void __iomem *mmio_base;
>>> + struct resource *res;
>>>
>>> unsigned int buf_start;
>>> unsigned int buf_count;
>>> @@ -1079,6 +1080,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
>>>
>>> this = &info->nand_chip;
>>> mtd->priv = info;
>>> + mtd->owner = THIS_MODULE;
>>>
>>> info->clk = clk_get(&pdev->dev, NULL);
>>> if (IS_ERR(info->clk)) {
>>> @@ -1125,6 +1127,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
>>> goto fail_put_clk;
>>> }
>>>
>>> + info->res = r;
>>> info->mmio_base = ioremap(r->start, r->end - r->start + 1);
>>> if (info->mmio_base == NULL) {
>>> dev_err(&pdev->dev, "ioremap() failed\n");
>>> @@ -1199,6 +1202,13 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
>>> info->data_buff, info->data_buff_phys);
>>> } else
>>> kfree(info->data_buff);
>>> +
>>> + iounmap(info->mmio_base);
>>> + release_mem_region(info->res->start, info->res->end - info->res->start + 1);
>> resource_size() is probably better for the second argument.
>>
>
> And maybe we don't even need to introduce the 'info->res', which is
> always valid by platform_get_resource() again in _remove().
Ok.
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-20 3:16 ` Eric Miao
2009-01-20 7:21 ` Mike Rapoport
@ 2009-01-20 7:33 ` Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Mike Rapoport
1 sibling, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2009-01-20 7:33 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, ben-linux
This is updated version together with a patch that allows platform to
keep NAND flash controller settings defined by the bootloader.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1'
2009-01-20 7:33 ` Mike Rapoport
@ 2009-01-20 7:33 ` Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Eric Miao
0 siblings, 2 replies; 13+ messages in thread
From: Mike Rapoport @ 2009-01-20 7:33 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, ben-linux, Mike Rapoport
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
---
drivers/mtd/nand/pxa3xx_nand.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index cc55cbc..ffa960b 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1118,14 +1118,14 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
goto fail_put_clk;
}
- r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
+ r = request_mem_region(r->start, resource_size(r), pdev->name);
if (r == NULL) {
dev_err(&pdev->dev, "failed to request memory resource\n");
ret = -EBUSY;
goto fail_put_clk;
}
- info->mmio_base = ioremap(r->start, r->end - r->start + 1);
+ info->mmio_base = ioremap(r->start, resource_size(r));
if (info->mmio_base == NULL) {
dev_err(&pdev->dev, "ioremap() failed\n");
ret = -ENODEV;
@@ -1174,7 +1174,7 @@ fail_free_buf:
fail_free_io:
iounmap(info->mmio_base);
fail_free_res:
- release_mem_region(r->start, r->end - r->start + 1);
+ release_mem_region(r->start, resource_size(r));
fail_put_clk:
clk_disable(info->clk);
clk_put(info->clk);
--
1.5.6.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Mike Rapoport
@ 2009-01-20 7:33 ` Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader Mike Rapoport
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Eric Miao
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Eric Miao
1 sibling, 2 replies; 13+ messages in thread
From: Mike Rapoport @ 2009-01-20 7:33 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, ben-linux, Mike Rapoport
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
---
drivers/mtd/nand/Kconfig | 2 +-
drivers/mtd/nand/pxa3xx_nand.c | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 8b12e6e..d3966d0 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
endchoice
config MTD_NAND_PXA3xx
- bool "Support for NAND flash devices on PXA3xx"
+ tristate "Support for NAND flash devices on PXA3xx"
depends on MTD_NAND && PXA3xx
help
This enables the driver for the NAND flash device found on
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index ffa960b..ead4a7a 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1079,6 +1079,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
this = &info->nand_chip;
mtd->priv = info;
+ mtd->owner = THIS_MODULE;
info->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
@@ -1187,6 +1188,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
{
struct mtd_info *mtd = platform_get_drvdata(pdev);
struct pxa3xx_nand_info *info = mtd->priv;
+ struct resource *r;
platform_set_drvdata(pdev, NULL);
@@ -1199,6 +1201,14 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
info->data_buff, info->data_buff_phys);
} else
kfree(info->data_buff);
+
+ iounmap(info->mmio_base);
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ release_mem_region(r->start, resource_size(r));
+
+ clk_disable(info->clk);
+ clk_put(info->clk);
+
kfree(mtd);
return 0;
}
--
1.5.6.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
@ 2009-01-20 7:33 ` Mike Rapoport
2009-01-22 7:06 ` Mike Rapoport
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Eric Miao
1 sibling, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2009-01-20 7:33 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, ben-linux, Mike Rapoport
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
---
arch/arm/mach-pxa/include/mach/pxa3xx_nand.h | 3 +
drivers/mtd/nand/pxa3xx_nand.c | 103 +++++++++++++++++++++++++-
2 files changed, 105 insertions(+), 1 deletions(-)
diff --git a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
index eb35fca..3478eae 100644
--- a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
+++ b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
@@ -49,6 +49,9 @@ struct pxa3xx_nand_platform_data {
*/
int enable_arbiter;
+ /* allow platform code to keep OBM/bootloader defined NFC config */
+ int keep_config;
+
const struct mtd_partition *parts;
unsigned int nr_parts;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index ead4a7a..2857a6a 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -171,7 +171,13 @@ static int use_dma = 1;
module_param(use_dma, bool, 0444);
MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
-#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
+/*
+ * Default NAND flash controller configuration setup by the
+ * bootloader. This configuration is used only when pdata->keep_config is set
+ */
+static struct pxa3xx_nand_timing default_timing;
+static struct pxa3xx_nand_flash default_flash;
+
static struct pxa3xx_nand_cmdset smallpage_cmdset = {
.read1 = 0x0000,
.read2 = 0x0050,
@@ -198,6 +204,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
.lock_status = 0x007A,
};
+#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
static struct pxa3xx_nand_timing samsung512MbX16_timing = {
.tCH = 10,
.tCS = 0,
@@ -297,9 +304,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
#define NDTR1_tWHR(c) (min((c), 15) << 4)
#define NDTR1_tAR(c) (min((c), 15) << 0)
+#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
+#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
+#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
+#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
+#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
+#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
+
+#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
+#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
+#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
+
/* convert nano-seconds to nand flash controller clock cycles */
#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
+/* convert nand flash controller clock cycles to nano-seconds */
+#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
+
static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
const struct pxa3xx_nand_timing *t)
{
@@ -921,6 +942,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
return 0;
}
+static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
+ struct pxa3xx_nand_timing *t)
+{
+ unsigned long nand_clk = clk_get_rate(info->clk);
+ uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
+ uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
+
+ t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
+ t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
+ t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
+ t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
+ t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
+ t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
+
+ t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
+ t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
+ t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
+}
+
+static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
+{
+ uint32_t ndcr = nand_readl(info, NDCR);
+ struct nand_flash_dev *type = NULL;
+ uint32_t id = -1;
+ int i;
+
+ default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
+ default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
+ default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
+ default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
+
+ if (default_flash.page_size == 2048)
+ default_flash.cmdset = &largepage_cmdset;
+ else
+ default_flash.cmdset = &smallpage_cmdset;
+
+ /* set info fields needed to __readid */
+ info->flash_info = &default_flash;
+ info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
+ info->reg_ndcr = ndcr;
+
+ if (__readid(info, &id))
+ return -ENODEV;
+
+ /* Lookup the flash id */
+ id = (id >> 8) & 0xff; /* device id is byte 2 */
+ for (i = 0; nand_flash_ids[i].name != NULL; i++) {
+ if (id == nand_flash_ids[i].id) {
+ type = &nand_flash_ids[i];
+ break;
+ }
+ }
+
+ if (!type)
+ return -ENODEV;
+
+ /* fill the missing flash information */
+ i = __ffs(default_flash.page_per_block * default_flash.page_size);
+ default_flash.num_blocks = type->chipsize << (20 - i);
+
+ info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
+
+ /* calculate addressing information */
+ info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
+
+ if (default_flash.num_blocks * default_flash.page_per_block > 65536)
+ info->row_addr_cycles = 3;
+ else
+ info->row_addr_cycles = 2;
+
+ pxa3xx_nand_detect_timing(info, &default_timing);
+ default_flash.timing = &default_timing;
+
+ return 0;
+}
+
static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
const struct pxa3xx_nand_platform_data *pdata)
{
@@ -928,6 +1025,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
uint32_t id = -1;
int i;
+ if (pdata->keep_config)
+ if (pxa3xx_nand_detect_config(info) == 0)
+ return 0;
+
for (i = 0; i<pdata->num_flash; ++i) {
f = pdata->flash + i;
--
1.5.6.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1'
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
@ 2009-01-20 9:01 ` Eric Miao
1 sibling, 0 replies; 13+ messages in thread
From: Eric Miao @ 2009-01-20 9:01 UTC (permalink / raw)
To: Mike Rapoport; +Cc: linux-mtd, eric.miao, linux-arm-kernel, ben-linux
On Tue, Jan 20, 2009 at 3:33 PM, Mike Rapoport <mike@compulab.co.il> wrote:
>
> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
OK
> ---
> drivers/mtd/nand/pxa3xx_nand.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
> index cc55cbc..ffa960b 100644
> --- a/drivers/mtd/nand/pxa3xx_nand.c
> +++ b/drivers/mtd/nand/pxa3xx_nand.c
> @@ -1118,14 +1118,14 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
> goto fail_put_clk;
> }
>
> - r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
> + r = request_mem_region(r->start, resource_size(r), pdev->name);
> if (r == NULL) {
> dev_err(&pdev->dev, "failed to request memory resource\n");
> ret = -EBUSY;
> goto fail_put_clk;
> }
>
> - info->mmio_base = ioremap(r->start, r->end - r->start + 1);
> + info->mmio_base = ioremap(r->start, resource_size(r));
> if (info->mmio_base == NULL) {
> dev_err(&pdev->dev, "ioremap() failed\n");
> ret = -ENODEV;
> @@ -1174,7 +1174,7 @@ fail_free_buf:
> fail_free_io:
> iounmap(info->mmio_base);
> fail_free_res:
> - release_mem_region(r->start, r->end - r->start + 1);
> + release_mem_region(r->start, resource_size(r));
> fail_put_clk:
> clk_disable(info->clk);
> clk_put(info->clk);
> --
> 1.5.6.4
>
>
> -------------------------------------------------------------------
> List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
> FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
> Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
>
--
Cheers
- eric
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: allow building as module
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader Mike Rapoport
@ 2009-01-20 9:01 ` Eric Miao
1 sibling, 0 replies; 13+ messages in thread
From: Eric Miao @ 2009-01-20 9:01 UTC (permalink / raw)
To: Mike Rapoport; +Cc: linux-mtd, eric.miao, linux-arm-kernel, ben-linux
On Tue, Jan 20, 2009 at 3:33 PM, Mike Rapoport <mike@compulab.co.il> wrote:
>
> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Looks OK.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader Mike Rapoport
@ 2009-01-22 7:06 ` Mike Rapoport
2009-01-22 8:03 ` Eric Miao
0 siblings, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2009-01-22 7:06 UTC (permalink / raw)
To: eric.miao; +Cc: linux-mtd, linux-arm-kernel, ben-linux
Eric,
Any comments?
Mike Rapoport wrote:
> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
> ---
> arch/arm/mach-pxa/include/mach/pxa3xx_nand.h | 3 +
> drivers/mtd/nand/pxa3xx_nand.c | 103 +++++++++++++++++++++++++-
> 2 files changed, 105 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
> index eb35fca..3478eae 100644
> --- a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
> +++ b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
> @@ -49,6 +49,9 @@ struct pxa3xx_nand_platform_data {
> */
> int enable_arbiter;
>
> + /* allow platform code to keep OBM/bootloader defined NFC config */
> + int keep_config;
> +
> const struct mtd_partition *parts;
> unsigned int nr_parts;
>
> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
> index ead4a7a..2857a6a 100644
> --- a/drivers/mtd/nand/pxa3xx_nand.c
> +++ b/drivers/mtd/nand/pxa3xx_nand.c
> @@ -171,7 +171,13 @@ static int use_dma = 1;
> module_param(use_dma, bool, 0444);
> MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
>
> -#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
> +/*
> + * Default NAND flash controller configuration setup by the
> + * bootloader. This configuration is used only when pdata->keep_config is set
> + */
> +static struct pxa3xx_nand_timing default_timing;
> +static struct pxa3xx_nand_flash default_flash;
> +
> static struct pxa3xx_nand_cmdset smallpage_cmdset = {
> .read1 = 0x0000,
> .read2 = 0x0050,
> @@ -198,6 +204,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
> .lock_status = 0x007A,
> };
>
> +#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
> static struct pxa3xx_nand_timing samsung512MbX16_timing = {
> .tCH = 10,
> .tCS = 0,
> @@ -297,9 +304,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
> #define NDTR1_tWHR(c) (min((c), 15) << 4)
> #define NDTR1_tAR(c) (min((c), 15) << 0)
>
> +#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
> +#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
> +#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
> +#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
> +#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
> +#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
> +
> +#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
> +#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
> +#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
> +
> /* convert nano-seconds to nand flash controller clock cycles */
> #define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
>
> +/* convert nand flash controller clock cycles to nano-seconds */
> +#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
> +
> static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
> const struct pxa3xx_nand_timing *t)
> {
> @@ -921,6 +942,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
> return 0;
> }
>
> +static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
> + struct pxa3xx_nand_timing *t)
> +{
> + unsigned long nand_clk = clk_get_rate(info->clk);
> + uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
> + uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
> +
> + t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
> + t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
> + t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
> + t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
> + t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
> + t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
> +
> + t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
> + t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
> + t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
> +}
> +
> +static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
> +{
> + uint32_t ndcr = nand_readl(info, NDCR);
> + struct nand_flash_dev *type = NULL;
> + uint32_t id = -1;
> + int i;
> +
> + default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
> + default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
> + default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
> + default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
> +
> + if (default_flash.page_size == 2048)
> + default_flash.cmdset = &largepage_cmdset;
> + else
> + default_flash.cmdset = &smallpage_cmdset;
> +
> + /* set info fields needed to __readid */
> + info->flash_info = &default_flash;
> + info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
> + info->reg_ndcr = ndcr;
> +
> + if (__readid(info, &id))
> + return -ENODEV;
> +
> + /* Lookup the flash id */
> + id = (id >> 8) & 0xff; /* device id is byte 2 */
> + for (i = 0; nand_flash_ids[i].name != NULL; i++) {
> + if (id == nand_flash_ids[i].id) {
> + type = &nand_flash_ids[i];
> + break;
> + }
> + }
> +
> + if (!type)
> + return -ENODEV;
> +
> + /* fill the missing flash information */
> + i = __ffs(default_flash.page_per_block * default_flash.page_size);
> + default_flash.num_blocks = type->chipsize << (20 - i);
> +
> + info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
> +
> + /* calculate addressing information */
> + info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
> +
> + if (default_flash.num_blocks * default_flash.page_per_block > 65536)
> + info->row_addr_cycles = 3;
> + else
> + info->row_addr_cycles = 2;
> +
> + pxa3xx_nand_detect_timing(info, &default_timing);
> + default_flash.timing = &default_timing;
> +
> + return 0;
> +}
> +
> static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
> const struct pxa3xx_nand_platform_data *pdata)
> {
> @@ -928,6 +1025,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
> uint32_t id = -1;
> int i;
>
> + if (pdata->keep_config)
> + if (pxa3xx_nand_detect_config(info) == 0)
> + return 0;
> +
> for (i = 0; i<pdata->num_flash; ++i) {
> f = pdata->flash + i;
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader
2009-01-22 7:06 ` Mike Rapoport
@ 2009-01-22 8:03 ` Eric Miao
0 siblings, 0 replies; 13+ messages in thread
From: Eric Miao @ 2009-01-22 8:03 UTC (permalink / raw)
To: Mike Rapoport; +Cc: linux-mtd, eric.miao, linux-arm-kernel, ben-linux
On Thu, Jan 22, 2009 at 3:06 PM, Mike Rapoport <mike@compulab.co.il> wrote:
> Eric,
> Any comments?
Yes, I'm OK with this.
Acked-by: Eric Miao <eric.miao@marvell.com>
>
> Mike Rapoport wrote:
>> Signed-off-by: Mike Rapoport <mike@compulab.co.il>
>> ---
>> arch/arm/mach-pxa/include/mach/pxa3xx_nand.h | 3 +
>> drivers/mtd/nand/pxa3xx_nand.c | 103 +++++++++++++++++++++++++-
>> 2 files changed, 105 insertions(+), 1 deletions(-)
>>
>> diff --git a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
>> index eb35fca..3478eae 100644
>> --- a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
>> +++ b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
>> @@ -49,6 +49,9 @@ struct pxa3xx_nand_platform_data {
>> */
>> int enable_arbiter;
>>
>> + /* allow platform code to keep OBM/bootloader defined NFC config */
>> + int keep_config;
>> +
>> const struct mtd_partition *parts;
>> unsigned int nr_parts;
>>
>> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
>> index ead4a7a..2857a6a 100644
>> --- a/drivers/mtd/nand/pxa3xx_nand.c
>> +++ b/drivers/mtd/nand/pxa3xx_nand.c
>> @@ -171,7 +171,13 @@ static int use_dma = 1;
>> module_param(use_dma, bool, 0444);
>> MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
>>
>> -#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
>> +/*
>> + * Default NAND flash controller configuration setup by the
>> + * bootloader. This configuration is used only when pdata->keep_config is set
>> + */
>> +static struct pxa3xx_nand_timing default_timing;
>> +static struct pxa3xx_nand_flash default_flash;
>> +
>> static struct pxa3xx_nand_cmdset smallpage_cmdset = {
>> .read1 = 0x0000,
>> .read2 = 0x0050,
>> @@ -198,6 +204,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
>> .lock_status = 0x007A,
>> };
>>
>> +#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
>> static struct pxa3xx_nand_timing samsung512MbX16_timing = {
>> .tCH = 10,
>> .tCS = 0,
>> @@ -297,9 +304,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
>> #define NDTR1_tWHR(c) (min((c), 15) << 4)
>> #define NDTR1_tAR(c) (min((c), 15) << 0)
>>
>> +#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
>> +#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
>> +#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
>> +#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
>> +#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
>> +#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
>> +
>> +#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
>> +#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
>> +#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
>> +
>> /* convert nano-seconds to nand flash controller clock cycles */
>> #define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
>>
>> +/* convert nand flash controller clock cycles to nano-seconds */
>> +#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
>> +
>> static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
>> const struct pxa3xx_nand_timing *t)
>> {
>> @@ -921,6 +942,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
>> return 0;
>> }
>>
>> +static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
>> + struct pxa3xx_nand_timing *t)
>> +{
>> + unsigned long nand_clk = clk_get_rate(info->clk);
>> + uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
>> + uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
>> +
>> + t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
>> + t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
>> + t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
>> + t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
>> + t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
>> + t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
>> +
>> + t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
>> + t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
>> + t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
>> +}
>> +
>> +static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
>> +{
>> + uint32_t ndcr = nand_readl(info, NDCR);
>> + struct nand_flash_dev *type = NULL;
>> + uint32_t id = -1;
>> + int i;
>> +
>> + default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
>> + default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
>> + default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
>> + default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
>> +
>> + if (default_flash.page_size == 2048)
>> + default_flash.cmdset = &largepage_cmdset;
>> + else
>> + default_flash.cmdset = &smallpage_cmdset;
>> +
>> + /* set info fields needed to __readid */
>> + info->flash_info = &default_flash;
>> + info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
>> + info->reg_ndcr = ndcr;
>> +
>> + if (__readid(info, &id))
>> + return -ENODEV;
>> +
>> + /* Lookup the flash id */
>> + id = (id >> 8) & 0xff; /* device id is byte 2 */
>> + for (i = 0; nand_flash_ids[i].name != NULL; i++) {
>> + if (id == nand_flash_ids[i].id) {
>> + type = &nand_flash_ids[i];
>> + break;
>> + }
>> + }
>> +
>> + if (!type)
>> + return -ENODEV;
>> +
>> + /* fill the missing flash information */
>> + i = __ffs(default_flash.page_per_block * default_flash.page_size);
>> + default_flash.num_blocks = type->chipsize << (20 - i);
>> +
>> + info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
>> +
>> + /* calculate addressing information */
>> + info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
>> +
>> + if (default_flash.num_blocks * default_flash.page_per_block > 65536)
>> + info->row_addr_cycles = 3;
>> + else
>> + info->row_addr_cycles = 2;
>> +
>> + pxa3xx_nand_detect_timing(info, &default_timing);
>> + default_flash.timing = &default_timing;
>> +
>> + return 0;
>> +}
>> +
>> static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
>> const struct pxa3xx_nand_platform_data *pdata)
>> {
>> @@ -928,6 +1025,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
>> uint32_t id = -1;
>> int i;
>>
>> + if (pdata->keep_config)
>> + if (pxa3xx_nand_detect_config(info) == 0)
>> + return 0;
>> +
>> for (i = 0; i<pdata->num_flash; ++i) {
>> f = pdata->flash + i;
>>
>
> --
> Sincerely yours,
> Mike.
>
>
> -------------------------------------------------------------------
> List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
> FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
> Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
>
--
Cheers
- eric
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader
2009-02-17 11:54 pxa3xx_nand improvements Mike Rapoport
@ 2009-02-17 11:54 ` Mike Rapoport
0 siblings, 0 replies; 13+ messages in thread
From: Mike Rapoport @ 2009-02-17 11:54 UTC (permalink / raw)
To: dwmw2; +Cc: eric.miao, linux-mtd
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Acked-by: Eric Miao <eric.miao@marvell.com>
---
arch/arm/mach-pxa/include/mach/pxa3xx_nand.h | 3 +
drivers/mtd/nand/pxa3xx_nand.c | 103 +++++++++++++++++++++++++-
2 files changed, 105 insertions(+), 1 deletions(-)
diff --git a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
index eb35fca..3478eae 100644
--- a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
+++ b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
@@ -49,6 +49,9 @@ struct pxa3xx_nand_platform_data {
*/
int enable_arbiter;
+ /* allow platform code to keep OBM/bootloader defined NFC config */
+ int keep_config;
+
const struct mtd_partition *parts;
unsigned int nr_parts;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index ead4a7a..2857a6a 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -171,7 +171,13 @@ static int use_dma = 1;
module_param(use_dma, bool, 0444);
MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
-#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
+/*
+ * Default NAND flash controller configuration setup by the
+ * bootloader. This configuration is used only when pdata->keep_config is set
+ */
+static struct pxa3xx_nand_timing default_timing;
+static struct pxa3xx_nand_flash default_flash;
+
static struct pxa3xx_nand_cmdset smallpage_cmdset = {
.read1 = 0x0000,
.read2 = 0x0050,
@@ -198,6 +204,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
.lock_status = 0x007A,
};
+#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
static struct pxa3xx_nand_timing samsung512MbX16_timing = {
.tCH = 10,
.tCS = 0,
@@ -297,9 +304,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
#define NDTR1_tWHR(c) (min((c), 15) << 4)
#define NDTR1_tAR(c) (min((c), 15) << 0)
+#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
+#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
+#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
+#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
+#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
+#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
+
+#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
+#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
+#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
+
/* convert nano-seconds to nand flash controller clock cycles */
#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
+/* convert nand flash controller clock cycles to nano-seconds */
+#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
+
static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
const struct pxa3xx_nand_timing *t)
{
@@ -921,6 +942,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
return 0;
}
+static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
+ struct pxa3xx_nand_timing *t)
+{
+ unsigned long nand_clk = clk_get_rate(info->clk);
+ uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
+ uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
+
+ t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
+ t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
+ t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
+ t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
+ t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
+ t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
+
+ t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
+ t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
+ t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
+}
+
+static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
+{
+ uint32_t ndcr = nand_readl(info, NDCR);
+ struct nand_flash_dev *type = NULL;
+ uint32_t id = -1;
+ int i;
+
+ default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
+ default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
+ default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
+ default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
+
+ if (default_flash.page_size == 2048)
+ default_flash.cmdset = &largepage_cmdset;
+ else
+ default_flash.cmdset = &smallpage_cmdset;
+
+ /* set info fields needed to __readid */
+ info->flash_info = &default_flash;
+ info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
+ info->reg_ndcr = ndcr;
+
+ if (__readid(info, &id))
+ return -ENODEV;
+
+ /* Lookup the flash id */
+ id = (id >> 8) & 0xff; /* device id is byte 2 */
+ for (i = 0; nand_flash_ids[i].name != NULL; i++) {
+ if (id == nand_flash_ids[i].id) {
+ type = &nand_flash_ids[i];
+ break;
+ }
+ }
+
+ if (!type)
+ return -ENODEV;
+
+ /* fill the missing flash information */
+ i = __ffs(default_flash.page_per_block * default_flash.page_size);
+ default_flash.num_blocks = type->chipsize << (20 - i);
+
+ info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
+
+ /* calculate addressing information */
+ info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
+
+ if (default_flash.num_blocks * default_flash.page_per_block > 65536)
+ info->row_addr_cycles = 3;
+ else
+ info->row_addr_cycles = 2;
+
+ pxa3xx_nand_detect_timing(info, &default_timing);
+ default_flash.timing = &default_timing;
+
+ return 0;
+}
+
static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
const struct pxa3xx_nand_platform_data *pdata)
{
@@ -928,6 +1025,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
uint32_t id = -1;
int i;
+ if (pdata->keep_config)
+ if (pxa3xx_nand_detect_config(info) == 0)
+ return 0;
+
for (i = 0; i<pdata->num_flash; ++i) {
f = pdata->flash + i;
--
1.5.6.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-02-17 11:55 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19 11:27 [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
2009-01-19 11:40 ` Ben Dooks
2009-01-20 3:16 ` Eric Miao
2009-01-20 7:21 ` Mike Rapoport
2009-01-20 7:33 ` Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Mike Rapoport
2009-01-20 7:33 ` [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader Mike Rapoport
2009-01-22 7:06 ` Mike Rapoport
2009-01-22 8:03 ` Eric Miao
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: allow building as module Eric Miao
2009-01-20 9:01 ` [PATCH] MTD: NAND: pxa3xx_nand: use resource_size instead of 'r->end - r->start + 1' Eric Miao
-- strict thread matches above, loose matches on Subject: below --
2009-02-17 11:54 pxa3xx_nand improvements Mike Rapoport
2009-02-17 11:54 ` [PATCH] MTD: NAND: pxa3xx_nand: add ability to keep controller settings defined by OBM/bootloader Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox