blob: 0e4b1c39742ccb9cf5f40adf2c66a91d2b9285ac [file] [log] [blame]
Paul Mundt02bf6cc2010-01-14 20:58:58 +09001/*
2 * Renesas Technology Europe SDK7786 Support.
3 *
4 * Copyright (C) 2010 Matt Fleming
5 * Copyright (C) 2010 Paul Mundt
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/io.h>
14#include <linux/smsc911x.h>
15#include <linux/i2c.h>
16#include <linux/irq.h>
Paul Mundtc8098212010-01-19 19:38:36 +090017#include <linux/clk.h>
Paul Mundt02bf6cc2010-01-14 20:58:58 +090018#include <asm/machvec.h>
Paul Mundt2267c782010-01-15 12:11:30 +090019#include <asm/heartbeat.h>
Paul Mundt02bf6cc2010-01-14 20:58:58 +090020#include <asm/sizes.h>
21
Paul Mundt2267c782010-01-15 12:11:30 +090022static struct resource heartbeat_resource = {
23 .start = 0x07fff8b0,
24 .end = 0x07fff8b0 + sizeof(u16) - 1,
25 .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,
26};
27
28static struct platform_device heartbeat_device = {
29 .name = "heartbeat",
30 .id = -1,
31 .num_resources = 1,
32 .resource = &heartbeat_resource,
33};
34
Paul Mundt02bf6cc2010-01-14 20:58:58 +090035static struct resource smsc911x_resources[] = {
36 [0] = {
37 .name = "smsc911x-memory",
38 .start = 0x07ffff00,
39 .end = 0x07ffff00 + SZ_256 - 1,
40 .flags = IORESOURCE_MEM,
41 },
42 [1] = {
43 .name = "smsc911x-irq",
44 .start = evt2irq(0x2c0),
45 .end = evt2irq(0x2c0),
46 .flags = IORESOURCE_IRQ,
47 },
48};
49
50static struct smsc911x_platform_config smsc911x_config = {
51 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
52 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
53 .flags = SMSC911X_USE_32BIT,
54 .phy_interface = PHY_INTERFACE_MODE_MII,
55};
56
57static struct platform_device smsc911x_device = {
58 .name = "smsc911x",
59 .id = -1,
60 .num_resources = ARRAY_SIZE(smsc911x_resources),
61 .resource = smsc911x_resources,
62 .dev = {
63 .platform_data = &smsc911x_config,
64 },
65};
66
67static struct resource smbus_fpga_resource = {
68 .start = 0x07fff9e0,
69 .end = 0x07fff9e0 + SZ_32 - 1,
70 .flags = IORESOURCE_MEM,
71};
72
73static struct platform_device smbus_fpga_device = {
74 .name = "i2c-sdk7786",
75 .id = 0,
76 .num_resources = 1,
77 .resource = &smbus_fpga_resource,
78};
79
80static struct resource smbus_pcie_resource = {
81 .start = 0x07fffc30,
82 .end = 0x07fffc30 + SZ_32 - 1,
83 .flags = IORESOURCE_MEM,
84};
85
86static struct platform_device smbus_pcie_device = {
87 .name = "i2c-sdk7786",
88 .id = 1,
89 .num_resources = 1,
90 .resource = &smbus_pcie_resource,
91};
92
93static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {
94 {
95 I2C_BOARD_INFO("max6900", 0x68),
96 },
97};
98
99static struct platform_device *sh7786_devices[] __initdata = {
Paul Mundt2267c782010-01-15 12:11:30 +0900100 &heartbeat_device,
Paul Mundt02bf6cc2010-01-14 20:58:58 +0900101 &smsc911x_device,
102 &smbus_fpga_device,
103 &smbus_pcie_device,
104};
105
106#define SBCR_REGS_BASE 0x07fff990
107
108#define SCBR_I2CMEN (1 << 0) /* FPGA I2C master enable */
109#define SCBR_I2CCEN (1 << 1) /* CPU I2C master enable */
110
111static int sdk7786_i2c_setup(void)
112{
113 void __iomem *sbcr;
114 unsigned int tmp;
115
116 sbcr = ioremap_nocache(SBCR_REGS_BASE, SZ_16);
117
118 /*
119 * Hand over I2C control to the FPGA.
120 */
121 tmp = ioread16(sbcr);
122 tmp &= ~SCBR_I2CCEN;
123 tmp |= SCBR_I2CMEN;
124 iowrite16(tmp, sbcr);
125
126 iounmap(sbcr);
127
128 return i2c_register_board_info(0, sdk7786_i2c_devices,
129 ARRAY_SIZE(sdk7786_i2c_devices));
130}
131
132static int __init sdk7786_devices_setup(void)
133{
134 int ret;
135
136 ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));
137 if (unlikely(ret != 0))
138 return ret;
139
140 return sdk7786_i2c_setup();
141}
142__initcall(sdk7786_devices_setup);
143
144#define FPGA_REGS_BASE 0x07fff800
145#define FPGA_REGS_SIZE 1152
146
147#define INTASR 0x010
148#define INTAMR 0x020
149#define INTBSR 0x090
150#define INTBMR 0x0a0
151#define INTMSR 0x130
152
153#define IASELR1 0x210
154#define IASELR2 0x220
155#define IASELR3 0x230
156#define IASELR4 0x240
157#define IASELR5 0x250
158#define IASELR6 0x260
159#define IASELR7 0x270
160#define IASELR8 0x280
161#define IASELR9 0x290
162#define IASELR10 0x2a0
163#define IASELR11 0x2b0
164#define IASELR12 0x2c0
165#define IASELR13 0x2d0
166#define IASELR14 0x2e0
167#define IASELR15 0x2f0
168
169static void __iomem *fpga_regs;
170
171static u16 fpga_read_reg(unsigned int reg)
172{
173 return __raw_readw(fpga_regs + reg);
174}
175
176static void fpga_write_reg(u16 val, unsigned int reg)
177{
178 __raw_writew(val, fpga_regs + reg);
179}
180
181enum {
182 ATA_IRQ_BIT = 1,
183 SPI_BUSY_BIT = 2,
184 LIRQ5_BIT = 3,
185 LIRQ6_BIT = 4,
186 LIRQ7_BIT = 5,
187 LIRQ8_BIT = 6,
188 KEY_IRQ_BIT = 7,
189 PEN_IRQ_BIT = 8,
190 ETH_IRQ_BIT = 9,
191 RTC_ALARM_BIT = 10,
192 CRYSTAL_FAIL_BIT = 12,
193 ETH_PME_BIT = 14,
194};
195
196static void __init init_sdk7786_IRQ(void)
197{
198 unsigned int tmp;
199
200 fpga_regs = ioremap_nocache(FPGA_REGS_BASE, FPGA_REGS_SIZE);
201 if (!fpga_regs) {
202 printk(KERN_ERR "Couldn't map FPGA registers\n");
203 return;
204 }
205
206 /* Enable priority encoding for all IRLs */
207 fpga_write_reg(fpga_read_reg(INTMSR) | 0x0303, INTMSR);
208
209 /* Clear FPGA interrupt status registers */
210 fpga_write_reg(0x0000, INTASR);
211 fpga_write_reg(0x0000, INTBSR);
212
213 /* Unmask FPGA interrupts */
214 tmp = fpga_read_reg(INTAMR);
215 tmp &= ~(1 << ETH_IRQ_BIT);
216 fpga_write_reg(tmp, INTAMR);
217
218 plat_irq_setup_pins(IRQ_MODE_IRL7654_MASK);
219 plat_irq_setup_pins(IRQ_MODE_IRL3210_MASK);
220}
221
Paul Mundt6f832e82010-01-15 16:31:04 +0900222#define MODSWR_REGS 0x07fff830
223
224static int sdk7786_mode_pins(void)
225{
226 void __iomem *modswr;
227 int pin_states;
228
229 modswr = ioremap_nocache(MODSWR_REGS, SZ_16);
230 if (!modswr)
231 return -ENXIO;
232
233 pin_states = ioread16(modswr);
234 iounmap(modswr);
235
236 return pin_states;
237}
238
Paul Mundtc8098212010-01-19 19:38:36 +0900239static int sdk7786_clk_init(void)
240{
241 struct clk *clk;
242 int ret;
243
244 /*
245 * Only handle the EXTAL case, anyone interfacing a crystal
246 * resonator will need to provide their own input clock.
247 */
248 if (test_mode_pin(MODE_PIN9))
249 return -EINVAL;
250
251 clk = clk_get(NULL, "extal");
252 if (!clk || IS_ERR(clk))
253 return PTR_ERR(clk);
254 ret = clk_set_rate(clk, 33333333);
255 clk_put(clk);
256
257 return ret;
258}
259
Paul Mundt02bf6cc2010-01-14 20:58:58 +0900260/* Initialize the board */
261static void __init sdk7786_setup(char **cmdline_p)
262{
263 printk(KERN_INFO "Renesas Technology Corp. SDK7786 support.\n");
264}
265
266/*
267 * The Machine Vector
268 */
269static struct sh_machine_vector mv_sdk7786 __initmv = {
270 .mv_name = "SDK7786",
271 .mv_setup = sdk7786_setup,
Paul Mundt6f832e82010-01-15 16:31:04 +0900272 .mv_mode_pins = sdk7786_mode_pins,
Paul Mundtc8098212010-01-19 19:38:36 +0900273 .mv_clk_init = sdk7786_clk_init,
Paul Mundt02bf6cc2010-01-14 20:58:58 +0900274 .mv_init_irq = init_sdk7786_IRQ,
275};