eeepc-laptop: Register as a pci-hotplug device
[linux-2.6/linux-acpi-2.6.git] / arch / powerpc / platforms / 44x / warp.c
blob42e09a9f77e264ecd0a87cd580a2254f1216de4c
1 /*
2 * PIKA Warp(tm) board specific routines
4 * Copyright (c) 2008-2009 PIKA Technologies
5 * Sean MacLennan <smaclennan@pikatech.com>
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.
12 #include <linux/init.h>
13 #include <linux/of_platform.h>
14 #include <linux/kthread.h>
15 #include <linux/i2c.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/of_gpio.h>
20 #include <asm/machdep.h>
21 #include <asm/prom.h>
22 #include <asm/udbg.h>
23 #include <asm/time.h>
24 #include <asm/uic.h>
25 #include <asm/ppc4xx.h>
28 static __initdata struct of_device_id warp_of_bus[] = {
29 { .compatible = "ibm,plb4", },
30 { .compatible = "ibm,opb", },
31 { .compatible = "ibm,ebc", },
32 {},
35 static int __init warp_device_probe(void)
37 of_platform_bus_probe(NULL, warp_of_bus, NULL);
38 return 0;
40 machine_device_initcall(warp, warp_device_probe);
42 static int __init warp_probe(void)
44 unsigned long root = of_get_flat_dt_root();
46 if (!of_flat_dt_is_compatible(root, "pika,warp"))
47 return 0;
49 /* For __dma_alloc_coherent */
50 ISA_DMA_THRESHOLD = ~0L;
52 return 1;
55 define_machine(warp) {
56 .name = "Warp",
57 .probe = warp_probe,
58 .progress = udbg_progress,
59 .init_IRQ = uic_init_tree,
60 .get_irq = uic_get_irq,
61 .restart = ppc4xx_reset_system,
62 .calibrate_decr = generic_calibrate_decr,
66 static u32 post_info;
68 /* I am not sure this is the best place for this... */
69 static int __init warp_post_info(void)
71 struct device_node *np;
72 void __iomem *fpga;
73 u32 post1, post2;
75 /* Sighhhh... POST information is in the sd area. */
76 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
77 if (np == NULL)
78 return -ENOENT;
80 fpga = of_iomap(np, 0);
81 of_node_put(np);
82 if (fpga == NULL)
83 return -ENOENT;
85 post1 = in_be32(fpga + 0x40);
86 post2 = in_be32(fpga + 0x44);
88 iounmap(fpga);
90 if (post1 || post2) {
91 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
92 post_info = 1;
93 } else
94 printk(KERN_INFO "Warp POST OK\n");
96 return 0;
100 #ifdef CONFIG_SENSORS_AD7414
102 static LIST_HEAD(dtm_shutdown_list);
103 static void __iomem *dtm_fpga;
104 static unsigned green_led, red_led;
107 struct dtm_shutdown {
108 struct list_head list;
109 void (*func)(void *arg);
110 void *arg;
114 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
116 struct dtm_shutdown *shutdown;
118 shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
119 if (shutdown == NULL)
120 return -ENOMEM;
122 shutdown->func = func;
123 shutdown->arg = arg;
125 list_add(&shutdown->list, &dtm_shutdown_list);
127 return 0;
130 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
132 struct dtm_shutdown *shutdown;
134 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
135 if (shutdown->func == func && shutdown->arg == arg) {
136 list_del(&shutdown->list);
137 kfree(shutdown);
138 return 0;
141 return -EINVAL;
144 static irqreturn_t temp_isr(int irq, void *context)
146 struct dtm_shutdown *shutdown;
147 int value = 1;
149 local_irq_disable();
151 gpio_set_value(green_led, 0);
153 /* Run through the shutdown list. */
154 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
155 shutdown->func(shutdown->arg);
157 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");
159 while (1) {
160 if (dtm_fpga) {
161 unsigned reset = in_be32(dtm_fpga + 0x14);
162 out_be32(dtm_fpga + 0x14, reset);
165 gpio_set_value(red_led, value);
166 value ^= 1;
167 mdelay(500);
171 static int pika_setup_leds(void)
173 struct device_node *np, *child;
175 np = of_find_compatible_node(NULL, NULL, "gpio-leds");
176 if (!np) {
177 printk(KERN_ERR __FILE__ ": Unable to find leds\n");
178 return -ENOENT;
181 for_each_child_of_node(np, child)
182 if (strcmp(child->name, "green") == 0) {
183 green_led = of_get_gpio(child, 0);
184 /* Turn back on the green LED */
185 gpio_set_value(green_led, 1);
186 } else if (strcmp(child->name, "red") == 0) {
187 red_led = of_get_gpio(child, 0);
188 /* Set based on post */
189 gpio_set_value(red_led, post_info);
192 of_node_put(np);
194 return 0;
197 static void pika_setup_critical_temp(struct i2c_client *client)
199 struct device_node *np;
200 int irq, rc;
202 /* Do this before enabling critical temp interrupt since we
203 * may immediately interrupt.
205 pika_setup_leds();
207 /* These registers are in 1 degree increments. */
208 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
209 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
211 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
212 if (np == NULL) {
213 printk(KERN_ERR __FILE__ ": Unable to find ad7414\n");
214 return;
217 irq = irq_of_parse_and_map(np, 0);
218 of_node_put(np);
219 if (irq == NO_IRQ) {
220 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
221 return;
224 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
225 if (rc) {
226 printk(KERN_ERR __FILE__
227 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
228 return;
232 static inline void pika_dtm_check_fan(void __iomem *fpga)
234 static int fan_state;
235 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
237 if (fan_state != fan) {
238 fan_state = fan;
239 if (fan)
240 printk(KERN_WARNING "Fan rotation error detected."
241 " Please check hardware.\n");
245 static int pika_dtm_thread(void __iomem *fpga)
247 struct i2c_adapter *adap;
248 struct i2c_client *client;
250 /* We loop in case either driver was compiled as a module and
251 * has not been insmoded yet.
253 while (!(adap = i2c_get_adapter(0))) {
254 set_current_state(TASK_INTERRUPTIBLE);
255 schedule_timeout(HZ);
258 while (1) {
259 list_for_each_entry(client, &adap->clients, list)
260 if (client->addr == 0x4a)
261 goto found_it;
263 set_current_state(TASK_INTERRUPTIBLE);
264 schedule_timeout(HZ);
267 found_it:
268 pika_setup_critical_temp(client);
270 i2c_put_adapter(adap);
272 printk(KERN_INFO "PIKA DTM thread running.\n");
274 while (!kthread_should_stop()) {
275 int val;
277 val = i2c_smbus_read_word_data(client, 0);
278 if (val < 0)
279 dev_dbg(&client->dev, "DTM read temp failed.\n");
280 else {
281 s16 temp = swab16(val);
282 out_be32(fpga + 0x20, temp);
285 pika_dtm_check_fan(fpga);
287 set_current_state(TASK_INTERRUPTIBLE);
288 schedule_timeout(HZ);
291 return 0;
295 static int __init pika_dtm_start(void)
297 struct task_struct *dtm_thread;
298 struct device_node *np;
300 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
301 if (np == NULL)
302 return -ENOENT;
304 dtm_fpga = of_iomap(np, 0);
305 of_node_put(np);
306 if (dtm_fpga == NULL)
307 return -ENOENT;
309 /* Must get post info before thread starts. */
310 warp_post_info();
312 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
313 if (IS_ERR(dtm_thread)) {
314 iounmap(dtm_fpga);
315 return PTR_ERR(dtm_thread);
318 return 0;
320 machine_late_initcall(warp, pika_dtm_start);
322 #else /* !CONFIG_SENSORS_AD7414 */
324 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
326 return 0;
329 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
331 return 0;
334 machine_late_initcall(warp, warp_post_info);
336 #endif
338 EXPORT_SYMBOL(pika_dtm_register_shutdown);
339 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);