2 * PIKA Warp(tm) board specific routines
4 * Copyright (c) 2008 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>
19 #include <asm/machdep.h>
24 #include <asm/ppc4xx.h>
26 static __initdata struct of_device_id warp_of_bus[] = {
27 { .compatible = "ibm,plb4", },
28 { .compatible = "ibm,opb", },
29 { .compatible = "ibm,ebc", },
33 static __initdata struct i2c_board_info warp_i2c_info[] = {
34 { I2C_BOARD_INFO("ad7414", 0x4a) }
37 static int __init warp_arch_init(void)
39 /* This should go away once support is moved to the dts. */
40 i2c_register_board_info(0, warp_i2c_info, ARRAY_SIZE(warp_i2c_info));
43 machine_arch_initcall(warp, warp_arch_init);
45 static int __init warp_device_probe(void)
47 of_platform_bus_probe(NULL, warp_of_bus, NULL);
50 machine_device_initcall(warp, warp_device_probe);
52 static int __init warp_probe(void)
54 unsigned long root = of_get_flat_dt_root();
56 return of_flat_dt_is_compatible(root, "pika,warp");
59 define_machine(warp) {
62 .progress = udbg_progress,
63 .init_IRQ = uic_init_tree,
64 .get_irq = uic_get_irq,
65 .restart = ppc4xx_reset_system,
66 .calibrate_decr = generic_calibrate_decr,
70 /* I am not sure this is the best place for this... */
71 static int __init warp_post_info(void)
73 struct device_node *np;
77 /* Sighhhh... POST information is in the sd area. */
78 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
82 fpga = of_iomap(np, 0);
87 post1 = in_be32(fpga + 0x40);
88 post2 = in_be32(fpga + 0x44);
93 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
95 printk(KERN_INFO "Warp POST OK\n");
99 machine_late_initcall(warp, warp_post_info);
102 #ifdef CONFIG_SENSORS_AD7414
104 static LIST_HEAD(dtm_shutdown_list);
105 static void __iomem *dtm_fpga;
106 static void __iomem *gpio_base;
109 struct dtm_shutdown {
110 struct list_head list;
111 void (*func)(void *arg);
116 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
118 struct dtm_shutdown *shutdown;
120 shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
121 if (shutdown == NULL)
124 shutdown->func = func;
127 list_add(&shutdown->list, &dtm_shutdown_list);
132 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
134 struct dtm_shutdown *shutdown;
136 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
137 if (shutdown->func == func && shutdown->arg == arg) {
138 list_del(&shutdown->list);
146 static irqreturn_t temp_isr(int irq, void *context)
148 struct dtm_shutdown *shutdown;
152 /* Run through the shutdown list. */
153 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
154 shutdown->func(shutdown->arg);
156 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n");
160 unsigned reset = in_be32(dtm_fpga + 0x14);
161 out_be32(dtm_fpga + 0x14, reset);
165 unsigned leds = in_be32(gpio_base);
167 /* green off, red toggle */
171 out_be32(gpio_base, leds);
178 static int pika_setup_leds(void)
180 struct device_node *np;
184 np = of_find_compatible_node(NULL, NULL, "linux,gpio-led");
186 printk(KERN_ERR __FILE__ ": Unable to find gpio-led\n");
190 gpios = of_get_property(np, "gpios", &len);
192 if (!gpios || len < 4) {
193 printk(KERN_ERR __FILE__
194 ": Unable to get gpios property (%d)\n", len);
198 np = of_find_node_by_phandle(gpios[0]);
200 printk(KERN_ERR __FILE__ ": Unable to find gpio\n");
204 gpio_base = of_iomap(np, 0);
207 printk(KERN_ERR __FILE__ ": Unable to map gpio");
214 static void pika_setup_critical_temp(struct i2c_client *client)
216 struct device_node *np;
219 /* Do this before enabling critical temp interrupt since we
220 * may immediately interrupt.
224 /* These registers are in 1 degree increments. */
225 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
226 i2c_smbus_write_byte_data(client, 3, 55); /* Tlow */
228 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
230 printk(KERN_ERR __FILE__ ": Unable to find ad7414\n");
234 irq = irq_of_parse_and_map(np, 0);
237 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
241 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
243 printk(KERN_ERR __FILE__
244 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
249 static inline void pika_dtm_check_fan(void __iomem *fpga)
251 static int fan_state;
252 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
254 if (fan_state != fan) {
257 printk(KERN_WARNING "Fan rotation error detected."
258 " Please check hardware.\n");
262 static int pika_dtm_thread(void __iomem *fpga)
264 struct i2c_adapter *adap;
265 struct i2c_client *client;
267 /* We loop in case either driver was compiled as a module and
268 * has not been insmoded yet.
270 while (!(adap = i2c_get_adapter(0))) {
271 set_current_state(TASK_INTERRUPTIBLE);
272 schedule_timeout(HZ);
276 list_for_each_entry(client, &adap->clients, list)
277 if (client->addr == 0x4a)
280 set_current_state(TASK_INTERRUPTIBLE);
281 schedule_timeout(HZ);
285 i2c_put_adapter(adap);
287 pika_setup_critical_temp(client);
289 printk(KERN_INFO "PIKA DTM thread running.\n");
291 while (!kthread_should_stop()) {
292 u16 temp = swab16(i2c_smbus_read_word_data(client, 0));
293 out_be32(fpga + 0x20, temp);
295 pika_dtm_check_fan(fpga);
297 set_current_state(TASK_INTERRUPTIBLE);
298 schedule_timeout(HZ);
305 static int __init pika_dtm_start(void)
307 struct task_struct *dtm_thread;
308 struct device_node *np;
310 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
314 dtm_fpga = of_iomap(np, 0);
316 if (dtm_fpga == NULL)
319 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
320 if (IS_ERR(dtm_thread)) {
322 return PTR_ERR(dtm_thread);
327 machine_late_initcall(warp, pika_dtm_start);
329 #else /* !CONFIG_SENSORS_AD7414 */
331 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
336 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
343 EXPORT_SYMBOL(pika_dtm_register_shutdown);
344 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);