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>
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", },
35 static int __init warp_device_probe(void)
37 of_platform_bus_probe(NULL, warp_of_bus, NULL);
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"))
49 /* For __dma_alloc_coherent */
50 ISA_DMA_THRESHOLD = ~0L;
55 define_machine(warp) {
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,
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;
75 /* Sighhhh... POST information is in the sd area. */
76 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
80 fpga = of_iomap(np, 0);
85 post1 = in_be32(fpga + 0x40);
86 post2 = in_be32(fpga + 0x44);
91 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
94 printk(KERN_INFO "Warp POST OK\n");
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);
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)
122 shutdown->func = func;
125 list_add(&shutdown->list, &dtm_shutdown_list);
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);
144 static irqreturn_t temp_isr(int irq, void *context)
146 struct dtm_shutdown *shutdown;
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");
161 unsigned reset = in_be32(dtm_fpga + 0x14);
162 out_be32(dtm_fpga + 0x14, reset);
165 gpio_set_value(red_led, value);
171 static int pika_setup_leds(void)
173 struct device_node *np, *child;
175 np = of_find_compatible_node(NULL, NULL, "gpio-leds");
177 printk(KERN_ERR __FILE__ ": Unable to find leds\n");
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);
197 static void pika_setup_critical_temp(struct i2c_client *client)
199 struct device_node *np;
202 /* Do this before enabling critical temp interrupt since we
203 * may immediately interrupt.
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");
213 printk(KERN_ERR __FILE__ ": Unable to find ad7414\n");
217 irq = irq_of_parse_and_map(np, 0);
220 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
224 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
226 printk(KERN_ERR __FILE__
227 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
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) {
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);
259 list_for_each_entry(client, &adap->clients, list)
260 if (client->addr == 0x4a)
263 set_current_state(TASK_INTERRUPTIBLE);
264 schedule_timeout(HZ);
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()) {
277 val = i2c_smbus_read_word_data(client, 0);
279 dev_dbg(&client->dev, "DTM read temp failed.\n");
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);
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");
304 dtm_fpga = of_iomap(np, 0);
306 if (dtm_fpga == NULL)
309 /* Must get post info before thread starts. */
312 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
313 if (IS_ERR(dtm_thread)) {
315 return PTR_ERR(dtm_thread);
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)
329 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
334 machine_late_initcall(warp, warp_post_info);
338 EXPORT_SYMBOL(pika_dtm_register_shutdown);
339 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);