Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 1 | // 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 Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 11 | #include <acpi/acpi_device.h> |
Simon Glass | a847b27 | 2020-02-06 09:54:57 -0700 | [diff] [blame] | 12 | #include <asm/test.h> |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 13 | #include <dm/test.h> |
| 14 | #include <test/ut.h> |
| 15 | |
| 16 | /* Base test of the irq uclass */ |
| 17 | static 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 Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 34 | DM_TEST(dm_test_irq_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | a847b27 | 2020-02-06 09:54:57 -0700 | [diff] [blame] | 35 | |
| 36 | /* Test of irq_first_device_type() */ |
| 37 | static 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 Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 46 | DM_TEST(dm_test_irq_type, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 515dcff | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 47 | |
| 48 | /* Test of irq_read_and_clear() */ |
| 49 | static 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 Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 63 | DM_TEST(dm_test_read_and_clear, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 515dcff | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 64 | |
| 65 | /* Test of irq_request() */ |
| 66 | static 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 Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 78 | DM_TEST(dm_test_request, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 79 | |
| 80 | /* Test of irq_get_acpi() */ |
| 81 | static 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 Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 100 | DM_TEST(dm_test_irq_get_acpi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |