board-autcpu12.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * linux/arch/arm/mach-clps711x/autcpu12.c
  3. *
  4. * (c) 2001 Thomas Gleixner, autronix automation <gleixner@autronix.de>
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/types.h>
  23. #include <linux/string.h>
  24. #include <linux/mm.h>
  25. #include <linux/io.h>
  26. #include <linux/gpio.h>
  27. #include <linux/ioport.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/mtd/physmap.h>
  30. #include <linux/mtd/plat-ram.h>
  31. #include <linux/mtd/partitions.h>
  32. #include <linux/mtd/nand-gpio.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/basic_mmio_gpio.h>
  35. #include <mach/hardware.h>
  36. #include <asm/sizes.h>
  37. #include <asm/setup.h>
  38. #include <asm/mach-types.h>
  39. #include <asm/mach/arch.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/page.h>
  42. #include <asm/mach/map.h>
  43. #include "common.h"
  44. #include "devices.h"
  45. /* NOR flash */
  46. #define AUTCPU12_FLASH_BASE (CS0_PHYS_BASE)
  47. /* Board specific hardware definitions */
  48. #define AUTCPU12_CHAR_LCD_BASE (CS1_PHYS_BASE + 0x00000000)
  49. #define AUTCPU12_CSAUX1_BASE (CS1_PHYS_BASE + 0x04000000)
  50. #define AUTCPU12_CAN_BASE (CS1_PHYS_BASE + 0x08000000)
  51. #define AUTCPU12_TOUCH_BASE (CS1_PHYS_BASE + 0x0a000000)
  52. #define AUTCPU12_IO_BASE (CS1_PHYS_BASE + 0x0c000000)
  53. #define AUTCPU12_LPT_BASE (CS1_PHYS_BASE + 0x0e000000)
  54. /* NVRAM */
  55. #define AUTCPU12_NVRAM_BASE (CS1_PHYS_BASE + 0x02000000)
  56. /* SmartMedia flash */
  57. #define AUTCPU12_SMC_BASE (CS1_PHYS_BASE + 0x06000000)
  58. #define AUTCPU12_SMC_SEL_BASE (AUTCPU12_SMC_BASE + 0x10)
  59. /* Ethernet */
  60. #define AUTCPU12_CS8900_BASE (CS2_PHYS_BASE + 0x300)
  61. #define AUTCPU12_CS8900_IRQ (IRQ_EINT3)
  62. /* NAND flash */
  63. #define AUTCPU12_MMGPIO_BASE (CLPS711X_NR_GPIO)
  64. #define AUTCPU12_SMC_NCE (AUTCPU12_MMGPIO_BASE + 0) /* Bit 0 */
  65. #define AUTCPU12_SMC_RDY CLPS711X_GPIO(1, 2)
  66. #define AUTCPU12_SMC_ALE CLPS711X_GPIO(1, 3)
  67. #define AUTCPU12_SMC_CLE CLPS711X_GPIO(1, 3)
  68. /* LCD contrast digital potentiometer */
  69. #define AUTCPU12_DPOT_CS CLPS711X_GPIO(4, 0)
  70. #define AUTCPU12_DPOT_CLK CLPS711X_GPIO(4, 1)
  71. #define AUTCPU12_DPOT_UD CLPS711X_GPIO(4, 2)
  72. static struct resource autcpu12_cs8900_resource[] __initdata = {
  73. DEFINE_RES_MEM(AUTCPU12_CS8900_BASE, SZ_1K),
  74. DEFINE_RES_IRQ(AUTCPU12_CS8900_IRQ),
  75. };
  76. static struct resource autcpu12_nand_resource[] __initdata = {
  77. DEFINE_RES_MEM(AUTCPU12_SMC_BASE, SZ_16),
  78. };
  79. static struct mtd_partition autcpu12_nand_parts[] __initdata = {
  80. {
  81. .name = "Flash partition 1",
  82. .offset = 0,
  83. .size = SZ_8M,
  84. },
  85. {
  86. .name = "Flash partition 2",
  87. .offset = MTDPART_OFS_APPEND,
  88. .size = MTDPART_SIZ_FULL,
  89. },
  90. };
  91. static void __init autcpu12_adjust_parts(struct gpio_nand_platdata *pdata,
  92. size_t sz)
  93. {
  94. switch (sz) {
  95. case SZ_16M:
  96. case SZ_32M:
  97. break;
  98. case SZ_64M:
  99. case SZ_128M:
  100. pdata->parts[0].size = SZ_16M;
  101. break;
  102. default:
  103. pr_warn("Unsupported SmartMedia device size %u\n", sz);
  104. break;
  105. }
  106. }
  107. static struct gpio_nand_platdata autcpu12_nand_pdata __initdata = {
  108. .gpio_rdy = AUTCPU12_SMC_RDY,
  109. .gpio_nce = AUTCPU12_SMC_NCE,
  110. .gpio_ale = AUTCPU12_SMC_ALE,
  111. .gpio_cle = AUTCPU12_SMC_CLE,
  112. .gpio_nwp = -1,
  113. .chip_delay = 20,
  114. .parts = autcpu12_nand_parts,
  115. .num_parts = ARRAY_SIZE(autcpu12_nand_parts),
  116. .adjust_parts = autcpu12_adjust_parts,
  117. };
  118. static struct platform_device autcpu12_nand_pdev __initdata = {
  119. .name = "gpio-nand",
  120. .id = -1,
  121. .resource = autcpu12_nand_resource,
  122. .num_resources = ARRAY_SIZE(autcpu12_nand_resource),
  123. .dev = {
  124. .platform_data = &autcpu12_nand_pdata,
  125. },
  126. };
  127. static struct resource autcpu12_mmgpio_resource[] __initdata = {
  128. DEFINE_RES_MEM_NAMED(AUTCPU12_SMC_SEL_BASE, SZ_1, "dat"),
  129. };
  130. static struct bgpio_pdata autcpu12_mmgpio_pdata __initdata = {
  131. .base = AUTCPU12_MMGPIO_BASE,
  132. .ngpio = 8,
  133. };
  134. static struct platform_device autcpu12_mmgpio_pdev __initdata = {
  135. .name = "basic-mmio-gpio",
  136. .id = -1,
  137. .resource = autcpu12_mmgpio_resource,
  138. .num_resources = ARRAY_SIZE(autcpu12_mmgpio_resource),
  139. .dev = {
  140. .platform_data = &autcpu12_mmgpio_pdata,
  141. },
  142. };
  143. static const struct gpio autcpu12_gpios[] __initconst = {
  144. { AUTCPU12_DPOT_CS, GPIOF_OUT_INIT_HIGH, "DPOT CS" },
  145. { AUTCPU12_DPOT_CLK, GPIOF_OUT_INIT_LOW, "DPOT CLK" },
  146. { AUTCPU12_DPOT_UD, GPIOF_OUT_INIT_LOW, "DPOT UD" },
  147. };
  148. static struct mtd_partition autcpu12_flash_partitions[] = {
  149. {
  150. .name = "NOR.0",
  151. .offset = 0,
  152. .size = MTDPART_SIZ_FULL,
  153. },
  154. };
  155. static struct physmap_flash_data autcpu12_flash_pdata = {
  156. .width = 4,
  157. .parts = autcpu12_flash_partitions,
  158. .nr_parts = ARRAY_SIZE(autcpu12_flash_partitions),
  159. };
  160. static struct resource autcpu12_flash_resources[] __initdata = {
  161. DEFINE_RES_MEM(AUTCPU12_FLASH_BASE, SZ_8M),
  162. };
  163. static struct platform_device autcpu12_flash_pdev __initdata = {
  164. .name = "physmap-flash",
  165. .id = 0,
  166. .resource = autcpu12_flash_resources,
  167. .num_resources = ARRAY_SIZE(autcpu12_flash_resources),
  168. .dev = {
  169. .platform_data = &autcpu12_flash_pdata,
  170. },
  171. };
  172. static struct resource autcpu12_nvram_resource[] __initdata = {
  173. DEFINE_RES_MEM(AUTCPU12_NVRAM_BASE, 0),
  174. };
  175. static struct platdata_mtd_ram autcpu12_nvram_pdata = {
  176. .bankwidth = 4,
  177. };
  178. static struct platform_device autcpu12_nvram_pdev __initdata = {
  179. .name = "mtd-ram",
  180. .id = 0,
  181. .resource = autcpu12_nvram_resource,
  182. .num_resources = ARRAY_SIZE(autcpu12_nvram_resource),
  183. .dev = {
  184. .platform_data = &autcpu12_nvram_pdata,
  185. },
  186. };
  187. static void __init autcpu12_nvram_init(void)
  188. {
  189. void __iomem *nvram;
  190. unsigned int save[2];
  191. resource_size_t nvram_size = SZ_128K;
  192. /*
  193. * Check for 32K/128K
  194. * Read ofs 0K
  195. * Read ofs 64K
  196. * Write complement to ofs 64K
  197. * Read and check result on ofs 0K
  198. * Restore contents
  199. */
  200. nvram = ioremap(autcpu12_nvram_resource[0].start, SZ_128K);
  201. if (nvram) {
  202. save[0] = readl(nvram + 0);
  203. save[1] = readl(nvram + SZ_64K);
  204. writel(~save[0], nvram + SZ_64K);
  205. if (readl(nvram + 0) != save[0]) {
  206. writel(save[0], nvram + 0);
  207. nvram_size = SZ_32K;
  208. } else
  209. writel(save[1], nvram + SZ_64K);
  210. iounmap(nvram);
  211. autcpu12_nvram_resource[0].end =
  212. autcpu12_nvram_resource[0].start + nvram_size - 1;
  213. platform_device_register(&autcpu12_nvram_pdev);
  214. } else
  215. pr_err("Failed to remap NVRAM resource\n");
  216. }
  217. static void __init autcpu12_init(void)
  218. {
  219. clps711x_devices_init();
  220. platform_device_register(&autcpu12_flash_pdev);
  221. platform_device_register_simple("video-clps711x", 0, NULL, 0);
  222. platform_device_register_simple("cs89x0", 0, autcpu12_cs8900_resource,
  223. ARRAY_SIZE(autcpu12_cs8900_resource));
  224. platform_device_register(&autcpu12_mmgpio_pdev);
  225. autcpu12_nvram_init();
  226. }
  227. static void __init autcpu12_init_late(void)
  228. {
  229. gpio_request_array(autcpu12_gpios, ARRAY_SIZE(autcpu12_gpios));
  230. if (IS_ENABLED(MTD_NAND_GPIO) && IS_ENABLED(GPIO_GENERIC_PLATFORM)) {
  231. /* We are need both drivers to handle NAND */
  232. platform_device_register(&autcpu12_nand_pdev);
  233. }
  234. }
  235. MACHINE_START(AUTCPU12, "autronix autcpu12")
  236. /* Maintainer: Thomas Gleixner */
  237. .atag_offset = 0x20000,
  238. .nr_irqs = CLPS711X_NR_IRQS,
  239. .map_io = clps711x_map_io,
  240. .init_early = clps711x_init_early,
  241. .init_irq = clps711x_init_irq,
  242. .init_time = clps711x_timer_init,
  243. .init_machine = autcpu12_init,
  244. .init_late = autcpu12_init_late,
  245. .handle_irq = clps711x_handle_irq,
  246. .restart = clps711x_restart,
  247. MACHINE_END