4 * Copyright (C) 2009 Texas Instruments
5 * Vimal Singh <vimalsingh@ti.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
16 #include <asm/mach/flash.h>
18 #include <plat/nand.h>
19 #include <plat/board.h>
20 #include <plat/gpmc.h>
22 #define WR_RD_PIN_MONITORING 0x00600000
24 static struct omap_nand_platform_data *gpmc_nand_data;
26 static struct resource gpmc_nand_resource = {
27 .flags = IORESOURCE_MEM,
30 static struct platform_device gpmc_nand_device = {
34 .resource = &gpmc_nand_resource,
37 static int omap2_nand_gpmc_retime(void)
39 struct gpmc_timings t;
42 memset(&t, 0, sizeof(t));
43 t.sync_clk = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->sync_clk);
44 t.cs_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_on);
45 t.adv_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->adv_on);
48 t.adv_rd_off = gpmc_round_ns_to_ticks(
49 gpmc_nand_data->gpmc_t->adv_rd_off);
51 t.access = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->access);
52 t.oe_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->oe_off);
53 t.cs_rd_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_rd_off);
54 t.rd_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->rd_cycle);
57 t.adv_wr_off = gpmc_round_ns_to_ticks(
58 gpmc_nand_data->gpmc_t->adv_wr_off);
60 if (cpu_is_omap34xx()) {
61 t.wr_data_mux_bus = gpmc_round_ns_to_ticks(
62 gpmc_nand_data->gpmc_t->wr_data_mux_bus);
63 t.wr_access = gpmc_round_ns_to_ticks(
64 gpmc_nand_data->gpmc_t->wr_access);
66 t.we_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->we_off);
67 t.cs_wr_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_wr_off);
68 t.wr_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->wr_cycle);
71 gpmc_cs_write_reg(gpmc_nand_data->cs, GPMC_CS_CONFIG1,
72 GPMC_CONFIG1_DEVICESIZE(gpmc_nand_data->devsize) |
73 GPMC_CONFIG1_DEVICETYPE_NAND);
75 err = gpmc_cs_set_timings(gpmc_nand_data->cs, &t);
82 static int gpmc_nand_setup(void)
84 struct device *dev = &gpmc_nand_device.dev;
86 /* Set timings in GPMC */
87 if (omap2_nand_gpmc_retime() < 0) {
88 dev_err(dev, "Unable to set gpmc timings\n");
95 int __init gpmc_nand_init(struct omap_nand_platform_data *_nand_data)
99 struct device *dev = &gpmc_nand_device.dev;
101 gpmc_nand_data = _nand_data;
102 gpmc_nand_data->nand_setup = gpmc_nand_setup;
103 gpmc_nand_device.dev.platform_data = gpmc_nand_data;
105 err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
106 &gpmc_nand_data->phys_base);
108 dev_err(dev, "Cannot request GPMC CS\n");
112 err = gpmc_nand_setup();
114 dev_err(dev, "NAND platform setup failed: %d\n", err);
118 /* Enable RD PIN Monitoring Reg */
119 if (gpmc_nand_data->dev_ready) {
120 val = gpmc_cs_read_reg(gpmc_nand_data->cs,
122 val |= WR_RD_PIN_MONITORING;
123 gpmc_cs_write_reg(gpmc_nand_data->cs,
124 GPMC_CS_CONFIG1, val);
127 err = platform_device_register(&gpmc_nand_device);
129 dev_err(dev, "Unable to register NAND device\n");
136 gpmc_cs_free(gpmc_nand_data->cs);