setup.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 <mach/fpga.h>
  19. #include <mach/irq.h>
  20. #include <asm/machvec.h>
  21. #include <asm/heartbeat.h>
  22. #include <asm/sizes.h>
  23. #include <asm/reboot.h>
  24. #include <asm/smp-ops.h>
  25. static struct resource heartbeat_resource = {
  26. .start = 0x07fff8b0,
  27. .end = 0x07fff8b0 + sizeof(u16) - 1,
  28. .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,
  29. };
  30. static struct platform_device heartbeat_device = {
  31. .name = "heartbeat",
  32. .id = -1,
  33. .num_resources = 1,
  34. .resource = &heartbeat_resource,
  35. };
  36. static struct resource smsc911x_resources[] = {
  37. [0] = {
  38. .name = "smsc911x-memory",
  39. .start = 0x07ffff00,
  40. .end = 0x07ffff00 + SZ_256 - 1,
  41. .flags = IORESOURCE_MEM,
  42. },
  43. [1] = {
  44. .name = "smsc911x-irq",
  45. .start = evt2irq(0x2c0),
  46. .end = evt2irq(0x2c0),
  47. .flags = IORESOURCE_IRQ,
  48. },
  49. };
  50. static struct smsc911x_platform_config smsc911x_config = {
  51. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  52. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  53. .flags = SMSC911X_USE_32BIT,
  54. .phy_interface = PHY_INTERFACE_MODE_MII,
  55. };
  56. static struct platform_device smsc911x_device = {
  57. .name = "smsc911x",
  58. .id = -1,
  59. .num_resources = ARRAY_SIZE(smsc911x_resources),
  60. .resource = smsc911x_resources,
  61. .dev = {
  62. .platform_data = &smsc911x_config,
  63. },
  64. };
  65. static struct resource smbus_fpga_resource = {
  66. .start = 0x07fff9e0,
  67. .end = 0x07fff9e0 + SZ_32 - 1,
  68. .flags = IORESOURCE_MEM,
  69. };
  70. static struct platform_device smbus_fpga_device = {
  71. .name = "i2c-sdk7786",
  72. .id = 0,
  73. .num_resources = 1,
  74. .resource = &smbus_fpga_resource,
  75. };
  76. static struct resource smbus_pcie_resource = {
  77. .start = 0x07fffc30,
  78. .end = 0x07fffc30 + SZ_32 - 1,
  79. .flags = IORESOURCE_MEM,
  80. };
  81. static struct platform_device smbus_pcie_device = {
  82. .name = "i2c-sdk7786",
  83. .id = 1,
  84. .num_resources = 1,
  85. .resource = &smbus_pcie_resource,
  86. };
  87. static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {
  88. {
  89. I2C_BOARD_INFO("max6900", 0x68),
  90. },
  91. };
  92. static struct platform_device *sh7786_devices[] __initdata = {
  93. &heartbeat_device,
  94. &smsc911x_device,
  95. &smbus_fpga_device,
  96. &smbus_pcie_device,
  97. };
  98. static int sdk7786_i2c_setup(void)
  99. {
  100. unsigned int tmp;
  101. /*
  102. * Hand over I2C control to the FPGA.
  103. */
  104. tmp = fpga_read_reg(SBCR);
  105. tmp &= ~SCBR_I2CCEN;
  106. tmp |= SCBR_I2CMEN;
  107. fpga_write_reg(tmp, SBCR);
  108. return i2c_register_board_info(0, sdk7786_i2c_devices,
  109. ARRAY_SIZE(sdk7786_i2c_devices));
  110. }
  111. static int __init sdk7786_devices_setup(void)
  112. {
  113. int ret;
  114. ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));
  115. if (unlikely(ret != 0))
  116. return ret;
  117. return sdk7786_i2c_setup();
  118. }
  119. __initcall(sdk7786_devices_setup);
  120. static int sdk7786_mode_pins(void)
  121. {
  122. return fpga_read_reg(MODSWR);
  123. }
  124. static int sdk7786_clk_init(void)
  125. {
  126. struct clk *clk;
  127. int ret;
  128. /*
  129. * Only handle the EXTAL case, anyone interfacing a crystal
  130. * resonator will need to provide their own input clock.
  131. */
  132. if (test_mode_pin(MODE_PIN9))
  133. return -EINVAL;
  134. clk = clk_get(NULL, "extal");
  135. if (!clk || IS_ERR(clk))
  136. return PTR_ERR(clk);
  137. ret = clk_set_rate(clk, 33333333);
  138. clk_put(clk);
  139. return ret;
  140. }
  141. static void sdk7786_restart(char *cmd)
  142. {
  143. fpga_write_reg(0xa5a5, SRSTR);
  144. }
  145. static void sdk7786_power_off(void)
  146. {
  147. fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR);
  148. /*
  149. * It can take up to 20us for the R8C to do its job, back off and
  150. * wait a bit until we've been shut off. Even though newer FPGA
  151. * versions don't set the ACK bit, the latency issue remains.
  152. */
  153. while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0)
  154. cpu_sleep();
  155. }
  156. /* Initialize the board */
  157. static void __init sdk7786_setup(char **cmdline_p)
  158. {
  159. pr_info("Renesas Technology Europe SDK7786 support:\n");
  160. sdk7786_fpga_init();
  161. pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);
  162. machine_ops.restart = sdk7786_restart;
  163. pm_power_off = sdk7786_power_off;
  164. register_smp_ops(&shx3_smp_ops);
  165. }
  166. /*
  167. * The Machine Vector
  168. */
  169. static struct sh_machine_vector mv_sdk7786 __initmv = {
  170. .mv_name = "SDK7786",
  171. .mv_setup = sdk7786_setup,
  172. .mv_mode_pins = sdk7786_mode_pins,
  173. .mv_clk_init = sdk7786_clk_init,
  174. .mv_init_irq = sdk7786_init_irq,
  175. };