pb1xxx-flash.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Flash memory access on Alchemy Pb1xxx boards
  3.  * 
  4.  * (C) 2001 Pete Popov <ppopov@mvista.com>
  5.  * 
  6.  * $Id: pb1xxx-flash.c,v 1.5 2002/02/01 23:08:50 ppopov Exp $
  7.  */
  8. #include <linux/config.h>
  9. #include <linux/module.h>
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/map.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <asm/io.h>
  16. #include <asm/au1000.h>
  17. #ifdef  DEBUG_RW
  18. #define DBG(x...) printk(x)
  19. #else
  20. #define DBG(x...)
  21. #endif
  22. #ifdef CONFIG_MIPS_PB1000
  23. #define WINDOW_ADDR 0x1F800000
  24. #define WINDOW_SIZE 0x800000
  25. #endif
  26. __u8 physmap_read8(struct map_info *map, unsigned long ofs)
  27. {
  28. __u8 ret;
  29. ret = __raw_readb(map->map_priv_1 + ofs);
  30. DBG("read8 from %x, %xn", (unsigned)(map->map_priv_1 + ofs), ret);
  31. return ret;
  32. }
  33. __u16 physmap_read16(struct map_info *map, unsigned long ofs)
  34. {
  35. __u16 ret;
  36. ret = __raw_readw(map->map_priv_1 + ofs);
  37. DBG("read16 from %x, %xn", (unsigned)(map->map_priv_1 + ofs), ret);
  38. return ret;
  39. }
  40. __u32 physmap_read32(struct map_info *map, unsigned long ofs)
  41. {
  42. __u32 ret;
  43. ret = __raw_readl(map->map_priv_1 + ofs);
  44. DBG("read32 from %x, %xn", (unsigned)(map->map_priv_1 + ofs), ret);
  45. return ret;
  46. }
  47. void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  48. {
  49. DBG("physmap_copy from %x to %xn", (unsigned)from, (unsigned)to);
  50. memcpy_fromio(to, map->map_priv_1 + from, len);
  51. }
  52. void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
  53. {
  54. DBG("write8 at %x, %xn", (unsigned)(map->map_priv_1 + adr), d);
  55. __raw_writeb(d, map->map_priv_1 + adr);
  56. mb();
  57. }
  58. void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
  59. {
  60. DBG("write16 at %x, %xn", (unsigned)(map->map_priv_1 + adr), d);
  61. __raw_writew(d, map->map_priv_1 + adr);
  62. mb();
  63. }
  64. void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
  65. {
  66. DBG("write32 at %x, %xn", (unsigned)(map->map_priv_1 + adr), d);
  67. __raw_writel(d, map->map_priv_1 + adr);
  68. mb();
  69. }
  70. void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  71. {
  72. DBG("physmap_copy_to %x from %xn", (unsigned)to, (unsigned)from);
  73. memcpy_toio(map->map_priv_1 + to, from, len);
  74. }
  75. static struct map_info pb1xxx_map = {
  76. name: "Pb1xxx flash",
  77. read8: physmap_read8,
  78. read16: physmap_read16,
  79. read32: physmap_read32,
  80. copy_from: physmap_copy_from,
  81. write8: physmap_write8,
  82. write16: physmap_write16,
  83. write32: physmap_write32,
  84. copy_to: physmap_copy_to,
  85. };
  86. #ifdef CONFIG_MIPS_PB1000
  87. static unsigned long flash_size = 0x00800000;
  88. static unsigned char flash_buswidth = 4;
  89. static struct mtd_partition pb1xxx_partitions[] = {
  90.         {
  91.                 name: "yamon env",
  92.                 size: 0x00020000,
  93.                 offset: 0,
  94.                 mask_flags: MTD_WRITEABLE
  95.         },{
  96.                 name: "User FS",
  97.                 size: 0x003e0000,
  98.                 offset: 0x20000,
  99.         },{
  100.                 name: "boot code",
  101.                 size: 0x100000,
  102.                 offset: 0x400000,
  103.                 mask_flags: MTD_WRITEABLE
  104.         },{
  105.                 name: "raw/kernel",
  106.                 size: 0x300000,
  107.                 offset: 0x500000
  108.         }
  109. };
  110. #elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100)
  111. static unsigned char flash_buswidth = 4;
  112. #if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
  113. /* both 32MB banks will be used. Combine the first 32MB bank and the
  114.  * first 28MB of the second bank together into a single jffs/jffs2
  115.  * partition.
  116.  */
  117. static unsigned long flash_size = 0x04000000;
  118. #define WINDOW_ADDR 0x1C000000
  119. #define WINDOW_SIZE 0x4000000
  120. static struct mtd_partition pb1xxx_partitions[] = {
  121.         {
  122.                 name: "User FS",
  123.                 size:   0x3c00000,
  124.                 offset: 0x0000000
  125.         },{
  126.                 name: "yamon",
  127.                 size: 0x0100000,
  128.                 offset: 0x3c00000,
  129.                 mask_flags: MTD_WRITEABLE
  130.         },{
  131.                 name: "raw kernel",
  132.                 size: 0x02c0000,
  133.                 offset: 0x3d00000
  134.         }
  135. };
  136. #elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER)
  137. static unsigned long flash_size = 0x02000000;
  138. #define WINDOW_ADDR 0x1E000000
  139. #define WINDOW_SIZE 0x2000000
  140. static struct mtd_partition pb1xxx_partitions[] = {
  141.         {
  142.                 name: "User FS",
  143.                 size:   0x1c00000,
  144.                 offset: 0x0000000
  145.         },{
  146.                 name: "yamon",
  147.                 size: 0x0100000,
  148.                 offset: 0x1c00000,
  149.                 mask_flags: MTD_WRITEABLE
  150.         },{
  151.                 name: "raw kernel",
  152.                 size: 0x02c0000,
  153.                 offset: 0x1d00000
  154.         }
  155. };
  156. #elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
  157. static unsigned long flash_size = 0x02000000;
  158. #define WINDOW_ADDR 0x1C000000
  159. #define WINDOW_SIZE 0x2000000
  160. static struct mtd_partition pb1xxx_partitions[] = {
  161.         {
  162.                 name: "User FS",
  163.                 size:   0x1e00000,
  164.                 offset: 0x0000000
  165.         },{
  166.                 name: "raw kernel",
  167.                 size: 0x0200000,
  168.                 offset: 0x1e00000,
  169.         }
  170. };
  171. #else
  172. #error MTD_PB1500 define combo error /* should never happen */
  173. #endif
  174. #else
  175. #error Unsupported board
  176. #endif
  177. #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
  178. static struct mtd_partition *parsed_parts;
  179. static struct mtd_info *mymtd;
  180. int __init pb1xxx_mtd_init(void)
  181. {
  182. struct mtd_partition *parts;
  183. int nb_parts = 0;
  184. char *part_type;
  185. /* Default flash buswidth */
  186. pb1xxx_map.buswidth = flash_buswidth;
  187. /*
  188.  * Static partition definition selection
  189.  */
  190. part_type = "static";
  191. parts = pb1xxx_partitions;
  192. nb_parts = NB_OF(pb1xxx_partitions);
  193. pb1xxx_map.size = flash_size;
  194. /*
  195.  * Now let's probe for the actual flash.  Do it here since
  196.  * specific machine settings might have been set above.
  197.  */
  198. printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash busn", 
  199. pb1xxx_map.buswidth*8);
  200. pb1xxx_map.map_priv_1 = 
  201. (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
  202. mymtd = do_map_probe("cfi_probe", &pb1xxx_map);
  203. if (!mymtd) return -ENXIO;
  204. mymtd->module = THIS_MODULE;
  205. add_mtd_partitions(mymtd, parts, nb_parts);
  206. return 0;
  207. }
  208. static void __exit pb1xxx_mtd_cleanup(void)
  209. {
  210. if (mymtd) {
  211. del_mtd_partitions(mymtd);
  212. map_destroy(mymtd);
  213. if (parsed_parts)
  214. kfree(parsed_parts);
  215. }
  216. }
  217. module_init(pb1xxx_mtd_init);
  218. module_exit(pb1xxx_mtd_cleanup);
  219. MODULE_AUTHOR("Pete Popov");
  220. MODULE_DESCRIPTION("Pb1xxx CFI map driver");
  221. MODULE_LICENSE("GPL");