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/slab.h>
20 #include <linux/export.h>
22 #include <asm/machdep.h>
27 #include <asm/ppc4xx.h>
30 static __initdata
struct of_device_id warp_of_bus
[] = {
31 { .compatible
= "ibm,plb4", },
32 { .compatible
= "ibm,opb", },
33 { .compatible
= "ibm,ebc", },
37 static int __init
warp_device_probe(void)
39 of_platform_bus_probe(NULL
, warp_of_bus
, NULL
);
42 machine_device_initcall(warp
, warp_device_probe
);
44 static int __init
warp_probe(void)
46 unsigned long root
= of_get_flat_dt_root();
48 if (!of_flat_dt_is_compatible(root
, "pika,warp"))
51 /* For __dma_alloc_coherent */
52 ISA_DMA_THRESHOLD
= ~0L;
57 define_machine(warp
) {
60 .progress
= udbg_progress
,
61 .init_IRQ
= uic_init_tree
,
62 .get_irq
= uic_get_irq
,
63 .restart
= ppc4xx_reset_system
,
64 .calibrate_decr
= generic_calibrate_decr
,
68 static int __init
warp_post_info(void)
70 struct device_node
*np
;
74 /* Sighhhh... POST information is in the sd area. */
75 np
= of_find_compatible_node(NULL
, NULL
, "pika,fpga-sd");
79 fpga
= of_iomap(np
, 0);
84 post1
= in_be32(fpga
+ 0x40);
85 post2
= in_be32(fpga
+ 0x44);
90 printk(KERN_INFO
"Warp POST %08x %08x\n", post1
, post2
);
92 printk(KERN_INFO
"Warp POST OK\n");
98 #ifdef CONFIG_SENSORS_AD7414
100 static LIST_HEAD(dtm_shutdown_list
);
101 static void __iomem
*dtm_fpga
;
102 static unsigned green_led
, red_led
;
105 struct dtm_shutdown
{
106 struct list_head list
;
107 void (*func
)(void *arg
);
112 int pika_dtm_register_shutdown(void (*func
)(void *arg
), void *arg
)
114 struct dtm_shutdown
*shutdown
;
116 shutdown
= kmalloc(sizeof(struct dtm_shutdown
), GFP_KERNEL
);
117 if (shutdown
== NULL
)
120 shutdown
->func
= func
;
123 list_add(&shutdown
->list
, &dtm_shutdown_list
);
128 int pika_dtm_unregister_shutdown(void (*func
)(void *arg
), void *arg
)
130 struct dtm_shutdown
*shutdown
;
132 list_for_each_entry(shutdown
, &dtm_shutdown_list
, list
)
133 if (shutdown
->func
== func
&& shutdown
->arg
== arg
) {
134 list_del(&shutdown
->list
);
142 static irqreturn_t
temp_isr(int irq
, void *context
)
144 struct dtm_shutdown
*shutdown
;
149 gpio_set_value(green_led
, 0);
151 /* Run through the shutdown list. */
152 list_for_each_entry(shutdown
, &dtm_shutdown_list
, list
)
153 shutdown
->func(shutdown
->arg
);
155 printk(KERN_EMERG
"\n\nCritical Temperature Shutdown\n\n");
159 unsigned reset
= in_be32(dtm_fpga
+ 0x14);
160 out_be32(dtm_fpga
+ 0x14, reset
);
163 gpio_set_value(red_led
, value
);
172 static int pika_setup_leds(void)
174 struct device_node
*np
, *child
;
176 np
= of_find_compatible_node(NULL
, NULL
, "gpio-leds");
178 printk(KERN_ERR __FILE__
": Unable to find leds\n");
182 for_each_child_of_node(np
, child
)
183 if (strcmp(child
->name
, "green") == 0)
184 green_led
= of_get_gpio(child
, 0);
185 else if (strcmp(child
->name
, "red") == 0)
186 red_led
= of_get_gpio(child
, 0);
193 static void pika_setup_critical_temp(struct device_node
*np
,
194 struct i2c_client
*client
)
198 /* Do this before enabling critical temp interrupt since we
199 * may immediately interrupt.
203 /* These registers are in 1 degree increments. */
204 i2c_smbus_write_byte_data(client
, 2, 65); /* Thigh */
205 i2c_smbus_write_byte_data(client
, 3, 0); /* Tlow */
207 irq
= irq_of_parse_and_map(np
, 0);
209 printk(KERN_ERR __FILE__
": Unable to get ad7414 irq\n");
213 rc
= request_irq(irq
, temp_isr
, 0, "ad7414", NULL
);
215 printk(KERN_ERR __FILE__
216 ": Unable to request ad7414 irq %d = %d\n", irq
, rc
);
221 static inline void pika_dtm_check_fan(void __iomem
*fpga
)
223 static int fan_state
;
224 u32 fan
= in_be32(fpga
+ 0x34) & (1 << 14);
226 if (fan_state
!= fan
) {
229 printk(KERN_WARNING
"Fan rotation error detected."
230 " Please check hardware.\n");
234 static int pika_dtm_thread(void __iomem
*fpga
)
236 struct device_node
*np
;
237 struct i2c_client
*client
;
239 np
= of_find_compatible_node(NULL
, NULL
, "adi,ad7414");
243 client
= of_find_i2c_device_by_node(np
);
244 if (client
== NULL
) {
249 pika_setup_critical_temp(np
, client
);
253 printk(KERN_INFO
"Warp DTM thread running.\n");
255 while (!kthread_should_stop()) {
258 val
= i2c_smbus_read_word_data(client
, 0);
260 dev_dbg(&client
->dev
, "DTM read temp failed.\n");
262 s16 temp
= swab16(val
);
263 out_be32(fpga
+ 0x20, temp
);
266 pika_dtm_check_fan(fpga
);
268 set_current_state(TASK_INTERRUPTIBLE
);
269 schedule_timeout(HZ
);
275 static int __init
pika_dtm_start(void)
277 struct task_struct
*dtm_thread
;
278 struct device_node
*np
;
280 np
= of_find_compatible_node(NULL
, NULL
, "pika,fpga");
284 dtm_fpga
= of_iomap(np
, 0);
286 if (dtm_fpga
== NULL
)
289 /* Must get post info before thread starts. */
292 dtm_thread
= kthread_run(pika_dtm_thread
, dtm_fpga
, "pika-dtm");
293 if (IS_ERR(dtm_thread
)) {
295 return PTR_ERR(dtm_thread
);
300 machine_late_initcall(warp
, pika_dtm_start
);
302 #else /* !CONFIG_SENSORS_AD7414 */
304 int pika_dtm_register_shutdown(void (*func
)(void *arg
), void *arg
)
309 int pika_dtm_unregister_shutdown(void (*func
)(void *arg
), void *arg
)
314 machine_late_initcall(warp
, warp_post_info
);
318 EXPORT_SYMBOL(pika_dtm_register_shutdown
);
319 EXPORT_SYMBOL(pika_dtm_unregister_shutdown
);