xref: /openbmc/linux/drivers/mtd/maps/ts5500_flash.c (revision 20e2fc42)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * ts5500_flash.c -- MTD map driver for Technology Systems TS-5500 board
4  *
5  * Copyright (C) 2004 Sean Young <sean@mess.org>
6  *
7  * Note:
8  * - In order for detection to work, jumper 3 must be set.
9  * - Drive A and B use the resident flash disk (RFD) flash translation layer.
10  * - If you have created your own jffs file system and the bios overwrites
11  *   it during boot, try disabling Drive A: and B: in the boot order.
12  */
13 
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/types.h>
21 
22 
23 #define WINDOW_ADDR	0x09400000
24 #define WINDOW_SIZE	0x00200000
25 
26 static struct map_info ts5500_map = {
27 	.name = "TS-5500 Flash",
28 	.size = WINDOW_SIZE,
29 	.bankwidth = 1,
30 	.phys = WINDOW_ADDR
31 };
32 
33 static const struct mtd_partition ts5500_partitions[] = {
34 	{
35 		.name = "Drive A",
36 		.offset = 0,
37 		.size = 0x0e0000
38 	},
39 	{
40 		.name = "BIOS",
41 		.offset = 0x0e0000,
42 		.size = 0x020000,
43 	},
44 	{
45 		.name = "Drive B",
46 		.offset = 0x100000,
47 		.size = 0x100000
48 	}
49 };
50 
51 #define NUM_PARTITIONS ARRAY_SIZE(ts5500_partitions)
52 
53 static struct mtd_info *mymtd;
54 
55 static int __init init_ts5500_map(void)
56 {
57 	int rc = 0;
58 
59 	ts5500_map.virt = ioremap_nocache(ts5500_map.phys, ts5500_map.size);
60 
61 	if (!ts5500_map.virt) {
62 		printk(KERN_ERR "Failed to ioremap_nocache\n");
63 		rc = -EIO;
64 		goto err2;
65 	}
66 
67 	simple_map_init(&ts5500_map);
68 
69 	mymtd = do_map_probe("jedec_probe", &ts5500_map);
70 	if (!mymtd)
71 		mymtd = do_map_probe("map_rom", &ts5500_map);
72 
73 	if (!mymtd) {
74 		rc = -ENXIO;
75 		goto err1;
76 	}
77 
78 	mymtd->owner = THIS_MODULE;
79 	mtd_device_register(mymtd, ts5500_partitions, NUM_PARTITIONS);
80 
81 	return 0;
82 
83 err1:
84 	iounmap(ts5500_map.virt);
85 err2:
86 	return rc;
87 }
88 
89 static void __exit cleanup_ts5500_map(void)
90 {
91 	if (mymtd) {
92 		mtd_device_unregister(mymtd);
93 		map_destroy(mymtd);
94 	}
95 
96 	if (ts5500_map.virt) {
97 		iounmap(ts5500_map.virt);
98 		ts5500_map.virt = NULL;
99 	}
100 }
101 
102 module_init(init_ts5500_map);
103 module_exit(cleanup_ts5500_map);
104 
105 MODULE_LICENSE("GPL");
106 MODULE_AUTHOR("Sean Young <sean@mess.org>");
107 MODULE_DESCRIPTION("MTD map driver for Technology Systems TS-5500 board");
108 
109