1 /*
2  * Intel Merrifield watchdog platform device library file
3  *
4  * (C) Copyright 2014 Intel Corporation
5  * Author: David Cohen <david.a.cohen@linux.intel.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; version 2
10  * of the License.
11  */
12 
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/platform_data/intel-mid_wdt.h>
17 
18 #include <asm/intel-mid.h>
19 #include <asm/intel_scu_ipc.h>
20 #include <asm/io_apic.h>
21 #include <asm/hw_irq.h>
22 
23 #define TANGIER_EXT_TIMER0_MSI 12
24 
25 static struct platform_device wdt_dev = {
26 	.name = "intel_mid_wdt",
27 	.id = -1,
28 };
29 
tangier_probe(struct platform_device * pdev)30 static int tangier_probe(struct platform_device *pdev)
31 {
32 	struct irq_alloc_info info;
33 	struct intel_mid_wdt_pdata *pdata = pdev->dev.platform_data;
34 	int gsi = TANGIER_EXT_TIMER0_MSI;
35 	int irq;
36 
37 	if (!pdata)
38 		return -EINVAL;
39 
40 	/* IOAPIC builds identity mapping between GSI and IRQ on MID */
41 	ioapic_set_alloc_attr(&info, cpu_to_node(0), 1, 0);
42 	irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
43 	if (irq < 0) {
44 		dev_warn(&pdev->dev, "cannot find interrupt %d in ioapic\n", gsi);
45 		return irq;
46 	}
47 
48 	pdata->irq = irq;
49 	return 0;
50 }
51 
52 static struct intel_mid_wdt_pdata tangier_pdata = {
53 	.probe = tangier_probe,
54 };
55 
wdt_scu_status_change(struct notifier_block * nb,unsigned long code,void * data)56 static int wdt_scu_status_change(struct notifier_block *nb,
57 				 unsigned long code, void *data)
58 {
59 	if (code == SCU_DOWN) {
60 		platform_device_unregister(&wdt_dev);
61 		return 0;
62 	}
63 
64 	return platform_device_register(&wdt_dev);
65 }
66 
67 static struct notifier_block wdt_scu_notifier = {
68 	.notifier_call	= wdt_scu_status_change,
69 };
70 
register_mid_wdt(void)71 static int __init register_mid_wdt(void)
72 {
73 	if (intel_mid_identify_cpu() != INTEL_MID_CPU_CHIP_TANGIER)
74 		return -ENODEV;
75 
76 	wdt_dev.dev.platform_data = &tangier_pdata;
77 
78 	/*
79 	 * We need to be sure that the SCU IPC is ready before watchdog device
80 	 * can be registered:
81 	 */
82 	intel_scu_notifier_add(&wdt_scu_notifier);
83 
84 	return 0;
85 }
86 arch_initcall(register_mid_wdt);
87