blob: 652813cd6c2d47f0dbb92113f912fd2cde2bf7ab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +00002 * $Id: dbox2-flash.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * D-Box 2 flash driver
5 */
6
7#include <linux/module.h>
8#include <linux/types.h>
9#include <linux/kernel.h>
10#include <linux/init.h>
11#include <asm/io.h>
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/map.h>
14#include <linux/mtd/partitions.h>
15#include <linux/config.h>
16#include <linux/errno.h>
17
18/* partition_info gives details on the logical partitions that the split the
19 * single flash device into. If the size if zero we use up to the end of the
20 * device. */
21static struct mtd_partition partition_info[]= {
22 {
23 .name = "BR bootloader",
Thomas Gleixner69f34c92005-11-07 11:15:40 +000024 .size = 128 * 1024,
25 .offset = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 .mask_flags = MTD_WRITEABLE
27 },
28 {
29 .name = "FLFS (U-Boot)",
Thomas Gleixner69f34c92005-11-07 11:15:40 +000030 .size = 128 * 1024,
31 .offset = MTDPART_OFS_APPEND,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 .mask_flags = 0
33 },
34 {
Thomas Gleixner69f34c92005-11-07 11:15:40 +000035 .name = "Root (SquashFS)",
36 .size = 7040 * 1024,
37 .offset = MTDPART_OFS_APPEND,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 .mask_flags = 0
39 },
40 {
41 .name = "var (JFFS2)",
Thomas Gleixner69f34c92005-11-07 11:15:40 +000042 .size = 896 * 1024,
43 .offset = MTDPART_OFS_APPEND,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .mask_flags = 0
45 },
46 {
Thomas Gleixner69f34c92005-11-07 11:15:40 +000047 .name = "Flash without bootloader",
48 .size = MTDPART_SIZ_FULL,
49 .offset = 128 * 1024,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 .mask_flags = 0
51 },
52 {
Thomas Gleixner69f34c92005-11-07 11:15:40 +000053 .name = "Complete Flash",
54 .size = MTDPART_SIZ_FULL,
55 .offset = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .mask_flags = MTD_WRITEABLE
57 }
58};
59
Tobias Klauser87d10f32006-03-31 02:29:45 -080060#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#define WINDOW_ADDR 0x10000000
63#define WINDOW_SIZE 0x800000
64
65static struct mtd_info *mymtd;
66
67
68struct map_info dbox2_flash_map = {
69 .name = "D-Box 2 flash memory",
70 .size = WINDOW_SIZE,
71 .bankwidth = 4,
72 .phys = WINDOW_ADDR,
73};
74
75int __init init_dbox2_flash(void)
76{
77 printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR);
78 dbox2_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
79
80 if (!dbox2_flash_map.virt) {
81 printk("Failed to ioremap\n");
82 return -EIO;
83 }
84 simple_map_init(&dbox2_flash_map);
85
86 // Probe for dual Intel 28F320 or dual AMD
87 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
88 if (!mymtd) {
89 // Probe for single Intel 28F640
90 dbox2_flash_map.bankwidth = 2;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
93 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if (mymtd) {
96 mymtd->owner = THIS_MODULE;
97
98 /* Create MTD devices for each partition. */
99 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return 0;
102 }
103
104 iounmap((void *)dbox2_flash_map.virt);
105 return -ENXIO;
106}
107
108static void __exit cleanup_dbox2_flash(void)
109{
110 if (mymtd) {
111 del_mtd_partitions(mymtd);
112 map_destroy(mymtd);
113 }
114 if (dbox2_flash_map.virt) {
115 iounmap((void *)dbox2_flash_map.virt);
116 dbox2_flash_map.virt = 0;
117 }
118}
119
120module_init(init_dbox2_flash);
121module_exit(cleanup_dbox2_flash);
122
123
124MODULE_LICENSE("GPL");
125MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>");
126MODULE_DESCRIPTION("MTD map driver for D-Box 2 board");