2 * Renesas Technology Europe SDK7786 Support.
4 * Copyright (C) 2010 Matt Fleming
5 * Copyright (C) 2010 Paul Mundt
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
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
14 #include <linux/smsc911x.h>
15 #include <linux/i2c.h>
16 #include <linux/irq.h>
17 #include <linux/clk.h>
18 #include <mach/fpga.h>
20 #include <asm/machvec.h>
21 #include <asm/heartbeat.h>
22 #include <asm/sizes.h>
23 #include <asm/reboot.h>
25 static struct resource heartbeat_resource = {
27 .end = 0x07fff8b0 + sizeof(u16) - 1,
28 .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,
31 static struct platform_device heartbeat_device = {
35 .resource = &heartbeat_resource,
38 static struct resource smsc911x_resources[] = {
40 .name = "smsc911x-memory",
42 .end = 0x07ffff00 + SZ_256 - 1,
43 .flags = IORESOURCE_MEM,
46 .name = "smsc911x-irq",
47 .start = evt2irq(0x2c0),
48 .end = evt2irq(0x2c0),
49 .flags = IORESOURCE_IRQ,
53 static struct smsc911x_platform_config smsc911x_config = {
54 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
55 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
56 .flags = SMSC911X_USE_32BIT,
57 .phy_interface = PHY_INTERFACE_MODE_MII,
60 static struct platform_device smsc911x_device = {
63 .num_resources = ARRAY_SIZE(smsc911x_resources),
64 .resource = smsc911x_resources,
66 .platform_data = &smsc911x_config,
70 static struct resource smbus_fpga_resource = {
72 .end = 0x07fff9e0 + SZ_32 - 1,
73 .flags = IORESOURCE_MEM,
76 static struct platform_device smbus_fpga_device = {
77 .name = "i2c-sdk7786",
80 .resource = &smbus_fpga_resource,
83 static struct resource smbus_pcie_resource = {
85 .end = 0x07fffc30 + SZ_32 - 1,
86 .flags = IORESOURCE_MEM,
89 static struct platform_device smbus_pcie_device = {
90 .name = "i2c-sdk7786",
93 .resource = &smbus_pcie_resource,
96 static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {
98 I2C_BOARD_INFO("max6900", 0x68),
102 static struct platform_device *sh7786_devices[] __initdata = {
109 static int sdk7786_i2c_setup(void)
114 * Hand over I2C control to the FPGA.
116 tmp = fpga_read_reg(SBCR);
119 fpga_write_reg(tmp, SBCR);
121 return i2c_register_board_info(0, sdk7786_i2c_devices,
122 ARRAY_SIZE(sdk7786_i2c_devices));
125 static int __init sdk7786_devices_setup(void)
129 ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));
130 if (unlikely(ret != 0))
133 return sdk7786_i2c_setup();
135 __initcall(sdk7786_devices_setup);
137 static int sdk7786_mode_pins(void)
139 return fpga_read_reg(MODSWR);
142 static int sdk7786_clk_init(void)
148 * Only handle the EXTAL case, anyone interfacing a crystal
149 * resonator will need to provide their own input clock.
151 if (test_mode_pin(MODE_PIN9))
154 clk = clk_get(NULL, "extal");
155 if (!clk || IS_ERR(clk))
157 ret = clk_set_rate(clk, 33333333);
163 static void sdk7786_restart(char *cmd)
165 fpga_write_reg(0xa5a5, SRSTR);
168 static void sdk7786_power_off(void)
170 fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR);
173 * It can take up to 20us for the R8C to do its job, back off and
174 * wait a bit until we've been shut off. Even though newer FPGA
175 * versions don't set the ACK bit, the latency issue remains.
177 while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0)
181 /* Initialize the board */
182 static void __init sdk7786_setup(char **cmdline_p)
184 pr_info("Renesas Technology Europe SDK7786 support:\n");
188 pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);
190 machine_ops.restart = sdk7786_restart;
191 pm_power_off = sdk7786_power_off;
197 static struct sh_machine_vector mv_sdk7786 __initmv = {
198 .mv_name = "SDK7786",
199 .mv_setup = sdk7786_setup,
200 .mv_mode_pins = sdk7786_mode_pins,
201 .mv_clk_init = sdk7786_clk_init,
202 .mv_init_irq = sdk7786_init_irq,