netsc520.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* netsc520.c -- MTD map driver for AMD NetSc520 Demonstration Board
  3. *
  4. * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com)
  5. * based on sc520cdp.c by Sysgo Real-Time Solutions GmbH
  6. *
  7. * The NetSc520 is a demonstration board for the Elan Sc520 processor available
  8. * from AMD. It has a single back of 16 megs of 32-bit Flash ROM and another
  9. * 16 megs of SDRAM.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <asm/io.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/map.h>
  18. #include <linux/mtd/partitions.h>
  19. /*
  20. ** The single, 16 megabyte flash bank is divided into four virtual
  21. ** partitions. The first partition is 768 KiB and is intended to
  22. ** store the kernel image loaded by the bootstrap loader. The second
  23. ** partition is 256 KiB and holds the BIOS image. The third
  24. ** partition is 14.5 MiB and is intended for the flash file system
  25. ** image. The last partition is 512 KiB and contains another copy
  26. ** of the BIOS image and the reset vector.
  27. **
  28. ** Only the third partition should be mounted. The first partition
  29. ** should not be mounted, but it can erased and written to using the
  30. ** MTD character routines. The second and fourth partitions should
  31. ** not be touched - it is possible to corrupt the BIOS image by
  32. ** mounting these partitions, and potentially the board will not be
  33. ** recoverable afterwards.
  34. */
  35. /* partition_info gives details on the logical partitions that the split the
  36. * single flash device into. If the size if zero we use up to the end of the
  37. * device. */
  38. static const struct mtd_partition partition_info[] = {
  39. {
  40. .name = "NetSc520 boot kernel",
  41. .offset = 0,
  42. .size = 0xc0000
  43. },
  44. {
  45. .name = "NetSc520 Low BIOS",
  46. .offset = 0xc0000,
  47. .size = 0x40000
  48. },
  49. {
  50. .name = "NetSc520 file system",
  51. .offset = 0x100000,
  52. .size = 0xe80000
  53. },
  54. {
  55. .name = "NetSc520 High BIOS",
  56. .offset = 0xf80000,
  57. .size = 0x80000
  58. },
  59. };
  60. #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
  61. #define WINDOW_SIZE 0x00100000
  62. #define WINDOW_ADDR 0x00200000
  63. static struct map_info netsc520_map = {
  64. .name = "netsc520 Flash Bank",
  65. .size = WINDOW_SIZE,
  66. .bankwidth = 4,
  67. .phys = WINDOW_ADDR,
  68. };
  69. #define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map)
  70. static struct mtd_info *mymtd;
  71. static int __init init_netsc520(void)
  72. {
  73. printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n",
  74. (unsigned long long)netsc520_map.size,
  75. (unsigned long long)netsc520_map.phys);
  76. netsc520_map.virt = ioremap(netsc520_map.phys, netsc520_map.size);
  77. if (!netsc520_map.virt) {
  78. printk("Failed to ioremap\n");
  79. return -EIO;
  80. }
  81. simple_map_init(&netsc520_map);
  82. mymtd = do_map_probe("cfi_probe", &netsc520_map);
  83. if(!mymtd)
  84. mymtd = do_map_probe("map_ram", &netsc520_map);
  85. if(!mymtd)
  86. mymtd = do_map_probe("map_rom", &netsc520_map);
  87. if (!mymtd) {
  88. iounmap(netsc520_map.virt);
  89. return -ENXIO;
  90. }
  91. mymtd->owner = THIS_MODULE;
  92. mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
  93. return 0;
  94. }
  95. static void __exit cleanup_netsc520(void)
  96. {
  97. if (mymtd) {
  98. mtd_device_unregister(mymtd);
  99. map_destroy(mymtd);
  100. }
  101. if (netsc520_map.virt) {
  102. iounmap(netsc520_map.virt);
  103. netsc520_map.virt = NULL;
  104. }
  105. }
  106. module_init(init_netsc520);
  107. module_exit(cleanup_netsc520);
  108. MODULE_LICENSE("GPL");
  109. MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>");
  110. MODULE_DESCRIPTION("MTD map driver for AMD NetSc520 Demonstration Board");