1 /*
2  * platform_wdt.c: Watchdog platform 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 #include <asm/intel-mid.h>
18 #include <asm/io_apic.h>
19 
20 #define TANGIER_EXT_TIMER0_MSI 15
21 
22 static struct platform_device wdt_dev = {
23 	.name = "intel_mid_wdt",
24 	.id = -1,
25 };
26 
tangier_probe(struct platform_device * pdev)27 static int tangier_probe(struct platform_device *pdev)
28 {
29 	int gsi;
30 	struct irq_alloc_info info;
31 	struct intel_mid_wdt_pdata *pdata = pdev->dev.platform_data;
32 
33 	if (!pdata)
34 		return -EINVAL;
35 
36 	/* IOAPIC builds identity mapping between GSI and IRQ on MID */
37 	gsi = pdata->irq;
38 	ioapic_set_alloc_attr(&info, cpu_to_node(0), 1, 0);
39 	if (mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info) <= 0) {
40 		dev_warn(&pdev->dev, "cannot find interrupt %d in ioapic\n",
41 			 gsi);
42 		return -EINVAL;
43 	}
44 
45 	return 0;
46 }
47 
48 static struct intel_mid_wdt_pdata tangier_pdata = {
49 	.irq = TANGIER_EXT_TIMER0_MSI,
50 	.probe = tangier_probe,
51 };
52 
register_mid_wdt(void)53 static int __init register_mid_wdt(void)
54 {
55 	if (intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_TANGIER) {
56 		wdt_dev.dev.platform_data = &tangier_pdata;
57 		return platform_device_register(&wdt_dev);
58 	}
59 
60 	return -ENODEV;
61 }
62 
63 rootfs_initcall(register_mid_wdt);
64