]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/x86/platform/intel-mid/device_libs/platform_mrfld_wdt.c
Linux 5.6-rc7
[linux.git] / arch / x86 / platform / intel-mid / device_libs / platform_mrfld_wdt.c
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/intel-mid.h>
15 #include <asm/intel_scu_ipc.h>
16 #include <asm/io_apic.h>
17 #include <asm/hw_irq.h>
18
19 #define TANGIER_EXT_TIMER0_MSI 12
20
21 static struct platform_device wdt_dev = {
22         .name = "intel_mid_wdt",
23         .id = -1,
24 };
25
26 static int tangier_probe(struct platform_device *pdev)
27 {
28         struct irq_alloc_info info;
29         struct intel_mid_wdt_pdata *pdata = pdev->dev.platform_data;
30         int gsi = TANGIER_EXT_TIMER0_MSI;
31         int irq;
32
33         if (!pdata)
34                 return -EINVAL;
35
36         /* IOAPIC builds identity mapping between GSI and IRQ on MID */
37         ioapic_set_alloc_attr(&info, cpu_to_node(0), 1, 0);
38         irq = mp_map_gsi_to_irq(gsi, IOAPIC_MAP_ALLOC, &info);
39         if (irq < 0) {
40                 dev_warn(&pdev->dev, "cannot find interrupt %d in ioapic\n", gsi);
41                 return irq;
42         }
43
44         pdata->irq = irq;
45         return 0;
46 }
47
48 static struct intel_mid_wdt_pdata tangier_pdata = {
49         .probe = tangier_probe,
50 };
51
52 static int wdt_scu_status_change(struct notifier_block *nb,
53                                  unsigned long code, void *data)
54 {
55         if (code == SCU_DOWN) {
56                 platform_device_unregister(&wdt_dev);
57                 return 0;
58         }
59
60         return platform_device_register(&wdt_dev);
61 }
62
63 static struct notifier_block wdt_scu_notifier = {
64         .notifier_call  = wdt_scu_status_change,
65 };
66
67 static int __init register_mid_wdt(void)
68 {
69         if (intel_mid_identify_cpu() != INTEL_MID_CPU_CHIP_TANGIER)
70                 return -ENODEV;
71
72         wdt_dev.dev.platform_data = &tangier_pdata;
73
74         /*
75          * We need to be sure that the SCU IPC is ready before watchdog device
76          * can be registered:
77          */
78         intel_scu_notifier_add(&wdt_scu_notifier);
79
80         return 0;
81 }
82 arch_initcall(register_mid_wdt);