18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (C) 2012 Thomas Petazzoni
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
78c2ecf20Sopenharmony_ci * License version 2.  This program is licensed "as is" without any
88c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/acpi.h>
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/of_device.h>
148c2ecf20Sopenharmony_ci#include <linux/of_irq.h>
158c2ecf20Sopenharmony_ci#include <linux/irqchip.h>
168c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * This special of_device_id is the sentinel at the end of the
208c2ecf20Sopenharmony_ci * of_device_id[] array of all irqchips. It is automatically placed at
218c2ecf20Sopenharmony_ci * the end of the array by the linker, thanks to being part of a
228c2ecf20Sopenharmony_ci * special section.
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_cistatic const struct of_device_id
258c2ecf20Sopenharmony_ciirqchip_of_match_end __used __section("__irqchip_of_table_end");
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciextern struct of_device_id __irqchip_of_table[];
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_civoid __init irqchip_init(void)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	of_irq_init(__irqchip_of_table);
328c2ecf20Sopenharmony_ci	acpi_probe_device_table(irqchip);
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciint platform_irqchip_probe(struct platform_device *pdev)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	struct device_node *np = pdev->dev.of_node;
388c2ecf20Sopenharmony_ci	struct device_node *par_np = of_irq_find_parent(np);
398c2ecf20Sopenharmony_ci	of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	if (!irq_init_cb) {
428c2ecf20Sopenharmony_ci		of_node_put(par_np);
438c2ecf20Sopenharmony_ci		return -EINVAL;
448c2ecf20Sopenharmony_ci	}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (par_np == np)
478c2ecf20Sopenharmony_ci		par_np = NULL;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/*
508c2ecf20Sopenharmony_ci	 * If there's a parent interrupt controller and  none of the parent irq
518c2ecf20Sopenharmony_ci	 * domains have been registered, that means the parent interrupt
528c2ecf20Sopenharmony_ci	 * controller has not been initialized yet.  it's not time for this
538c2ecf20Sopenharmony_ci	 * interrupt controller to initialize. So, defer probe of this
548c2ecf20Sopenharmony_ci	 * interrupt controller. The actual initialization callback of this
558c2ecf20Sopenharmony_ci	 * interrupt controller can check for specific domains as necessary.
568c2ecf20Sopenharmony_ci	 */
578c2ecf20Sopenharmony_ci	if (par_np && !irq_find_matching_host(par_np, DOMAIN_BUS_ANY)) {
588c2ecf20Sopenharmony_ci		of_node_put(par_np);
598c2ecf20Sopenharmony_ci		return -EPROBE_DEFER;
608c2ecf20Sopenharmony_ci	}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	return irq_init_cb(np, par_np);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(platform_irqchip_probe);
65