cstm_mips_ixx.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * $Id: cstm_mips_ixx.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
  3. *
  4. * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
  5. * Config with both CFI and JEDEC device support.
  6. *
  7. * Basically physmap.c with the addition of partitions and
  8. * an array of mapping info to accomodate more than one flash type per board.
  9. *
  10. * Copyright 2000 MontaVista Software Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/types.h>
  34. #include <linux/kernel.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. #include <linux/config.h>
  41. #include <linux/delay.h>
  42. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  43. #define CC_GCR 0xB4013818
  44. #define CC_GPBCR 0xB401380A
  45. #define CC_GPBDR 0xB4013808
  46. #define CC_M68K_DEVICE 1
  47. #define CC_M68K_FUNCTION 6
  48. #define CC_CONFADDR 0xB8004000
  49. #define CC_CONFDATA 0xB8004004
  50. #define CC_FC_FCR 0xB8002004
  51. #define CC_FC_DCR 0xB8002008
  52. #define CC_GPACR 0xB4013802
  53. #define CC_GPAICR 0xB4013804
  54. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  55. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  56. void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
  57. {
  58. static DEFINE_SPINLOCK(vpp_lock);
  59. static int vpp_count = 0;
  60. unsigned long flags;
  61. spin_lock_irqsave(&vpp_lock, flags);
  62. if (vpp) {
  63. if (!vpp_count++) {
  64. __u16 data;
  65. __u8 data1;
  66. static u8 first = 1;
  67. // Set GPIO port B pin3 to high
  68. data = *(__u16 *)(CC_GPBCR);
  69. data = (data & 0xff0f) | 0x0040;
  70. *(__u16 *)CC_GPBCR = data;
  71. *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) | 0x08;
  72. if (first) {
  73. first = 0;
  74. /* need to have this delay for first
  75. enabling vpp after powerup */
  76. udelay(40);
  77. }
  78. }
  79. } else {
  80. if (!--vpp_count) {
  81. __u16 data;
  82. // Set GPIO port B pin3 to high
  83. data = *(__u16 *)(CC_GPBCR);
  84. data = (data & 0xff3f) | 0x0040;
  85. *(__u16 *)CC_GPBCR = data;
  86. *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) & 0xf7;
  87. }
  88. }
  89. spin_unlock_irqrestore(&vpp_lock, flags);
  90. }
  91. #endif
  92. /* board and partition description */
  93. #define MAX_PHYSMAP_PARTITIONS 8
  94. struct cstm_mips_ixx_info {
  95. char *name;
  96. unsigned long window_addr;
  97. unsigned long window_size;
  98. int bankwidth;
  99. int num_partitions;
  100. };
  101. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  102. #define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
  103. const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
  104. {
  105. { // 28F128J3A in 2x16 configuration
  106. "big flash", // name
  107. 0x08000000, // window_addr
  108. 0x02000000, // window_size
  109. 4, // bankwidth
  110. 1, // num_partitions
  111. }
  112. };
  113. static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
  114. { // 28F128J3A in 2x16 configuration
  115. {
  116. .name = "main partition ",
  117. .size = 0x02000000, // 128 x 2 x 128k byte sectors
  118. .offset = 0,
  119. },
  120. },
  121. };
  122. #else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  123. #define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
  124. const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
  125. {
  126. {
  127. "MTD flash", // name
  128. CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr
  129. CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size
  130. CONFIG_MTD_CSTM_MIPS_IXX_BUSWIDTH, // bankwidth
  131. 1, // num_partitions
  132. },
  133. };
  134. static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
  135. {
  136. {
  137. .name = "main partition",
  138. .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN,
  139. .offset = 0,
  140. },
  141. },
  142. };
  143. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  144. struct map_info cstm_mips_ixx_map[PHYSMAP_NUMBER];
  145. int __init init_cstm_mips_ixx(void)
  146. {
  147. int i;
  148. int jedec;
  149. struct mtd_info *mymtd;
  150. struct mtd_partition *parts;
  151. /* Initialize mapping */
  152. for (i=0;i<PHYSMAP_NUMBER;i++) {
  153. printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
  154. cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr);
  155. cstm_mips_ixx_map[i].phys = cstm_mips_ixx_board_desc[i].window_addr;
  156. cstm_mips_ixx_map[i].virt = ioremap(cstm_mips_ixx_board_desc[i].window_addr, cstm_mips_ixx_board_desc[i].window_size);
  157. if (!cstm_mips_ixx_map[i].virt) {
  158. printk(KERN_WARNING "Failed to ioremap\n");
  159. return -EIO;
  160. }
  161. cstm_mips_ixx_map[i].name = cstm_mips_ixx_board_desc[i].name;
  162. cstm_mips_ixx_map[i].size = cstm_mips_ixx_board_desc[i].window_size;
  163. cstm_mips_ixx_map[i].bankwidth = cstm_mips_ixx_board_desc[i].bankwidth;
  164. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  165. cstm_mips_ixx_map[i].set_vpp = cstm_mips_ixx_set_vpp;
  166. #endif
  167. simple_map_init(&cstm_mips_ixx_map[i]);
  168. //printk(KERN_NOTICE "cstm_mips_ixx: ioremap is %x\n",(unsigned int)(cstm_mips_ixx_map[i].virt));
  169. }
  170. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  171. setup_ITE_IVR_flash();
  172. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  173. for (i=0;i<PHYSMAP_NUMBER;i++) {
  174. parts = &cstm_mips_ixx_partitions[i][0];
  175. jedec = 0;
  176. mymtd = (struct mtd_info *)do_map_probe("cfi_probe", &cstm_mips_ixx_map[i]);
  177. //printk(KERN_NOTICE "phymap %d cfi_probe: mymtd is %x\n",i,(unsigned int)mymtd);
  178. if (!mymtd) {
  179. jedec = 1;
  180. mymtd = (struct mtd_info *)do_map_probe("jedec", &cstm_mips_ixx_map[i]);
  181. printk(KERN_NOTICE "cstm_mips_ixx %d jedec: mymtd is %x\n",i,(unsigned int)mymtd);
  182. }
  183. if (mymtd) {
  184. mymtd->owner = THIS_MODULE;
  185. cstm_mips_ixx_map[i].map_priv_2 = (unsigned long)mymtd;
  186. add_mtd_partitions(mymtd, parts, cstm_mips_ixx_board_desc[i].num_partitions);
  187. }
  188. else
  189. return -ENXIO;
  190. }
  191. return 0;
  192. }
  193. static void __exit cleanup_cstm_mips_ixx(void)
  194. {
  195. int i;
  196. struct mtd_info *mymtd;
  197. for (i=0;i<PHYSMAP_NUMBER;i++) {
  198. mymtd = (struct mtd_info *)cstm_mips_ixx_map[i].map_priv_2;
  199. if (mymtd) {
  200. del_mtd_partitions(mymtd);
  201. map_destroy(mymtd);
  202. }
  203. if (cstm_mips_ixx_map[i].virt) {
  204. iounmap((void *)cstm_mips_ixx_map[i].virt);
  205. cstm_mips_ixx_map[i].virt = 0;
  206. }
  207. }
  208. }
  209. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  210. void PCISetULongByOffset(__u32 DevNumber, __u32 FuncNumber, __u32 Offset, __u32 data)
  211. {
  212. __u32 offset;
  213. offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ;
  214. *(__u32 *)CC_CONFADDR = offset;
  215. *(__u32 *)CC_CONFDATA = data;
  216. }
  217. void setup_ITE_IVR_flash()
  218. {
  219. __u32 size, base;
  220. size = 0x0e000000; // 32MiB
  221. base = (0x08000000) >> 8 >>1; // Bug: we must shift one more bit
  222. /* need to set ITE flash to 32 bits instead of default 8 */
  223. #ifdef CONFIG_MIPS_IVR
  224. *(__u32 *)CC_FC_FCR = 0x55;
  225. *(__u32 *)CC_GPACR = 0xfffc;
  226. #else
  227. *(__u32 *)CC_FC_FCR = 0x77;
  228. #endif
  229. /* turn bursting off */
  230. *(__u32 *)CC_FC_DCR = 0x0;
  231. /* setup for one chip 4 byte PCI access */
  232. PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x60, size | base);
  233. PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x64, 0x02);
  234. }
  235. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  236. module_init(init_cstm_mips_ixx);
  237. module_exit(cleanup_cstm_mips_ixx);
  238. MODULE_LICENSE("GPL");
  239. MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
  240. MODULE_DESCRIPTION("MTD map driver for ITE 8172G and Globespan IVR boards");