Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 1 | /* |
| 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 Mundt | c809821 | 2010-01-19 19:38:36 +0900 | [diff] [blame] | 17 | #include <linux/clk.h> |
Paul Mundt | 5f24071 | 2010-01-20 15:23:54 +0900 | [diff] [blame] | 18 | #include <mach/fpga.h> |
| 19 | #include <mach/irq.h> |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 20 | #include <asm/machvec.h> |
Paul Mundt | 2267c78 | 2010-01-15 12:11:30 +0900 | [diff] [blame] | 21 | #include <asm/heartbeat.h> |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 22 | #include <asm/sizes.h> |
Paul Mundt | b51989b | 2010-01-20 16:53:11 +0900 | [diff] [blame^] | 23 | #include <asm/reboot.h> |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 24 | |
Paul Mundt | 2267c78 | 2010-01-15 12:11:30 +0900 | [diff] [blame] | 25 | static struct resource heartbeat_resource = { |
| 26 | .start = 0x07fff8b0, |
| 27 | .end = 0x07fff8b0 + sizeof(u16) - 1, |
| 28 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT, |
| 29 | }; |
| 30 | |
| 31 | static struct platform_device heartbeat_device = { |
| 32 | .name = "heartbeat", |
| 33 | .id = -1, |
| 34 | .num_resources = 1, |
| 35 | .resource = &heartbeat_resource, |
| 36 | }; |
| 37 | |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 38 | static struct resource smsc911x_resources[] = { |
| 39 | [0] = { |
| 40 | .name = "smsc911x-memory", |
| 41 | .start = 0x07ffff00, |
| 42 | .end = 0x07ffff00 + SZ_256 - 1, |
| 43 | .flags = IORESOURCE_MEM, |
| 44 | }, |
| 45 | [1] = { |
| 46 | .name = "smsc911x-irq", |
| 47 | .start = evt2irq(0x2c0), |
| 48 | .end = evt2irq(0x2c0), |
| 49 | .flags = IORESOURCE_IRQ, |
| 50 | }, |
| 51 | }; |
| 52 | |
| 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, |
| 58 | }; |
| 59 | |
| 60 | static struct platform_device smsc911x_device = { |
| 61 | .name = "smsc911x", |
| 62 | .id = -1, |
| 63 | .num_resources = ARRAY_SIZE(smsc911x_resources), |
| 64 | .resource = smsc911x_resources, |
| 65 | .dev = { |
| 66 | .platform_data = &smsc911x_config, |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | static struct resource smbus_fpga_resource = { |
| 71 | .start = 0x07fff9e0, |
| 72 | .end = 0x07fff9e0 + SZ_32 - 1, |
| 73 | .flags = IORESOURCE_MEM, |
| 74 | }; |
| 75 | |
| 76 | static struct platform_device smbus_fpga_device = { |
| 77 | .name = "i2c-sdk7786", |
| 78 | .id = 0, |
| 79 | .num_resources = 1, |
| 80 | .resource = &smbus_fpga_resource, |
| 81 | }; |
| 82 | |
| 83 | static struct resource smbus_pcie_resource = { |
| 84 | .start = 0x07fffc30, |
| 85 | .end = 0x07fffc30 + SZ_32 - 1, |
| 86 | .flags = IORESOURCE_MEM, |
| 87 | }; |
| 88 | |
| 89 | static struct platform_device smbus_pcie_device = { |
| 90 | .name = "i2c-sdk7786", |
| 91 | .id = 1, |
| 92 | .num_resources = 1, |
| 93 | .resource = &smbus_pcie_resource, |
| 94 | }; |
| 95 | |
| 96 | static struct i2c_board_info __initdata sdk7786_i2c_devices[] = { |
| 97 | { |
| 98 | I2C_BOARD_INFO("max6900", 0x68), |
| 99 | }, |
| 100 | }; |
| 101 | |
| 102 | static struct platform_device *sh7786_devices[] __initdata = { |
Paul Mundt | 2267c78 | 2010-01-15 12:11:30 +0900 | [diff] [blame] | 103 | &heartbeat_device, |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 104 | &smsc911x_device, |
| 105 | &smbus_fpga_device, |
| 106 | &smbus_pcie_device, |
| 107 | }; |
| 108 | |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 109 | static int sdk7786_i2c_setup(void) |
| 110 | { |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 111 | unsigned int tmp; |
| 112 | |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 113 | /* |
| 114 | * Hand over I2C control to the FPGA. |
| 115 | */ |
Paul Mundt | efd590d | 2010-01-20 15:08:36 +0900 | [diff] [blame] | 116 | tmp = fpga_read_reg(SBCR); |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 117 | tmp &= ~SCBR_I2CCEN; |
| 118 | tmp |= SCBR_I2CMEN; |
Paul Mundt | efd590d | 2010-01-20 15:08:36 +0900 | [diff] [blame] | 119 | fpga_write_reg(tmp, SBCR); |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 120 | |
| 121 | return i2c_register_board_info(0, sdk7786_i2c_devices, |
| 122 | ARRAY_SIZE(sdk7786_i2c_devices)); |
| 123 | } |
| 124 | |
| 125 | static int __init sdk7786_devices_setup(void) |
| 126 | { |
| 127 | int ret; |
| 128 | |
| 129 | ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices)); |
| 130 | if (unlikely(ret != 0)) |
| 131 | return ret; |
| 132 | |
| 133 | return sdk7786_i2c_setup(); |
| 134 | } |
| 135 | __initcall(sdk7786_devices_setup); |
| 136 | |
Paul Mundt | 6f832e8 | 2010-01-15 16:31:04 +0900 | [diff] [blame] | 137 | static int sdk7786_mode_pins(void) |
| 138 | { |
Paul Mundt | efd590d | 2010-01-20 15:08:36 +0900 | [diff] [blame] | 139 | return fpga_read_reg(MODSWR); |
Paul Mundt | 6f832e8 | 2010-01-15 16:31:04 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Paul Mundt | c809821 | 2010-01-19 19:38:36 +0900 | [diff] [blame] | 142 | static int sdk7786_clk_init(void) |
| 143 | { |
| 144 | struct clk *clk; |
| 145 | int ret; |
| 146 | |
| 147 | /* |
| 148 | * Only handle the EXTAL case, anyone interfacing a crystal |
| 149 | * resonator will need to provide their own input clock. |
| 150 | */ |
| 151 | if (test_mode_pin(MODE_PIN9)) |
| 152 | return -EINVAL; |
| 153 | |
| 154 | clk = clk_get(NULL, "extal"); |
| 155 | if (!clk || IS_ERR(clk)) |
| 156 | return PTR_ERR(clk); |
| 157 | ret = clk_set_rate(clk, 33333333); |
| 158 | clk_put(clk); |
| 159 | |
| 160 | return ret; |
| 161 | } |
| 162 | |
Paul Mundt | b51989b | 2010-01-20 16:53:11 +0900 | [diff] [blame^] | 163 | static void sdk7786_restart(char *cmd) |
| 164 | { |
| 165 | fpga_write_reg(0xa5a5, SRSTR); |
| 166 | } |
| 167 | |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 168 | /* Initialize the board */ |
| 169 | static void __init sdk7786_setup(char **cmdline_p) |
| 170 | { |
Paul Mundt | efd590d | 2010-01-20 15:08:36 +0900 | [diff] [blame] | 171 | pr_info("Renesas Technology Europe SDK7786 support:\n"); |
| 172 | |
| 173 | sdk7786_fpga_init(); |
| 174 | |
| 175 | pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf); |
Paul Mundt | b51989b | 2010-01-20 16:53:11 +0900 | [diff] [blame^] | 176 | |
| 177 | machine_ops.restart = sdk7786_restart; |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* |
| 181 | * The Machine Vector |
| 182 | */ |
| 183 | static struct sh_machine_vector mv_sdk7786 __initmv = { |
| 184 | .mv_name = "SDK7786", |
| 185 | .mv_setup = sdk7786_setup, |
Paul Mundt | 6f832e8 | 2010-01-15 16:31:04 +0900 | [diff] [blame] | 186 | .mv_mode_pins = sdk7786_mode_pins, |
Paul Mundt | c809821 | 2010-01-19 19:38:36 +0900 | [diff] [blame] | 187 | .mv_clk_init = sdk7786_clk_init, |
Paul Mundt | 5f24071 | 2010-01-20 15:23:54 +0900 | [diff] [blame] | 188 | .mv_init_irq = sdk7786_init_irq, |
Paul Mundt | 02bf6cc | 2010-01-14 20:58:58 +0900 | [diff] [blame] | 189 | }; |