blob: a74f3cf54cc56b8ae0c1ecf1caefbd0d2dccc138 [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
Alexander Clouter4d72cef2012-05-12 15:17:00 +010011#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
Alexander Clouter7171d862008-05-31 22:32:37 +010013#include <linux/kernel.h>
14#include <linux/init.h>
Alexander Clouter39008f92009-02-06 22:16:55 +000015#include <linux/sysfs.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010016#include <linux/platform_device.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010017#include <linux/mv643xx_eth.h>
18#include <linux/ata_platform.h>
19#include <linux/m48t86.h>
Alexander Clouter75bb6b92009-02-23 22:40:01 +000020#include <linux/mtd/nand.h>
21#include <linux/mtd/partitions.h>
Alexander Cloutera914d432009-05-03 12:57:48 -070022#include <linux/timeriomem-rng.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010023#include <asm/mach-types.h>
24#include <asm/mach/arch.h>
25#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/orion5x.h>
Alexander Clouter7171d862008-05-31 22:32:37 +010027#include "common.h"
28#include "mpp.h"
Alexander Clouter39008f92009-02-06 22:16:55 +000029#include "ts78xx-fpga.h"
Alexander Clouter7171d862008-05-31 22:32:37 +010030
31/*****************************************************************************
32 * TS-78xx Info
33 ****************************************************************************/
34
35/*
36 * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE
37 */
38#define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000
39#define TS78XX_FPGA_REGS_VIRT_BASE 0xff900000
40#define TS78XX_FPGA_REGS_SIZE SZ_1M
41
Alexander Clouter39008f92009-02-06 22:16:55 +000042static struct ts78xx_fpga_data ts78xx_fpga = {
43 .id = 0,
44 .state = 1,
45/* .supports = ... - populated by ts78xx_fpga_supports() */
46};
Alexander Clouter7171d862008-05-31 22:32:37 +010047
Alexander Clouter7171d862008-05-31 22:32:37 +010048/*****************************************************************************
49 * I/O Address Mapping
50 ****************************************************************************/
51static struct map_desc ts78xx_io_desc[] __initdata = {
52 {
53 .virtual = TS78XX_FPGA_REGS_VIRT_BASE,
54 .pfn = __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE),
55 .length = TS78XX_FPGA_REGS_SIZE,
56 .type = MT_DEVICE,
57 },
58};
59
60void __init ts78xx_map_io(void)
61{
62 orion5x_map_io();
63 iotable_init(ts78xx_io_desc, ARRAY_SIZE(ts78xx_io_desc));
64}
65
66/*****************************************************************************
Alexander Clouter7171d862008-05-31 22:32:37 +010067 * Ethernet
68 ****************************************************************************/
69static struct mv643xx_eth_platform_data ts78xx_eth_data = {
Lennert Buytenhekac840602008-08-26 14:06:47 +020070 .phy_addr = MV643XX_ETH_PHY_ADDR(0),
Alexander Clouter7171d862008-05-31 22:32:37 +010071};
72
73/*****************************************************************************
Alexander Clouter39008f92009-02-06 22:16:55 +000074 * SATA
75 ****************************************************************************/
76static struct mv_sata_platform_data ts78xx_sata_data = {
77 .n_ports = 2,
78};
79
80/*****************************************************************************
Alexander Clouter7171d862008-05-31 22:32:37 +010081 * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c
82 ****************************************************************************/
Alexander Clouter39008f92009-02-06 22:16:55 +000083#define TS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x808)
84#define TS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c)
85
86static unsigned char ts78xx_ts_rtc_readbyte(unsigned long addr)
Alexander Clouter7171d862008-05-31 22:32:37 +010087{
Alexander Clouter39008f92009-02-06 22:16:55 +000088 writeb(addr, TS_RTC_CTRL);
89 return readb(TS_RTC_DATA);
Alexander Clouter7171d862008-05-31 22:32:37 +010090}
91
Alexander Clouter39008f92009-02-06 22:16:55 +000092static void ts78xx_ts_rtc_writebyte(unsigned char value, unsigned long addr)
Alexander Clouter7171d862008-05-31 22:32:37 +010093{
Alexander Clouter39008f92009-02-06 22:16:55 +000094 writeb(addr, TS_RTC_CTRL);
95 writeb(value, TS_RTC_DATA);
Alexander Clouter7171d862008-05-31 22:32:37 +010096}
97
Alexander Clouter39008f92009-02-06 22:16:55 +000098static struct m48t86_ops ts78xx_ts_rtc_ops = {
99 .readbyte = ts78xx_ts_rtc_readbyte,
100 .writebyte = ts78xx_ts_rtc_writebyte,
Alexander Clouter7171d862008-05-31 22:32:37 +0100101};
102
Alexander Clouter39008f92009-02-06 22:16:55 +0000103static struct platform_device ts78xx_ts_rtc_device = {
Alexander Clouter7171d862008-05-31 22:32:37 +0100104 .name = "rtc-m48t86",
105 .id = -1,
106 .dev = {
Alexander Clouter39008f92009-02-06 22:16:55 +0000107 .platform_data = &ts78xx_ts_rtc_ops,
Alexander Clouter7171d862008-05-31 22:32:37 +0100108 },
109 .num_resources = 0,
110};
111
112/*
113 * TS uses some of the user storage space on the RTC chip so see if it is
114 * present; as it's an optional feature at purchase time and not all boards
115 * will have it present
116 *
117 * I've used the method TS use in their rtc7800.c example for the detection
118 *
119 * TODO: track down a guinea pig without an RTC to see if we can work out a
Alexander Clouter9f234992012-05-12 15:16:58 +0100120 * better RTC detection routine
Alexander Clouter7171d862008-05-31 22:32:37 +0100121 */
Alexander Clouter39008f92009-02-06 22:16:55 +0000122static int ts78xx_ts_rtc_load(void)
Alexander Clouter7171d862008-05-31 22:32:37 +0100123{
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000124 int rc;
Alexander Clouter7171d862008-05-31 22:32:37 +0100125 unsigned char tmp_rtc0, tmp_rtc1;
126
Alexander Clouter39008f92009-02-06 22:16:55 +0000127 tmp_rtc0 = ts78xx_ts_rtc_readbyte(126);
128 tmp_rtc1 = ts78xx_ts_rtc_readbyte(127);
Alexander Clouter7171d862008-05-31 22:32:37 +0100129
Alexander Clouter39008f92009-02-06 22:16:55 +0000130 ts78xx_ts_rtc_writebyte(0x00, 126);
131 ts78xx_ts_rtc_writebyte(0x55, 127);
132 if (ts78xx_ts_rtc_readbyte(127) == 0x55) {
133 ts78xx_ts_rtc_writebyte(0xaa, 127);
134 if (ts78xx_ts_rtc_readbyte(127) == 0xaa
135 && ts78xx_ts_rtc_readbyte(126) == 0x00) {
136 ts78xx_ts_rtc_writebyte(tmp_rtc0, 126);
137 ts78xx_ts_rtc_writebyte(tmp_rtc1, 127);
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000138
Alexander Clouter39008f92009-02-06 22:16:55 +0000139 if (ts78xx_fpga.supports.ts_rtc.init == 0) {
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000140 rc = platform_device_register(&ts78xx_ts_rtc_device);
141 if (!rc)
142 ts78xx_fpga.supports.ts_rtc.init = 1;
Alexander Clouter39008f92009-02-06 22:16:55 +0000143 } else
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000144 rc = platform_device_add(&ts78xx_ts_rtc_device);
145
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100146 if (rc)
147 pr_info("RTC could not be registered: %d\n",
148 rc);
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000149 return rc;
Alexander Clouter7171d862008-05-31 22:32:37 +0100150 }
151 }
152
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100153 pr_info("RTC not found\n");
Alexander Clouter39008f92009-02-06 22:16:55 +0000154 return -ENODEV;
Alexander Clouter7171d862008-05-31 22:32:37 +0100155};
Alexander Clouter39008f92009-02-06 22:16:55 +0000156
157static void ts78xx_ts_rtc_unload(void)
158{
159 platform_device_del(&ts78xx_ts_rtc_device);
160}
Alexander Clouter7171d862008-05-31 22:32:37 +0100161
162/*****************************************************************************
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000163 * NAND Flash
164 ****************************************************************************/
165#define TS_NAND_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x800) /* VIRT */
166#define TS_NAND_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x804) /* PHYS */
167
168/*
169 * hardware specific access to control-lines
170 *
171 * ctrl:
172 * NAND_NCE: bit 0 -> bit 2
173 * NAND_CLE: bit 1 -> bit 1
174 * NAND_ALE: bit 2 -> bit 0
175 */
176static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
177 unsigned int ctrl)
178{
179 struct nand_chip *this = mtd->priv;
180
181 if (ctrl & NAND_CTRL_CHANGE) {
182 unsigned char bits;
183
184 bits = (ctrl & NAND_NCE) << 2;
185 bits |= ctrl & NAND_CLE;
186 bits |= (ctrl & NAND_ALE) >> 2;
187
188 writeb((readb(TS_NAND_CTRL) & ~0x7) | bits, TS_NAND_CTRL);
189 }
190
191 if (cmd != NAND_CMD_NONE)
192 writeb(cmd, this->IO_ADDR_W);
193}
194
195static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd)
196{
197 return readb(TS_NAND_CTRL) & 0x20;
198}
199
Alexander Cloutere25bac92011-01-08 11:55:25 +0000200static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd,
201 const uint8_t *buf, int len)
202{
203 struct nand_chip *chip = mtd->priv;
204 void __iomem *io_base = chip->IO_ADDR_W;
205 unsigned long off = ((unsigned long)buf & 3);
206 int sz;
207
208 if (off) {
Alexander Clouter53936c52011-03-05 11:31:04 +0000209 sz = min_t(int, 4 - off, len);
Alexander Cloutere25bac92011-01-08 11:55:25 +0000210 writesb(io_base, buf, sz);
211 buf += sz;
212 len -= sz;
213 }
214
215 sz = len >> 2;
216 if (sz) {
217 u32 *buf32 = (u32 *)buf;
218 writesl(io_base, buf32, sz);
219 buf += sz << 2;
220 len -= sz << 2;
221 }
222
223 if (len)
224 writesb(io_base, buf, len);
225}
226
227static void ts78xx_ts_nand_read_buf(struct mtd_info *mtd,
228 uint8_t *buf, int len)
229{
230 struct nand_chip *chip = mtd->priv;
231 void __iomem *io_base = chip->IO_ADDR_R;
232 unsigned long off = ((unsigned long)buf & 3);
233 int sz;
234
235 if (off) {
Alexander Clouter53936c52011-03-05 11:31:04 +0000236 sz = min_t(int, 4 - off, len);
Alexander Cloutere25bac92011-01-08 11:55:25 +0000237 readsb(io_base, buf, sz);
238 buf += sz;
239 len -= sz;
240 }
241
242 sz = len >> 2;
243 if (sz) {
244 u32 *buf32 = (u32 *)buf;
245 readsl(io_base, buf32, sz);
246 buf += sz << 2;
247 len -= sz << 2;
248 }
249
250 if (len)
251 readsb(io_base, buf, len);
252}
253
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000254const char *ts_nand_part_probes[] = { "cmdlinepart", NULL };
255
256static struct mtd_partition ts78xx_ts_nand_parts[] = {
257 {
258 .name = "mbr",
259 .offset = 0,
260 .size = SZ_128K,
261 .mask_flags = MTD_WRITEABLE,
262 }, {
263 .name = "kernel",
264 .offset = MTDPART_OFS_APPEND,
265 .size = SZ_4M,
266 }, {
267 .name = "initrd",
268 .offset = MTDPART_OFS_APPEND,
269 .size = SZ_4M,
270 }, {
271 .name = "rootfs",
272 .offset = MTDPART_OFS_APPEND,
273 .size = MTDPART_SIZ_FULL,
274 }
275};
276
277static struct platform_nand_data ts78xx_ts_nand_data = {
278 .chip = {
Marek Vasutef077172010-08-12 02:14:54 +0100279 .nr_chips = 1,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000280 .part_probe_types = ts_nand_part_probes,
281 .partitions = ts78xx_ts_nand_parts,
282 .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts),
283 .chip_delay = 15,
Brian Norrisbb9ebd42011-05-31 16:31:23 -0700284 .bbt_options = NAND_BBT_USE_FLASH,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000285 },
286 .ctrl = {
287 /*
288 * The HW ECC offloading functions, used to give about a 9%
289 * performance increase for 'dd if=/dev/mtdblockX' and 5% for
290 * nanddump. This all however was changed by git commit
291 * e6cf5df1838c28bb060ac45b5585e48e71bbc740 so now there is
292 * no performance advantage to be had so we no longer bother
293 */
294 .cmd_ctrl = ts78xx_ts_nand_cmd_ctrl,
295 .dev_ready = ts78xx_ts_nand_dev_ready,
Alexander Cloutere25bac92011-01-08 11:55:25 +0000296 .write_buf = ts78xx_ts_nand_write_buf,
297 .read_buf = ts78xx_ts_nand_read_buf,
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000298 },
299};
300
Alexander Clouter167473a2012-05-12 15:16:59 +0100301static struct resource ts78xx_ts_nand_resources
302 = DEFINE_RES_MEM(TS_NAND_DATA, 4);
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000303
304static struct platform_device ts78xx_ts_nand_device = {
305 .name = "gen_nand",
306 .id = -1,
307 .dev = {
308 .platform_data = &ts78xx_ts_nand_data,
309 },
310 .resource = &ts78xx_ts_nand_resources,
311 .num_resources = 1,
312};
313
314static int ts78xx_ts_nand_load(void)
315{
316 int rc;
317
318 if (ts78xx_fpga.supports.ts_nand.init == 0) {
319 rc = platform_device_register(&ts78xx_ts_nand_device);
320 if (!rc)
321 ts78xx_fpga.supports.ts_nand.init = 1;
322 } else
323 rc = platform_device_add(&ts78xx_ts_nand_device);
324
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100325 if (rc)
326 pr_info("NAND could not be registered: %d\n", rc);
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000327 return rc;
328};
329
330static void ts78xx_ts_nand_unload(void)
331{
332 platform_device_del(&ts78xx_ts_nand_device);
333}
334
335/*****************************************************************************
Alexander Cloutera914d432009-05-03 12:57:48 -0700336 * HW RNG
337 ****************************************************************************/
338#define TS_RNG_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x044)
339
Alexander Clouter167473a2012-05-12 15:16:59 +0100340static struct resource ts78xx_ts_rng_resource
341 = DEFINE_RES_MEM(TS_RNG_DATA, 4);
Alexander Cloutera914d432009-05-03 12:57:48 -0700342
343static struct timeriomem_rng_data ts78xx_ts_rng_data = {
344 .period = 1000000, /* one second */
345};
346
347static struct platform_device ts78xx_ts_rng_device = {
348 .name = "timeriomem_rng",
349 .id = -1,
350 .dev = {
351 .platform_data = &ts78xx_ts_rng_data,
352 },
353 .resource = &ts78xx_ts_rng_resource,
354 .num_resources = 1,
355};
356
357static int ts78xx_ts_rng_load(void)
358{
359 int rc;
360
361 if (ts78xx_fpga.supports.ts_rng.init == 0) {
362 rc = platform_device_register(&ts78xx_ts_rng_device);
363 if (!rc)
364 ts78xx_fpga.supports.ts_rng.init = 1;
365 } else
366 rc = platform_device_add(&ts78xx_ts_rng_device);
367
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100368 if (rc)
369 pr_info("RNG could not be registered: %d\n", rc);
Alexander Cloutera914d432009-05-03 12:57:48 -0700370 return rc;
371};
372
373static void ts78xx_ts_rng_unload(void)
374{
375 platform_device_del(&ts78xx_ts_rng_device);
376}
377
378/*****************************************************************************
Alexander Clouter39008f92009-02-06 22:16:55 +0000379 * FPGA 'hotplug' support code
Alexander Clouter7171d862008-05-31 22:32:37 +0100380 ****************************************************************************/
Alexander Clouter39008f92009-02-06 22:16:55 +0000381static void ts78xx_fpga_devices_zero_init(void)
Alexander Clouter7171d862008-05-31 22:32:37 +0100382{
Alexander Clouter39008f92009-02-06 22:16:55 +0000383 ts78xx_fpga.supports.ts_rtc.init = 0;
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000384 ts78xx_fpga.supports.ts_nand.init = 0;
Alexander Cloutera914d432009-05-03 12:57:48 -0700385 ts78xx_fpga.supports.ts_rng.init = 0;
Alexander Clouter39008f92009-02-06 22:16:55 +0000386}
Alexander Clouter7171d862008-05-31 22:32:37 +0100387
Alexander Clouter39008f92009-02-06 22:16:55 +0000388static void ts78xx_fpga_supports(void)
389{
390 /* TODO: put this 'table' into ts78xx-fpga.h */
391 switch (ts78xx_fpga.id) {
Alexander Clouter0c1355e2009-03-21 11:09:25 +0000392 case TS7800_REV_1:
393 case TS7800_REV_2:
394 case TS7800_REV_3:
395 case TS7800_REV_4:
396 case TS7800_REV_5:
Alexander Clouter17718e12011-02-16 22:29:39 +0000397 case TS7800_REV_6:
398 case TS7800_REV_7:
399 case TS7800_REV_8:
400 case TS7800_REV_9:
Alexander Clouter39008f92009-02-06 22:16:55 +0000401 ts78xx_fpga.supports.ts_rtc.present = 1;
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000402 ts78xx_fpga.supports.ts_nand.present = 1;
Alexander Cloutera914d432009-05-03 12:57:48 -0700403 ts78xx_fpga.supports.ts_rng.present = 1;
Alexander Clouter39008f92009-02-06 22:16:55 +0000404 break;
405 default:
Alexander Clouterb3882332011-03-05 11:49:36 +0000406 /* enable devices if magic matches */
407 switch ((ts78xx_fpga.id >> 8) & 0xffffff) {
408 case TS7800_FPGA_MAGIC:
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100409 pr_warning("unrecognised FPGA revision 0x%.2x\n",
Alexander Clouterb3882332011-03-05 11:49:36 +0000410 ts78xx_fpga.id & 0xff);
411 ts78xx_fpga.supports.ts_rtc.present = 1;
412 ts78xx_fpga.supports.ts_nand.present = 1;
413 ts78xx_fpga.supports.ts_rng.present = 1;
414 break;
415 default:
416 ts78xx_fpga.supports.ts_rtc.present = 0;
417 ts78xx_fpga.supports.ts_nand.present = 0;
418 ts78xx_fpga.supports.ts_rng.present = 0;
419 }
Alexander Clouter39008f92009-02-06 22:16:55 +0000420 }
421}
422
423static int ts78xx_fpga_load_devices(void)
424{
425 int tmp, ret = 0;
426
427 if (ts78xx_fpga.supports.ts_rtc.present == 1) {
428 tmp = ts78xx_ts_rtc_load();
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100429 if (tmp)
Alexander Clouterf5273fa2009-02-23 22:37:36 +0000430 ts78xx_fpga.supports.ts_rtc.present = 0;
Alexander Clouter39008f92009-02-06 22:16:55 +0000431 ret |= tmp;
432 }
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000433 if (ts78xx_fpga.supports.ts_nand.present == 1) {
434 tmp = ts78xx_ts_nand_load();
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100435 if (tmp)
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000436 ts78xx_fpga.supports.ts_nand.present = 0;
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000437 ret |= tmp;
438 }
Alexander Cloutera914d432009-05-03 12:57:48 -0700439 if (ts78xx_fpga.supports.ts_rng.present == 1) {
440 tmp = ts78xx_ts_rng_load();
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100441 if (tmp)
Alexander Cloutera914d432009-05-03 12:57:48 -0700442 ts78xx_fpga.supports.ts_rng.present = 0;
Alexander Cloutera914d432009-05-03 12:57:48 -0700443 ret |= tmp;
444 }
Alexander Clouter39008f92009-02-06 22:16:55 +0000445
446 return ret;
447}
448
449static int ts78xx_fpga_unload_devices(void)
450{
451 int ret = 0;
452
453 if (ts78xx_fpga.supports.ts_rtc.present == 1)
454 ts78xx_ts_rtc_unload();
Alexander Clouter75bb6b92009-02-23 22:40:01 +0000455 if (ts78xx_fpga.supports.ts_nand.present == 1)
456 ts78xx_ts_nand_unload();
Alexander Cloutera914d432009-05-03 12:57:48 -0700457 if (ts78xx_fpga.supports.ts_rng.present == 1)
458 ts78xx_ts_rng_unload();
Alexander Clouter39008f92009-02-06 22:16:55 +0000459
460 return ret;
461}
462
463static int ts78xx_fpga_load(void)
464{
465 ts78xx_fpga.id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
466
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100467 pr_info("FPGA magic=0x%.6x, rev=0x%.2x\n",
Alexander Clouter39008f92009-02-06 22:16:55 +0000468 (ts78xx_fpga.id >> 8) & 0xffffff,
469 ts78xx_fpga.id & 0xff);
470
471 ts78xx_fpga_supports();
472
473 if (ts78xx_fpga_load_devices()) {
474 ts78xx_fpga.state = -1;
475 return -EBUSY;
476 }
477
478 return 0;
Alexander Clouter7171d862008-05-31 22:32:37 +0100479};
480
Alexander Clouter39008f92009-02-06 22:16:55 +0000481static int ts78xx_fpga_unload(void)
482{
483 unsigned int fpga_id;
484
485 fpga_id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
486
487 /*
488 * There does not seem to be a feasible way to block access to the GPIO
489 * pins from userspace (/dev/mem). This if clause should hopefully warn
490 * those foolish enough not to follow 'policy' :)
491 *
492 * UrJTAG SVN since r1381 can be used to reprogram the FPGA
493 */
494 if (ts78xx_fpga.id != fpga_id) {
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100495 pr_err("FPGA magic/rev mismatch\n"
Alexander Clouter39008f92009-02-06 22:16:55 +0000496 "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n",
497 (ts78xx_fpga.id >> 8) & 0xffffff, ts78xx_fpga.id & 0xff,
498 (fpga_id >> 8) & 0xffffff, fpga_id & 0xff);
499 ts78xx_fpga.state = -1;
500 return -EBUSY;
501 }
502
503 if (ts78xx_fpga_unload_devices()) {
504 ts78xx_fpga.state = -1;
505 return -EBUSY;
506 }
507
508 return 0;
509};
510
511static ssize_t ts78xx_fpga_show(struct kobject *kobj,
512 struct kobj_attribute *attr, char *buf)
513{
514 if (ts78xx_fpga.state < 0)
515 return sprintf(buf, "borked\n");
516
517 return sprintf(buf, "%s\n", (ts78xx_fpga.state) ? "online" : "offline");
518}
519
520static ssize_t ts78xx_fpga_store(struct kobject *kobj,
521 struct kobj_attribute *attr, const char *buf, size_t n)
522{
523 int value, ret;
524
525 if (ts78xx_fpga.state < 0) {
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100526 pr_err("FPGA borked, you must powercycle ASAP\n");
Alexander Clouter39008f92009-02-06 22:16:55 +0000527 return -EBUSY;
528 }
529
530 if (strncmp(buf, "online", sizeof("online") - 1) == 0)
531 value = 1;
532 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
533 value = 0;
Alexander Clouter4d72cef2012-05-12 15:17:00 +0100534 else
Alexander Clouter39008f92009-02-06 22:16:55 +0000535 return -EINVAL;
Alexander Clouter39008f92009-02-06 22:16:55 +0000536
537 if (ts78xx_fpga.state == value)
538 return n;
539
540 ret = (ts78xx_fpga.state == 0)
541 ? ts78xx_fpga_load()
542 : ts78xx_fpga_unload();
543
544 if (!(ret < 0))
545 ts78xx_fpga.state = value;
546
547 return n;
548}
549
550static struct kobj_attribute ts78xx_fpga_attr =
551 __ATTR(ts78xx_fpga, 0644, ts78xx_fpga_show, ts78xx_fpga_store);
552
Alexander Clouter7171d862008-05-31 22:32:37 +0100553/*****************************************************************************
554 * General Setup
555 ****************************************************************************/
Andrew Lunn554cdae2011-05-15 13:32:53 +0200556static unsigned int ts78xx_mpp_modes[] __initdata = {
557 MPP0_UNUSED,
558 MPP1_GPIO, /* JTAG Clock */
559 MPP2_GPIO, /* JTAG Data In */
560 MPP3_GPIO, /* Lat ECP2 256 FPGA - PB2B */
561 MPP4_GPIO, /* JTAG Data Out */
562 MPP5_GPIO, /* JTAG TMS */
563 MPP6_GPIO, /* Lat ECP2 256 FPGA - PB31A_CLK4+ */
564 MPP7_GPIO, /* Lat ECP2 256 FPGA - PB22B */
565 MPP8_UNUSED,
566 MPP9_UNUSED,
567 MPP10_UNUSED,
568 MPP11_UNUSED,
569 MPP12_UNUSED,
570 MPP13_UNUSED,
571 MPP14_UNUSED,
572 MPP15_UNUSED,
573 MPP16_UART,
574 MPP17_UART,
575 MPP18_UART,
576 MPP19_UART,
Alexander Clouterf5412862009-02-06 21:59:15 +0000577 /*
578 * MPP[20] PCI Clock Out 1
579 * MPP[21] PCI Clock Out 0
580 * MPP[22] Unused
581 * MPP[23] Unused
582 * MPP[24] Unused
583 * MPP[25] Unused
584 */
Andrew Lunn554cdae2011-05-15 13:32:53 +0200585 0,
Alexander Clouter7171d862008-05-31 22:32:37 +0100586};
587
588static void __init ts78xx_init(void)
589{
Alexander Clouter39008f92009-02-06 22:16:55 +0000590 int ret;
591
Alexander Clouter7171d862008-05-31 22:32:37 +0100592 /*
593 * Setup basic Orion functions. Need to be called early.
594 */
595 orion5x_init();
596
Alexander Clouter7171d862008-05-31 22:32:37 +0100597 orion5x_mpp_conf(ts78xx_mpp_modes);
598
599 /*
Alexander Clouter7171d862008-05-31 22:32:37 +0100600 * Configure peripherals.
601 */
602 orion5x_ehci0_init();
603 orion5x_ehci1_init();
604 orion5x_eth_init(&ts78xx_eth_data);
605 orion5x_sata_init(&ts78xx_sata_data);
606 orion5x_uart0_init();
607 orion5x_uart1_init();
Saeed Bishara1d5a1a62008-06-16 23:25:12 -1100608 orion5x_xor_init();
Alexander Clouter7171d862008-05-31 22:32:37 +0100609
Alexander Clouter39008f92009-02-06 22:16:55 +0000610 /* FPGA init */
611 ts78xx_fpga_devices_zero_init();
612 ret = ts78xx_fpga_load();
Alexander Clouter4f8cf612012-05-12 15:17:01 +0100613 ret = sysfs_create_file(firmware_kobj, &ts78xx_fpga_attr.attr);
Alexander Clouter39008f92009-02-06 22:16:55 +0000614 if (ret)
Alexander Clouter7bcdca92011-03-06 10:04:31 +0000615 pr_err("sysfs_create_file failed: %d\n", ret);
Alexander Clouter7171d862008-05-31 22:32:37 +0100616}
617
618MACHINE_START(TS78XX, "Technologic Systems TS-78xx SBC")
619 /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */
Nicolas Pitre65aa1b12011-07-05 22:38:15 -0400620 .atag_offset = 0x100,
Alexander Clouter7171d862008-05-31 22:32:37 +0100621 .init_machine = ts78xx_init,
622 .map_io = ts78xx_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200623 .init_early = orion5x_init_early,
Alexander Clouter7171d862008-05-31 22:32:37 +0100624 .init_irq = orion5x_init_irq,
625 .timer = &orion5x_timer,
Russell King764cbcc2011-11-05 10:13:41 +0000626 .restart = orion5x_restart,
Alexander Clouter7171d862008-05-31 22:32:37 +0100627MACHINE_END