This source file includes following definitions.
- of_gpio_spi_cs_get_count
- of_gpio_get_count
- of_gpiochip_match_node_and_xlate
- of_find_gpiochip_by_xlate
- of_xlate_and_get_gpiod_flags
- of_gpio_need_valid_mask
- of_gpio_flags_quirks
- of_get_named_gpiod_flags
- of_get_named_gpio_flags
- gpiod_get_from_of_node
- of_find_spi_gpio
- of_find_spi_cs_gpio
- of_find_regulator_gpio
- of_find_arizona_gpio
- of_find_gpio
- of_parse_own_gpio
- of_gpiochip_scan_gpios
- of_gpio_simple_xlate
- of_mm_gpiochip_add_data
- of_mm_gpiochip_remove
- of_gpiochip_init_valid_mask
- of_gpiochip_add_pin_range
- of_gpiochip_add_pin_range
- of_gpiochip_add
- of_gpiochip_remove
1
2
3
4
5
6
7
8
9
10 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/errno.h>
13 #include <linux/module.h>
14 #include <linux/io.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/of.h>
17 #include <linux/of_address.h>
18 #include <linux/of_gpio.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/slab.h>
21 #include <linux/gpio/machine.h>
22
23 #include "gpiolib.h"
24 #include "gpiolib-of.h"
25
26
27
28
29
30
31
32
33
34
35 int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
36 {
37 struct device_node *np = dev->of_node;
38
39 if (!IS_ENABLED(CONFIG_SPI_MASTER))
40 return 0;
41 if (!con_id || strcmp(con_id, "cs"))
42 return 0;
43 if (!of_device_is_compatible(np, "fsl,spi") &&
44 !of_device_is_compatible(np, "aeroflexgaisler,spictrl"))
45 return 0;
46 return of_gpio_named_count(np, "gpios");
47 }
48
49
50
51
52
53
54
55 int of_gpio_get_count(struct device *dev, const char *con_id)
56 {
57 int ret;
58 char propname[32];
59 unsigned int i;
60
61 ret = of_gpio_spi_cs_get_count(dev, con_id);
62 if (ret > 0)
63 return ret;
64
65 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
66 if (con_id)
67 snprintf(propname, sizeof(propname), "%s-%s",
68 con_id, gpio_suffixes[i]);
69 else
70 snprintf(propname, sizeof(propname), "%s",
71 gpio_suffixes[i]);
72
73 ret = of_gpio_named_count(dev->of_node, propname);
74 if (ret > 0)
75 break;
76 }
77 return ret ? ret : -ENOENT;
78 }
79
80 static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
81 {
82 struct of_phandle_args *gpiospec = data;
83
84 return chip->gpiodev->dev.of_node == gpiospec->np &&
85 chip->of_xlate &&
86 chip->of_xlate(chip, gpiospec, NULL) >= 0;
87 }
88
89 static struct gpio_chip *of_find_gpiochip_by_xlate(
90 struct of_phandle_args *gpiospec)
91 {
92 return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
93 }
94
95 static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
96 struct of_phandle_args *gpiospec,
97 enum of_gpio_flags *flags)
98 {
99 int ret;
100
101 if (chip->of_gpio_n_cells != gpiospec->args_count)
102 return ERR_PTR(-EINVAL);
103
104 ret = chip->of_xlate(chip, gpiospec, flags);
105 if (ret < 0)
106 return ERR_PTR(ret);
107
108 return gpiochip_get_desc(chip, ret);
109 }
110
111
112
113
114
115
116
117 bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
118 {
119 int size;
120 struct device_node *np = gc->of_node;
121
122 size = of_property_count_u32_elems(np, "gpio-reserved-ranges");
123 if (size > 0 && size % 2 == 0)
124 return true;
125 return false;
126 }
127
128 static void of_gpio_flags_quirks(struct device_node *np,
129 const char *propname,
130 enum of_gpio_flags *flags,
131 int index)
132 {
133
134
135
136 if (IS_ENABLED(CONFIG_MMC)) {
137
138
139
140
141
142
143
144
145 if (!strcmp(propname, "cd-gpios")) {
146 if (of_property_read_bool(np, "cd-inverted"))
147 *flags ^= OF_GPIO_ACTIVE_LOW;
148 }
149 }
150
151
152
153
154 if (IS_ENABLED(CONFIG_REGULATOR) &&
155 (of_device_is_compatible(np, "regulator-fixed") ||
156 of_device_is_compatible(np, "reg-fixed-voltage") ||
157 (!(strcmp(propname, "enable-gpio") &&
158 strcmp(propname, "enable-gpios")) &&
159 of_device_is_compatible(np, "regulator-gpio")))) {
160
161
162
163
164
165
166 if (*flags & OF_GPIO_ACTIVE_LOW) {
167 pr_warn("%s GPIO handle specifies active low - ignored\n",
168 of_node_full_name(np));
169 *flags &= ~OF_GPIO_ACTIVE_LOW;
170 }
171 if (!of_property_read_bool(np, "enable-active-high"))
172 *flags |= OF_GPIO_ACTIVE_LOW;
173 }
174
175
176
177 if (IS_ENABLED(CONFIG_REGULATOR) &&
178 of_device_is_compatible(np, "reg-fixed-voltage") &&
179 of_property_read_bool(np, "gpio-open-drain")) {
180 *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN);
181 pr_info("%s uses legacy open drain flag - update the DTS if you can\n",
182 of_node_full_name(np));
183 }
184
185
186
187
188
189
190 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
191 of_property_read_bool(np, "cs-gpios")) {
192 struct device_node *child;
193 u32 cs;
194 int ret;
195
196 for_each_child_of_node(np, child) {
197 ret = of_property_read_u32(child, "reg", &cs);
198 if (ret)
199 continue;
200 if (cs == index) {
201
202
203
204
205
206
207
208
209
210
211
212
213 if (of_property_read_bool(child, "spi-cs-high")) {
214 if (*flags & OF_GPIO_ACTIVE_LOW) {
215 pr_warn("%s GPIO handle specifies active low - ignored\n",
216 of_node_full_name(child));
217 *flags &= ~OF_GPIO_ACTIVE_LOW;
218 }
219 } else {
220 if (!(*flags & OF_GPIO_ACTIVE_LOW))
221 pr_info("%s enforce active low on chipselect handle\n",
222 of_node_full_name(child));
223 *flags |= OF_GPIO_ACTIVE_LOW;
224 }
225 of_node_put(child);
226 break;
227 }
228 }
229 }
230
231
232 if (IS_ENABLED(CONFIG_STMMAC_ETH) &&
233 !strcmp(propname, "snps,reset-gpio") &&
234 of_property_read_bool(np, "snps,reset-active-low"))
235 *flags |= OF_GPIO_ACTIVE_LOW;
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249 static struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
250 const char *propname, int index, enum of_gpio_flags *flags)
251 {
252 struct of_phandle_args gpiospec;
253 struct gpio_chip *chip;
254 struct gpio_desc *desc;
255 int ret;
256
257 ret = of_parse_phandle_with_args_map(np, propname, "gpio", index,
258 &gpiospec);
259 if (ret) {
260 pr_debug("%s: can't parse '%s' property of node '%pOF[%d]'\n",
261 __func__, propname, np, index);
262 return ERR_PTR(ret);
263 }
264
265 chip = of_find_gpiochip_by_xlate(&gpiospec);
266 if (!chip) {
267 desc = ERR_PTR(-EPROBE_DEFER);
268 goto out;
269 }
270
271 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags);
272 if (IS_ERR(desc))
273 goto out;
274
275 if (flags)
276 of_gpio_flags_quirks(np, propname, flags, index);
277
278 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n",
279 __func__, propname, np, index,
280 PTR_ERR_OR_ZERO(desc));
281
282 out:
283 of_node_put(gpiospec.np);
284
285 return desc;
286 }
287
288 int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
289 int index, enum of_gpio_flags *flags)
290 {
291 struct gpio_desc *desc;
292
293 desc = of_get_named_gpiod_flags(np, list_name, index, flags);
294
295 if (IS_ERR(desc))
296 return PTR_ERR(desc);
297 else
298 return desc_to_gpio(desc);
299 }
300 EXPORT_SYMBOL_GPL(of_get_named_gpio_flags);
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
317 const char *propname, int index,
318 enum gpiod_flags dflags,
319 const char *label)
320 {
321 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
322 struct gpio_desc *desc;
323 enum of_gpio_flags flags;
324 bool active_low = false;
325 bool single_ended = false;
326 bool open_drain = false;
327 bool transitory = false;
328 int ret;
329
330 desc = of_get_named_gpiod_flags(node, propname,
331 index, &flags);
332
333 if (!desc || IS_ERR(desc)) {
334 return desc;
335 }
336
337 active_low = flags & OF_GPIO_ACTIVE_LOW;
338 single_ended = flags & OF_GPIO_SINGLE_ENDED;
339 open_drain = flags & OF_GPIO_OPEN_DRAIN;
340 transitory = flags & OF_GPIO_TRANSITORY;
341
342 ret = gpiod_request(desc, label);
343 if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
344 return desc;
345 if (ret)
346 return ERR_PTR(ret);
347
348 if (active_low)
349 lflags |= GPIO_ACTIVE_LOW;
350
351 if (single_ended) {
352 if (open_drain)
353 lflags |= GPIO_OPEN_DRAIN;
354 else
355 lflags |= GPIO_OPEN_SOURCE;
356 }
357
358 if (transitory)
359 lflags |= GPIO_TRANSITORY;
360
361 ret = gpiod_configure_flags(desc, propname, lflags, dflags);
362 if (ret < 0) {
363 gpiod_put(desc);
364 return ERR_PTR(ret);
365 }
366
367 return desc;
368 }
369 EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
370
371
372
373
374
375
376 static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id,
377 enum of_gpio_flags *of_flags)
378 {
379 char prop_name[32];
380 struct device_node *np = dev->of_node;
381 struct gpio_desc *desc;
382
383
384
385
386
387 if (!IS_ENABLED(CONFIG_SPI_MASTER))
388 return ERR_PTR(-ENOENT);
389
390
391 if (!of_device_is_compatible(np, "spi-gpio") || !con_id)
392 return ERR_PTR(-ENOENT);
393
394
395 snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id);
396
397 desc = of_get_named_gpiod_flags(np, prop_name, 0, of_flags);
398 return desc;
399 }
400
401
402
403
404
405
406 static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev,
407 const char *con_id,
408 unsigned int idx,
409 unsigned long *flags)
410 {
411 struct device_node *np = dev->of_node;
412
413 if (!IS_ENABLED(CONFIG_SPI_MASTER))
414 return ERR_PTR(-ENOENT);
415
416
417 if (!of_device_is_compatible(np, "fsl,spi") &&
418 !of_device_is_compatible(np, "aeroflexgaisler,spictrl"))
419 return ERR_PTR(-ENOENT);
420
421 if (!con_id || strcmp(con_id, "cs"))
422 return ERR_PTR(-ENOENT);
423
424
425
426
427
428
429 return of_find_gpio(dev, NULL, idx, flags);
430 }
431
432
433
434
435
436
437 static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *con_id,
438 enum of_gpio_flags *of_flags)
439 {
440
441 const char *whitelist[] = {
442 "wlf,ldoena",
443 "wlf,ldo1ena",
444 "wlf,ldo2ena",
445 };
446 struct device_node *np = dev->of_node;
447 struct gpio_desc *desc;
448 int i;
449
450 if (!IS_ENABLED(CONFIG_REGULATOR))
451 return ERR_PTR(-ENOENT);
452
453 if (!con_id)
454 return ERR_PTR(-ENOENT);
455
456 i = match_string(whitelist, ARRAY_SIZE(whitelist), con_id);
457 if (i < 0)
458 return ERR_PTR(-ENOENT);
459
460 desc = of_get_named_gpiod_flags(np, con_id, 0, of_flags);
461 return desc;
462 }
463
464 static struct gpio_desc *of_find_arizona_gpio(struct device *dev,
465 const char *con_id,
466 enum of_gpio_flags *of_flags)
467 {
468 if (!IS_ENABLED(CONFIG_MFD_ARIZONA))
469 return ERR_PTR(-ENOENT);
470
471 if (!con_id || strcmp(con_id, "wlf,reset"))
472 return ERR_PTR(-ENOENT);
473
474 return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags);
475 }
476
477 struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
478 unsigned int idx, unsigned long *flags)
479 {
480 char prop_name[32];
481 enum of_gpio_flags of_flags;
482 struct gpio_desc *desc;
483 unsigned int i;
484
485
486 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
487 if (con_id)
488 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
489 gpio_suffixes[i]);
490 else
491 snprintf(prop_name, sizeof(prop_name), "%s",
492 gpio_suffixes[i]);
493
494 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
495 &of_flags);
496
497 if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
498 break;
499 }
500
501 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
502
503 desc = of_find_spi_gpio(dev, con_id, &of_flags);
504 }
505
506 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
507
508 desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
509 if (!IS_ERR(desc))
510 return desc;
511 }
512
513 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
514
515 desc = of_find_regulator_gpio(dev, con_id, &of_flags);
516 }
517
518 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
519 desc = of_find_arizona_gpio(dev, con_id, &of_flags);
520
521 if (IS_ERR(desc))
522 return desc;
523
524 if (of_flags & OF_GPIO_ACTIVE_LOW)
525 *flags |= GPIO_ACTIVE_LOW;
526
527 if (of_flags & OF_GPIO_SINGLE_ENDED) {
528 if (of_flags & OF_GPIO_OPEN_DRAIN)
529 *flags |= GPIO_OPEN_DRAIN;
530 else
531 *flags |= GPIO_OPEN_SOURCE;
532 }
533
534 if (of_flags & OF_GPIO_TRANSITORY)
535 *flags |= GPIO_TRANSITORY;
536
537 if (of_flags & OF_GPIO_PULL_UP)
538 *flags |= GPIO_PULL_UP;
539 if (of_flags & OF_GPIO_PULL_DOWN)
540 *flags |= GPIO_PULL_DOWN;
541
542 return desc;
543 }
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558 static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
559 struct gpio_chip *chip,
560 unsigned int idx, const char **name,
561 unsigned long *lflags,
562 enum gpiod_flags *dflags)
563 {
564 struct device_node *chip_np;
565 enum of_gpio_flags xlate_flags;
566 struct of_phandle_args gpiospec;
567 struct gpio_desc *desc;
568 unsigned int i;
569 u32 tmp;
570 int ret;
571
572 chip_np = chip->of_node;
573 if (!chip_np)
574 return ERR_PTR(-EINVAL);
575
576 xlate_flags = 0;
577 *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
578 *dflags = 0;
579
580 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp);
581 if (ret)
582 return ERR_PTR(ret);
583
584 gpiospec.np = chip_np;
585 gpiospec.args_count = tmp;
586
587 for (i = 0; i < tmp; i++) {
588 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
589 &gpiospec.args[i]);
590 if (ret)
591 return ERR_PTR(ret);
592 }
593
594 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
595 if (IS_ERR(desc))
596 return desc;
597
598 if (xlate_flags & OF_GPIO_ACTIVE_LOW)
599 *lflags |= GPIO_ACTIVE_LOW;
600 if (xlate_flags & OF_GPIO_TRANSITORY)
601 *lflags |= GPIO_TRANSITORY;
602
603 if (of_property_read_bool(np, "input"))
604 *dflags |= GPIOD_IN;
605 else if (of_property_read_bool(np, "output-low"))
606 *dflags |= GPIOD_OUT_LOW;
607 else if (of_property_read_bool(np, "output-high"))
608 *dflags |= GPIOD_OUT_HIGH;
609 else {
610 pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n",
611 desc_to_gpio(desc), np);
612 return ERR_PTR(-EINVAL);
613 }
614
615 if (name && of_property_read_string(np, "line-name", name))
616 *name = np->name;
617
618 return desc;
619 }
620
621
622
623
624
625
626
627
628
629 static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
630 {
631 struct gpio_desc *desc = NULL;
632 struct device_node *np;
633 const char *name;
634 unsigned long lflags;
635 enum gpiod_flags dflags;
636 unsigned int i;
637 int ret;
638
639 for_each_available_child_of_node(chip->of_node, np) {
640 if (!of_property_read_bool(np, "gpio-hog"))
641 continue;
642
643 for (i = 0;; i++) {
644 desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
645 &dflags);
646 if (IS_ERR(desc))
647 break;
648
649 ret = gpiod_hog(desc, name, lflags, dflags);
650 if (ret < 0) {
651 of_node_put(np);
652 return ret;
653 }
654 }
655 }
656
657 return 0;
658 }
659
660
661
662
663
664
665
666
667
668
669
670 static int of_gpio_simple_xlate(struct gpio_chip *gc,
671 const struct of_phandle_args *gpiospec,
672 u32 *flags)
673 {
674
675
676
677
678
679
680 if (gc->of_gpio_n_cells < 2) {
681 WARN_ON(1);
682 return -EINVAL;
683 }
684
685 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
686 return -EINVAL;
687
688 if (gpiospec->args[0] >= gc->ngpio)
689 return -EINVAL;
690
691 if (flags)
692 *flags = gpiospec->args[1];
693
694 return gpiospec->args[0];
695 }
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717 int of_mm_gpiochip_add_data(struct device_node *np,
718 struct of_mm_gpio_chip *mm_gc,
719 void *data)
720 {
721 int ret = -ENOMEM;
722 struct gpio_chip *gc = &mm_gc->gc;
723
724 gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
725 if (!gc->label)
726 goto err0;
727
728 mm_gc->regs = of_iomap(np, 0);
729 if (!mm_gc->regs)
730 goto err1;
731
732 gc->base = -1;
733
734 if (mm_gc->save_regs)
735 mm_gc->save_regs(mm_gc);
736
737 mm_gc->gc.of_node = np;
738
739 ret = gpiochip_add_data(gc, data);
740 if (ret)
741 goto err2;
742
743 return 0;
744 err2:
745 iounmap(mm_gc->regs);
746 err1:
747 kfree(gc->label);
748 err0:
749 pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret);
750 return ret;
751 }
752 EXPORT_SYMBOL_GPL(of_mm_gpiochip_add_data);
753
754
755
756
757
758 void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
759 {
760 struct gpio_chip *gc = &mm_gc->gc;
761
762 if (!mm_gc)
763 return;
764
765 gpiochip_remove(gc);
766 iounmap(mm_gc->regs);
767 kfree(gc->label);
768 }
769 EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove);
770
771 static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
772 {
773 int len, i;
774 u32 start, count;
775 struct device_node *np = chip->of_node;
776
777 len = of_property_count_u32_elems(np, "gpio-reserved-ranges");
778 if (len < 0 || len % 2 != 0)
779 return;
780
781 for (i = 0; i < len; i += 2) {
782 of_property_read_u32_index(np, "gpio-reserved-ranges",
783 i, &start);
784 of_property_read_u32_index(np, "gpio-reserved-ranges",
785 i + 1, &count);
786 if (start >= chip->ngpio || start + count >= chip->ngpio)
787 continue;
788
789 bitmap_clear(chip->valid_mask, start, count);
790 }
791 };
792
793 #ifdef CONFIG_PINCTRL
794 static int of_gpiochip_add_pin_range(struct gpio_chip *chip)
795 {
796 struct device_node *np = chip->of_node;
797 struct of_phandle_args pinspec;
798 struct pinctrl_dev *pctldev;
799 int index = 0, ret;
800 const char *name;
801 static const char group_names_propname[] = "gpio-ranges-group-names";
802 struct property *group_names;
803
804 if (!np)
805 return 0;
806
807 group_names = of_find_property(np, group_names_propname, NULL);
808
809 for (;; index++) {
810 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3,
811 index, &pinspec);
812 if (ret)
813 break;
814
815 pctldev = of_pinctrl_get(pinspec.np);
816 of_node_put(pinspec.np);
817 if (!pctldev)
818 return -EPROBE_DEFER;
819
820 if (pinspec.args[2]) {
821 if (group_names) {
822 of_property_read_string_index(np,
823 group_names_propname,
824 index, &name);
825 if (strlen(name)) {
826 pr_err("%pOF: Group name of numeric GPIO ranges must be the empty string.\n",
827 np);
828 break;
829 }
830 }
831
832 ret = gpiochip_add_pin_range(chip,
833 pinctrl_dev_get_devname(pctldev),
834 pinspec.args[0],
835 pinspec.args[1],
836 pinspec.args[2]);
837 if (ret)
838 return ret;
839 } else {
840
841 if (pinspec.args[1]) {
842 pr_err("%pOF: Illegal gpio-range format.\n",
843 np);
844 break;
845 }
846
847 if (!group_names) {
848 pr_err("%pOF: GPIO group range requested but no %s property.\n",
849 np, group_names_propname);
850 break;
851 }
852
853 ret = of_property_read_string_index(np,
854 group_names_propname,
855 index, &name);
856 if (ret)
857 break;
858
859 if (!strlen(name)) {
860 pr_err("%pOF: Group name of GPIO group range cannot be the empty string.\n",
861 np);
862 break;
863 }
864
865 ret = gpiochip_add_pingroup_range(chip, pctldev,
866 pinspec.args[0], name);
867 if (ret)
868 return ret;
869 }
870 }
871
872 return 0;
873 }
874
875 #else
876 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; }
877 #endif
878
879 int of_gpiochip_add(struct gpio_chip *chip)
880 {
881 int ret;
882
883 if (!chip->of_node)
884 return 0;
885
886 if (!chip->of_xlate) {
887 chip->of_gpio_n_cells = 2;
888 chip->of_xlate = of_gpio_simple_xlate;
889 }
890
891 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS)
892 return -EINVAL;
893
894 of_gpiochip_init_valid_mask(chip);
895
896 ret = of_gpiochip_add_pin_range(chip);
897 if (ret)
898 return ret;
899
900
901 if (!chip->names)
902 devprop_gpiochip_set_names(chip,
903 of_fwnode_handle(chip->of_node));
904
905 of_node_get(chip->of_node);
906
907 ret = of_gpiochip_scan_gpios(chip);
908 if (ret)
909 of_node_put(chip->of_node);
910
911 return ret;
912 }
913
914 void of_gpiochip_remove(struct gpio_chip *chip)
915 {
916 of_node_put(chip->of_node);
917 }