2 * Support for configuration of IO Delay module found on Texas Instruments SoCs
5 * Copyright (C) 2015-2017 Texas Instruments Incorporated - https://www.ti.com/
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/err.h>
13 #include <linux/init.h>
15 #include <linux/module.h>
17 #include <linux/of_device.h>
18 #include <linux/regmap.h>
19 #include <linux/seq_file.h>
20 #include <linux/slab.h>
22 #include <linux/pinctrl/pinconf-generic.h>
23 #include <linux/pinctrl/pinconf.h>
24 #include <linux/pinctrl/pinctrl.h>
27 #include "../devicetree.h"
29 #define DRIVER_NAME "ti-iodelay"
32 * struct ti_iodelay_reg_data - Describes the registers for the iodelay instance
33 * @signature_mask: CONFIG_REG mask for the signature bits (see TRM)
34 * @signature_value: CONFIG_REG signature value to be written (see TRM)
35 * @lock_mask: CONFIG_REG mask for the lock bits (see TRM)
36 * @lock_val: CONFIG_REG lock value for the lock bits (see TRM)
37 * @unlock_val:CONFIG_REG unlock value for the lock bits (see TRM)
38 * @binary_data_coarse_mask: CONFIG_REG coarse mask (see TRM)
39 * @binary_data_fine_mask: CONFIG_REG fine mask (see TRM)
40 * @reg_refclk_offset: Refclk register offset
41 * @refclk_period_mask: Refclk mask
42 * @reg_coarse_offset: Coarse register configuration offset
43 * @coarse_delay_count_mask: Coarse delay count mask
44 * @coarse_ref_count_mask: Coarse ref count mask
45 * @reg_fine_offset: Fine register configuration offset
46 * @fine_delay_count_mask: Fine delay count mask
47 * @fine_ref_count_mask: Fine ref count mask
48 * @reg_global_lock_offset: Global iodelay module lock register offset
49 * @global_lock_mask: Lock mask
50 * @global_unlock_val: Unlock value
51 * @global_lock_val: Lock value
52 * @reg_start_offset: Offset to iodelay registers after the CONFIG_REG_0 to 8
53 * @reg_nr_per_pin: Number of iodelay registers for each pin
54 * @regmap_config: Regmap configuration for the IODelay region
56 struct ti_iodelay_reg_data {
62 u32 binary_data_coarse_mask;
63 u32 binary_data_fine_mask;
65 u32 reg_refclk_offset;
66 u32 refclk_period_mask;
68 u32 reg_coarse_offset;
69 u32 coarse_delay_count_mask;
70 u32 coarse_ref_count_mask;
73 u32 fine_delay_count_mask;
74 u32 fine_ref_count_mask;
76 u32 reg_global_lock_offset;
78 u32 global_unlock_val;
84 struct regmap_config *regmap_config;
88 * struct ti_iodelay_reg_values - Computed io_reg configuration values (see TRM)
89 * @coarse_ref_count: Coarse reference count
90 * @coarse_delay_count: Coarse delay count
91 * @fine_ref_count: Fine reference count
92 * @fine_delay_count: Fine Delay count
93 * @ref_clk_period: Reference Clock period
94 * @cdpe: Coarse delay parameter
95 * @fdpe: Fine delay parameter
97 struct ti_iodelay_reg_values {
99 u16 coarse_delay_count;
102 u16 fine_delay_count;
111 * struct ti_iodelay_cfg - Description of each configuration parameters
112 * @offset: Configuration register offset
113 * @a_delay: Agnostic Delay (in ps)
114 * @g_delay: Gnostic Delay (in ps)
116 struct ti_iodelay_cfg {
123 * struct ti_iodelay_pingroup - Structure that describes one group
124 * @cfg: configuration array for the pin (from dt)
125 * @ncfg: number of configuration values allocated
126 * @config: pinconf "Config" - currently a dummy value
128 struct ti_iodelay_pingroup {
129 struct ti_iodelay_cfg *cfg;
131 unsigned long config;
135 * struct ti_iodelay_device - Represents information for a iodelay instance
136 * @dev: Device pointer
137 * @phys_base: Physical address base of the iodelay device
138 * @reg_base: Virtual address base of the iodelay device
139 * @regmap: Regmap for this iodelay instance
140 * @pctl: Pinctrl device
141 * @desc: pinctrl descriptor for pctl
142 * @pa: pinctrl pin wise description
143 * @reg_data: Register definition data for the IODelay instance
144 * @reg_init_conf_values: Initial configuration values.
146 struct ti_iodelay_device {
148 unsigned long phys_base;
149 void __iomem *reg_base;
150 struct regmap *regmap;
152 struct pinctrl_dev *pctl;
153 struct pinctrl_desc desc;
154 struct pinctrl_pin_desc *pa;
156 const struct ti_iodelay_reg_data *reg_data;
157 struct ti_iodelay_reg_values reg_init_conf_values;
161 * ti_iodelay_extract() - extract bits for a field
162 * @val: Register value
165 * Return: extracted value which is appropriately shifted
167 static inline u32 ti_iodelay_extract(u32 val, u32 mask)
169 return (val & mask) >> __ffs(mask);
173 * ti_iodelay_compute_dpe() - Compute equation for delay parameter
174 * @period: Period to use
175 * @ref: Reference Count
176 * @delay: Delay count
177 * @delay_m: Delay multiplier
179 * Return: Computed delay parameter
181 static inline u32 ti_iodelay_compute_dpe(u16 period, u16 ref, u16 delay,
186 /* Handle overflow conditions */
187 m = 10 * (u64)period * (u64)ref;
188 d = 2 * (u64)delay * (u64)delay_m;
190 /* Truncate result back to 32 bits */
191 return div64_u64(m, d);
195 * ti_iodelay_pinconf_set() - Configure the pin configuration
196 * @iod: iodelay device
197 * @cfg: Configuration
199 * Update the configuration register as per TRM and lockup once done.
200 * *IMPORTANT NOTE* SoC TRM does recommend doing iodelay programmation only
201 * while in Isolation. But, then, isolation also implies that every pin
202 * on the SoC (including DDR) will be isolated out. The only benefit being
203 * a glitchless configuration, However, the intent of this driver is purely
204 * to support a "glitchy" configuration where applicable.
206 * Return: 0 in case of success, else appropriate error value
208 static int ti_iodelay_pinconf_set(struct ti_iodelay_device *iod,
209 struct ti_iodelay_cfg *cfg)
211 const struct ti_iodelay_reg_data *reg = iod->reg_data;
212 struct ti_iodelay_reg_values *ival = &iod->reg_init_conf_values;
213 struct device *dev = iod->dev;
214 u32 g_delay_coarse, g_delay_fine;
215 u32 a_delay_coarse, a_delay_fine;
216 u32 c_elements, f_elements;
218 u32 reg_mask, reg_val, tmp_val;
221 /* NOTE: Truncation is expected in all division below */
222 g_delay_coarse = cfg->g_delay / 920;
223 g_delay_fine = ((cfg->g_delay % 920) * 10) / 60;
225 a_delay_coarse = cfg->a_delay / ival->cdpe;
226 a_delay_fine = ((cfg->a_delay % ival->cdpe) * 10) / ival->fdpe;
228 c_elements = g_delay_coarse + a_delay_coarse;
229 f_elements = (g_delay_fine + a_delay_fine) / 10;
231 if (f_elements > 22) {
232 total_delay = c_elements * ival->cdpe + f_elements * ival->fdpe;
233 c_elements = total_delay / ival->cdpe;
234 f_elements = (total_delay % ival->cdpe) / ival->fdpe;
237 reg_mask = reg->signature_mask;
238 reg_val = reg->signature_value << __ffs(reg->signature_mask);
240 reg_mask |= reg->binary_data_coarse_mask;
241 tmp_val = c_elements << __ffs(reg->binary_data_coarse_mask);
242 if (tmp_val & ~reg->binary_data_coarse_mask) {
243 dev_err(dev, "Masking overflow of coarse elements %08x\n",
245 tmp_val &= reg->binary_data_coarse_mask;
249 reg_mask |= reg->binary_data_fine_mask;
250 tmp_val = f_elements << __ffs(reg->binary_data_fine_mask);
251 if (tmp_val & ~reg->binary_data_fine_mask) {
252 dev_err(dev, "Masking overflow of fine elements %08x\n",
254 tmp_val &= reg->binary_data_fine_mask;
259 * NOTE: we leave the iodelay values unlocked - this is to work around
260 * situations such as those found with mmc mode change.
261 * However, this leaves open any unwarranted changes to padconf register
262 * impacting iodelay configuration. Use with care!
264 reg_mask |= reg->lock_mask;
265 reg_val |= reg->unlock_val << __ffs(reg->lock_mask);
266 r = regmap_update_bits(iod->regmap, cfg->offset, reg_mask, reg_val);
268 dev_dbg(dev, "Set reg 0x%x Delay(a: %d g: %d), Elements(C=%d F=%d)0x%x\n",
269 cfg->offset, cfg->a_delay, cfg->g_delay, c_elements,
270 f_elements, reg_val);
276 * ti_iodelay_pinconf_init_dev() - Initialize IODelay device
277 * @iod: iodelay device
279 * Unlocks the iodelay region, computes the common parameters
281 * Return: 0 in case of success, else appropriate error value
283 static int ti_iodelay_pinconf_init_dev(struct ti_iodelay_device *iod)
285 const struct ti_iodelay_reg_data *reg = iod->reg_data;
286 struct device *dev = iod->dev;
287 struct ti_iodelay_reg_values *ival = &iod->reg_init_conf_values;
291 /* unlock the iodelay region */
292 r = regmap_update_bits(iod->regmap, reg->reg_global_lock_offset,
293 reg->global_lock_mask, reg->global_unlock_val);
297 /* Read up Recalibration sequence done by bootloader */
298 r = regmap_read(iod->regmap, reg->reg_refclk_offset, &val);
301 ival->ref_clk_period = ti_iodelay_extract(val, reg->refclk_period_mask);
302 dev_dbg(dev, "refclk_period=0x%04x\n", ival->ref_clk_period);
304 r = regmap_read(iod->regmap, reg->reg_coarse_offset, &val);
307 ival->coarse_ref_count =
308 ti_iodelay_extract(val, reg->coarse_ref_count_mask);
309 ival->coarse_delay_count =
310 ti_iodelay_extract(val, reg->coarse_delay_count_mask);
311 if (!ival->coarse_delay_count) {
312 dev_err(dev, "Invalid Coarse delay count (0) (reg=0x%08x)\n",
316 ival->cdpe = ti_iodelay_compute_dpe(ival->ref_clk_period,
317 ival->coarse_ref_count,
318 ival->coarse_delay_count, 88);
320 dev_err(dev, "Invalid cdpe computed params = %d %d %d\n",
321 ival->ref_clk_period, ival->coarse_ref_count,
322 ival->coarse_delay_count);
325 dev_dbg(iod->dev, "coarse: ref=0x%04x delay=0x%04x cdpe=0x%08x\n",
326 ival->coarse_ref_count, ival->coarse_delay_count, ival->cdpe);
328 r = regmap_read(iod->regmap, reg->reg_fine_offset, &val);
331 ival->fine_ref_count =
332 ti_iodelay_extract(val, reg->fine_ref_count_mask);
333 ival->fine_delay_count =
334 ti_iodelay_extract(val, reg->fine_delay_count_mask);
335 if (!ival->fine_delay_count) {
336 dev_err(dev, "Invalid Fine delay count (0) (reg=0x%08x)\n",
340 ival->fdpe = ti_iodelay_compute_dpe(ival->ref_clk_period,
341 ival->fine_ref_count,
342 ival->fine_delay_count, 264);
344 dev_err(dev, "Invalid fdpe(0) computed params = %d %d %d\n",
345 ival->ref_clk_period, ival->fine_ref_count,
346 ival->fine_delay_count);
349 dev_dbg(iod->dev, "fine: ref=0x%04x delay=0x%04x fdpe=0x%08x\n",
350 ival->fine_ref_count, ival->fine_delay_count, ival->fdpe);
356 * ti_iodelay_pinconf_deinit_dev() - deinit the iodelay device
357 * @iod: IODelay device
359 * Deinitialize the IODelay device (basically just lock the region back up.
361 static void ti_iodelay_pinconf_deinit_dev(struct ti_iodelay_device *iod)
363 const struct ti_iodelay_reg_data *reg = iod->reg_data;
365 /* lock the iodelay region back again */
366 regmap_update_bits(iod->regmap, reg->reg_global_lock_offset,
367 reg->global_lock_mask, reg->global_lock_val);
371 * ti_iodelay_get_pingroup() - Find the group mapped by a group selector
372 * @iod: iodelay device
373 * @selector: Group Selector
375 * Return: Corresponding group representing group selector
377 static struct ti_iodelay_pingroup *
378 ti_iodelay_get_pingroup(struct ti_iodelay_device *iod, unsigned int selector)
380 struct group_desc *g;
382 g = pinctrl_generic_get_group(iod->pctl, selector);
384 dev_err(iod->dev, "%s could not find pingroup %i\n", __func__,
394 * ti_iodelay_offset_to_pin() - get a pin index based on the register offset
395 * @iod: iodelay driver instance
396 * @offset: register offset from the base
398 static int ti_iodelay_offset_to_pin(struct ti_iodelay_device *iod,
401 const struct ti_iodelay_reg_data *r = iod->reg_data;
404 if (offset > r->regmap_config->max_register) {
405 dev_err(iod->dev, "mux offset out of range: 0x%x (0x%x)\n",
406 offset, r->regmap_config->max_register);
410 index = (offset - r->reg_start_offset) / r->regmap_config->reg_stride;
411 index /= r->reg_nr_per_pin;
417 * ti_iodelay_node_iterator() - Iterate iodelay node
418 * @pctldev: Pin controller driver
420 * @pinctrl_spec: Parsed arguments from device tree
421 * @pins: Array of pins in the pin group
422 * @pin_index: Pin index in the pin array
423 * @data: Pin controller driver specific data
426 static int ti_iodelay_node_iterator(struct pinctrl_dev *pctldev,
427 struct device_node *np,
428 const struct of_phandle_args *pinctrl_spec,
429 int *pins, int pin_index, void *data)
431 struct ti_iodelay_device *iod;
432 struct ti_iodelay_cfg *cfg = data;
433 const struct ti_iodelay_reg_data *r;
434 struct pinctrl_pin_desc *pd;
437 iod = pinctrl_dev_get_drvdata(pctldev);
443 if (pinctrl_spec->args_count < r->reg_nr_per_pin) {
444 dev_err(iod->dev, "invalid args_count for spec: %i\n",
445 pinctrl_spec->args_count);
450 /* Index plus two value cells */
451 cfg[pin_index].offset = pinctrl_spec->args[0];
452 cfg[pin_index].a_delay = pinctrl_spec->args[1] & 0xffff;
453 cfg[pin_index].g_delay = pinctrl_spec->args[2] & 0xffff;
455 pin = ti_iodelay_offset_to_pin(iod, cfg[pin_index].offset);
457 dev_err(iod->dev, "could not add functions for %pOFn %ux\n",
458 np, cfg[pin_index].offset);
461 pins[pin_index] = pin;
464 pd->drv_data = &cfg[pin_index];
466 dev_dbg(iod->dev, "%pOFn offset=%x a_delay = %d g_delay = %d\n",
467 np, cfg[pin_index].offset, cfg[pin_index].a_delay,
468 cfg[pin_index].g_delay);
474 * ti_iodelay_dt_node_to_map() - Map a device tree node to appropriate group
475 * @pctldev: pinctrl device representing IODelay device
476 * @np: Node Pointer (device tree)
477 * @map: Pinctrl Map returned back to pinctrl framework
478 * @num_maps: Number of maps (1)
480 * Maps the device tree description into a group of configuration parameters
481 * for iodelay block entry.
483 * Return: 0 in case of success, else appropriate error value
485 static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
486 struct device_node *np,
487 struct pinctrl_map **map,
488 unsigned int *num_maps)
490 struct ti_iodelay_device *iod;
491 struct ti_iodelay_cfg *cfg;
492 struct ti_iodelay_pingroup *g;
493 const char *name = "pinctrl-pin-array";
494 int rows, *pins, error = -EINVAL, i;
496 iod = pinctrl_dev_get_drvdata(pctldev);
500 rows = pinctrl_count_index_with_args(np, name);
504 *map = devm_kzalloc(iod->dev, sizeof(**map), GFP_KERNEL);
509 g = devm_kzalloc(iod->dev, sizeof(*g), GFP_KERNEL);
515 pins = devm_kcalloc(iod->dev, rows, sizeof(*pins), GFP_KERNEL);
521 cfg = devm_kcalloc(iod->dev, rows, sizeof(*cfg), GFP_KERNEL);
527 for (i = 0; i < rows; i++) {
528 struct of_phandle_args pinctrl_spec;
530 error = pinctrl_parse_index_with_args(np, name, i,
535 error = ti_iodelay_node_iterator(pctldev, np, &pinctrl_spec,
543 g->config = PIN_CONFIG_END;
545 error = pinctrl_generic_add_group(iod->pctl, np->name, pins, i, g);
549 (*map)->type = PIN_MAP_TYPE_CONFIGS_GROUP;
550 (*map)->data.configs.group_or_pin = np->name;
551 (*map)->data.configs.configs = &g->config;
552 (*map)->data.configs.num_configs = 1;
558 devm_kfree(iod->dev, cfg);
560 devm_kfree(iod->dev, pins);
562 devm_kfree(iod->dev, g);
564 devm_kfree(iod->dev, *map);
570 * ti_iodelay_pinconf_group_get() - Get the group configuration
571 * @pctldev: pinctrl device representing IODelay device
572 * @selector: Group selector
573 * @config: Configuration returned
575 * Return: The configuration if the group is valid, else returns -EINVAL
577 static int ti_iodelay_pinconf_group_get(struct pinctrl_dev *pctldev,
578 unsigned int selector,
579 unsigned long *config)
581 struct ti_iodelay_device *iod;
582 struct ti_iodelay_pingroup *group;
584 iod = pinctrl_dev_get_drvdata(pctldev);
585 group = ti_iodelay_get_pingroup(iod, selector);
590 *config = group->config;
595 * ti_iodelay_pinconf_group_set() - Configure the groups of pins
596 * @pctldev: pinctrl device representing IODelay device
597 * @selector: Group selector
598 * @configs: Configurations
599 * @num_configs: Number of configurations
601 * Return: 0 if all went fine, else appropriate error value.
603 static int ti_iodelay_pinconf_group_set(struct pinctrl_dev *pctldev,
604 unsigned int selector,
605 unsigned long *configs,
606 unsigned int num_configs)
608 struct ti_iodelay_device *iod;
610 struct ti_iodelay_pingroup *group;
613 iod = pinctrl_dev_get_drvdata(pctldev);
615 group = ti_iodelay_get_pingroup(iod, selector);
617 if (num_configs != 1) {
618 dev_err(dev, "Unsupported number of configurations %d\n",
623 if (*configs != PIN_CONFIG_END) {
624 dev_err(dev, "Unsupported configuration\n");
628 for (i = 0; i < group->ncfg; i++) {
629 if (ti_iodelay_pinconf_set(iod, &group->cfg[i]))
636 #ifdef CONFIG_DEBUG_FS
638 * ti_iodelay_pin_to_offset() - get pin register offset based on the pin index
639 * @iod: iodelay driver instance
640 * @selector: Pin index
642 static unsigned int ti_iodelay_pin_to_offset(struct ti_iodelay_device *iod,
643 unsigned int selector)
645 const struct ti_iodelay_reg_data *r = iod->reg_data;
648 offset = selector * r->regmap_config->reg_stride;
649 offset *= r->reg_nr_per_pin;
650 offset += r->reg_start_offset;
655 static void ti_iodelay_pin_dbg_show(struct pinctrl_dev *pctldev,
659 struct ti_iodelay_device *iod;
660 struct pinctrl_pin_desc *pd;
661 struct ti_iodelay_cfg *cfg;
662 const struct ti_iodelay_reg_data *r;
663 unsigned long offset;
666 iod = pinctrl_dev_get_drvdata(pctldev);
669 offset = ti_iodelay_pin_to_offset(iod, pin);
673 regmap_read(iod->regmap, offset, &in);
674 regmap_read(iod->regmap, offset + r->regmap_config->reg_stride, &oen);
675 regmap_read(iod->regmap, offset + r->regmap_config->reg_stride * 2,
678 seq_printf(s, "%lx a: %i g: %i (%08x %08x %08x) %s ",
679 iod->phys_base + offset,
680 cfg ? cfg->a_delay : -1,
681 cfg ? cfg->g_delay : -1,
682 in, oen, out, DRIVER_NAME);
686 * ti_iodelay_pinconf_group_dbg_show() - show the group information
687 * @pctldev: Show the group information
689 * @selector: Group selector
691 * Provide the configuration information of the selected group
693 static void ti_iodelay_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
695 unsigned int selector)
697 struct ti_iodelay_device *iod;
698 struct ti_iodelay_pingroup *group;
701 iod = pinctrl_dev_get_drvdata(pctldev);
702 group = ti_iodelay_get_pingroup(iod, selector);
706 for (i = 0; i < group->ncfg; i++) {
707 struct ti_iodelay_cfg *cfg;
710 cfg = &group->cfg[i];
711 regmap_read(iod->regmap, cfg->offset, ®);
712 seq_printf(s, "\n\t0x%08x = 0x%08x (%3d, %3d)",
713 cfg->offset, reg, cfg->a_delay, cfg->g_delay);
718 static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
719 .get_groups_count = pinctrl_generic_get_group_count,
720 .get_group_name = pinctrl_generic_get_group_name,
721 .get_group_pins = pinctrl_generic_get_group_pins,
722 #ifdef CONFIG_DEBUG_FS
723 .pin_dbg_show = ti_iodelay_pin_dbg_show,
725 .dt_node_to_map = ti_iodelay_dt_node_to_map,
728 static const struct pinconf_ops ti_iodelay_pinctrl_pinconf_ops = {
729 .pin_config_group_get = ti_iodelay_pinconf_group_get,
730 .pin_config_group_set = ti_iodelay_pinconf_group_set,
731 #ifdef CONFIG_DEBUG_FS
732 .pin_config_group_dbg_show = ti_iodelay_pinconf_group_dbg_show,
737 * ti_iodelay_alloc_pins() - Allocate structures needed for pins for iodelay
738 * @dev: Device pointer
739 * @iod: iodelay device
740 * @base_phy: Base Physical Address
742 * Return: 0 if all went fine, else appropriate error value.
744 static int ti_iodelay_alloc_pins(struct device *dev,
745 struct ti_iodelay_device *iod, u32 base_phy)
747 const struct ti_iodelay_reg_data *r = iod->reg_data;
748 struct pinctrl_pin_desc *pin;
752 nr_pins = ti_iodelay_offset_to_pin(iod, r->regmap_config->max_register);
753 dev_dbg(dev, "Allocating %i pins\n", nr_pins);
755 iod->pa = devm_kcalloc(dev, nr_pins, sizeof(*iod->pa), GFP_KERNEL);
759 iod->desc.pins = iod->pa;
760 iod->desc.npins = nr_pins;
762 phy_reg = r->reg_start_offset + base_phy;
764 for (i = 0; i < nr_pins; i++, phy_reg += 4) {
772 static struct regmap_config dra7_iodelay_regmap_config = {
776 .max_register = 0xd1c,
779 static struct ti_iodelay_reg_data dra7_iodelay_data = {
780 .signature_mask = 0x0003f000,
781 .signature_value = 0x29,
782 .lock_mask = 0x00000400,
785 .binary_data_coarse_mask = 0x000003e0,
786 .binary_data_fine_mask = 0x0000001f,
788 .reg_refclk_offset = 0x14,
789 .refclk_period_mask = 0xffff,
791 .reg_coarse_offset = 0x18,
792 .coarse_delay_count_mask = 0xffff0000,
793 .coarse_ref_count_mask = 0x0000ffff,
795 .reg_fine_offset = 0x1C,
796 .fine_delay_count_mask = 0xffff0000,
797 .fine_ref_count_mask = 0x0000ffff,
799 .reg_global_lock_offset = 0x2c,
800 .global_lock_mask = 0x0000ffff,
801 .global_unlock_val = 0x0000aaaa,
802 .global_lock_val = 0x0000aaab,
804 .reg_start_offset = 0x30,
806 .regmap_config = &dra7_iodelay_regmap_config,
809 static const struct of_device_id ti_iodelay_of_match[] = {
810 {.compatible = "ti,dra7-iodelay", .data = &dra7_iodelay_data},
811 { /* Hopefully no more.. */ },
813 MODULE_DEVICE_TABLE(of, ti_iodelay_of_match);
816 * ti_iodelay_probe() - Standard probe
817 * @pdev: platform device
819 * Return: 0 if all went fine, else appropriate error value.
821 static int ti_iodelay_probe(struct platform_device *pdev)
823 struct device *dev = &pdev->dev;
824 struct device_node *np = of_node_get(dev->of_node);
825 const struct of_device_id *match;
826 struct resource *res;
827 struct ti_iodelay_device *iod;
832 dev_err(dev, "No OF node\n");
836 match = of_match_device(ti_iodelay_of_match, dev);
839 dev_err(dev, "No DATA match\n");
843 iod = devm_kzalloc(dev, sizeof(*iod), GFP_KERNEL);
849 iod->reg_data = match->data;
851 /* So far We can assume there is only 1 bank of registers */
852 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
854 dev_err(dev, "Missing MEM resource\n");
859 iod->phys_base = res->start;
860 iod->reg_base = devm_ioremap_resource(dev, res);
861 if (IS_ERR(iod->reg_base)) {
862 ret = PTR_ERR(iod->reg_base);
866 iod->regmap = devm_regmap_init_mmio(dev, iod->reg_base,
867 iod->reg_data->regmap_config);
868 if (IS_ERR(iod->regmap)) {
869 dev_err(dev, "Regmap MMIO init failed.\n");
870 ret = PTR_ERR(iod->regmap);
874 ret = ti_iodelay_pinconf_init_dev(iod);
878 ret = ti_iodelay_alloc_pins(dev, iod, res->start);
882 iod->desc.pctlops = &ti_iodelay_pinctrl_ops;
883 /* no pinmux ops - we are pinconf */
884 iod->desc.confops = &ti_iodelay_pinctrl_pinconf_ops;
885 iod->desc.name = dev_name(dev);
886 iod->desc.owner = THIS_MODULE;
888 ret = pinctrl_register_and_init(&iod->desc, dev, iod, &iod->pctl);
890 dev_err(dev, "Failed to register pinctrl\n");
894 platform_set_drvdata(pdev, iod);
896 return pinctrl_enable(iod->pctl);
904 * ti_iodelay_remove() - standard remove
905 * @pdev: platform device
907 * Return: 0 if all went fine, else appropriate error value.
909 static int ti_iodelay_remove(struct platform_device *pdev)
911 struct ti_iodelay_device *iod = platform_get_drvdata(pdev);
917 pinctrl_unregister(iod->pctl);
919 ti_iodelay_pinconf_deinit_dev(iod);
921 /* Expect other allocations to be freed by devm */
926 static struct platform_driver ti_iodelay_driver = {
927 .probe = ti_iodelay_probe,
928 .remove = ti_iodelay_remove,
931 .of_match_table = ti_iodelay_of_match,
934 module_platform_driver(ti_iodelay_driver);
936 MODULE_AUTHOR("Texas Instruments, Inc.");
937 MODULE_DESCRIPTION("Pinconf driver for TI's IO Delay module");
938 MODULE_LICENSE("GPL v2");