GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / mach-omap2 / gpmc-smc91x.c
blobd20289ba9d2ca95665a649d88b16c67a962d5db8
1 /*
2 * linux/arch/arm/mach-omap2/gpmc-smc91x.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Contact: Tony Lindgren
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>
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>
20 #include <plat/board.h>
21 #include <plat/gpmc.h>
22 #include <plat/gpmc-smc91x.h>
24 static struct omap_smc91x_platform_data *gpmc_cfg;
26 static struct resource gpmc_smc91x_resources[] = {
27 [0] = {
28 .flags = IORESOURCE_MEM,
30 [1] = {
31 .flags = IORESOURCE_IRQ,
35 static struct smc91x_platdata gpmc_smc91x_info = {
36 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT | SMC91X_IO_SHIFT_0,
37 .leda = RPC_LED_100_10,
38 .ledb = RPC_LED_TX_RX,
41 static struct platform_device gpmc_smc91x_device = {
42 .name = "smc91x",
43 .id = -1,
44 .dev = {
45 .platform_data = &gpmc_smc91x_info,
47 .num_resources = ARRAY_SIZE(gpmc_smc91x_resources),
48 .resource = gpmc_smc91x_resources,
52 * Set the gpmc timings for smc91c96. The timings are taken
53 * from the data sheet available at:
54 * http://www.smsc.com/main/catalog/lan91c96.html
55 * REVISIT: Level shifters can add at least to the access latency.
57 static int smc91c96_gpmc_retime(void)
59 struct gpmc_timings t;
60 const int t3 = 10; /* Figure 12.2 read and 12.4 write */
61 const int t4_r = 20; /* Figure 12.2 read */
62 const int t4_w = 5; /* Figure 12.4 write */
63 const int t5 = 25; /* Figure 12.2 read */
64 const int t6 = 15; /* Figure 12.2 read */
65 const int t7 = 5; /* Figure 12.4 write */
66 const int t8 = 5; /* Figure 12.4 write */
67 const int t20 = 185; /* Figure 12.2 read and 12.4 write */
68 u32 l;
70 memset(&t, 0, sizeof(t));
72 /* Read timings */
73 t.cs_on = 0;
74 t.adv_on = t.cs_on;
75 t.oe_on = t.adv_on + t3;
76 t.access = t.oe_on + t5;
77 t.oe_off = t.access;
78 t.adv_rd_off = t.oe_off + max(t4_r, t6);
79 t.cs_rd_off = t.oe_off;
80 t.rd_cycle = t20 - t.oe_on;
82 /* Write timings */
83 t.we_on = t.adv_on + t3;
85 if (cpu_is_omap34xx() && (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)) {
86 t.wr_data_mux_bus = t.we_on;
87 t.we_off = t.wr_data_mux_bus + t7;
88 } else
89 t.we_off = t.we_on + t7;
90 if (cpu_is_omap34xx())
91 t.wr_access = t.we_off;
92 t.adv_wr_off = t.we_off + max(t4_w, t8);
93 t.cs_wr_off = t.we_off + t4_w;
94 t.wr_cycle = t20 - t.we_on;
96 l = GPMC_CONFIG1_DEVICESIZE_16;
97 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
98 l |= GPMC_CONFIG1_MUXADDDATA;
99 if (gpmc_cfg->flags & GPMC_READ_MON)
100 l |= GPMC_CONFIG1_WAIT_READ_MON;
101 if (gpmc_cfg->flags & GPMC_WRITE_MON)
102 l |= GPMC_CONFIG1_WAIT_WRITE_MON;
103 if (gpmc_cfg->wait_pin)
104 l |= GPMC_CONFIG1_WAIT_PIN_SEL(gpmc_cfg->wait_pin);
105 gpmc_cs_write_reg(gpmc_cfg->cs, GPMC_CS_CONFIG1, l);
107 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
108 return 0;
110 return gpmc_cs_set_timings(gpmc_cfg->cs, &t);
114 * Initialize smc91x device connected to the GPMC. Note that we
115 * assume that pin multiplexing is done in the board-*.c file,
116 * or in the bootloader.
118 void __init gpmc_smc91x_init(struct omap_smc91x_platform_data *board_data)
120 unsigned long cs_mem_base;
121 int ret;
123 gpmc_cfg = board_data;
125 if (gpmc_cfg->flags & GPMC_TIMINGS_SMC91C96)
126 gpmc_cfg->retime = smc91c96_gpmc_retime;
128 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
129 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
130 return;
133 gpmc_smc91x_resources[0].start = cs_mem_base + 0x300;
134 gpmc_smc91x_resources[0].end = cs_mem_base + 0x30f;
135 gpmc_smc91x_resources[1].flags |= (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
137 if (gpmc_cfg->retime) {
138 ret = gpmc_cfg->retime();
139 if (ret != 0)
140 goto free1;
143 if (gpio_request(gpmc_cfg->gpio_irq, "SMC91X irq") < 0)
144 goto free1;
146 gpio_direction_input(gpmc_cfg->gpio_irq);
147 gpmc_smc91x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
149 if (gpmc_cfg->gpio_pwrdwn) {
150 ret = gpio_request(gpmc_cfg->gpio_pwrdwn, "SMC91X powerdown");
151 if (ret)
152 goto free2;
153 gpio_direction_output(gpmc_cfg->gpio_pwrdwn, 0);
156 if (gpmc_cfg->gpio_reset) {
157 ret = gpio_request(gpmc_cfg->gpio_reset, "SMC91X reset");
158 if (ret)
159 goto free3;
161 gpio_direction_output(gpmc_cfg->gpio_reset, 0);
162 gpio_set_value(gpmc_cfg->gpio_reset, 1);
163 msleep(100);
164 gpio_set_value(gpmc_cfg->gpio_reset, 0);
167 if (platform_device_register(&gpmc_smc91x_device) < 0) {
168 printk(KERN_ERR "Unable to register smc91x device\n");
169 gpio_free(gpmc_cfg->gpio_reset);
170 goto free3;
173 return;
175 free3:
176 if (gpmc_cfg->gpio_pwrdwn)
177 gpio_free(gpmc_cfg->gpio_pwrdwn);
178 free2:
179 gpio_free(gpmc_cfg->gpio_irq);
180 free1:
181 gpmc_cs_free(gpmc_cfg->cs);
183 printk(KERN_ERR "Could not initialize smc91x\n");