Merge branch 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / arch / arm / mach-omap2 / gpmc-smc91x.c
CommitLineData
1a48e157
TL
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
3ef5d007 20#include "gpmc.h"
60628152 21#include "gpmc-smc91x.h"
1a48e157 22
dbc04161
TL
23#include "soc.h"
24
1a48e157
TL
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 = {
3bc48014
LM
37 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT | SMC91X_IO_SHIFT_0,
38 .leda = RPC_LED_100_10,
39 .ledb = RPC_LED_TX_RX,
1a48e157
TL
40};
41
42static struct platform_device gpmc_smc91x_device = {
43 .name = "smc91x",
44 .id = -1,
1a48e157
TL
45 .dev = {
46 .platform_data = &gpmc_smc91x_info,
47 },
3bc48014
LM
48 .num_resources = ARRAY_SIZE(gpmc_smc91x_resources),
49 .resource = gpmc_smc91x_resources,
1a48e157
TL
50};
51
52/*
53 * Set the gpmc timings for smc91c96. The timings are taken
54 * from the data sheet available at:
55 * http://www.smsc.com/main/catalog/lan91c96.html
56 * REVISIT: Level shifters can add at least to the access latency.
57 */
58static int smc91c96_gpmc_retime(void)
59{
60 struct gpmc_timings t;
ac2d9ae1 61 struct gpmc_device_timings dev_t;
1a48e157
TL
62 const int t3 = 10; /* Figure 12.2 read and 12.4 write */
63 const int t4_r = 20; /* Figure 12.2 read */
64 const int t4_w = 5; /* Figure 12.4 write */
65 const int t5 = 25; /* Figure 12.2 read */
66 const int t6 = 15; /* Figure 12.2 read */
67 const int t7 = 5; /* Figure 12.4 write */
68 const int t8 = 5; /* Figure 12.4 write */
69 const int t20 = 185; /* Figure 12.2 read and 12.4 write */
70 u32 l;
71
1a48e157
TL
72 l = GPMC_CONFIG1_DEVICESIZE_16;
73 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
74 l |= GPMC_CONFIG1_MUXADDDATA;
75 if (gpmc_cfg->flags & GPMC_READ_MON)
76 l |= GPMC_CONFIG1_WAIT_READ_MON;
77 if (gpmc_cfg->flags & GPMC_WRITE_MON)
78 l |= GPMC_CONFIG1_WAIT_WRITE_MON;
79 if (gpmc_cfg->wait_pin)
80 l |= GPMC_CONFIG1_WAIT_PIN_SEL(gpmc_cfg->wait_pin);
81 gpmc_cs_write_reg(gpmc_cfg->cs, GPMC_CS_CONFIG1, l);
82
83 /*
84 * FIXME: Calculate the address and data bus muxed timings.
85 * Note that at least adv_rd_off needs to be changed according
86 * to omap3430 TRM Figure 11-11. Are the sdp boards using the
87 * FPGA in between smc91x and omap as the timings are different
88 * from above?
89 */
90 if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
91 return 0;
92
ac2d9ae1
AM
93 memset(&dev_t, 0, sizeof(dev_t));
94
95 dev_t.t_oeasu = t3 * 1000;
96 dev_t.t_oe = t5 * 1000;
97 dev_t.t_cez_r = t4_r * 1000;
98 dev_t.t_oez = t6 * 1000;
99 dev_t.t_rd_cycle = (t20 - t3) * 1000;
100
101 dev_t.t_weasu = t3 * 1000;
102 dev_t.t_wpl = t7 * 1000;
103 dev_t.t_wph = t8 * 1000;
104 dev_t.t_cez_w = t4_w * 1000;
105 dev_t.t_wr_cycle = (t20 - t3) * 1000;
106
107 gpmc_calc_timings(&t, &dev_t);
108
1a48e157
TL
109 return gpmc_cs_set_timings(gpmc_cfg->cs, &t);
110}
111
112/*
113 * Initialize smc91x device connected to the GPMC. Note that we
114 * assume that pin multiplexing is done in the board-*.c file,
115 * or in the bootloader.
116 */
117void __init gpmc_smc91x_init(struct omap_smc91x_platform_data *board_data)
118{
119 unsigned long cs_mem_base;
120 int ret;
121
122 gpmc_cfg = board_data;
123
124 if (gpmc_cfg->flags & GPMC_TIMINGS_SMC91C96)
125 gpmc_cfg->retime = smc91c96_gpmc_retime;
126
127 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
128 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
129 return;
130 }
131
132 gpmc_smc91x_resources[0].start = cs_mem_base + 0x300;
133 gpmc_smc91x_resources[0].end = cs_mem_base + 0x30f;
134 gpmc_smc91x_resources[1].flags |= (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
135
136 if (gpmc_cfg->retime) {
137 ret = gpmc_cfg->retime();
138 if (ret != 0)
139 goto free1;
140 }
141
bc593f5d 142 if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "SMC91X irq") < 0)
1a48e157
TL
143 goto free1;
144
1a48e157
TL
145 gpmc_smc91x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
146
147 if (gpmc_cfg->gpio_pwrdwn) {
bc593f5d
IG
148 ret = gpio_request_one(gpmc_cfg->gpio_pwrdwn,
149 GPIOF_OUT_INIT_LOW, "SMC91X powerdown");
1a48e157
TL
150 if (ret)
151 goto free2;
1a48e157
TL
152 }
153
154 if (gpmc_cfg->gpio_reset) {
bc593f5d
IG
155 ret = gpio_request_one(gpmc_cfg->gpio_reset,
156 GPIOF_OUT_INIT_LOW, "SMC91X reset");
1a48e157
TL
157 if (ret)
158 goto free3;
159
1a48e157
TL
160 gpio_set_value(gpmc_cfg->gpio_reset, 1);
161 msleep(100);
162 gpio_set_value(gpmc_cfg->gpio_reset, 0);
163 }
164
165 if (platform_device_register(&gpmc_smc91x_device) < 0) {
166 printk(KERN_ERR "Unable to register smc91x device\n");
167 gpio_free(gpmc_cfg->gpio_reset);
168 goto free3;
169 }
170
171 return;
172
173free3:
174 if (gpmc_cfg->gpio_pwrdwn)
175 gpio_free(gpmc_cfg->gpio_pwrdwn);
176free2:
177 gpio_free(gpmc_cfg->gpio_irq);
178free1:
179 gpmc_cs_free(gpmc_cfg->cs);
180
181 printk(KERN_ERR "Could not initialize smc91x\n");
182}
This page took 0.264722 seconds and 5 git commands to generate.