blob: 51dd5e4abb413acb415a9c38523fb4eaaeaddf1f [file] [log] [blame]
Simon Glass54028bc2019-12-06 21:41:59 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for irq uclass
4 *
5 * Copyright 2019 Google LLC
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <irq.h>
Simon Glassb24cbf42020-07-07 13:11:41 -060011#include <acpi/acpi_device.h>
Simon Glassa847b272020-02-06 09:54:57 -070012#include <asm/test.h>
Simon Glass54028bc2019-12-06 21:41:59 -070013#include <dm/test.h>
14#include <test/ut.h>
15
16/* Base test of the irq uclass */
17static int dm_test_irq_base(struct unit_test_state *uts)
18{
19 struct udevice *dev;
20
21 ut_assertok(uclass_first_device_err(UCLASS_IRQ, &dev));
22
23 ut_asserteq(5, irq_route_pmc_gpio_gpe(dev, 4));
24 ut_asserteq(-ENOENT, irq_route_pmc_gpio_gpe(dev, 14));
25
26 ut_assertok(irq_set_polarity(dev, 4, true));
27 ut_asserteq(-EINVAL, irq_set_polarity(dev, 14, true));
28
29 ut_assertok(irq_snapshot_polarities(dev));
30 ut_assertok(irq_restore_polarities(dev));
31
32 return 0;
33}
Simon Glass974dccd2020-07-28 19:41:12 -060034DM_TEST(dm_test_irq_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassa847b272020-02-06 09:54:57 -070035
36/* Test of irq_first_device_type() */
37static int dm_test_irq_type(struct unit_test_state *uts)
38{
39 struct udevice *dev;
40
41 ut_assertok(irq_first_device_type(SANDBOX_IRQT_BASE, &dev));
42 ut_asserteq(-ENODEV, irq_first_device_type(X86_IRQT_BASE, &dev));
43
44 return 0;
45}
Simon Glass974dccd2020-07-28 19:41:12 -060046DM_TEST(dm_test_irq_type, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass515dcff2020-02-06 09:55:00 -070047
48/* Test of irq_read_and_clear() */
49static int dm_test_read_and_clear(struct unit_test_state *uts)
50{
51 struct irq irq;
52
53 ut_assertok(irq_first_device_type(SANDBOX_IRQT_BASE, &irq.dev));
54 irq.id = SANDBOX_IRQN_PEND;
55 ut_asserteq(0, irq_read_and_clear(&irq));
56 ut_asserteq(0, irq_read_and_clear(&irq));
57 ut_asserteq(0, irq_read_and_clear(&irq));
58 ut_asserteq(1, irq_read_and_clear(&irq));
59 ut_asserteq(0, irq_read_and_clear(&irq));
60
61 return 0;
62}
Simon Glass974dccd2020-07-28 19:41:12 -060063DM_TEST(dm_test_read_and_clear, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass515dcff2020-02-06 09:55:00 -070064
65/* Test of irq_request() */
66static int dm_test_request(struct unit_test_state *uts)
67{
68 struct udevice *dev;
69 struct irq irq;
70
71 ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
72 ut_asserteq_str("a-test", dev->name);
73 ut_assertok(irq_get_by_index(dev, 0, &irq));
74 ut_asserteq(3, irq.id);
75
76 return 0;
77}
Simon Glass974dccd2020-07-28 19:41:12 -060078DM_TEST(dm_test_request, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassb24cbf42020-07-07 13:11:41 -060079
80/* Test of irq_get_acpi() */
81static int dm_test_irq_get_acpi(struct unit_test_state *uts)
82{
83 struct acpi_irq airq;
84 struct udevice *dev;
85 struct irq irq;
86
87 ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
88 ut_assertok(irq_get_by_index(dev, 0, &irq));
89
90 /* see sandbox_get_acpi() */
91 ut_assertok(irq_get_acpi(&irq, &airq));
92 ut_asserteq(3, airq.pin);
93 ut_asserteq(ACPI_IRQ_LEVEL_TRIGGERED, airq.mode);
94 ut_asserteq(ACPI_IRQ_ACTIVE_HIGH, airq.polarity);
95 ut_asserteq(ACPI_IRQ_SHARED, airq.shared);
96 ut_asserteq(ACPI_IRQ_WAKE, airq.wake);
97
98 return 0;
99}
Simon Glass974dccd2020-07-28 19:41:12 -0600100DM_TEST(dm_test_irq_get_acpi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);