code style scripts/checkpatch.pl (linux-3.9-rc1) formatting
[linux-2.6.32.60-moxart.git] / drivers / mtd / maps / uc7112lx.c
blob5cbda8672cc9fc7bffa3c70ca90d75e970f110f9
1 /* UC-7112-LX flash mapping driver
2 * Copyright (C) 2013 Jonas Jensen <jonas.jensen@gmail.com>
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2 of the License,
6 * or (at your option) any later version. */
8 #include <mach/hardware.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/io.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
21 #define RW_PART0_OF 0x0
23 /* bootloader for MOXART CPU */
24 #define RW_PART0_SZ 0x40000
26 #define RW_PART1_OF (RW_PART0_OF+RW_PART0_SZ)
27 #define RW_PART1_SZ (0x200000-RW_PART0_SZ) /* kernel */
29 #define RW_PART2_OF (RW_PART1_OF+RW_PART1_SZ)
30 #define RW_PART2_SZ 0x800000 /* root fs */
32 #define RW_PART3_OF (RW_PART2_OF+RW_PART2_SZ)
33 #define RW_PART3_SZ 0x600000 /* user fs */
35 #define CONFIG_FLASH_MEM_BASE 0x80000000
36 #define CONFIG_FLASH_SIZE 0x01000000
38 static struct map_info moxart_flash_map = {
39 .name = "UC-7112-LX-PLUS",
40 .bankwidth = 2,
41 .phys = CONFIG_FLASH_MEM_BASE,
42 .size = CONFIG_FLASH_SIZE,
43 .virt = (void __iomem *)IO_ADDRESS(CONFIG_FLASH_MEM_BASE),
45 /* MTD: Unable to init map for flash */
46 /* .virt = 0xf4000000, */
50 static struct mtd_partition moxart_flash_partitions[] = {
52 .name = "Bootloader",
53 .offset = RW_PART0_OF,
54 .size = RW_PART0_SZ
57 .name = "LinuxKernel",
58 .offset = RW_PART1_OF,
59 .size = RW_PART1_SZ,
60 /* .mask_flags = MTD_WRITEABLE */
63 .name = "RootFileSystem",
64 .offset = RW_PART2_OF,
65 .size = RW_PART2_SZ,
66 /* .mask_flags = MTD_WRITEABLE */
69 .name = "UserDisk",
70 .offset = RW_PART3_OF,
71 .size = RW_PART3_SZ
75 /*struct map_info moxart_flash_map = {
76 .name = "UC7110LX V2 FLASH",
77 .size = CONFIG_FLASH_SIZE,
78 .bankwidth = 2,
79 .phys = CONFIG_FLASH_MEM_BASE,
80 .virt = IO_ADDRESS(CONFIG_FLASH_MEM_BASE),
83 static int mtd_reboot(struct notifier_block *n, unsigned long code, void *p)
85 if(code != SYS_RESTART)
86 return NOTIFY_DONE;
88 *( u16 *)(IO_ADDRESS(CONFIG_FLASH_MEM_BASE) + (0x55 * 2)) = 0xb0;
89 *( u16 *)(IO_ADDRESS(CONFIG_FLASH_MEM_BASE) + (0x55 * 2)) = 0xff;
90 return NOTIFY_DONE;
93 static struct notifier_block mtd_notifier = {
94 notifier_call: mtd_reboot,
95 next: NULL,
96 priority: 0
97 };*/
99 static struct mtd_info *moxart_mtd;
101 int __init init_flash(void)
103 pr_notice(
104 "MTD: MOXART flash: %d-bit bus, mapping: 0x%x at 0x%x\n",
105 moxart_flash_map.bankwidth*8,
106 CONFIG_FLASH_SIZE, CONFIG_FLASH_MEM_BASE);
107 simple_map_init(&moxart_flash_map);
109 moxart_mtd = do_map_probe("cfi_probe", &moxart_flash_map);
110 if (moxart_mtd) {
111 moxart_mtd->owner = THIS_MODULE;
112 pr_notice("MTD: Using static partition definition\n");
113 add_mtd_partitions(moxart_mtd, moxart_flash_partitions,
114 ARRAY_SIZE(moxart_flash_partitions));
115 } else {
116 pr_err("MTD: map probe failed for flash\n");
117 iounmap(moxart_flash_map.virt);
118 return -ENXIO;
121 /* return -ENXIO; */
122 return 0;
125 int __init init_moxart_flash(void)
127 int status;
129 status = init_flash();
130 if (status)
131 pr_err("MTD: Unable to init map for flash\n");
132 /*else
133 register_reboot_notifier(&mtd_notifier); */
134 return status;
138 static void __exit cleanup_moxart_flash(void)
140 if (moxart_mtd) {
141 /* unregister_reboot_notifier(&mtd_notifier); */
142 del_mtd_partitions(moxart_mtd);
143 map_destroy(moxart_mtd);
147 module_init(init_moxart_flash);
148 module_exit(cleanup_moxart_flash);
150 MODULE_LICENSE("GPL");
151 MODULE_AUTHOR("Jonas Jensen");
152 MODULE_DESCRIPTION("MTD map driver for UC-7112-LX");