1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PIKA Warp(tm) board specific routines
5 * Copyright (c) 2008-2009 PIKA Technologies
6 * Sean MacLennan <smaclennan@pikatech.com>
8 #include <linux/init.h>
9 #include <linux/of_platform.h>
10 #include <linux/kthread.h>
11 #include <linux/i2c.h>
12 #include <linux/interrupt.h>
13 #include <linux/delay.h>
14 #include <linux/of_gpio.h>
15 #include <linux/slab.h>
16 #include <linux/export.h>
18 #include <asm/machdep.h>
23 #include <asm/ppc4xx.h>
27 static const struct of_device_id warp_of_bus
[] __initconst
= {
28 { .compatible
= "ibm,plb4", },
29 { .compatible
= "ibm,opb", },
30 { .compatible
= "ibm,ebc", },
34 static int __init
warp_device_probe(void)
36 of_platform_bus_probe(NULL
, warp_of_bus
, NULL
);
39 machine_device_initcall(warp
, warp_device_probe
);
41 static int __init
warp_probe(void)
43 if (!of_machine_is_compatible("pika,warp"))
49 define_machine(warp
) {
52 .progress
= udbg_progress
,
53 .init_IRQ
= uic_init_tree
,
54 .get_irq
= uic_get_irq
,
55 .restart
= ppc4xx_reset_system
,
56 .calibrate_decr
= generic_calibrate_decr
,
60 static int __init
warp_post_info(void)
62 struct device_node
*np
;
66 /* Sighhhh... POST information is in the sd area. */
67 np
= of_find_compatible_node(NULL
, NULL
, "pika,fpga-sd");
71 fpga
= of_iomap(np
, 0);
76 post1
= in_be32(fpga
+ 0x40);
77 post2
= in_be32(fpga
+ 0x44);
82 printk(KERN_INFO
"Warp POST %08x %08x\n", post1
, post2
);
84 printk(KERN_INFO
"Warp POST OK\n");
90 #ifdef CONFIG_SENSORS_AD7414
92 static LIST_HEAD(dtm_shutdown_list
);
93 static void __iomem
*dtm_fpga
;
94 static unsigned green_led
, red_led
;
98 struct list_head list
;
99 void (*func
)(void *arg
);
104 int pika_dtm_register_shutdown(void (*func
)(void *arg
), void *arg
)
106 struct dtm_shutdown
*shutdown
;
108 shutdown
= kmalloc(sizeof(struct dtm_shutdown
), GFP_KERNEL
);
109 if (shutdown
== NULL
)
112 shutdown
->func
= func
;
115 list_add(&shutdown
->list
, &dtm_shutdown_list
);
120 int pika_dtm_unregister_shutdown(void (*func
)(void *arg
), void *arg
)
122 struct dtm_shutdown
*shutdown
;
124 list_for_each_entry(shutdown
, &dtm_shutdown_list
, list
)
125 if (shutdown
->func
== func
&& shutdown
->arg
== arg
) {
126 list_del(&shutdown
->list
);
134 static irqreturn_t
temp_isr(int irq
, void *context
)
136 struct dtm_shutdown
*shutdown
;
141 gpio_set_value(green_led
, 0);
143 /* Run through the shutdown list. */
144 list_for_each_entry(shutdown
, &dtm_shutdown_list
, list
)
145 shutdown
->func(shutdown
->arg
);
147 printk(KERN_EMERG
"\n\nCritical Temperature Shutdown\n\n");
151 unsigned reset
= in_be32(dtm_fpga
+ 0x14);
152 out_be32(dtm_fpga
+ 0x14, reset
);
155 gpio_set_value(red_led
, value
);
164 static int pika_setup_leds(void)
166 struct device_node
*np
, *child
;
168 np
= of_find_compatible_node(NULL
, NULL
, "gpio-leds");
170 printk(KERN_ERR __FILE__
": Unable to find leds\n");
174 for_each_child_of_node(np
, child
)
175 if (of_node_name_eq(child
, "green"))
176 green_led
= of_get_gpio(child
, 0);
177 else if (of_node_name_eq(child
, "red"))
178 red_led
= of_get_gpio(child
, 0);
185 static void pika_setup_critical_temp(struct device_node
*np
,
186 struct i2c_client
*client
)
190 /* Do this before enabling critical temp interrupt since we
191 * may immediately interrupt.
195 /* These registers are in 1 degree increments. */
196 i2c_smbus_write_byte_data(client
, 2, 65); /* Thigh */
197 i2c_smbus_write_byte_data(client
, 3, 0); /* Tlow */
199 irq
= irq_of_parse_and_map(np
, 0);
201 printk(KERN_ERR __FILE__
": Unable to get ad7414 irq\n");
205 rc
= request_irq(irq
, temp_isr
, 0, "ad7414", NULL
);
207 printk(KERN_ERR __FILE__
208 ": Unable to request ad7414 irq %d = %d\n", irq
, rc
);
213 static inline void pika_dtm_check_fan(void __iomem
*fpga
)
215 static int fan_state
;
216 u32 fan
= in_be32(fpga
+ 0x34) & (1 << 14);
218 if (fan_state
!= fan
) {
221 printk(KERN_WARNING
"Fan rotation error detected."
222 " Please check hardware.\n");
226 static int pika_dtm_thread(void __iomem
*fpga
)
228 struct device_node
*np
;
229 struct i2c_client
*client
;
231 np
= of_find_compatible_node(NULL
, NULL
, "adi,ad7414");
235 client
= of_find_i2c_device_by_node(np
);
236 if (client
== NULL
) {
241 pika_setup_critical_temp(np
, client
);
245 printk(KERN_INFO
"Warp DTM thread running.\n");
247 while (!kthread_should_stop()) {
250 val
= i2c_smbus_read_word_data(client
, 0);
252 dev_dbg(&client
->dev
, "DTM read temp failed.\n");
254 s16 temp
= swab16(val
);
255 out_be32(fpga
+ 0x20, temp
);
258 pika_dtm_check_fan(fpga
);
260 set_current_state(TASK_INTERRUPTIBLE
);
261 schedule_timeout(HZ
);
267 static int __init
pika_dtm_start(void)
269 struct task_struct
*dtm_thread
;
270 struct device_node
*np
;
272 np
= of_find_compatible_node(NULL
, NULL
, "pika,fpga");
276 dtm_fpga
= of_iomap(np
, 0);
278 if (dtm_fpga
== NULL
)
281 /* Must get post info before thread starts. */
284 dtm_thread
= kthread_run(pika_dtm_thread
, dtm_fpga
, "pika-dtm");
285 if (IS_ERR(dtm_thread
)) {
287 return PTR_ERR(dtm_thread
);
292 machine_late_initcall(warp
, pika_dtm_start
);
294 #else /* !CONFIG_SENSORS_AD7414 */
296 int pika_dtm_register_shutdown(void (*func
)(void *arg
), void *arg
)
301 int pika_dtm_unregister_shutdown(void (*func
)(void *arg
), void *arg
)
306 machine_late_initcall(warp
, warp_post_info
);
310 EXPORT_SYMBOL(pika_dtm_register_shutdown
);
311 EXPORT_SYMBOL(pika_dtm_unregister_shutdown
);