sbc_gxx.c 6.3 KB

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