aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2014-11-20 12:14:47 -0500
committerArnd Bergmann <arnd@arndb.de>2014-11-20 12:14:47 -0500
commit594b732110194e1ba1f2dac674b006d5278e99c9 (patch)
treeb127ed49ff86e79d1cd4b132e42ba8abcdb73471
parent0233903e40b9f45220976f684ad2b87e7dbfcfee (diff)
parent6f8782a7a1c826e1c013d6b7d5504af6bcc079e6 (diff)
Merge tag 'omap-for-v3.19/gpmc-timings' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap into next/omap-gpmc
Pull "omap gpmc changes for v3.19" from Tony Lindgren: GPMC (General Purpose Memory Controller) changes for omaps. These changes allow us to drop dependencies to bootloader timings now that the known device tree entries have been fixed. So we can now require proper timings to be configured and get rid of the legacy smsc91x code. Note that this branch has a dependency to the related device tree branch sent in a separate pull request as timings are now required. * tag 'omap-for-v3.19/gpmc-timings' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap: ARM: OMAP2+: Remove unnecesary include in GPMC driver ARM: OMAP2+: Drop legacy code for gpmc-smc91x.c ARM: OMAP2+: Require proper GPMC timings for devices ARM: OMAP2+: Show bootloader GPMC timings to allow configuring the .dts file ARM: OMAP2+: Fix support for multiple devices on a GPMC chip select ARM: OMAP2+: gpmc: Sanity check GPMC fck on probe ARM: OMAP2+: gpmc: Keep Chip Select disabled while configuring it ARM: OMAP2+: gpmc: Always enable A26-A11 for non NAND devices ARM: OMAP2+: gpmc: Error out if timings fail in gpmc_probe_generic_child() ARM: OMAP2+: gpmc: Print error message in set_gpmc_timing_reg() Signed-off-by: Arnd Bergmann <arnd@arndb.de>
-rw-r--r--arch/arm/mach-omap2/Makefile3
-rw-r--r--arch/arm/mach-omap2/board-3430sdp.c28
-rw-r--r--arch/arm/mach-omap2/board-rx51-peripherals.c29
-rw-r--r--arch/arm/mach-omap2/gpmc-smc91x.c186
-rw-r--r--arch/arm/mach-omap2/gpmc-smc91x.h42
-rw-r--r--arch/arm/mach-omap2/gpmc.c295
6 files changed, 237 insertions, 346 deletions
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index d9e94122073e..3e824f8fec48 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -284,9 +284,6 @@ obj-y += $(onenand-m) $(onenand-y)
284nand-$(CONFIG_MTD_NAND_OMAP2) := gpmc-nand.o 284nand-$(CONFIG_MTD_NAND_OMAP2) := gpmc-nand.o
285obj-y += $(nand-m) $(nand-y) 285obj-y += $(nand-m) $(nand-y)
286 286
287smc91x-$(CONFIG_SMC91X) := gpmc-smc91x.o
288obj-y += $(smc91x-m) $(smc91x-y)
289
290smsc911x-$(CONFIG_SMSC911X) := gpmc-smsc911x.o 287smsc911x-$(CONFIG_SMSC911X) := gpmc-smsc911x.o
291obj-y += $(smsc911x-m) $(smsc911x-y) 288obj-y += $(smsc911x-m) $(smsc911x-y)
292ifneq ($(CONFIG_HWSPINLOCK_OMAP),) 289ifneq ($(CONFIG_HWSPINLOCK_OMAP),)
diff --git a/arch/arm/mach-omap2/board-3430sdp.c b/arch/arm/mach-omap2/board-3430sdp.c
index d21a3048d06b..9857882c2f41 100644
--- a/arch/arm/mach-omap2/board-3430sdp.c
+++ b/arch/arm/mach-omap2/board-3430sdp.c
@@ -38,7 +38,6 @@
38#include <video/omap-panel-data.h> 38#include <video/omap-panel-data.h>
39 39
40#include "gpmc.h" 40#include "gpmc.h"
41#include "gpmc-smc91x.h"
42 41
43#include "soc.h" 42#include "soc.h"
44#include "board-flash.h" 43#include "board-flash.h"
@@ -407,32 +406,6 @@ static int __init omap3430_i2c_init(void)
407 return 0; 406 return 0;
408} 407}
409 408
410#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
411
412static struct omap_smc91x_platform_data board_smc91x_data = {
413 .cs = 3,
414 .flags = GPMC_MUX_ADD_DATA | GPMC_TIMINGS_SMC91C96 |
415 IORESOURCE_IRQ_LOWLEVEL,
416};
417
418static void __init board_smc91x_init(void)
419{
420 if (omap_rev() > OMAP3430_REV_ES1_0)
421 board_smc91x_data.gpio_irq = 6;
422 else
423 board_smc91x_data.gpio_irq = 29;
424
425 gpmc_smc91x_init(&board_smc91x_data);
426}
427
428#else
429
430static inline void board_smc91x_init(void)
431{
432}
433
434#endif
435
436static void enable_board_wakeup_source(void) 409static void enable_board_wakeup_source(void)
437{ 410{
438 /* T2 interrupt line (keypad) */ 411 /* T2 interrupt line (keypad) */
@@ -609,7 +582,6 @@ static void __init omap_3430sdp_init(void)
609 omap_sdrc_init(hyb18m512160af6_sdrc_params, NULL); 582 omap_sdrc_init(hyb18m512160af6_sdrc_params, NULL);
610 usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 583 usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb");
611 usb_musb_init(NULL); 584 usb_musb_init(NULL);
612 board_smc91x_init();
613 board_flash_init(sdp_flash_partitions, chip_sel_3430, 0); 585 board_flash_init(sdp_flash_partitions, chip_sel_3430, 0);
614 sdp3430_display_init(); 586 sdp3430_display_init();
615 enable_board_wakeup_source(); 587 enable_board_wakeup_source();
diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
index ddfc8df83c6a..30e7d4ce7b8d 100644
--- a/arch/arm/mach-omap2/board-rx51-peripherals.c
+++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
@@ -32,7 +32,6 @@
32 32
33#include "common.h" 33#include "common.h"
34#include <linux/omap-dma.h> 34#include <linux/omap-dma.h>
35#include "gpmc-smc91x.h"
36 35
37#include "board-rx51.h" 36#include "board-rx51.h"
38 37
@@ -1146,33 +1145,6 @@ static struct omap_onenand_platform_data board_onenand_data[] = {
1146}; 1145};
1147#endif 1146#endif
1148 1147
1149#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
1150
1151static struct omap_smc91x_platform_data board_smc91x_data = {
1152 .cs = 1,
1153 .gpio_irq = 54,
1154 .gpio_pwrdwn = 86,
1155 .gpio_reset = 164,
1156 .flags = GPMC_TIMINGS_SMC91C96 | IORESOURCE_IRQ_HIGHLEVEL,
1157};
1158
1159static void __init board_smc91x_init(void)
1160{
1161 omap_mux_init_gpio(54, OMAP_PIN_INPUT_PULLDOWN);
1162 omap_mux_init_gpio(86, OMAP_PIN_OUTPUT);
1163 omap_mux_init_gpio(164, OMAP_PIN_OUTPUT);
1164
1165 gpmc_smc91x_init(&board_smc91x_data);
1166}
1167
1168#else
1169
1170static inline void board_smc91x_init(void)
1171{
1172}
1173
1174#endif
1175
1176static struct gpio rx51_wl1251_gpios[] __initdata = { 1148static struct gpio rx51_wl1251_gpios[] __initdata = {
1177 { RX51_WL1251_IRQ_GPIO, GPIOF_IN, "wl1251 irq" }, 1149 { RX51_WL1251_IRQ_GPIO, GPIOF_IN, "wl1251 irq" },
1178}; 1150};
@@ -1303,7 +1275,6 @@ void __init rx51_peripherals_init(void)
1303 rx51_i2c_init(); 1275 rx51_i2c_init();
1304 regulator_has_full_constraints(); 1276 regulator_has_full_constraints();
1305 gpmc_onenand_init(board_onenand_data); 1277 gpmc_onenand_init(board_onenand_data);
1306 board_smc91x_init();
1307 rx51_add_gpio_keys(); 1278 rx51_add_gpio_keys();
1308 rx51_init_wl1251(); 1279 rx51_init_wl1251();
1309 rx51_init_tsc2005(); 1280 rx51_init_tsc2005();
diff --git a/arch/arm/mach-omap2/gpmc-smc91x.c b/arch/arm/mach-omap2/gpmc-smc91x.c
deleted file mode 100644
index 61a063595e66..000000000000
--- a/arch/arm/mach-omap2/gpmc-smc91x.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * linux/arch/arm/mach-omap2/gpmc-smc91x.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Contact: Tony Lindgren
6 *
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.
10 */
11
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/gpio.h>
15#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18#include <linux/smc91x.h>
19
20#include "gpmc.h"
21#include "gpmc-smc91x.h"
22
23#include "soc.h"
24
25static struct omap_smc91x_platform_data *gpmc_cfg;
26
27static struct resource gpmc_smc91x_resources[] = {
28 [0] = {
29 .flags = IORESOURCE_MEM,
30 },
31 [1] = {
32 .flags = IORESOURCE_IRQ,
33 },
34};
35
36static struct smc91x_platdata gpmc_smc91x_info = {
37 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT | SMC91X_IO_SHIFT_0,
38 .leda = RPC_LED_100_10,
39 .ledb = RPC_LED_TX_RX,
40};
41
42static struct platform_device gpmc_smc91x_device = {
43 .name = "smc91x",
44 .id = -1,
45 .dev = {
46 .platform_data = &gpmc_smc91x_info,
47 },
48 .num_resources = ARRAY_SIZE(gpmc_smc91x_resources),
49 .resource = gpmc_smc91x_resources,
50};
51
52static struct gpmc_settings smc91x_settings = {
53 .device_width = GPMC_DEVWIDTH_16BIT,
54};
55
56/*
57 * Set the gpmc timings for smc91c96. The timings are taken
58 * from the data sheet available at:
59 * http://www.smsc.com/main/catalog/lan91c96.html
60 * REVISIT: Level shifters can add at least to the access latency.
61 */
62static int smc91c96_gpmc_retime(void)
63{
64 struct gpmc_timings t;
65 struct gpmc_device_timings dev_t;
66 const int t3 = 10; /* Figure 12.2 read and 12.4 write */
67 const int t4_r = 20; /* Figure 12.2 read */
68 const int t4_w = 5; /* Figure 12.4 write */
69 const int t5 = 25; /* Figure 12.2 read */
70 const int t6 = 15; /* Figure 12.2 read */
71 const int t7 = 5; /* Figure 12.4 write */
72 const int t8 = 5; /* Figure 12.4 write */
73 const int t20 = 185; /* Figure 12.2 read and 12.4 write */
74
75 /*
76 * FIXME: Calculate the address and data bus muxed timings.
77 * Note that at least adv_rd_off needs to be changed according
78 * to omap3430 TRM Figure 11-11. Are the sdp boards using the
79 * FPGA in between smc91x and omap as the timings are different
80 * from above?
81 */
82 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
83 return 0;
84
85 memset(&dev_t, 0, sizeof(dev_t));
86
87 dev_t.t_oeasu = t3 * 1000;
88 dev_t.t_oe = t5 * 1000;
89 dev_t.t_cez_r = t4_r * 1000;
90 dev_t.t_oez = t6 * 1000;
91 dev_t.t_rd_cycle = (t20 - t3) * 1000;
92
93 dev_t.t_weasu = t3 * 1000;
94 dev_t.t_wpl = t7 * 1000;
95 dev_t.t_wph = t8 * 1000;
96 dev_t.t_cez_w = t4_w * 1000;
97 dev_t.t_wr_cycle = (t20 - t3) * 1000;
98
99 gpmc_calc_timings(&t, &smc91x_settings, &dev_t);
100
101 return gpmc_cs_set_timings(gpmc_cfg->cs, &t);
102}
103
104/*
105 * Initialize smc91x device connected to the GPMC. Note that we
106 * assume that pin multiplexing is done in the board-*.c file,
107 * or in the bootloader.
108 */
109void __init gpmc_smc91x_init(struct omap_smc91x_platform_data *board_data)
110{
111 unsigned long cs_mem_base;
112 int ret;
113
114 gpmc_cfg = board_data;
115
116 if (gpmc_cfg->flags & GPMC_TIMINGS_SMC91C96)
117 gpmc_cfg->retime = smc91c96_gpmc_retime;
118
119 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
120 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
121 return;
122 }
123
124 gpmc_smc91x_resources[0].start = cs_mem_base + 0x300;
125 gpmc_smc91x_resources[0].end = cs_mem_base + 0x30f;
126 gpmc_smc91x_resources[1].flags |= (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
127
128 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
129 smc91x_settings.mux_add_data = GPMC_MUX_AD;
130 if (gpmc_cfg->flags & GPMC_READ_MON)
131 smc91x_settings.wait_on_read = true;
132 if (gpmc_cfg->flags & GPMC_WRITE_MON)
133 smc91x_settings.wait_on_write = true;
134 if (gpmc_cfg->wait_pin)
135 smc91x_settings.wait_pin = gpmc_cfg->wait_pin;
136 ret = gpmc_cs_program_settings(gpmc_cfg->cs, &smc91x_settings);
137 if (ret < 0)
138 goto free1;
139
140 if (gpmc_cfg->retime) {
141 ret = gpmc_cfg->retime();
142 if (ret != 0)
143 goto free1;
144 }
145
146 if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "SMC91X irq") < 0)
147 goto free1;
148
149 gpmc_smc91x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
150
151 if (gpmc_cfg->gpio_pwrdwn) {
152 ret = gpio_request_one(gpmc_cfg->gpio_pwrdwn,
153 GPIOF_OUT_INIT_LOW, "SMC91X powerdown");
154 if (ret)
155 goto free2;
156 }
157
158 if (gpmc_cfg->gpio_reset) {
159 ret = gpio_request_one(gpmc_cfg->gpio_reset,
160 GPIOF_OUT_INIT_LOW, "SMC91X reset");
161 if (ret)
162 goto free3;
163
164 gpio_set_value(gpmc_cfg->gpio_reset, 1);
165 msleep(100);
166 gpio_set_value(gpmc_cfg->gpio_reset, 0);
167 }
168
169 if (platform_device_register(&gpmc_smc91x_device) < 0) {
170 printk(KERN_ERR "Unable to register smc91x device\n");
171 gpio_free(gpmc_cfg->gpio_reset);
172 goto free3;
173 }
174
175 return;
176
177free3:
178 if (gpmc_cfg->gpio_pwrdwn)
179 gpio_free(gpmc_cfg->gpio_pwrdwn);
180free2:
181 gpio_free(gpmc_cfg->gpio_irq);
182free1:
183 gpmc_cs_free(gpmc_cfg->cs);
184
185 printk(KERN_ERR "Could not initialize smc91x\n");
186}
diff --git a/arch/arm/mach-omap2/gpmc-smc91x.h b/arch/arm/mach-omap2/gpmc-smc91x.h
deleted file mode 100644
index b64fbee4d567..000000000000
--- a/arch/arm/mach-omap2/gpmc-smc91x.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * arch/arm/plat-omap/include/mach/gpmc-smc91x.h
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __ASM_ARCH_OMAP_GPMC_SMC91X_H__
12
13#define GPMC_TIMINGS_SMC91C96 (1 << 4)
14#define GPMC_MUX_ADD_DATA (1 << 5) /* GPMC_CONFIG1_MUXADDDATA */
15#define GPMC_READ_MON (1 << 6) /* GPMC_CONFIG1_WAIT_READ_MON */
16#define GPMC_WRITE_MON (1 << 7) /* GPMC_CONFIG1_WAIT_WRITE_MON */
17
18struct omap_smc91x_platform_data {
19 int cs;
20 int gpio_irq;
21 int gpio_pwrdwn;
22 int gpio_reset;
23 int wait_pin; /* Optional GPMC_CONFIG1_WAITPINSELECT */
24 u32 flags;
25 int (*retime)(void);
26};
27
28#if defined(CONFIG_SMC91X) || \
29 defined(CONFIG_SMC91X_MODULE)
30
31extern void gpmc_smc91x_init(struct omap_smc91x_platform_data *d);
32
33#else
34
35#define board_smc91x_data NULL
36
37static inline void gpmc_smc91x_init(struct omap_smc91x_platform_data *d)
38{
39}
40
41#endif
42#endif
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index 5fa3755261ce..9ea92b6f180d 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -37,7 +37,6 @@
37#include <asm/mach-types.h> 37#include <asm/mach-types.h>
38 38
39#include "soc.h" 39#include "soc.h"
40#include "common.h"
41#include "omap_device.h" 40#include "omap_device.h"
42#include "gpmc.h" 41#include "gpmc.h"
43#include "gpmc-nand.h" 42#include "gpmc-nand.h"
@@ -85,6 +84,8 @@
85#define GPMC_ECC_CTRL_ECCREG8 0x008 84#define GPMC_ECC_CTRL_ECCREG8 0x008
86#define GPMC_ECC_CTRL_ECCREG9 0x009 85#define GPMC_ECC_CTRL_ECCREG9 0x009
87 86
87#define GPMC_CONFIG_LIMITEDADDRESS BIT(1)
88
88#define GPMC_CONFIG2_CSEXTRADELAY BIT(7) 89#define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
89#define GPMC_CONFIG3_ADVEXTRADELAY BIT(7) 90#define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
90#define GPMC_CONFIG4_OEEXTRADELAY BIT(7) 91#define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
@@ -118,6 +119,15 @@
118 */ 119 */
119#define GPMC_NR_IRQ 2 120#define GPMC_NR_IRQ 2
120 121
122struct gpmc_cs_data {
123 const char *name;
124
125#define GPMC_CS_RESERVED (1 << 0)
126 u32 flags;
127
128 struct resource mem;
129};
130
121struct gpmc_client_irq { 131struct gpmc_client_irq {
122 unsigned irq; 132 unsigned irq;
123 u32 bitmask; 133 u32 bitmask;
@@ -155,10 +165,9 @@ static struct irq_chip gpmc_irq_chip;
155static int gpmc_irq_start; 165static int gpmc_irq_start;
156 166
157static struct resource gpmc_mem_root; 167static struct resource gpmc_mem_root;
158static struct resource gpmc_cs_mem[GPMC_CS_NUM]; 168static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM];
159static DEFINE_SPINLOCK(gpmc_mem_lock); 169static DEFINE_SPINLOCK(gpmc_mem_lock);
160/* Define chip-selects as reserved by default until probe completes */ 170/* Define chip-selects as reserved by default until probe completes */
161static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1);
162static unsigned int gpmc_cs_num = GPMC_CS_NUM; 171static unsigned int gpmc_cs_num = GPMC_CS_NUM;
163static unsigned int gpmc_nr_waitpins; 172static unsigned int gpmc_nr_waitpins;
164static struct device *gpmc_dev; 173static struct device *gpmc_dev;
@@ -202,11 +211,6 @@ static unsigned long gpmc_get_fclk_period(void)
202{ 211{
203 unsigned long rate = clk_get_rate(gpmc_l3_clk); 212 unsigned long rate = clk_get_rate(gpmc_l3_clk);
204 213
205 if (rate == 0) {
206 printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
207 return 0;
208 }
209
210 rate /= 1000; 214 rate /= 1000;
211 rate = 1000000000 / rate; /* In picoseconds */ 215 rate = 1000000000 / rate; /* In picoseconds */
212 216
@@ -284,12 +288,130 @@ static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
284} 288}
285 289
286#ifdef DEBUG 290#ifdef DEBUG
287static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, 291static int get_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
288 int time, const char *name) 292 bool raw, bool noval, int shift,
293 const char *name)
294{
295 u32 l;
296 int nr_bits, max_value, mask;
297
298 l = gpmc_cs_read_reg(cs, reg);
299 nr_bits = end_bit - st_bit + 1;
300 max_value = (1 << nr_bits) - 1;
301 mask = max_value << st_bit;
302 l = (l & mask) >> st_bit;
303 if (shift)
304 l = (shift << l);
305 if (noval && (l == 0))
306 return 0;
307 if (!raw) {
308 unsigned int time_ns_min, time_ns, time_ns_max;
309
310 time_ns_min = gpmc_ticks_to_ns(l ? l - 1 : 0);
311 time_ns = gpmc_ticks_to_ns(l);
312 time_ns_max = gpmc_ticks_to_ns(l + 1 > max_value ?
313 max_value : l + 1);
314 pr_info("gpmc,%s = <%u> (%u - %u ns, %i ticks)\n",
315 name, time_ns, time_ns_min, time_ns_max, l);
316 } else {
317 pr_info("gpmc,%s = <%u>\n", name, l);
318 }
319
320 return l;
321}
322
323#define GPMC_PRINT_CONFIG(cs, config) \
324 pr_info("cs%i %s: 0x%08x\n", cs, #config, \
325 gpmc_cs_read_reg(cs, config))
326#define GPMC_GET_RAW(reg, st, end, field) \
327 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 0, 0, field)
328#define GPMC_GET_RAW_BOOL(reg, st, end, field) \
329 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, 0, field)
330#define GPMC_GET_RAW_SHIFT(reg, st, end, shift, field) \
331 get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, (shift), field)
332#define GPMC_GET_TICKS(reg, st, end, field) \
333 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, 0, 0, field)
334
335static void gpmc_show_regs(int cs, const char *desc)
336{
337 pr_info("gpmc cs%i %s:\n", cs, desc);
338 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG1);
339 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG2);
340 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG3);
341 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG4);
342 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG5);
343 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG6);
344}
345
346/*
347 * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available,
348 * see commit c9fb809.
349 */
350static void gpmc_cs_show_timings(int cs, const char *desc)
351{
352 gpmc_show_regs(cs, desc);
353
354 pr_info("gpmc cs%i access configuration:\n", cs);
355 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity");
356 GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data");
357 GPMC_GET_RAW(GPMC_CS_CONFIG1, 12, 13, "device-width");
358 GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin");
359 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write");
360 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read");
361 GPMC_GET_RAW_SHIFT(GPMC_CS_CONFIG1, 23, 24, 4, "burst-length");
362 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write");
363 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write");
364 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read");
365 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read");
366 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap");
367
368 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay");
369
370 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay");
371
372 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay");
373 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay");
374
375 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen");
376 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen");
377
378 pr_info("gpmc cs%i timings configuration:\n", cs);
379 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns");
380 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns");
381 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns");
382
383 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns");
384 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns");
385 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns");
386
387 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns");
388 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns");
389 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns");
390 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns");
391
392 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns");
393 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns");
394 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns");
395
396 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns");
397
398 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns");
399 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns");
400
401 GPMC_GET_TICKS(GPMC_CS_CONFIG1, 18, 19, "wait-monitoring-ns");
402 GPMC_GET_TICKS(GPMC_CS_CONFIG1, 25, 26, "clk-activation-ns");
403
404 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns");
405 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns");
406}
289#else 407#else
290static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, 408static inline void gpmc_cs_show_timings(int cs, const char *desc)
291 int time) 409{
410}
292#endif 411#endif
412
413static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
414 int time, const char *name)
293{ 415{
294 u32 l; 416 u32 l;
295 int ticks, mask, nr_bits; 417 int ticks, mask, nr_bits;
@@ -299,15 +421,15 @@ static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
299 else 421 else
300 ticks = gpmc_ns_to_ticks(time); 422 ticks = gpmc_ns_to_ticks(time);
301 nr_bits = end_bit - st_bit + 1; 423 nr_bits = end_bit - st_bit + 1;
302 if (ticks >= 1 << nr_bits) { 424 mask = (1 << nr_bits) - 1;
303#ifdef DEBUG 425
304 printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n", 426 if (ticks > mask) {
305 cs, name, time, ticks, 1 << nr_bits); 427 pr_err("%s: GPMC error! CS%d: %s: %d ns, %d ticks > %d\n",
306#endif 428 __func__, cs, name, time, ticks, mask);
429
307 return -1; 430 return -1;
308 } 431 }
309 432
310 mask = (1 << nr_bits) - 1;
311 l = gpmc_cs_read_reg(cs, reg); 433 l = gpmc_cs_read_reg(cs, reg);
312#ifdef DEBUG 434#ifdef DEBUG
313 printk(KERN_INFO 435 printk(KERN_INFO
@@ -322,16 +444,10 @@ static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
322 return 0; 444 return 0;
323} 445}
324 446
325#ifdef DEBUG
326#define GPMC_SET_ONE(reg, st, end, field) \ 447#define GPMC_SET_ONE(reg, st, end, field) \
327 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \ 448 if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
328 t->field, #field) < 0) \ 449 t->field, #field) < 0) \
329 return -1 450 return -1
330#else
331#define GPMC_SET_ONE(reg, st, end, field) \
332 if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \
333 return -1
334#endif
335 451
336int gpmc_calc_divider(unsigned int sync_clk) 452int gpmc_calc_divider(unsigned int sync_clk)
337{ 453{
@@ -353,6 +469,7 @@ int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
353 int div; 469 int div;
354 u32 l; 470 u32 l;
355 471
472 gpmc_cs_show_timings(cs, "before gpmc_cs_set_timings");
356 div = gpmc_calc_divider(t->sync_clk); 473 div = gpmc_calc_divider(t->sync_clk);
357 if (div < 0) 474 if (div < 0)
358 return div; 475 return div;
@@ -402,11 +519,12 @@ int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
402 } 519 }
403 520
404 gpmc_cs_bool_timings(cs, &t->bool_timings); 521 gpmc_cs_bool_timings(cs, &t->bool_timings);
522 gpmc_cs_show_timings(cs, "after gpmc_cs_set_timings");
405 523
406 return 0; 524 return 0;
407} 525}
408 526
409static int gpmc_cs_enable_mem(int cs, u32 base, u32 size) 527static int gpmc_cs_set_memconf(int cs, u32 base, u32 size)
410{ 528{
411 u32 l; 529 u32 l;
412 u32 mask; 530 u32 mask;
@@ -430,6 +548,15 @@ static int gpmc_cs_enable_mem(int cs, u32 base, u32 size)
430 return 0; 548 return 0;
431} 549}
432 550
551static void gpmc_cs_enable_mem(int cs)
552{
553 u32 l;
554
555 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
556 l |= GPMC_CONFIG7_CSVALID;
557 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
558}
559
433static void gpmc_cs_disable_mem(int cs) 560static void gpmc_cs_disable_mem(int cs)
434{ 561{
435 u32 l; 562 u32 l;
@@ -460,13 +587,30 @@ static int gpmc_cs_mem_enabled(int cs)
460 587
461static void gpmc_cs_set_reserved(int cs, int reserved) 588static void gpmc_cs_set_reserved(int cs, int reserved)
462{ 589{
463 gpmc_cs_map &= ~(1 << cs); 590 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
464 gpmc_cs_map |= (reserved ? 1 : 0) << cs; 591
592 gpmc->flags |= GPMC_CS_RESERVED;
465} 593}
466 594
467static bool gpmc_cs_reserved(int cs) 595static bool gpmc_cs_reserved(int cs)
468{ 596{
469 return gpmc_cs_map & (1 << cs); 597 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
598
599 return gpmc->flags & GPMC_CS_RESERVED;
600}
601
602static void gpmc_cs_set_name(int cs, const char *name)
603{
604 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
605
606 gpmc->name = name;
607}
608
609const char *gpmc_cs_get_name(int cs)
610{
611 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
612
613 return gpmc->name;
470} 614}
471 615
472static unsigned long gpmc_mem_align(unsigned long size) 616static unsigned long gpmc_mem_align(unsigned long size)
@@ -485,7 +629,8 @@ static unsigned long gpmc_mem_align(unsigned long size)
485 629
486static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size) 630static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
487{ 631{
488 struct resource *res = &gpmc_cs_mem[cs]; 632 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
633 struct resource *res = &gpmc->mem;
489 int r; 634 int r;
490 635
491 size = gpmc_mem_align(size); 636 size = gpmc_mem_align(size);
@@ -500,7 +645,8 @@ static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
500 645
501static int gpmc_cs_delete_mem(int cs) 646static int gpmc_cs_delete_mem(int cs)
502{ 647{
503 struct resource *res = &gpmc_cs_mem[cs]; 648 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
649 struct resource *res = &gpmc->mem;
504 int r; 650 int r;
505 651
506 spin_lock(&gpmc_mem_lock); 652 spin_lock(&gpmc_mem_lock);
@@ -541,23 +687,24 @@ static int gpmc_cs_remap(int cs, u32 base)
541 gpmc_cs_get_memconf(cs, &old_base, &size); 687 gpmc_cs_get_memconf(cs, &old_base, &size);
542 if (base == old_base) 688 if (base == old_base)
543 return 0; 689 return 0;
544 gpmc_cs_disable_mem(cs); 690
545 ret = gpmc_cs_delete_mem(cs); 691 ret = gpmc_cs_delete_mem(cs);
546 if (ret < 0) 692 if (ret < 0)
547 return ret; 693 return ret;
694
548 ret = gpmc_cs_insert_mem(cs, base, size); 695 ret = gpmc_cs_insert_mem(cs, base, size);
549 if (ret < 0) 696 if (ret < 0)
550 return ret; 697 return ret;
551 ret = gpmc_cs_enable_mem(cs, base, size);
552 if (ret < 0)
553 return ret;
554 698
555 return 0; 699 ret = gpmc_cs_set_memconf(cs, base, size);
700
701 return ret;
556} 702}
557 703
558int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) 704int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
559{ 705{
560 struct resource *res = &gpmc_cs_mem[cs]; 706 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
707 struct resource *res = &gpmc->mem;
561 int r = -1; 708 int r = -1;
562 709
563 if (cs > gpmc_cs_num) { 710 if (cs > gpmc_cs_num) {
@@ -581,12 +728,17 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
581 if (r < 0) 728 if (r < 0)
582 goto out; 729 goto out;
583 730
584 r = gpmc_cs_enable_mem(cs, res->start, resource_size(res)); 731 /* Disable CS while changing base address and size mask */
732 gpmc_cs_disable_mem(cs);
733
734 r = gpmc_cs_set_memconf(cs, res->start, resource_size(res));
585 if (r < 0) { 735 if (r < 0) {
586 release_resource(res); 736 release_resource(res);
587 goto out; 737 goto out;
588 } 738 }
589 739
740 /* Enable CS */
741 gpmc_cs_enable_mem(cs);
590 *base = res->start; 742 *base = res->start;
591 gpmc_cs_set_reserved(cs, 1); 743 gpmc_cs_set_reserved(cs, 1);
592out: 744out:
@@ -597,7 +749,8 @@ EXPORT_SYMBOL(gpmc_cs_request);
597 749
598void gpmc_cs_free(int cs) 750void gpmc_cs_free(int cs)
599{ 751{
600 struct resource *res = &gpmc_cs_mem[cs]; 752 struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
753 struct resource *res = &gpmc->mem;
601 754
602 spin_lock(&gpmc_mem_lock); 755 spin_lock(&gpmc_mem_lock);
603 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { 756 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
@@ -1511,7 +1664,9 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
1511 struct gpmc_timings gpmc_t; 1664 struct gpmc_timings gpmc_t;
1512 struct resource res; 1665 struct resource res;
1513 unsigned long base; 1666 unsigned long base;
1667 const char *name;
1514 int ret, cs; 1668 int ret, cs;
1669 u32 val;
1515 1670
1516 if (of_property_read_u32(child, "reg", &cs) < 0) { 1671 if (of_property_read_u32(child, "reg", &cs) < 0) {
1517 dev_err(&pdev->dev, "%s has no 'reg' property\n", 1672 dev_err(&pdev->dev, "%s has no 'reg' property\n",
@@ -1525,28 +1680,41 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
1525 return -ENODEV; 1680 return -ENODEV;
1526 } 1681 }
1527 1682
1683 /*
1684 * Check if we have multiple instances of the same device
1685 * on a single chip select. If so, use the already initialized
1686 * timings.
1687 */
1688 name = gpmc_cs_get_name(cs);
1689 if (name && child->name && of_node_cmp(child->name, name) == 0)
1690 goto no_timings;
1691
1528 ret = gpmc_cs_request(cs, resource_size(&res), &base); 1692 ret = gpmc_cs_request(cs, resource_size(&res), &base);
1529 if (ret < 0) { 1693 if (ret < 0) {
1530 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); 1694 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
1531 return ret; 1695 return ret;
1532 } 1696 }
1697 gpmc_cs_set_name(cs, child->name);
1698
1699 gpmc_read_settings_dt(child, &gpmc_s);
1700 gpmc_read_timings_dt(child, &gpmc_t);
1533 1701
1534 /* 1702 /*
1535 * For some GPMC devices we still need to rely on the bootloader 1703 * For some GPMC devices we still need to rely on the bootloader
1536 * timings because the devices can be connected via FPGA. So far 1704 * timings because the devices can be connected via FPGA.
1537 * the list is smc91x on the omap2 SDP boards, and 8250 on zooms. 1705 * REVISIT: Add timing support from slls644g.pdf.
1538 * REVISIT: Add timing support from slls644g.pdf and from the
1539 * lan91c96 manual.
1540 */ 1706 */
1541 if (of_device_is_compatible(child, "ns16550a") || 1707 if (!gpmc_t.cs_rd_off) {
1542 of_device_is_compatible(child, "smsc,lan91c94") || 1708 WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n",
1543 of_device_is_compatible(child, "smsc,lan91c111")) { 1709 cs);
1544 dev_warn(&pdev->dev, 1710 gpmc_cs_show_timings(cs,
1545 "%s using bootloader timings on CS%d\n", 1711 "please add GPMC bootloader timings to .dts");
1546 child->name, cs);
1547 goto no_timings; 1712 goto no_timings;
1548 } 1713 }
1549 1714
1715 /* CS must be disabled while making changes to gpmc configuration */
1716 gpmc_cs_disable_mem(cs);
1717
1550 /* 1718 /*
1551 * FIXME: gpmc_cs_request() will map the CS to an arbitary 1719 * FIXME: gpmc_cs_request() will map the CS to an arbitary
1552 * location in the gpmc address space. When booting with 1720 * location in the gpmc address space. When booting with
@@ -1562,8 +1730,6 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
1562 goto err; 1730 goto err;
1563 } 1731 }
1564 1732
1565 gpmc_read_settings_dt(child, &gpmc_s);
1566
1567 ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width); 1733 ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width);
1568 if (ret < 0) 1734 if (ret < 0)
1569 goto err; 1735 goto err;
@@ -1572,8 +1738,20 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
1572 if (ret < 0) 1738 if (ret < 0)
1573 goto err; 1739 goto err;
1574 1740
1575 gpmc_read_timings_dt(child, &gpmc_t); 1741 ret = gpmc_cs_set_timings(cs, &gpmc_t);
1576 gpmc_cs_set_timings(cs, &gpmc_t); 1742 if (ret) {
1743 dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n",
1744 child->name);
1745 goto err;
1746 }
1747
1748 /* Clear limited address i.e. enable A26-A11 */
1749 val = gpmc_read_reg(GPMC_CONFIG);
1750 val &= ~GPMC_CONFIG_LIMITEDADDRESS;
1751 gpmc_write_reg(GPMC_CONFIG, val);
1752
1753 /* Enable CS region */
1754 gpmc_cs_enable_mem(cs);
1577 1755
1578no_timings: 1756no_timings:
1579 if (of_platform_device_create(child, NULL, &pdev->dev)) 1757 if (of_platform_device_create(child, NULL, &pdev->dev))
@@ -1670,13 +1848,18 @@ static int gpmc_probe(struct platform_device *pdev)
1670 else 1848 else
1671 gpmc_irq = res->start; 1849 gpmc_irq = res->start;
1672 1850
1673 gpmc_l3_clk = clk_get(&pdev->dev, "fck"); 1851 gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck");
1674 if (IS_ERR(gpmc_l3_clk)) { 1852 if (IS_ERR(gpmc_l3_clk)) {
1675 dev_err(&pdev->dev, "error: clk_get\n"); 1853 dev_err(&pdev->dev, "Failed to get GPMC fck\n");
1676 gpmc_irq = 0; 1854 gpmc_irq = 0;
1677 return PTR_ERR(gpmc_l3_clk); 1855 return PTR_ERR(gpmc_l3_clk);
1678 } 1856 }
1679 1857
1858 if (!clk_get_rate(gpmc_l3_clk)) {
1859 dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n");
1860 return -EINVAL;
1861 }
1862
1680 pm_runtime_enable(&pdev->dev); 1863 pm_runtime_enable(&pdev->dev);
1681 pm_runtime_get_sync(&pdev->dev); 1864 pm_runtime_get_sync(&pdev->dev);
1682 1865
@@ -1708,9 +1891,6 @@ static int gpmc_probe(struct platform_device *pdev)
1708 if (gpmc_setup_irq() < 0) 1891 if (gpmc_setup_irq() < 0)
1709 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n"); 1892 dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
1710 1893
1711 /* Now the GPMC is initialised, unreserve the chip-selects */
1712 gpmc_cs_map = 0;
1713
1714 if (!pdev->dev.of_node) { 1894 if (!pdev->dev.of_node) {
1715 gpmc_cs_num = GPMC_CS_NUM; 1895 gpmc_cs_num = GPMC_CS_NUM;
1716 gpmc_nr_waitpins = GPMC_NR_WAITPINS; 1896 gpmc_nr_waitpins = GPMC_NR_WAITPINS;
@@ -1719,7 +1899,6 @@ static int gpmc_probe(struct platform_device *pdev)
1719 rc = gpmc_probe_dt(pdev); 1899 rc = gpmc_probe_dt(pdev);
1720 if (rc < 0) { 1900 if (rc < 0) {
1721 pm_runtime_put_sync(&pdev->dev); 1901 pm_runtime_put_sync(&pdev->dev);
1722 clk_put(gpmc_l3_clk);
1723 dev_err(gpmc_dev, "failed to probe DT parameters\n"); 1902 dev_err(gpmc_dev, "failed to probe DT parameters\n");
1724 return rc; 1903 return rc;
1725 } 1904 }