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,
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 device_node *np,
198 struct i2c_client *client)
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 irq = irq_of_parse_and_map(np, 0);
213 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
217 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
219 printk(KERN_ERR __FILE__
220 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
225 static inline void pika_dtm_check_fan(void __iomem *fpga)
227 static int fan_state;
228 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
230 if (fan_state != fan) {
233 printk(KERN_WARNING "Fan rotation error detected."
234 " Please check hardware.\n");
238 static int pika_dtm_thread(void __iomem *fpga)
240 struct device_node *np;
241 struct i2c_client *client;
243 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
247 client = of_find_i2c_device_by_node(np);
248 if (client == NULL) {
253 pika_setup_critical_temp(np, client);
257 printk(KERN_INFO "Warp DTM thread running.\n");
259 while (!kthread_should_stop()) {
262 val = i2c_smbus_read_word_data(client, 0);
264 dev_dbg(&client->dev, "DTM read temp failed.\n");
266 s16 temp = swab16(val);
267 out_be32(fpga + 0x20, temp);
270 pika_dtm_check_fan(fpga);
272 set_current_state(TASK_INTERRUPTIBLE);
273 schedule_timeout(HZ);
279 static int __init pika_dtm_start(void)
281 struct task_struct *dtm_thread;
282 struct device_node *np;
284 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
288 dtm_fpga = of_iomap(np, 0);
290 if (dtm_fpga == NULL)
293 /* Must get post info before thread starts. */
296 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
297 if (IS_ERR(dtm_thread)) {
299 return PTR_ERR(dtm_thread);
304 machine_late_initcall(warp, pika_dtm_start);
306 #else /* !CONFIG_SENSORS_AD7414 */
308 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
313 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
318 machine_late_initcall(warp, warp_post_info);
322 EXPORT_SYMBOL(pika_dtm_register_shutdown);
323 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);