blob: 1e1436363b8b3f10af4d09d6bb71ae22aa6e9a97 [file] [log] [blame]
Alexander Clouter7171d862008-05-31 22:32:37 +01001/*
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 Clouter39008f92009-02-06 22:16:55 +000013#include <linux/sysfs.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010014#include <linux/platform_device.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010015#include <linux/mv643xx_eth.h>
16#include <linux/ata_platform.h>
17#include <linux/m48t86.h>
Alexander Clouter75bb6b92009-02-23 22:40:01 +000018#include <linux/mtd/nand.h>
19#include <linux/mtd/partitions.h>
Alexander Cloutera914d432009-05-03 12:57:48 -070020#include <linux/timeriomem-rng.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010021#include <asm/mach-types.h>
22#include <asm/mach/arch.h>
23#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/orion5x.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010025#include "common.h"
26#include "mpp.h"
Alexander Clouter39008f92009-02-06 22:16:55 +000027#include "ts78xx-fpga.h"
Alexander Clouter7171d862008-05-31 22:32:37 +010028
29/*****************************************************************************
30 * TS-78xx Info
31 ****************************************************************************/
32
33/*
34 * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE
35 */
36#define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000
37#define TS78XX_FPGA_REGS_VIRT_BASE 0xff900000
38#define TS78XX_FPGA_REGS_SIZE SZ_1M
39
Alexander Clouter39008f92009-02-06 22:16:55 +000040static struct ts78xx_fpga_data ts78xx_fpga = {
41 .id = 0,
42 .state = 1,
43/* .supports = ... - populated by ts78xx_fpga_supports() */
44};
Alexander Clouter7171d862008-05-31 22:32:37 +010045
Alexander Clouter7171d862008-05-31 22:32:37 +010046/*****************************************************************************
47 * I/O Address Mapping
48 ****************************************************************************/
49static struct map_desc ts78xx_io_desc[] __initdata = {
50 {
51 .virtual = TS78XX_FPGA_REGS_VIRT_BASE,
52 .pfn = __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE),
53 .length = TS78XX_FPGA_REGS_SIZE,
54 .type = MT_DEVICE,
55 },
56};
57
58void __init ts78xx_map_io(void)
59{
60 orion5x_map_io();
61 iotable_init(ts78xx_io_desc, ARRAY_SIZE(ts78xx_io_desc));
62}
63
64/*****************************************************************************
Alexander Clouter7171d862008-05-31 22:32:37 +010065 * Ethernet
66 ****************************************************************************/
67static struct mv643xx_eth_platform_data ts78xx_eth_data = {
Lennert Buytenhekac8406052008-08-26 14:06:47 +020068 .phy_addr = MV643XX_ETH_PHY_ADDR(0),
Alexander Clouter7171d862008-05-31 22:32:37 +010069};
70
71/*****************************************************************************
Alexander Clouter39008f92009-02-06 22:16:55 +000072 * SATA
73 ****************************************************************************/
74static struct mv_sata_platform_data ts78xx_sata_data = {
75 .n_ports = 2,
76};
77
78/*****************************************************************************
Alexander Clouter7171d862008-05-31 22:32:37 +010079 * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c
80 ****************************************************************************/
Alexander Clouter39008f92009-02-06 22:16:55 +000081#define TS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x808)
82#define TS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c)
83
84static unsigned char ts78xx_ts_rtc_readbyte(unsigned long addr)
Alexander Clouter7171d862008-05-31 22:32:37 +010085{
Alexander Clouter39008f92009-02-06 22:16:55 +000086 writeb(addr, TS_RTC_CTRL);
87 return readb(TS_RTC_DATA);
Alexander Clouter7171d862008-05-31 22:32:37 +010088}
89
Alexander Clouter39008f92009-02-06 22:16:55 +000090static void ts78xx_ts_rtc_writebyte(unsigned char value, unsigned long addr)
Alexander Clouter7171d862008-05-31 22:32:37 +010091{
Alexander Clouter39008f92009-02-06 22:16:55 +000092 writeb(addr, TS_RTC_CTRL);
93 writeb(value, TS_RTC_DATA);
Alexander Clouter7171d862008-05-31 22:32:37 +010094}
95
Alexander Clouter39008f92009-02-06 22:16:55 +000096static struct m48t86_ops ts78xx_ts_rtc_ops = {
97 .readbyte = ts78xx_ts_rtc_readbyte,
98 .writebyte = ts78xx_ts_rtc_writebyte,
Alexander Clouter7171d862008-05-31 22:32:37 +010099};
100
Alexander Clouter39008f92009-02-06 22:16:55 +0000101static struct platform_device ts78xx_ts_rtc_device = {
Alexander Clouter7171d862008-05-31 22:32:37 +0100102 .name = "rtc-m48t86",
103 .id = -1,
104 .dev = {
Alexander Clouter39008f92009-02-06 22:16:55 +0000105 .platform_data = &ts78xx_ts_rtc_ops,
Alexander Clouter7171d862008-05-31 22:32:37 +0100106 },
107 .num_resources = 0,
108};
109
110/*
111 * TS uses some of the user storage space on the RTC chip so see if it is
112 * present; as it's an optional feature at purchase time and not all boards
113 * will have it present
114 *
115 * I've used the method TS use in their rtc7800.c example for the detection
116 *
117 * TODO: track down a guinea pig without an RTC to see if we can work out a
Alexander Clouter9f234992012-05-12 15:16:58 +0100118 * better RTC detection routine
Alexander Clouter7171d862008-05-31 22:32:37 +0100119 */
Alexander Clouter39008f92009-02-06 22:16:55 +0000120static int ts78xx_ts_rtc_load(void)
Alexander Clouter7171d862008-05-31 22:32:37 +0100121{
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000122 int rc;
Alexander Clouter7171d862008-05-31 22:32:37 +0100123 unsigned char tmp_rtc0, tmp_rtc1;
124
Alexander Clouter39008f92009-02-06 22:16:55 +0000125 tmp_rtc0 = ts78xx_ts_rtc_readbyte(126);
126 tmp_rtc1 = ts78xx_ts_rtc_readbyte(127);
Alexander Clouter7171d862008-05-31 22:32:37 +0100127
Alexander Clouter39008f92009-02-06 22:16:55 +0000128 ts78xx_ts_rtc_writebyte(0x00, 126);
129 ts78xx_ts_rtc_writebyte(0x55, 127);
130 if (ts78xx_ts_rtc_readbyte(127) == 0x55) {
131 ts78xx_ts_rtc_writebyte(0xaa, 127);
132 if (ts78xx_ts_rtc_readbyte(127) == 0xaa
133 && ts78xx_ts_rtc_readbyte(126) == 0x00) {
134 ts78xx_ts_rtc_writebyte(tmp_rtc0, 126);
135 ts78xx_ts_rtc_writebyte(tmp_rtc1, 127);
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000136
Alexander Clouter39008f92009-02-06 22:16:55 +0000137 if (ts78xx_fpga.supports.ts_rtc.init == 0) {
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000138 rc = platform_device_register(&ts78xx_ts_rtc_device);
139 if (!rc)
140 ts78xx_fpga.supports.ts_rtc.init = 1;
Alexander Clouter39008f92009-02-06 22:16:55 +0000141 } else
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000142 rc = platform_device_add(&ts78xx_ts_rtc_device);
143
144 return rc;
Alexander Clouter7171d862008-05-31 22:32:37 +0100145 }
146 }
147
Alexander Clouter39008f92009-02-06 22:16:55 +0000148 return -ENODEV;
Alexander Clouter7171d862008-05-31 22:32:37 +0100149};
Alexander Clouter39008f92009-02-06 22:16:55 +0000150
151static void ts78xx_ts_rtc_unload(void)
152{
153 platform_device_del(&ts78xx_ts_rtc_device);
154}
Alexander Clouter7171d862008-05-31 22:32:37 +0100155
156/*****************************************************************************
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000157 * NAND Flash
158 ****************************************************************************/
159#define TS_NAND_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x800) /* VIRT */
160#define TS_NAND_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x804) /* PHYS */
161
162/*
163 * hardware specific access to control-lines
164 *
165 * ctrl:
166 * NAND_NCE: bit 0 -> bit 2
167 * NAND_CLE: bit 1 -> bit 1
168 * NAND_ALE: bit 2 -> bit 0
169 */
170static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
171 unsigned int ctrl)
172{
173 struct nand_chip *this = mtd->priv;
174
175 if (ctrl & NAND_CTRL_CHANGE) {
176 unsigned char bits;
177
178 bits = (ctrl & NAND_NCE) << 2;
179 bits |= ctrl & NAND_CLE;
180 bits |= (ctrl & NAND_ALE) >> 2;
181
182 writeb((readb(TS_NAND_CTRL) & ~0x7) | bits, TS_NAND_CTRL);
183 }
184
185 if (cmd != NAND_CMD_NONE)
186 writeb(cmd, this->IO_ADDR_W);
187}
188
189static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd)
190{
191 return readb(TS_NAND_CTRL) & 0x20;
192}
193
Alexander Cloutere25bac92011-01-08 11:55:25 +0000194static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd,
195 const uint8_t *buf, int len)
196{
197 struct nand_chip *chip = mtd->priv;
198 void __iomem *io_base = chip->IO_ADDR_W;
199 unsigned long off = ((unsigned long)buf & 3);
200 int sz;
201
202 if (off) {
Alexander Clouter53936c52011-03-05 11:31:04 +0000203 sz = min_t(int, 4 - off, len);
Alexander Cloutere25bac92011-01-08 11:55:25 +0000204 writesb(io_base, buf, sz);
205 buf += sz;
206 len -= sz;
207 }
208
209 sz = len >> 2;
210 if (sz) {
211 u32 *buf32 = (u32 *)buf;
212 writesl(io_base, buf32, sz);
213 buf += sz << 2;
214 len -= sz << 2;
215 }
216
217 if (len)
218 writesb(io_base, buf, len);
219}
220
221static void ts78xx_ts_nand_read_buf(struct mtd_info *mtd,
222 uint8_t *buf, int len)
223{
224 struct nand_chip *chip = mtd->priv;
225 void __iomem *io_base = chip->IO_ADDR_R;
226 unsigned long off = ((unsigned long)buf & 3);
227 int sz;
228
229 if (off) {
Alexander Clouter53936c52011-03-05 11:31:04 +0000230 sz = min_t(int, 4 - off, len);
Alexander Cloutere25bac92011-01-08 11:55:25 +0000231 readsb(io_base, buf, sz);
232 buf += sz;
233 len -= sz;
234 }
235
236 sz = len >> 2;
237 if (sz) {
238 u32 *buf32 = (u32 *)buf;
239 readsl(io_base, buf32, sz);
240 buf += sz << 2;
241 len -= sz << 2;
242 }
243
244 if (len)
245 readsb(io_base, buf, len);
246}
247
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000248const char *ts_nand_part_probes[] = { "cmdlinepart", NULL };
249
250static struct mtd_partition ts78xx_ts_nand_parts[] = {
251 {
252 .name = "mbr",
253 .offset = 0,
254 .size = SZ_128K,
255 .mask_flags = MTD_WRITEABLE,
256 }, {
257 .name = "kernel",
258 .offset = MTDPART_OFS_APPEND,
259 .size = SZ_4M,
260 }, {
261 .name = "initrd",
262 .offset = MTDPART_OFS_APPEND,
263 .size = SZ_4M,
264 }, {
265 .name = "rootfs",
266 .offset = MTDPART_OFS_APPEND,
267 .size = MTDPART_SIZ_FULL,
268 }
269};
270
271static struct platform_nand_data ts78xx_ts_nand_data = {
272 .chip = {
Marek Vasutef077172010-08-12 02:14:54 +0100273 .nr_chips = 1,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000274 .part_probe_types = ts_nand_part_probes,
275 .partitions = ts78xx_ts_nand_parts,
276 .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts),
277 .chip_delay = 15,
Brian Norrisbb9ebd42011-05-31 16:31:23 -0700278 .bbt_options = NAND_BBT_USE_FLASH,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000279 },
280 .ctrl = {
281 /*
282 * The HW ECC offloading functions, used to give about a 9%
283 * performance increase for 'dd if=/dev/mtdblockX' and 5% for
284 * nanddump. This all however was changed by git commit
285 * e6cf5df1838c28bb060ac45b5585e48e71bbc740 so now there is
286 * no performance advantage to be had so we no longer bother
287 */
288 .cmd_ctrl = ts78xx_ts_nand_cmd_ctrl,
289 .dev_ready = ts78xx_ts_nand_dev_ready,
Alexander Cloutere25bac92011-01-08 11:55:25 +0000290 .write_buf = ts78xx_ts_nand_write_buf,
291 .read_buf = ts78xx_ts_nand_read_buf,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000292 },
293};
294
Alexander Clouter167473a2012-05-12 15:16:59 +0100295static struct resource ts78xx_ts_nand_resources
296 = DEFINE_RES_MEM(TS_NAND_DATA, 4);
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000297
298static struct platform_device ts78xx_ts_nand_device = {
299 .name = "gen_nand",
300 .id = -1,
301 .dev = {
302 .platform_data = &ts78xx_ts_nand_data,
303 },
304 .resource = &ts78xx_ts_nand_resources,
305 .num_resources = 1,
306};
307
308static int ts78xx_ts_nand_load(void)
309{
310 int rc;
311
312 if (ts78xx_fpga.supports.ts_nand.init == 0) {
313 rc = platform_device_register(&ts78xx_ts_nand_device);
314 if (!rc)
315 ts78xx_fpga.supports.ts_nand.init = 1;
316 } else
317 rc = platform_device_add(&ts78xx_ts_nand_device);
318
319 return rc;
320};
321
322static void ts78xx_ts_nand_unload(void)
323{
324 platform_device_del(&ts78xx_ts_nand_device);
325}
326
327/*****************************************************************************
Alexander Cloutera914d432009-05-03 12:57:48 -0700328 * HW RNG
329 ****************************************************************************/
330#define TS_RNG_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x044)
331
Alexander Clouter167473a2012-05-12 15:16:59 +0100332static struct resource ts78xx_ts_rng_resource
333 = DEFINE_RES_MEM(TS_RNG_DATA, 4);
Alexander Cloutera914d432009-05-03 12:57:48 -0700334
335static struct timeriomem_rng_data ts78xx_ts_rng_data = {
336 .period = 1000000, /* one second */
337};
338
339static struct platform_device ts78xx_ts_rng_device = {
340 .name = "timeriomem_rng",
341 .id = -1,
342 .dev = {
343 .platform_data = &ts78xx_ts_rng_data,
344 },
345 .resource = &ts78xx_ts_rng_resource,
346 .num_resources = 1,
347};
348
349static int ts78xx_ts_rng_load(void)
350{
351 int rc;
352
353 if (ts78xx_fpga.supports.ts_rng.init == 0) {
354 rc = platform_device_register(&ts78xx_ts_rng_device);
355 if (!rc)
356 ts78xx_fpga.supports.ts_rng.init = 1;
357 } else
358 rc = platform_device_add(&ts78xx_ts_rng_device);
359
360 return rc;
361};
362
363static void ts78xx_ts_rng_unload(void)
364{
365 platform_device_del(&ts78xx_ts_rng_device);
366}
367
368/*****************************************************************************
Alexander Clouter39008f92009-02-06 22:16:55 +0000369 * FPGA 'hotplug' support code
Alexander Clouter7171d862008-05-31 22:32:37 +0100370 ****************************************************************************/
Alexander Clouter39008f92009-02-06 22:16:55 +0000371static void ts78xx_fpga_devices_zero_init(void)
Alexander Clouter7171d862008-05-31 22:32:37 +0100372{
Alexander Clouter39008f92009-02-06 22:16:55 +0000373 ts78xx_fpga.supports.ts_rtc.init = 0;
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000374 ts78xx_fpga.supports.ts_nand.init = 0;
Alexander Cloutera914d432009-05-03 12:57:48 -0700375 ts78xx_fpga.supports.ts_rng.init = 0;
Alexander Clouter39008f92009-02-06 22:16:55 +0000376}
Alexander Clouter7171d862008-05-31 22:32:37 +0100377
Alexander Clouter39008f92009-02-06 22:16:55 +0000378static void ts78xx_fpga_supports(void)
379{
380 /* TODO: put this 'table' into ts78xx-fpga.h */
381 switch (ts78xx_fpga.id) {
Alexander Clouter0c1355e2009-03-21 11:09:25 +0000382 case TS7800_REV_1:
383 case TS7800_REV_2:
384 case TS7800_REV_3:
385 case TS7800_REV_4:
386 case TS7800_REV_5:
Alexander Clouter17718e12011-02-16 22:29:39 +0000387 case TS7800_REV_6:
388 case TS7800_REV_7:
389 case TS7800_REV_8:
390 case TS7800_REV_9:
Alexander Clouter39008f92009-02-06 22:16:55 +0000391 ts78xx_fpga.supports.ts_rtc.present = 1;
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000392 ts78xx_fpga.supports.ts_nand.present = 1;
Alexander Cloutera914d432009-05-03 12:57:48 -0700393 ts78xx_fpga.supports.ts_rng.present = 1;
Alexander Clouter39008f92009-02-06 22:16:55 +0000394 break;
395 default:
Alexander Clouterb3882332011-03-05 11:49:36 +0000396 /* enable devices if magic matches */
397 switch ((ts78xx_fpga.id >> 8) & 0xffffff) {
398 case TS7800_FPGA_MAGIC:
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000399 pr_warning("TS-7800 FPGA: unrecognized revision 0x%.2x\n",
Alexander Clouterb3882332011-03-05 11:49:36 +0000400 ts78xx_fpga.id & 0xff);
401 ts78xx_fpga.supports.ts_rtc.present = 1;
402 ts78xx_fpga.supports.ts_nand.present = 1;
403 ts78xx_fpga.supports.ts_rng.present = 1;
404 break;
405 default:
406 ts78xx_fpga.supports.ts_rtc.present = 0;
407 ts78xx_fpga.supports.ts_nand.present = 0;
408 ts78xx_fpga.supports.ts_rng.present = 0;
409 }
Alexander Clouter39008f92009-02-06 22:16:55 +0000410 }
411}
412
413static int ts78xx_fpga_load_devices(void)
414{
415 int tmp, ret = 0;
416
417 if (ts78xx_fpga.supports.ts_rtc.present == 1) {
418 tmp = ts78xx_ts_rtc_load();
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000419 if (tmp) {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000420 pr_info("TS-78xx: RTC not registered\n");
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000421 ts78xx_fpga.supports.ts_rtc.present = 0;
422 }
Alexander Clouter39008f92009-02-06 22:16:55 +0000423 ret |= tmp;
424 }
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000425 if (ts78xx_fpga.supports.ts_nand.present == 1) {
426 tmp = ts78xx_ts_nand_load();
427 if (tmp) {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000428 pr_info("TS-78xx: NAND not registered\n");
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000429 ts78xx_fpga.supports.ts_nand.present = 0;
430 }
431 ret |= tmp;
432 }
Alexander Cloutera914d432009-05-03 12:57:48 -0700433 if (ts78xx_fpga.supports.ts_rng.present == 1) {
434 tmp = ts78xx_ts_rng_load();
435 if (tmp) {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000436 pr_info("TS-78xx: RNG not registered\n");
Alexander Cloutera914d432009-05-03 12:57:48 -0700437 ts78xx_fpga.supports.ts_rng.present = 0;
438 }
439 ret |= tmp;
440 }
Alexander Clouter39008f92009-02-06 22:16:55 +0000441
442 return ret;
443}
444
445static int ts78xx_fpga_unload_devices(void)
446{
447 int ret = 0;
448
449 if (ts78xx_fpga.supports.ts_rtc.present == 1)
450 ts78xx_ts_rtc_unload();
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000451 if (ts78xx_fpga.supports.ts_nand.present == 1)
452 ts78xx_ts_nand_unload();
Alexander Cloutera914d432009-05-03 12:57:48 -0700453 if (ts78xx_fpga.supports.ts_rng.present == 1)
454 ts78xx_ts_rng_unload();
Alexander Clouter39008f92009-02-06 22:16:55 +0000455
456 return ret;
457}
458
459static int ts78xx_fpga_load(void)
460{
461 ts78xx_fpga.id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
462
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000463 pr_info("TS-78xx FPGA: magic=0x%.6x, rev=0x%.2x\n",
Alexander Clouter39008f92009-02-06 22:16:55 +0000464 (ts78xx_fpga.id >> 8) & 0xffffff,
465 ts78xx_fpga.id & 0xff);
466
467 ts78xx_fpga_supports();
468
469 if (ts78xx_fpga_load_devices()) {
470 ts78xx_fpga.state = -1;
471 return -EBUSY;
472 }
473
474 return 0;
Alexander Clouter7171d862008-05-31 22:32:37 +0100475};
476
Alexander Clouter39008f92009-02-06 22:16:55 +0000477static int ts78xx_fpga_unload(void)
478{
479 unsigned int fpga_id;
480
481 fpga_id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
482
483 /*
484 * There does not seem to be a feasible way to block access to the GPIO
485 * pins from userspace (/dev/mem). This if clause should hopefully warn
486 * those foolish enough not to follow 'policy' :)
487 *
488 * UrJTAG SVN since r1381 can be used to reprogram the FPGA
489 */
490 if (ts78xx_fpga.id != fpga_id) {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000491 pr_err("TS-78xx FPGA: magic/rev mismatch\n"
Alexander Clouter39008f92009-02-06 22:16:55 +0000492 "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n",
493 (ts78xx_fpga.id >> 8) & 0xffffff, ts78xx_fpga.id & 0xff,
494 (fpga_id >> 8) & 0xffffff, fpga_id & 0xff);
495 ts78xx_fpga.state = -1;
496 return -EBUSY;
497 }
498
499 if (ts78xx_fpga_unload_devices()) {
500 ts78xx_fpga.state = -1;
501 return -EBUSY;
502 }
503
504 return 0;
505};
506
507static ssize_t ts78xx_fpga_show(struct kobject *kobj,
508 struct kobj_attribute *attr, char *buf)
509{
510 if (ts78xx_fpga.state < 0)
511 return sprintf(buf, "borked\n");
512
513 return sprintf(buf, "%s\n", (ts78xx_fpga.state) ? "online" : "offline");
514}
515
516static ssize_t ts78xx_fpga_store(struct kobject *kobj,
517 struct kobj_attribute *attr, const char *buf, size_t n)
518{
519 int value, ret;
520
521 if (ts78xx_fpga.state < 0) {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000522 pr_err("TS-78xx FPGA: borked, you must powercycle asap\n");
Alexander Clouter39008f92009-02-06 22:16:55 +0000523 return -EBUSY;
524 }
525
526 if (strncmp(buf, "online", sizeof("online") - 1) == 0)
527 value = 1;
528 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
529 value = 0;
530 else {
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000531 pr_err("ts78xx_fpga_store: Invalid value\n");
Alexander Clouter39008f92009-02-06 22:16:55 +0000532 return -EINVAL;
533 }
534
535 if (ts78xx_fpga.state == value)
536 return n;
537
538 ret = (ts78xx_fpga.state == 0)
539 ? ts78xx_fpga_load()
540 : ts78xx_fpga_unload();
541
542 if (!(ret < 0))
543 ts78xx_fpga.state = value;
544
545 return n;
546}
547
548static struct kobj_attribute ts78xx_fpga_attr =
549 __ATTR(ts78xx_fpga, 0644, ts78xx_fpga_show, ts78xx_fpga_store);
550
Alexander Clouter7171d862008-05-31 22:32:37 +0100551/*****************************************************************************
552 * General Setup
553 ****************************************************************************/
Andrew Lunn554cdae2011-05-15 13:32:53 +0200554static unsigned int ts78xx_mpp_modes[] __initdata = {
555 MPP0_UNUSED,
556 MPP1_GPIO, /* JTAG Clock */
557 MPP2_GPIO, /* JTAG Data In */
558 MPP3_GPIO, /* Lat ECP2 256 FPGA - PB2B */
559 MPP4_GPIO, /* JTAG Data Out */
560 MPP5_GPIO, /* JTAG TMS */
561 MPP6_GPIO, /* Lat ECP2 256 FPGA - PB31A_CLK4+ */
562 MPP7_GPIO, /* Lat ECP2 256 FPGA - PB22B */
563 MPP8_UNUSED,
564 MPP9_UNUSED,
565 MPP10_UNUSED,
566 MPP11_UNUSED,
567 MPP12_UNUSED,
568 MPP13_UNUSED,
569 MPP14_UNUSED,
570 MPP15_UNUSED,
571 MPP16_UART,
572 MPP17_UART,
573 MPP18_UART,
574 MPP19_UART,
Alexander Clouterf5412862009-02-06 21:59:15 +0000575 /*
576 * MPP[20] PCI Clock Out 1
577 * MPP[21] PCI Clock Out 0
578 * MPP[22] Unused
579 * MPP[23] Unused
580 * MPP[24] Unused
581 * MPP[25] Unused
582 */
Andrew Lunn554cdae2011-05-15 13:32:53 +0200583 0,
Alexander Clouter7171d862008-05-31 22:32:37 +0100584};
585
586static void __init ts78xx_init(void)
587{
Alexander Clouter39008f92009-02-06 22:16:55 +0000588 int ret;
589
Alexander Clouter7171d862008-05-31 22:32:37 +0100590 /*
591 * Setup basic Orion functions. Need to be called early.
592 */
593 orion5x_init();
594
Alexander Clouter7171d862008-05-31 22:32:37 +0100595 orion5x_mpp_conf(ts78xx_mpp_modes);
596
597 /*
Alexander Clouter7171d862008-05-31 22:32:37 +0100598 * Configure peripherals.
599 */
600 orion5x_ehci0_init();
601 orion5x_ehci1_init();
602 orion5x_eth_init(&ts78xx_eth_data);
603 orion5x_sata_init(&ts78xx_sata_data);
604 orion5x_uart0_init();
605 orion5x_uart1_init();
Saeed Bishara1d5a1a62008-06-16 23:25:12 -1100606 orion5x_xor_init();
Alexander Clouter7171d862008-05-31 22:32:37 +0100607
Alexander Clouter39008f92009-02-06 22:16:55 +0000608 /* FPGA init */
609 ts78xx_fpga_devices_zero_init();
610 ret = ts78xx_fpga_load();
Alexander Clouter4f8cf612012-05-12 15:17:01 +0100611 ret = sysfs_create_file(firmware_kobj, &ts78xx_fpga_attr.attr);
Alexander Clouter39008f92009-02-06 22:16:55 +0000612 if (ret)
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000613 pr_err("sysfs_create_file failed: %d\n", ret);
Alexander Clouter7171d862008-05-31 22:32:37 +0100614}
615
616MACHINE_START(TS78XX, "Technologic Systems TS-78xx SBC")
617 /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */
Nicolas Pitre65aa1b12011-07-05 22:38:15 -0400618 .atag_offset = 0x100,
Alexander Clouter7171d862008-05-31 22:32:37 +0100619 .init_machine = ts78xx_init,
620 .map_io = ts78xx_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200621 .init_early = orion5x_init_early,
Alexander Clouter7171d862008-05-31 22:32:37 +0100622 .init_irq = orion5x_init_irq,
623 .timer = &orion5x_timer,
Russell King764cbcc22011-11-05 10:13:41 +0000624 .restart = orion5x_restart,
Alexander Clouter7171d862008-05-31 22:32:37 +0100625MACHINE_END