board-acs5k.c 5.7 KB

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