blob: 39cf6150a72b2701af6eb62348ce364b3d88ce26 [file] [log] [blame]
Sean MacLennanf9bdedb2008-01-22 04:55:29 +11001/*
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
16#include <asm/machdep.h>
17#include <asm/prom.h>
18#include <asm/udbg.h>
19#include <asm/time.h>
20#include <asm/uic.h>
Stefan Roese93173ce2008-03-28 01:43:31 +110021#include <asm/ppc4xx.h>
Sean MacLennanf9bdedb2008-01-22 04:55:29 +110022
23static __initdata struct of_device_id warp_of_bus[] = {
24 { .compatible = "ibm,plb4", },
25 { .compatible = "ibm,opb", },
26 { .compatible = "ibm,ebc", },
27 {},
28};
29
30static int __init warp_device_probe(void)
31{
32 of_platform_bus_probe(NULL, warp_of_bus, NULL);
33 return 0;
34}
35machine_device_initcall(warp, warp_device_probe);
36
37static int __init warp_probe(void)
38{
39 unsigned long root = of_get_flat_dt_root();
40
41 return of_flat_dt_is_compatible(root, "pika,warp");
42}
43
44define_machine(warp) {
45 .name = "Warp",
46 .probe = warp_probe,
47 .progress = udbg_progress,
48 .init_IRQ = uic_init_tree,
49 .get_irq = uic_get_irq,
Stefan Roese93173ce2008-03-28 01:43:31 +110050 .restart = ppc4xx_reset_system,
Sean MacLennanf9bdedb2008-01-22 04:55:29 +110051 .calibrate_decr = generic_calibrate_decr,
52};
53
54
55#define LED_GREEN (0x80000000 >> 0)
56#define LED_RED (0x80000000 >> 1)
57
58
59/* This is for the power LEDs 1 = on, 0 = off, -1 = leave alone */
60void warp_set_power_leds(int green, int red)
61{
62 static void __iomem *gpio_base = NULL;
63 unsigned leds;
64
65 if (gpio_base == NULL) {
66 struct device_node *np;
67
68 /* Power LEDS are on the second GPIO controller */
69 np = of_find_compatible_node(NULL, NULL, "ibm,gpio-440EP");
70 if (np)
71 np = of_find_compatible_node(np, NULL, "ibm,gpio-440EP");
72 if (np == NULL) {
73 printk(KERN_ERR __FILE__ ": Unable to find gpio\n");
74 return;
75 }
76
77 gpio_base = of_iomap(np, 0);
78 of_node_put(np);
79 if (gpio_base == NULL) {
80 printk(KERN_ERR __FILE__ ": Unable to map gpio");
81 return;
82 }
83 }
84
85 leds = in_be32(gpio_base);
86
87 switch (green) {
88 case 0: leds &= ~LED_GREEN; break;
89 case 1: leds |= LED_GREEN; break;
90 }
91 switch (red) {
92 case 0: leds &= ~LED_RED; break;
93 case 1: leds |= LED_RED; break;
94 }
95
96 out_be32(gpio_base, leds);
97}
98EXPORT_SYMBOL(warp_set_power_leds);
99
100
101#ifdef CONFIG_SENSORS_AD7414
102static int pika_dtm_thread(void __iomem *fpga)
103{
104 extern int ad7414_get_temp(int index);
105
106 while (!kthread_should_stop()) {
107 int temp = ad7414_get_temp(0);
108
109 out_be32(fpga, temp);
110
111 set_current_state(TASK_INTERRUPTIBLE);
112 schedule_timeout(HZ);
113 }
114
115 return 0;
116}
117
118static int __init pika_dtm_start(void)
119{
120 struct task_struct *dtm_thread;
121 struct device_node *np;
122 struct resource res;
123 void __iomem *fpga;
124
125 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
126 if (np == NULL)
127 return -ENOENT;
128
129 /* We do not call of_iomap here since it would map in the entire
130 * fpga space, which is over 8k.
131 */
132 if (of_address_to_resource(np, 0, &res)) {
133 of_node_put(np);
134 return -ENOENT;
135 }
136 of_node_put(np);
137
Sean MacLennanc41f4af2008-01-26 16:39:39 +1100138 fpga = ioremap(res.start, 0x24);
Sean MacLennanf9bdedb2008-01-22 04:55:29 +1100139 if (fpga == NULL)
140 return -ENOENT;
141
142 dtm_thread = kthread_run(pika_dtm_thread, fpga + 0x20, "pika-dtm");
143 if (IS_ERR(dtm_thread)) {
144 iounmap(fpga);
145 return PTR_ERR(dtm_thread);
146 }
147
148 return 0;
149}
150device_initcall(pika_dtm_start);
151#endif