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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * $Id: dbox2-flash.c,v 1.4 2001/10/02 15:05:14 dwmw2 Exp $
  3.  *
  4.  * Nokia / Sagem D-Box 2 flash driver
  5.  */
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <asm/io.h>
  10. #include <linux/mtd/mtd.h>
  11. #include <linux/mtd/map.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/config.h>
  14. /* partition_info gives details on the logical partitions that the split the
  15.  * single flash device into. If the size if zero we use up to the end of the
  16.  * device. */
  17. static struct mtd_partition partition_info[]= {{name: "BR bootloader", // raw
  18.       size: 128 * 1024, 
  19.       offset: 0,                  
  20.       mask_flags: MTD_WRITEABLE},
  21.                                                      {name: "PPC bootloader", // flfs
  22.       size: 128 * 1024, 
  23.       offset: MTDPART_OFS_APPEND, 
  24.       mask_flags: 0},
  25.                                                      {name: "Kernel", // idxfs
  26.       size: 768 * 1024, 
  27.       offset: MTDPART_OFS_APPEND, 
  28.       mask_flags: 0},
  29.                                                      {name: "System", // jffs
  30.       size: MTDPART_SIZ_FULL, 
  31.       offset: MTDPART_OFS_APPEND, 
  32.       mask_flags: 0}};
  33. #define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0]))
  34. #define WINDOW_ADDR 0x10000000
  35. #define WINDOW_SIZE 0x800000
  36. static struct mtd_info *mymtd;
  37. __u8 dbox2_flash_read8(struct map_info *map, unsigned long ofs)
  38. {
  39. return __raw_readb(map->map_priv_1 + ofs);
  40. }
  41. __u16 dbox2_flash_read16(struct map_info *map, unsigned long ofs)
  42. {
  43. return __raw_readw(map->map_priv_1 + ofs);
  44. }
  45. __u32 dbox2_flash_read32(struct map_info *map, unsigned long ofs)
  46. {
  47. return __raw_readl(map->map_priv_1 + ofs);
  48. }
  49. void dbox2_flash_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  50. {
  51. memcpy_fromio(to, map->map_priv_1 + from, len);
  52. }
  53. void dbox2_flash_write8(struct map_info *map, __u8 d, unsigned long adr)
  54. {
  55. __raw_writeb(d, map->map_priv_1 + adr);
  56. mb();
  57. }
  58. void dbox2_flash_write16(struct map_info *map, __u16 d, unsigned long adr)
  59. {
  60. __raw_writew(d, map->map_priv_1 + adr);
  61. mb();
  62. }
  63. void dbox2_flash_write32(struct map_info *map, __u32 d, unsigned long adr)
  64. {
  65. __raw_writel(d, map->map_priv_1 + adr);
  66. mb();
  67. }
  68. void dbox2_flash_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  69. {
  70. memcpy_toio(map->map_priv_1 + to, from, len);
  71. }
  72. struct map_info dbox2_flash_map = {
  73. name: "D-Box 2 flash memory",
  74. size: WINDOW_SIZE,
  75. buswidth: 4,
  76. read8: dbox2_flash_read8,
  77. read16: dbox2_flash_read16,
  78. read32: dbox2_flash_read32,
  79. copy_from: dbox2_flash_copy_from,
  80. write8: dbox2_flash_write8,
  81. write16: dbox2_flash_write16,
  82. write32: dbox2_flash_write32,
  83. copy_to: dbox2_flash_copy_to
  84. };
  85. int __init init_dbox2_flash(void)
  86. {
  87.         printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)n", WINDOW_SIZE, WINDOW_ADDR);
  88. dbox2_flash_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
  89. if (!dbox2_flash_map.map_priv_1) {
  90. printk("Failed to ioremapn");
  91. return -EIO;
  92. }
  93. // Probe for dual Intel 28F320 or dual AMD
  94. mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
  95. if (!mymtd) {
  96.     // Probe for single Intel 28F640
  97.     dbox2_flash_map.buswidth = 2;
  98.     mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
  99. }
  100.     
  101. if (mymtd) {
  102. mymtd->module = THIS_MODULE;
  103.                 /* Create MTD devices for each partition. */
  104.         add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
  105. return 0;
  106. }
  107. iounmap((void *)dbox2_flash_map.map_priv_1);
  108. return -ENXIO;
  109. }
  110. static void __exit cleanup_dbox2_flash(void)
  111. {
  112. if (mymtd) {
  113. del_mtd_partitions(mymtd);
  114. map_destroy(mymtd);
  115. }
  116. if (dbox2_flash_map.map_priv_1) {
  117. iounmap((void *)dbox2_flash_map.map_priv_1);
  118. dbox2_flash_map.map_priv_1 = 0;
  119. }
  120. }
  121. module_init(init_dbox2_flash);
  122. module_exit(cleanup_dbox2_flash);
  123. MODULE_LICENSE("GPL");
  124. MODULE_AUTHOR("K醨i Dav眇sson <kd@flaga.is>");
  125. MODULE_DESCRIPTION("MTD map driver for Nokia/Sagem D-Box 2 board");