setup.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 <asm/machvec.h>
  18. #include <asm/heartbeat.h>
  19. #include <asm/sizes.h>
  20. static struct resource heartbeat_resource = {
  21. .start = 0x07fff8b0,
  22. .end = 0x07fff8b0 + sizeof(u16) - 1,
  23. .flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,
  24. };
  25. static struct platform_device heartbeat_device = {
  26. .name = "heartbeat",
  27. .id = -1,
  28. .num_resources = 1,
  29. .resource = &heartbeat_resource,
  30. };
  31. static struct resource smsc911x_resources[] = {
  32. [0] = {
  33. .name = "smsc911x-memory",
  34. .start = 0x07ffff00,
  35. .end = 0x07ffff00 + SZ_256 - 1,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .name = "smsc911x-irq",
  40. .start = evt2irq(0x2c0),
  41. .end = evt2irq(0x2c0),
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct smsc911x_platform_config smsc911x_config = {
  46. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  47. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  48. .flags = SMSC911X_USE_32BIT,
  49. .phy_interface = PHY_INTERFACE_MODE_MII,
  50. };
  51. static struct platform_device smsc911x_device = {
  52. .name = "smsc911x",
  53. .id = -1,
  54. .num_resources = ARRAY_SIZE(smsc911x_resources),
  55. .resource = smsc911x_resources,
  56. .dev = {
  57. .platform_data = &smsc911x_config,
  58. },
  59. };
  60. static struct resource smbus_fpga_resource = {
  61. .start = 0x07fff9e0,
  62. .end = 0x07fff9e0 + SZ_32 - 1,
  63. .flags = IORESOURCE_MEM,
  64. };
  65. static struct platform_device smbus_fpga_device = {
  66. .name = "i2c-sdk7786",
  67. .id = 0,
  68. .num_resources = 1,
  69. .resource = &smbus_fpga_resource,
  70. };
  71. static struct resource smbus_pcie_resource = {
  72. .start = 0x07fffc30,
  73. .end = 0x07fffc30 + SZ_32 - 1,
  74. .flags = IORESOURCE_MEM,
  75. };
  76. static struct platform_device smbus_pcie_device = {
  77. .name = "i2c-sdk7786",
  78. .id = 1,
  79. .num_resources = 1,
  80. .resource = &smbus_pcie_resource,
  81. };
  82. static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {
  83. {
  84. I2C_BOARD_INFO("max6900", 0x68),
  85. },
  86. };
  87. static struct platform_device *sh7786_devices[] __initdata = {
  88. &heartbeat_device,
  89. &smsc911x_device,
  90. &smbus_fpga_device,
  91. &smbus_pcie_device,
  92. };
  93. #define SBCR_REGS_BASE 0x07fff990
  94. #define SCBR_I2CMEN (1 << 0) /* FPGA I2C master enable */
  95. #define SCBR_I2CCEN (1 << 1) /* CPU I2C master enable */
  96. static int sdk7786_i2c_setup(void)
  97. {
  98. void __iomem *sbcr;
  99. unsigned int tmp;
  100. sbcr = ioremap_nocache(SBCR_REGS_BASE, SZ_16);
  101. /*
  102. * Hand over I2C control to the FPGA.
  103. */
  104. tmp = ioread16(sbcr);
  105. tmp &= ~SCBR_I2CCEN;
  106. tmp |= SCBR_I2CMEN;
  107. iowrite16(tmp, sbcr);
  108. iounmap(sbcr);
  109. return i2c_register_board_info(0, sdk7786_i2c_devices,
  110. ARRAY_SIZE(sdk7786_i2c_devices));
  111. }
  112. static int __init sdk7786_devices_setup(void)
  113. {
  114. int ret;
  115. ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));
  116. if (unlikely(ret != 0))
  117. return ret;
  118. return sdk7786_i2c_setup();
  119. }
  120. __initcall(sdk7786_devices_setup);
  121. #define FPGA_REGS_BASE 0x07fff800
  122. #define FPGA_REGS_SIZE 1152
  123. #define INTASR 0x010
  124. #define INTAMR 0x020
  125. #define INTBSR 0x090
  126. #define INTBMR 0x0a0
  127. #define INTMSR 0x130
  128. #define IASELR1 0x210
  129. #define IASELR2 0x220
  130. #define IASELR3 0x230
  131. #define IASELR4 0x240
  132. #define IASELR5 0x250
  133. #define IASELR6 0x260
  134. #define IASELR7 0x270
  135. #define IASELR8 0x280
  136. #define IASELR9 0x290
  137. #define IASELR10 0x2a0
  138. #define IASELR11 0x2b0
  139. #define IASELR12 0x2c0
  140. #define IASELR13 0x2d0
  141. #define IASELR14 0x2e0
  142. #define IASELR15 0x2f0
  143. static void __iomem *fpga_regs;
  144. static u16 fpga_read_reg(unsigned int reg)
  145. {
  146. return __raw_readw(fpga_regs + reg);
  147. }
  148. static void fpga_write_reg(u16 val, unsigned int reg)
  149. {
  150. __raw_writew(val, fpga_regs + reg);
  151. }
  152. enum {
  153. ATA_IRQ_BIT = 1,
  154. SPI_BUSY_BIT = 2,
  155. LIRQ5_BIT = 3,
  156. LIRQ6_BIT = 4,
  157. LIRQ7_BIT = 5,
  158. LIRQ8_BIT = 6,
  159. KEY_IRQ_BIT = 7,
  160. PEN_IRQ_BIT = 8,
  161. ETH_IRQ_BIT = 9,
  162. RTC_ALARM_BIT = 10,
  163. CRYSTAL_FAIL_BIT = 12,
  164. ETH_PME_BIT = 14,
  165. };
  166. static void __init init_sdk7786_IRQ(void)
  167. {
  168. unsigned int tmp;
  169. fpga_regs = ioremap_nocache(FPGA_REGS_BASE, FPGA_REGS_SIZE);
  170. if (!fpga_regs) {
  171. printk(KERN_ERR "Couldn't map FPGA registers\n");
  172. return;
  173. }
  174. /* Enable priority encoding for all IRLs */
  175. fpga_write_reg(fpga_read_reg(INTMSR) | 0x0303, INTMSR);
  176. /* Clear FPGA interrupt status registers */
  177. fpga_write_reg(0x0000, INTASR);
  178. fpga_write_reg(0x0000, INTBSR);
  179. /* Unmask FPGA interrupts */
  180. tmp = fpga_read_reg(INTAMR);
  181. tmp &= ~(1 << ETH_IRQ_BIT);
  182. fpga_write_reg(tmp, INTAMR);
  183. plat_irq_setup_pins(IRQ_MODE_IRL7654_MASK);
  184. plat_irq_setup_pins(IRQ_MODE_IRL3210_MASK);
  185. }
  186. /* Initialize the board */
  187. static void __init sdk7786_setup(char **cmdline_p)
  188. {
  189. printk(KERN_INFO "Renesas Technology Corp. SDK7786 support.\n");
  190. }
  191. /*
  192. * The Machine Vector
  193. */
  194. static struct sh_machine_vector mv_sdk7786 __initmv = {
  195. .mv_name = "SDK7786",
  196. .mv_setup = sdk7786_setup,
  197. .mv_init_irq = init_sdk7786_IRQ,
  198. };