xref: /linux/drivers/platform/x86/intel_scu_wdt.c (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Intel Merrifield watchdog platform device library file
4  *
5  * (C) Copyright 2014 Intel Corporation
6  * Author: David Cohen <david.a.cohen@linux.intel.com>
7  */
8 
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/platform_device.h>
12 #include <linux/platform_data/intel-mid_wdt.h>
13 
14 #include <asm/cpu_device_id.h>
15 #include <asm/intel-family.h>
16 #include <asm/intel-mid.h>
17 #include <asm/io_apic.h>
18 #include <asm/hw_irq.h>
19 
20 #define TANGIER_EXT_TIMER0_MSI 12
21 
22 static struct platform_device wdt_dev = {
23 	.name = "intel_mid_wdt",
24 	.id = -1,
25 };
26 
27 static int tangier_probe(struct platform_device *pdev)
28 {
29 	struct irq_alloc_info info;
30 	struct intel_mid_wdt_pdata *pdata = pdev->dev.platform_data;
31 	int gsi = TANGIER_EXT_TIMER0_MSI;
32 	int irq;
33 
34 	if (!pdata)
35 		return -EINVAL;
36 
37 	/* IOAPIC builds identity mapping between GSI and IRQ on MID */
38 	ioapic_set_alloc_attr(&info, cpu_to_node(0), 1, 0);
39 	irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
40 	if (irq < 0) {
41 		dev_warn(&pdev->dev, "cannot find interrupt %d in ioapic\n", gsi);
42 		return irq;
43 	}
44 
45 	pdata->irq = irq;
46 	return 0;
47 }
48 
49 static struct intel_mid_wdt_pdata tangier_pdata = {
50 	.probe = tangier_probe,
51 };
52 
53 static const struct x86_cpu_id intel_mid_cpu_ids[] = {
54 	X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_MID, &tangier_pdata),
55 	{}
56 };
57 
58 static int __init register_mid_wdt(void)
59 {
60 	const struct x86_cpu_id *id;
61 
62 	id = x86_match_cpu(intel_mid_cpu_ids);
63 	if (!id)
64 		return -ENODEV;
65 
66 	wdt_dev.dev.platform_data = (struct intel_mid_wdt_pdata *)id->driver_data;
67 	return platform_device_register(&wdt_dev);
68 }
69 arch_initcall(register_mid_wdt);
70 
71 static void __exit unregister_mid_wdt(void)
72 {
73 	platform_device_unregister(&wdt_dev);
74 }
75 __exitcall(unregister_mid_wdt);
76