Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Core driver for the imx pin controller |
| 3 | * |
| 4 | * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 5 | * Copyright (C) 2012 Linaro Ltd. |
| 6 | * |
| 7 | * Author: Dong Aisheng <dong.aisheng@linaro.org> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/io.h> |
Philipp Zabel | 8626ada | 2016-02-25 18:23:07 +0100 | [diff] [blame] | 18 | #include <linux/mfd/syscon.h> |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/of_device.h> |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 22 | #include <linux/of_address.h> |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 23 | #include <linux/pinctrl/machine.h> |
| 24 | #include <linux/pinctrl/pinconf.h> |
| 25 | #include <linux/pinctrl/pinctrl.h> |
| 26 | #include <linux/pinctrl/pinmux.h> |
| 27 | #include <linux/slab.h> |
Philipp Zabel | 8626ada | 2016-02-25 18:23:07 +0100 | [diff] [blame] | 28 | #include <linux/regmap.h> |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 29 | |
Linus Walleij | edad3b2 | 2014-09-03 13:37:38 +0200 | [diff] [blame] | 30 | #include "../core.h" |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 31 | #include "pinctrl-imx.h" |
| 32 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 33 | /* The bits in CONFIG cell defined in binding doc*/ |
| 34 | #define IMX_NO_PAD_CTL 0x80000000 /* no pin config need */ |
| 35 | #define IMX_PAD_SION 0x40000000 /* set SION */ |
| 36 | |
| 37 | /** |
| 38 | * @dev: a pointer back to containing device |
| 39 | * @base: the offset to the controller in virtual memory |
| 40 | */ |
| 41 | struct imx_pinctrl { |
| 42 | struct device *dev; |
| 43 | struct pinctrl_dev *pctl; |
| 44 | void __iomem *base; |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 45 | void __iomem *input_sel_base; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 46 | const struct imx_pinctrl_soc_info *info; |
| 47 | }; |
| 48 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 49 | static const inline struct imx_pin_group *imx_pinctrl_find_group_by_name( |
| 50 | const struct imx_pinctrl_soc_info *info, |
| 51 | const char *name) |
| 52 | { |
| 53 | const struct imx_pin_group *grp = NULL; |
| 54 | int i; |
| 55 | |
| 56 | for (i = 0; i < info->ngroups; i++) { |
| 57 | if (!strcmp(info->groups[i].name, name)) { |
| 58 | grp = &info->groups[i]; |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return grp; |
| 64 | } |
| 65 | |
| 66 | static int imx_get_groups_count(struct pinctrl_dev *pctldev) |
| 67 | { |
| 68 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 69 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 70 | |
| 71 | return info->ngroups; |
| 72 | } |
| 73 | |
| 74 | static const char *imx_get_group_name(struct pinctrl_dev *pctldev, |
| 75 | unsigned selector) |
| 76 | { |
| 77 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 78 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 79 | |
| 80 | return info->groups[selector].name; |
| 81 | } |
| 82 | |
| 83 | static int imx_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector, |
| 84 | const unsigned **pins, |
| 85 | unsigned *npins) |
| 86 | { |
| 87 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 88 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 89 | |
| 90 | if (selector >= info->ngroups) |
| 91 | return -EINVAL; |
| 92 | |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 93 | *pins = info->groups[selector].pin_ids; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 94 | *npins = info->groups[selector].npins; |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static void imx_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
| 100 | unsigned offset) |
| 101 | { |
| 102 | seq_printf(s, "%s", dev_name(pctldev->dev)); |
| 103 | } |
| 104 | |
| 105 | static int imx_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 106 | struct device_node *np, |
| 107 | struct pinctrl_map **map, unsigned *num_maps) |
| 108 | { |
| 109 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 110 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 111 | const struct imx_pin_group *grp; |
| 112 | struct pinctrl_map *new_map; |
| 113 | struct device_node *parent; |
| 114 | int map_num = 1; |
Hui Wang | 1807161 | 2012-06-20 18:13:47 +0800 | [diff] [blame] | 115 | int i, j; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * first find the group of this node and check if we need create |
| 119 | * config maps for pins |
| 120 | */ |
| 121 | grp = imx_pinctrl_find_group_by_name(info, np->name); |
| 122 | if (!grp) { |
| 123 | dev_err(info->dev, "unable to find group for node %s\n", |
| 124 | np->name); |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | |
| 128 | for (i = 0; i < grp->npins; i++) { |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 129 | if (!(grp->pins[i].config & IMX_NO_PAD_CTL)) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 130 | map_num++; |
| 131 | } |
| 132 | |
| 133 | new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL); |
| 134 | if (!new_map) |
| 135 | return -ENOMEM; |
| 136 | |
| 137 | *map = new_map; |
| 138 | *num_maps = map_num; |
| 139 | |
| 140 | /* create mux map */ |
| 141 | parent = of_get_parent(np); |
Devendra Naga | c71157c | 2012-06-07 22:19:26 +0530 | [diff] [blame] | 142 | if (!parent) { |
| 143 | kfree(new_map); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 144 | return -EINVAL; |
Devendra Naga | c71157c | 2012-06-07 22:19:26 +0530 | [diff] [blame] | 145 | } |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 146 | new_map[0].type = PIN_MAP_TYPE_MUX_GROUP; |
| 147 | new_map[0].data.mux.function = parent->name; |
| 148 | new_map[0].data.mux.group = np->name; |
| 149 | of_node_put(parent); |
| 150 | |
| 151 | /* create config map */ |
| 152 | new_map++; |
Hui Wang | 1807161 | 2012-06-20 18:13:47 +0800 | [diff] [blame] | 153 | for (i = j = 0; i < grp->npins; i++) { |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 154 | if (!(grp->pins[i].config & IMX_NO_PAD_CTL)) { |
Hui Wang | 1807161 | 2012-06-20 18:13:47 +0800 | [diff] [blame] | 155 | new_map[j].type = PIN_MAP_TYPE_CONFIGS_PIN; |
| 156 | new_map[j].data.configs.group_or_pin = |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 157 | pin_get_name(pctldev, grp->pins[i].pin); |
| 158 | new_map[j].data.configs.configs = &grp->pins[i].config; |
Hui Wang | 1807161 | 2012-06-20 18:13:47 +0800 | [diff] [blame] | 159 | new_map[j].data.configs.num_configs = 1; |
| 160 | j++; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| 164 | dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n", |
Dong Aisheng | 67695f2 | 2012-06-08 21:33:12 +0800 | [diff] [blame] | 165 | (*map)->data.mux.function, (*map)->data.mux.group, map_num); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static void imx_dt_free_map(struct pinctrl_dev *pctldev, |
| 171 | struct pinctrl_map *map, unsigned num_maps) |
| 172 | { |
Devendra Naga | 3a86a5f | 2012-06-09 00:52:11 +0530 | [diff] [blame] | 173 | kfree(map); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 174 | } |
| 175 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 176 | static const struct pinctrl_ops imx_pctrl_ops = { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 177 | .get_groups_count = imx_get_groups_count, |
| 178 | .get_group_name = imx_get_group_name, |
| 179 | .get_group_pins = imx_get_group_pins, |
| 180 | .pin_dbg_show = imx_pin_dbg_show, |
| 181 | .dt_node_to_map = imx_dt_node_to_map, |
| 182 | .dt_free_map = imx_dt_free_map, |
| 183 | |
| 184 | }; |
| 185 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 186 | static int imx_pmx_set(struct pinctrl_dev *pctldev, unsigned selector, |
| 187 | unsigned group) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 188 | { |
| 189 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 190 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 191 | const struct imx_pin_reg *pin_reg; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 192 | unsigned int npins, pin_id; |
| 193 | int i; |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 194 | struct imx_pin_group *grp; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 195 | |
| 196 | /* |
| 197 | * Configure the mux mode for each pin in the group for a specific |
| 198 | * function. |
| 199 | */ |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 200 | grp = &info->groups[group]; |
| 201 | npins = grp->npins; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 202 | |
| 203 | dev_dbg(ipctl->dev, "enable function %s group %s\n", |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 204 | info->functions[selector].name, grp->name); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 205 | |
| 206 | for (i = 0; i < npins; i++) { |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 207 | struct imx_pin *pin = &grp->pins[i]; |
| 208 | pin_id = pin->pin; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 209 | pin_reg = &info->pin_regs[pin_id]; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 210 | |
Stefan Agner | 3dac191 | 2014-09-06 18:25:04 +0200 | [diff] [blame] | 211 | if (pin_reg->mux_reg == -1) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 212 | dev_err(ipctl->dev, "Pin(%s) does not support mux function\n", |
| 213 | info->pins[pin_id].name); |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 217 | if (info->flags & SHARE_MUX_CONF_REG) { |
| 218 | u32 reg; |
| 219 | reg = readl(ipctl->base + pin_reg->mux_reg); |
| 220 | reg &= ~(0x7 << 20); |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 221 | reg |= (pin->mux_mode << 20); |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 222 | writel(reg, ipctl->base + pin_reg->mux_reg); |
| 223 | } else { |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 224 | writel(pin->mux_mode, ipctl->base + pin_reg->mux_reg); |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 225 | } |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 226 | dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%x\n", |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 227 | pin_reg->mux_reg, pin->mux_mode); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 228 | |
Shawn Guo | 94176fa | 2013-08-04 21:39:23 +0800 | [diff] [blame] | 229 | /* |
| 230 | * If the select input value begins with 0xff, it's a quirky |
| 231 | * select input and the value should be interpreted as below. |
| 232 | * 31 23 15 7 0 |
| 233 | * | 0xff | shift | width | select | |
| 234 | * It's used to work around the problem that the select |
| 235 | * input for some pin is not implemented in the select |
| 236 | * input register but in some general purpose register. |
| 237 | * We encode the select input value, width and shift of |
| 238 | * the bit field into input_val cell of pin function ID |
| 239 | * in device tree, and then decode them here for setting |
| 240 | * up the select input bits in general purpose register. |
| 241 | */ |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 242 | if (pin->input_val >> 24 == 0xff) { |
| 243 | u32 val = pin->input_val; |
Shawn Guo | 94176fa | 2013-08-04 21:39:23 +0800 | [diff] [blame] | 244 | u8 select = val & 0xff; |
| 245 | u8 width = (val >> 8) & 0xff; |
| 246 | u8 shift = (val >> 16) & 0xff; |
| 247 | u32 mask = ((1 << width) - 1) << shift; |
| 248 | /* |
| 249 | * The input_reg[i] here is actually some IOMUXC general |
| 250 | * purpose register, not regular select input register. |
| 251 | */ |
Peter Chen | a3183c6 | 2013-10-28 14:01:16 +0800 | [diff] [blame] | 252 | val = readl(ipctl->base + pin->input_reg); |
Shawn Guo | 94176fa | 2013-08-04 21:39:23 +0800 | [diff] [blame] | 253 | val &= ~mask; |
| 254 | val |= select << shift; |
Peter Chen | a3183c6 | 2013-10-28 14:01:16 +0800 | [diff] [blame] | 255 | writel(val, ipctl->base + pin->input_reg); |
| 256 | } else if (pin->input_reg) { |
Shawn Guo | 94176fa | 2013-08-04 21:39:23 +0800 | [diff] [blame] | 257 | /* |
| 258 | * Regular select input register can never be at offset |
| 259 | * 0, and we only print register value for regular case. |
| 260 | */ |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 261 | if (ipctl->input_sel_base) |
| 262 | writel(pin->input_val, ipctl->input_sel_base + |
| 263 | pin->input_reg); |
| 264 | else |
| 265 | writel(pin->input_val, ipctl->base + |
| 266 | pin->input_reg); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 267 | dev_dbg(ipctl->dev, |
| 268 | "==>select_input: offset 0x%x val 0x%x\n", |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 269 | pin->input_reg, pin->input_val); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 276 | static int imx_pmx_get_funcs_count(struct pinctrl_dev *pctldev) |
| 277 | { |
| 278 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 279 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 280 | |
| 281 | return info->nfunctions; |
| 282 | } |
| 283 | |
| 284 | static const char *imx_pmx_get_func_name(struct pinctrl_dev *pctldev, |
| 285 | unsigned selector) |
| 286 | { |
| 287 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 288 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 289 | |
| 290 | return info->functions[selector].name; |
| 291 | } |
| 292 | |
| 293 | static int imx_pmx_get_groups(struct pinctrl_dev *pctldev, unsigned selector, |
| 294 | const char * const **groups, |
| 295 | unsigned * const num_groups) |
| 296 | { |
| 297 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 298 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 299 | |
| 300 | *groups = info->functions[selector].groups; |
| 301 | *num_groups = info->functions[selector].num_groups; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Stefan Agner | 1f2b045 | 2014-10-16 21:47:57 +0200 | [diff] [blame] | 306 | static int imx_pmx_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 307 | struct pinctrl_gpio_range *range, unsigned offset) |
| 308 | { |
| 309 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 310 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 311 | const struct imx_pin_reg *pin_reg; |
| 312 | struct imx_pin_group *grp; |
| 313 | struct imx_pin *imx_pin; |
| 314 | unsigned int pin, group; |
| 315 | u32 reg; |
| 316 | |
| 317 | /* Currently implementation only for shared mux/conf register */ |
| 318 | if (!(info->flags & SHARE_MUX_CONF_REG)) |
| 319 | return -EINVAL; |
| 320 | |
| 321 | pin_reg = &info->pin_regs[offset]; |
| 322 | if (pin_reg->mux_reg == -1) |
| 323 | return -EINVAL; |
| 324 | |
| 325 | /* Find the pinctrl config with GPIO mux mode for the requested pin */ |
| 326 | for (group = 0; group < info->ngroups; group++) { |
| 327 | grp = &info->groups[group]; |
| 328 | for (pin = 0; pin < grp->npins; pin++) { |
| 329 | imx_pin = &grp->pins[pin]; |
| 330 | if (imx_pin->pin == offset && !imx_pin->mux_mode) |
| 331 | goto mux_pin; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return -EINVAL; |
| 336 | |
| 337 | mux_pin: |
| 338 | reg = readl(ipctl->base + pin_reg->mux_reg); |
| 339 | reg &= ~(0x7 << 20); |
| 340 | reg |= imx_pin->config; |
| 341 | writel(reg, ipctl->base + pin_reg->mux_reg); |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
Stefan Agner | 23c3960 | 2016-01-08 10:50:30 -0800 | [diff] [blame] | 346 | static void imx_pmx_gpio_disable_free(struct pinctrl_dev *pctldev, |
| 347 | struct pinctrl_gpio_range *range, unsigned offset) |
| 348 | { |
| 349 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 350 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 351 | const struct imx_pin_reg *pin_reg; |
| 352 | u32 reg; |
| 353 | |
| 354 | /* |
| 355 | * Only Vybrid has the input/output buffer enable flags (IBE/OBE) |
| 356 | * They are part of the shared mux/conf register. |
| 357 | */ |
| 358 | if (!(info->flags & SHARE_MUX_CONF_REG)) |
| 359 | return; |
| 360 | |
| 361 | pin_reg = &info->pin_regs[offset]; |
| 362 | if (pin_reg->mux_reg == -1) |
| 363 | return; |
| 364 | |
| 365 | /* Clear IBE/OBE/PUE to disable the pin (Hi-Z) */ |
| 366 | reg = readl(ipctl->base + pin_reg->mux_reg); |
| 367 | reg &= ~0x7; |
| 368 | writel(reg, ipctl->base + pin_reg->mux_reg); |
| 369 | } |
| 370 | |
Stefan Agner | 1f2b045 | 2014-10-16 21:47:57 +0200 | [diff] [blame] | 371 | static int imx_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 372 | struct pinctrl_gpio_range *range, unsigned offset, bool input) |
| 373 | { |
| 374 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 375 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 376 | const struct imx_pin_reg *pin_reg; |
| 377 | u32 reg; |
| 378 | |
| 379 | /* |
| 380 | * Only Vybrid has the input/output buffer enable flags (IBE/OBE) |
| 381 | * They are part of the shared mux/conf register. |
| 382 | */ |
| 383 | if (!(info->flags & SHARE_MUX_CONF_REG)) |
| 384 | return -EINVAL; |
| 385 | |
| 386 | pin_reg = &info->pin_regs[offset]; |
| 387 | if (pin_reg->mux_reg == -1) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | /* IBE always enabled allows us to read the value "on the wire" */ |
| 391 | reg = readl(ipctl->base + pin_reg->mux_reg); |
| 392 | if (input) |
| 393 | reg &= ~0x2; |
| 394 | else |
| 395 | reg |= 0x2; |
| 396 | writel(reg, ipctl->base + pin_reg->mux_reg); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 401 | static const struct pinmux_ops imx_pmx_ops = { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 402 | .get_functions_count = imx_pmx_get_funcs_count, |
| 403 | .get_function_name = imx_pmx_get_func_name, |
| 404 | .get_function_groups = imx_pmx_get_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 405 | .set_mux = imx_pmx_set, |
Stefan Agner | 1f2b045 | 2014-10-16 21:47:57 +0200 | [diff] [blame] | 406 | .gpio_request_enable = imx_pmx_gpio_request_enable, |
Stefan Agner | 23c3960 | 2016-01-08 10:50:30 -0800 | [diff] [blame] | 407 | .gpio_disable_free = imx_pmx_gpio_disable_free, |
Stefan Agner | 1f2b045 | 2014-10-16 21:47:57 +0200 | [diff] [blame] | 408 | .gpio_set_direction = imx_pmx_gpio_set_direction, |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | static int imx_pinconf_get(struct pinctrl_dev *pctldev, |
| 412 | unsigned pin_id, unsigned long *config) |
| 413 | { |
| 414 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 415 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 416 | const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id]; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 417 | |
Stefan Agner | 3dac191 | 2014-09-06 18:25:04 +0200 | [diff] [blame] | 418 | if (pin_reg->conf_reg == -1) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 419 | dev_err(info->dev, "Pin(%s) does not support config function\n", |
| 420 | info->pins[pin_id].name); |
| 421 | return -EINVAL; |
| 422 | } |
| 423 | |
| 424 | *config = readl(ipctl->base + pin_reg->conf_reg); |
| 425 | |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 426 | if (info->flags & SHARE_MUX_CONF_REG) |
| 427 | *config &= 0xffff; |
| 428 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int imx_pinconf_set(struct pinctrl_dev *pctldev, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 433 | unsigned pin_id, unsigned long *configs, |
| 434 | unsigned num_configs) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 435 | { |
| 436 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 437 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 438 | const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id]; |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 439 | int i; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 440 | |
Stefan Agner | 3dac191 | 2014-09-06 18:25:04 +0200 | [diff] [blame] | 441 | if (pin_reg->conf_reg == -1) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 442 | dev_err(info->dev, "Pin(%s) does not support config function\n", |
| 443 | info->pins[pin_id].name); |
| 444 | return -EINVAL; |
| 445 | } |
| 446 | |
| 447 | dev_dbg(ipctl->dev, "pinconf set pin %s\n", |
| 448 | info->pins[pin_id].name); |
| 449 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 450 | for (i = 0; i < num_configs; i++) { |
| 451 | if (info->flags & SHARE_MUX_CONF_REG) { |
| 452 | u32 reg; |
| 453 | reg = readl(ipctl->base + pin_reg->conf_reg); |
| 454 | reg &= ~0xffff; |
| 455 | reg |= configs[i]; |
| 456 | writel(reg, ipctl->base + pin_reg->conf_reg); |
| 457 | } else { |
| 458 | writel(configs[i], ipctl->base + pin_reg->conf_reg); |
| 459 | } |
| 460 | dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%lx\n", |
| 461 | pin_reg->conf_reg, configs[i]); |
| 462 | } /* for each config */ |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static void imx_pinconf_dbg_show(struct pinctrl_dev *pctldev, |
| 468 | struct seq_file *s, unsigned pin_id) |
| 469 | { |
| 470 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 471 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 472 | const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id]; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 473 | unsigned long config; |
| 474 | |
Uwe Kleine-König | 4ff0f03 | 2015-01-27 23:50:25 +0100 | [diff] [blame] | 475 | if (!pin_reg || pin_reg->conf_reg == -1) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 476 | seq_printf(s, "N/A"); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | config = readl(ipctl->base + pin_reg->conf_reg); |
| 481 | seq_printf(s, "0x%lx", config); |
| 482 | } |
| 483 | |
| 484 | static void imx_pinconf_group_dbg_show(struct pinctrl_dev *pctldev, |
| 485 | struct seq_file *s, unsigned group) |
| 486 | { |
| 487 | struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); |
| 488 | const struct imx_pinctrl_soc_info *info = ipctl->info; |
| 489 | struct imx_pin_group *grp; |
| 490 | unsigned long config; |
| 491 | const char *name; |
| 492 | int i, ret; |
| 493 | |
| 494 | if (group > info->ngroups) |
| 495 | return; |
| 496 | |
| 497 | seq_printf(s, "\n"); |
| 498 | grp = &info->groups[group]; |
| 499 | for (i = 0; i < grp->npins; i++) { |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 500 | struct imx_pin *pin = &grp->pins[i]; |
| 501 | name = pin_get_name(pctldev, pin->pin); |
| 502 | ret = imx_pinconf_get(pctldev, pin->pin, &config); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 503 | if (ret) |
| 504 | return; |
| 505 | seq_printf(s, "%s: 0x%lx", name, config); |
| 506 | } |
| 507 | } |
| 508 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 509 | static const struct pinconf_ops imx_pinconf_ops = { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 510 | .pin_config_get = imx_pinconf_get, |
| 511 | .pin_config_set = imx_pinconf_set, |
| 512 | .pin_config_dbg_show = imx_pinconf_dbg_show, |
| 513 | .pin_config_group_dbg_show = imx_pinconf_group_dbg_show, |
| 514 | }; |
| 515 | |
| 516 | static struct pinctrl_desc imx_pinctrl_desc = { |
| 517 | .pctlops = &imx_pctrl_ops, |
| 518 | .pmxops = &imx_pmx_ops, |
| 519 | .confops = &imx_pinconf_ops, |
| 520 | .owner = THIS_MODULE, |
| 521 | }; |
| 522 | |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 523 | /* |
| 524 | * Each pin represented in fsl,pins consists of 5 u32 PIN_FUNC_ID and |
| 525 | * 1 u32 CONFIG, so 24 types in total for each pin. |
| 526 | */ |
| 527 | #define FSL_PIN_SIZE 24 |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 528 | #define SHARE_FSL_PIN_SIZE 20 |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 529 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 530 | static int imx_pinctrl_parse_groups(struct device_node *np, |
| 531 | struct imx_pin_group *grp, |
| 532 | struct imx_pinctrl_soc_info *info, |
| 533 | u32 index) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 534 | { |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 535 | int size, pin_size; |
Richard Zhao | a695145 | 2012-09-18 14:54:00 +0800 | [diff] [blame] | 536 | const __be32 *list; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 537 | int i; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 538 | u32 config; |
| 539 | |
| 540 | dev_dbg(info->dev, "group(%d): %s\n", index, np->name); |
| 541 | |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 542 | if (info->flags & SHARE_MUX_CONF_REG) |
| 543 | pin_size = SHARE_FSL_PIN_SIZE; |
| 544 | else |
| 545 | pin_size = FSL_PIN_SIZE; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 546 | /* Initialise group */ |
| 547 | grp->name = np->name; |
| 548 | |
| 549 | /* |
| 550 | * the binding format is fsl,pins = <PIN_FUNC_ID CONFIG ...>, |
| 551 | * do sanity check and calculate pins number |
| 552 | */ |
| 553 | list = of_get_property(np, "fsl,pins", &size); |
Sascha Hauer | 1bf1fea9 | 2013-08-09 14:20:51 +0200 | [diff] [blame] | 554 | if (!list) { |
| 555 | dev_err(info->dev, "no fsl,pins property in node %s\n", np->full_name); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 559 | /* we do not check return since it's safe node passed down */ |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 560 | if (!size || size % pin_size) { |
Sascha Hauer | 0131251 | 2013-08-09 14:20:50 +0200 | [diff] [blame] | 561 | dev_err(info->dev, "Invalid fsl,pins property in node %s\n", np->full_name); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 562 | return -EINVAL; |
| 563 | } |
| 564 | |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 565 | grp->npins = size / pin_size; |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 566 | grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(struct imx_pin), |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 567 | GFP_KERNEL); |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 568 | grp->pin_ids = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int), |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 569 | GFP_KERNEL); |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 570 | if (!grp->pins || ! grp->pin_ids) |
| 571 | return -ENOMEM; |
| 572 | |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 573 | for (i = 0; i < grp->npins; i++) { |
| 574 | u32 mux_reg = be32_to_cpu(*list++); |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 575 | u32 conf_reg; |
| 576 | unsigned int pin_id; |
| 577 | struct imx_pin_reg *pin_reg; |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 578 | struct imx_pin *pin = &grp->pins[i]; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 579 | |
Adrian Alonso | e7b37a5 | 2015-09-25 16:05:59 -0500 | [diff] [blame] | 580 | if (!(info->flags & ZERO_OFFSET_VALID) && !mux_reg) |
| 581 | mux_reg = -1; |
| 582 | |
Markus Pargmann | 16837f9 | 2015-03-24 16:26:18 +0100 | [diff] [blame] | 583 | if (info->flags & SHARE_MUX_CONF_REG) { |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 584 | conf_reg = mux_reg; |
Markus Pargmann | 16837f9 | 2015-03-24 16:26:18 +0100 | [diff] [blame] | 585 | } else { |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 586 | conf_reg = be32_to_cpu(*list++); |
Markus Pargmann | 16837f9 | 2015-03-24 16:26:18 +0100 | [diff] [blame] | 587 | if (!conf_reg) |
| 588 | conf_reg = -1; |
| 589 | } |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 590 | |
Adrian Alonso | e7b37a5 | 2015-09-25 16:05:59 -0500 | [diff] [blame] | 591 | pin_id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4; |
Jingchang Lu | bf5a530 | 2013-05-28 17:32:07 +0800 | [diff] [blame] | 592 | pin_reg = &info->pin_regs[pin_id]; |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 593 | pin->pin = pin_id; |
| 594 | grp->pin_ids[i] = pin_id; |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 595 | pin_reg->mux_reg = mux_reg; |
| 596 | pin_reg->conf_reg = conf_reg; |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 597 | pin->input_reg = be32_to_cpu(*list++); |
| 598 | pin->mux_mode = be32_to_cpu(*list++); |
| 599 | pin->input_val = be32_to_cpu(*list++); |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 600 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 601 | /* SION bit is in mux register */ |
| 602 | config = be32_to_cpu(*list++); |
| 603 | if (config & IMX_PAD_SION) |
Sascha Hauer | 8f903f8 | 2013-07-28 16:29:22 +0200 | [diff] [blame] | 604 | pin->mux_mode |= IOMUXC_CONFIG_SION; |
| 605 | pin->config = config & ~IMX_PAD_SION; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 606 | |
Fabio Estevam | 08b5195 | 2014-04-13 12:09:05 -0300 | [diff] [blame] | 607 | dev_dbg(info->dev, "%s: 0x%x 0x%08lx", info->pins[pin_id].name, |
Sascha Hauer | 4060446 | 2013-08-23 10:38:57 +0200 | [diff] [blame] | 608 | pin->mux_mode, pin->config); |
| 609 | } |
Devendra Naga | 3a86a5f | 2012-06-09 00:52:11 +0530 | [diff] [blame] | 610 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 614 | static int imx_pinctrl_parse_functions(struct device_node *np, |
| 615 | struct imx_pinctrl_soc_info *info, |
| 616 | u32 index) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 617 | { |
| 618 | struct device_node *child; |
| 619 | struct imx_pmx_func *func; |
| 620 | struct imx_pin_group *grp; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 621 | u32 i = 0; |
| 622 | |
| 623 | dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name); |
| 624 | |
| 625 | func = &info->functions[index]; |
| 626 | |
| 627 | /* Initialise function */ |
| 628 | func->name = np->name; |
| 629 | func->num_groups = of_get_child_count(np); |
Rickard Strandqvist | 9eedfd6 | 2014-06-26 13:28:16 +0200 | [diff] [blame] | 630 | if (func->num_groups == 0) { |
Sascha Hauer | 0131251 | 2013-08-09 14:20:50 +0200 | [diff] [blame] | 631 | dev_err(info->dev, "no groups defined in %s\n", np->full_name); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 632 | return -EINVAL; |
| 633 | } |
| 634 | func->groups = devm_kzalloc(info->dev, |
| 635 | func->num_groups * sizeof(char *), GFP_KERNEL); |
| 636 | |
| 637 | for_each_child_of_node(np, child) { |
| 638 | func->groups[i] = child->name; |
Robin Gong | ee16351 | 2015-09-24 15:53:57 -0500 | [diff] [blame] | 639 | grp = &info->groups[info->group_index++]; |
Sascha Hauer | 5e13762c | 2013-08-09 14:20:52 +0200 | [diff] [blame] | 640 | imx_pinctrl_parse_groups(child, grp, info, i++); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
Markus Pargmann | 5fcdf6a | 2015-04-10 16:22:38 +0200 | [diff] [blame] | 646 | /* |
| 647 | * Check if the DT contains pins in the direct child nodes. This indicates the |
| 648 | * newer DT format to store pins. This function returns true if the first found |
| 649 | * fsl,pins property is in a child of np. Otherwise false is returned. |
| 650 | */ |
| 651 | static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np) |
| 652 | { |
| 653 | struct device_node *function_np; |
| 654 | struct device_node *pinctrl_np; |
| 655 | |
| 656 | for_each_child_of_node(np, function_np) { |
| 657 | if (of_property_read_bool(function_np, "fsl,pins")) |
| 658 | return true; |
| 659 | |
| 660 | for_each_child_of_node(function_np, pinctrl_np) { |
| 661 | if (of_property_read_bool(pinctrl_np, "fsl,pins")) |
| 662 | return false; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | return true; |
| 667 | } |
| 668 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 669 | static int imx_pinctrl_probe_dt(struct platform_device *pdev, |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 670 | struct imx_pinctrl_soc_info *info) |
| 671 | { |
| 672 | struct device_node *np = pdev->dev.of_node; |
| 673 | struct device_node *child; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 674 | u32 nfuncs = 0; |
| 675 | u32 i = 0; |
Markus Pargmann | 5fcdf6a | 2015-04-10 16:22:38 +0200 | [diff] [blame] | 676 | bool flat_funcs; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 677 | |
| 678 | if (!np) |
| 679 | return -ENODEV; |
| 680 | |
Markus Pargmann | 5fcdf6a | 2015-04-10 16:22:38 +0200 | [diff] [blame] | 681 | flat_funcs = imx_pinctrl_dt_is_flat_functions(np); |
| 682 | if (flat_funcs) { |
| 683 | nfuncs = 1; |
| 684 | } else { |
| 685 | nfuncs = of_get_child_count(np); |
| 686 | if (nfuncs <= 0) { |
| 687 | dev_err(&pdev->dev, "no functions defined\n"); |
| 688 | return -EINVAL; |
| 689 | } |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | info->nfunctions = nfuncs; |
| 693 | info->functions = devm_kzalloc(&pdev->dev, nfuncs * sizeof(struct imx_pmx_func), |
| 694 | GFP_KERNEL); |
| 695 | if (!info->functions) |
| 696 | return -ENOMEM; |
| 697 | |
Markus Pargmann | 5fcdf6a | 2015-04-10 16:22:38 +0200 | [diff] [blame] | 698 | if (flat_funcs) { |
| 699 | info->ngroups = of_get_child_count(np); |
| 700 | } else { |
| 701 | info->ngroups = 0; |
| 702 | for_each_child_of_node(np, child) |
| 703 | info->ngroups += of_get_child_count(child); |
| 704 | } |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 705 | info->groups = devm_kzalloc(&pdev->dev, info->ngroups * sizeof(struct imx_pin_group), |
| 706 | GFP_KERNEL); |
| 707 | if (!info->groups) |
| 708 | return -ENOMEM; |
| 709 | |
Markus Pargmann | 5fcdf6a | 2015-04-10 16:22:38 +0200 | [diff] [blame] | 710 | if (flat_funcs) { |
| 711 | imx_pinctrl_parse_functions(np, info, 0); |
| 712 | } else { |
| 713 | for_each_child_of_node(np, child) |
| 714 | imx_pinctrl_parse_functions(child, info, i++); |
| 715 | } |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 720 | int imx_pinctrl_probe(struct platform_device *pdev, |
| 721 | struct imx_pinctrl_soc_info *info) |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 722 | { |
Philipp Zabel | 8626ada | 2016-02-25 18:23:07 +0100 | [diff] [blame] | 723 | struct regmap_config config = { .name = "gpr" }; |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 724 | struct device_node *dev_np = pdev->dev.of_node; |
| 725 | struct device_node *np; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 726 | struct imx_pinctrl *ipctl; |
| 727 | struct resource *res; |
Philipp Zabel | 8626ada | 2016-02-25 18:23:07 +0100 | [diff] [blame] | 728 | struct regmap *gpr; |
Stefan Agner | 4691dd0 | 2015-02-06 17:30:56 +0100 | [diff] [blame] | 729 | int ret, i; |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 730 | |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 731 | if (!info || !info->pins || !info->npins) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 732 | dev_err(&pdev->dev, "wrong pinctrl info\n"); |
| 733 | return -EINVAL; |
| 734 | } |
| 735 | info->dev = &pdev->dev; |
| 736 | |
Philipp Zabel | 8626ada | 2016-02-25 18:23:07 +0100 | [diff] [blame] | 737 | if (info->gpr_compatible) { |
| 738 | gpr = syscon_regmap_lookup_by_compatible(info->gpr_compatible); |
| 739 | if (!IS_ERR(gpr)) |
| 740 | regmap_attach_dev(&pdev->dev, gpr, &config); |
| 741 | } |
| 742 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 743 | /* Create state holders etc for this driver */ |
| 744 | ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); |
| 745 | if (!ipctl) |
| 746 | return -ENOMEM; |
| 747 | |
Stefan Agner | 3dac191 | 2014-09-06 18:25:04 +0200 | [diff] [blame] | 748 | info->pin_regs = devm_kmalloc(&pdev->dev, sizeof(*info->pin_regs) * |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 749 | info->npins, GFP_KERNEL); |
| 750 | if (!info->pin_regs) |
| 751 | return -ENOMEM; |
Stefan Agner | 4691dd0 | 2015-02-06 17:30:56 +0100 | [diff] [blame] | 752 | |
| 753 | for (i = 0; i < info->npins; i++) { |
| 754 | info->pin_regs[i].mux_reg = -1; |
| 755 | info->pin_regs[i].conf_reg = -1; |
| 756 | } |
Shawn Guo | e164153 | 2013-02-20 10:32:52 +0800 | [diff] [blame] | 757 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 758 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 9e0c1fb | 2013-01-21 11:09:14 +0100 | [diff] [blame] | 759 | ipctl->base = devm_ioremap_resource(&pdev->dev, res); |
| 760 | if (IS_ERR(ipctl->base)) |
| 761 | return PTR_ERR(ipctl->base); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 762 | |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 763 | if (of_property_read_bool(dev_np, "fsl,input-sel")) { |
| 764 | np = of_parse_phandle(dev_np, "fsl,input-sel", 0); |
Vladimir Zapolskiy | 9a4f424 | 2016-03-09 02:45:36 +0200 | [diff] [blame] | 765 | if (!np) { |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 766 | dev_err(&pdev->dev, "iomuxc fsl,input-sel property not found\n"); |
| 767 | return -EINVAL; |
| 768 | } |
Vladimir Zapolskiy | 9a4f424 | 2016-03-09 02:45:36 +0200 | [diff] [blame] | 769 | |
| 770 | ipctl->input_sel_base = of_iomap(np, 0); |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 771 | of_node_put(np); |
Vladimir Zapolskiy | 9a4f424 | 2016-03-09 02:45:36 +0200 | [diff] [blame] | 772 | if (!ipctl->input_sel_base) { |
| 773 | dev_err(&pdev->dev, |
| 774 | "iomuxc input select base address not found\n"); |
| 775 | return -ENOMEM; |
| 776 | } |
Adrian Alonso | 26d8cde | 2015-09-25 16:06:00 -0500 | [diff] [blame] | 777 | } |
| 778 | |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 779 | imx_pinctrl_desc.name = dev_name(&pdev->dev); |
| 780 | imx_pinctrl_desc.pins = info->pins; |
| 781 | imx_pinctrl_desc.npins = info->npins; |
| 782 | |
| 783 | ret = imx_pinctrl_probe_dt(pdev, info); |
| 784 | if (ret) { |
| 785 | dev_err(&pdev->dev, "fail to probe dt properties\n"); |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | ipctl->info = info; |
| 790 | ipctl->dev = info->dev; |
| 791 | platform_set_drvdata(pdev, ipctl); |
Laxman Dewangan | a4b0f45 | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 792 | ipctl->pctl = devm_pinctrl_register(&pdev->dev, &imx_pinctrl_desc, ipctl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 793 | if (IS_ERR(ipctl->pctl)) { |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 794 | dev_err(&pdev->dev, "could not register IMX pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 795 | return PTR_ERR(ipctl->pctl); |
Dong Aisheng | ae75ff8 | 2012-04-27 20:26:16 +0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | dev_info(&pdev->dev, "initialized IMX pinctrl driver\n"); |
| 799 | |
| 800 | return 0; |
| 801 | } |