Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Pin Function Controller pinmux support. |
| 3 | * |
| 4 | * Copyright (C) 2012 Paul Mundt |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
Paul Mundt | 5440711 | 2012-07-20 16:18:21 +0900 | [diff] [blame] | 10 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 11 | #define DRV_NAME "sh-pfc" |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 12 | |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 13 | #include <linux/device.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 14 | #include <linux/err.h> |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 17 | #include <linux/of.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 18 | #include <linux/pinctrl/consumer.h> |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 19 | #include <linux/pinctrl/machine.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 20 | #include <linux/pinctrl/pinconf.h> |
| 21 | #include <linux/pinctrl/pinconf-generic.h> |
| 22 | #include <linux/pinctrl/pinctrl.h> |
| 23 | #include <linux/pinctrl/pinmux.h> |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 26 | |
Laurent Pinchart | f916513 | 2012-12-15 23:50:44 +0100 | [diff] [blame] | 27 | #include "core.h" |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 28 | #include "../core.h" |
| 29 | #include "../pinconf.h" |
Laurent Pinchart | f916513 | 2012-12-15 23:50:44 +0100 | [diff] [blame] | 30 | |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 31 | struct sh_pfc_pin_config { |
| 32 | u32 type; |
| 33 | }; |
| 34 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 35 | struct sh_pfc_pinctrl { |
| 36 | struct pinctrl_dev *pctl; |
Laurent Pinchart | dcc427e | 2013-02-16 16:38:30 +0100 | [diff] [blame] | 37 | struct pinctrl_desc pctl_desc; |
Laurent Pinchart | dcc427e | 2013-02-16 16:38:30 +0100 | [diff] [blame] | 38 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 39 | struct sh_pfc *pfc; |
| 40 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 41 | struct pinctrl_pin_desc *pins; |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 42 | struct sh_pfc_pin_config *configs; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 43 | }; |
| 44 | |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 45 | static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 46 | { |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 47 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 48 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 49 | return pmx->pfc->info->nr_groups; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 50 | } |
| 51 | |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 52 | static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 53 | unsigned selector) |
| 54 | { |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 55 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 56 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 57 | return pmx->pfc->info->groups[selector].name; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 58 | } |
| 59 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 60 | static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 61 | const unsigned **pins, unsigned *num_pins) |
| 62 | { |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 63 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 64 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 65 | *pins = pmx->pfc->info->groups[selector].pins; |
| 66 | *num_pins = pmx->pfc->info->groups[selector].nr_pins; |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 67 | |
| 68 | return 0; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 71 | static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
| 72 | unsigned offset) |
| 73 | { |
| 74 | seq_printf(s, "%s", DRV_NAME); |
| 75 | } |
| 76 | |
Laurent Pinchart | 3a8d63d | 2013-06-19 13:26:02 +0200 | [diff] [blame] | 77 | #ifdef CONFIG_OF |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 78 | static int sh_pfc_map_add_config(struct pinctrl_map *map, |
| 79 | const char *group_or_pin, |
| 80 | enum pinctrl_map_type type, |
| 81 | unsigned long *configs, |
| 82 | unsigned int num_configs) |
| 83 | { |
| 84 | unsigned long *cfgs; |
| 85 | |
| 86 | cfgs = kmemdup(configs, num_configs * sizeof(*cfgs), |
| 87 | GFP_KERNEL); |
| 88 | if (cfgs == NULL) |
| 89 | return -ENOMEM; |
| 90 | |
| 91 | map->type = type; |
| 92 | map->data.configs.group_or_pin = group_or_pin; |
| 93 | map->data.configs.configs = cfgs; |
| 94 | map->data.configs.num_configs = num_configs; |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 99 | static int sh_pfc_dt_subnode_to_map(struct device *dev, struct device_node *np, |
| 100 | struct pinctrl_map **map, |
| 101 | unsigned int *num_maps, unsigned int *index) |
| 102 | { |
| 103 | struct pinctrl_map *maps = *map; |
| 104 | unsigned int nmaps = *num_maps; |
| 105 | unsigned int idx = *index; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 106 | unsigned int num_configs; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 107 | const char *function = NULL; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 108 | unsigned long *configs; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 109 | struct property *prop; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 110 | unsigned int num_groups; |
| 111 | unsigned int num_pins; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 112 | const char *group; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 113 | const char *pin; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 114 | int ret; |
| 115 | |
| 116 | /* Parse the function and configuration properties. At least a function |
| 117 | * or one configuration must be specified. |
| 118 | */ |
| 119 | ret = of_property_read_string(np, "renesas,function", &function); |
| 120 | if (ret < 0 && ret != -EINVAL) { |
| 121 | dev_err(dev, "Invalid function in DT\n"); |
| 122 | return ret; |
| 123 | } |
| 124 | |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 125 | ret = pinconf_generic_parse_dt_config(np, &configs, &num_configs); |
| 126 | if (ret < 0) |
| 127 | return ret; |
| 128 | |
| 129 | if (!function && num_configs == 0) { |
| 130 | dev_err(dev, |
| 131 | "DT node must contain at least a function or config\n"); |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 132 | goto done; |
| 133 | } |
| 134 | |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 135 | /* Count the number of pins and groups and reallocate mappings. */ |
| 136 | ret = of_property_count_strings(np, "renesas,pins"); |
| 137 | if (ret == -EINVAL) { |
| 138 | num_pins = 0; |
| 139 | } else if (ret < 0) { |
| 140 | dev_err(dev, "Invalid pins list in DT\n"); |
| 141 | goto done; |
| 142 | } else { |
| 143 | num_pins = ret; |
| 144 | } |
| 145 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 146 | ret = of_property_count_strings(np, "renesas,groups"); |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 147 | if (ret == -EINVAL) { |
| 148 | num_groups = 0; |
| 149 | } else if (ret < 0) { |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 150 | dev_err(dev, "Invalid pin groups list in DT\n"); |
| 151 | goto done; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 152 | } else { |
| 153 | num_groups = ret; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 156 | if (!num_pins && !num_groups) { |
| 157 | dev_err(dev, "No pin or group provided in DT node\n"); |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 158 | ret = -ENODEV; |
| 159 | goto done; |
| 160 | } |
| 161 | |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 162 | if (function) |
| 163 | nmaps += num_groups; |
| 164 | if (configs) |
| 165 | nmaps += num_pins + num_groups; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 166 | |
| 167 | maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL); |
| 168 | if (maps == NULL) { |
| 169 | ret = -ENOMEM; |
| 170 | goto done; |
| 171 | } |
| 172 | |
| 173 | *map = maps; |
| 174 | *num_maps = nmaps; |
| 175 | |
| 176 | /* Iterate over pins and groups and create the mappings. */ |
| 177 | of_property_for_each_string(np, "renesas,groups", prop, group) { |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 178 | if (function) { |
| 179 | maps[idx].type = PIN_MAP_TYPE_MUX_GROUP; |
| 180 | maps[idx].data.mux.group = group; |
| 181 | maps[idx].data.mux.function = function; |
| 182 | idx++; |
| 183 | } |
| 184 | |
| 185 | if (configs) { |
| 186 | ret = sh_pfc_map_add_config(&maps[idx], group, |
| 187 | PIN_MAP_TYPE_CONFIGS_GROUP, |
| 188 | configs, num_configs); |
| 189 | if (ret < 0) |
| 190 | goto done; |
| 191 | |
| 192 | idx++; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (!configs) { |
| 197 | ret = 0; |
| 198 | goto done; |
| 199 | } |
| 200 | |
| 201 | of_property_for_each_string(np, "renesas,pins", prop, pin) { |
| 202 | ret = sh_pfc_map_add_config(&maps[idx], pin, |
| 203 | PIN_MAP_TYPE_CONFIGS_PIN, |
| 204 | configs, num_configs); |
| 205 | if (ret < 0) |
| 206 | goto done; |
| 207 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 208 | idx++; |
| 209 | } |
| 210 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 211 | done: |
| 212 | *index = idx; |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 213 | kfree(configs); |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev, |
| 218 | struct pinctrl_map *map, unsigned num_maps) |
| 219 | { |
Laurent Pinchart | 12f3ad8 | 2013-06-17 20:50:03 +0200 | [diff] [blame] | 220 | unsigned int i; |
| 221 | |
| 222 | if (map == NULL) |
| 223 | return; |
| 224 | |
| 225 | for (i = 0; i < num_maps; ++i) { |
| 226 | if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP || |
| 227 | map[i].type == PIN_MAP_TYPE_CONFIGS_PIN) |
| 228 | kfree(map[i].data.configs.configs); |
| 229 | } |
| 230 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 231 | kfree(map); |
| 232 | } |
| 233 | |
| 234 | static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 235 | struct device_node *np, |
| 236 | struct pinctrl_map **map, unsigned *num_maps) |
| 237 | { |
| 238 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 239 | struct device *dev = pmx->pfc->dev; |
| 240 | struct device_node *child; |
| 241 | unsigned int index; |
| 242 | int ret; |
| 243 | |
| 244 | *map = NULL; |
| 245 | *num_maps = 0; |
| 246 | index = 0; |
| 247 | |
| 248 | for_each_child_of_node(np, child) { |
| 249 | ret = sh_pfc_dt_subnode_to_map(dev, child, map, num_maps, |
| 250 | &index); |
| 251 | if (ret < 0) |
| 252 | goto done; |
| 253 | } |
| 254 | |
| 255 | /* If no mapping has been found in child nodes try the config node. */ |
| 256 | if (*num_maps == 0) { |
| 257 | ret = sh_pfc_dt_subnode_to_map(dev, np, map, num_maps, &index); |
| 258 | if (ret < 0) |
| 259 | goto done; |
| 260 | } |
| 261 | |
| 262 | if (*num_maps) |
| 263 | return 0; |
| 264 | |
| 265 | dev_err(dev, "no mapping found in node %s\n", np->full_name); |
| 266 | ret = -EINVAL; |
| 267 | |
| 268 | done: |
| 269 | if (ret < 0) |
| 270 | sh_pfc_dt_free_map(pctldev, *map, *num_maps); |
| 271 | |
| 272 | return ret; |
| 273 | } |
Laurent Pinchart | 3a8d63d | 2013-06-19 13:26:02 +0200 | [diff] [blame] | 274 | #endif /* CONFIG_OF */ |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 275 | |
Laurent Pinchart | fe330ce | 2013-02-15 16:04:47 +0100 | [diff] [blame] | 276 | static const struct pinctrl_ops sh_pfc_pinctrl_ops = { |
Paul Mundt | e3f805e | 2012-07-17 15:48:18 +0900 | [diff] [blame] | 277 | .get_groups_count = sh_pfc_get_groups_count, |
| 278 | .get_group_name = sh_pfc_get_group_name, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 279 | .get_group_pins = sh_pfc_get_group_pins, |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 280 | .pin_dbg_show = sh_pfc_pin_dbg_show, |
Laurent Pinchart | 3a8d63d | 2013-06-19 13:26:02 +0200 | [diff] [blame] | 281 | #ifdef CONFIG_OF |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 282 | .dt_node_to_map = sh_pfc_dt_node_to_map, |
| 283 | .dt_free_map = sh_pfc_dt_free_map, |
Laurent Pinchart | 3a8d63d | 2013-06-19 13:26:02 +0200 | [diff] [blame] | 284 | #endif |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 285 | }; |
| 286 | |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 287 | static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev) |
| 288 | { |
| 289 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 290 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 291 | return pmx->pfc->info->nr_functions; |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev, |
| 295 | unsigned selector) |
| 296 | { |
| 297 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 298 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 299 | return pmx->pfc->info->functions[selector].name; |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 300 | } |
| 301 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 302 | static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev, |
| 303 | unsigned selector, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 304 | const char * const **groups, |
| 305 | unsigned * const num_groups) |
| 306 | { |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 307 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 308 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 309 | *groups = pmx->pfc->info->functions[selector].groups; |
| 310 | *num_groups = pmx->pfc->info->functions[selector].nr_groups; |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 311 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame^] | 315 | static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector, |
| 316 | unsigned group) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 317 | { |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 318 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 319 | struct sh_pfc *pfc = pmx->pfc; |
| 320 | const struct sh_pfc_pin_group *grp = &pfc->info->groups[group]; |
| 321 | unsigned long flags; |
| 322 | unsigned int i; |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 323 | int ret = 0; |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 324 | |
| 325 | spin_lock_irqsave(&pfc->lock, flags); |
| 326 | |
| 327 | for (i = 0; i < grp->nr_pins; ++i) { |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 328 | int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]); |
| 329 | struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; |
| 330 | |
| 331 | if (cfg->type != PINMUX_TYPE_NONE) { |
| 332 | ret = -EBUSY; |
| 333 | goto done; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | for (i = 0; i < grp->nr_pins; ++i) { |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 338 | ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION); |
| 339 | if (ret < 0) |
| 340 | break; |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 343 | done: |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 344 | spin_unlock_irqrestore(&pfc->lock, flags); |
| 345 | return ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 346 | } |
| 347 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 348 | static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 349 | struct pinctrl_gpio_range *range, |
| 350 | unsigned offset) |
| 351 | { |
| 352 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 353 | struct sh_pfc *pfc = pmx->pfc; |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 354 | int idx = sh_pfc_get_pin_index(pfc, offset); |
| 355 | struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 356 | unsigned long flags; |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 357 | int ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 358 | |
| 359 | spin_lock_irqsave(&pfc->lock, flags); |
| 360 | |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 361 | if (cfg->type != PINMUX_TYPE_NONE) { |
Laurent Pinchart | 9a643c9 | 2013-03-10 18:00:02 +0100 | [diff] [blame] | 362 | dev_err(pfc->dev, |
| 363 | "Pin %u is busy, can't configure it as GPIO.\n", |
| 364 | offset); |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 365 | ret = -EBUSY; |
| 366 | goto done; |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 367 | } |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 368 | |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 369 | if (!pfc->gpio) { |
| 370 | /* If GPIOs are handled externally the pin mux type need to be |
| 371 | * set to GPIO here. |
| 372 | */ |
| 373 | const struct sh_pfc_pin *pin = &pfc->info->pins[idx]; |
| 374 | |
| 375 | ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO); |
| 376 | if (ret < 0) |
| 377 | goto done; |
| 378 | } |
| 379 | |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 380 | cfg->type = PINMUX_TYPE_GPIO; |
| 381 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 382 | ret = 0; |
| 383 | |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 384 | done: |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 385 | spin_unlock_irqrestore(&pfc->lock, flags); |
| 386 | |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, |
| 391 | struct pinctrl_gpio_range *range, |
| 392 | unsigned offset) |
| 393 | { |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 394 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 395 | struct sh_pfc *pfc = pmx->pfc; |
| 396 | int idx = sh_pfc_get_pin_index(pfc, offset); |
| 397 | struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; |
| 398 | unsigned long flags; |
| 399 | |
| 400 | spin_lock_irqsave(&pfc->lock, flags); |
| 401 | cfg->type = PINMUX_TYPE_NONE; |
| 402 | spin_unlock_irqrestore(&pfc->lock, flags); |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 406 | struct pinctrl_gpio_range *range, |
| 407 | unsigned offset, bool input) |
| 408 | { |
| 409 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 410 | struct sh_pfc *pfc = pmx->pfc; |
| 411 | int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT; |
| 412 | int idx = sh_pfc_get_pin_index(pfc, offset); |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 413 | const struct sh_pfc_pin *pin = &pfc->info->pins[idx]; |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 414 | struct sh_pfc_pin_config *cfg = &pmx->configs[idx]; |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 415 | unsigned long flags; |
Laurent Pinchart | 6dc9b45 | 2013-03-13 18:18:30 +0100 | [diff] [blame] | 416 | unsigned int dir; |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 417 | int ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 418 | |
Laurent Pinchart | 6dc9b45 | 2013-03-13 18:18:30 +0100 | [diff] [blame] | 419 | /* Check if the requested direction is supported by the pin. Not all SoC |
| 420 | * provide pin config data, so perform the check conditionally. |
| 421 | */ |
| 422 | if (pin->configs) { |
| 423 | dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT; |
| 424 | if (!(pin->configs & dir)) |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 428 | spin_lock_irqsave(&pfc->lock, flags); |
| 429 | |
Laurent Pinchart | 9fddc4a | 2013-03-10 17:25:29 +0100 | [diff] [blame] | 430 | ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type); |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 431 | if (ret < 0) |
| 432 | goto done; |
| 433 | |
| 434 | cfg->type = new_type; |
| 435 | |
| 436 | done: |
| 437 | spin_unlock_irqrestore(&pfc->lock, flags); |
Laurent Pinchart | 0d00f00 | 2013-03-10 16:55:19 +0100 | [diff] [blame] | 438 | return ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 439 | } |
| 440 | |
Laurent Pinchart | fe330ce | 2013-02-15 16:04:47 +0100 | [diff] [blame] | 441 | static const struct pinmux_ops sh_pfc_pinmux_ops = { |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 442 | .get_functions_count = sh_pfc_get_functions_count, |
| 443 | .get_function_name = sh_pfc_get_function_name, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 444 | .get_function_groups = sh_pfc_get_function_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame^] | 445 | .set_mux = sh_pfc_func_set_mux, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 446 | .gpio_request_enable = sh_pfc_gpio_request_enable, |
| 447 | .gpio_disable_free = sh_pfc_gpio_disable_free, |
| 448 | .gpio_set_direction = sh_pfc_gpio_set_direction, |
| 449 | }; |
| 450 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 451 | /* Check whether the requested parameter is supported for a pin. */ |
| 452 | static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin, |
| 453 | enum pin_config_param param) |
| 454 | { |
| 455 | int idx = sh_pfc_get_pin_index(pfc, _pin); |
| 456 | const struct sh_pfc_pin *pin = &pfc->info->pins[idx]; |
| 457 | |
| 458 | switch (param) { |
| 459 | case PIN_CONFIG_BIAS_DISABLE: |
| 460 | return true; |
| 461 | |
| 462 | case PIN_CONFIG_BIAS_PULL_UP: |
| 463 | return pin->configs & SH_PFC_PIN_CFG_PULL_UP; |
| 464 | |
| 465 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 466 | return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN; |
| 467 | |
| 468 | default: |
| 469 | return false; |
| 470 | } |
| 471 | } |
| 472 | |
Laurent Pinchart | 934cb02 | 2013-02-14 22:35:09 +0100 | [diff] [blame] | 473 | static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 474 | unsigned long *config) |
| 475 | { |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 476 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 477 | struct sh_pfc *pfc = pmx->pfc; |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 478 | enum pin_config_param param = pinconf_to_config_param(*config); |
| 479 | unsigned long flags; |
| 480 | unsigned int bias; |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 481 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 482 | if (!sh_pfc_pinconf_validate(pfc, _pin, param)) |
| 483 | return -ENOTSUPP; |
| 484 | |
| 485 | switch (param) { |
| 486 | case PIN_CONFIG_BIAS_DISABLE: |
| 487 | case PIN_CONFIG_BIAS_PULL_UP: |
| 488 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 489 | if (!pfc->info->ops || !pfc->info->ops->get_bias) |
| 490 | return -ENOTSUPP; |
| 491 | |
| 492 | spin_lock_irqsave(&pfc->lock, flags); |
| 493 | bias = pfc->info->ops->get_bias(pfc, _pin); |
| 494 | spin_unlock_irqrestore(&pfc->lock, flags); |
| 495 | |
| 496 | if (bias != param) |
| 497 | return -EINVAL; |
| 498 | |
| 499 | *config = 0; |
| 500 | break; |
| 501 | |
| 502 | default: |
| 503 | return -ENOTSUPP; |
| 504 | } |
Paul Mundt | d93a891 | 2012-07-11 17:17:10 +0900 | [diff] [blame] | 505 | |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 506 | return 0; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 507 | } |
| 508 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 509 | static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 510 | unsigned long *configs, unsigned num_configs) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 511 | { |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 512 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 513 | struct sh_pfc *pfc = pmx->pfc; |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 514 | enum pin_config_param param; |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 515 | unsigned long flags; |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 516 | unsigned int i; |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 517 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 518 | for (i = 0; i < num_configs; i++) { |
| 519 | param = pinconf_to_config_param(configs[i]); |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 520 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 521 | if (!sh_pfc_pinconf_validate(pfc, _pin, param)) |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 522 | return -ENOTSUPP; |
| 523 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 524 | switch (param) { |
| 525 | case PIN_CONFIG_BIAS_PULL_UP: |
| 526 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 527 | case PIN_CONFIG_BIAS_DISABLE: |
| 528 | if (!pfc->info->ops || !pfc->info->ops->set_bias) |
| 529 | return -ENOTSUPP; |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 530 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 531 | spin_lock_irqsave(&pfc->lock, flags); |
| 532 | pfc->info->ops->set_bias(pfc, _pin, param); |
| 533 | spin_unlock_irqrestore(&pfc->lock, flags); |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 534 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 535 | break; |
| 536 | |
| 537 | default: |
| 538 | return -ENOTSUPP; |
| 539 | } |
| 540 | } /* for each config */ |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 541 | |
| 542 | return 0; |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 543 | } |
| 544 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 545 | static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 546 | unsigned long *configs, |
| 547 | unsigned num_configs) |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 548 | { |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 549 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
| 550 | const unsigned int *pins; |
| 551 | unsigned int num_pins; |
| 552 | unsigned int i; |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 553 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 554 | pins = pmx->pfc->info->groups[group].pins; |
| 555 | num_pins = pmx->pfc->info->groups[group].nr_pins; |
Paul Mundt | fdd85ec | 2012-07-20 16:39:09 +0900 | [diff] [blame] | 556 | |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 557 | for (i = 0; i < num_pins; ++i) |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 558 | sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs); |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 559 | |
| 560 | return 0; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 561 | } |
| 562 | |
Laurent Pinchart | fe330ce | 2013-02-15 16:04:47 +0100 | [diff] [blame] | 563 | static const struct pinconf_ops sh_pfc_pinconf_ops = { |
Laurent Pinchart | c58d9c1 | 2013-03-10 16:44:02 +0100 | [diff] [blame] | 564 | .is_generic = true, |
| 565 | .pin_config_get = sh_pfc_pinconf_get, |
| 566 | .pin_config_set = sh_pfc_pinconf_set, |
| 567 | .pin_config_group_set = sh_pfc_pinconf_group_set, |
| 568 | .pin_config_config_dbg_show = pinconf_generic_dump_config, |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 569 | }; |
| 570 | |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 571 | /* PFC ranges -> pinctrl pin descs */ |
| 572 | static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 573 | { |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 574 | unsigned int i; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 575 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 576 | /* Allocate and initialize the pins and configs arrays. */ |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 577 | pmx->pins = devm_kzalloc(pfc->dev, |
| 578 | sizeof(*pmx->pins) * pfc->info->nr_pins, |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 579 | GFP_KERNEL); |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 580 | if (unlikely(!pmx->pins)) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 581 | return -ENOMEM; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 582 | |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 583 | pmx->configs = devm_kzalloc(pfc->dev, |
| 584 | sizeof(*pmx->configs) * pfc->info->nr_pins, |
| 585 | GFP_KERNEL); |
| 586 | if (unlikely(!pmx->configs)) |
| 587 | return -ENOMEM; |
| 588 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 589 | for (i = 0; i < pfc->info->nr_pins; ++i) { |
| 590 | const struct sh_pfc_pin *info = &pfc->info->pins[i]; |
| 591 | struct sh_pfc_pin_config *cfg = &pmx->configs[i]; |
| 592 | struct pinctrl_pin_desc *pin = &pmx->pins[i]; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 593 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 594 | /* If the pin number is equal to -1 all pins are considered */ |
| 595 | pin->number = info->pin != (u16)-1 ? info->pin : i; |
| 596 | pin->name = info->name; |
| 597 | cfg->type = PINMUX_TYPE_NONE; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 598 | } |
| 599 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 600 | return 0; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 601 | } |
| 602 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 603 | int sh_pfc_register_pinctrl(struct sh_pfc *pfc) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 604 | { |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 605 | struct sh_pfc_pinctrl *pmx; |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 606 | int ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 607 | |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 608 | pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL); |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 609 | if (unlikely(!pmx)) |
| 610 | return -ENOMEM; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 611 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 612 | pmx->pfc = pfc; |
| 613 | pfc->pinctrl = pmx; |
| 614 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 615 | ret = sh_pfc_map_pins(pfc, pmx); |
| 616 | if (ret < 0) |
| 617 | return ret; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 618 | |
Laurent Pinchart | dcc427e | 2013-02-16 16:38:30 +0100 | [diff] [blame] | 619 | pmx->pctl_desc.name = DRV_NAME; |
| 620 | pmx->pctl_desc.owner = THIS_MODULE; |
| 621 | pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops; |
| 622 | pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; |
| 623 | pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 624 | pmx->pctl_desc.pins = pmx->pins; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 625 | pmx->pctl_desc.npins = pfc->info->nr_pins; |
Laurent Pinchart | dcc427e | 2013-02-16 16:38:30 +0100 | [diff] [blame] | 626 | |
| 627 | pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); |
Wei Yongjun | fd9d05b | 2013-03-11 22:08:12 +0800 | [diff] [blame] | 628 | if (pmx->pctl == NULL) |
| 629 | return -EINVAL; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 630 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 631 | return 0; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 632 | } |
| 633 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 634 | int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 635 | { |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 636 | struct sh_pfc_pinctrl *pmx = pfc->pinctrl; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 637 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 638 | pinctrl_unregister(pmx->pctl); |
| 639 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 640 | pfc->pinctrl = NULL; |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 641 | return 0; |
| 642 | } |