ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / lasat.c
1 /*
2  * Flash device on lasat 100 and 200 boards
3  *
4  * Presumably (C) 2002 Brian Murphy <brian@murphy.dk> or whoever he
5  * works for.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version
9  * 2 as published by the Free Software Foundation.
10  *
11  * $Id: lasat.c,v 1.5 2003/05/21 12:45:19 dwmw2 Exp $
12  *
13  */
14
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <asm/io.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/config.h>
24 #include <asm/lasat/lasat.h>
25 #include <asm/lasat/lasat_mtd.h>
26
27 static struct mtd_info *mymtd;
28
29 static struct map_info sp_map = {
30         .name = "SP flash",
31         .buswidth = 4,
32 };
33
34 static struct mtd_partition partition_info[LASAT_MTD_LAST];
35 static char *lasat_mtd_partnames[] = {"Bootloader", "Service", "Normal", "Filesystem", "Config"};
36
37 static int __init init_sp(void)
38 {
39         int i;
40         /* this does not play well with the old flash code which 
41          * protects and uprotects the flash when necessary */
42         /* FIXME: Implement set_vpp() */
43         printk(KERN_NOTICE "Unprotecting flash\n");
44         *lasat_misc->flash_wp_reg |= 1 << lasat_misc->flash_wp_bit;
45
46         sp_map.virt = lasat_flash_partition_start(LASAT_MTD_BOOTLOADER);
47         sp_map.phys = virt_to_phys(sp_map.virt);
48         sp_map.size = lasat_board_info.li_flash_size;
49
50         simple_map_init(&sp_map);
51
52         printk(KERN_NOTICE "sp flash device: %lx at %lx\n", 
53                         sp_map.size, sp_map.phys);
54
55         for (i=0; i < LASAT_MTD_LAST; i++)
56                 partition_info[i].name = lasat_mtd_partnames[i];
57
58         mymtd = do_map_probe("cfi_probe", &sp_map);
59         if (mymtd) {
60                 u32 size, offset = 0;
61
62                 mymtd->owner = THIS_MODULE;
63
64                 for (i=0; i < LASAT_MTD_LAST; i++) {
65                         size = lasat_flash_partition_size(i);
66                         partition_info[i].size = size;
67                         partition_info[i].offset = offset;
68                         offset += size;
69                 }
70
71                 add_mtd_partitions( mymtd, partition_info, LASAT_MTD_LAST );
72                 return 0;
73         }
74
75         return -ENXIO;
76 }
77
78 static void __exit cleanup_sp(void)
79 {
80         if (mymtd) {
81                 del_mtd_partitions(mymtd);
82                 map_destroy(mymtd);
83         }
84         if (sp_map.virt) {
85                 sp_map.virt = 0;
86         }
87 }
88
89 module_init(init_sp);
90 module_exit(cleanup_sp);
91
92 MODULE_LICENSE("GPL");
93 MODULE_AUTHOR("Brian Murphy <brian@murphy.dk>");
94 MODULE_DESCRIPTION("Lasat Safepipe/Masquerade MTD map driver");