flash.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Merisc board-specific flash initialization
  3. *
  4. * Copyright (C) 2008 Martinsson Elektronik AB
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/partitions.h>
  14. #include <linux/mtd/physmap.h>
  15. #include <mach/smc.h>
  16. /* Will be translated to units of 14.3 ns, rounded up */
  17. static struct smc_timing flash_timing __initdata = {
  18. .ncs_read_setup = 1 * 14,
  19. .nrd_setup = 5 * 14,
  20. .ncs_write_setup = 1 * 14,
  21. .nwe_setup = 2 * 14,
  22. .ncs_read_pulse = 12 * 14,
  23. .nrd_pulse = 7 * 14,
  24. .ncs_write_pulse = 8 * 14,
  25. .nwe_pulse = 4 * 14,
  26. .read_cycle = 14 * 14,
  27. .write_cycle = 10 * 14,
  28. };
  29. static struct smc_config flash_config __initdata = {
  30. .bus_width = 2,
  31. .nrd_controlled = 1,
  32. .nwe_controlled = 1,
  33. .byte_write = 1,
  34. .tdf_cycles = 3,
  35. };
  36. static struct mtd_partition flash_0_parts[] = {
  37. {
  38. .name = "boot",
  39. .offset = 0x00000000,
  40. .size = 0x00060000,
  41. .mask_flags = 0,
  42. },
  43. {
  44. .name = "kernel",
  45. .offset = 0x00060000,
  46. .size = 0x00200000,
  47. .mask_flags = 0,
  48. },
  49. {
  50. .name = "root",
  51. .offset = 0x00260000,
  52. .size = MTDPART_SIZ_FULL,
  53. .mask_flags = 0,
  54. },
  55. };
  56. static struct mtd_partition flash_1_parts[] = {
  57. {
  58. .name = "2ndflash",
  59. .offset = 0x00000000,
  60. .size = MTDPART_SIZ_FULL,
  61. .mask_flags = 0,
  62. },
  63. };
  64. static struct physmap_flash_data flash_data[] = {
  65. {
  66. .width = 2,
  67. .nr_parts = ARRAY_SIZE(flash_0_parts),
  68. .parts = flash_0_parts,
  69. },
  70. {
  71. .width = 2,
  72. .nr_parts = ARRAY_SIZE(flash_1_parts),
  73. .parts = flash_1_parts,
  74. }
  75. };
  76. static struct resource flash_resource[] = {
  77. {
  78. .start = 0x00000000,
  79. .end = 0x03ffffff,
  80. .flags = IORESOURCE_MEM,
  81. },
  82. {
  83. .start = 0x04000000,
  84. .end = 0x07ffffff,
  85. .flags = IORESOURCE_MEM,
  86. },
  87. };
  88. static struct platform_device flash_device[] = {
  89. {
  90. .name = "physmap-flash",
  91. .id = 0,
  92. .resource = &flash_resource[0],
  93. .num_resources = 1,
  94. .dev = {
  95. .platform_data = &flash_data[0],
  96. },
  97. },
  98. {
  99. .name = "physmap-flash",
  100. .id = 1,
  101. .resource = &flash_resource[1],
  102. .num_resources = 1,
  103. .dev = {
  104. .platform_data = &flash_data[1],
  105. },
  106. },
  107. };
  108. static int __init merisc_flash_init(void)
  109. {
  110. int ret;
  111. smc_set_timing(&flash_config, &flash_timing);
  112. ret = smc_set_configuration(0, &flash_config);
  113. if (ret < 0) {
  114. printk(KERN_ERR "Merisc: failed to set NOR flash timing #0\n");
  115. return ret;
  116. }
  117. ret = smc_set_configuration(4, &flash_config);
  118. if (ret < 0) {
  119. printk(KERN_ERR "Merisc: failed to set NOR flash timing #1\n");
  120. return ret;
  121. }
  122. platform_device_register(&flash_device[0]);
  123. platform_device_register(&flash_device[1]);
  124. return 0;
  125. }
  126. device_initcall(merisc_flash_init);