2 * arch/arm/mach-orion5x/ts78xx-setup.c
4 * Maintainer: Alexander Clouter <alex@digriz.org.uk>
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.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/sysfs.h>
14 #include <linux/platform_device.h>
15 #include <linux/mv643xx_eth.h>
16 #include <linux/ata_platform.h>
17 #include <linux/m48t86.h>
18 #include <linux/mtd/nand.h>
19 #include <linux/mtd/partitions.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/arch.h>
22 #include <asm/mach/map.h>
23 #include <mach/orion5x.h>
26 #include "ts78xx-fpga.h"
28 /*****************************************************************************
30 ****************************************************************************/
33 * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE
35 #define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000
36 #define TS78XX_FPGA_REGS_VIRT_BASE 0xff900000
37 #define TS78XX_FPGA_REGS_SIZE SZ_1M
39 static struct ts78xx_fpga_data ts78xx_fpga
= {
42 /* .supports = ... - populated by ts78xx_fpga_supports() */
45 /*****************************************************************************
47 ****************************************************************************/
48 static struct map_desc ts78xx_io_desc
[] __initdata
= {
50 .virtual = TS78XX_FPGA_REGS_VIRT_BASE
,
51 .pfn
= __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE
),
52 .length
= TS78XX_FPGA_REGS_SIZE
,
57 void __init
ts78xx_map_io(void)
60 iotable_init(ts78xx_io_desc
, ARRAY_SIZE(ts78xx_io_desc
));
63 /*****************************************************************************
65 ****************************************************************************/
66 static struct mv643xx_eth_platform_data ts78xx_eth_data
= {
67 .phy_addr
= MV643XX_ETH_PHY_ADDR(0),
70 /*****************************************************************************
72 ****************************************************************************/
73 static struct mv_sata_platform_data ts78xx_sata_data
= {
77 /*****************************************************************************
78 * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c
79 ****************************************************************************/
80 #define TS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE | 0x808)
81 #define TS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c)
83 static unsigned char ts78xx_ts_rtc_readbyte(unsigned long addr
)
85 writeb(addr
, TS_RTC_CTRL
);
86 return readb(TS_RTC_DATA
);
89 static void ts78xx_ts_rtc_writebyte(unsigned char value
, unsigned long addr
)
91 writeb(addr
, TS_RTC_CTRL
);
92 writeb(value
, TS_RTC_DATA
);
95 static struct m48t86_ops ts78xx_ts_rtc_ops
= {
96 .readbyte
= ts78xx_ts_rtc_readbyte
,
97 .writebyte
= ts78xx_ts_rtc_writebyte
,
100 static struct platform_device ts78xx_ts_rtc_device
= {
101 .name
= "rtc-m48t86",
104 .platform_data
= &ts78xx_ts_rtc_ops
,
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
114 * I've used the method TS use in their rtc7800.c example for the detection
116 * TODO: track down a guinea pig without an RTC to see if we can work out a
117 * better RTC detection routine
119 static int ts78xx_ts_rtc_load(void)
122 unsigned char tmp_rtc0
, tmp_rtc1
;
124 tmp_rtc0
= ts78xx_ts_rtc_readbyte(126);
125 tmp_rtc1
= ts78xx_ts_rtc_readbyte(127);
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);
136 if (ts78xx_fpga
.supports
.ts_rtc
.init
== 0) {
137 rc
= platform_device_register(&ts78xx_ts_rtc_device
);
139 ts78xx_fpga
.supports
.ts_rtc
.init
= 1;
141 rc
= platform_device_add(&ts78xx_ts_rtc_device
);
150 static void ts78xx_ts_rtc_unload(void)
152 platform_device_del(&ts78xx_ts_rtc_device
);
155 /*****************************************************************************
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 */
162 * hardware specific access to control-lines
165 * NAND_NCE: bit 0 -> bit 2
166 * NAND_CLE: bit 1 -> bit 1
167 * NAND_ALE: bit 2 -> bit 0
169 static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info
*mtd
, int cmd
,
172 struct nand_chip
*this = mtd
->priv
;
174 if (ctrl
& NAND_CTRL_CHANGE
) {
177 bits
= (ctrl
& NAND_NCE
) << 2;
178 bits
|= ctrl
& NAND_CLE
;
179 bits
|= (ctrl
& NAND_ALE
) >> 2;
181 writeb((readb(TS_NAND_CTRL
) & ~0x7) | bits
, TS_NAND_CTRL
);
184 if (cmd
!= NAND_CMD_NONE
)
185 writeb(cmd
, this->IO_ADDR_W
);
188 static int ts78xx_ts_nand_dev_ready(struct mtd_info
*mtd
)
190 return readb(TS_NAND_CTRL
) & 0x20;
193 const char *ts_nand_part_probes
[] = { "cmdlinepart", NULL
};
195 static struct mtd_partition ts78xx_ts_nand_parts
[] = {
200 .mask_flags
= MTD_WRITEABLE
,
203 .offset
= MTDPART_OFS_APPEND
,
207 .offset
= MTDPART_OFS_APPEND
,
211 .offset
= MTDPART_OFS_APPEND
,
212 .size
= MTDPART_SIZ_FULL
,
216 static struct platform_nand_data ts78xx_ts_nand_data
= {
218 .part_probe_types
= ts_nand_part_probes
,
219 .partitions
= ts78xx_ts_nand_parts
,
220 .nr_partitions
= ARRAY_SIZE(ts78xx_ts_nand_parts
),
222 .options
= NAND_USE_FLASH_BBT
,
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
232 .cmd_ctrl
= ts78xx_ts_nand_cmd_ctrl
,
233 .dev_ready
= ts78xx_ts_nand_dev_ready
,
237 static struct resource ts78xx_ts_nand_resources
= {
238 .start
= TS_NAND_DATA
,
239 .end
= TS_NAND_DATA
+ 4,
240 .flags
= IORESOURCE_IO
,
243 static struct platform_device ts78xx_ts_nand_device
= {
247 .platform_data
= &ts78xx_ts_nand_data
,
249 .resource
= &ts78xx_ts_nand_resources
,
253 static int ts78xx_ts_nand_load(void)
257 if (ts78xx_fpga
.supports
.ts_nand
.init
== 0) {
258 rc
= platform_device_register(&ts78xx_ts_nand_device
);
260 ts78xx_fpga
.supports
.ts_nand
.init
= 1;
262 rc
= platform_device_add(&ts78xx_ts_nand_device
);
267 static void ts78xx_ts_nand_unload(void)
269 platform_device_del(&ts78xx_ts_nand_device
);
272 /*****************************************************************************
273 * FPGA 'hotplug' support code
274 ****************************************************************************/
275 static void ts78xx_fpga_devices_zero_init(void)
277 ts78xx_fpga
.supports
.ts_rtc
.init
= 0;
278 ts78xx_fpga
.supports
.ts_nand
.init
= 0;
281 static void ts78xx_fpga_supports(void)
283 /* TODO: put this 'table' into ts78xx-fpga.h */
284 switch (ts78xx_fpga
.id
) {
290 ts78xx_fpga
.supports
.ts_rtc
.present
= 1;
291 ts78xx_fpga
.supports
.ts_nand
.present
= 1;
294 ts78xx_fpga
.supports
.ts_rtc
.present
= 0;
295 ts78xx_fpga
.supports
.ts_nand
.present
= 0;
299 static int ts78xx_fpga_load_devices(void)
303 if (ts78xx_fpga
.supports
.ts_rtc
.present
== 1) {
304 tmp
= ts78xx_ts_rtc_load();
306 printk(KERN_INFO
"TS-78xx: RTC not registered\n");
307 ts78xx_fpga
.supports
.ts_rtc
.present
= 0;
311 if (ts78xx_fpga
.supports
.ts_nand
.present
== 1) {
312 tmp
= ts78xx_ts_nand_load();
314 printk(KERN_INFO
"TS-78xx: NAND not registered\n");
315 ts78xx_fpga
.supports
.ts_nand
.present
= 0;
323 static int ts78xx_fpga_unload_devices(void)
327 if (ts78xx_fpga
.supports
.ts_rtc
.present
== 1)
328 ts78xx_ts_rtc_unload();
329 if (ts78xx_fpga
.supports
.ts_nand
.present
== 1)
330 ts78xx_ts_nand_unload();
335 static int ts78xx_fpga_load(void)
337 ts78xx_fpga
.id
= readl(TS78XX_FPGA_REGS_VIRT_BASE
);
339 printk(KERN_INFO
"TS-78xx FPGA: magic=0x%.6x, rev=0x%.2x\n",
340 (ts78xx_fpga
.id
>> 8) & 0xffffff,
341 ts78xx_fpga
.id
& 0xff);
343 ts78xx_fpga_supports();
345 if (ts78xx_fpga_load_devices()) {
346 ts78xx_fpga
.state
= -1;
353 static int ts78xx_fpga_unload(void)
355 unsigned int fpga_id
;
357 fpga_id
= readl(TS78XX_FPGA_REGS_VIRT_BASE
);
360 * There does not seem to be a feasible way to block access to the GPIO
361 * pins from userspace (/dev/mem). This if clause should hopefully warn
362 * those foolish enough not to follow 'policy' :)
364 * UrJTAG SVN since r1381 can be used to reprogram the FPGA
366 if (ts78xx_fpga
.id
!= fpga_id
) {
367 printk(KERN_ERR
"TS-78xx FPGA: magic/rev mismatch\n"
368 "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n",
369 (ts78xx_fpga
.id
>> 8) & 0xffffff, ts78xx_fpga
.id
& 0xff,
370 (fpga_id
>> 8) & 0xffffff, fpga_id
& 0xff);
371 ts78xx_fpga
.state
= -1;
375 if (ts78xx_fpga_unload_devices()) {
376 ts78xx_fpga
.state
= -1;
383 static ssize_t
ts78xx_fpga_show(struct kobject
*kobj
,
384 struct kobj_attribute
*attr
, char *buf
)
386 if (ts78xx_fpga
.state
< 0)
387 return sprintf(buf
, "borked\n");
389 return sprintf(buf
, "%s\n", (ts78xx_fpga
.state
) ? "online" : "offline");
392 static ssize_t
ts78xx_fpga_store(struct kobject
*kobj
,
393 struct kobj_attribute
*attr
, const char *buf
, size_t n
)
397 if (ts78xx_fpga
.state
< 0) {
398 printk(KERN_ERR
"TS-78xx FPGA: borked, you must powercycle asap\n");
402 if (strncmp(buf
, "online", sizeof("online") - 1) == 0)
404 else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
407 printk(KERN_ERR
"ts78xx_fpga_store: Invalid value\n");
411 if (ts78xx_fpga
.state
== value
)
414 ret
= (ts78xx_fpga
.state
== 0)
416 : ts78xx_fpga_unload();
419 ts78xx_fpga
.state
= value
;
424 static struct kobj_attribute ts78xx_fpga_attr
=
425 __ATTR(ts78xx_fpga
, 0644, ts78xx_fpga_show
, ts78xx_fpga_store
);
427 /*****************************************************************************
429 ****************************************************************************/
430 static struct orion5x_mpp_mode ts78xx_mpp_modes
[] __initdata
= {
432 { 1, MPP_GPIO
}, /* JTAG Clock */
433 { 2, MPP_GPIO
}, /* JTAG Data In */
434 { 3, MPP_GPIO
}, /* Lat ECP2 256 FPGA - PB2B */
435 { 4, MPP_GPIO
}, /* JTAG Data Out */
436 { 5, MPP_GPIO
}, /* JTAG TMS */
437 { 6, MPP_GPIO
}, /* Lat ECP2 256 FPGA - PB31A_CLK4+ */
438 { 7, MPP_GPIO
}, /* Lat ECP2 256 FPGA - PB22B */
452 * MPP[20] PCI Clock Out 1
453 * MPP[21] PCI Clock Out 0
462 static void __init
ts78xx_init(void)
467 * Setup basic Orion functions. Need to be called early.
471 orion5x_mpp_conf(ts78xx_mpp_modes
);
474 * Configure peripherals.
476 orion5x_ehci0_init();
477 orion5x_ehci1_init();
478 orion5x_eth_init(&ts78xx_eth_data
);
479 orion5x_sata_init(&ts78xx_sata_data
);
480 orion5x_uart0_init();
481 orion5x_uart1_init();
485 ts78xx_fpga_devices_zero_init();
486 ret
= ts78xx_fpga_load();
487 ret
= sysfs_create_file(power_kobj
, &ts78xx_fpga_attr
.attr
);
489 printk(KERN_ERR
"sysfs_create_file failed: %d\n", ret
);
492 MACHINE_START(TS78XX
, "Technologic Systems TS-78xx SBC")
493 /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */
494 .phys_io
= ORION5X_REGS_PHYS_BASE
,
495 .io_pg_offst
= ((ORION5X_REGS_VIRT_BASE
) >> 18) & 0xFFFC,
496 .boot_params
= 0x00000100,
497 .init_machine
= ts78xx_init
,
498 .map_io
= ts78xx_map_io
,
499 .init_irq
= orion5x_init_irq
,
500 .timer
= &orion5x_timer
,