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