Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-orion5x/ts78xx-setup.c |
| 3 | * |
| 4 | * Maintainer: Alexander Clouter <alex@digriz.org.uk> |
| 5 | * |
| 6 | * This file is licensed under the terms of the GNU General Public |
| 7 | * License version 2. This program is licensed "as is" without any |
| 8 | * warranty of any kind, whether express or implied. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 13 | #include <linux/sysfs.h> |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 15 | #include <linux/mv643xx_eth.h> |
| 16 | #include <linux/ata_platform.h> |
| 17 | #include <linux/m48t86.h> |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 18 | #include <linux/mtd/nand.h> |
| 19 | #include <linux/mtd/partitions.h> |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
| 21 | #include <asm/mach/arch.h> |
| 22 | #include <asm/mach/map.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/orion5x.h> |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 24 | #include "common.h" |
| 25 | #include "mpp.h" |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 26 | #include "ts78xx-fpga.h" |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 27 | |
| 28 | /***************************************************************************** |
| 29 | * TS-78xx Info |
| 30 | ****************************************************************************/ |
| 31 | |
| 32 | /* |
| 33 | * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE |
| 34 | */ |
| 35 | #define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000 |
| 36 | #define TS78XX_FPGA_REGS_VIRT_BASE 0xff900000 |
| 37 | #define TS78XX_FPGA_REGS_SIZE SZ_1M |
| 38 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 39 | static struct ts78xx_fpga_data ts78xx_fpga = { |
| 40 | .id = 0, |
| 41 | .state = 1, |
| 42 | /* .supports = ... - populated by ts78xx_fpga_supports() */ |
| 43 | }; |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 44 | |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 45 | /***************************************************************************** |
| 46 | * I/O Address Mapping |
| 47 | ****************************************************************************/ |
| 48 | static struct map_desc ts78xx_io_desc[] __initdata = { |
| 49 | { |
| 50 | .virtual = TS78XX_FPGA_REGS_VIRT_BASE, |
| 51 | .pfn = __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE), |
| 52 | .length = TS78XX_FPGA_REGS_SIZE, |
| 53 | .type = MT_DEVICE, |
| 54 | }, |
| 55 | }; |
| 56 | |
| 57 | void __init ts78xx_map_io(void) |
| 58 | { |
| 59 | orion5x_map_io(); |
| 60 | iotable_init(ts78xx_io_desc, ARRAY_SIZE(ts78xx_io_desc)); |
| 61 | } |
| 62 | |
| 63 | /***************************************************************************** |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 64 | * Ethernet |
| 65 | ****************************************************************************/ |
| 66 | static struct mv643xx_eth_platform_data ts78xx_eth_data = { |
Lennert Buytenhek | ac84060 | 2008-08-26 14:06:47 +0200 | [diff] [blame] | 67 | .phy_addr = MV643XX_ETH_PHY_ADDR(0), |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /***************************************************************************** |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 71 | * SATA |
| 72 | ****************************************************************************/ |
| 73 | static struct mv_sata_platform_data ts78xx_sata_data = { |
| 74 | .n_ports = 2, |
| 75 | }; |
| 76 | |
| 77 | /***************************************************************************** |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 78 | * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c |
| 79 | ****************************************************************************/ |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 80 | #define TS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x808) |
| 81 | #define TS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c) |
| 82 | |
| 83 | static unsigned char ts78xx_ts_rtc_readbyte(unsigned long addr) |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 84 | { |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 85 | writeb(addr, TS_RTC_CTRL); |
| 86 | return readb(TS_RTC_DATA); |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 89 | static void ts78xx_ts_rtc_writebyte(unsigned char value, unsigned long addr) |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 90 | { |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 91 | writeb(addr, TS_RTC_CTRL); |
| 92 | writeb(value, TS_RTC_DATA); |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 95 | static struct m48t86_ops ts78xx_ts_rtc_ops = { |
| 96 | .readbyte = ts78xx_ts_rtc_readbyte, |
| 97 | .writebyte = ts78xx_ts_rtc_writebyte, |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 100 | static struct platform_device ts78xx_ts_rtc_device = { |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 101 | .name = "rtc-m48t86", |
| 102 | .id = -1, |
| 103 | .dev = { |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 104 | .platform_data = &ts78xx_ts_rtc_ops, |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 105 | }, |
| 106 | .num_resources = 0, |
| 107 | }; |
| 108 | |
| 109 | /* |
| 110 | * TS uses some of the user storage space on the RTC chip so see if it is |
| 111 | * present; as it's an optional feature at purchase time and not all boards |
| 112 | * will have it present |
| 113 | * |
| 114 | * I've used the method TS use in their rtc7800.c example for the detection |
| 115 | * |
| 116 | * TODO: track down a guinea pig without an RTC to see if we can work out a |
| 117 | * better RTC detection routine |
| 118 | */ |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 119 | static int ts78xx_ts_rtc_load(void) |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 120 | { |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 121 | int rc; |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 122 | unsigned char tmp_rtc0, tmp_rtc1; |
| 123 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 124 | tmp_rtc0 = ts78xx_ts_rtc_readbyte(126); |
| 125 | tmp_rtc1 = ts78xx_ts_rtc_readbyte(127); |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 126 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 127 | ts78xx_ts_rtc_writebyte(0x00, 126); |
| 128 | ts78xx_ts_rtc_writebyte(0x55, 127); |
| 129 | if (ts78xx_ts_rtc_readbyte(127) == 0x55) { |
| 130 | ts78xx_ts_rtc_writebyte(0xaa, 127); |
| 131 | if (ts78xx_ts_rtc_readbyte(127) == 0xaa |
| 132 | && ts78xx_ts_rtc_readbyte(126) == 0x00) { |
| 133 | ts78xx_ts_rtc_writebyte(tmp_rtc0, 126); |
| 134 | ts78xx_ts_rtc_writebyte(tmp_rtc1, 127); |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 135 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 136 | if (ts78xx_fpga.supports.ts_rtc.init == 0) { |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 137 | rc = platform_device_register(&ts78xx_ts_rtc_device); |
| 138 | if (!rc) |
| 139 | ts78xx_fpga.supports.ts_rtc.init = 1; |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 140 | } else |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 141 | rc = platform_device_add(&ts78xx_ts_rtc_device); |
| 142 | |
| 143 | return rc; |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 147 | return -ENODEV; |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 148 | }; |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 149 | |
| 150 | static void ts78xx_ts_rtc_unload(void) |
| 151 | { |
| 152 | platform_device_del(&ts78xx_ts_rtc_device); |
| 153 | } |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 154 | |
| 155 | /***************************************************************************** |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 156 | * NAND Flash |
| 157 | ****************************************************************************/ |
| 158 | #define TS_NAND_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x800) /* VIRT */ |
| 159 | #define TS_NAND_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x804) /* PHYS */ |
| 160 | |
| 161 | /* |
| 162 | * hardware specific access to control-lines |
| 163 | * |
| 164 | * ctrl: |
| 165 | * NAND_NCE: bit 0 -> bit 2 |
| 166 | * NAND_CLE: bit 1 -> bit 1 |
| 167 | * NAND_ALE: bit 2 -> bit 0 |
| 168 | */ |
| 169 | static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, |
| 170 | unsigned int ctrl) |
| 171 | { |
| 172 | struct nand_chip *this = mtd->priv; |
| 173 | |
| 174 | if (ctrl & NAND_CTRL_CHANGE) { |
| 175 | unsigned char bits; |
| 176 | |
| 177 | bits = (ctrl & NAND_NCE) << 2; |
| 178 | bits |= ctrl & NAND_CLE; |
| 179 | bits |= (ctrl & NAND_ALE) >> 2; |
| 180 | |
| 181 | writeb((readb(TS_NAND_CTRL) & ~0x7) | bits, TS_NAND_CTRL); |
| 182 | } |
| 183 | |
| 184 | if (cmd != NAND_CMD_NONE) |
| 185 | writeb(cmd, this->IO_ADDR_W); |
| 186 | } |
| 187 | |
| 188 | static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd) |
| 189 | { |
| 190 | return readb(TS_NAND_CTRL) & 0x20; |
| 191 | } |
| 192 | |
| 193 | const char *ts_nand_part_probes[] = { "cmdlinepart", NULL }; |
| 194 | |
| 195 | static struct mtd_partition ts78xx_ts_nand_parts[] = { |
| 196 | { |
| 197 | .name = "mbr", |
| 198 | .offset = 0, |
| 199 | .size = SZ_128K, |
| 200 | .mask_flags = MTD_WRITEABLE, |
| 201 | }, { |
| 202 | .name = "kernel", |
| 203 | .offset = MTDPART_OFS_APPEND, |
| 204 | .size = SZ_4M, |
| 205 | }, { |
| 206 | .name = "initrd", |
| 207 | .offset = MTDPART_OFS_APPEND, |
| 208 | .size = SZ_4M, |
| 209 | }, { |
| 210 | .name = "rootfs", |
| 211 | .offset = MTDPART_OFS_APPEND, |
| 212 | .size = MTDPART_SIZ_FULL, |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | static struct platform_nand_data ts78xx_ts_nand_data = { |
| 217 | .chip = { |
| 218 | .part_probe_types = ts_nand_part_probes, |
| 219 | .partitions = ts78xx_ts_nand_parts, |
| 220 | .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts), |
| 221 | .chip_delay = 15, |
| 222 | .options = NAND_USE_FLASH_BBT, |
| 223 | }, |
| 224 | .ctrl = { |
| 225 | /* |
| 226 | * The HW ECC offloading functions, used to give about a 9% |
| 227 | * performance increase for 'dd if=/dev/mtdblockX' and 5% for |
| 228 | * nanddump. This all however was changed by git commit |
| 229 | * e6cf5df1838c28bb060ac45b5585e48e71bbc740 so now there is |
| 230 | * no performance advantage to be had so we no longer bother |
| 231 | */ |
| 232 | .cmd_ctrl = ts78xx_ts_nand_cmd_ctrl, |
| 233 | .dev_ready = ts78xx_ts_nand_dev_ready, |
| 234 | }, |
| 235 | }; |
| 236 | |
| 237 | static struct resource ts78xx_ts_nand_resources = { |
| 238 | .start = TS_NAND_DATA, |
| 239 | .end = TS_NAND_DATA + 4, |
| 240 | .flags = IORESOURCE_IO, |
| 241 | }; |
| 242 | |
| 243 | static struct platform_device ts78xx_ts_nand_device = { |
| 244 | .name = "gen_nand", |
| 245 | .id = -1, |
| 246 | .dev = { |
| 247 | .platform_data = &ts78xx_ts_nand_data, |
| 248 | }, |
| 249 | .resource = &ts78xx_ts_nand_resources, |
| 250 | .num_resources = 1, |
| 251 | }; |
| 252 | |
| 253 | static int ts78xx_ts_nand_load(void) |
| 254 | { |
| 255 | int rc; |
| 256 | |
| 257 | if (ts78xx_fpga.supports.ts_nand.init == 0) { |
| 258 | rc = platform_device_register(&ts78xx_ts_nand_device); |
| 259 | if (!rc) |
| 260 | ts78xx_fpga.supports.ts_nand.init = 1; |
| 261 | } else |
| 262 | rc = platform_device_add(&ts78xx_ts_nand_device); |
| 263 | |
| 264 | return rc; |
| 265 | }; |
| 266 | |
| 267 | static void ts78xx_ts_nand_unload(void) |
| 268 | { |
| 269 | platform_device_del(&ts78xx_ts_nand_device); |
| 270 | } |
| 271 | |
| 272 | /***************************************************************************** |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 273 | * FPGA 'hotplug' support code |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 274 | ****************************************************************************/ |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 275 | static void ts78xx_fpga_devices_zero_init(void) |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 276 | { |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 277 | ts78xx_fpga.supports.ts_rtc.init = 0; |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 278 | ts78xx_fpga.supports.ts_nand.init = 0; |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 279 | } |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 280 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 281 | static void ts78xx_fpga_supports(void) |
| 282 | { |
| 283 | /* TODO: put this 'table' into ts78xx-fpga.h */ |
| 284 | switch (ts78xx_fpga.id) { |
| 285 | case TS7800_REV_B: |
| 286 | ts78xx_fpga.supports.ts_rtc.present = 1; |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 287 | ts78xx_fpga.supports.ts_nand.present = 1; |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 288 | break; |
| 289 | default: |
| 290 | ts78xx_fpga.supports.ts_rtc.present = 0; |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 291 | ts78xx_fpga.supports.ts_nand.present = 0; |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | static int ts78xx_fpga_load_devices(void) |
| 296 | { |
| 297 | int tmp, ret = 0; |
| 298 | |
| 299 | if (ts78xx_fpga.supports.ts_rtc.present == 1) { |
| 300 | tmp = ts78xx_ts_rtc_load(); |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 301 | if (tmp) { |
Alexander Clouter | 673492a | 2009-02-23 22:38:50 +0000 | [diff] [blame] | 302 | printk(KERN_INFO "TS-78xx: RTC not registered\n"); |
Alexander Clouter | f5273fa | 2009-02-23 22:37:36 +0000 | [diff] [blame] | 303 | ts78xx_fpga.supports.ts_rtc.present = 0; |
| 304 | } |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 305 | ret |= tmp; |
| 306 | } |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 307 | if (ts78xx_fpga.supports.ts_nand.present == 1) { |
| 308 | tmp = ts78xx_ts_nand_load(); |
| 309 | if (tmp) { |
| 310 | printk(KERN_INFO "TS-78xx: NAND not registered\n"); |
| 311 | ts78xx_fpga.supports.ts_nand.present = 0; |
| 312 | } |
| 313 | ret |= tmp; |
| 314 | } |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | static int ts78xx_fpga_unload_devices(void) |
| 320 | { |
| 321 | int ret = 0; |
| 322 | |
| 323 | if (ts78xx_fpga.supports.ts_rtc.present == 1) |
| 324 | ts78xx_ts_rtc_unload(); |
Alexander Clouter | 75bb6b9 | 2009-02-23 22:40:01 +0000 | [diff] [blame^] | 325 | if (ts78xx_fpga.supports.ts_nand.present == 1) |
| 326 | ts78xx_ts_nand_unload(); |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 327 | |
| 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | static int ts78xx_fpga_load(void) |
| 332 | { |
| 333 | ts78xx_fpga.id = readl(TS78XX_FPGA_REGS_VIRT_BASE); |
| 334 | |
| 335 | printk(KERN_INFO "TS-78xx FPGA: magic=0x%.6x, rev=0x%.2x\n", |
| 336 | (ts78xx_fpga.id >> 8) & 0xffffff, |
| 337 | ts78xx_fpga.id & 0xff); |
| 338 | |
| 339 | ts78xx_fpga_supports(); |
| 340 | |
| 341 | if (ts78xx_fpga_load_devices()) { |
| 342 | ts78xx_fpga.state = -1; |
| 343 | return -EBUSY; |
| 344 | } |
| 345 | |
| 346 | return 0; |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 347 | }; |
| 348 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 349 | static int ts78xx_fpga_unload(void) |
| 350 | { |
| 351 | unsigned int fpga_id; |
| 352 | |
| 353 | fpga_id = readl(TS78XX_FPGA_REGS_VIRT_BASE); |
| 354 | |
| 355 | /* |
| 356 | * There does not seem to be a feasible way to block access to the GPIO |
| 357 | * pins from userspace (/dev/mem). This if clause should hopefully warn |
| 358 | * those foolish enough not to follow 'policy' :) |
| 359 | * |
| 360 | * UrJTAG SVN since r1381 can be used to reprogram the FPGA |
| 361 | */ |
| 362 | if (ts78xx_fpga.id != fpga_id) { |
| 363 | printk(KERN_ERR "TS-78xx FPGA: magic/rev mismatch\n" |
| 364 | "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n", |
| 365 | (ts78xx_fpga.id >> 8) & 0xffffff, ts78xx_fpga.id & 0xff, |
| 366 | (fpga_id >> 8) & 0xffffff, fpga_id & 0xff); |
| 367 | ts78xx_fpga.state = -1; |
| 368 | return -EBUSY; |
| 369 | } |
| 370 | |
| 371 | if (ts78xx_fpga_unload_devices()) { |
| 372 | ts78xx_fpga.state = -1; |
| 373 | return -EBUSY; |
| 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | }; |
| 378 | |
| 379 | static ssize_t ts78xx_fpga_show(struct kobject *kobj, |
| 380 | struct kobj_attribute *attr, char *buf) |
| 381 | { |
| 382 | if (ts78xx_fpga.state < 0) |
| 383 | return sprintf(buf, "borked\n"); |
| 384 | |
| 385 | return sprintf(buf, "%s\n", (ts78xx_fpga.state) ? "online" : "offline"); |
| 386 | } |
| 387 | |
| 388 | static ssize_t ts78xx_fpga_store(struct kobject *kobj, |
| 389 | struct kobj_attribute *attr, const char *buf, size_t n) |
| 390 | { |
| 391 | int value, ret; |
| 392 | |
| 393 | if (ts78xx_fpga.state < 0) { |
| 394 | printk(KERN_ERR "TS-78xx FPGA: borked, you must powercycle asap\n"); |
| 395 | return -EBUSY; |
| 396 | } |
| 397 | |
| 398 | if (strncmp(buf, "online", sizeof("online") - 1) == 0) |
| 399 | value = 1; |
| 400 | else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) |
| 401 | value = 0; |
| 402 | else { |
| 403 | printk(KERN_ERR "ts78xx_fpga_store: Invalid value\n"); |
| 404 | return -EINVAL; |
| 405 | } |
| 406 | |
| 407 | if (ts78xx_fpga.state == value) |
| 408 | return n; |
| 409 | |
| 410 | ret = (ts78xx_fpga.state == 0) |
| 411 | ? ts78xx_fpga_load() |
| 412 | : ts78xx_fpga_unload(); |
| 413 | |
| 414 | if (!(ret < 0)) |
| 415 | ts78xx_fpga.state = value; |
| 416 | |
| 417 | return n; |
| 418 | } |
| 419 | |
| 420 | static struct kobj_attribute ts78xx_fpga_attr = |
| 421 | __ATTR(ts78xx_fpga, 0644, ts78xx_fpga_show, ts78xx_fpga_store); |
| 422 | |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 423 | /***************************************************************************** |
| 424 | * General Setup |
| 425 | ****************************************************************************/ |
| 426 | static struct orion5x_mpp_mode ts78xx_mpp_modes[] __initdata = { |
| 427 | { 0, MPP_UNUSED }, |
| 428 | { 1, MPP_GPIO }, /* JTAG Clock */ |
| 429 | { 2, MPP_GPIO }, /* JTAG Data In */ |
| 430 | { 3, MPP_GPIO }, /* Lat ECP2 256 FPGA - PB2B */ |
| 431 | { 4, MPP_GPIO }, /* JTAG Data Out */ |
| 432 | { 5, MPP_GPIO }, /* JTAG TMS */ |
| 433 | { 6, MPP_GPIO }, /* Lat ECP2 256 FPGA - PB31A_CLK4+ */ |
| 434 | { 7, MPP_GPIO }, /* Lat ECP2 256 FPGA - PB22B */ |
| 435 | { 8, MPP_UNUSED }, |
| 436 | { 9, MPP_UNUSED }, |
| 437 | { 10, MPP_UNUSED }, |
| 438 | { 11, MPP_UNUSED }, |
| 439 | { 12, MPP_UNUSED }, |
| 440 | { 13, MPP_UNUSED }, |
| 441 | { 14, MPP_UNUSED }, |
| 442 | { 15, MPP_UNUSED }, |
| 443 | { 16, MPP_UART }, |
| 444 | { 17, MPP_UART }, |
| 445 | { 18, MPP_UART }, |
| 446 | { 19, MPP_UART }, |
Alexander Clouter | f541286 | 2009-02-06 21:59:15 +0000 | [diff] [blame] | 447 | /* |
| 448 | * MPP[20] PCI Clock Out 1 |
| 449 | * MPP[21] PCI Clock Out 0 |
| 450 | * MPP[22] Unused |
| 451 | * MPP[23] Unused |
| 452 | * MPP[24] Unused |
| 453 | * MPP[25] Unused |
| 454 | */ |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 455 | { -1 }, |
| 456 | }; |
| 457 | |
| 458 | static void __init ts78xx_init(void) |
| 459 | { |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 460 | int ret; |
| 461 | |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 462 | /* |
| 463 | * Setup basic Orion functions. Need to be called early. |
| 464 | */ |
| 465 | orion5x_init(); |
| 466 | |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 467 | orion5x_mpp_conf(ts78xx_mpp_modes); |
| 468 | |
| 469 | /* |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 470 | * Configure peripherals. |
| 471 | */ |
| 472 | orion5x_ehci0_init(); |
| 473 | orion5x_ehci1_init(); |
| 474 | orion5x_eth_init(&ts78xx_eth_data); |
| 475 | orion5x_sata_init(&ts78xx_sata_data); |
| 476 | orion5x_uart0_init(); |
| 477 | orion5x_uart1_init(); |
Saeed Bishara | 1d5a1a6 | 2008-06-16 23:25:12 -1100 | [diff] [blame] | 478 | orion5x_xor_init(); |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 479 | |
Alexander Clouter | 39008f9 | 2009-02-06 22:16:55 +0000 | [diff] [blame] | 480 | /* FPGA init */ |
| 481 | ts78xx_fpga_devices_zero_init(); |
| 482 | ret = ts78xx_fpga_load(); |
| 483 | ret = sysfs_create_file(power_kobj, &ts78xx_fpga_attr.attr); |
| 484 | if (ret) |
| 485 | printk(KERN_ERR "sysfs_create_file failed: %d\n", ret); |
Alexander Clouter | 7171d86 | 2008-05-31 22:32:37 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | MACHINE_START(TS78XX, "Technologic Systems TS-78xx SBC") |
| 489 | /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */ |
| 490 | .phys_io = ORION5X_REGS_PHYS_BASE, |
| 491 | .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC, |
| 492 | .boot_params = 0x00000100, |
| 493 | .init_machine = ts78xx_init, |
| 494 | .map_io = ts78xx_map_io, |
| 495 | .init_irq = orion5x_init_irq, |
| 496 | .timer = &orion5x_timer, |
| 497 | MACHINE_END |