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>
19 #include <linux/of_i2c.h>
21 #include <asm/machdep.h>
26 #include <asm/ppc4xx.h>
29 static __initdata struct of_device_id warp_of_bus[] = {
30 { .compatible = "ibm,plb4", },
31 { .compatible = "ibm,opb", },
32 { .compatible = "ibm,ebc", },
36 static int __init warp_device_probe(void)
38 of_platform_bus_probe(NULL, warp_of_bus, NULL);
41 machine_device_initcall(warp, warp_device_probe);
43 static int __init warp_probe(void)
45 unsigned long root = of_get_flat_dt_root();
47 if (!of_flat_dt_is_compatible(root, "pika,warp"))
50 /* For __dma_alloc_coherent */
51 ISA_DMA_THRESHOLD = ~0L;
56 define_machine(warp) {
59 .progress = udbg_progress,
60 .init_IRQ = uic_init_tree,
61 .get_irq = uic_get_irq,
62 .restart = ppc4xx_reset_system,
63 .calibrate_decr = generic_calibrate_decr,
67 static int __init warp_post_info(void)
69 struct device_node *np;
73 /* Sighhhh... POST information is in the sd area. */
74 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
78 fpga = of_iomap(np, 0);
83 post1 = in_be32(fpga + 0x40);
84 post2 = in_be32(fpga + 0x44);
89 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
91 printk(KERN_INFO "Warp POST OK\n");
97 #ifdef CONFIG_SENSORS_AD7414
99 static LIST_HEAD(dtm_shutdown_list);
100 static void __iomem *dtm_fpga;
101 static unsigned green_led, red_led;
104 struct dtm_shutdown {
105 struct list_head list;
106 void (*func)(void *arg);
111 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
113 struct dtm_shutdown *shutdown;
115 shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
116 if (shutdown == NULL)
119 shutdown->func = func;
122 list_add(&shutdown->list, &dtm_shutdown_list);
127 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
129 struct dtm_shutdown *shutdown;
131 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
132 if (shutdown->func == func && shutdown->arg == arg) {
133 list_del(&shutdown->list);
141 static irqreturn_t temp_isr(int irq, void *context)
143 struct dtm_shutdown *shutdown;
148 gpio_set_value(green_led, 0);
150 /* Run through the shutdown list. */
151 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
152 shutdown->func(shutdown->arg);
154 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");
158 unsigned reset = in_be32(dtm_fpga + 0x14);
159 out_be32(dtm_fpga + 0x14, reset);
162 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 else if (strcmp(child->name, "red") == 0)
185 red_led = of_get_gpio(child, 0);
192 static void pika_setup_critical_temp(struct device_node *np,
193 struct i2c_client *client)
197 /* Do this before enabling critical temp interrupt since we
198 * may immediately interrupt.
202 /* These registers are in 1 degree increments. */
203 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
204 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
206 irq = irq_of_parse_and_map(np, 0);
208 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
212 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
214 printk(KERN_ERR __FILE__
215 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
220 static inline void pika_dtm_check_fan(void __iomem *fpga)
222 static int fan_state;
223 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
225 if (fan_state != fan) {
228 printk(KERN_WARNING "Fan rotation error detected."
229 " Please check hardware.\n");
233 static int pika_dtm_thread(void __iomem *fpga)
235 struct device_node *np;
236 struct i2c_client *client;
238 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
242 client = of_find_i2c_device_by_node(np);
243 if (client == NULL) {
248 pika_setup_critical_temp(np, client);
252 printk(KERN_INFO "Warp DTM thread running.\n");
254 while (!kthread_should_stop()) {
257 val = i2c_smbus_read_word_data(client, 0);
259 dev_dbg(&client->dev, "DTM read temp failed.\n");
261 s16 temp = swab16(val);
262 out_be32(fpga + 0x20, temp);
265 pika_dtm_check_fan(fpga);
267 set_current_state(TASK_INTERRUPTIBLE);
268 schedule_timeout(HZ);
274 static int __init pika_dtm_start(void)
276 struct task_struct *dtm_thread;
277 struct device_node *np;
279 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
283 dtm_fpga = of_iomap(np, 0);
285 if (dtm_fpga == NULL)
288 /* Must get post info before thread starts. */
291 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
292 if (IS_ERR(dtm_thread)) {
294 return PTR_ERR(dtm_thread);
299 machine_late_initcall(warp, pika_dtm_start);
301 #else /* !CONFIG_SENSORS_AD7414 */
303 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
308 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
313 machine_late_initcall(warp, warp_post_info);
317 EXPORT_SYMBOL(pika_dtm_register_shutdown);
318 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);