1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * arch/arm/mach-orion5x/ts78xx-setup.c
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Maintainer: Alexander Clouter <alex@digriz.org.uk>
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This file is licensed under the terms of the GNU General Public
7*4882a593Smuzhiyun * License version 2. This program is licensed "as is" without any
8*4882a593Smuzhiyun * warranty of any kind, whether express or implied.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/init.h>
15*4882a593Smuzhiyun #include <linux/sysfs.h>
16*4882a593Smuzhiyun #include <linux/platform_device.h>
17*4882a593Smuzhiyun #include <linux/mv643xx_eth.h>
18*4882a593Smuzhiyun #include <linux/ata_platform.h>
19*4882a593Smuzhiyun #include <linux/mtd/platnand.h>
20*4882a593Smuzhiyun #include <linux/timeriomem-rng.h>
21*4882a593Smuzhiyun #include <asm/mach-types.h>
22*4882a593Smuzhiyun #include <asm/mach/arch.h>
23*4882a593Smuzhiyun #include <asm/mach/map.h>
24*4882a593Smuzhiyun #include "common.h"
25*4882a593Smuzhiyun #include "mpp.h"
26*4882a593Smuzhiyun #include "orion5x.h"
27*4882a593Smuzhiyun #include "ts78xx-fpga.h"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /*****************************************************************************
30*4882a593Smuzhiyun * TS-78xx Info
31*4882a593Smuzhiyun ****************************************************************************/
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE
35*4882a593Smuzhiyun */
36*4882a593Smuzhiyun #define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000
37*4882a593Smuzhiyun #define TS78XX_FPGA_REGS_VIRT_BASE IOMEM(0xff900000)
38*4882a593Smuzhiyun #define TS78XX_FPGA_REGS_SIZE SZ_1M
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun static struct ts78xx_fpga_data ts78xx_fpga = {
41*4882a593Smuzhiyun .id = 0,
42*4882a593Smuzhiyun .state = 1,
43*4882a593Smuzhiyun /* .supports = ... - populated by ts78xx_fpga_supports() */
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /*****************************************************************************
47*4882a593Smuzhiyun * I/O Address Mapping
48*4882a593Smuzhiyun ****************************************************************************/
49*4882a593Smuzhiyun static struct map_desc ts78xx_io_desc[] __initdata = {
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun .virtual = (unsigned long)TS78XX_FPGA_REGS_VIRT_BASE,
52*4882a593Smuzhiyun .pfn = __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE),
53*4882a593Smuzhiyun .length = TS78XX_FPGA_REGS_SIZE,
54*4882a593Smuzhiyun .type = MT_DEVICE,
55*4882a593Smuzhiyun },
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun
ts78xx_map_io(void)58*4882a593Smuzhiyun static void __init ts78xx_map_io(void)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun orion5x_map_io();
61*4882a593Smuzhiyun iotable_init(ts78xx_io_desc, ARRAY_SIZE(ts78xx_io_desc));
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /*****************************************************************************
65*4882a593Smuzhiyun * Ethernet
66*4882a593Smuzhiyun ****************************************************************************/
67*4882a593Smuzhiyun static struct mv643xx_eth_platform_data ts78xx_eth_data = {
68*4882a593Smuzhiyun .phy_addr = MV643XX_ETH_PHY_ADDR(0),
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /*****************************************************************************
72*4882a593Smuzhiyun * SATA
73*4882a593Smuzhiyun ****************************************************************************/
74*4882a593Smuzhiyun static struct mv_sata_platform_data ts78xx_sata_data = {
75*4882a593Smuzhiyun .n_ports = 2,
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /*****************************************************************************
79*4882a593Smuzhiyun * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c
80*4882a593Smuzhiyun ****************************************************************************/
81*4882a593Smuzhiyun #define TS_RTC_CTRL (TS78XX_FPGA_REGS_PHYS_BASE + 0x808)
82*4882a593Smuzhiyun #define TS_RTC_DATA (TS78XX_FPGA_REGS_PHYS_BASE + 0x80c)
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun static struct resource ts78xx_ts_rtc_resources[] = {
85*4882a593Smuzhiyun DEFINE_RES_MEM(TS_RTC_CTRL, 0x01),
86*4882a593Smuzhiyun DEFINE_RES_MEM(TS_RTC_DATA, 0x01),
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun static struct platform_device ts78xx_ts_rtc_device = {
90*4882a593Smuzhiyun .name = "rtc-m48t86",
91*4882a593Smuzhiyun .id = -1,
92*4882a593Smuzhiyun .resource = ts78xx_ts_rtc_resources,
93*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(ts78xx_ts_rtc_resources),
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun
ts78xx_ts_rtc_load(void)96*4882a593Smuzhiyun static int ts78xx_ts_rtc_load(void)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun int rc;
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rtc.init == 0) {
101*4882a593Smuzhiyun rc = platform_device_register(&ts78xx_ts_rtc_device);
102*4882a593Smuzhiyun if (!rc)
103*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.init = 1;
104*4882a593Smuzhiyun } else {
105*4882a593Smuzhiyun rc = platform_device_add(&ts78xx_ts_rtc_device);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun if (rc)
109*4882a593Smuzhiyun pr_info("RTC could not be registered: %d\n", rc);
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun return rc;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
ts78xx_ts_rtc_unload(void)114*4882a593Smuzhiyun static void ts78xx_ts_rtc_unload(void)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun platform_device_del(&ts78xx_ts_rtc_device);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /*****************************************************************************
120*4882a593Smuzhiyun * NAND Flash
121*4882a593Smuzhiyun ****************************************************************************/
122*4882a593Smuzhiyun #define TS_NAND_CTRL (TS78XX_FPGA_REGS_VIRT_BASE + 0x800) /* VIRT */
123*4882a593Smuzhiyun #define TS_NAND_DATA (TS78XX_FPGA_REGS_PHYS_BASE + 0x804) /* PHYS */
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun * hardware specific access to control-lines
127*4882a593Smuzhiyun *
128*4882a593Smuzhiyun * ctrl:
129*4882a593Smuzhiyun * NAND_NCE: bit 0 -> bit 2
130*4882a593Smuzhiyun * NAND_CLE: bit 1 -> bit 1
131*4882a593Smuzhiyun * NAND_ALE: bit 2 -> bit 0
132*4882a593Smuzhiyun */
ts78xx_ts_nand_cmd_ctrl(struct nand_chip * this,int cmd,unsigned int ctrl)133*4882a593Smuzhiyun static void ts78xx_ts_nand_cmd_ctrl(struct nand_chip *this, int cmd,
134*4882a593Smuzhiyun unsigned int ctrl)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun if (ctrl & NAND_CTRL_CHANGE) {
137*4882a593Smuzhiyun unsigned char bits;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun bits = (ctrl & NAND_NCE) << 2;
140*4882a593Smuzhiyun bits |= ctrl & NAND_CLE;
141*4882a593Smuzhiyun bits |= (ctrl & NAND_ALE) >> 2;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun writeb((readb(TS_NAND_CTRL) & ~0x7) | bits, TS_NAND_CTRL);
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun if (cmd != NAND_CMD_NONE)
147*4882a593Smuzhiyun writeb(cmd, this->legacy.IO_ADDR_W);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun
ts78xx_ts_nand_dev_ready(struct nand_chip * chip)150*4882a593Smuzhiyun static int ts78xx_ts_nand_dev_ready(struct nand_chip *chip)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun return readb(TS_NAND_CTRL) & 0x20;
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
ts78xx_ts_nand_write_buf(struct nand_chip * chip,const uint8_t * buf,int len)155*4882a593Smuzhiyun static void ts78xx_ts_nand_write_buf(struct nand_chip *chip,
156*4882a593Smuzhiyun const uint8_t *buf, int len)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun void __iomem *io_base = chip->legacy.IO_ADDR_W;
159*4882a593Smuzhiyun unsigned long off = ((unsigned long)buf & 3);
160*4882a593Smuzhiyun int sz;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun if (off) {
163*4882a593Smuzhiyun sz = min_t(int, 4 - off, len);
164*4882a593Smuzhiyun writesb(io_base, buf, sz);
165*4882a593Smuzhiyun buf += sz;
166*4882a593Smuzhiyun len -= sz;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun sz = len >> 2;
170*4882a593Smuzhiyun if (sz) {
171*4882a593Smuzhiyun u32 *buf32 = (u32 *)buf;
172*4882a593Smuzhiyun writesl(io_base, buf32, sz);
173*4882a593Smuzhiyun buf += sz << 2;
174*4882a593Smuzhiyun len -= sz << 2;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun if (len)
178*4882a593Smuzhiyun writesb(io_base, buf, len);
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun
ts78xx_ts_nand_read_buf(struct nand_chip * chip,uint8_t * buf,int len)181*4882a593Smuzhiyun static void ts78xx_ts_nand_read_buf(struct nand_chip *chip,
182*4882a593Smuzhiyun uint8_t *buf, int len)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun void __iomem *io_base = chip->legacy.IO_ADDR_R;
185*4882a593Smuzhiyun unsigned long off = ((unsigned long)buf & 3);
186*4882a593Smuzhiyun int sz;
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun if (off) {
189*4882a593Smuzhiyun sz = min_t(int, 4 - off, len);
190*4882a593Smuzhiyun readsb(io_base, buf, sz);
191*4882a593Smuzhiyun buf += sz;
192*4882a593Smuzhiyun len -= sz;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun sz = len >> 2;
196*4882a593Smuzhiyun if (sz) {
197*4882a593Smuzhiyun u32 *buf32 = (u32 *)buf;
198*4882a593Smuzhiyun readsl(io_base, buf32, sz);
199*4882a593Smuzhiyun buf += sz << 2;
200*4882a593Smuzhiyun len -= sz << 2;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun if (len)
204*4882a593Smuzhiyun readsb(io_base, buf, len);
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun static struct mtd_partition ts78xx_ts_nand_parts[] = {
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun .name = "mbr",
210*4882a593Smuzhiyun .offset = 0,
211*4882a593Smuzhiyun .size = SZ_128K,
212*4882a593Smuzhiyun .mask_flags = MTD_WRITEABLE,
213*4882a593Smuzhiyun }, {
214*4882a593Smuzhiyun .name = "kernel",
215*4882a593Smuzhiyun .offset = MTDPART_OFS_APPEND,
216*4882a593Smuzhiyun .size = SZ_4M,
217*4882a593Smuzhiyun }, {
218*4882a593Smuzhiyun .name = "initrd",
219*4882a593Smuzhiyun .offset = MTDPART_OFS_APPEND,
220*4882a593Smuzhiyun .size = SZ_4M,
221*4882a593Smuzhiyun }, {
222*4882a593Smuzhiyun .name = "rootfs",
223*4882a593Smuzhiyun .offset = MTDPART_OFS_APPEND,
224*4882a593Smuzhiyun .size = MTDPART_SIZ_FULL,
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun };
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun static struct platform_nand_data ts78xx_ts_nand_data = {
229*4882a593Smuzhiyun .chip = {
230*4882a593Smuzhiyun .nr_chips = 1,
231*4882a593Smuzhiyun .partitions = ts78xx_ts_nand_parts,
232*4882a593Smuzhiyun .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts),
233*4882a593Smuzhiyun .chip_delay = 15,
234*4882a593Smuzhiyun .bbt_options = NAND_BBT_USE_FLASH,
235*4882a593Smuzhiyun },
236*4882a593Smuzhiyun .ctrl = {
237*4882a593Smuzhiyun /*
238*4882a593Smuzhiyun * The HW ECC offloading functions, used to give about a 9%
239*4882a593Smuzhiyun * performance increase for 'dd if=/dev/mtdblockX' and 5% for
240*4882a593Smuzhiyun * nanddump. This all however was changed by git commit
241*4882a593Smuzhiyun * e6cf5df1838c28bb060ac45b5585e48e71bbc740 so now there is
242*4882a593Smuzhiyun * no performance advantage to be had so we no longer bother
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun .cmd_ctrl = ts78xx_ts_nand_cmd_ctrl,
245*4882a593Smuzhiyun .dev_ready = ts78xx_ts_nand_dev_ready,
246*4882a593Smuzhiyun .write_buf = ts78xx_ts_nand_write_buf,
247*4882a593Smuzhiyun .read_buf = ts78xx_ts_nand_read_buf,
248*4882a593Smuzhiyun },
249*4882a593Smuzhiyun };
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun static struct resource ts78xx_ts_nand_resources
252*4882a593Smuzhiyun = DEFINE_RES_MEM(TS_NAND_DATA, 4);
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun static struct platform_device ts78xx_ts_nand_device = {
255*4882a593Smuzhiyun .name = "gen_nand",
256*4882a593Smuzhiyun .id = -1,
257*4882a593Smuzhiyun .dev = {
258*4882a593Smuzhiyun .platform_data = &ts78xx_ts_nand_data,
259*4882a593Smuzhiyun },
260*4882a593Smuzhiyun .resource = &ts78xx_ts_nand_resources,
261*4882a593Smuzhiyun .num_resources = 1,
262*4882a593Smuzhiyun };
263*4882a593Smuzhiyun
ts78xx_ts_nand_load(void)264*4882a593Smuzhiyun static int ts78xx_ts_nand_load(void)
265*4882a593Smuzhiyun {
266*4882a593Smuzhiyun int rc;
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_nand.init == 0) {
269*4882a593Smuzhiyun rc = platform_device_register(&ts78xx_ts_nand_device);
270*4882a593Smuzhiyun if (!rc)
271*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.init = 1;
272*4882a593Smuzhiyun } else
273*4882a593Smuzhiyun rc = platform_device_add(&ts78xx_ts_nand_device);
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun if (rc)
276*4882a593Smuzhiyun pr_info("NAND could not be registered: %d\n", rc);
277*4882a593Smuzhiyun return rc;
278*4882a593Smuzhiyun };
279*4882a593Smuzhiyun
ts78xx_ts_nand_unload(void)280*4882a593Smuzhiyun static void ts78xx_ts_nand_unload(void)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun platform_device_del(&ts78xx_ts_nand_device);
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /*****************************************************************************
286*4882a593Smuzhiyun * HW RNG
287*4882a593Smuzhiyun ****************************************************************************/
288*4882a593Smuzhiyun #define TS_RNG_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x044)
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun static struct resource ts78xx_ts_rng_resource
291*4882a593Smuzhiyun = DEFINE_RES_MEM(TS_RNG_DATA, 4);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun static struct timeriomem_rng_data ts78xx_ts_rng_data = {
294*4882a593Smuzhiyun .period = 1000000, /* one second */
295*4882a593Smuzhiyun };
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun static struct platform_device ts78xx_ts_rng_device = {
298*4882a593Smuzhiyun .name = "timeriomem_rng",
299*4882a593Smuzhiyun .id = -1,
300*4882a593Smuzhiyun .dev = {
301*4882a593Smuzhiyun .platform_data = &ts78xx_ts_rng_data,
302*4882a593Smuzhiyun },
303*4882a593Smuzhiyun .resource = &ts78xx_ts_rng_resource,
304*4882a593Smuzhiyun .num_resources = 1,
305*4882a593Smuzhiyun };
306*4882a593Smuzhiyun
ts78xx_ts_rng_load(void)307*4882a593Smuzhiyun static int ts78xx_ts_rng_load(void)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun int rc;
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rng.init == 0) {
312*4882a593Smuzhiyun rc = platform_device_register(&ts78xx_ts_rng_device);
313*4882a593Smuzhiyun if (!rc)
314*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.init = 1;
315*4882a593Smuzhiyun } else
316*4882a593Smuzhiyun rc = platform_device_add(&ts78xx_ts_rng_device);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun if (rc)
319*4882a593Smuzhiyun pr_info("RNG could not be registered: %d\n", rc);
320*4882a593Smuzhiyun return rc;
321*4882a593Smuzhiyun };
322*4882a593Smuzhiyun
ts78xx_ts_rng_unload(void)323*4882a593Smuzhiyun static void ts78xx_ts_rng_unload(void)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun platform_device_del(&ts78xx_ts_rng_device);
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun /*****************************************************************************
329*4882a593Smuzhiyun * FPGA 'hotplug' support code
330*4882a593Smuzhiyun ****************************************************************************/
ts78xx_fpga_devices_zero_init(void)331*4882a593Smuzhiyun static void ts78xx_fpga_devices_zero_init(void)
332*4882a593Smuzhiyun {
333*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.init = 0;
334*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.init = 0;
335*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.init = 0;
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun
ts78xx_fpga_supports(void)338*4882a593Smuzhiyun static void ts78xx_fpga_supports(void)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun /* TODO: put this 'table' into ts78xx-fpga.h */
341*4882a593Smuzhiyun switch (ts78xx_fpga.id) {
342*4882a593Smuzhiyun case TS7800_REV_1:
343*4882a593Smuzhiyun case TS7800_REV_2:
344*4882a593Smuzhiyun case TS7800_REV_3:
345*4882a593Smuzhiyun case TS7800_REV_4:
346*4882a593Smuzhiyun case TS7800_REV_5:
347*4882a593Smuzhiyun case TS7800_REV_6:
348*4882a593Smuzhiyun case TS7800_REV_7:
349*4882a593Smuzhiyun case TS7800_REV_8:
350*4882a593Smuzhiyun case TS7800_REV_9:
351*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.present = 1;
352*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.present = 1;
353*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.present = 1;
354*4882a593Smuzhiyun break;
355*4882a593Smuzhiyun default:
356*4882a593Smuzhiyun /* enable devices if magic matches */
357*4882a593Smuzhiyun switch ((ts78xx_fpga.id >> 8) & 0xffffff) {
358*4882a593Smuzhiyun case TS7800_FPGA_MAGIC:
359*4882a593Smuzhiyun pr_warn("unrecognised FPGA revision 0x%.2x\n",
360*4882a593Smuzhiyun ts78xx_fpga.id & 0xff);
361*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.present = 1;
362*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.present = 1;
363*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.present = 1;
364*4882a593Smuzhiyun break;
365*4882a593Smuzhiyun default:
366*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.present = 0;
367*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.present = 0;
368*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.present = 0;
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
ts78xx_fpga_load_devices(void)373*4882a593Smuzhiyun static int ts78xx_fpga_load_devices(void)
374*4882a593Smuzhiyun {
375*4882a593Smuzhiyun int tmp, ret = 0;
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rtc.present == 1) {
378*4882a593Smuzhiyun tmp = ts78xx_ts_rtc_load();
379*4882a593Smuzhiyun if (tmp)
380*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rtc.present = 0;
381*4882a593Smuzhiyun ret |= tmp;
382*4882a593Smuzhiyun }
383*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_nand.present == 1) {
384*4882a593Smuzhiyun tmp = ts78xx_ts_nand_load();
385*4882a593Smuzhiyun if (tmp)
386*4882a593Smuzhiyun ts78xx_fpga.supports.ts_nand.present = 0;
387*4882a593Smuzhiyun ret |= tmp;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rng.present == 1) {
390*4882a593Smuzhiyun tmp = ts78xx_ts_rng_load();
391*4882a593Smuzhiyun if (tmp)
392*4882a593Smuzhiyun ts78xx_fpga.supports.ts_rng.present = 0;
393*4882a593Smuzhiyun ret |= tmp;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun return ret;
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun
ts78xx_fpga_unload_devices(void)399*4882a593Smuzhiyun static int ts78xx_fpga_unload_devices(void)
400*4882a593Smuzhiyun {
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rtc.present == 1)
403*4882a593Smuzhiyun ts78xx_ts_rtc_unload();
404*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_nand.present == 1)
405*4882a593Smuzhiyun ts78xx_ts_nand_unload();
406*4882a593Smuzhiyun if (ts78xx_fpga.supports.ts_rng.present == 1)
407*4882a593Smuzhiyun ts78xx_ts_rng_unload();
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun return 0;
410*4882a593Smuzhiyun }
411*4882a593Smuzhiyun
ts78xx_fpga_load(void)412*4882a593Smuzhiyun static int ts78xx_fpga_load(void)
413*4882a593Smuzhiyun {
414*4882a593Smuzhiyun ts78xx_fpga.id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun pr_info("FPGA magic=0x%.6x, rev=0x%.2x\n",
417*4882a593Smuzhiyun (ts78xx_fpga.id >> 8) & 0xffffff,
418*4882a593Smuzhiyun ts78xx_fpga.id & 0xff);
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun ts78xx_fpga_supports();
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun if (ts78xx_fpga_load_devices()) {
423*4882a593Smuzhiyun ts78xx_fpga.state = -1;
424*4882a593Smuzhiyun return -EBUSY;
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun return 0;
428*4882a593Smuzhiyun };
429*4882a593Smuzhiyun
ts78xx_fpga_unload(void)430*4882a593Smuzhiyun static int ts78xx_fpga_unload(void)
431*4882a593Smuzhiyun {
432*4882a593Smuzhiyun unsigned int fpga_id;
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun fpga_id = readl(TS78XX_FPGA_REGS_VIRT_BASE);
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /*
437*4882a593Smuzhiyun * There does not seem to be a feasible way to block access to the GPIO
438*4882a593Smuzhiyun * pins from userspace (/dev/mem). This if clause should hopefully warn
439*4882a593Smuzhiyun * those foolish enough not to follow 'policy' :)
440*4882a593Smuzhiyun *
441*4882a593Smuzhiyun * UrJTAG SVN since r1381 can be used to reprogram the FPGA
442*4882a593Smuzhiyun */
443*4882a593Smuzhiyun if (ts78xx_fpga.id != fpga_id) {
444*4882a593Smuzhiyun pr_err("FPGA magic/rev mismatch\n"
445*4882a593Smuzhiyun "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n",
446*4882a593Smuzhiyun (ts78xx_fpga.id >> 8) & 0xffffff, ts78xx_fpga.id & 0xff,
447*4882a593Smuzhiyun (fpga_id >> 8) & 0xffffff, fpga_id & 0xff);
448*4882a593Smuzhiyun ts78xx_fpga.state = -1;
449*4882a593Smuzhiyun return -EBUSY;
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun if (ts78xx_fpga_unload_devices()) {
453*4882a593Smuzhiyun ts78xx_fpga.state = -1;
454*4882a593Smuzhiyun return -EBUSY;
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun return 0;
458*4882a593Smuzhiyun };
459*4882a593Smuzhiyun
ts78xx_fpga_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)460*4882a593Smuzhiyun static ssize_t ts78xx_fpga_show(struct kobject *kobj,
461*4882a593Smuzhiyun struct kobj_attribute *attr, char *buf)
462*4882a593Smuzhiyun {
463*4882a593Smuzhiyun if (ts78xx_fpga.state < 0)
464*4882a593Smuzhiyun return sprintf(buf, "borked\n");
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun return sprintf(buf, "%s\n", (ts78xx_fpga.state) ? "online" : "offline");
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun
ts78xx_fpga_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t n)469*4882a593Smuzhiyun static ssize_t ts78xx_fpga_store(struct kobject *kobj,
470*4882a593Smuzhiyun struct kobj_attribute *attr, const char *buf, size_t n)
471*4882a593Smuzhiyun {
472*4882a593Smuzhiyun int value, ret;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun if (ts78xx_fpga.state < 0) {
475*4882a593Smuzhiyun pr_err("FPGA borked, you must powercycle ASAP\n");
476*4882a593Smuzhiyun return -EBUSY;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun if (strncmp(buf, "online", sizeof("online") - 1) == 0)
480*4882a593Smuzhiyun value = 1;
481*4882a593Smuzhiyun else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
482*4882a593Smuzhiyun value = 0;
483*4882a593Smuzhiyun else
484*4882a593Smuzhiyun return -EINVAL;
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun if (ts78xx_fpga.state == value)
487*4882a593Smuzhiyun return n;
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun ret = (ts78xx_fpga.state == 0)
490*4882a593Smuzhiyun ? ts78xx_fpga_load()
491*4882a593Smuzhiyun : ts78xx_fpga_unload();
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun if (!(ret < 0))
494*4882a593Smuzhiyun ts78xx_fpga.state = value;
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun return n;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun static struct kobj_attribute ts78xx_fpga_attr =
500*4882a593Smuzhiyun __ATTR(ts78xx_fpga, 0644, ts78xx_fpga_show, ts78xx_fpga_store);
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun /*****************************************************************************
503*4882a593Smuzhiyun * General Setup
504*4882a593Smuzhiyun ****************************************************************************/
505*4882a593Smuzhiyun static unsigned int ts78xx_mpp_modes[] __initdata = {
506*4882a593Smuzhiyun MPP0_UNUSED,
507*4882a593Smuzhiyun MPP1_GPIO, /* JTAG Clock */
508*4882a593Smuzhiyun MPP2_GPIO, /* JTAG Data In */
509*4882a593Smuzhiyun MPP3_GPIO, /* Lat ECP2 256 FPGA - PB2B */
510*4882a593Smuzhiyun MPP4_GPIO, /* JTAG Data Out */
511*4882a593Smuzhiyun MPP5_GPIO, /* JTAG TMS */
512*4882a593Smuzhiyun MPP6_GPIO, /* Lat ECP2 256 FPGA - PB31A_CLK4+ */
513*4882a593Smuzhiyun MPP7_GPIO, /* Lat ECP2 256 FPGA - PB22B */
514*4882a593Smuzhiyun MPP8_UNUSED,
515*4882a593Smuzhiyun MPP9_UNUSED,
516*4882a593Smuzhiyun MPP10_UNUSED,
517*4882a593Smuzhiyun MPP11_UNUSED,
518*4882a593Smuzhiyun MPP12_UNUSED,
519*4882a593Smuzhiyun MPP13_UNUSED,
520*4882a593Smuzhiyun MPP14_UNUSED,
521*4882a593Smuzhiyun MPP15_UNUSED,
522*4882a593Smuzhiyun MPP16_UART,
523*4882a593Smuzhiyun MPP17_UART,
524*4882a593Smuzhiyun MPP18_UART,
525*4882a593Smuzhiyun MPP19_UART,
526*4882a593Smuzhiyun /*
527*4882a593Smuzhiyun * MPP[20] PCI Clock Out 1
528*4882a593Smuzhiyun * MPP[21] PCI Clock Out 0
529*4882a593Smuzhiyun * MPP[22] Unused
530*4882a593Smuzhiyun * MPP[23] Unused
531*4882a593Smuzhiyun * MPP[24] Unused
532*4882a593Smuzhiyun * MPP[25] Unused
533*4882a593Smuzhiyun */
534*4882a593Smuzhiyun 0,
535*4882a593Smuzhiyun };
536*4882a593Smuzhiyun
ts78xx_init(void)537*4882a593Smuzhiyun static void __init ts78xx_init(void)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun int ret;
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun /*
542*4882a593Smuzhiyun * Setup basic Orion functions. Need to be called early.
543*4882a593Smuzhiyun */
544*4882a593Smuzhiyun orion5x_init();
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun orion5x_mpp_conf(ts78xx_mpp_modes);
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun /*
549*4882a593Smuzhiyun * Configure peripherals.
550*4882a593Smuzhiyun */
551*4882a593Smuzhiyun orion5x_ehci0_init();
552*4882a593Smuzhiyun orion5x_ehci1_init();
553*4882a593Smuzhiyun orion5x_eth_init(&ts78xx_eth_data);
554*4882a593Smuzhiyun orion5x_sata_init(&ts78xx_sata_data);
555*4882a593Smuzhiyun orion5x_uart0_init();
556*4882a593Smuzhiyun orion5x_uart1_init();
557*4882a593Smuzhiyun orion5x_xor_init();
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun /* FPGA init */
560*4882a593Smuzhiyun ts78xx_fpga_devices_zero_init();
561*4882a593Smuzhiyun ret = ts78xx_fpga_load();
562*4882a593Smuzhiyun ret = sysfs_create_file(firmware_kobj, &ts78xx_fpga_attr.attr);
563*4882a593Smuzhiyun if (ret)
564*4882a593Smuzhiyun pr_err("sysfs_create_file failed: %d\n", ret);
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun MACHINE_START(TS78XX, "Technologic Systems TS-78xx SBC")
568*4882a593Smuzhiyun /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */
569*4882a593Smuzhiyun .atag_offset = 0x100,
570*4882a593Smuzhiyun .nr_irqs = ORION5X_NR_IRQS,
571*4882a593Smuzhiyun .init_machine = ts78xx_init,
572*4882a593Smuzhiyun .map_io = ts78xx_map_io,
573*4882a593Smuzhiyun .init_early = orion5x_init_early,
574*4882a593Smuzhiyun .init_irq = orion5x_init_irq,
575*4882a593Smuzhiyun .init_time = orion5x_timer_init,
576*4882a593Smuzhiyun .restart = orion5x_restart,
577*4882a593Smuzhiyun MACHINE_END
578