warp.c (7a9787e1eba95a166265e6a260cf30af04ef0a99) | warp.c (805e324b7fbddf9f420f0ea09eb61c21777b0526) |
---|---|
1/* 2 * PIKA Warp(tm) board specific routines 3 * | 1/* 2 * PIKA Warp(tm) board specific routines 3 * |
4 * Copyright (c) 2008 PIKA Technologies | 4 * Copyright (c) 2008-2009 PIKA Technologies |
5 * Sean MacLennan <smaclennan@pikatech.com> 6 * 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. 11 */ 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> | 5 * Sean MacLennan <smaclennan@pikatech.com> 6 * 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. 11 */ 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> |
|
18 19#include <asm/machdep.h> 20#include <asm/prom.h> 21#include <asm/udbg.h> 22#include <asm/time.h> 23#include <asm/uic.h> 24#include <asm/ppc4xx.h> 25 | 19 20#include <asm/machdep.h> 21#include <asm/prom.h> 22#include <asm/udbg.h> 23#include <asm/time.h> 24#include <asm/uic.h> 25#include <asm/ppc4xx.h> 26 |
27 |
|
26static __initdata struct of_device_id warp_of_bus[] = { 27 { .compatible = "ibm,plb4", }, 28 { .compatible = "ibm,opb", }, 29 { .compatible = "ibm,ebc", }, 30 {}, 31}; 32 33static int __init warp_device_probe(void) --- 16 unchanged lines hidden (view full) --- 50 .progress = udbg_progress, 51 .init_IRQ = uic_init_tree, 52 .get_irq = uic_get_irq, 53 .restart = ppc4xx_reset_system, 54 .calibrate_decr = generic_calibrate_decr, 55}; 56 57 | 28static __initdata struct of_device_id warp_of_bus[] = { 29 { .compatible = "ibm,plb4", }, 30 { .compatible = "ibm,opb", }, 31 { .compatible = "ibm,ebc", }, 32 {}, 33}; 34 35static int __init warp_device_probe(void) --- 16 unchanged lines hidden (view full) --- 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, 57}; 58 59 |
60static u32 post_info; 61 |
|
58/* I am not sure this is the best place for this... */ 59static int __init warp_post_info(void) 60{ 61 struct device_node *np; 62 void __iomem *fpga; 63 u32 post1, post2; 64 65 /* Sighhhh... POST information is in the sd area. */ --- 6 unchanged lines hidden (view full) --- 72 if (fpga == NULL) 73 return -ENOENT; 74 75 post1 = in_be32(fpga + 0x40); 76 post2 = in_be32(fpga + 0x44); 77 78 iounmap(fpga); 79 | 62/* I am not sure this is the best place for this... */ 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. */ --- 6 unchanged lines hidden (view full) --- 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 |
80 if (post1 || post2) | 84 if (post1 || post2) { |
81 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2); | 85 printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2); |
82 else | 86 post_info = 1; 87 } else |
83 printk(KERN_INFO "Warp POST OK\n"); 84 85 return 0; 86} | 88 printk(KERN_INFO "Warp POST OK\n"); 89 90 return 0; 91} |
87machine_late_initcall(warp, warp_post_info); | |
88 89 90#ifdef CONFIG_SENSORS_AD7414 91 92static LIST_HEAD(dtm_shutdown_list); 93static void __iomem *dtm_fpga; | 92 93 94#ifdef CONFIG_SENSORS_AD7414 95 96static LIST_HEAD(dtm_shutdown_list); 97static void __iomem *dtm_fpga; |
94static void __iomem *gpio_base; | 98static unsigned green_led, red_led; |
95 96 97struct dtm_shutdown { 98 struct list_head list; 99 void (*func)(void *arg); 100 void *arg; 101}; 102 --- 26 unchanged lines hidden (view full) --- 129 } 130 131 return -EINVAL; 132} 133 134static irqreturn_t temp_isr(int irq, void *context) 135{ 136 struct dtm_shutdown *shutdown; | 99 100 101struct dtm_shutdown { 102 struct list_head list; 103 void (*func)(void *arg); 104 void *arg; 105}; 106 --- 26 unchanged lines hidden (view full) --- 133 } 134 135 return -EINVAL; 136} 137 138static irqreturn_t temp_isr(int irq, void *context) 139{ 140 struct dtm_shutdown *shutdown; |
141 int value = 1; |
|
137 138 local_irq_disable(); 139 | 142 143 local_irq_disable(); 144 |
145 gpio_set_value(green_led, 0); 146 |
|
140 /* Run through the shutdown list. */ 141 list_for_each_entry(shutdown, &dtm_shutdown_list, list) 142 shutdown->func(shutdown->arg); 143 | 147 /* Run through the shutdown list. */ 148 list_for_each_entry(shutdown, &dtm_shutdown_list, list) 149 shutdown->func(shutdown->arg); 150 |
144 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n"); | 151 printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n"); |
145 146 while (1) { 147 if (dtm_fpga) { 148 unsigned reset = in_be32(dtm_fpga + 0x14); 149 out_be32(dtm_fpga + 0x14, reset); 150 } 151 | 152 153 while (1) { 154 if (dtm_fpga) { 155 unsigned reset = in_be32(dtm_fpga + 0x14); 156 out_be32(dtm_fpga + 0x14, reset); 157 } 158 |
152 if (gpio_base) { 153 unsigned leds = in_be32(gpio_base); 154 155 /* green off, red toggle */ 156 leds &= ~0x80000000; 157 leds ^= 0x40000000; 158 159 out_be32(gpio_base, leds); 160 } 161 | 159 gpio_set_value(red_led, value); 160 value ^= 1; |
162 mdelay(500); 163 } 164} 165 166static int pika_setup_leds(void) 167{ | 161 mdelay(500); 162 } 163} 164 165static int pika_setup_leds(void) 166{ |
168 struct device_node *np; 169 const u32 *gpios; 170 int len; | 167 struct device_node *np, *child; |
171 | 168 |
172 np = of_find_compatible_node(NULL, NULL, "linux,gpio-led"); | 169 np = of_find_compatible_node(NULL, NULL, "gpio-leds"); |
173 if (!np) { | 170 if (!np) { |
174 printk(KERN_ERR __FILE__ ": Unable to find gpio-led\n"); | 171 printk(KERN_ERR __FILE__ ": Unable to find leds\n"); |
175 return -ENOENT; 176 } 177 | 172 return -ENOENT; 173 } 174 |
178 gpios = of_get_property(np, "gpios", &len); 179 of_node_put(np); 180 if (!gpios || len < 4) { 181 printk(KERN_ERR __FILE__ 182 ": Unable to get gpios property (%d)\n", len); 183 return -ENOENT; 184 } | 175 for_each_child_of_node(np, child) 176 if (strcmp(child->name, "green") == 0) { 177 green_led = of_get_gpio(child, 0); 178 /* Turn back on the green LED */ 179 gpio_set_value(green_led, 1); 180 } else if (strcmp(child->name, "red") == 0) { 181 red_led = of_get_gpio(child, 0); 182 /* Set based on post */ 183 gpio_set_value(red_led, post_info); 184 } |
185 | 185 |
186 np = of_find_node_by_phandle(gpios[0]); 187 if (!np) { 188 printk(KERN_ERR __FILE__ ": Unable to find gpio\n"); 189 return -ENOENT; 190 } 191 192 gpio_base = of_iomap(np, 0); | |
193 of_node_put(np); | 186 of_node_put(np); |
194 if (!gpio_base) { 195 printk(KERN_ERR __FILE__ ": Unable to map gpio"); 196 return -ENOMEM; 197 } | |
198 199 return 0; 200} 201 202static void pika_setup_critical_temp(struct i2c_client *client) 203{ 204 struct device_node *np; 205 int irq, rc; --- 59 unchanged lines hidden (view full) --- 265 if (client->addr == 0x4a) 266 goto found_it; 267 268 set_current_state(TASK_INTERRUPTIBLE); 269 schedule_timeout(HZ); 270 } 271 272found_it: | 187 188 return 0; 189} 190 191static void pika_setup_critical_temp(struct i2c_client *client) 192{ 193 struct device_node *np; 194 int irq, rc; --- 59 unchanged lines hidden (view full) --- 254 if (client->addr == 0x4a) 255 goto found_it; 256 257 set_current_state(TASK_INTERRUPTIBLE); 258 schedule_timeout(HZ); 259 } 260 261found_it: |
273 i2c_put_adapter(adap); 274 | |
275 pika_setup_critical_temp(client); 276 | 262 pika_setup_critical_temp(client); 263 |
264 i2c_put_adapter(adap); 265 |
|
277 printk(KERN_INFO "PIKA DTM thread running.\n"); 278 279 while (!kthread_should_stop()) { 280 int val; 281 282 val = i2c_smbus_read_word_data(client, 0); 283 if (val < 0) 284 dev_dbg(&client->dev, "DTM read temp failed.\n"); --- 21 unchanged lines hidden (view full) --- 306 if (np == NULL) 307 return -ENOENT; 308 309 dtm_fpga = of_iomap(np, 0); 310 of_node_put(np); 311 if (dtm_fpga == NULL) 312 return -ENOENT; 313 | 266 printk(KERN_INFO "PIKA DTM thread running.\n"); 267 268 while (!kthread_should_stop()) { 269 int val; 270 271 val = i2c_smbus_read_word_data(client, 0); 272 if (val < 0) 273 dev_dbg(&client->dev, "DTM read temp failed.\n"); --- 21 unchanged lines hidden (view full) --- 295 if (np == NULL) 296 return -ENOENT; 297 298 dtm_fpga = of_iomap(np, 0); 299 of_node_put(np); 300 if (dtm_fpga == NULL) 301 return -ENOENT; 302 |
303 /* Must get post info before thread starts. */ 304 warp_post_info(); 305 |
|
314 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm"); 315 if (IS_ERR(dtm_thread)) { 316 iounmap(dtm_fpga); 317 return PTR_ERR(dtm_thread); 318 } 319 320 return 0; 321} --- 6 unchanged lines hidden (view full) --- 328 return 0; 329} 330 331int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg) 332{ 333 return 0; 334} 335 | 306 dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm"); 307 if (IS_ERR(dtm_thread)) { 308 iounmap(dtm_fpga); 309 return PTR_ERR(dtm_thread); 310 } 311 312 return 0; 313} --- 6 unchanged lines hidden (view full) --- 320 return 0; 321} 322 323int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg) 324{ 325 return 0; 326} 327 |
328machine_late_initcall(warp, warp_post_info); 329 |
|
336#endif 337 338EXPORT_SYMBOL(pika_dtm_register_shutdown); 339EXPORT_SYMBOL(pika_dtm_unregister_shutdown); | 330#endif 331 332EXPORT_SYMBOL(pika_dtm_register_shutdown); 333EXPORT_SYMBOL(pika_dtm_unregister_shutdown); |