sbc_gxx.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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/ioport.h>
  35. #include <linux/init.h>
  36. #include <asm/io.h>
  37. #include <linux/mtd/mtd.h>
  38. #include <linux/mtd/map.h>
  39. #include <linux/mtd/partitions.h>
  40. // Defines
  41. // - Hardware specific
  42. #define WINDOW_START 0xdc000
  43. /* Number of bits in offset. */
  44. #define WINDOW_SHIFT 14
  45. #define WINDOW_LENGTH (1 << WINDOW_SHIFT)
  46. /* The bits for the offset into the window. */
  47. #define WINDOW_MASK (WINDOW_LENGTH-1)
  48. #define PAGE_IO 0x258
  49. #define PAGE_IO_SIZE 2
  50. /* bit 7 of 0x259 must be 1 to enable device. */
  51. #define DEVICE_ENABLE 0x8000
  52. // - Flash / Partition sizing
  53. #define MAX_SIZE_KiB 16384
  54. #define BOOT_PARTITION_SIZE_KiB 768
  55. #define DATA_PARTITION_SIZE_KiB 1280
  56. #define APP_PARTITION_SIZE_KiB 6144
  57. // Globals
  58. static volatile int page_in_window = -1; // Current page in window.
  59. static void __iomem *iomapadr;
  60. static DEFINE_SPINLOCK(sbc_gxx_spin);
  61. /* partition_info gives details on the logical partitions that the split the
  62. * single flash device into. If the size if zero we use up to the end of the
  63. * device. */
  64. static struct mtd_partition partition_info[]={
  65. { .name = "SBC-GXx flash boot partition",
  66. .offset = 0,
  67. .size = BOOT_PARTITION_SIZE_KiB*1024 },
  68. { .name = "SBC-GXx flash data partition",
  69. .offset = BOOT_PARTITION_SIZE_KiB*1024,
  70. .size = (DATA_PARTITION_SIZE_KiB)*1024 },
  71. { .name = "SBC-GXx flash application partition",
  72. .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
  73. };
  74. #define NUM_PARTITIONS 3
  75. static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
  76. {
  77. unsigned long page = ofs >> WINDOW_SHIFT;
  78. if( page!=page_in_window ) {
  79. outw( page | DEVICE_ENABLE, PAGE_IO );
  80. page_in_window = page;
  81. }
  82. }
  83. static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
  84. {
  85. map_word ret;
  86. spin_lock(&sbc_gxx_spin);
  87. sbc_gxx_page(map, ofs);
  88. ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
  89. spin_unlock(&sbc_gxx_spin);
  90. return ret;
  91. }
  92. static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  93. {
  94. while(len) {
  95. unsigned long thislen = len;
  96. if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
  97. thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
  98. spin_lock(&sbc_gxx_spin);
  99. sbc_gxx_page(map, from);
  100. memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
  101. spin_unlock(&sbc_gxx_spin);
  102. to += thislen;
  103. from += thislen;
  104. len -= thislen;
  105. }
  106. }
  107. static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
  108. {
  109. spin_lock(&sbc_gxx_spin);
  110. sbc_gxx_page(map, adr);
  111. writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
  112. spin_unlock(&sbc_gxx_spin);
  113. }
  114. static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  115. {
  116. while(len) {
  117. unsigned long thislen = len;
  118. if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
  119. thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
  120. spin_lock(&sbc_gxx_spin);
  121. sbc_gxx_page(map, to);
  122. memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
  123. spin_unlock(&sbc_gxx_spin);
  124. to += thislen;
  125. from += thislen;
  126. len -= thislen;
  127. }
  128. }
  129. static struct map_info sbc_gxx_map = {
  130. .name = "SBC-GXx flash",
  131. .phys = NO_XIP,
  132. .size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount
  133. of flash so the cfi probe routines find all
  134. the chips */
  135. .bankwidth = 1,
  136. .read = sbc_gxx_read8,
  137. .copy_from = sbc_gxx_copy_from,
  138. .write = sbc_gxx_write8,
  139. .copy_to = sbc_gxx_copy_to
  140. };
  141. /* MTD device for all of the flash. */
  142. static struct mtd_info *all_mtd;
  143. static void cleanup_sbc_gxx(void)
  144. {
  145. if( all_mtd ) {
  146. mtd_device_unregister(all_mtd);
  147. map_destroy( all_mtd );
  148. }
  149. iounmap(iomapadr);
  150. release_region(PAGE_IO,PAGE_IO_SIZE);
  151. }
  152. static int __init init_sbc_gxx(void)
  153. {
  154. iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
  155. if (!iomapadr) {
  156. printk( KERN_ERR"%s: failed to ioremap memory region\n",
  157. sbc_gxx_map.name );
  158. return -EIO;
  159. }
  160. if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
  161. printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
  162. sbc_gxx_map.name,
  163. PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
  164. iounmap(iomapadr);
  165. return -EAGAIN;
  166. }
  167. printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
  168. sbc_gxx_map.name,
  169. PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
  170. WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
  171. /* Probe for chip. */
  172. all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
  173. if( !all_mtd ) {
  174. cleanup_sbc_gxx();
  175. return -ENXIO;
  176. }
  177. all_mtd->owner = THIS_MODULE;
  178. /* Create MTD devices for each partition. */
  179. mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS);
  180. return 0;
  181. }
  182. module_init(init_sbc_gxx);
  183. module_exit(cleanup_sbc_gxx);
  184. MODULE_LICENSE("GPL");
  185. MODULE_AUTHOR("Arcom Control Systems Ltd.");
  186. MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");