cstm_mips_ixx.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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/delay.h>
  41. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  42. #define CC_GCR 0xB4013818
  43. #define CC_GPBCR 0xB401380A
  44. #define CC_GPBDR 0xB4013808
  45. #define CC_M68K_DEVICE 1
  46. #define CC_M68K_FUNCTION 6
  47. #define CC_CONFADDR 0xB8004000
  48. #define CC_CONFDATA 0xB8004004
  49. #define CC_FC_FCR 0xB8002004
  50. #define CC_FC_DCR 0xB8002008
  51. #define CC_GPACR 0xB4013802
  52. #define CC_GPAICR 0xB4013804
  53. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  54. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  55. void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
  56. {
  57. static DEFINE_SPINLOCK(vpp_lock);
  58. static int vpp_count = 0;
  59. unsigned long flags;
  60. spin_lock_irqsave(&vpp_lock, flags);
  61. if (vpp) {
  62. if (!vpp_count++) {
  63. __u16 data;
  64. __u8 data1;
  65. static u8 first = 1;
  66. // Set GPIO port B pin3 to high
  67. data = *(__u16 *)(CC_GPBCR);
  68. data = (data & 0xff0f) | 0x0040;
  69. *(__u16 *)CC_GPBCR = data;
  70. *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) | 0x08;
  71. if (first) {
  72. first = 0;
  73. /* need to have this delay for first
  74. enabling vpp after powerup */
  75. udelay(40);
  76. }
  77. }
  78. } else {
  79. if (!--vpp_count) {
  80. __u16 data;
  81. // Set GPIO port B pin3 to high
  82. data = *(__u16 *)(CC_GPBCR);
  83. data = (data & 0xff3f) | 0x0040;
  84. *(__u16 *)CC_GPBCR = data;
  85. *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) & 0xf7;
  86. }
  87. }
  88. spin_unlock_irqrestore(&vpp_lock, flags);
  89. }
  90. #endif
  91. /* board and partition description */
  92. #define MAX_PHYSMAP_PARTITIONS 8
  93. struct cstm_mips_ixx_info {
  94. char *name;
  95. unsigned long window_addr;
  96. unsigned long window_size;
  97. int bankwidth;
  98. int num_partitions;
  99. };
  100. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  101. #define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
  102. const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
  103. {
  104. { // 28F128J3A in 2x16 configuration
  105. "big flash", // name
  106. 0x08000000, // window_addr
  107. 0x02000000, // window_size
  108. 4, // bankwidth
  109. 1, // num_partitions
  110. }
  111. };
  112. static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
  113. { // 28F128J3A in 2x16 configuration
  114. {
  115. .name = "main partition ",
  116. .size = 0x02000000, // 128 x 2 x 128k byte sectors
  117. .offset = 0,
  118. },
  119. },
  120. };
  121. #else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  122. #define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
  123. const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
  124. {
  125. {
  126. "MTD flash", // name
  127. CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr
  128. CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size
  129. CONFIG_MTD_CSTM_MIPS_IXX_BUSWIDTH, // bankwidth
  130. 1, // num_partitions
  131. },
  132. };
  133. static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
  134. {
  135. {
  136. .name = "main partition",
  137. .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN,
  138. .offset = 0,
  139. },
  140. },
  141. };
  142. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  143. struct map_info cstm_mips_ixx_map[PHYSMAP_NUMBER];
  144. int __init init_cstm_mips_ixx(void)
  145. {
  146. int i;
  147. int jedec;
  148. struct mtd_info *mymtd;
  149. struct mtd_partition *parts;
  150. /* Initialize mapping */
  151. for (i=0;i<PHYSMAP_NUMBER;i++) {
  152. printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
  153. cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr);
  154. cstm_mips_ixx_map[i].phys = cstm_mips_ixx_board_desc[i].window_addr;
  155. cstm_mips_ixx_map[i].virt = ioremap(cstm_mips_ixx_board_desc[i].window_addr, cstm_mips_ixx_board_desc[i].window_size);
  156. if (!cstm_mips_ixx_map[i].virt) {
  157. int j = 0;
  158. printk(KERN_WARNING "Failed to ioremap\n");
  159. for (j = 0; j < i; j++) {
  160. if (cstm_mips_ixx_map[j].virt) {
  161. iounmap((void *)cstm_mips_ixx_map[j].virt);
  162. cstm_mips_ixx_map[j].virt = 0;
  163. }
  164. }
  165. return -EIO;
  166. }
  167. cstm_mips_ixx_map[i].name = cstm_mips_ixx_board_desc[i].name;
  168. cstm_mips_ixx_map[i].size = cstm_mips_ixx_board_desc[i].window_size;
  169. cstm_mips_ixx_map[i].bankwidth = cstm_mips_ixx_board_desc[i].bankwidth;
  170. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  171. cstm_mips_ixx_map[i].set_vpp = cstm_mips_ixx_set_vpp;
  172. #endif
  173. simple_map_init(&cstm_mips_ixx_map[i]);
  174. //printk(KERN_NOTICE "cstm_mips_ixx: ioremap is %x\n",(unsigned int)(cstm_mips_ixx_map[i].virt));
  175. }
  176. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  177. setup_ITE_IVR_flash();
  178. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  179. for (i=0;i<PHYSMAP_NUMBER;i++) {
  180. parts = &cstm_mips_ixx_partitions[i][0];
  181. jedec = 0;
  182. mymtd = (struct mtd_info *)do_map_probe("cfi_probe", &cstm_mips_ixx_map[i]);
  183. //printk(KERN_NOTICE "phymap %d cfi_probe: mymtd is %x\n",i,(unsigned int)mymtd);
  184. if (!mymtd) {
  185. jedec = 1;
  186. mymtd = (struct mtd_info *)do_map_probe("jedec", &cstm_mips_ixx_map[i]);
  187. printk(KERN_NOTICE "cstm_mips_ixx %d jedec: mymtd is %x\n",i,(unsigned int)mymtd);
  188. }
  189. if (mymtd) {
  190. mymtd->owner = THIS_MODULE;
  191. cstm_mips_ixx_map[i].map_priv_2 = (unsigned long)mymtd;
  192. add_mtd_partitions(mymtd, parts, cstm_mips_ixx_board_desc[i].num_partitions);
  193. }
  194. else {
  195. for (i = 0; i < PHYSMAP_NUMBER; i++) {
  196. if (cstm_mips_ixx_map[i].virt) {
  197. iounmap((void *)cstm_mips_ixx_map[i].virt);
  198. cstm_mips_ixx_map[i].virt = 0;
  199. }
  200. }
  201. return -ENXIO;
  202. }
  203. }
  204. return 0;
  205. }
  206. static void __exit cleanup_cstm_mips_ixx(void)
  207. {
  208. int i;
  209. struct mtd_info *mymtd;
  210. for (i=0;i<PHYSMAP_NUMBER;i++) {
  211. mymtd = (struct mtd_info *)cstm_mips_ixx_map[i].map_priv_2;
  212. if (mymtd) {
  213. del_mtd_partitions(mymtd);
  214. map_destroy(mymtd);
  215. }
  216. if (cstm_mips_ixx_map[i].virt) {
  217. iounmap((void *)cstm_mips_ixx_map[i].virt);
  218. cstm_mips_ixx_map[i].virt = 0;
  219. }
  220. }
  221. }
  222. #if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
  223. void PCISetULongByOffset(__u32 DevNumber, __u32 FuncNumber, __u32 Offset, __u32 data)
  224. {
  225. __u32 offset;
  226. offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ;
  227. *(__u32 *)CC_CONFADDR = offset;
  228. *(__u32 *)CC_CONFDATA = data;
  229. }
  230. void setup_ITE_IVR_flash()
  231. {
  232. __u32 size, base;
  233. size = 0x0e000000; // 32MiB
  234. base = (0x08000000) >> 8 >>1; // Bug: we must shift one more bit
  235. /* need to set ITE flash to 32 bits instead of default 8 */
  236. #ifdef CONFIG_MIPS_IVR
  237. *(__u32 *)CC_FC_FCR = 0x55;
  238. *(__u32 *)CC_GPACR = 0xfffc;
  239. #else
  240. *(__u32 *)CC_FC_FCR = 0x77;
  241. #endif
  242. /* turn bursting off */
  243. *(__u32 *)CC_FC_DCR = 0x0;
  244. /* setup for one chip 4 byte PCI access */
  245. PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x60, size | base);
  246. PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x64, 0x02);
  247. }
  248. #endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
  249. module_init(init_cstm_mips_ixx);
  250. module_exit(cleanup_cstm_mips_ixx);
  251. MODULE_LICENSE("GPL");
  252. MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
  253. MODULE_DESCRIPTION("MTD map driver for ITE 8172G and Globespan IVR boards");