2008-01-21 17:55:29 +00:00
|
|
|
/*
|
|
|
|
* PIKA Warp(tm) board specific routines
|
|
|
|
*
|
2009-04-06 11:58:25 +00:00
|
|
|
* Copyright (c) 2008-2009 PIKA Technologies
|
2008-01-21 17:55:29 +00:00
|
|
|
* Sean MacLennan <smaclennan@pikatech.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/kthread.h>
|
2008-05-20 13:28:52 +00:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
2009-04-06 11:58:25 +00:00
|
|
|
#include <linux/of_gpio.h>
|
2009-06-19 19:43:59 +00:00
|
|
|
#include <linux/of_i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-07-29 06:19:31 +00:00
|
|
|
#include <linux/export.h>
|
2008-01-21 17:55:29 +00:00
|
|
|
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/udbg.h>
|
|
|
|
#include <asm/time.h>
|
|
|
|
#include <asm/uic.h>
|
2008-03-27 14:43:31 +00:00
|
|
|
#include <asm/ppc4xx.h>
|
2008-01-21 17:55:29 +00:00
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
|
2008-01-21 17:55:29 +00:00
|
|
|
static __initdata struct of_device_id warp_of_bus[] = {
|
|
|
|
{ .compatible = "ibm,plb4", },
|
|
|
|
{ .compatible = "ibm,opb", },
|
|
|
|
{ .compatible = "ibm,ebc", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init warp_device_probe(void)
|
|
|
|
{
|
|
|
|
of_platform_bus_probe(NULL, warp_of_bus, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
machine_device_initcall(warp, warp_device_probe);
|
|
|
|
|
|
|
|
static int __init warp_probe(void)
|
|
|
|
{
|
|
|
|
unsigned long root = of_get_flat_dt_root();
|
|
|
|
|
2009-06-10 15:09:23 +00:00
|
|
|
if (!of_flat_dt_is_compatible(root, "pika,warp"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* For __dma_alloc_coherent */
|
|
|
|
ISA_DMA_THRESHOLD = ~0L;
|
|
|
|
|
|
|
|
return 1;
|
2008-01-21 17:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define_machine(warp) {
|
|
|
|
.name = "Warp",
|
|
|
|
.probe = warp_probe,
|
|
|
|
.progress = udbg_progress,
|
|
|
|
.init_IRQ = uic_init_tree,
|
|
|
|
.get_irq = uic_get_irq,
|
2008-03-27 14:43:31 +00:00
|
|
|
.restart = ppc4xx_reset_system,
|
2008-01-21 17:55:29 +00:00
|
|
|
.calibrate_decr = generic_calibrate_decr,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
static int __init warp_post_info(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
void __iomem *fpga;
|
|
|
|
u32 post1, post2;
|
|
|
|
|
|
|
|
/* Sighhhh... POST information is in the sd area. */
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");
|
|
|
|
if (np == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
fpga = of_iomap(np, 0);
|
|
|
|
of_node_put(np);
|
|
|
|
if (fpga == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
post1 = in_be32(fpga + 0x40);
|
|
|
|
post2 = in_be32(fpga + 0x44);
|
|
|
|
|
|
|
|
iounmap(fpga);
|
|
|
|
|
2009-06-28 11:22:51 +00:00
|
|
|
if (post1 || post2)
|
2008-05-20 13:28:52 +00:00
|
|
|
printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);
|
2009-06-28 11:22:51 +00:00
|
|
|
else
|
2008-05-20 13:28:52 +00:00
|
|
|
printk(KERN_INFO "Warp POST OK\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_SENSORS_AD7414
|
|
|
|
|
|
|
|
static LIST_HEAD(dtm_shutdown_list);
|
|
|
|
static void __iomem *dtm_fpga;
|
2009-04-06 11:58:25 +00:00
|
|
|
static unsigned green_led, red_led;
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct dtm_shutdown {
|
|
|
|
struct list_head list;
|
|
|
|
void (*func)(void *arg);
|
|
|
|
void *arg;
|
|
|
|
};
|
2008-01-21 17:55:29 +00:00
|
|
|
|
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
|
2008-01-21 17:55:29 +00:00
|
|
|
{
|
2008-05-20 13:28:52 +00:00
|
|
|
struct dtm_shutdown *shutdown;
|
|
|
|
|
|
|
|
shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);
|
|
|
|
if (shutdown == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
shutdown->func = func;
|
|
|
|
shutdown->arg = arg;
|
|
|
|
|
|
|
|
list_add(&shutdown->list, &dtm_shutdown_list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
|
|
|
|
{
|
|
|
|
struct dtm_shutdown *shutdown;
|
|
|
|
|
|
|
|
list_for_each_entry(shutdown, &dtm_shutdown_list, list)
|
|
|
|
if (shutdown->func == func && shutdown->arg == arg) {
|
|
|
|
list_del(&shutdown->list);
|
|
|
|
kfree(shutdown);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t temp_isr(int irq, void *context)
|
|
|
|
{
|
|
|
|
struct dtm_shutdown *shutdown;
|
2009-04-06 11:58:25 +00:00
|
|
|
int value = 1;
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
gpio_set_value(green_led, 0);
|
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
/* Run through the shutdown list. */
|
|
|
|
list_for_each_entry(shutdown, &dtm_shutdown_list, list)
|
|
|
|
shutdown->func(shutdown->arg);
|
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (dtm_fpga) {
|
|
|
|
unsigned reset = in_be32(dtm_fpga + 0x14);
|
|
|
|
out_be32(dtm_fpga + 0x14, reset);
|
2008-01-21 17:55:29 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
gpio_set_value(red_led, value);
|
|
|
|
value ^= 1;
|
2008-05-20 13:28:52 +00:00
|
|
|
mdelay(500);
|
|
|
|
}
|
2009-07-05 14:02:15 +00:00
|
|
|
|
|
|
|
/* Not reached */
|
|
|
|
return IRQ_HANDLED;
|
2008-05-20 13:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pika_setup_leds(void)
|
|
|
|
{
|
2009-04-06 11:58:25 +00:00
|
|
|
struct device_node *np, *child;
|
2008-05-20 13:28:52 +00:00
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
np = of_find_compatible_node(NULL, NULL, "gpio-leds");
|
2008-05-20 13:28:52 +00:00
|
|
|
if (!np) {
|
2009-04-06 11:58:25 +00:00
|
|
|
printk(KERN_ERR __FILE__ ": Unable to find leds\n");
|
2008-05-20 13:28:52 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2008-01-21 17:55:29 +00:00
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
for_each_child_of_node(np, child)
|
2009-06-28 11:22:51 +00:00
|
|
|
if (strcmp(child->name, "green") == 0)
|
2009-04-06 11:58:25 +00:00
|
|
|
green_led = of_get_gpio(child, 0);
|
2009-06-28 11:22:51 +00:00
|
|
|
else if (strcmp(child->name, "red") == 0)
|
2009-04-06 11:58:25 +00:00
|
|
|
red_led = of_get_gpio(child, 0);
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
of_node_put(np);
|
2008-01-21 17:55:29 +00:00
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
return 0;
|
2008-01-21 17:55:29 +00:00
|
|
|
}
|
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
static void pika_setup_critical_temp(struct device_node *np,
|
|
|
|
struct i2c_client *client)
|
2008-05-20 13:28:52 +00:00
|
|
|
{
|
|
|
|
int irq, rc;
|
|
|
|
|
|
|
|
/* Do this before enabling critical temp interrupt since we
|
|
|
|
* may immediately interrupt.
|
|
|
|
*/
|
|
|
|
pika_setup_leds();
|
|
|
|
|
|
|
|
/* These registers are in 1 degree increments. */
|
|
|
|
i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
|
2008-07-26 01:45:10 +00:00
|
|
|
i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (irq == NO_IRQ) {
|
|
|
|
printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);
|
|
|
|
if (rc) {
|
|
|
|
printk(KERN_ERR __FILE__
|
|
|
|
": Unable to request ad7414 irq %d = %d\n", irq, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pika_dtm_check_fan(void __iomem *fpga)
|
|
|
|
{
|
|
|
|
static int fan_state;
|
|
|
|
u32 fan = in_be32(fpga + 0x34) & (1 << 14);
|
|
|
|
|
|
|
|
if (fan_state != fan) {
|
|
|
|
fan_state = fan;
|
|
|
|
if (fan)
|
|
|
|
printk(KERN_WARNING "Fan rotation error detected."
|
|
|
|
" Please check hardware.\n");
|
|
|
|
}
|
|
|
|
}
|
2008-01-21 17:55:29 +00:00
|
|
|
|
|
|
|
static int pika_dtm_thread(void __iomem *fpga)
|
|
|
|
{
|
2009-06-19 19:43:59 +00:00
|
|
|
struct device_node *np;
|
2008-05-20 13:28:52 +00:00
|
|
|
struct i2c_client *client;
|
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
|
|
|
|
if (np == NULL)
|
|
|
|
return -ENOENT;
|
2008-05-20 13:28:52 +00:00
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
client = of_find_i2c_device_by_node(np);
|
|
|
|
if (client == NULL) {
|
|
|
|
of_node_put(np);
|
|
|
|
return -ENOENT;
|
2008-05-20 13:28:52 +00:00
|
|
|
}
|
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
pika_setup_critical_temp(np, client);
|
2008-05-20 13:28:52 +00:00
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
of_node_put(np);
|
2009-04-06 11:58:25 +00:00
|
|
|
|
2009-06-19 19:43:59 +00:00
|
|
|
printk(KERN_INFO "Warp DTM thread running.\n");
|
2008-01-21 17:55:29 +00:00
|
|
|
|
|
|
|
while (!kthread_should_stop()) {
|
2008-07-26 01:45:10 +00:00
|
|
|
int val;
|
|
|
|
|
|
|
|
val = i2c_smbus_read_word_data(client, 0);
|
|
|
|
if (val < 0)
|
|
|
|
dev_dbg(&client->dev, "DTM read temp failed.\n");
|
|
|
|
else {
|
|
|
|
s16 temp = swab16(val);
|
|
|
|
out_be32(fpga + 0x20, temp);
|
|
|
|
}
|
2008-01-21 17:55:29 +00:00
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
pika_dtm_check_fan(fpga);
|
2008-01-21 17:55:29 +00:00
|
|
|
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
schedule_timeout(HZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init pika_dtm_start(void)
|
|
|
|
{
|
|
|
|
struct task_struct *dtm_thread;
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "pika,fpga");
|
|
|
|
if (np == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
dtm_fpga = of_iomap(np, 0);
|
2008-01-21 17:55:29 +00:00
|
|
|
of_node_put(np);
|
2008-05-20 13:28:52 +00:00
|
|
|
if (dtm_fpga == NULL)
|
2008-01-21 17:55:29 +00:00
|
|
|
return -ENOENT;
|
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
/* Must get post info before thread starts. */
|
|
|
|
warp_post_info();
|
|
|
|
|
2008-05-20 13:28:52 +00:00
|
|
|
dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");
|
2008-01-21 17:55:29 +00:00
|
|
|
if (IS_ERR(dtm_thread)) {
|
2008-05-20 13:28:52 +00:00
|
|
|
iounmap(dtm_fpga);
|
2008-01-21 17:55:29 +00:00
|
|
|
return PTR_ERR(dtm_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-20 13:28:52 +00:00
|
|
|
machine_late_initcall(warp, pika_dtm_start);
|
|
|
|
|
|
|
|
#else /* !CONFIG_SENSORS_AD7414 */
|
|
|
|
|
|
|
|
int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-06 11:58:25 +00:00
|
|
|
machine_late_initcall(warp, warp_post_info);
|
|
|
|
|
2008-01-21 17:55:29 +00:00
|
|
|
#endif
|
2008-05-20 13:28:52 +00:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(pika_dtm_register_shutdown);
|
|
|
|
EXPORT_SYMBOL(pika_dtm_unregister_shutdown);
|