board-acs5k.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * arch/arm/mach-ks8695/board-acs5k.c
  3. *
  4. * Brivo Systems LLC, ACS-5000 Master Board
  5. *
  6. * Copyright 2008 Simtec Electronics
  7. * Daniel Silverstone <dsilvers@simtec.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/gpio.h>
  14. #include <linux/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/i2c.h>
  20. #include <linux/i2c-algo-bit.h>
  21. #include <linux/i2c-gpio.h>
  22. #include <linux/platform_data/pca953x.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/map.h>
  25. #include <linux/mtd/physmap.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/irq.h>
  31. #include "devices.h"
  32. #include <mach/gpio-ks8695.h>
  33. #include "generic.h"
  34. static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = {
  35. .sda_pin = 4,
  36. .scl_pin = 5,
  37. .udelay = 10,
  38. };
  39. static struct platform_device acs5k_i2c_device = {
  40. .name = "i2c-gpio",
  41. .id = -1,
  42. .num_resources = 0,
  43. .resource = NULL,
  44. .dev = {
  45. .platform_data = &acs5k_i2c_device_platdata,
  46. },
  47. };
  48. static int acs5k_pca9555_setup(struct i2c_client *client,
  49. unsigned gpio_base, unsigned ngpio,
  50. void *context)
  51. {
  52. static int acs5k_gpio_value[] = {
  53. -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, -1, 0, 1, 0, -1, -1
  54. };
  55. int n;
  56. for (n = 0; n < ARRAY_SIZE(acs5k_gpio_value); ++n) {
  57. gpio_request(gpio_base + n, "ACS-5000 GPIO Expander");
  58. if (acs5k_gpio_value[n] < 0)
  59. gpio_direction_input(gpio_base + n);
  60. else
  61. gpio_direction_output(gpio_base + n,
  62. acs5k_gpio_value[n]);
  63. gpio_export(gpio_base + n, 0); /* Export, direction locked down */
  64. }
  65. return 0;
  66. }
  67. static struct pca953x_platform_data acs5k_i2c_pca9555_platdata = {
  68. .gpio_base = 16, /* Start directly after the CPU's GPIO */
  69. .invert = 0, /* Do not invert */
  70. .setup = acs5k_pca9555_setup,
  71. };
  72. static struct i2c_board_info acs5k_i2c_devs[] __initdata = {
  73. {
  74. I2C_BOARD_INFO("pcf8563", 0x51),
  75. },
  76. {
  77. I2C_BOARD_INFO("pca9555", 0x20),
  78. .platform_data = &acs5k_i2c_pca9555_platdata,
  79. },
  80. };
  81. static void acs5k_i2c_init(void)
  82. {
  83. /* The gpio interface */
  84. platform_device_register(&acs5k_i2c_device);
  85. /* I2C devices */
  86. i2c_register_board_info(0, acs5k_i2c_devs,
  87. ARRAY_SIZE(acs5k_i2c_devs));
  88. }
  89. static struct mtd_partition acs5k_nor_partitions[] = {
  90. [0] = {
  91. .name = "Boot Agent and config",
  92. .size = SZ_256K,
  93. .offset = 0,
  94. .mask_flags = MTD_WRITEABLE,
  95. },
  96. [1] = {
  97. .name = "Kernel",
  98. .size = SZ_1M,
  99. .offset = SZ_256K,
  100. },
  101. [2] = {
  102. .name = "SquashFS1",
  103. .size = SZ_2M,
  104. .offset = SZ_256K + SZ_1M,
  105. },
  106. [3] = {
  107. .name = "SquashFS2",
  108. .size = SZ_4M + SZ_2M,
  109. .offset = SZ_256K + SZ_1M + SZ_2M,
  110. },
  111. [4] = {
  112. .name = "Data",
  113. .size = SZ_16M + SZ_4M + SZ_2M + SZ_512K, /* 22.5 MB */
  114. .offset = SZ_256K + SZ_8M + SZ_1M,
  115. }
  116. };
  117. static struct physmap_flash_data acs5k_nor_pdata = {
  118. .width = 4,
  119. .nr_parts = ARRAY_SIZE(acs5k_nor_partitions),
  120. .parts = acs5k_nor_partitions,
  121. };
  122. static struct resource acs5k_nor_resource[] = {
  123. [0] = {
  124. .start = SZ_32M, /* We expect the bootloader to map
  125. * the flash here.
  126. */
  127. .end = SZ_32M + SZ_16M - 1,
  128. .flags = IORESOURCE_MEM,
  129. },
  130. [1] = {
  131. .start = SZ_32M + SZ_16M,
  132. .end = SZ_32M + SZ_32M - SZ_256K - 1,
  133. .flags = IORESOURCE_MEM,
  134. }
  135. };
  136. static struct platform_device acs5k_device_nor = {
  137. .name = "physmap-flash",
  138. .id = -1,
  139. .num_resources = ARRAY_SIZE(acs5k_nor_resource),
  140. .resource = acs5k_nor_resource,
  141. .dev = {
  142. .platform_data = &acs5k_nor_pdata,
  143. },
  144. };
  145. static void __init acs5k_register_nor(void)
  146. {
  147. int ret;
  148. if (acs5k_nor_partitions[0].mask_flags == 0)
  149. printk(KERN_WARNING "Warning: Unprotecting bootloader and configuration partition\n");
  150. ret = platform_device_register(&acs5k_device_nor);
  151. if (ret < 0)
  152. printk(KERN_ERR "failed to register physmap-flash device\n");
  153. }
  154. static int __init acs5k_protection_setup(char *s)
  155. {
  156. /* We can't allocate anything here but we should be able
  157. * to trivially parse s and decide if we can protect the
  158. * bootloader partition or not
  159. */
  160. if (strcmp(s, "no") == 0)
  161. acs5k_nor_partitions[0].mask_flags = 0;
  162. return 1;
  163. }
  164. __setup("protect_bootloader=", acs5k_protection_setup);
  165. static void __init acs5k_init_gpio(void)
  166. {
  167. int i;
  168. ks8695_register_gpios();
  169. for (i = 0; i < 4; ++i)
  170. gpio_request(i, "ACS5K IRQ");
  171. gpio_request(7, "ACS5K KS_FRDY");
  172. for (i = 8; i < 16; ++i)
  173. gpio_request(i, "ACS5K Unused");
  174. gpio_request(3, "ACS5K CAN Control");
  175. gpio_request(6, "ACS5K Heartbeat");
  176. gpio_direction_output(3, 1); /* Default CAN_RESET high */
  177. gpio_direction_output(6, 0); /* Default KS8695_ACTIVE low */
  178. gpio_export(3, 0); /* export CAN_RESET as output only */
  179. gpio_export(6, 0); /* export KS8695_ACTIVE as output only */
  180. }
  181. static void __init acs5k_init(void)
  182. {
  183. acs5k_init_gpio();
  184. /* Network device */
  185. ks8695_add_device_lan(); /* eth0 = LAN */
  186. ks8695_add_device_wan(); /* ethX = WAN */
  187. /* NOR devices */
  188. acs5k_register_nor();
  189. /* I2C bus */
  190. acs5k_i2c_init();
  191. }
  192. MACHINE_START(ACS5K, "Brivo Systems LLC ACS-5000 Master board")
  193. /* Maintainer: Simtec Electronics. */
  194. .atag_offset = 0x100,
  195. .map_io = ks8695_map_io,
  196. .init_irq = ks8695_init_irq,
  197. .init_machine = acs5k_init,
  198. .init_time = ks8695_timer_init,
  199. .restart = ks8695_restart,
  200. MACHINE_END