Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Pin controller and GPIO driver for Amlogic Meson SoCs
4 *
5 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
6 */
7
8/*
9 * The available pins are organized in banks (A,B,C,D,E,X,Y,Z,AO,
10 * BOOT,CARD for meson6, X,Y,DV,H,Z,AO,BOOT,CARD for meson8 and
11 * X,Y,DV,H,AO,BOOT,CARD,DIF for meson8b) and each bank has a
12 * variable number of pins.
13 *
14 * The AO bank is special because it belongs to the Always-On power
15 * domain which can't be powered off; the bank also uses a set of
16 * registers different from the other banks.
17 *
18 * For each pin controller there are 4 different register ranges that
19 * control the following properties of the pins:
20 * 1) pin muxing
21 * 2) pull enable/disable
22 * 3) pull up/down
23 * 4) GPIO direction, output value, input value
24 *
25 * In some cases the register ranges for pull enable and pull
26 * direction are the same and thus there are only 3 register ranges.
27 *
28 * Since Meson G12A SoC, the ao register ranges for gpio, pull enable
29 * and pull direction are the same, so there are only 2 register ranges.
30 *
31 * For the pull and GPIO configuration every bank uses a contiguous
32 * set of bits in the register sets described above; the same register
33 * can be shared by more banks with different offsets.
34 *
35 * In addition to this there are some registers shared between all
36 * banks that control the IRQ functionality. This feature is not
37 * supported at the moment by the driver.
38 */
39
40#include <linux/device.h>
41#include <linux/gpio/driver.h>
42#include <linux/init.h>
43#include <linux/io.h>
44#include <linux/of.h>
45#include <linux/of_address.h>
46#include <linux/of_device.h>
47#include <linux/pinctrl/pinconf-generic.h>
48#include <linux/pinctrl/pinconf.h>
49#include <linux/pinctrl/pinctrl.h>
50#include <linux/pinctrl/pinmux.h>
51#include <linux/platform_device.h>
52#include <linux/regmap.h>
53#include <linux/seq_file.h>
54
55#include "../core.h"
56#include "../pinctrl-utils.h"
57#include "pinctrl-meson.h"
58
59/**
60 * meson_get_bank() - find the bank containing a given pin
61 *
62 * @pc: the pinctrl instance
63 * @pin: the pin number
64 * @bank: the found bank
65 *
66 * Return: 0 on success, a negative value on error
67 */
68static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin,
69 struct meson_bank **bank)
70{
71 int i;
72
73 for (i = 0; i < pc->data->num_banks; i++) {
74 if (pin >= pc->data->banks[i].first &&
75 pin <= pc->data->banks[i].last) {
76 *bank = &pc->data->banks[i];
77 return 0;
78 }
79 }
80
81 return -EINVAL;
82}
83
84/**
85 * meson_calc_reg_and_bit() - calculate register and bit for a pin
86 *
87 * @bank: the bank containing the pin
88 * @pin: the pin number
89 * @reg_type: the type of register needed (pull-enable, pull, etc...)
90 * @reg: the computed register offset
91 * @bit: the computed bit
92 */
93static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin,
94 enum meson_reg_type reg_type,
95 unsigned int *reg, unsigned int *bit)
96{
97 struct meson_reg_desc *desc = &bank->regs[reg_type];
98
99 *reg = desc->reg * 4;
100 *bit = desc->bit + pin - bank->first;
101}
102
103static int meson_get_groups_count(struct pinctrl_dev *pcdev)
104{
105 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
106
107 return pc->data->num_groups;
108}
109
110static const char *meson_get_group_name(struct pinctrl_dev *pcdev,
111 unsigned selector)
112{
113 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
114
115 return pc->data->groups[selector].name;
116}
117
118static int meson_get_group_pins(struct pinctrl_dev *pcdev, unsigned selector,
119 const unsigned **pins, unsigned *num_pins)
120{
121 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
122
123 *pins = pc->data->groups[selector].pins;
124 *num_pins = pc->data->groups[selector].num_pins;
125
126 return 0;
127}
128
129static void meson_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s,
130 unsigned offset)
131{
132 seq_printf(s, " %s", dev_name(pcdev->dev));
133}
134
135static const struct pinctrl_ops meson_pctrl_ops = {
136 .get_groups_count = meson_get_groups_count,
137 .get_group_name = meson_get_group_name,
138 .get_group_pins = meson_get_group_pins,
139 .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
140 .dt_free_map = pinctrl_utils_free_map,
141 .pin_dbg_show = meson_pin_dbg_show,
142};
143
144int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev)
145{
146 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
147
148 return pc->data->num_funcs;
149}
150
151const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
152 unsigned selector)
153{
154 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
155
156 return pc->data->funcs[selector].name;
157}
158
159int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector,
160 const char * const **groups,
161 unsigned * const num_groups)
162{
163 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
164
165 *groups = pc->data->funcs[selector].groups;
166 *num_groups = pc->data->funcs[selector].num_groups;
167
168 return 0;
169}
170
171static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc,
172 unsigned int pin,
173 unsigned int reg_type,
174 bool arg)
175{
176 struct meson_bank *bank;
177 unsigned int reg, bit;
178 int ret;
179
180 ret = meson_get_bank(pc, pin, &bank);
181 if (ret)
182 return ret;
183
184 meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit);
185 return regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
186 arg ? BIT(bit) : 0);
187}
188
189static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc,
190 unsigned int pin,
191 unsigned int reg_type)
192{
193 struct meson_bank *bank;
194 unsigned int reg, bit, val;
195 int ret;
196
197 ret = meson_get_bank(pc, pin, &bank);
198 if (ret)
199 return ret;
200
201 meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit);
202 ret = regmap_read(pc->reg_gpio, reg, &val);
203 if (ret)
204 return ret;
205
206 return BIT(bit) & val ? 1 : 0;
207}
208
209static int meson_pinconf_set_output(struct meson_pinctrl *pc,
210 unsigned int pin,
211 bool out)
212{
213 return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out);
214}
215
216static int meson_pinconf_get_output(struct meson_pinctrl *pc,
217 unsigned int pin)
218{
219 int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR);
220
221 if (ret < 0)
222 return ret;
223
224 return !ret;
225}
226
227static int meson_pinconf_set_drive(struct meson_pinctrl *pc,
228 unsigned int pin,
229 bool high)
230{
231 return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high);
232}
233
234static int meson_pinconf_get_drive(struct meson_pinctrl *pc,
235 unsigned int pin)
236{
237 return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT);
238}
239
240static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc,
241 unsigned int pin,
242 bool high)
243{
244 int ret;
245
246 ret = meson_pinconf_set_output(pc, pin, true);
247 if (ret)
248 return ret;
249
250 return meson_pinconf_set_drive(pc, pin, high);
251}
252
253static int meson_pinconf_disable_bias(struct meson_pinctrl *pc,
254 unsigned int pin)
255{
256 struct meson_bank *bank;
257 unsigned int reg, bit = 0;
258 int ret;
259
260 ret = meson_get_bank(pc, pin, &bank);
261 if (ret)
262 return ret;
263
264 meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit);
265 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0);
266 if (ret)
267 return ret;
268
269 return 0;
270}
271
272static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin,
273 bool pull_up)
274{
275 struct meson_bank *bank;
276 unsigned int reg, bit, val = 0;
277 int ret;
278
279 ret = meson_get_bank(pc, pin, &bank);
280 if (ret)
281 return ret;
282
283 meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit);
284 if (pull_up)
285 val = BIT(bit);
286
287 ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val);
288 if (ret)
289 return ret;
290
291 meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit);
292 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit));
293 if (ret)
294 return ret;
295
296 return 0;
297}
298
299static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc,
300 unsigned int pin,
301 u16 drive_strength_ua)
302{
303 struct meson_bank *bank;
304 unsigned int reg, bit, ds_val;
305 int ret;
306
307 if (!pc->reg_ds) {
308 dev_err(pc->dev, "drive-strength not supported\n");
309 return -ENOTSUPP;
310 }
311
312 ret = meson_get_bank(pc, pin, &bank);
313 if (ret)
314 return ret;
315
316 meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit);
317 bit = bit << 1;
318
319 if (drive_strength_ua <= 500) {
320 ds_val = MESON_PINCONF_DRV_500UA;
321 } else if (drive_strength_ua <= 2500) {
322 ds_val = MESON_PINCONF_DRV_2500UA;
323 } else if (drive_strength_ua <= 3000) {
324 ds_val = MESON_PINCONF_DRV_3000UA;
325 } else if (drive_strength_ua <= 4000) {
326 ds_val = MESON_PINCONF_DRV_4000UA;
327 } else {
328 dev_warn_once(pc->dev,
329 "pin %u: invalid drive-strength : %d , default to 4mA\n",
330 pin, drive_strength_ua);
331 ds_val = MESON_PINCONF_DRV_4000UA;
332 }
333
334 ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit);
335 if (ret)
336 return ret;
337
338 return 0;
339}
340
341static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin,
342 unsigned long *configs, unsigned num_configs)
343{
344 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
345 enum pin_config_param param;
346 unsigned int arg = 0;
347 int i, ret;
348
349 for (i = 0; i < num_configs; i++) {
350 param = pinconf_to_config_param(configs[i]);
351
352 switch (param) {
353 case PIN_CONFIG_DRIVE_STRENGTH_UA:
354 case PIN_CONFIG_OUTPUT_ENABLE:
355 case PIN_CONFIG_OUTPUT:
356 arg = pinconf_to_config_argument(configs[i]);
357 break;
358
359 default:
360 break;
361 }
362
363 switch (param) {
364 case PIN_CONFIG_BIAS_DISABLE:
365 ret = meson_pinconf_disable_bias(pc, pin);
366 break;
367 case PIN_CONFIG_BIAS_PULL_UP:
368 ret = meson_pinconf_enable_bias(pc, pin, true);
369 break;
370 case PIN_CONFIG_BIAS_PULL_DOWN:
371 ret = meson_pinconf_enable_bias(pc, pin, false);
372 break;
373 case PIN_CONFIG_DRIVE_STRENGTH_UA:
374 ret = meson_pinconf_set_drive_strength(pc, pin, arg);
375 break;
376 case PIN_CONFIG_OUTPUT_ENABLE:
377 ret = meson_pinconf_set_output(pc, pin, arg);
378 break;
379 case PIN_CONFIG_OUTPUT:
380 ret = meson_pinconf_set_output_drive(pc, pin, arg);
381 break;
382 default:
383 ret = -ENOTSUPP;
384 }
385
386 if (ret)
387 return ret;
388 }
389
390 return 0;
391}
392
393static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin)
394{
395 struct meson_bank *bank;
396 unsigned int reg, bit, val;
397 int ret, conf;
398
399 ret = meson_get_bank(pc, pin, &bank);
400 if (ret)
401 return ret;
402
403 meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit);
404
405 ret = regmap_read(pc->reg_pullen, reg, &val);
406 if (ret)
407 return ret;
408
409 if (!(val & BIT(bit))) {
410 conf = PIN_CONFIG_BIAS_DISABLE;
411 } else {
412 meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit);
413
414 ret = regmap_read(pc->reg_pull, reg, &val);
415 if (ret)
416 return ret;
417
418 if (val & BIT(bit))
419 conf = PIN_CONFIG_BIAS_PULL_UP;
420 else
421 conf = PIN_CONFIG_BIAS_PULL_DOWN;
422 }
423
424 return conf;
425}
426
427static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc,
428 unsigned int pin,
429 u16 *drive_strength_ua)
430{
431 struct meson_bank *bank;
432 unsigned int reg, bit;
433 unsigned int val;
434 int ret;
435
436 if (!pc->reg_ds)
437 return -ENOTSUPP;
438
439 ret = meson_get_bank(pc, pin, &bank);
440 if (ret)
441 return ret;
442
443 meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit);
444 bit = bit << 1;
445
446 ret = regmap_read(pc->reg_ds, reg, &val);
447 if (ret)
448 return ret;
449
450 switch ((val >> bit) & 0x3) {
451 case MESON_PINCONF_DRV_500UA:
452 *drive_strength_ua = 500;
453 break;
454 case MESON_PINCONF_DRV_2500UA:
455 *drive_strength_ua = 2500;
456 break;
457 case MESON_PINCONF_DRV_3000UA:
458 *drive_strength_ua = 3000;
459 break;
460 case MESON_PINCONF_DRV_4000UA:
461 *drive_strength_ua = 4000;
462 break;
463 default:
464 return -EINVAL;
465 }
466
467 return 0;
468}
469
470static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin,
471 unsigned long *config)
472{
473 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
474 enum pin_config_param param = pinconf_to_config_param(*config);
475 u16 arg;
476 int ret;
477
478 switch (param) {
479 case PIN_CONFIG_BIAS_DISABLE:
480 case PIN_CONFIG_BIAS_PULL_DOWN:
481 case PIN_CONFIG_BIAS_PULL_UP:
482 if (meson_pinconf_get_pull(pc, pin) == param)
483 arg = 1;
484 else
485 return -EINVAL;
486 break;
487 case PIN_CONFIG_DRIVE_STRENGTH_UA:
488 ret = meson_pinconf_get_drive_strength(pc, pin, &arg);
489 if (ret)
490 return ret;
491 break;
492 case PIN_CONFIG_OUTPUT_ENABLE:
493 ret = meson_pinconf_get_output(pc, pin);
494 if (ret <= 0)
495 return -EINVAL;
496 arg = 1;
497 break;
498 case PIN_CONFIG_OUTPUT:
499 ret = meson_pinconf_get_output(pc, pin);
500 if (ret <= 0)
501 return -EINVAL;
502
503 ret = meson_pinconf_get_drive(pc, pin);
504 if (ret < 0)
505 return -EINVAL;
506
507 arg = ret;
508 break;
509
510 default:
511 return -ENOTSUPP;
512 }
513
514 *config = pinconf_to_config_packed(param, arg);
515 dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config);
516
517 return 0;
518}
519
520static int meson_pinconf_group_set(struct pinctrl_dev *pcdev,
521 unsigned int num_group,
522 unsigned long *configs, unsigned num_configs)
523{
524 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
525 struct meson_pmx_group *group = &pc->data->groups[num_group];
526 int i;
527
528 dev_dbg(pc->dev, "set pinconf for group %s\n", group->name);
529
530 for (i = 0; i < group->num_pins; i++) {
531 meson_pinconf_set(pcdev, group->pins[i], configs,
532 num_configs);
533 }
534
535 return 0;
536}
537
538static int meson_pinconf_group_get(struct pinctrl_dev *pcdev,
539 unsigned int group, unsigned long *config)
540{
541 return -ENOTSUPP;
542}
543
544static const struct pinconf_ops meson_pinconf_ops = {
545 .pin_config_get = meson_pinconf_get,
546 .pin_config_set = meson_pinconf_set,
547 .pin_config_group_get = meson_pinconf_group_get,
548 .pin_config_group_set = meson_pinconf_group_set,
549 .is_generic = true,
550};
551
552static int meson_gpio_get_direction(struct gpio_chip *chip, unsigned gpio)
553{
554 struct meson_pinctrl *pc = gpiochip_get_data(chip);
555 int ret;
556
557 ret = meson_pinconf_get_output(pc, gpio);
558 if (ret < 0)
559 return ret;
560
561 return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
562}
563
564static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
565{
566 return meson_pinconf_set_output(gpiochip_get_data(chip), gpio, false);
567}
568
569static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
570 int value)
571{
572 return meson_pinconf_set_output_drive(gpiochip_get_data(chip),
573 gpio, value);
574}
575
576static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
577{
578 meson_pinconf_set_drive(gpiochip_get_data(chip), gpio, value);
579}
580
581static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio)
582{
583 struct meson_pinctrl *pc = gpiochip_get_data(chip);
584 unsigned int reg, bit, val;
585 struct meson_bank *bank;
586 int ret;
587
588 ret = meson_get_bank(pc, gpio, &bank);
589 if (ret)
590 return ret;
591
592 meson_calc_reg_and_bit(bank, gpio, REG_IN, ®, &bit);
593 regmap_read(pc->reg_gpio, reg, &val);
594
595 return !!(val & BIT(bit));
596}
597
598static int meson_gpiolib_register(struct meson_pinctrl *pc)
599{
600 int ret;
601
602 pc->chip.label = pc->data->name;
603 pc->chip.parent = pc->dev;
604 pc->chip.request = gpiochip_generic_request;
605 pc->chip.free = gpiochip_generic_free;
606 pc->chip.set_config = gpiochip_generic_config;
607 pc->chip.get_direction = meson_gpio_get_direction;
608 pc->chip.direction_input = meson_gpio_direction_input;
609 pc->chip.direction_output = meson_gpio_direction_output;
610 pc->chip.get = meson_gpio_get;
611 pc->chip.set = meson_gpio_set;
612 pc->chip.base = -1;
613 pc->chip.ngpio = pc->data->num_pins;
614 pc->chip.can_sleep = false;
615 pc->chip.of_node = pc->of_node;
616 pc->chip.of_gpio_n_cells = 2;
617
618 ret = gpiochip_add_data(&pc->chip, pc);
619 if (ret) {
620 dev_err(pc->dev, "can't add gpio chip %s\n",
621 pc->data->name);
622 return ret;
623 }
624
625 return 0;
626}
627
628static struct regmap_config meson_regmap_config = {
629 .reg_bits = 32,
630 .val_bits = 32,
631 .reg_stride = 4,
632};
633
634static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
635 struct device_node *node, char *name)
636{
637 struct resource res;
638 void __iomem *base;
639 int i;
640
641 i = of_property_match_string(node, "reg-names", name);
642 if (of_address_to_resource(node, i, &res))
643 return NULL;
644
645 base = devm_ioremap_resource(pc->dev, &res);
646 if (IS_ERR(base))
647 return ERR_CAST(base);
648
649 meson_regmap_config.max_register = resource_size(&res) - 4;
650 meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL,
651 "%pOFn-%s", node,
652 name);
653 if (!meson_regmap_config.name)
654 return ERR_PTR(-ENOMEM);
655
656 return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config);
657}
658
659static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
660 struct device_node *node)
661{
662 struct device_node *np, *gpio_np = NULL;
663
664 for_each_child_of_node(node, np) {
665 if (!of_find_property(np, "gpio-controller", NULL))
666 continue;
667 if (gpio_np) {
668 dev_err(pc->dev, "multiple gpio nodes\n");
669 of_node_put(np);
670 return -EINVAL;
671 }
672 gpio_np = np;
673 }
674
675 if (!gpio_np) {
676 dev_err(pc->dev, "no gpio node found\n");
677 return -EINVAL;
678 }
679
680 pc->of_node = gpio_np;
681
682 pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
683 if (IS_ERR_OR_NULL(pc->reg_mux)) {
684 dev_err(pc->dev, "mux registers not found\n");
685 return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT;
686 }
687
688 pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio");
689 if (IS_ERR_OR_NULL(pc->reg_gpio)) {
690 dev_err(pc->dev, "gpio registers not found\n");
691 return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT;
692 }
693
694 pc->reg_pull = meson_map_resource(pc, gpio_np, "pull");
695 if (IS_ERR(pc->reg_pull))
696 pc->reg_pull = NULL;
697
698 pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable");
699 if (IS_ERR(pc->reg_pullen))
700 pc->reg_pullen = NULL;
701
702 pc->reg_ds = meson_map_resource(pc, gpio_np, "ds");
703 if (IS_ERR(pc->reg_ds)) {
704 dev_dbg(pc->dev, "ds registers not found - skipping\n");
705 pc->reg_ds = NULL;
706 }
707
708 if (pc->data->parse_dt)
709 return pc->data->parse_dt(pc);
710
711 return 0;
712}
713
714int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc)
715{
716 if (!pc->reg_pull)
717 return -EINVAL;
718
719 pc->reg_pullen = pc->reg_pull;
720
721 return 0;
722}
723
724int meson_a1_parse_dt_extra(struct meson_pinctrl *pc)
725{
726 pc->reg_pull = pc->reg_gpio;
727 pc->reg_pullen = pc->reg_gpio;
728 pc->reg_ds = pc->reg_gpio;
729
730 return 0;
731}
732
733int meson_pinctrl_probe(struct platform_device *pdev)
734{
735 struct device *dev = &pdev->dev;
736 struct meson_pinctrl *pc;
737 int ret;
738
739 pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL);
740 if (!pc)
741 return -ENOMEM;
742
743 pc->dev = dev;
744 pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev);
745
746 ret = meson_pinctrl_parse_dt(pc, dev->of_node);
747 if (ret)
748 return ret;
749
750 pc->desc.name = "pinctrl-meson";
751 pc->desc.owner = THIS_MODULE;
752 pc->desc.pctlops = &meson_pctrl_ops;
753 pc->desc.pmxops = pc->data->pmx_ops;
754 pc->desc.confops = &meson_pinconf_ops;
755 pc->desc.pins = pc->data->pins;
756 pc->desc.npins = pc->data->num_pins;
757
758 pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc);
759 if (IS_ERR(pc->pcdev)) {
760 dev_err(pc->dev, "can't register pinctrl device");
761 return PTR_ERR(pc->pcdev);
762 }
763
764 return meson_gpiolib_register(pc);
765}