warp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * PIKA Warp(tm) board specific routines
  3. *
  4. * Copyright (c) 2008 PIKA Technologies
  5. * Sean MacLennan <smaclennan@pikatech.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/kthread.h>
  15. #include <asm/machdep.h>
  16. #include <asm/prom.h>
  17. #include <asm/udbg.h>
  18. #include <asm/time.h>
  19. #include <asm/uic.h>
  20. #include <asm/ppc4xx.h>
  21. static __initdata struct of_device_id warp_of_bus[] = {
  22. { .compatible = "ibm,plb4", },
  23. { .compatible = "ibm,opb", },
  24. { .compatible = "ibm,ebc", },
  25. {},
  26. };
  27. static int __init warp_device_probe(void)
  28. {
  29. of_platform_bus_probe(NULL, warp_of_bus, NULL);
  30. return 0;
  31. }
  32. machine_device_initcall(warp, warp_device_probe);
  33. static int __init warp_probe(void)
  34. {
  35. unsigned long root = of_get_flat_dt_root();
  36. return of_flat_dt_is_compatible(root, "pika,warp");
  37. }
  38. define_machine(warp) {
  39. .name = "Warp",
  40. .probe = warp_probe,
  41. .progress = udbg_progress,
  42. .init_IRQ = uic_init_tree,
  43. .get_irq = uic_get_irq,
  44. .restart = ppc4xx_reset_system,
  45. .calibrate_decr = generic_calibrate_decr,
  46. };
  47. #define LED_GREEN (0x80000000 >> 0)
  48. #define LED_RED (0x80000000 >> 1)
  49. /* This is for the power LEDs 1 = on, 0 = off, -1 = leave alone */
  50. void warp_set_power_leds(int green, int red)
  51. {
  52. static void __iomem *gpio_base = NULL;
  53. unsigned leds;
  54. if (gpio_base == NULL) {
  55. struct device_node *np;
  56. /* Power LEDS are on the second GPIO controller */
  57. np = of_find_compatible_node(NULL, NULL, "ibm,gpio-440EP");
  58. if (np)
  59. np = of_find_compatible_node(np, NULL, "ibm,gpio-440EP");
  60. if (np == NULL) {
  61. printk(KERN_ERR __FILE__ ": Unable to find gpio\n");
  62. return;
  63. }
  64. gpio_base = of_iomap(np, 0);
  65. of_node_put(np);
  66. if (gpio_base == NULL) {
  67. printk(KERN_ERR __FILE__ ": Unable to map gpio");
  68. return;
  69. }
  70. }
  71. leds = in_be32(gpio_base);
  72. switch (green) {
  73. case 0: leds &= ~LED_GREEN; break;
  74. case 1: leds |= LED_GREEN; break;
  75. }
  76. switch (red) {
  77. case 0: leds &= ~LED_RED; break;
  78. case 1: leds |= LED_RED; break;
  79. }
  80. out_be32(gpio_base, leds);
  81. }
  82. EXPORT_SYMBOL(warp_set_power_leds);
  83. #ifdef CONFIG_SENSORS_AD7414
  84. static int pika_dtm_thread(void __iomem *fpga)
  85. {
  86. extern int ad7414_get_temp(int index);
  87. while (!kthread_should_stop()) {
  88. int temp = ad7414_get_temp(0);
  89. out_be32(fpga, temp);
  90. set_current_state(TASK_INTERRUPTIBLE);
  91. schedule_timeout(HZ);
  92. }
  93. return 0;
  94. }
  95. static int __init pika_dtm_start(void)
  96. {
  97. struct task_struct *dtm_thread;
  98. struct device_node *np;
  99. struct resource res;
  100. void __iomem *fpga;
  101. np = of_find_compatible_node(NULL, NULL, "pika,fpga");
  102. if (np == NULL)
  103. return -ENOENT;
  104. /* We do not call of_iomap here since it would map in the entire
  105. * fpga space, which is over 8k.
  106. */
  107. if (of_address_to_resource(np, 0, &res)) {
  108. of_node_put(np);
  109. return -ENOENT;
  110. }
  111. of_node_put(np);
  112. fpga = ioremap(res.start, 0x24);
  113. if (fpga == NULL)
  114. return -ENOENT;
  115. dtm_thread = kthread_run(pika_dtm_thread, fpga + 0x20, "pika-dtm");
  116. if (IS_ERR(dtm_thread)) {
  117. iounmap(fpga);
  118. return PTR_ERR(dtm_thread);
  119. }
  120. return 0;
  121. }
  122. device_initcall(pika_dtm_start);
  123. #endif