2 * Flash device on lasat 100 and 200 boards
4 * Presumably (C) 2002 Brian Murphy <brian@murphy.dk> or whoever he
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.
11 * $Id: lasat.c,v 1.1 2003/01/24 14:26:38 dwmw2 Exp $
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/map.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/config.h>
23 #include <asm/lasat/lasat.h>
24 #include <asm/lasat/lasat_mtd.h>
26 static struct mtd_info *mymtd;
28 static __u8 sp_read8(struct map_info *map, unsigned long ofs)
30 return __raw_readb(map->map_priv_1 + ofs);
33 static __u16 sp_read16(struct map_info *map, unsigned long ofs)
35 return __raw_readw(map->map_priv_1 + ofs);
38 static __u32 sp_read32(struct map_info *map, unsigned long ofs)
40 return __raw_readl(map->map_priv_1 + ofs);
43 static void sp_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
45 memcpy_fromio(to, map->map_priv_1 + from, len);
48 static void sp_write8(struct map_info *map, __u8 d, unsigned long adr)
50 __raw_writeb(d, map->map_priv_1 + adr);
54 static void sp_write16(struct map_info *map, __u16 d, unsigned long adr)
56 __raw_writew(d, map->map_priv_1 + adr);
60 static void sp_write32(struct map_info *map, __u32 d, unsigned long adr)
62 __raw_writel(d, map->map_priv_1 + adr);
66 static void sp_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
68 memcpy_toio(map->map_priv_1 + to, from, len);
71 static struct map_info sp_map = {
77 .copy_from = sp_copy_from,
79 .write16 = sp_write16,
80 .write32 = sp_write32,
84 static struct mtd_partition partition_info[LASAT_MTD_LAST];
85 static char *lasat_mtd_partnames[] = {"Bootloader", "Service", "Normal", "Filesystem", "Config"};
87 static int __init init_sp(void)
90 /* this does not play well with the old flash code which
91 * protects and uprotects the flash when necessary */
92 printk(KERN_NOTICE "Unprotecting flash\n");
93 *lasat_misc->flash_wp_reg |= 1 << lasat_misc->flash_wp_bit;
95 sp_map.map_priv_1 = lasat_flash_partition_start(LASAT_MTD_BOOTLOADER);
96 sp_map.size = lasat_board_info.li_flash_size;
98 printk(KERN_NOTICE "sp flash device: %lx at %lx\n",
99 sp_map.size, sp_map.map_priv_1);
101 for (i=0; i < LASAT_MTD_LAST; i++)
102 partition_info[i].name = lasat_mtd_partnames[i];
104 mymtd = do_map_probe("cfi_probe", &sp_map);
106 u32 size, offset = 0;
108 mymtd->module = THIS_MODULE;
110 for (i=0; i < LASAT_MTD_LAST; i++) {
111 size = lasat_flash_partition_size(i);
112 partition_info[i].size = size;
113 partition_info[i].offset = offset;
117 add_mtd_partitions( mymtd, partition_info, LASAT_MTD_LAST );
124 static void __exit cleanup_sp(void)
127 del_mtd_partitions(mymtd);
130 if (sp_map.map_priv_1) {
131 sp_map.map_priv_1 = 0;
135 module_init(init_sp);
136 module_exit(cleanup_sp);
138 MODULE_LICENSE("GPL");
139 MODULE_AUTHOR("Brian Murphy <brian@murphy.dk>");
140 MODULE_DESCRIPTION("Lasat Safepipe/Masquerade MTD map driver");