slarmUnprocessedDataOperation.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Buffalo Terastation Pro II/Live Board Setup
  3. *
  4. * Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/gpio.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pci.h>
  16. #include <linux/irq.h>
  17. #include <linux/delay.h>
  18. #include <linux/mtd/physmap.h>
  19. #include <linux/mv643xx_eth.h>
  20. #include <linux/i2c.h>
  21. #include <linux/serial_reg.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/pci.h>
  25. #include <mach/orion5x.h>
  26. #include "common.h"
  27. #include "mpp.h"
  28. /*****************************************************************************
  29. * Terastation Pro 2/Live Info
  30. ****************************************************************************/
  31. /*
  32. * Terastation Pro 2 hardware :
  33. * - Marvell 88F5281-D0
  34. * - Marvell 88SX6042 SATA controller (PCI)
  35. * - Marvell 88E1118 Gigabit Ethernet PHY
  36. * - 256KB NOR flash
  37. * - 128MB of DDR RAM
  38. * - PCIe port (not equipped)
  39. */
  40. /*
  41. * 256K NOR flash Device bus boot chip select
  42. */
  43. #define TSP2_NOR_BOOT_BASE 0xf4000000
  44. #define TSP2_NOR_BOOT_SIZE SZ_256K
  45. /*****************************************************************************
  46. * 256KB NOR Flash on BOOT Device
  47. ****************************************************************************/
  48. static struct physmap_flash_data tsp2_nor_flash_data = {
  49. .width = 1,
  50. };
  51. static struct resource tsp2_nor_flash_resource = {
  52. .flags = IORESOURCE_MEM,
  53. .start = TSP2_NOR_BOOT_BASE,
  54. .end = TSP2_NOR_BOOT_BASE + TSP2_NOR_BOOT_SIZE - 1,
  55. };
  56. static struct platform_device tsp2_nor_flash = {
  57. .name = "physmap-flash",
  58. .id = 0,
  59. .dev = {
  60. .platform_data = &tsp2_nor_flash_data,
  61. },
  62. .num_resources = 1,
  63. .resource = &tsp2_nor_flash_resource,
  64. };
  65. /*****************************************************************************
  66. * PCI
  67. ****************************************************************************/
  68. #define TSP2_PCI_SLOT0_OFFS 7
  69. #define TSP2_PCI_SLOT0_IRQ_PIN 11
  70. void __init tsp2_pci_preinit(void)
  71. {
  72. int pin;
  73. /*
  74. * Configure PCI GPIO IRQ pins
  75. */
  76. pin = TSP2_PCI_SLOT0_IRQ_PIN;
  77. if (gpio_request(pin, "PCI Int1") == 0) {
  78. if (gpio_direction_input(pin) == 0) {
  79. irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
  80. } else {
  81. printk(KERN_ERR "tsp2_pci_preinit failed "
  82. "to set_irq_type pin %d\n", pin);
  83. gpio_free(pin);
  84. }
  85. } else {
  86. printk(KERN_ERR "tsp2_pci_preinit failed to "
  87. "gpio_request %d\n", pin);
  88. }
  89. }
  90. static int __init tsp2_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  91. {
  92. int irq;
  93. /*
  94. * Check for devices with hard-wired IRQs.
  95. */
  96. irq = orion5x_pci_map_irq(dev, slot, pin);
  97. if (irq != -1)
  98. return irq;
  99. /*
  100. * PCI IRQs are connected via GPIOs.
  101. */
  102. if (slot == TSP2_PCI_SLOT0_OFFS)
  103. return gpio_to_irq(TSP2_PCI_SLOT0_IRQ_PIN);
  104. return -1;
  105. }
  106. static struct hw_pci tsp2_pci __initdata = {
  107. .nr_controllers = 2,
  108. .preinit = tsp2_pci_preinit,
  109. .setup = orion5x_pci_sys_setup,
  110. .scan = orion5x_pci_sys_scan_bus,
  111. .map_irq = tsp2_pci_map_irq,
  112. };
  113. static int __init tsp2_pci_init(void)
  114. {
  115. if (machine_is_terastation_pro2())
  116. pci_common_init(&tsp2_pci);
  117. return 0;
  118. }
  119. subsys_initcall(tsp2_pci_init);
  120. /*****************************************************************************
  121. * Ethernet
  122. ****************************************************************************/
  123. static struct mv643xx_eth_platform_data tsp2_eth_data = {
  124. .phy_addr = 0,
  125. };
  126. /*****************************************************************************
  127. * RTC 5C372a on I2C bus
  128. ****************************************************************************/
  129. #define TSP2_RTC_GPIO 9
  130. static struct i2c_board_info __initdata tsp2_i2c_rtc = {
  131. I2C_BOARD_INFO("rs5c372a", 0x32),
  132. };
  133. /*****************************************************************************
  134. * Terastation Pro II specific power off method via UART1-attached
  135. * microcontroller
  136. ****************************************************************************/
  137. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  138. static int tsp2_miconread(unsigned char *buf, int count)
  139. {
  140. int i;
  141. int timeout;
  142. for (i = 0; i < count; i++) {
  143. timeout = 10;
  144. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  145. if (--timeout == 0)
  146. break;
  147. udelay(1000);
  148. }
  149. if (timeout == 0)
  150. break;
  151. buf[i] = readl(UART1_REG(RX));
  152. }
  153. /* return read bytes */
  154. return i;
  155. }
  156. static int tsp2_miconwrite(const unsigned char *buf, int count)
  157. {
  158. int i = 0;
  159. while (count--) {
  160. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  161. barrier();
  162. writel(buf[i++], UART1_REG(TX));
  163. }
  164. return 0;
  165. }
  166. static int tsp2_miconsend(const unsigned char *data, int count)
  167. {
  168. int i;
  169. unsigned char checksum = 0;
  170. unsigned char recv_buf[40];
  171. unsigned char send_buf[40];
  172. unsigned char correct_ack[3];
  173. int retry = 2;
  174. /* Generate checksum */
  175. for (i = 0; i < count; i++)
  176. checksum -= data[i];
  177. do {
  178. /* Send data */
  179. tsp2_miconwrite(data, count);
  180. /* send checksum */
  181. tsp2_miconwrite(&checksum, 1);
  182. if (tsp2_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  183. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  184. /* send preamble to clear the receive buffer */
  185. memset(&send_buf, 0xff, sizeof(send_buf));
  186. tsp2_miconwrite(send_buf, sizeof(send_buf));
  187. /* make dummy reads */
  188. mdelay(100);
  189. tsp2_miconread(recv_buf, sizeof(recv_buf));
  190. } else {
  191. /* Generate expected ack */
  192. correct_ack[0] = 0x01;
  193. correct_ack[1] = data[1];
  194. correct_ack[2] = 0x00;
  195. /* checksum Check */
  196. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  197. recv_buf[3]) & 0xFF) {
  198. printk(KERN_ERR ">%s: Checksum Error : "
  199. "Received data[%02x, %02x, %02x, %02x]"
  200. "\n", __func__, recv_buf[0],
  201. recv_buf[1], recv_buf[2], recv_buf[3]);
  202. } else {
  203. /* Check Received Data */
  204. if (correct_ack[0] == recv_buf[0] &&