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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * pnc2000.c - mapper for Photron PNC-2000 board.
  3.  *
  4.  * Copyright (C) 2000 Crossnet Co. <info@crossnet.co.jp>
  5.  *
  6.  * This code is GPL
  7.  *
  8.  * $Id: pnc2000.c,v 1.10 2001/10/02 15:05:14 dwmw2 Exp $
  9.  */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/map.h>
  15. #include <linux/mtd/partitions.h>
  16. #define WINDOW_ADDR 0xbf000000
  17. #define WINDOW_SIZE 0x00400000
  18. /* 
  19.  * MAP DRIVER STUFF
  20.  */
  21. __u8 pnc_read8(struct map_info *map, unsigned long ofs)
  22. {
  23.   return *(__u8 *)(WINDOW_ADDR + ofs);
  24. }
  25. __u16 pnc_read16(struct map_info *map, unsigned long ofs)
  26. {
  27.   return *(__u16 *)(WINDOW_ADDR + ofs);
  28. }
  29. __u32 pnc_read32(struct map_info *map, unsigned long ofs)
  30. {
  31.   return *(volatile unsigned int *)(WINDOW_ADDR + ofs);
  32. }
  33. void pnc_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  34. {
  35.   memcpy(to, (void *)(WINDOW_ADDR + from), len);
  36. }
  37. void pnc_write8(struct map_info *map, __u8 d, unsigned long adr)
  38. {
  39.   *(__u8 *)(WINDOW_ADDR + adr) = d;
  40. }
  41. void pnc_write16(struct map_info *map, __u16 d, unsigned long adr)
  42. {
  43.   *(__u16 *)(WINDOW_ADDR + adr) = d;
  44. }
  45. void pnc_write32(struct map_info *map, __u32 d, unsigned long adr)
  46. {
  47.   *(__u32 *)(WINDOW_ADDR + adr) = d;
  48. }
  49. void pnc_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  50. {
  51.   memcpy((void *)(WINDOW_ADDR + to), from, len);
  52. }
  53. struct map_info pnc_map = {
  54. name: "PNC-2000",
  55. size: WINDOW_SIZE,
  56. buswidth: 4,
  57. read8: pnc_read8,
  58. read16: pnc_read16,
  59. read32: pnc_read32,
  60. copy_from: pnc_copy_from,
  61. write8: pnc_write8,
  62. write16: pnc_write16,
  63. write32: pnc_write32,
  64. copy_to: pnc_copy_to
  65. };
  66. /*
  67.  * MTD 'PARTITIONING' STUFF 
  68.  */
  69. static struct mtd_partition pnc_partitions[3] = {
  70. {
  71. name: "PNC-2000 boot firmware",
  72. size: 0x20000,
  73. offset: 0
  74. },
  75. {
  76. name: "PNC-2000 kernel",
  77. size: 0x1a0000,
  78. offset: 0x20000
  79. },
  80. {
  81. name: "PNC-2000 filesystem",
  82. size: 0x240000,
  83. offset: 0x1c0000
  84. }
  85. };
  86. /* 
  87.  * This is the master MTD device for which all the others are just
  88.  * auto-relocating aliases.
  89.  */
  90. static struct mtd_info *mymtd;
  91. int __init init_pnc2000(void)
  92. {
  93. printk(KERN_NOTICE "Photron PNC-2000 flash mapping: %x at %xn", WINDOW_SIZE, WINDOW_ADDR);
  94. mymtd = do_map_probe("cfi_probe", &pnc_map);
  95. if (mymtd) {
  96. mymtd->module = THIS_MODULE;
  97. return add_mtd_partitions(mymtd, pnc_partitions, 3);
  98. }
  99. return -ENXIO;
  100. }
  101. static void __exit cleanup_pnc2000(void)
  102. {
  103. if (mymtd) {
  104. del_mtd_partitions(mymtd);
  105. map_destroy(mymtd);
  106. }
  107. }
  108. module_init(init_pnc2000);
  109. module_exit(cleanup_pnc2000);
  110. MODULE_LICENSE("GPL");
  111. MODULE_AUTHOR("Crossnet Co. <info@crossnet.co.jp>");
  112. MODULE_DESCRIPTION("MTD map driver for Photron PNC-2000 board");