Path: blob/master/arch/powerpc/platforms/44x/warp.c
10820 views
/*1* PIKA Warp(tm) board specific routines2*3* Copyright (c) 2008-2009 PIKA Technologies4* Sean MacLennan <[email protected]>5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License as published by the8* Free Software Foundation; either version 2 of the License, or (at your9* option) any later version.10*/11#include <linux/init.h>12#include <linux/of_platform.h>13#include <linux/kthread.h>14#include <linux/i2c.h>15#include <linux/interrupt.h>16#include <linux/delay.h>17#include <linux/of_gpio.h>18#include <linux/of_i2c.h>19#include <linux/slab.h>2021#include <asm/machdep.h>22#include <asm/prom.h>23#include <asm/udbg.h>24#include <asm/time.h>25#include <asm/uic.h>26#include <asm/ppc4xx.h>272829static __initdata struct of_device_id warp_of_bus[] = {30{ .compatible = "ibm,plb4", },31{ .compatible = "ibm,opb", },32{ .compatible = "ibm,ebc", },33{},34};3536static int __init warp_device_probe(void)37{38of_platform_bus_probe(NULL, warp_of_bus, NULL);39return 0;40}41machine_device_initcall(warp, warp_device_probe);4243static int __init warp_probe(void)44{45unsigned long root = of_get_flat_dt_root();4647if (!of_flat_dt_is_compatible(root, "pika,warp"))48return 0;4950/* For __dma_alloc_coherent */51ISA_DMA_THRESHOLD = ~0L;5253return 1;54}5556define_machine(warp) {57.name = "Warp",58.probe = warp_probe,59.progress = udbg_progress,60.init_IRQ = uic_init_tree,61.get_irq = uic_get_irq,62.restart = ppc4xx_reset_system,63.calibrate_decr = generic_calibrate_decr,64};656667static int __init warp_post_info(void)68{69struct device_node *np;70void __iomem *fpga;71u32 post1, post2;7273/* Sighhhh... POST information is in the sd area. */74np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd");75if (np == NULL)76return -ENOENT;7778fpga = of_iomap(np, 0);79of_node_put(np);80if (fpga == NULL)81return -ENOENT;8283post1 = in_be32(fpga + 0x40);84post2 = in_be32(fpga + 0x44);8586iounmap(fpga);8788if (post1 || post2)89printk(KERN_INFO "Warp POST %08x %08x\n", post1, post2);90else91printk(KERN_INFO "Warp POST OK\n");9293return 0;94}959697#ifdef CONFIG_SENSORS_AD74149899static LIST_HEAD(dtm_shutdown_list);100static void __iomem *dtm_fpga;101static unsigned green_led, red_led;102103104struct dtm_shutdown {105struct list_head list;106void (*func)(void *arg);107void *arg;108};109110111int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)112{113struct dtm_shutdown *shutdown;114115shutdown = kmalloc(sizeof(struct dtm_shutdown), GFP_KERNEL);116if (shutdown == NULL)117return -ENOMEM;118119shutdown->func = func;120shutdown->arg = arg;121122list_add(&shutdown->list, &dtm_shutdown_list);123124return 0;125}126127int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)128{129struct dtm_shutdown *shutdown;130131list_for_each_entry(shutdown, &dtm_shutdown_list, list)132if (shutdown->func == func && shutdown->arg == arg) {133list_del(&shutdown->list);134kfree(shutdown);135return 0;136}137138return -EINVAL;139}140141static irqreturn_t temp_isr(int irq, void *context)142{143struct dtm_shutdown *shutdown;144int value = 1;145146local_irq_disable();147148gpio_set_value(green_led, 0);149150/* Run through the shutdown list. */151list_for_each_entry(shutdown, &dtm_shutdown_list, list)152shutdown->func(shutdown->arg);153154printk(KERN_EMERG "\n\nCritical Temperature Shutdown\n\n");155156while (1) {157if (dtm_fpga) {158unsigned reset = in_be32(dtm_fpga + 0x14);159out_be32(dtm_fpga + 0x14, reset);160}161162gpio_set_value(red_led, value);163value ^= 1;164mdelay(500);165}166167/* Not reached */168return IRQ_HANDLED;169}170171static int pika_setup_leds(void)172{173struct device_node *np, *child;174175np = of_find_compatible_node(NULL, NULL, "gpio-leds");176if (!np) {177printk(KERN_ERR __FILE__ ": Unable to find leds\n");178return -ENOENT;179}180181for_each_child_of_node(np, child)182if (strcmp(child->name, "green") == 0)183green_led = of_get_gpio(child, 0);184else if (strcmp(child->name, "red") == 0)185red_led = of_get_gpio(child, 0);186187of_node_put(np);188189return 0;190}191192static void pika_setup_critical_temp(struct device_node *np,193struct i2c_client *client)194{195int irq, rc;196197/* Do this before enabling critical temp interrupt since we198* may immediately interrupt.199*/200pika_setup_leds();201202/* These registers are in 1 degree increments. */203i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */204i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */205206irq = irq_of_parse_and_map(np, 0);207if (irq == NO_IRQ) {208printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");209return;210}211212rc = request_irq(irq, temp_isr, 0, "ad7414", NULL);213if (rc) {214printk(KERN_ERR __FILE__215": Unable to request ad7414 irq %d = %d\n", irq, rc);216return;217}218}219220static inline void pika_dtm_check_fan(void __iomem *fpga)221{222static int fan_state;223u32 fan = in_be32(fpga + 0x34) & (1 << 14);224225if (fan_state != fan) {226fan_state = fan;227if (fan)228printk(KERN_WARNING "Fan rotation error detected."229" Please check hardware.\n");230}231}232233static int pika_dtm_thread(void __iomem *fpga)234{235struct device_node *np;236struct i2c_client *client;237238np = of_find_compatible_node(NULL, NULL, "adi,ad7414");239if (np == NULL)240return -ENOENT;241242client = of_find_i2c_device_by_node(np);243if (client == NULL) {244of_node_put(np);245return -ENOENT;246}247248pika_setup_critical_temp(np, client);249250of_node_put(np);251252printk(KERN_INFO "Warp DTM thread running.\n");253254while (!kthread_should_stop()) {255int val;256257val = i2c_smbus_read_word_data(client, 0);258if (val < 0)259dev_dbg(&client->dev, "DTM read temp failed.\n");260else {261s16 temp = swab16(val);262out_be32(fpga + 0x20, temp);263}264265pika_dtm_check_fan(fpga);266267set_current_state(TASK_INTERRUPTIBLE);268schedule_timeout(HZ);269}270271return 0;272}273274static int __init pika_dtm_start(void)275{276struct task_struct *dtm_thread;277struct device_node *np;278279np = of_find_compatible_node(NULL, NULL, "pika,fpga");280if (np == NULL)281return -ENOENT;282283dtm_fpga = of_iomap(np, 0);284of_node_put(np);285if (dtm_fpga == NULL)286return -ENOENT;287288/* Must get post info before thread starts. */289warp_post_info();290291dtm_thread = kthread_run(pika_dtm_thread, dtm_fpga, "pika-dtm");292if (IS_ERR(dtm_thread)) {293iounmap(dtm_fpga);294return PTR_ERR(dtm_thread);295}296297return 0;298}299machine_late_initcall(warp, pika_dtm_start);300301#else /* !CONFIG_SENSORS_AD7414 */302303int pika_dtm_register_shutdown(void (*func)(void *arg), void *arg)304{305return 0;306}307308int pika_dtm_unregister_shutdown(void (*func)(void *arg), void *arg)309{310return 0;311}312313machine_late_initcall(warp, warp_post_info);314315#endif316317EXPORT_SYMBOL(pika_dtm_register_shutdown);318EXPORT_SYMBOL(pika_dtm_unregister_shutdown);319320321