Lines Matching +full:motor +full:- +full:driver

1 // SPDX-License-Identifier: GPL-2.0
6 #define pr_fmt(fmt) "### dt-test ### " fmt
10 #include <linux/dma-direct.h> /* to test phys_to_dma/dma_to_phys */
29 #include <linux/i2c-mux.h>
30 #include <linux/gpio/driver.h>
54 #define OF_KREF_READ(NODE) kref_read(&(NODE)->kobj.kref)
85 np = of_find_node_by_path("/testcase-data");
87 unittest(np && name && !strcmp("/testcase-data", name),
88 "find /testcase-data failed\n");
93 np = of_find_node_by_path("/testcase-data/");
94 unittest(!np, "trailing '/' on /testcase-data/ should fail\n");
96 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
98 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
99 "find /testcase-data/phandle-tests/consumer-a failed\n");
103 np = of_find_node_by_path("testcase-alias");
105 unittest(np && name && !strcmp("/testcase-data", name),
106 "find testcase-alias failed\n");
111 np = of_find_node_by_path("testcase-alias/");
112 unittest(!np, "trailing '/' on testcase-alias/ should fail\n");
114 np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
116 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
117 "find testcase-alias/phandle-tests/consumer-a failed\n");
121 np = of_find_node_by_path("/testcase-data/missing-path");
122 unittest(!np, "non-existent path returned node %pOF\n", np);
125 np = of_find_node_by_path("missing-alias");
126 unittest(!np, "non-existent alias returned node %pOF\n", np);
129 np = of_find_node_by_path("testcase-alias/missing-path");
130 unittest(!np, "non-existent alias with relative path returned node %pOF\n", np);
133 np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
138 np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
143 np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
148 np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
152 np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
158 np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
164 np = of_find_node_opts_by_path("testcase-alias/phandle-tests/consumer-a:testaliasoption",
167 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name) &&
173 np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
178 np = of_find_node_opts_by_path("testcase-alias", &options);
193 np = of_find_node_by_path("/testcase-data");
206 /* Add a new property - should pass*/
207 prop->name = "new-property";
208 prop->value = "new-property-data";
209 prop->length = strlen(prop->value) + 1;
212 /* Try to add an existing property - should fail */
214 prop->name = "new-property";
215 prop->value = "new-property-data-should-fail";
216 prop->length = strlen(prop->value) + 1;
220 /* Try to modify an existing property - should pass */
221 prop->value = "modify-property-data-should-pass";
222 prop->length = strlen(prop->value) + 1;
226 /* Try to modify non-existent property - should pass*/
228 prop->name = "modify-property";
229 prop->value = "modify-missing-property-data-should-pass";
230 prop->length = strlen(prop->value) + 1;
234 /* Remove property - should pass */
238 /* Adding very large property - should pass */
240 prop->name = "large-property-PAGE_SIZEx8";
241 prop->length = PAGE_SIZE * 8;
242 prop->value = kzalloc(prop->length, GFP_KERNEL);
243 unittest(prop->value != NULL, "Unable to allocate large buffer\n");
244 if (prop->value)
254 if (child->parent != np) {
257 return -EINVAL;
302 size = snprintf(buf, buf_size - 2, fmt, np);
311 for (i = 0; i < 2; i++, size--) {
325 const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100";
334 num_to_str(phandle_str, sizeof(phandle_str), np->phandle, 0);
341 of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
346 of_unittest_printf_one(np, "%-10pOFP", "dev@100 ");
348 of_unittest_printf_one(np, "%pOFF", "----");
349 of_unittest_printf_one(np, "%pOFPF", "dev@100:----");
350 of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device");
351 of_unittest_printf_one(np, "%pOFc", "test-sub-device");
353 "\"test-sub-device\",\"test-compat2\",\"test-compat3\"");
370 if (!np->phandle)
373 hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
374 if (nh->np->phandle == np->phandle) {
376 np->phandle, nh->np, np);
386 nh->np = np;
387 hash_add(phandle_ht, &nh->node, np->phandle);
395 hash_del(&nh->node);
406 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
412 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
419 rc = of_parse_phandle_with_args(np, "phandle-list",
420 "#phandle-cells", i, &args);
422 /* Test the values from tests-phandle.dtsi */
436 passed &= (rc == -ENOENT);
461 passed &= (rc == -ENOENT);
467 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
476 rc = of_parse_phandle_with_args(np, "phandle-list-missing",
477 "#phandle-cells", 0, &args);
478 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
479 rc = of_count_phandle_with_args(np, "phandle-list-missing",
480 "#phandle-cells");
481 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
487 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
489 rc = of_parse_phandle_with_args(np, "phandle-list",
490 "#phandle-cells-missing", 0, &args);
493 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
495 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
498 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
500 rc = of_count_phandle_with_args(np, "phandle-list",
501 "#phandle-cells-missing");
504 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
506 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
512 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
514 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
515 "#phandle-cells", 0, &args);
518 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
520 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
523 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
525 rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
526 "#phandle-cells");
529 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
531 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
537 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
539 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
540 "#phandle-cells", 1, &args);
543 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
545 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
548 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
550 rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
551 "#phandle-cells");
554 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
556 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
566 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b");
572 p[0] = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
573 p[1] = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
574 p[2] = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
575 p[3] = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
576 p[4] = of_find_node_by_path("/testcase-data/phandle-tests/provider4");
577 p[5] = of_find_node_by_path("/testcase-data/phandle-tests/provider5");
586 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
593 rc = of_parse_phandle_with_args_map(np, "phandle-list",
596 /* Test the values from tests-phandle.dtsi */
613 passed &= (rc == -ENOENT);
647 passed &= (rc == -ENOENT);
653 unittest(passed, "index %i - data error on node %s rc=%i\n",
654 i, args.np->full_name, rc);
662 rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
664 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
670 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
672 rc = of_parse_phandle_with_args_map(np, "phandle-list",
673 "phandle-missing", 0, &args);
675 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
677 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
683 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678");
685 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
688 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678");
690 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
696 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
698 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
701 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
703 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
719 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
725 rc = of_property_match_string(np, "phandle-list-names", "first");
727 rc = of_property_match_string(np, "phandle-list-names", "second");
729 rc = of_property_match_string(np, "phandle-list-names", "third");
731 rc = of_property_match_string(np, "phandle-list-names", "fourth");
732 unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
733 rc = of_property_match_string(np, "missing-property", "blah");
734 unittest(rc == -EINVAL, "missing property; rc=%i\n", rc);
735 rc = of_property_match_string(np, "empty-property", "blah");
736 unittest(rc == -ENODATA, "empty property; rc=%i\n", rc);
737 rc = of_property_match_string(np, "unterminated-string", "blah");
738 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
741 rc = of_property_count_strings(np, "string-property");
743 rc = of_property_count_strings(np, "phandle-list-names");
745 rc = of_property_count_strings(np, "unterminated-string");
746 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
747 rc = of_property_count_strings(np, "unterminated-string-list");
748 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
751 rc = of_property_read_string_index(np, "string-property", 0, strings);
754 rc = of_property_read_string_index(np, "string-property", 1, strings);
755 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
756 rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
758 rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
760 rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
763 rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
764 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
766 rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
767 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
768 rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
771 rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
772 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
776 rc = of_property_read_string_array(np, "string-property", strings, 4);
778 rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
780 rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
781 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
782 /* -- An incorrectly formed string should cause a failure */
783 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
784 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
785 /* -- parsing the correctly formed strings should still work: */
787 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
790 rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
794 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
795 (p1)->value && (p2)->value && \
796 !memcmp((p1)->value, (p2)->value, (p1)->length) && \
797 !strcmp((p1)->name, (p2)->name))
810 unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
819 struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
823 struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
840 nchangeset = of_find_node_by_path("/testcase-data/changeset");
841 nremove = of_get_child_by_name(nchangeset, "node-remove");
860 n1->parent = parent;
861 n2->parent = parent;
862 n21->parent = n2;
864 ppremove = of_find_property(parent, "prop-remove", NULL);
880 unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n");
885 unittest(!of_changeset_add_prop_string(&chgset, n22, "prop-str", "abcd"),
886 "fail add prop prop-str");
887 unittest(!of_changeset_add_prop_string_array(&chgset, n22, "prop-str-array",
890 "fail add prop prop-str-array");
891 unittest(!of_changeset_add_prop_u32_array(&chgset, n22, "prop-u32-array",
893 "fail add prop prop-u32-array");
900 unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
903 unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n22")),
909 unittest(!of_find_node_by_path("/testcase-data/changeset/n2/n21"),
912 unittest(of_property_present(parent, "prop-remove"),
915 ret = of_property_read_string(parent, "prop-update", &propstr);
1037 nchangeset = of_find_node_by_path("/testcase-data/changeset");
1045 np = of_changeset_create_node(&chgset, nchangeset, "test-prop");
1046 if (unittest(np, "failed to create test-prop node\n"))
1049 ret = of_changeset_add_prop_string(&chgset, np, "prop-string", "abcde");
1050 unittest(ret == 0, "failed to add prop-string\n");
1052 ret = of_changeset_add_prop_string_array(&chgset, np, "prop-string-array",
1054 unittest(ret == 0, "failed to add prop-string-array\n");
1056 ret = of_changeset_add_prop_u32(&chgset, np, "prop-u32", 1234);
1057 unittest(ret == 0, "failed to add prop-u32\n");
1059 ret = of_changeset_add_prop_u32_array(&chgset, np, "prop-u32-array",
1061 unittest(ret == 0, "failed to add prop-u32-array\n");
1063 ret = of_changeset_add_prop_bool(&chgset, np, "prop-bool");
1064 unittest(ret == 0, "failed to add prop-bool\n");
1072 np = of_find_node_by_path("/testcase-data/changeset/test-prop");
1073 if (unittest(np, "failed to find test-prop node\n"))
1076 changeset_check_string(np, "prop-string", "abcde");
1077 changeset_check_string_array(np, "prop-string-array", str_array, ARRAY_SIZE(str_array));
1078 changeset_check_u32(np, "prop-u32", 1234);
1079 changeset_check_u32_array(np, "prop-u32-array", u32_array, ARRAY_SIZE(u32_array));
1080 changeset_check_bool(np, "prop-bool");
1102 np = of_find_node_by_path("/testcase-data/address-tests");
1144 dev_bogus->dma_range_map = map;
1164 of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
1167 of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
1169 of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
1183 np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000");
1190 pr_err("missing dma-ranges property\n");
1195 * Get the dma-ranges from the device tree
1234 np = of_find_node_by_path("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0");
1241 pr_err("missing dma-ranges property\n");
1246 * Get the dma-ranges from the device tree
1271 np = of_find_node_by_path("/testcase-data/address-tests");
1341 np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
1396 np = of_find_node_by_path("/testcase-data/address-tests/bus@80000000/device@1000");
1410 np = of_find_node_by_path("/testcase-data/platform-tests-2/node/test-device@100");
1417 unittest(ret == -EINVAL, "of_address_to_resource(%pOF) expected error on untranslatable address\n",
1450 while (count--) {
1451 ret = of_address_to_resource(np, expected->index, &res);
1453 np, expected->index, ret);
1454 unittest(resource_type(&res) == resource_type(&expected->res) &&
1455 res.start == expected->res.start &&
1456 resource_size(&res) == resource_size(&expected->res),
1458 np, expected->index, &res, &expected->res);
1487 of_unittest_check_addr("/testcase-data/address-tests2/bus-2cell@10000000/device@100000",
1491 of_unittest_check_addr("/testcase-data/address-tests2/bus-3cell@20000000/local-bus@100000/device@f1001000",
1495 of_unittest_check_addr("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0/dev@e0000000",
1509 np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
1525 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1530 np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
1542 /* Test the values from tests-phandle.dtsi */
1571 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1586 np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
1598 /* Test the values from tests-phandle.dtsi */
1639 * #address-cells. See the comments in
1640 * drivers/of/unittest-data/tests-interrupts.dtsi
1641 * nodes intmap1 and interrupts-extended0
1651 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1678 { .path = "/testcase-data/match-node/name0", .data = "A", },
1679 { .path = "/testcase-data/match-node/name1", .data = "B", },
1680 { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
1681 { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
1682 { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
1683 { .path = "/testcase-data/match-node/name3", .data = "E", },
1684 { .path = "/testcase-data/match-node/name4", .data = "G", },
1685 { .path = "/testcase-data/match-node/name5", .data = "H", },
1686 { .path = "/testcase-data/match-node/name6", .data = "G", },
1687 { .path = "/testcase-data/match-node/name7", .data = "I", },
1688 { .path = "/testcase-data/match-node/name8", .data = "J", },
1689 { .path = "/testcase-data/match-node/name9", .data = "K", },
1713 if (strcmp(match->data, match_node_tests[i].data) != 0) {
1716 (const char *)match->data);
1725 .name = "unittest-bus",
1733 { .compatible = "test-device", },
1737 np = of_find_node_by_path("/testcase-data");
1740 /* Test that a missing irq domain returns -EPROBE_DEFER */
1741 np = of_find_node_by_path("/testcase-data/testcase-device1");
1747 unittest(irq == -EPROBE_DEFER,
1748 "device deferred probe failed - %d\n", irq);
1750 /* Test that a parsing failure does not return -EPROBE_DEFER */
1751 np = of_find_node_by_path("/testcase-data/testcase-device2");
1756 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1761 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1763 unittest(irq < 0 && irq != -EPROBE_DEFER,
1764 "device parsing error failed - %d\n", irq);
1767 np = of_find_node_by_path("/testcase-data/platform-tests");
1779 test_bus->dev.of_node = np;
1783 * registered to catch problems with un-inserted resources. The
1790 of_platform_populate(np, match, NULL, &test_bus->dev);
1801 of_platform_depopulate(&test_bus->dev);
1814 * update_node_properties - adds the properties
1830 child->parent = dup;
1839 * compiled with the '-@' option. If you encounter this error,
1847 * sets prop->next to NULL
1849 for (prop = np->properties; prop != NULL; prop = save_next) {
1850 save_next = prop->next;
1853 if (ret == -EEXIST && !strcmp(prop->name, "name"))
1856 np, prop->name);
1862 * attach_node_and_children - attaches nodes
1864 * CAUTION: misleading function name - if node @np already exists in
1894 child = np->child;
1895 np->child = NULL;
1899 np->sibling = np->parent->child;
1900 np->parent->child = np;
1908 next = child->sibling;
1915 * unittest_data_add - Reads, copies data from
1929 const int size = __dtbo_testcases_end - __dtbo_testcases_begin;
1935 return -ENODATA;
1941 return -ENOMEM;
1950 return -ENODATA;
1955 return -ENODATA;
1967 return -EINVAL;
1970 /* attach the sub-tree to live tree */
1972 pr_warn("%s: no live tree to attach sub-tree\n", __func__);
1974 return -ENODEV;
1978 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1980 np = unittest_data_node->child;
1982 struct device_node *next = np->sibling;
1984 np->parent = of_root;
1991 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
2003 struct device *dev = &pdev->dev;
2004 struct device_node *np = dev->of_node;
2008 return -EINVAL;
2014 of_platform_populate(np, NULL, NULL, &pdev->dev);
2021 struct device *dev = &pdev->dev;
2022 struct device_node *np = dev->of_node;
2035 .driver = {
2081 pr_debug("%s(): %s %d %d\n", __func__, chip->label, offset,
2095 return -ENOMEM;
2099 devptr->chip.fwnode = dev_fwnode(&pdev->dev);
2100 devptr->chip.label = "of-unittest-gpio";
2101 devptr->chip.base = -1; /* dynamic allocation */
2102 devptr->chip.ngpio = 5;
2103 devptr->chip.request = unittest_gpio_chip_request;
2105 ret = gpiochip_add_data(&devptr->chip, NULL);
2108 "gpiochip_add_data() for node @%pfw failed, ret = %d\n", devptr->chip.fwnode, ret);
2118 struct device *dev = &pdev->dev;
2120 dev_dbg(dev, "%s for node @%pfw\n", __func__, devptr->chip.fwnode);
2122 if (devptr->chip.base != -1)
2123 gpiochip_remove(&devptr->chip);
2129 { .compatible = "unittest-gpio", },
2136 .driver = {
2137 .name = "unittest-gpio",
2149 * tests: apply overlays before registering driver
2150 * Similar to installing a driver as a module, the
2151 * driver is registered after applying the overlays.
2158 * - apply overlay_gpio_01
2159 * - apply overlay_gpio_02a
2160 * - apply overlay_gpio_02b
2161 * - register driver
2163 * register driver will result in
2164 * - probe and processing gpio hog for overlay_gpio_01
2165 * - probe for overlay_gpio_02a
2166 * - processing gpio for overlay_gpio_02b
2188 if (unittest(ret == 0, "could not register unittest gpio driver\n"))
2196 unittest_gpio_chip_request_count - chip_request_count);
2199 * tests: apply overlays after registering driver
2201 * Similar to a driver built-in to the kernel, the
2202 * driver is registered before applying the overlays.
2206 * - apply overlay_gpio_03
2209 * - probe and processing gpio hog.
2225 unittest_gpio_chip_request_count - chip_request_count);
2230 * - apply overlay_gpio_04a
2233 * - probe for overlay_gpio_04a
2250 * - apply overlay_gpio_04b
2253 * - processing gpio for overlay_gpio_04b
2263 unittest_gpio_chip_request_count - chip_request_count);
2300 put_device(&client->dev);
2334 base = "/testcase-data/overlay-node/test-bus";
2337 base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
2343 snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr);
2344 buf[sizeof(buf) - 1] = '\0';
2367 snprintf(buf, sizeof(buf) - 1,
2369 buf[sizeof(buf) - 1] = '\0';
2374 static const char *bus_path = "/testcase-data/overlay-node/test-bus";
2397 track_ovcs_id_cnt--;
2410 ovcs_id = track_ovcs_id[track_ovcs_id_cnt - 1];
2411 overlay_nr = track_ovcs_id_overlay_nr[track_ovcs_id_cnt - 1];
2414 if (ret == -ENODEV) {
2437 return -EFAULT;
2456 return -EINVAL;
2473 return -EINVAL;
2521 return -EINVAL;
2533 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2539 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2553 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2559 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2574 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2580 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2593 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2599 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2623 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2629 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2663 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2677 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2680 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2694 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2710 for (i = 1; i >= 0; i--) {
2750 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2759 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2770 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2776 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2790 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2801 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2816 for (i = 1; i >= 0; i--) {
2844 child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
2896 struct device *dev = &pdev->dev;
2897 struct device_node *np = dev->of_node;
2904 return -EINVAL;
2912 return -ENOMEM;
2915 std->pdev = pdev;
2918 adap = &std->adap;
2920 adap->nr = -1;
2921 strscpy(adap->name, pdev->name, sizeof(adap->name));
2922 adap->class = I2C_CLASS_DEPRECATED;
2923 adap->algo = &unittest_i2c_algo;
2924 adap->dev.parent = dev;
2925 adap->dev.of_node = dev->of_node;
2926 adap->timeout = 5 * HZ;
2927 adap->retries = 3;
2940 struct device *dev = &pdev->dev;
2941 struct device_node *np = dev->of_node;
2945 i2c_del_adapter(&std->adap);
2949 { .compatible = "unittest-i2c-bus", },
2956 .driver = {
2957 .name = "unittest-i2c-bus",
2964 struct device *dev = &client->dev;
2965 struct device_node *np = client->dev.of_node;
2969 return -EINVAL;
2979 struct device *dev = &client->dev;
2980 struct device_node *np = client->dev.of_node;
2986 { .name = "unittest-i2c-dev" },
2991 .driver = {
2992 .name = "unittest-i2c-dev",
3009 struct device *dev = &client->dev;
3010 struct i2c_adapter *adap = client->adapter;
3011 struct device_node *np = client->dev.of_node, *child;
3019 return -EINVAL;
3022 max_reg = (u32)-1;
3026 if (max_reg == (u32)-1 || reg > max_reg)
3029 nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
3032 return -EINVAL;
3038 return -ENOMEM;
3043 return -ENODEV;
3054 struct device *dev = &client->dev;
3055 struct device_node *np = client->dev.of_node;
3063 { .name = "unittest-i2c-mux" },
3068 .driver = {
3069 .name = "unittest-i2c-mux",
3084 "could not register unittest i2c device driver\n"))
3090 "could not register unittest i2c bus driver\n"))
3096 "i2c i2c-1: Added multiplexed i2c bus 2");
3101 "i2c i2c-1: Added multiplexed i2c bus 2");
3104 "could not register unittest i2c mux driver\n"))
3126 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
3131 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
3145 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
3151 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
3170 "i2c i2c-1: Added multiplexed i2c bus 3");
3175 "i2c i2c-1: Added multiplexed i2c bus 3");
3201 * ret = -EBUSY which is -16.
3210 of_node_get(nd->overlay);
3215 found = of_find_node_by_name(nd->overlay, "test-unittest16");
3218 ret = -EBUSY;
3223 found = of_find_node_by_name(nd->overlay, "test-unittest17");
3226 ret = -EEXIST;
3231 found = of_find_node_by_name(nd->overlay, "test-unittest18");
3234 ret = -EXDEV;
3239 found = of_find_node_by_name(nd->overlay, "test-unittest19");
3242 ret = -ENODEV;
3247 of_node_put(nd->overlay);
3248 ret = -EINVAL;
3279 * Applying overlays 16 - 19 will each trigger an error for a
3285 /* --- overlay 16 --- */
3287 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
3292 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
3296 /* --- overlay 17 --- */
3298 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
3303 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
3307 /* --- overlay 18 --- */
3315 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3318 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3319 if (ret == -EXDEV) {
3333 /* --- overlay 19 --- */
3341 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3343 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3344 if (ret == -ENODEV)
3355 /* --- overlay 20 --- */
3379 unittest(0, "could not register unittest driver\n");
3456 const char *refcount_path = "/testcase-data/refcount-node";
3457 const char *refcount_parent_path = "/testcase-data";
3460 * Node lifecycle tests, non-dynamic node:
3462 * - Decrementing refcount to zero via of_node_put() should cause the
3466 * - Decrementing refcount past zero should result in additional
3482 refcount = kref_read(&np->kobj.kref);
3489 EXPECT_BEGIN(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3496 unittest(1, "/testcase-data/refcount-node is one");
3499 EXPECT_END(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3510 EXPECT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3512 EXPECT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3513 EXPECT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3516 unittest(1, "/testcase-data/refcount-node is zero");
3519 EXPECT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3520 EXPECT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3522 EXPECT_END(KERN_INFO, "------------[ cut here ]------------");
3528 EXPECT_NOT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3530 EXPECT_NOT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3531 EXPECT_NOT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3533 unittest(1, "/testcase-data/refcount-node is zero, second time");
3536 EXPECT_NOT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3537 EXPECT_NOT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3539 EXPECT_NOT_END(KERN_INFO, "------------[ cut here ]------------");
3543 * attempt to of_node_get() node "refcount-node". One example of
3548 * Prevent the stack trace by removing node "refcount-node" from
3553 * Directly manipulate the child list of node /testcase-data to
3554 * remove child refcount-node. This is ignoring all proper methods
3564 prev_sibling = np->child;
3565 next_sibling = prev_sibling->sibling;
3566 if (!strcmp(prev_sibling->full_name, "refcount-node")) {
3567 np->child = next_sibling;
3568 next_sibling = next_sibling->sibling;
3571 if (!strcmp(next_sibling->full_name, "refcount-node"))
3572 prev_sibling->sibling = next_sibling->sibling;
3574 next_sibling = next_sibling->sibling;
3650 OVERLAY_INFO(overlay_base, -9999, 0),
3667 OVERLAY_INFO(overlay_16, -EBUSY, 0),
3668 OVERLAY_INFO(overlay_17, -EEXIST, 0),
3679 OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL, -ENODEV),
3680 OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL, -ENODEV),
3681 OVERLAY_INFO(overlay_bad_phandle, -EINVAL, 0),
3682 OVERLAY_INFO(overlay_bad_symbol, -EINVAL, -ENODEV),
3683 OVERLAY_INFO(overlay_bad_unresolved, -EINVAL, 0),
3718 for (info = overlays; info && info->name; info++) {
3719 if (!strcmp(overlay_name, info->name)) {
3731 if (info->expected_result != -9999) {
3736 data_size = info->dtbo_end - info->dtbo_begin;
3742 size = fdt_totalsize(info->dtbo_begin);
3754 memcpy(new_fdt, info->dtbo_begin, size);
3766 * /proc/device-tree/ contains the updated structure and values from
3779 for (info = overlays; info && info->name; info++) {
3780 if (!strcmp(overlay_name, info->name)) {
3790 size = info->dtbo_end - info->dtbo_begin;
3794 ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id,
3797 *ovcs_id = info->ovcs_id;
3804 if (ret != info->expected_result) {
3806 info->expected_result, ret, overlay_name);
3812 ret2 = of_overlay_remove(&info->ovcs_id);
3813 if (ret2 != info->expected_result_remove) {
3815 info->expected_result_remove, ret2,
3865 pprev = &overlay_base_root->child;
3866 for (np = overlay_base_root->child; np; np = np->sibling) {
3868 *pprev = np->sibling;
3871 pprev = &np->sibling;
3878 pprev = &overlay_base_root->child;
3879 for (np = overlay_base_root->child; np; np = np->sibling) {
3882 *pprev = np->sibling;
3885 pprev = &np->sibling;
3892 if (!strcmp(np->full_name, base_child->full_name)) {
3910 for (np = overlay_base_root->child; np; np = np->sibling)
3911 np->parent = of_root;
3915 for (last_sibling = np = of_root->child; np; np = np->sibling)
3919 last_sibling->sibling = overlay_base_root->child;
3921 of_root->child = overlay_base_root->child;
3933 prop->name);
3938 /* "name" auto-generated by unflatten */
3939 if (!strcmp(prop->name, "name"))
3942 prop->name);
3947 prop->name);
3958 /* --- overlay --- */
3961 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3963 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3965 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3967 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3969 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3971 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3973 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3994 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3996 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3998 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
4000 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
4002 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
4004 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
4006 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
4010 /* --- overlay_bad_add_dup_node --- */
4013 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
4015 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
4017 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
4019 "OF: Error reverting changeset (-19)");
4025 "OF: Error reverting changeset (-19)");
4027 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
4029 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
4031 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
4033 /* --- overlay_bad_add_dup_prop --- */
4036 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
4038 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
4040 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
4042 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
4044 "OF: Error reverting changeset (-19)");
4050 "OF: Error reverting changeset (-19)");
4052 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
4054 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
4056 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
4058 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
4060 /* --- overlay_bad_phandle --- */
4065 /* --- overlay_bad_symbol --- */
4068 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
4070 "OF: Error reverting changeset (-19)");
4076 "OF: Error reverting changeset (-19)");
4078 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
4080 /* --- overlay_bad_unresolved --- */
4085 "OF: resolver: overlay phandle fixup failed: -22");
4091 "OF: resolver: overlay phandle fixup failed: -22");
4105 * PCI device tree node test driver
4119 dn = pdev->dev.of_node;
4121 dev_err(&pdev->dev, "does not find bus endpoint");
4122 return -EINVAL;
4125 for (info = overlays; info && info->name; info++) {
4126 if (!strcmp(info->name, "overlay_pci_node"))
4129 if (!info || !info->name) {
4130 dev_err(&pdev->dev, "no overlay data for overlay_pci_node");
4131 return -ENODEV;
4134 size = info->dtbo_end - info->dtbo_begin;
4135 ret = of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn);
4140 of_platform_default_populate(dn, NULL, &pdev->dev);
4150 of_platform_depopulate(&pdev->dev);
4169 return -ENODEV;
4171 dev = &pdev->dev;
4173 dev = dev->parent;
4176 return -ENODEV;
4180 unittest(res->start == exp_addr, "Incorrect translated address %llx, expected %llx\n",
4181 (u64)res->start, exp_addr);
4189 { .compatible = "unittest-pci" },
4195 .driver = {
4196 .name = "unittest-pci",
4209 pnp = pdev->dev.of_node;
4212 return -ENODEV;
4215 path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp);
4217 unittest(np, "Failed to get unittest-pci node under PCI node\n");
4219 rc = -ENODEV;
4226 rc = -ENODEV;
4228 path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp);
4231 child_dev = device_find_any_child(&pdev->dev);
4252 unittest(!rc, "Failed to register pci test driver; rc = %d\n", rc);
4257 if (unittest(!rc, "Failed to register unittest pci driver\n")) {
4270 "No test PCI device been found. Please run QEMU with '-device pci-testdev'\n");
4295 pr_info("start of unittest - you will see error messages\n");
4307 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
4346 pr_info("end of unittest - %i passed, %i failed\n",