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"))
46 /* For arch_dma_alloc */
47 ISA_DMA_THRESHOLD = ~0L;
52 define_machine(warp) {
55 .progress = udbg_progress,
56 .init_IRQ = uic_init_tree,
57 .get_irq = uic_get_irq,
58 .restart = ppc4xx_reset_system,
59 .calibrate_decr = generic_calibrate_decr,
63 static int __init warp_post_info(void)
65 struct device_node *np;
69 /* Sighhhh... POST information is in the sd area. */
70 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
74 fpga = of_iomap(np, 0);
79 post1 = in_be32(fpga + 0x40);
80 post2 = in_be32(fpga + 0x44);
85 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
87 printk(KERN_INFO "Warp POST OK\n");
93 #ifdef CONFIG_SENSORS_AD7414
95 static LIST_HEAD(dtm_shutdown_list);
96 static void __iomem *dtm_fpga;
97 static unsigned green_led, red_led;
100 struct dtm_shutdown {
101 struct list_head list;
102 void (*func)(void *arg);
107 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
109 struct dtm_shutdown *shutdown;
111 shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
112 if (shutdown == NULL)
115 shutdown->func = func;
118 list_add(&shutdown->list, &dtm_shutdown_list);
123 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
125 struct dtm_shutdown *shutdown;
127 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
128 if (shutdown->func == func && shutdown->arg == arg) {
129 list_del(&shutdown->list);
137 static irqreturn_t temp_isr(int irq, void *context)
139 struct dtm_shutdown *shutdown;
144 gpio_set_value(green_led, 0);
146 /* Run through the shutdown list. */
147 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
148 shutdown->func(shutdown->arg);
150 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");
154 unsigned reset = in_be32(dtm_fpga + 0x14);
155 out_be32(dtm_fpga + 0x14, reset);
158 gpio_set_value(red_led, value);
167 static int pika_setup_leds(void)
169 struct device_node *np, *child;
171 np = of_find_compatible_node(NULL, NULL, "gpio-leds");
173 printk(KERN_ERR __FILE__ ": Unable to find leds\n");
177 for_each_child_of_node(np, child)
178 if (of_node_name_eq(child, "green"))
179 green_led = of_get_gpio(child, 0);
180 else if (of_node_name_eq(child, "red"))
181 red_led = of_get_gpio(child, 0);
188 static void pika_setup_critical_temp(struct device_node *np,
189 struct i2c_client *client)
193 /* Do this before enabling critical temp interrupt since we
194 * may immediately interrupt.
198 /* These registers are in 1 degree increments. */
199 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
200 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
202 irq = irq_of_parse_and_map(np, 0);
204 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
208 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
210 printk(KERN_ERR __FILE__
211 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
216 static inline void pika_dtm_check_fan(void __iomem *fpga)
218 static int fan_state;
219 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
221 if (fan_state != fan) {
224 printk(KERN_WARNING "Fan rotation error detected."
225 " Please check hardware.\n");
229 static int pika_dtm_thread(void __iomem *fpga)
231 struct device_node *np;
232 struct i2c_client *client;
234 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
238 client = of_find_i2c_device_by_node(np);
239 if (client == NULL) {
244 pika_setup_critical_temp(np, client);
248 printk(KERN_INFO "Warp DTM thread running.\n");
250 while (!kthread_should_stop()) {
253 val = i2c_smbus_read_word_data(client, 0);
255 dev_dbg(&client->dev, "DTM read temp failed.\n");
257 s16 temp = swab16(val);
258 out_be32(fpga + 0x20, temp);
261 pika_dtm_check_fan(fpga);
263 set_current_state(TASK_INTERRUPTIBLE);
264 schedule_timeout(HZ);
270 static int __init pika_dtm_start(void)
272 struct task_struct *dtm_thread;
273 struct device_node *np;
275 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
279 dtm_fpga = of_iomap(np, 0);
281 if (dtm_fpga == NULL)
284 /* Must get post info before thread starts. */
287 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
288 if (IS_ERR(dtm_thread)) {
290 return PTR_ERR(dtm_thread);
295 machine_late_initcall(warp, pika_dtm_start);
297 #else /* !CONFIG_SENSORS_AD7414 */
299 int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
304 int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
309 machine_late_initcall(warp, warp_post_info);
313 EXPORT_SYMBOL(pika_dtm_register_shutdown);
314 EXPORT_SYMBOL(pika_dtm_unregister_shutdown);