11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/kernel.h>
38 #define TS78XX_FPGA_REGS_PHYS_BASE 0xe8000000
39 #define TS78XX_FPGA_REGS_VIRT_BASE IOMEM(0xff900000)
40 #define TS78XX_FPGA_REGS_SIZE SZ_1M
83 #define TS_RTC_CTRL (TS78XX_FPGA_REGS_VIRT_BASE + 0x808)
84 #define TS_RTC_DATA (TS78XX_FPGA_REGS_VIRT_BASE + 0x80c)
86 static unsigned char ts78xx_ts_rtc_readbyte(
unsigned long addr)
92 static void ts78xx_ts_rtc_writebyte(
unsigned char value,
unsigned long addr)
99 .readbyte = ts78xx_ts_rtc_readbyte,
100 .writebyte = ts78xx_ts_rtc_writebyte,
104 .name =
"rtc-m48t86",
107 .platform_data = &ts78xx_ts_rtc_ops,
122 static int ts78xx_ts_rtc_load(
void)
125 unsigned char tmp_rtc0, tmp_rtc1;
127 tmp_rtc0 = ts78xx_ts_rtc_readbyte(126);
128 tmp_rtc1 = ts78xx_ts_rtc_readbyte(127);
130 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);
139 if (ts78xx_fpga.
supports.ts_rtc.init == 0) {
142 ts78xx_fpga.
supports.ts_rtc.init = 1;
147 pr_info(
"RTC could not be registered: %d\n",
157 static void ts78xx_ts_rtc_unload(
void)
165 #define TS_NAND_CTRL (TS78XX_FPGA_REGS_VIRT_BASE + 0x800)
166 #define TS_NAND_DATA (TS78XX_FPGA_REGS_PHYS_BASE + 0x804)
176 static void ts78xx_ts_nand_cmd_ctrl(
struct mtd_info *mtd,
int cmd,
195 static int ts78xx_ts_nand_dev_ready(
struct mtd_info *mtd)
200 static void ts78xx_ts_nand_write_buf(
struct mtd_info *mtd,
205 unsigned long off = ((
unsigned long)buf & 3);
209 sz =
min_t(
int, 4 - off, len);
227 static void ts78xx_ts_nand_read_buf(
struct mtd_info *mtd,
232 unsigned long off = ((
unsigned long)buf & 3);
236 sz =
min_t(
int, 4 - off, len);
245 readsl(io_base, buf32, sz);
251 readsb(io_base, buf, len);
278 .partitions = ts78xx_ts_nand_parts,
279 .nr_partitions =
ARRAY_SIZE(ts78xx_ts_nand_parts),
291 .cmd_ctrl = ts78xx_ts_nand_cmd_ctrl,
292 .dev_ready = ts78xx_ts_nand_dev_ready,
293 .write_buf = ts78xx_ts_nand_write_buf,
294 .read_buf = ts78xx_ts_nand_read_buf,
298 static struct resource ts78xx_ts_nand_resources
305 .platform_data = &ts78xx_ts_nand_data,
307 .resource = &ts78xx_ts_nand_resources,
311 static int ts78xx_ts_nand_load(
void)
315 if (ts78xx_fpga.
supports.ts_nand.init == 0) {
318 ts78xx_fpga.
supports.ts_nand.init = 1;
323 pr_info(
"NAND could not be registered: %d\n", rc);
327 static void ts78xx_ts_nand_unload(
void)
335 #define TS_RNG_DATA (TS78XX_FPGA_REGS_PHYS_BASE | 0x044)
337 static struct resource ts78xx_ts_rng_resource
345 .name =
"timeriomem_rng",
348 .platform_data = &ts78xx_ts_rng_data,
350 .resource = &ts78xx_ts_rng_resource,
354 static int ts78xx_ts_rng_load(
void)
358 if (ts78xx_fpga.
supports.ts_rng.init == 0) {
361 ts78xx_fpga.
supports.ts_rng.init = 1;
366 pr_info(
"RNG could not be registered: %d\n", rc);
370 static void ts78xx_ts_rng_unload(
void)
378 static void ts78xx_fpga_devices_zero_init(
void)
380 ts78xx_fpga.
supports.ts_rtc.init = 0;
381 ts78xx_fpga.
supports.ts_nand.init = 0;
382 ts78xx_fpga.
supports.ts_rng.init = 0;
385 static void ts78xx_fpga_supports(
void)
388 switch (ts78xx_fpga.
id) {
398 ts78xx_fpga.
supports.ts_rtc.present = 1;
399 ts78xx_fpga.
supports.ts_nand.present = 1;
400 ts78xx_fpga.
supports.ts_rng.present = 1;
404 switch ((ts78xx_fpga.
id >> 8) & 0xffffff) {
406 pr_warning(
"unrecognised FPGA revision 0x%.2x\n",
407 ts78xx_fpga.
id & 0xff);
408 ts78xx_fpga.
supports.ts_rtc.present = 1;
409 ts78xx_fpga.
supports.ts_nand.present = 1;
410 ts78xx_fpga.
supports.ts_rng.present = 1;
413 ts78xx_fpga.
supports.ts_rtc.present = 0;
414 ts78xx_fpga.
supports.ts_nand.present = 0;
415 ts78xx_fpga.
supports.ts_rng.present = 0;
420 static int ts78xx_fpga_load_devices(
void)
424 if (ts78xx_fpga.
supports.ts_rtc.present == 1) {
425 tmp = ts78xx_ts_rtc_load();
427 ts78xx_fpga.
supports.ts_rtc.present = 0;
430 if (ts78xx_fpga.
supports.ts_nand.present == 1) {
431 tmp = ts78xx_ts_nand_load();
433 ts78xx_fpga.
supports.ts_nand.present = 0;
436 if (ts78xx_fpga.
supports.ts_rng.present == 1) {
437 tmp = ts78xx_ts_rng_load();
439 ts78xx_fpga.
supports.ts_rng.present = 0;
446 static int ts78xx_fpga_unload_devices(
void)
450 if (ts78xx_fpga.
supports.ts_rtc.present == 1)
451 ts78xx_ts_rtc_unload();
452 if (ts78xx_fpga.
supports.ts_nand.present == 1)
453 ts78xx_ts_nand_unload();
454 if (ts78xx_fpga.
supports.ts_rng.present == 1)
455 ts78xx_ts_rng_unload();
460 static int ts78xx_fpga_load(
void)
464 pr_info(
"FPGA magic=0x%.6x, rev=0x%.2x\n",
465 (ts78xx_fpga.
id >> 8) & 0xffffff,
466 ts78xx_fpga.
id & 0xff);
468 ts78xx_fpga_supports();
470 if (ts78xx_fpga_load_devices()) {
471 ts78xx_fpga.
state = -1;
478 static int ts78xx_fpga_unload(
void)
480 unsigned int fpga_id;
491 if (ts78xx_fpga.
id != fpga_id) {
492 pr_err(
"FPGA magic/rev mismatch\n"
493 "TS-78xx FPGA: was 0x%.6x/%.2x but now 0x%.6x/%.2x\n",
494 (ts78xx_fpga.
id >> 8) & 0xffffff, ts78xx_fpga.
id & 0xff,
495 (fpga_id >> 8) & 0xffffff, fpga_id & 0xff);
496 ts78xx_fpga.
state = -1;
500 if (ts78xx_fpga_unload_devices()) {
501 ts78xx_fpga.
state = -1;
511 if (ts78xx_fpga.
state < 0)
512 return sprintf(buf,
"borked\n");
514 return sprintf(buf,
"%s\n", (ts78xx_fpga.
state) ?
"online" :
"offline");
522 if (ts78xx_fpga.
state < 0) {
523 pr_err(
"FPGA borked, you must powercycle ASAP\n");
527 if (
strncmp(buf,
"online",
sizeof(
"online") - 1) == 0)
529 else if (
strncmp(buf,
"offline",
sizeof(
"offline") - 1) == 0)
534 if (ts78xx_fpga.
state == value)
537 ret = (ts78xx_fpga.
state == 0)
539 : ts78xx_fpga_unload();
548 __ATTR(ts78xx_fpga, 0644, ts78xx_fpga_show, ts78xx_fpga_store);
553 static unsigned int ts78xx_mpp_modes[] __initdata = {
585 static void __init ts78xx_init(
void)
608 ts78xx_fpga_devices_zero_init();
609 ret = ts78xx_fpga_load();
612 pr_err(
"sysfs_create_file failed: %d\n", ret);
617 .atag_offset = 0x100,
618 .init_machine = ts78xx_init,