sbc_gxx.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
  2. SBC-GXm and SBC-GX1 series boards.
  3. Copyright (C) 2001 Arcom Control System Ltd
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  15. The SBC-MediaGX / SBC-GXx has up to 16 MiB of
  16. Intel StrataFlash (28F320/28F640) in x8 mode.
  17. This driver uses the CFI probe and Intel Extended Command Set drivers.
  18. The flash is accessed as follows:
  19. 16 KiB memory window at 0xdc000-0xdffff
  20. Two IO address locations for paging
  21. 0x258
  22. bit 0-7: address bit 14-21
  23. 0x259
  24. bit 0-1: address bit 22-23
  25. bit 7: 0 - reset/powered down
  26. 1 - device enabled
  27. The single flash device is divided into 3 partition which appear as
  28. separate MTD devices.
  29. 25/04/2001 AJL (Arcom) Modified signon strings and partition sizes
  30. (to support bzImages up to 638KiB-ish)
  31. */
  32. // Includes
  33. #include <linux/module.h>
  34. #include <linux/slab.h>
  35. #include <linux/ioport.h>
  36. #include <linux/init.h>
  37. #include <asm/io.h>
  38. #include <linux/mtd/mtd.h>
  39. #include <linux/mtd/map.h>
  40. #include <linux/mtd/partitions.h>
  41. // Defines
  42. // - Hardware specific
  43. #define WINDOW_START 0xdc000
  44. /* Number of bits in offset. */
  45. #define WINDOW_SHIFT 14
  46. #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
  47. /* The bits for the offset into the window. */
  48. #define WINDOW_MASK (WINDOW_LENGTH-1)
  49. #define PAGE_IO 0x258
  50. #define PAGE_IO_SIZE 2
  51. /* bit 7 of 0x259 must be 1 to enable device. */
  52. #define DEVICE_ENABLE 0x8000
  53. // - Flash / Partition sizing
  54. #define MAX_SIZE_KiB 16384
  55. #define BOOT_PARTITION_SIZE_KiB 768
  56. #define DATA_PARTITION_SIZE_KiB 1280
  57. #define APP_PARTITION_SIZE_KiB 6144
  58. // Globals
  59. static volatile int page_in_window = -1; // Current page in window.
  60. static void __iomem *iomapadr;
  61. static DEFINE_SPINLOCK(sbc_gxx_spin);
  62. /* partition_info gives details on the logical partitions that the split the
  63. * single flash device into. If the size if zero we use up to the end of the
  64. * device. */
  65. static struct mtd_partition partition_info[]={
  66. { .name = "SBC-GXx flash boot partition",
  67. .offset = 0,
  68. .size = BOOT_PARTITION_SIZE_KiB*1024 },
  69. { .name = "SBC-GXx flash data partition",
  70. .offset = BOOT_PARTITION_SIZE_KiB*1024,
  71. .size = (DATA_PARTITION_SIZE_KiB)*1024 },
  72. { .name = "SBC-GXx flash application partition",
  73. .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
  74. };
  75. #define NUM_PARTITIONS 3
  76. static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
  77. {
  78. unsigned long page = ofs >> WINDOW_SHIFT;
  79. if( page!=page_in_window ) {
  80. outw( page | DEVICE_ENABLE, PAGE_IO );
  81. page_in_window = page;
  82. }
  83. }
  84. static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
  85. {
  86. map_word ret;
  87. spin_lock(&sbc_gxx_spin);
  88. sbc_gxx_page(map, ofs);
  89. ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
  90. spin_unlock(&sbc_gxx_spin);
  91. return ret;
  92. }
  93. static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  94. {
  95. while(len) {
  96. unsigned long thislen = len;
  97. if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
  98. thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
  99. spin_lock(&sbc_gxx_spin);
  100. sbc_gxx_page(map, from);
  101. memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
  102. spin_unlock(&sbc_gxx_spin);
  103. to += thislen;
  104. from += thislen;
  105. len -= thislen;
  106. }
  107. }
  108. static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
  109. {
  110. spin_lock(&sbc_gxx_spin);
  111. sbc_gxx_page(map, adr);
  112. writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
  113. spin_unlock(&sbc_gxx_spin);
  114. }
  115. static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  116. {
  117. while(len) {
  118. unsigned long thislen = len;
  119. if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
  120. thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
  121. spin_lock(&sbc_gxx_spin);
  122. sbc_gxx_page(map, to);
  123. memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
  124. spin_unlock(&sbc_gxx_spin);
  125. to += thislen;
  126. from += thislen;
  127. len -= thislen;
  128. }
  129. }
  130. static struct map_info sbc_gxx_map = {
  131. .name = "SBC-GXx flash",
  132. .phys = NO_XIP,
  133. .size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount
  134. of flash so the cfi probe routines find all
  135. the chips */
  136. .bankwidth = 1,
  137. .read = sbc_gxx_read8,
  138. .copy_from = sbc_gxx_copy_from,
  139. .write = sbc_gxx_write8,
  140. .copy_to = sbc_gxx_copy_to
  141. };
  142. /* MTD device for all of the flash. */
  143. static struct mtd_info *all_mtd;
  144. static void cleanup_sbc_gxx(void)
  145. {
  146. if( all_mtd ) {
  147. del_mtd_partitions( all_mtd );
  148. map_destroy( all_mtd );
  149. }
  150. iounmap(iomapadr);
  151. release_region(PAGE_IO,PAGE_IO_SIZE);
  152. }
  153. static int __init init_sbc_gxx(void)
  154. {
  155. iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
  156. if (!iomapadr) {
  157. printk( KERN_ERR"%s: failed to ioremap memory region\n",
  158. sbc_gxx_map.name );
  159. return -EIO;
  160. }
  161. if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
  162. printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
  163. sbc_gxx_map.name,
  164. PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
  165. iounmap(iomapadr);
  166. return -EAGAIN;
  167. }
  168. printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
  169. sbc_gxx_map.name,
  170. PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
  171. WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
  172. /* Probe for chip. */
  173. all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
  174. if( !all_mtd ) {
  175. cleanup_sbc_gxx();
  176. return -ENXIO;
  177. }
  178. all_mtd->owner = THIS_MODULE;
  179. /* Create MTD devices for each partition. */
  180. add_mtd_partitions(all_mtd, partition_info, NUM_PARTITIONS );
  181. return 0;
  182. }
  183. module_init(init_sbc_gxx);
  184. module_exit(cleanup_sbc_gxx);
  185. MODULE_LICENSE("GPL");
  186. MODULE_AUTHOR("Arcom Control Systems Ltd.");
  187. MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");