1
2
3
4
5
6
7
8
9
10
11
12#include <linux/err.h>
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_device.h>
18#include <linux/pinctrl/pinconf.h>
19#include <linux/pinctrl/pinconf-generic.h>
20#include <linux/pinctrl/pinctrl.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23
24#include "../core.h"
25#include "../devicetree.h"
26
27#define DRIVER_NAME "ti-iodelay"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54struct ti_iodelay_reg_data {
55 u32 signature_mask;
56 u32 signature_value;
57 u32 lock_mask;
58 u32 lock_val;
59 u32 unlock_val;
60 u32 binary_data_coarse_mask;
61 u32 binary_data_fine_mask;
62
63 u32 reg_refclk_offset;
64 u32 refclk_period_mask;
65
66 u32 reg_coarse_offset;
67 u32 coarse_delay_count_mask;
68 u32 coarse_ref_count_mask;
69
70 u32 reg_fine_offset;
71 u32 fine_delay_count_mask;
72 u32 fine_ref_count_mask;
73
74 u32 reg_global_lock_offset;
75 u32 global_lock_mask;
76 u32 global_unlock_val;
77 u32 global_lock_val;
78
79 u32 reg_start_offset;
80 u32 reg_nr_per_pin;
81
82 struct regmap_config *regmap_config;
83};
84
85
86
87
88
89
90
91
92
93
94
95struct ti_iodelay_reg_values {
96 u16 coarse_ref_count;
97 u16 coarse_delay_count;
98
99 u16 fine_ref_count;
100 u16 fine_delay_count;
101
102 u16 ref_clk_period;
103
104 u32 cdpe;
105 u32 fdpe;
106};
107
108
109
110
111
112
113
114struct ti_iodelay_cfg {
115 u16 offset;
116 u16 a_delay;
117 u16 g_delay;
118};
119
120
121
122
123
124
125
126struct ti_iodelay_pingroup {
127 struct ti_iodelay_cfg *cfg;
128 int ncfg;
129 unsigned long config;
130};
131
132
133
134
135
136
137
138
139
140
141
142
143
144struct ti_iodelay_device {
145 struct device *dev;
146 unsigned long phys_base;
147 void __iomem *reg_base;
148 struct regmap *regmap;
149
150 struct pinctrl_dev *pctl;
151 struct pinctrl_desc desc;
152 struct pinctrl_pin_desc *pa;
153
154 const struct ti_iodelay_reg_data *reg_data;
155 struct ti_iodelay_reg_values reg_init_conf_values;
156};
157
158
159
160
161
162
163
164
165static inline u32 ti_iodelay_extract(u32 val, u32 mask)
166{
167 return (val & mask) >> __ffs(mask);
168}
169
170
171
172
173
174
175
176
177
178
179static inline u32 ti_iodelay_compute_dpe(u16 period, u16 ref, u16 delay,
180 u16 delay_m)
181{
182 u64 m, d;
183
184
185 m = 10 * (u64)period * (u64)ref;
186 d = 2 * (u64)delay * (u64)delay_m;
187
188
189 return div64_u64(m, d);
190}
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206static int ti_iodelay_pinconf_set(struct ti_iodelay_device *iod,
207 struct ti_iodelay_cfg *cfg)
208{
209 const struct ti_iodelay_reg_data *reg = iod->reg_data;
210 struct ti_iodelay_reg_values *ival = &iod->reg_init_conf_values;
211 struct device *dev = iod->dev;
212 u32 g_delay_coarse, g_delay_fine;
213 u32 a_delay_coarse, a_delay_fine;
214 u32 c_elements, f_elements;
215 u32 total_delay;
216 u32 reg_mask, reg_val, tmp_val;
217 int r;
218
219
220 g_delay_coarse = cfg->g_delay / 920;
221 g_delay_fine = ((cfg->g_delay % 920) * 10) / 60;
222
223 a_delay_coarse = cfg->a_delay / ival->cdpe;
224 a_delay_fine = ((cfg->a_delay % ival->cdpe) * 10) / ival->fdpe;
225
226 c_elements = g_delay_coarse + a_delay_coarse;
227 f_elements = (g_delay_fine + a_delay_fine) / 10;
228
229 if (f_elements > 22) {
230 total_delay = c_elements * ival->cdpe + f_elements * ival->fdpe;
231 c_elements = total_delay / ival->cdpe;
232 f_elements = (total_delay % ival->cdpe) / ival->fdpe;
233 }
234
235 reg_mask = reg->signature_mask;
236 reg_val = reg->signature_value << __ffs(reg->signature_mask);
237
238 reg_mask |= reg->binary_data_coarse_mask;
239 tmp_val = c_elements << __ffs(reg->binary_data_coarse_mask);
240 if (tmp_val & ~reg->binary_data_coarse_mask) {
241 dev_err(dev, "Masking overflow of coarse elements %08x\n",
242 tmp_val);
243 tmp_val &= reg->binary_data_coarse_mask;
244 }
245 reg_val |= tmp_val;
246
247 reg_mask |= reg->binary_data_fine_mask;
248 tmp_val = f_elements << __ffs(reg->binary_data_fine_mask);
249 if (tmp_val & ~reg->binary_data_fine_mask) {
250 dev_err(dev, "Masking overflow of fine elements %08x\n",
251 tmp_val);
252 tmp_val &= reg->binary_data_fine_mask;
253 }
254 reg_val |= tmp_val;
255
256
257
258
259
260
261
262 reg_mask |= reg->lock_mask;
263 reg_val |= reg->unlock_val << __ffs(reg->lock_mask);
264 r = regmap_update_bits(iod->regmap, cfg->offset, reg_mask, reg_val);
265
266 dev_dbg(dev, "Set reg 0x%x Delay(a: %d g: %d), Elements(C=%d F=%d)0x%x\n",
267 cfg->offset, cfg->a_delay, cfg->g_delay, c_elements,
268 f_elements, reg_val);
269
270 return r;
271}
272
273
274
275
276
277
278
279
280
281static int ti_iodelay_pinconf_init_dev(struct ti_iodelay_device *iod)
282{
283 const struct ti_iodelay_reg_data *reg = iod->reg_data;
284 struct device *dev = iod->dev;
285 struct ti_iodelay_reg_values *ival = &iod->reg_init_conf_values;
286 u32 val;
287 int r;
288
289
290 r = regmap_update_bits(iod->regmap, reg->reg_global_lock_offset,
291 reg->global_lock_mask, reg->global_unlock_val);
292 if (r)
293 return r;
294
295
296 r = regmap_read(iod->regmap, reg->reg_refclk_offset, &val);
297 if (r)
298 return r;
299 ival->ref_clk_period = ti_iodelay_extract(val, reg->refclk_period_mask);
300 dev_dbg(dev, "refclk_period=0x%04x\n", ival->ref_clk_period);
301
302 r = regmap_read(iod->regmap, reg->reg_coarse_offset, &val);
303 if (r)
304 return r;
305 ival->coarse_ref_count =
306 ti_iodelay_extract(val, reg->coarse_ref_count_mask);
307 ival->coarse_delay_count =
308 ti_iodelay_extract(val, reg->coarse_delay_count_mask);
309 if (!ival->coarse_delay_count) {
310 dev_err(dev, "Invalid Coarse delay count (0) (reg=0x%08x)\n",
311 val);
312 return -EINVAL;
313 }
314 ival->cdpe = ti_iodelay_compute_dpe(ival->ref_clk_period,
315 ival->coarse_ref_count,
316 ival->coarse_delay_count, 88);
317 if (!ival->cdpe) {
318 dev_err(dev, "Invalid cdpe computed params = %d %d %d\n",
319 ival->ref_clk_period, ival->coarse_ref_count,
320 ival->coarse_delay_count);
321 return -EINVAL;
322 }
323 dev_dbg(iod->dev, "coarse: ref=0x%04x delay=0x%04x cdpe=0x%08x\n",
324 ival->coarse_ref_count, ival->coarse_delay_count, ival->cdpe);
325
326 r = regmap_read(iod->regmap, reg->reg_fine_offset, &val);
327 if (r)
328 return r;
329 ival->fine_ref_count =
330 ti_iodelay_extract(val, reg->fine_ref_count_mask);
331 ival->fine_delay_count =
332 ti_iodelay_extract(val, reg->fine_delay_count_mask);
333 if (!ival->fine_delay_count) {
334 dev_err(dev, "Invalid Fine delay count (0) (reg=0x%08x)\n",
335 val);
336 return -EINVAL;
337 }
338 ival->fdpe = ti_iodelay_compute_dpe(ival->ref_clk_period,
339 ival->fine_ref_count,
340 ival->fine_delay_count, 264);
341 if (!ival->fdpe) {
342 dev_err(dev, "Invalid fdpe(0) computed params = %d %d %d\n",
343 ival->ref_clk_period, ival->fine_ref_count,
344 ival->fine_delay_count);
345 return -EINVAL;
346 }
347 dev_dbg(iod->dev, "fine: ref=0x%04x delay=0x%04x fdpe=0x%08x\n",
348 ival->fine_ref_count, ival->fine_delay_count, ival->fdpe);
349
350 return 0;
351}
352
353
354
355
356
357
358
359static void ti_iodelay_pinconf_deinit_dev(struct ti_iodelay_device *iod)
360{
361 const struct ti_iodelay_reg_data *reg = iod->reg_data;
362
363
364 regmap_update_bits(iod->regmap, reg->reg_global_lock_offset,
365 reg->global_lock_mask, reg->global_lock_val);
366}
367
368
369
370
371
372
373
374
375static struct ti_iodelay_pingroup *
376ti_iodelay_get_pingroup(struct ti_iodelay_device *iod, unsigned int selector)
377{
378 struct group_desc *g;
379
380 g = pinctrl_generic_get_group(iod->pctl, selector);
381 if (!g) {
382 dev_err(iod->dev, "%s could not find pingroup %i\n", __func__,
383 selector);
384
385 return NULL;
386 }
387
388 return g->data;
389}
390
391
392
393
394
395
396static int ti_iodelay_offset_to_pin(struct ti_iodelay_device *iod,
397 unsigned int offset)
398{
399 const struct ti_iodelay_reg_data *r = iod->reg_data;
400 unsigned int index;
401
402 if (offset > r->regmap_config->max_register) {
403 dev_err(iod->dev, "mux offset out of range: 0x%x (0x%x)\n",
404 offset, r->regmap_config->max_register);
405 return -EINVAL;
406 }
407
408 index = (offset - r->reg_start_offset) / r->regmap_config->reg_stride;
409 index /= r->reg_nr_per_pin;
410
411 return index;
412}
413
414
415
416
417
418
419
420
421
422
423
424static int ti_iodelay_node_iterator(struct pinctrl_dev *pctldev,
425 struct device_node *np,
426 const struct of_phandle_args *pinctrl_spec,
427 int *pins, int pin_index, void *data)
428{
429 struct ti_iodelay_device *iod;
430 struct ti_iodelay_cfg *cfg = data;
431 const struct ti_iodelay_reg_data *r;
432 struct pinctrl_pin_desc *pd;
433 int pin;
434
435 iod = pinctrl_dev_get_drvdata(pctldev);
436 if (!iod)
437 return -EINVAL;
438
439 r = iod->reg_data;
440
441 if (pinctrl_spec->args_count < r->reg_nr_per_pin) {
442 dev_err(iod->dev, "invalid args_count for spec: %i\n",
443 pinctrl_spec->args_count);
444
445 return -EINVAL;
446 }
447
448
449 cfg[pin_index].offset = pinctrl_spec->args[0];
450 cfg[pin_index].a_delay = pinctrl_spec->args[1] & 0xffff;
451 cfg[pin_index].g_delay = pinctrl_spec->args[2] & 0xffff;
452
453 pin = ti_iodelay_offset_to_pin(iod, cfg[pin_index].offset);
454 if (pin < 0) {
455 dev_err(iod->dev, "could not add functions for %pOFn %ux\n",
456 np, cfg[pin_index].offset);
457 return -ENODEV;
458 }
459 pins[pin_index] = pin;
460
461 pd = &iod->pa[pin];
462 pd->drv_data = &cfg[pin_index];
463
464 dev_dbg(iod->dev, "%pOFn offset=%x a_delay = %d g_delay = %d\n",
465 np, cfg[pin_index].offset, cfg[pin_index].a_delay,
466 cfg[pin_index].g_delay);
467
468 return 0;
469}
470
471
472
473
474
475
476
477
478
479
480
481
482
483static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
484 struct device_node *np,
485 struct pinctrl_map **map,
486 unsigned int *num_maps)
487{
488 struct ti_iodelay_device *iod;
489 struct ti_iodelay_cfg *cfg;
490 struct ti_iodelay_pingroup *g;
491 const char *name = "pinctrl-pin-array";
492 int rows, *pins, error = -EINVAL, i;
493
494 iod = pinctrl_dev_get_drvdata(pctldev);
495 if (!iod)
496 return -EINVAL;
497
498 rows = pinctrl_count_index_with_args(np, name);
499 if (rows < 0)
500 return rows;
501
502 *map = devm_kzalloc(iod->dev, sizeof(**map), GFP_KERNEL);
503 if (!*map)
504 return -ENOMEM;
505 *num_maps = 0;
506
507 g = devm_kzalloc(iod->dev, sizeof(*g), GFP_KERNEL);
508 if (!g) {
509 error = -ENOMEM;
510 goto free_map;
511 }
512
513 pins = devm_kcalloc(iod->dev, rows, sizeof(*pins), GFP_KERNEL);
514 if (!pins) {
515 error = -ENOMEM;
516 goto free_group;
517 }
518
519 cfg = devm_kcalloc(iod->dev, rows, sizeof(*cfg), GFP_KERNEL);
520 if (!cfg) {
521 error = -ENOMEM;
522 goto free_pins;
523 }
524
525 for (i = 0; i < rows; i++) {
526 struct of_phandle_args pinctrl_spec;
527
528 error = pinctrl_parse_index_with_args(np, name, i,
529 &pinctrl_spec);
530 if (error)
531 goto free_data;
532
533 error = ti_iodelay_node_iterator(pctldev, np, &pinctrl_spec,
534 pins, i, cfg);
535 if (error)
536 goto free_data;
537 }
538
539 g->cfg = cfg;
540 g->ncfg = i;
541 g->config = PIN_CONFIG_END;
542
543 error = pinctrl_generic_add_group(iod->pctl, np->name, pins, i, g);
544 if (error < 0)
545 goto free_data;
546
547 (*map)->type = PIN_MAP_TYPE_CONFIGS_GROUP;
548 (*map)->data.configs.group_or_pin = np->name;
549 (*map)->data.configs.configs = &g->config;
550 (*map)->data.configs.num_configs = 1;
551 *num_maps = 1;
552
553 return 0;
554
555free_data:
556 devm_kfree(iod->dev, cfg);
557free_pins:
558 devm_kfree(iod->dev, pins);
559free_group:
560 devm_kfree(iod->dev, g);
561free_map:
562 devm_kfree(iod->dev, *map);
563
564 return error;
565}
566
567
568
569
570
571
572
573
574
575static int ti_iodelay_pinconf_group_get(struct pinctrl_dev *pctldev,
576 unsigned int selector,
577 unsigned long *config)
578{
579 struct ti_iodelay_device *iod;
580 struct ti_iodelay_pingroup *group;
581
582 iod = pinctrl_dev_get_drvdata(pctldev);
583 group = ti_iodelay_get_pingroup(iod, selector);
584
585 if (!group)
586 return -EINVAL;
587
588 *config = group->config;
589 return 0;
590}
591
592
593
594
595
596
597
598
599
600
601static int ti_iodelay_pinconf_group_set(struct pinctrl_dev *pctldev,
602 unsigned int selector,
603 unsigned long *configs,
604 unsigned int num_configs)
605{
606 struct ti_iodelay_device *iod;
607 struct device *dev;
608 struct ti_iodelay_pingroup *group;
609 int i;
610
611 iod = pinctrl_dev_get_drvdata(pctldev);
612 dev = iod->dev;
613 group = ti_iodelay_get_pingroup(iod, selector);
614
615 if (num_configs != 1) {
616 dev_err(dev, "Unsupported number of configurations %d\n",
617 num_configs);
618 return -EINVAL;
619 }
620
621 if (*configs != PIN_CONFIG_END) {
622 dev_err(dev, "Unsupported configuration\n");
623 return -EINVAL;
624 }
625
626 for (i = 0; i < group->ncfg; i++) {
627 if (ti_iodelay_pinconf_set(iod, &group->cfg[i]))
628 return -ENOTSUPP;
629 }
630
631 return 0;
632}
633
634#ifdef CONFIG_DEBUG_FS
635
636
637
638
639
640static unsigned int ti_iodelay_pin_to_offset(struct ti_iodelay_device *iod,
641 unsigned int selector)
642{
643 const struct ti_iodelay_reg_data *r = iod->reg_data;
644 unsigned int offset;
645
646 offset = selector * r->regmap_config->reg_stride;
647 offset *= r->reg_nr_per_pin;
648 offset += r->reg_start_offset;
649
650 return offset;
651}
652
653static void ti_iodelay_pin_dbg_show(struct pinctrl_dev *pctldev,
654 struct seq_file *s,
655 unsigned int pin)
656{
657 struct ti_iodelay_device *iod;
658 struct pinctrl_pin_desc *pd;
659 struct ti_iodelay_cfg *cfg;
660 const struct ti_iodelay_reg_data *r;
661 unsigned long offset;
662 u32 in, oen, out;
663
664 iod = pinctrl_dev_get_drvdata(pctldev);
665 r = iod->reg_data;
666
667 offset = ti_iodelay_pin_to_offset(iod, pin);
668 pd = &iod->pa[pin];
669 cfg = pd->drv_data;
670
671 regmap_read(iod->regmap, offset, &in);
672 regmap_read(iod->regmap, offset + r->regmap_config->reg_stride, &oen);
673 regmap_read(iod->regmap, offset + r->regmap_config->reg_stride * 2,
674 &out);
675
676 seq_printf(s, "%lx a: %i g: %i (%08x %08x %08x) %s ",
677 iod->phys_base + offset,
678 cfg ? cfg->a_delay : -1,
679 cfg ? cfg->g_delay : -1,
680 in, oen, out, DRIVER_NAME);
681}
682
683
684
685
686
687
688
689
690
691static void ti_iodelay_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
692 struct seq_file *s,
693 unsigned int selector)
694{
695 struct ti_iodelay_device *iod;
696 struct ti_iodelay_pingroup *group;
697 int i;
698
699 iod = pinctrl_dev_get_drvdata(pctldev);
700 group = ti_iodelay_get_pingroup(iod, selector);
701 if (!group)
702 return;
703
704 for (i = 0; i < group->ncfg; i++) {
705 struct ti_iodelay_cfg *cfg;
706 u32 reg = 0;
707
708 cfg = &group->cfg[i];
709 regmap_read(iod->regmap, cfg->offset, ®);
710 seq_printf(s, "\n\t0x%08x = 0x%08x (%3d, %3d)",
711 cfg->offset, reg, cfg->a_delay, cfg->g_delay);
712 }
713}
714#endif
715
716static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
717 .get_groups_count = pinctrl_generic_get_group_count,
718 .get_group_name = pinctrl_generic_get_group_name,
719 .get_group_pins = pinctrl_generic_get_group_pins,
720#ifdef CONFIG_DEBUG_FS
721 .pin_dbg_show = ti_iodelay_pin_dbg_show,
722#endif
723 .dt_node_to_map = ti_iodelay_dt_node_to_map,
724};
725
726static const struct pinconf_ops ti_iodelay_pinctrl_pinconf_ops = {
727 .pin_config_group_get = ti_iodelay_pinconf_group_get,
728 .pin_config_group_set = ti_iodelay_pinconf_group_set,
729#ifdef CONFIG_DEBUG_FS
730 .pin_config_group_dbg_show = ti_iodelay_pinconf_group_dbg_show,
731#endif
732};
733
734
735
736
737
738
739
740
741
742static int ti_iodelay_alloc_pins(struct device *dev,
743 struct ti_iodelay_device *iod, u32 base_phy)
744{
745 const struct ti_iodelay_reg_data *r = iod->reg_data;
746 struct pinctrl_pin_desc *pin;
747 u32 phy_reg;
748 int nr_pins, i;
749
750 nr_pins = ti_iodelay_offset_to_pin(iod, r->regmap_config->max_register);
751 dev_dbg(dev, "Allocating %i pins\n", nr_pins);
752
753 iod->pa = devm_kcalloc(dev, nr_pins, sizeof(*iod->pa), GFP_KERNEL);
754 if (!iod->pa)
755 return -ENOMEM;
756
757 iod->desc.pins = iod->pa;
758 iod->desc.npins = nr_pins;
759
760 phy_reg = r->reg_start_offset + base_phy;
761
762 for (i = 0; i < nr_pins; i++, phy_reg += 4) {
763 pin = &iod->pa[i];
764 pin->number = i;
765 }
766
767 return 0;
768}
769
770static struct regmap_config dra7_iodelay_regmap_config = {
771 .reg_bits = 32,
772 .reg_stride = 4,
773 .val_bits = 32,
774 .max_register = 0xd1c,
775};
776
777static struct ti_iodelay_reg_data dra7_iodelay_data = {
778 .signature_mask = 0x0003f000,
779 .signature_value = 0x29,
780 .lock_mask = 0x00000400,
781 .lock_val = 1,
782 .unlock_val = 0,
783 .binary_data_coarse_mask = 0x000003e0,
784 .binary_data_fine_mask = 0x0000001f,
785
786 .reg_refclk_offset = 0x14,
787 .refclk_period_mask = 0xffff,
788
789 .reg_coarse_offset = 0x18,
790 .coarse_delay_count_mask = 0xffff0000,
791 .coarse_ref_count_mask = 0x0000ffff,
792
793 .reg_fine_offset = 0x1C,
794 .fine_delay_count_mask = 0xffff0000,
795 .fine_ref_count_mask = 0x0000ffff,
796
797 .reg_global_lock_offset = 0x2c,
798 .global_lock_mask = 0x0000ffff,
799 .global_unlock_val = 0x0000aaaa,
800 .global_lock_val = 0x0000aaab,
801
802 .reg_start_offset = 0x30,
803 .reg_nr_per_pin = 3,
804 .regmap_config = &dra7_iodelay_regmap_config,
805};
806
807static const struct of_device_id ti_iodelay_of_match[] = {
808 {.compatible = "ti,dra7-iodelay", .data = &dra7_iodelay_data},
809 { },
810};
811MODULE_DEVICE_TABLE(of, ti_iodelay_of_match);
812
813
814
815
816
817
818
819static int ti_iodelay_probe(struct platform_device *pdev)
820{
821 struct device *dev = &pdev->dev;
822 struct device_node *np = of_node_get(dev->of_node);
823 const struct of_device_id *match;
824 struct resource *res;
825 struct ti_iodelay_device *iod;
826 int ret = 0;
827
828 if (!np) {
829 ret = -EINVAL;
830 dev_err(dev, "No OF node\n");
831 goto exit_out;
832 }
833
834 match = of_match_device(ti_iodelay_of_match, dev);
835 if (!match) {
836 ret = -EINVAL;
837 dev_err(dev, "No DATA match\n");
838 goto exit_out;
839 }
840
841 iod = devm_kzalloc(dev, sizeof(*iod), GFP_KERNEL);
842 if (!iod) {
843 ret = -ENOMEM;
844 goto exit_out;
845 }
846 iod->dev = dev;
847 iod->reg_data = match->data;
848
849
850 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
851 if (!res) {
852 dev_err(dev, "Missing MEM resource\n");
853 ret = -ENODEV;
854 goto exit_out;
855 }
856
857 iod->phys_base = res->start;
858 iod->reg_base = devm_ioremap_resource(dev, res);
859 if (IS_ERR(iod->reg_base)) {
860 ret = PTR_ERR(iod->reg_base);
861 goto exit_out;
862 }
863
864 iod->regmap = devm_regmap_init_mmio(dev, iod->reg_base,
865 iod->reg_data->regmap_config);
866 if (IS_ERR(iod->regmap)) {
867 dev_err(dev, "Regmap MMIO init failed.\n");
868 ret = PTR_ERR(iod->regmap);
869 goto exit_out;
870 }
871
872 ret = ti_iodelay_pinconf_init_dev(iod);
873 if (ret)
874 goto exit_out;
875
876 ret = ti_iodelay_alloc_pins(dev, iod, res->start);
877 if (ret)
878 goto exit_out;
879
880 iod->desc.pctlops = &ti_iodelay_pinctrl_ops;
881
882 iod->desc.confops = &ti_iodelay_pinctrl_pinconf_ops;
883 iod->desc.name = dev_name(dev);
884 iod->desc.owner = THIS_MODULE;
885
886 ret = pinctrl_register_and_init(&iod->desc, dev, iod, &iod->pctl);
887 if (ret) {
888 dev_err(dev, "Failed to register pinctrl\n");
889 goto exit_out;
890 }
891
892 platform_set_drvdata(pdev, iod);
893
894 return pinctrl_enable(iod->pctl);
895
896exit_out:
897 of_node_put(np);
898 return ret;
899}
900
901
902
903
904
905
906
907static int ti_iodelay_remove(struct platform_device *pdev)
908{
909 struct ti_iodelay_device *iod = platform_get_drvdata(pdev);
910
911 if (!iod)
912 return 0;
913
914 if (iod->pctl)
915 pinctrl_unregister(iod->pctl);
916
917 ti_iodelay_pinconf_deinit_dev(iod);
918
919
920
921 return 0;
922}
923
924static struct platform_driver ti_iodelay_driver = {
925 .probe = ti_iodelay_probe,
926 .remove = ti_iodelay_remove,
927 .driver = {
928 .name = DRIVER_NAME,
929 .of_match_table = ti_iodelay_of_match,
930 },
931};
932module_platform_driver(ti_iodelay_driver);
933
934MODULE_AUTHOR("Texas Instruments, Inc.");
935MODULE_DESCRIPTION("Pinconf driver for TI's IO Delay module");
936MODULE_LICENSE("GPL v2");
937