dt2-setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*
  2. * arch/arm/mach-orion5x/dt2-setup.c
  3. *
  4. * Freecom DataTank Gateway Setup
  5. *
  6. * Copyright (C) 2009 Zintis Petersons <Zintis.Petersons@abcsolutions.lv>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  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/mtd/physmap.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/if_ether.h>
  21. #include <net/dsa.h>
  22. #include <linux/ata_platform.h>
  23. #include <linux/i2c.h>
  24. #include <linux/reboot.h>
  25. #include <linux/interrupt.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/gpio.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/pci.h>
  30. #include <mach/orion5x.h>
  31. #include "common.h"
  32. #include "mpp.h"
  33. /*****************************************************************************
  34. * DT2 local
  35. ****************************************************************************/
  36. #include <asm/setup.h>
  37. #include "dt2-common.h"
  38. u32 mvUbootVer = 0;
  39. u32 mvTclk = 166666667;
  40. u32 mvSysclk = 200000000;
  41. u32 mvIsUsbHost = 1;
  42. u32 overEthAddr = 0;
  43. u32 gBoardId = -1;
  44. struct DT2_EEPROM_STRUCT dt2_eeprom;
  45. /*****************************************************************************
  46. * DT2 Info
  47. ****************************************************************************/
  48. /*
  49. * PCI
  50. */
  51. #define DT2_PCI_SLOT0_OFFS 7
  52. #define DT2_PCI_SLOT0_IRQ_A_PIN 3
  53. #define DT2_PCI_SLOT0_IRQ_B_PIN 2
  54. #define DT2_PIN_GPIO_SYNC 25
  55. #define DT2_PIN_GPIO_POWER 24
  56. #define DT2_PIN_GPIO_UNPLUG1 23
  57. #define DT2_PIN_GPIO_UNPLUG2 22
  58. #define DT2_PIN_GPIO_RESET 4
  59. #define DT2_NOR_BOOT_BASE 0xf4000000
  60. #define DT2_NOR_BOOT_SIZE SZ_512K
  61. #define DT2_LEDS_BASE 0xfa000000
  62. #define DT2_LEDS_SIZE SZ_1K
  63. /*****************************************************************************
  64. * 512K NOR Flash on Device bus Boot CS
  65. ****************************************************************************/
  66. static struct mtd_partition dt2_partitions[] = {
  67. {
  68. .name = "u-boot",
  69. .size = 0x00080000,
  70. .offset = 0,
  71. },
  72. };
  73. static struct physmap_flash_data dt2_nor_flash_data = {
  74. .width = 1, /* 8 bit bus width */
  75. .parts = dt2_partitions,
  76. .nr_parts = ARRAY_SIZE(dt2_partitions)
  77. };
  78. static struct resource dt2_nor_flash_resource = {
  79. .flags = IORESOURCE_MEM,
  80. .start = DT2_NOR_BOOT_BASE,
  81. .end = DT2_NOR_BOOT_BASE + DT2_NOR_BOOT_SIZE - 1,
  82. };
  83. static struct platform_device dt2_nor_flash = {
  84. .name = "physmap-flash",
  85. .id = 0,
  86. .dev = {
  87. .platform_data = &dt2_nor_flash_data,
  88. },
  89. .resource = &dt2_nor_flash_resource,
  90. .num_resources = 1,
  91. };
  92. /*****************************************************************************
  93. * PCI
  94. ****************************************************************************/
  95. void __init dt2_pci_preinit(void)
  96. {
  97. int pin, irq;
  98. /*
  99. * Configure PCI GPIO IRQ pins
  100. */
  101. pin = DT2_PCI_SLOT0_IRQ_A_PIN;
  102. if (gpio_request(pin, "PCI IntA") == 0) {
  103. if (gpio_direction_input(pin) == 0) {
  104. irq = gpio_to_irq(pin);
  105. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_LOW);
  106. printk (KERN_INFO "PCI IntA IRQ: %d\n", irq);
  107. } else {
  108. printk(KERN_ERR "dt2_pci_preinit failed to "
  109. "irq_set_irq_type pin %d\n", pin);
  110. gpio_free(pin);
  111. }
  112. } else {
  113. printk(KERN_ERR "dt2_pci_preinit failed to request gpio %d\n", pin);
  114. }
  115. pin = DT2_PCI_SLOT0_IRQ_B_PIN;
  116. if (gpio_request(pin, "PCI IntB") == 0) {
  117. if (gpio_direction_input(pin) == 0) {
  118. irq = gpio_to_irq(pin);
  119. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_LOW);
  120. printk (KERN_INFO "PCI IntB IRQ: %d\n", irq);
  121. } else {
  122. printk(KERN_ERR "dt2_pci_preinit failed to "
  123. "irq_set_irq_type pin %d\n", pin);
  124. gpio_free(pin);
  125. }
  126. } else {
  127. printk(KERN_ERR "dt2_pci_preinit failed to gpio_request %d\n", pin);
  128. }
  129. }
  130. static int __init dt2_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  131. {
  132. int irq;
  133. /*
  134. * Check for devices with hard-wired IRQs.
  135. */
  136. irq = orion5x_pci_map_irq(dev, slot, pin);
  137. if (irq != -1){
  138. printk(KERN_INFO "orion5x_pci_map_irq: %d\n", irq);
  139. return irq;
  140. }
  141. /*
  142. * PCI IRQs are connected via GPIOs
  143. */
  144. switch (slot - DT2_PCI_SLOT0_OFFS) {
  145. case 0:
  146. if (pin == 1){
  147. irq = gpio_to_irq(DT2_PCI_SLOT0_IRQ_A_PIN);
  148. printk(KERN_INFO "dt2_pci_map_irq DT2_PCI_SLOT0_IRQ_A_PIN: %d\n", irq);
  149. }
  150. else {
  151. irq = gpio_to_irq(DT2_PCI_SLOT0_IRQ_B_PIN);
  152. printk(KERN_INFO "dt2_pci_map_irq DT2_PCI_SLOT0_IRQ_B_PIN: %d\n", irq);
  153. }
  154. default:
  155. irq = -1;
  156. printk(KERN_INFO "dt2_pci_map_irq IRQ: %d\n", irq);
  157. }
  158. return irq;
  159. }
  160. static struct hw_pci dt2_pci __initdata = {
  161. .nr_controllers = 2,
  162. .preinit = dt2_pci_preinit,
  163. .setup = orion5x_pci_sys_setup,
  164. .scan = orion5x_pci_sys_scan_bus,
  165. .map_irq = dt2_pci_map_irq,
  166. };
  167. static int __init dt2_pci_init(void)
  168. {
  169. if (machine_is_dt2())
  170. pci_common_init(&dt2_pci);
  171. return 0;
  172. }
  173. subsys_initcall(dt2_pci_init);
  174. /*****************************************************************************
  175. * Ethernet
  176. ****************************************************************************/
  177. static struct mv643xx_eth_platform_data dt2_eth_data = {
  178. .phy_addr = MV643XX_ETH_PHY_NONE,
  179. .speed = SPEED_1000,
  180. .duplex = DUPLEX_FULL,
  181. };
  182. static struct dsa_chip_data dt2_switch_chip_data = {
  183. .port_names[0] = "wan",
  184. .port_names[1] = "lan1",
  185. .port_names[2] = "lan2",
  186. .port_names[3] = "cpu",
  187. .port_names[4] = "lan3",
  188. .port_names[5] = "lan4",
  189. };
  190. static struct dsa_platform_data dt2_switch_plat_data = {
  191. .nr_chips = 1,
  192. .chip = &dt2_switch_chip_data,
  193. };
  194. /*****************************************************************************
  195. * RTC ISL1208 on I2C bus
  196. ****************************************************************************/
  197. static struct i2c_board_info __initdata dt2_i2c_rtc = {
  198. I2C_BOARD_INFO("isl1208", 0x6F),
  199. };
  200. /*****************************************************************************
  201. * Sata
  202. ****************************************************************************/
  203. static struct mv_sata_platform_data dt2_sata_data = {
  204. .n_ports = 2,
  205. };
  206. /*****************************************************************************
  207. * General Setup
  208. ****************************************************************************/
  209. static unsigned int dt2_mpp_modes[] __initdata = {
  210. MPP0_GPIO, // RTC interrupt
  211. MPP1_GPIO, // 88e6131 interrupt
  212. MPP2_GPIO, // PCI_intB
  213. MPP3_GPIO, // PCI_intA
  214. MPP4_GPIO, // reset button switch
  215. MPP5_GPIO,
  216. MPP6_GPIO,
  217. MPP7_GPIO,
  218. MPP8_GPIO,
  219. MPP9_GIGE, /* GE_RXERR */
  220. MPP10_GPIO, // usb
  221. MPP11_GPIO, // usb
  222. MPP12_GIGE, // GE_TXD[4]
  223. MPP13_GIGE, // GE_TXD[5]
  224. MPP14_GIGE, // GE_TXD[6]
  225. MPP15_GIGE, // GE_TXD[7]
  226. MPP16_GIGE, // GE_RXD[4]
  227. MPP17_GIGE, // GE_RXD[5]
  228. MPP18_GIGE, // GE_RXD[6]
  229. MPP19_GIGE, // GE_RXD[7]
  230. 0,
  231. };
  232. /*****************************************************************************
  233. * LEDS
  234. ****************************************************************************/
  235. static struct platform_device dt2_leds = {
  236. .name = "dt2-led",
  237. .id = -1,
  238. };
  239. /****************************************************************************
  240. * GPIO key
  241. ****************************************************************************/
  242. static irqreturn_t dt2_reset_handler(int irq, void *dev_id)
  243. {
  244. /* This is the paper-clip reset which does an emergency reboot. */
  245. printk(KERN_INFO "Restarting system.\n");
  246. machine_restart(NULL);
  247. /* This should never be reached. */
  248. return IRQ_HANDLED;
  249. }
  250. static irqreturn_t dt2_power_handler(int irq, void *dev_id)
  251. {
  252. printk(KERN_INFO "Shutting down system.\n");
  253. machine_power_off();
  254. return IRQ_HANDLED;
  255. }
  256. static void __init dt2_init(void)
  257. {
  258. /*
  259. * Setup basic Orion functions. Need to be called early.
  260. */
  261. orion5x_init();
  262. orion5x_mpp_conf(dt2_mpp_modes);
  263. /*
  264. * Configure peripherals.
  265. */
  266. orion5x_uart0_init();
  267. orion5x_ehci0_init();
  268. orion5x_ehci1_init();
  269. orion5x_i2c_init();
  270. orion5x_sata_init(&dt2_sata_data);
  271. orion5x_xor_init();
  272. printk(KERN_INFO "U-Boot parameters:\n");
  273. printk(KERN_INFO "Sys Clk = %d, Tclk = %d, BoardID = 0x%02x\n", mvSysclk, mvTclk, gBoardId);
  274. printk(KERN_INFO "Serial: %s\n", dt2_eeprom.fc.dt2_serial_number);
  275. printk(KERN_INFO "Revision: %016x\n", dt2_eeprom.fc.dt2_revision);
  276. printk(KERN_INFO "DT2: Using MAC address %pM for port 0\n",
  277. dt2_eeprom.gw.mac_addr[0]);
  278. printk(KERN_INFO "DT2: Using MAC address %pM for port 1\n",
  279. dt2_eeprom.gw.mac_addr[1]);
  280. orion5x_eth_init(&dt2_eth_data);
  281. memcpy(dt2_eth_data.mac_addr, dt2_eeprom.gw.mac_addr[0], 6);
  282. orion5x_eth_switch_init(&dt2_switch_plat_data, NO_IRQ);
  283. i2c_register_board_info(0, &dt2_i2c_rtc, 1);
  284. mvebu_mbus_add_window("devbus-boot", DT2_NOR_BOOT_BASE,
  285. DT2_NOR_BOOT_SIZE);
  286. platform_device_register(&dt2_nor_flash);
  287. mvebu_mbus_add_window("devbus-cs0", DT2_LEDS_BASE, DT2_LEDS_SIZE);
  288. platform_device_register(&dt2_leds);
  289. if (request_irq(gpio_to_irq(DT2_PIN_GPIO_RESET), &dt2_reset_handler,
  290. IRQF_TRIGGER_LOW,
  291. "DT2: Reset button", NULL) < 0) {
  292. printk("DT2: Reset Button IRQ %d not available\n",
  293. gpio_to_irq(DT2_PIN_GPIO_RESET));
  294. }
  295. if (request_irq(gpio_to_irq(DT2_PIN_GPIO_POWER), &dt2_power_handler,
  296. IRQF_TRIGGER_LOW,
  297. "DT2: Power button", NULL) < 0) {
  298. printk(KERN_DEBUG "DT2: Power Button IRQ %d not available\n",
  299. gpio_to_irq(DT2_PIN_GPIO_POWER));
  300. }
  301. }
  302. static int __init parse_tag_dt2_uboot(const struct tag *t)
  303. {
  304. struct tag_mv_uboot *mv_uboot;
  305. // Get pointer to our block
  306. mv_uboot = (struct tag_mv_uboot*)&t->u;
  307. mvTclk = mv_uboot->tclk;
  308. mvSysclk = mv_uboot->sysclk;
  309. mvUbootVer = mv_uboot->uboot_version;
  310. mvIsUsbHost = mv_uboot->isUsbHost;
  311. // Some clock fixups
  312. if(mvTclk == 166000000) mvTclk = 166666667;
  313. else if(mvTclk == 133000000) mvTclk = 133333333;
  314. else if(mvSysclk == 166000000) mvSysclk = 166666667;
  315. gBoardId = (mvUbootVer & 0xff);
  316. //DT2 specific data
  317. memcpy(&dt2_eeprom, mv_uboot->dt2_eeprom, sizeof(struct DT2_EEPROM_STRUCT));
  318. return 0;
  319. }
  320. __tagtable(ATAG_MV_UBOOT, parse_tag_dt2_uboot);
  321. /*
  322. * This is OpenWrt specific fixup. It includes code from original "tag_fixup_mem32" to
  323. * fixup bogus memory tags and also fixes kernel cmdline by adding " init=/etc/preinit"
  324. * at the end. It is important to flash OpenWrt image from original Freecom firmware.
  325. *
  326. * Vanilla kernel should use "tag_fixup_mem32" function.
  327. */
  328. void __init openwrt_fixup(struct tag *t, char **from, struct meminfo *meminfo)
  329. {
  330. char *p = NULL;
  331. static char openwrt_init_tag[] __initdata = " init=/etc/preinit";
  332. for (; t->hdr.size; t = tag_next(t)){
  333. /* Locate the Freecom cmdline */
  334. if (t->hdr.tag == ATAG_CMDLINE) {
  335. p = t->u.cmdline.cmdline;
  336. printk("%s(%d): Found cmdline '%s' at 0x%0lx\n",
  337. __FUNCTION__, __LINE__, p, (unsigned long)p);
  338. }
  339. /*
  340. * Many orion-based systems have buggy bootloader implementations.
  341. * This is a common fixup for bogus memory tags.
  342. */
  343. if (t->hdr.tag == ATAG_MEM &&
  344. (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
  345. t->u.mem.start & ~PAGE_MASK)) {
  346. printk(KERN_WARNING
  347. "Clearing invalid memory bank %dKB@0x%08x\n",
  348. t->u.mem.size / 1024, t->u.mem.start);
  349. t->hdr.tag = 0;
  350. }
  351. }
  352. printk("%s(%d): End of table at 0x%0lx\n", __FUNCTION__, __LINE__, (unsigned long)t);
  353. /* Overwrite the end of the table with a new cmdline tag. */
  354. t->hdr.tag = ATAG_CMDLINE;
  355. t->hdr.size =
  356. (sizeof (struct tag_header) +
  357. strlen(p) + strlen(openwrt_init_tag) + 1 + 4) >> 2;
  358. strlcpy(t->u.cmdline.cmdline, p, COMMAND_LINE_SIZE);
  359. strlcpy(t->u.cmdline.cmdline + strlen(p), openwrt_init_tag,
  360. COMMAND_LINE_SIZE - strlen(p));
  361. printk("%s(%d): New cmdline '%s' at 0x%0lx\n",
  362. __FUNCTION__, __LINE__,
  363. t->u.cmdline.cmdline, (unsigned long)t->u.cmdline.cmdline);
  364. t = tag_next(t);
  365. printk("%s(%d): New end of table at 0x%0lx\n", __FUNCTION__, __LINE__, (unsigned long)t);
  366. t->hdr.tag = ATAG_NONE;
  367. t->hdr.size = 0;
  368. }
  369. /* Warning: Freecom uses their own custom bootloader with mach-type (=1500) */
  370. MACHINE_START(DT2, "Freecom DataTank Gateway")
  371. /* Maintainer: Zintis Petersons <Zintis.Petersons@abcsolutions.lv> */
  372. .atag_offset = 0x100,
  373. .init_machine = dt2_init,
  374. .map_io = orion5x_map_io,
  375. .init_irq = orion5x_init_irq,
  376. .init_time = orion5x_timer_init,
  377. .fixup = openwrt_fixup, //tag_fixup_mem32,
  378. MACHINE_END