]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - arch/powerpc/platforms/44x/warp.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-kernels.git] / arch / powerpc / platforms / 44x / warp.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
f9bdedb2
SM
2/*
3 * PIKA Warp(tm) board specific routines
4 *
805e324b 5 * Copyright (c) 2008-2009 PIKA Technologies
f9bdedb2 6 * Sean MacLennan <smaclennan@pikatech.com>
f9bdedb2
SM
7 */
8#include <linux/init.h>
9#include <linux/of_platform.h>
10#include <linux/kthread.h>
4ebef31f
SM
11#include <linux/i2c.h>
12#include <linux/interrupt.h>
13#include <linux/delay.h>
805e324b 14#include <linux/of_gpio.h>
5a0e3ad6 15#include <linux/slab.h>
93087948 16#include <linux/export.h>
f9bdedb2
SM
17
18#include <asm/machdep.h>
19#include <asm/prom.h>
20#include <asm/udbg.h>
21#include <asm/time.h>
22#include <asm/uic.h>
93173ce2 23#include <asm/ppc4xx.h>
308c09f1 24#include <asm/dma.h>
f9bdedb2 25
805e324b 26
ce6d73c9 27static const struct of_device_id warp_of_bus[] __initconst = {
f9bdedb2
SM
28 { .compatible = "ibm,plb4", },
29 { .compatible = "ibm,opb", },
30 { .compatible = "ibm,ebc", },
31 {},
32};
33
34static int __init warp_device_probe(void)
35{
36 of_platform_bus_probe(NULL, warp_of_bus, NULL);
37 return 0;
38}
39machine_device_initcall(warp, warp_device_probe);
40
41static int __init warp_probe(void)
42{
56571384 43 if (!of_machine_is_compatible("pika,warp"))
79290e4b
SM
44 return 0;
45
68005b67 46 /* For arch_dma_alloc */
79290e4b
SM
47 ISA_DMA_THRESHOLD = ~0L;
48
49 return 1;
f9bdedb2
SM
50}
51
52define_machine(warp) {
53 .name = "Warp",
54 .probe = warp_probe,
55 .progress = udbg_progress,
56 .init_IRQ = uic_init_tree,
57 .get_irq = uic_get_irq,
93173ce2 58 .restart = ppc4xx_reset_system,
f9bdedb2
SM
59 .calibrate_decr = generic_calibrate_decr,
60};
61
62
4ebef31f
SM
63static int __init warp_post_info(void)
64{
65 struct device_node *np;
66 void __iomem *fpga;
67 u32 post1, post2;
68
69 /* Sighhhh... POST information is in the sd area. */
70 np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
71 if (np == NULL)
72 return -ENOENT;
73
74 fpga = of_iomap(np, 0);
75 of_node_put(np);
76 if (fpga == NULL)
77 return -ENOENT;
78
79 post1 = in_be32(fpga + 0x40);
80 post2 = in_be32(fpga + 0x44);
81
82 iounmap(fpga);
83
ba703e1a 84 if (post1 || post2)
4ebef31f 85 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
ba703e1a 86 else
4ebef31f
SM
87 printk(KERN_INFO "Warp POST OK\n");
88
89 return 0;
90}
4ebef31f
SM
91
92
93#ifdef CONFIG_SENSORS_AD7414
94
95static LIST_HEAD(dtm_shutdown_list);
96static void __iomem *dtm_fpga;
805e324b 97static unsigned green_led, red_led;
4ebef31f
SM
98
99
100struct dtm_shutdown {
101 struct list_head list;
102 void (*func)(void *arg);
103 void *arg;
104};
f9bdedb2
SM
105
106
4ebef31f 107int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
f9bdedb2 108{
4ebef31f
SM
109 struct dtm_shutdown *shutdown;
110
111 shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
112 if (shutdown == NULL)
113 return -ENOMEM;
114
115 shutdown->func = func;
116 shutdown->arg = arg;
117
118 list_add(&shutdown->list, &dtm_shutdown_list);
119
120 return 0;
121}
122
123int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
124{
125 struct dtm_shutdown *shutdown;
126
127 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
128 if (shutdown->func == func && shutdown->arg == arg) {
129 list_del(&shutdown->list);
130 kfree(shutdown);
131 return 0;
132 }
133
134 return -EINVAL;
135}
136
137static irqreturn_t temp_isr(int irq, void *context)
138{
139 struct dtm_shutdown *shutdown;
805e324b 140 int value = 1;
4ebef31f
SM
141
142 local_irq_disable();
143
805e324b
SM
144 gpio_set_value(green_led, 0);
145
4ebef31f
SM
146 /* Run through the shutdown list. */
147 list_for_each_entry(shutdown, &dtm_shutdown_list, list)
148 shutdown->func(shutdown->arg);
149
805e324b 150 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");
4ebef31f
SM
151
152 while (1) {
153 if (dtm_fpga) {
154 unsigned reset = in_be32(dtm_fpga + 0x14);
155 out_be32(dtm_fpga + 0x14, reset);
f9bdedb2
SM
156 }
157
805e324b
SM
158 gpio_set_value(red_led, value);
159 value ^= 1;
4ebef31f
SM
160 mdelay(500);
161 }
a22ebd06
JB
162
163 /* Not reached */
164 return IRQ_HANDLED;
4ebef31f
SM
165}
166
167static int pika_setup_leds(void)
168{
805e324b 169 struct device_node *np, *child;
4ebef31f 170
805e324b 171 np = of_find_compatible_node(NULL, NULL, "gpio-leds");
4ebef31f 172 if (!np) {
805e324b 173 printk(KERN_ERR __FILE__ ": Unable to find leds\n");
4ebef31f
SM
174 return -ENOENT;
175 }
f9bdedb2 176
805e324b 177 for_each_child_of_node(np, child)
2c8e65b5 178 if (of_node_name_eq(child, "green"))
805e324b 179 green_led = of_get_gpio(child, 0);
2c8e65b5 180 else if (of_node_name_eq(child, "red"))
805e324b 181 red_led = of_get_gpio(child, 0);
4ebef31f 182
4ebef31f 183 of_node_put(np);
f9bdedb2 184
4ebef31f 185 return 0;
f9bdedb2 186}
f9bdedb2 187
3984114f
SM
188static void pika_setup_critical_temp(struct device_node *np,
189 struct i2c_client *client)
4ebef31f 190{
4ebef31f
SM
191 int irq, rc;
192
193 /* Do this before enabling critical temp interrupt since we
194 * may immediately interrupt.
195 */
196 pika_setup_leds();
197
198 /* These registers are in 1 degree increments. */
199 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
048040a3 200 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
4ebef31f 201
4ebef31f 202 irq = irq_of_parse_and_map(np, 0);
ef24ba70 203 if (!irq) {
4ebef31f
SM
204 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
205 return;
206 }
207
208 rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
209 if (rc) {
210 printk(KERN_ERR __FILE__
211 ": Unable to request ad7414 irq %d = %d\n", irq, rc);
212 return;
213 }
214}
215
216static inline void pika_dtm_check_fan(void __iomem *fpga)
217{
218 static int fan_state;
219 u32 fan = in_be32(fpga + 0x34) & (1 << 14);
220
221 if (fan_state != fan) {
222 fan_state = fan;
223 if (fan)
224 printk(KERN_WARNING "Fan rotation error detected."
225 " Please check hardware.\n");
226 }
227}
f9bdedb2 228
f9bdedb2
SM
229static int pika_dtm_thread(void __iomem *fpga)
230{
3984114f 231 struct device_node *np;
4ebef31f
SM
232 struct i2c_client *client;
233
3984114f
SM
234 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
235 if (np == NULL)
236 return -ENOENT;
4ebef31f 237
3984114f
SM
238 client = of_find_i2c_device_by_node(np);
239 if (client == NULL) {
240 of_node_put(np);
241 return -ENOENT;
4ebef31f
SM
242 }
243
3984114f 244 pika_setup_critical_temp(np, client);
4ebef31f 245
3984114f 246 of_node_put(np);
805e324b 247
3984114f 248 printk(KERN_INFO "Warp DTM thread running.\n");
f9bdedb2
SM
249
250 while (!kthread_should_stop()) {
048040a3
SM
251 int val;
252
253 val = i2c_smbus_read_word_data(client, 0);
254 if (val < 0)
255 dev_dbg(&client->dev, "DTM read temp failed.\n");
256 else {
257 s16 temp = swab16(val);
258 out_be32(fpga + 0x20, temp);
259 }
f9bdedb2 260
4ebef31f 261 pika_dtm_check_fan(fpga);
f9bdedb2
SM
262
263 set_current_state(TASK_INTERRUPTIBLE);
264 schedule_timeout(HZ);
265 }
266
267 return 0;
268}
269
270static int __init pika_dtm_start(void)
271{
272 struct task_struct *dtm_thread;
273 struct device_node *np;
f9bdedb2
SM
274
275 np = of_find_compatible_node(NULL, NULL, "pika,fpga");
276 if (np == NULL)
277 return -ENOENT;
278
4ebef31f 279 dtm_fpga = of_iomap(np, 0);
f9bdedb2 280 of_node_put(np);
4ebef31f 281 if (dtm_fpga == NULL)
f9bdedb2
SM
282 return -ENOENT;
283
805e324b
SM
284 /* Must get post info before thread starts. */
285 warp_post_info();
286
4ebef31f 287 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
f9bdedb2 288 if (IS_ERR(dtm_thread)) {
4ebef31f 289 iounmap(dtm_fpga);
f9bdedb2
SM
290 return PTR_ERR(dtm_thread);
291 }
292
293 return 0;
294}
4ebef31f
SM
295machine_late_initcall(warp, pika_dtm_start);
296
297#else /* !CONFIG_SENSORS_AD7414 */
298
299int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
300{
301 return 0;
302}
303
304int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
305{
306 return 0;
307}
308
805e324b
SM
309machine_late_initcall(warp, warp_post_info);
310
f9bdedb2 311#endif
4ebef31f
SM
312
313EXPORT_SYMBOL(pika_dtm_register_shutdown);
314EXPORT_SYMBOL(pika_dtm_unregister_shutdown);