setup.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Renesas Technology Europe SDK7786 Support.
  3. *
  4. * Copyright (C) 2010 Matt Fleming
  5. * Copyright (C) 2010 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/io.h>
  14. #include <linux/smsc911x.h>
  15. #include <linux/i2c.h>
  16. #include <linux/irq.h>
  17. #include <linux/clk.h>
  18. #include <linux/clkdev.h>
  19. #include <mach/fpga.h>
  20. #include <mach/irq.h>
  21. #include <asm/machvec.h>
  22. #include <asm/heartbeat.h>
  23. #include <asm/sizes.h>
  24. #include <asm/clock.h>
  25. #include <asm/reboot.h>
  26. #include <asm/smp-ops.h>
  27. static struct resource heartbeat_resource = {
  28. .start = 0x07fff8b0,
  29. .end = 0x07fff8b0 + sizeof(u16) - 1,
  30. .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,
  31. };
  32. static struct platform_device heartbeat_device = {
  33. .name = "heartbeat",
  34. .id = -1,
  35. .num_resources = 1,
  36. .resource = &heartbeat_resource,
  37. };
  38. static struct resource smsc911x_resources[] = {
  39. [0] = {
  40. .name = "smsc911x-memory",
  41. .start = 0x07ffff00,
  42. .end = 0x07ffff00 + SZ_256 - 1,
  43. .flags = IORESOURCE_MEM,
  44. },
  45. [1] = {
  46. .name = "smsc911x-irq",
  47. .start = evt2irq(0x2c0),
  48. .end = evt2irq(0x2c0),
  49. .flags = IORESOURCE_IRQ,
  50. },
  51. };
  52. static struct smsc911x_platform_config smsc911x_config = {
  53. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  54. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  55. .flags = SMSC911X_USE_32BIT,
  56. .phy_interface = PHY_INTERFACE_MODE_MII,
  57. };
  58. static struct platform_device smsc911x_device = {
  59. .name = "smsc911x",
  60. .id = -1,
  61. .num_resources = ARRAY_SIZE(smsc911x_resources),
  62. .resource = smsc911x_resources,
  63. .dev = {
  64. .platform_data = &smsc911x_config,
  65. },
  66. };
  67. static struct resource smbus_fpga_resource = {
  68. .start = 0x07fff9e0,
  69. .end = 0x07fff9e0 + SZ_32 - 1,
  70. .flags = IORESOURCE_MEM,
  71. };
  72. static struct platform_device smbus_fpga_device = {
  73. .name = "i2c-sdk7786",
  74. .id = 0,
  75. .num_resources = 1,
  76. .resource = &smbus_fpga_resource,
  77. };
  78. static struct resource smbus_pcie_resource = {
  79. .start = 0x07fffc30,
  80. .end = 0x07fffc30 + SZ_32 - 1,
  81. .flags = IORESOURCE_MEM,
  82. };
  83. static struct platform_device smbus_pcie_device = {
  84. .name = "i2c-sdk7786",
  85. .id = 1,
  86. .num_resources = 1,
  87. .resource = &smbus_pcie_resource,
  88. };
  89. static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {
  90. {
  91. I2C_BOARD_INFO("max6900", 0x68),
  92. },
  93. };
  94. static struct platform_device *sh7786_devices[] __initdata = {
  95. &heartbeat_device,
  96. &smsc911x_device,
  97. &smbus_fpga_device,
  98. &smbus_pcie_device,
  99. };
  100. static int sdk7786_i2c_setup(void)
  101. {
  102. unsigned int tmp;
  103. /*
  104. * Hand over I2C control to the FPGA.
  105. */
  106. tmp = fpga_read_reg(SBCR);
  107. tmp &= ~SCBR_I2CCEN;
  108. tmp |= SCBR_I2CMEN;
  109. fpga_write_reg(tmp, SBCR);
  110. return i2c_register_board_info(0, sdk7786_i2c_devices,
  111. ARRAY_SIZE(sdk7786_i2c_devices));
  112. }
  113. static int __init sdk7786_devices_setup(void)
  114. {
  115. int ret;
  116. ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));
  117. if (unlikely(ret != 0))
  118. return ret;
  119. return sdk7786_i2c_setup();
  120. }
  121. device_initcall(sdk7786_devices_setup);
  122. static int sdk7786_mode_pins(void)
  123. {
  124. return fpga_read_reg(MODSWR);
  125. }
  126. /*
  127. * FPGA-driven PCIe clocks
  128. *
  129. * Historically these include the oscillator, clock B (slots 2/3/4) and
  130. * clock A (slot 1 and the CPU clock). Newer revs of the PCB shove
  131. * everything under a single PCIe clocks enable bit that happens to map
  132. * to the same bit position as the oscillator bit for earlier FPGA
  133. * versions.
  134. *
  135. * Given that the legacy clocks have the side-effect of shutting the CPU
  136. * off through the FPGA along with the PCI slots, we simply leave them in
  137. * their initial state and don't bother registering them with the clock
  138. * framework.
  139. */
  140. static int sdk7786_pcie_clk_enable(struct clk *clk)
  141. {
  142. fpga_write_reg(fpga_read_reg(PCIECR) | PCIECR_CLKEN, PCIECR);
  143. return 0;
  144. }
  145. static void sdk7786_pcie_clk_disable(struct clk *clk)
  146. {
  147. fpga_write_reg(fpga_read_reg(PCIECR) & ~PCIECR_CLKEN, PCIECR);
  148. }
  149. static struct sh_clk_ops sdk7786_pcie_clk_ops = {
  150. .enable = sdk7786_pcie_clk_enable,
  151. .disable = sdk7786_pcie_clk_disable,
  152. };
  153. static struct clk sdk7786_pcie_clk = {
  154. .ops = &sdk7786_pcie_clk_ops,
  155. };
  156. static struct clk_lookup sdk7786_pcie_cl = {
  157. .con_id = "pcie_plat_clk",
  158. .clk = &sdk7786_pcie_clk,
  159. };
  160. static int sdk7786_clk_init(void)
  161. {
  162. struct clk *clk;
  163. int ret;
  164. /*
  165. * Only handle the EXTAL case, anyone interfacing a crystal
  166. * resonator will need to provide their own input clock.
  167. */
  168. if (test_mode_pin(MODE_PIN9))
  169. return -EINVAL;
  170. clk = clk_get(NULL, "extal");
  171. if (IS_ERR(clk))
  172. return PTR_ERR(clk);
  173. ret = clk_set_rate(clk, 33333333);
  174. clk_put(clk);
  175. /*
  176. * Setup the FPGA clocks.
  177. */
  178. ret = clk_register(&sdk7786_pcie_clk);
  179. if (unlikely(ret)) {
  180. pr_err("FPGA clock registration failed\n");
  181. return ret;
  182. }
  183. clkdev_add(&sdk7786_pcie_cl);
  184. return 0;
  185. }
  186. static void sdk7786_restart(char *cmd)
  187. {
  188. fpga_write_reg(0xa5a5, SRSTR);
  189. }
  190. static void sdk7786_power_off(void)
  191. {
  192. fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR);
  193. /*
  194. * It can take up to 20us for the R8C to do its job, back off and
  195. * wait a bit until we've been shut off. Even though newer FPGA
  196. * versions don't set the ACK bit, the latency issue remains.
  197. */
  198. while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0)
  199. cpu_sleep();
  200. }
  201. /* Initialize the board */
  202. static void __init sdk7786_setup(char **cmdline_p)
  203. {
  204. pr_info("Renesas Technology Europe SDK7786 support:\n");
  205. sdk7786_fpga_init();
  206. sdk7786_nmi_init();
  207. pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);
  208. machine_ops.restart = sdk7786_restart;
  209. pm_power_off = sdk7786_power_off;
  210. register_smp_ops(&shx3_smp_ops);
  211. }
  212. /*
  213. * The Machine Vector
  214. */
  215. static struct sh_machine_vector mv_sdk7786 __initmv = {
  216. .mv_name = "SDK7786",
  217. .mv_setup = sdk7786_setup,
  218. .mv_mode_pins = sdk7786_mode_pins,
  219. .mv_clk_init = sdk7786_clk_init,
  220. .mv_init_irq = sdk7786_init_irq,
  221. };