setup.c 4.0 KB

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