Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1 | /* |
| 2 | * pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's. |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com |
| 6 | * Copyright (c) 2012 Linaro Ltd |
| 7 | * http://www.linaro.org |
| 8 | * |
| 9 | * Author: Thomas Abraham <thomas.ab@samsung.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This driver implements the Samsung pinctrl driver. It supports setting up of |
| 17 | * pinmux and pinconf configurations. The gpiolib interface is also included. |
| 18 | * External interrupt (gpio and wakeup) support are not included in this driver |
| 19 | * but provides extensions to which platform specific implementation of the gpio |
| 20 | * and wakeup interrupts can be hooked to. |
| 21 | */ |
| 22 | |
Paul Gortmaker | 8208b28 | 2017-05-22 16:56:46 -0400 | [diff] [blame] | 23 | #include <linux/init.h> |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/gpio.h> |
Tomasz Figa | a19fe2d | 2012-10-11 10:11:20 +0200 | [diff] [blame] | 29 | #include <linux/irqdomain.h> |
Marek Szyprowski | 9abc2b9 | 2017-01-26 10:29:23 +0100 | [diff] [blame] | 30 | #include <linux/of_device.h> |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 31 | #include <linux/spinlock.h> |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 32 | |
Krzysztof Kozlowski | 4460dc2 | 2017-06-15 17:06:28 +0200 | [diff] [blame^] | 33 | #include <dt-bindings/pinctrl/samsung.h> |
| 34 | |
Sachin Kamat | ebe629a | 2014-07-10 17:33:27 +0530 | [diff] [blame] | 35 | #include "../core.h" |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 36 | #include "pinctrl-samsung.h" |
| 37 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 38 | /* maximum number of the memory resources */ |
| 39 | #define SAMSUNG_PINCTRL_NUM_RESOURCES 2 |
| 40 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 41 | /* list of all possible config options supported */ |
Axel Lin | d5fd5da | 2012-12-10 09:54:03 +0900 | [diff] [blame] | 42 | static struct pin_config { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 43 | const char *property; |
| 44 | enum pincfg_type param; |
| 45 | } cfg_params[] = { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 46 | { "samsung,pin-pud", PINCFG_TYPE_PUD }, |
| 47 | { "samsung,pin-drv", PINCFG_TYPE_DRV }, |
| 48 | { "samsung,pin-con-pdn", PINCFG_TYPE_CON_PDN }, |
| 49 | { "samsung,pin-pud-pdn", PINCFG_TYPE_PUD_PDN }, |
Tomasz Figa | 2700bc0 | 2014-07-02 17:41:04 +0200 | [diff] [blame] | 50 | { "samsung,pin-val", PINCFG_TYPE_DAT }, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 51 | }; |
| 52 | |
Sachin Kamat | 6fb6f1ba | 2012-11-24 11:20:51 +0900 | [diff] [blame] | 53 | static unsigned int pin_base; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 54 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 55 | static int samsung_get_group_count(struct pinctrl_dev *pctldev) |
| 56 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 57 | struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 58 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 59 | return pmx->nr_groups; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 60 | } |
| 61 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 62 | static const char *samsung_get_group_name(struct pinctrl_dev *pctldev, |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 63 | unsigned group) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 64 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 65 | struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 66 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 67 | return pmx->pin_groups[group].name; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 68 | } |
| 69 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 70 | static int samsung_get_group_pins(struct pinctrl_dev *pctldev, |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 71 | unsigned group, |
| 72 | const unsigned **pins, |
| 73 | unsigned *num_pins) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 74 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 75 | struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 76 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 77 | *pins = pmx->pin_groups[group].pins; |
| 78 | *num_pins = pmx->pin_groups[group].num_pins; |
| 79 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 83 | static int reserve_map(struct device *dev, struct pinctrl_map **map, |
| 84 | unsigned *reserved_maps, unsigned *num_maps, |
| 85 | unsigned reserve) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 86 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 87 | unsigned old_num = *reserved_maps; |
| 88 | unsigned new_num = *num_maps + reserve; |
| 89 | struct pinctrl_map *new_map; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 90 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 91 | if (old_num >= new_num) |
| 92 | return 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 93 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 94 | new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 95 | if (!new_map) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 96 | return -ENOMEM; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 97 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 98 | memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map)); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 99 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 100 | *map = new_map; |
| 101 | *reserved_maps = new_num; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 102 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 103 | return 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 104 | } |
| 105 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 106 | static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps, |
| 107 | unsigned *num_maps, const char *group, |
| 108 | const char *function) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 109 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 110 | if (WARN_ON(*num_maps == *reserved_maps)) |
| 111 | return -ENOSPC; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 112 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 113 | (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP; |
| 114 | (*map)[*num_maps].data.mux.group = group; |
| 115 | (*map)[*num_maps].data.mux.function = function; |
| 116 | (*num_maps)++; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static int add_map_configs(struct device *dev, struct pinctrl_map **map, |
| 122 | unsigned *reserved_maps, unsigned *num_maps, |
| 123 | const char *group, unsigned long *configs, |
| 124 | unsigned num_configs) |
| 125 | { |
| 126 | unsigned long *dup_configs; |
| 127 | |
| 128 | if (WARN_ON(*num_maps == *reserved_maps)) |
| 129 | return -ENOSPC; |
| 130 | |
| 131 | dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs), |
| 132 | GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 133 | if (!dup_configs) |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 134 | return -ENOMEM; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 135 | |
| 136 | (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP; |
| 137 | (*map)[*num_maps].data.configs.group_or_pin = group; |
| 138 | (*map)[*num_maps].data.configs.configs = dup_configs; |
| 139 | (*map)[*num_maps].data.configs.num_configs = num_configs; |
| 140 | (*num_maps)++; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int add_config(struct device *dev, unsigned long **configs, |
| 146 | unsigned *num_configs, unsigned long config) |
| 147 | { |
| 148 | unsigned old_num = *num_configs; |
| 149 | unsigned new_num = old_num + 1; |
| 150 | unsigned long *new_configs; |
| 151 | |
| 152 | new_configs = krealloc(*configs, sizeof(*new_configs) * new_num, |
| 153 | GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 154 | if (!new_configs) |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 155 | return -ENOMEM; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 156 | |
| 157 | new_configs[old_num] = config; |
| 158 | |
| 159 | *configs = new_configs; |
| 160 | *num_configs = new_num; |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static void samsung_dt_free_map(struct pinctrl_dev *pctldev, |
| 166 | struct pinctrl_map *map, |
| 167 | unsigned num_maps) |
| 168 | { |
| 169 | int i; |
| 170 | |
| 171 | for (i = 0; i < num_maps; i++) |
| 172 | if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) |
| 173 | kfree(map[i].data.configs.configs); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 174 | |
| 175 | kfree(map); |
| 176 | } |
| 177 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 178 | static int samsung_dt_subnode_to_map(struct samsung_pinctrl_drv_data *drvdata, |
| 179 | struct device *dev, |
| 180 | struct device_node *np, |
| 181 | struct pinctrl_map **map, |
| 182 | unsigned *reserved_maps, |
| 183 | unsigned *num_maps) |
| 184 | { |
| 185 | int ret, i; |
| 186 | u32 val; |
| 187 | unsigned long config; |
| 188 | unsigned long *configs = NULL; |
| 189 | unsigned num_configs = 0; |
| 190 | unsigned reserve; |
| 191 | struct property *prop; |
| 192 | const char *group; |
| 193 | bool has_func = false; |
| 194 | |
| 195 | ret = of_property_read_u32(np, "samsung,pin-function", &val); |
| 196 | if (!ret) |
| 197 | has_func = true; |
| 198 | |
| 199 | for (i = 0; i < ARRAY_SIZE(cfg_params); i++) { |
| 200 | ret = of_property_read_u32(np, cfg_params[i].property, &val); |
| 201 | if (!ret) { |
| 202 | config = PINCFG_PACK(cfg_params[i].param, val); |
| 203 | ret = add_config(dev, &configs, &num_configs, config); |
| 204 | if (ret < 0) |
| 205 | goto exit; |
| 206 | /* EINVAL=missing, which is fine since it's optional */ |
| 207 | } else if (ret != -EINVAL) { |
| 208 | dev_err(dev, "could not parse property %s\n", |
| 209 | cfg_params[i].property); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | reserve = 0; |
| 214 | if (has_func) |
| 215 | reserve++; |
| 216 | if (num_configs) |
| 217 | reserve++; |
| 218 | ret = of_property_count_strings(np, "samsung,pins"); |
| 219 | if (ret < 0) { |
| 220 | dev_err(dev, "could not parse property samsung,pins\n"); |
| 221 | goto exit; |
| 222 | } |
| 223 | reserve *= ret; |
| 224 | |
| 225 | ret = reserve_map(dev, map, reserved_maps, num_maps, reserve); |
| 226 | if (ret < 0) |
| 227 | goto exit; |
| 228 | |
| 229 | of_property_for_each_string(np, "samsung,pins", prop, group) { |
| 230 | if (has_func) { |
| 231 | ret = add_map_mux(map, reserved_maps, |
| 232 | num_maps, group, np->full_name); |
| 233 | if (ret < 0) |
| 234 | goto exit; |
| 235 | } |
| 236 | |
| 237 | if (num_configs) { |
| 238 | ret = add_map_configs(dev, map, reserved_maps, |
| 239 | num_maps, group, configs, |
| 240 | num_configs); |
| 241 | if (ret < 0) |
| 242 | goto exit; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | ret = 0; |
| 247 | |
| 248 | exit: |
| 249 | kfree(configs); |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 254 | struct device_node *np_config, |
| 255 | struct pinctrl_map **map, |
| 256 | unsigned *num_maps) |
| 257 | { |
| 258 | struct samsung_pinctrl_drv_data *drvdata; |
| 259 | unsigned reserved_maps; |
| 260 | struct device_node *np; |
| 261 | int ret; |
| 262 | |
| 263 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 264 | |
| 265 | reserved_maps = 0; |
| 266 | *map = NULL; |
| 267 | *num_maps = 0; |
| 268 | |
| 269 | if (!of_get_child_count(np_config)) |
| 270 | return samsung_dt_subnode_to_map(drvdata, pctldev->dev, |
| 271 | np_config, map, |
| 272 | &reserved_maps, |
| 273 | num_maps); |
| 274 | |
| 275 | for_each_child_of_node(np_config, np) { |
| 276 | ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map, |
| 277 | &reserved_maps, num_maps); |
| 278 | if (ret < 0) { |
| 279 | samsung_dt_free_map(pctldev, *map, *num_maps); |
| 280 | return ret; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 287 | /* list of pinctrl callbacks for the pinctrl core */ |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 288 | static const struct pinctrl_ops samsung_pctrl_ops = { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 289 | .get_groups_count = samsung_get_group_count, |
| 290 | .get_group_name = samsung_get_group_name, |
| 291 | .get_group_pins = samsung_get_group_pins, |
| 292 | .dt_node_to_map = samsung_dt_node_to_map, |
| 293 | .dt_free_map = samsung_dt_free_map, |
| 294 | }; |
| 295 | |
| 296 | /* check if the selector is a valid pin function selector */ |
| 297 | static int samsung_get_functions_count(struct pinctrl_dev *pctldev) |
| 298 | { |
| 299 | struct samsung_pinctrl_drv_data *drvdata; |
| 300 | |
| 301 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 302 | return drvdata->nr_functions; |
| 303 | } |
| 304 | |
| 305 | /* return the name of the pin function specified */ |
| 306 | static const char *samsung_pinmux_get_fname(struct pinctrl_dev *pctldev, |
| 307 | unsigned selector) |
| 308 | { |
| 309 | struct samsung_pinctrl_drv_data *drvdata; |
| 310 | |
| 311 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 312 | return drvdata->pmx_functions[selector].name; |
| 313 | } |
| 314 | |
| 315 | /* return the groups associated for the specified function selector */ |
| 316 | static int samsung_pinmux_get_groups(struct pinctrl_dev *pctldev, |
| 317 | unsigned selector, const char * const **groups, |
| 318 | unsigned * const num_groups) |
| 319 | { |
| 320 | struct samsung_pinctrl_drv_data *drvdata; |
| 321 | |
| 322 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 323 | *groups = drvdata->pmx_functions[selector].groups; |
| 324 | *num_groups = drvdata->pmx_functions[selector].num_groups; |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * given a pin number that is local to a pin controller, find out the pin bank |
| 330 | * and the register base of the pin bank. |
| 331 | */ |
Tomasz Figa | 62f14c0 | 2012-10-11 10:11:08 +0200 | [diff] [blame] | 332 | static void pin_to_reg_bank(struct samsung_pinctrl_drv_data *drvdata, |
| 333 | unsigned pin, void __iomem **reg, u32 *offset, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 334 | struct samsung_pin_bank **bank) |
| 335 | { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 336 | struct samsung_pin_bank *b; |
| 337 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 338 | b = drvdata->pin_banks; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 339 | |
| 340 | while ((pin >= b->pin_base) && |
| 341 | ((b->pin_base + b->nr_pins - 1) < pin)) |
| 342 | b++; |
| 343 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 344 | *reg = b->pctl_base + b->pctl_offset; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 345 | *offset = pin - b->pin_base; |
| 346 | if (bank) |
| 347 | *bank = b; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* enable or disable a pinmux function */ |
| 351 | static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector, |
Marek Szyprowski | 991efb0 | 2017-01-26 10:29:22 +0100 | [diff] [blame] | 352 | unsigned group) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 353 | { |
| 354 | struct samsung_pinctrl_drv_data *drvdata; |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 355 | const struct samsung_pin_bank_type *type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 356 | struct samsung_pin_bank *bank; |
| 357 | void __iomem *reg; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 358 | u32 mask, shift, data, pin_offset; |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 359 | unsigned long flags; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 360 | const struct samsung_pmx_func *func; |
| 361 | const struct samsung_pin_group *grp; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 362 | |
| 363 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 364 | func = &drvdata->pmx_functions[selector]; |
| 365 | grp = &drvdata->pin_groups[group]; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 366 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 367 | pin_to_reg_bank(drvdata, grp->pins[0] - drvdata->pin_base, |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 368 | ®, &pin_offset, &bank); |
| 369 | type = bank->type; |
| 370 | mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1; |
| 371 | shift = pin_offset * type->fld_width[PINCFG_TYPE_FUNC]; |
| 372 | if (shift >= 32) { |
| 373 | /* Some banks have two config registers */ |
| 374 | shift -= 32; |
| 375 | reg += 4; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 376 | } |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 377 | |
| 378 | spin_lock_irqsave(&bank->slock, flags); |
| 379 | |
| 380 | data = readl(reg + type->reg_offset[PINCFG_TYPE_FUNC]); |
| 381 | data &= ~(mask << shift); |
Marek Szyprowski | 991efb0 | 2017-01-26 10:29:22 +0100 | [diff] [blame] | 382 | data |= func->val << shift; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 383 | writel(data, reg + type->reg_offset[PINCFG_TYPE_FUNC]); |
| 384 | |
| 385 | spin_unlock_irqrestore(&bank->slock, flags); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /* enable a specified pinmux by writing to registers */ |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 389 | static int samsung_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 390 | unsigned selector, |
| 391 | unsigned group) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 392 | { |
Marek Szyprowski | 991efb0 | 2017-01-26 10:29:22 +0100 | [diff] [blame] | 393 | samsung_pinmux_setup(pctldev, selector, group); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 397 | /* list of pinmux callbacks for the pinmux vertical in pinctrl core */ |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 398 | static const struct pinmux_ops samsung_pinmux_ops = { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 399 | .get_functions_count = samsung_get_functions_count, |
| 400 | .get_function_name = samsung_pinmux_get_fname, |
| 401 | .get_function_groups = samsung_pinmux_get_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 402 | .set_mux = samsung_pinmux_set_mux, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | /* set or get the pin config settings for a specified pin */ |
| 406 | static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin, |
| 407 | unsigned long *config, bool set) |
| 408 | { |
| 409 | struct samsung_pinctrl_drv_data *drvdata; |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 410 | const struct samsung_pin_bank_type *type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 411 | struct samsung_pin_bank *bank; |
| 412 | void __iomem *reg_base; |
| 413 | enum pincfg_type cfg_type = PINCFG_UNPACK_TYPE(*config); |
| 414 | u32 data, width, pin_offset, mask, shift; |
| 415 | u32 cfg_value, cfg_reg; |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 416 | unsigned long flags; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 417 | |
| 418 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 419 | pin_to_reg_bank(drvdata, pin - drvdata->pin_base, ®_base, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 420 | &pin_offset, &bank); |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 421 | type = bank->type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 422 | |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 423 | if (cfg_type >= PINCFG_TYPE_NUM || !type->fld_width[cfg_type]) |
Tomasz Figa | 7c367d3 | 2012-10-11 10:11:07 +0200 | [diff] [blame] | 424 | return -EINVAL; |
| 425 | |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 426 | width = type->fld_width[cfg_type]; |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 427 | cfg_reg = type->reg_offset[cfg_type]; |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 428 | |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 429 | spin_lock_irqsave(&bank->slock, flags); |
| 430 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 431 | mask = (1 << width) - 1; |
| 432 | shift = pin_offset * width; |
| 433 | data = readl(reg_base + cfg_reg); |
| 434 | |
| 435 | if (set) { |
| 436 | cfg_value = PINCFG_UNPACK_VALUE(*config); |
| 437 | data &= ~(mask << shift); |
| 438 | data |= (cfg_value << shift); |
| 439 | writel(data, reg_base + cfg_reg); |
| 440 | } else { |
| 441 | data >>= shift; |
| 442 | data &= mask; |
| 443 | *config = PINCFG_PACK(cfg_type, data); |
| 444 | } |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 445 | |
| 446 | spin_unlock_irqrestore(&bank->slock, flags); |
| 447 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | /* set the pin config settings for a specified pin */ |
| 452 | static int samsung_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 453 | unsigned long *configs, unsigned num_configs) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 454 | { |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 455 | int i, ret; |
| 456 | |
| 457 | for (i = 0; i < num_configs; i++) { |
| 458 | ret = samsung_pinconf_rw(pctldev, pin, &configs[i], true); |
| 459 | if (ret < 0) |
| 460 | return ret; |
| 461 | } /* for each config */ |
| 462 | |
| 463 | return 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* get the pin config settings for a specified pin */ |
| 467 | static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin, |
| 468 | unsigned long *config) |
| 469 | { |
| 470 | return samsung_pinconf_rw(pctldev, pin, config, false); |
| 471 | } |
| 472 | |
| 473 | /* set the pin config settings for a specified pin group */ |
| 474 | static int samsung_pinconf_group_set(struct pinctrl_dev *pctldev, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 475 | unsigned group, unsigned long *configs, |
| 476 | unsigned num_configs) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 477 | { |
| 478 | struct samsung_pinctrl_drv_data *drvdata; |
| 479 | const unsigned int *pins; |
| 480 | unsigned int cnt; |
| 481 | |
| 482 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 483 | pins = drvdata->pin_groups[group].pins; |
| 484 | |
| 485 | for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++) |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 486 | samsung_pinconf_set(pctldev, pins[cnt], configs, num_configs); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | /* get the pin config settings for a specified pin group */ |
| 492 | static int samsung_pinconf_group_get(struct pinctrl_dev *pctldev, |
| 493 | unsigned int group, unsigned long *config) |
| 494 | { |
| 495 | struct samsung_pinctrl_drv_data *drvdata; |
| 496 | const unsigned int *pins; |
| 497 | |
| 498 | drvdata = pinctrl_dev_get_drvdata(pctldev); |
| 499 | pins = drvdata->pin_groups[group].pins; |
| 500 | samsung_pinconf_get(pctldev, pins[0], config); |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | /* list of pinconfig callbacks for pinconfig vertical in the pinctrl code */ |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 505 | static const struct pinconf_ops samsung_pinconf_ops = { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 506 | .pin_config_get = samsung_pinconf_get, |
| 507 | .pin_config_set = samsung_pinconf_set, |
| 508 | .pin_config_group_get = samsung_pinconf_group_get, |
| 509 | .pin_config_group_set = samsung_pinconf_group_set, |
| 510 | }; |
| 511 | |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 512 | /* |
| 513 | * The samsung_gpio_set_vlaue() should be called with "bank->slock" held |
| 514 | * to avoid race condition. |
| 515 | */ |
| 516 | static void samsung_gpio_set_value(struct gpio_chip *gc, |
| 517 | unsigned offset, int value) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 518 | { |
Linus Walleij | 9f57f81 | 2015-12-08 10:18:50 +0100 | [diff] [blame] | 519 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 520 | const struct samsung_pin_bank_type *type = bank->type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 521 | void __iomem *reg; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 522 | u32 data; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 523 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 524 | reg = bank->pctl_base + bank->pctl_offset; |
Tomasz Figa | 62f14c0 | 2012-10-11 10:11:08 +0200 | [diff] [blame] | 525 | |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 526 | data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]); |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 527 | data &= ~(1 << offset); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 528 | if (value) |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 529 | data |= 1 << offset; |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 530 | writel(data, reg + type->reg_offset[PINCFG_TYPE_DAT]); |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 531 | } |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 532 | |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 533 | /* gpiolib gpio_set callback function */ |
| 534 | static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value) |
| 535 | { |
| 536 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
| 537 | unsigned long flags; |
| 538 | |
| 539 | spin_lock_irqsave(&bank->slock, flags); |
| 540 | samsung_gpio_set_value(gc, offset, value); |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 541 | spin_unlock_irqrestore(&bank->slock, flags); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* gpiolib gpio_get callback function */ |
| 545 | static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset) |
| 546 | { |
| 547 | void __iomem *reg; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 548 | u32 data; |
Linus Walleij | 9f57f81 | 2015-12-08 10:18:50 +0100 | [diff] [blame] | 549 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 550 | const struct samsung_pin_bank_type *type = bank->type; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 551 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 552 | reg = bank->pctl_base + bank->pctl_offset; |
Tomasz Figa | 62f14c0 | 2012-10-11 10:11:08 +0200 | [diff] [blame] | 553 | |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 554 | data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]); |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 555 | data >>= offset; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 556 | data &= 1; |
| 557 | return data; |
| 558 | } |
| 559 | |
| 560 | /* |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 561 | * The samsung_gpio_set_direction() should be called with "bank->slock" held |
| 562 | * to avoid race condition. |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 563 | * The calls to gpio_direction_output() and gpio_direction_input() |
| 564 | * leads to this function call. |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 565 | */ |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 566 | static int samsung_gpio_set_direction(struct gpio_chip *gc, |
| 567 | unsigned offset, bool input) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 568 | { |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 569 | const struct samsung_pin_bank_type *type; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 570 | struct samsung_pin_bank *bank; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 571 | void __iomem *reg; |
| 572 | u32 data, mask, shift; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 573 | |
Linus Walleij | 9f57f81 | 2015-12-08 10:18:50 +0100 | [diff] [blame] | 574 | bank = gpiochip_get_data(gc); |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 575 | type = bank->type; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 576 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 577 | reg = bank->pctl_base + bank->pctl_offset |
| 578 | + type->reg_offset[PINCFG_TYPE_FUNC]; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 579 | |
| 580 | mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1; |
| 581 | shift = offset * type->fld_width[PINCFG_TYPE_FUNC]; |
| 582 | if (shift >= 32) { |
| 583 | /* Some banks have two config registers */ |
| 584 | shift -= 32; |
| 585 | reg += 4; |
| 586 | } |
| 587 | |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 588 | data = readl(reg); |
| 589 | data &= ~(mask << shift); |
| 590 | if (!input) |
Krzysztof Kozlowski | 4460dc2 | 2017-06-15 17:06:28 +0200 | [diff] [blame^] | 591 | data |= EXYNOS_PIN_FUNC_OUTPUT << shift; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 592 | writel(data, reg); |
| 593 | |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 594 | return 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 595 | } |
| 596 | |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 597 | /* gpiolib gpio_direction_input callback function. */ |
| 598 | static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset) |
| 599 | { |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 600 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
| 601 | unsigned long flags; |
| 602 | int ret; |
| 603 | |
| 604 | spin_lock_irqsave(&bank->slock, flags); |
| 605 | ret = samsung_gpio_set_direction(gc, offset, true); |
| 606 | spin_unlock_irqrestore(&bank->slock, flags); |
| 607 | return ret; |
Tomasz Figa | 18c28ca | 2014-07-02 17:40:59 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* gpiolib gpio_direction_output callback function. */ |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 611 | static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset, |
| 612 | int value) |
| 613 | { |
Youngmin Nam | d9ff0eb | 2016-02-09 00:49:28 +0900 | [diff] [blame] | 614 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
| 615 | unsigned long flags; |
| 616 | int ret; |
| 617 | |
| 618 | spin_lock_irqsave(&bank->slock, flags); |
| 619 | samsung_gpio_set_value(gc, offset, value); |
| 620 | ret = samsung_gpio_set_direction(gc, offset, false); |
| 621 | spin_unlock_irqrestore(&bank->slock, flags); |
| 622 | |
| 623 | return ret; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* |
Tomasz Figa | a19fe2d | 2012-10-11 10:11:20 +0200 | [diff] [blame] | 627 | * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin |
| 628 | * and a virtual IRQ, if not already present. |
| 629 | */ |
| 630 | static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset) |
| 631 | { |
Linus Walleij | 9f57f81 | 2015-12-08 10:18:50 +0100 | [diff] [blame] | 632 | struct samsung_pin_bank *bank = gpiochip_get_data(gc); |
Tomasz Figa | a19fe2d | 2012-10-11 10:11:20 +0200 | [diff] [blame] | 633 | unsigned int virq; |
| 634 | |
| 635 | if (!bank->irq_domain) |
| 636 | return -ENXIO; |
| 637 | |
| 638 | virq = irq_create_mapping(bank->irq_domain, offset); |
| 639 | |
| 640 | return (virq) ? : -ENXIO; |
| 641 | } |
| 642 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 643 | static struct samsung_pin_group *samsung_pinctrl_create_groups( |
| 644 | struct device *dev, |
| 645 | struct samsung_pinctrl_drv_data *drvdata, |
| 646 | unsigned int *cnt) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 647 | { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 648 | struct pinctrl_desc *ctrldesc = &drvdata->pctl; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 649 | struct samsung_pin_group *groups, *grp; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 650 | const struct pinctrl_pin_desc *pdesc; |
| 651 | int i; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 652 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 653 | groups = devm_kzalloc(dev, ctrldesc->npins * sizeof(*groups), |
| 654 | GFP_KERNEL); |
| 655 | if (!groups) |
| 656 | return ERR_PTR(-EINVAL); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 657 | grp = groups; |
| 658 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 659 | pdesc = ctrldesc->pins; |
| 660 | for (i = 0; i < ctrldesc->npins; ++i, ++pdesc, ++grp) { |
| 661 | grp->name = pdesc->name; |
| 662 | grp->pins = &pdesc->number; |
| 663 | grp->num_pins = 1; |
| 664 | } |
| 665 | |
| 666 | *cnt = ctrldesc->npins; |
| 667 | return groups; |
| 668 | } |
| 669 | |
| 670 | static int samsung_pinctrl_create_function(struct device *dev, |
| 671 | struct samsung_pinctrl_drv_data *drvdata, |
| 672 | struct device_node *func_np, |
| 673 | struct samsung_pmx_func *func) |
| 674 | { |
| 675 | int npins; |
| 676 | int ret; |
| 677 | int i; |
| 678 | |
| 679 | if (of_property_read_u32(func_np, "samsung,pin-function", &func->val)) |
| 680 | return 0; |
| 681 | |
| 682 | npins = of_property_count_strings(func_np, "samsung,pins"); |
| 683 | if (npins < 1) { |
| 684 | dev_err(dev, "invalid pin list in %s node", func_np->name); |
| 685 | return -EINVAL; |
| 686 | } |
| 687 | |
| 688 | func->name = func_np->full_name; |
| 689 | |
| 690 | func->groups = devm_kzalloc(dev, npins * sizeof(char *), GFP_KERNEL); |
| 691 | if (!func->groups) |
| 692 | return -ENOMEM; |
| 693 | |
| 694 | for (i = 0; i < npins; ++i) { |
| 695 | const char *gname; |
| 696 | |
| 697 | ret = of_property_read_string_index(func_np, "samsung,pins", |
| 698 | i, &gname); |
| 699 | if (ret) { |
| 700 | dev_err(dev, |
| 701 | "failed to read pin name %d from %s node\n", |
| 702 | i, func_np->name); |
| 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | func->groups[i] = gname; |
| 707 | } |
| 708 | |
| 709 | func->num_groups = npins; |
| 710 | return 1; |
| 711 | } |
| 712 | |
| 713 | static struct samsung_pmx_func *samsung_pinctrl_create_functions( |
| 714 | struct device *dev, |
| 715 | struct samsung_pinctrl_drv_data *drvdata, |
| 716 | unsigned int *cnt) |
| 717 | { |
| 718 | struct samsung_pmx_func *functions, *func; |
| 719 | struct device_node *dev_np = dev->of_node; |
| 720 | struct device_node *cfg_np; |
| 721 | unsigned int func_cnt = 0; |
| 722 | int ret; |
| 723 | |
| 724 | /* |
| 725 | * Iterate over all the child nodes of the pin controller node |
| 726 | * and create pin groups and pin function lists. |
| 727 | */ |
| 728 | for_each_child_of_node(dev_np, cfg_np) { |
| 729 | struct device_node *func_np; |
| 730 | |
| 731 | if (!of_get_child_count(cfg_np)) { |
| 732 | if (!of_find_property(cfg_np, |
| 733 | "samsung,pin-function", NULL)) |
| 734 | continue; |
| 735 | ++func_cnt; |
| 736 | continue; |
| 737 | } |
| 738 | |
| 739 | for_each_child_of_node(cfg_np, func_np) { |
| 740 | if (!of_find_property(func_np, |
| 741 | "samsung,pin-function", NULL)) |
| 742 | continue; |
| 743 | ++func_cnt; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | functions = devm_kzalloc(dev, func_cnt * sizeof(*functions), |
| 748 | GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 749 | if (!functions) |
Marek Szyprowski | 1f7b8ea | 2017-01-19 14:48:46 +0100 | [diff] [blame] | 750 | return ERR_PTR(-ENOMEM); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 751 | func = functions; |
| 752 | |
| 753 | /* |
| 754 | * Iterate over all the child nodes of the pin controller node |
| 755 | * and create pin groups and pin function lists. |
| 756 | */ |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 757 | func_cnt = 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 758 | for_each_child_of_node(dev_np, cfg_np) { |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 759 | struct device_node *func_np; |
| 760 | |
| 761 | if (!of_get_child_count(cfg_np)) { |
| 762 | ret = samsung_pinctrl_create_function(dev, drvdata, |
| 763 | cfg_np, func); |
| 764 | if (ret < 0) |
| 765 | return ERR_PTR(ret); |
| 766 | if (ret > 0) { |
| 767 | ++func; |
| 768 | ++func_cnt; |
| 769 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 770 | continue; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 771 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 772 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 773 | for_each_child_of_node(cfg_np, func_np) { |
| 774 | ret = samsung_pinctrl_create_function(dev, drvdata, |
| 775 | func_np, func); |
| 776 | if (ret < 0) |
| 777 | return ERR_PTR(ret); |
| 778 | if (ret > 0) { |
| 779 | ++func; |
| 780 | ++func_cnt; |
| 781 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 782 | } |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 783 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 784 | |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 785 | *cnt = func_cnt; |
| 786 | return functions; |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | * Parse the information about all the available pin groups and pin functions |
| 791 | * from device node of the pin-controller. A pin group is formed with all |
| 792 | * the pins listed in the "samsung,pins" property. |
| 793 | */ |
| 794 | |
| 795 | static int samsung_pinctrl_parse_dt(struct platform_device *pdev, |
| 796 | struct samsung_pinctrl_drv_data *drvdata) |
| 797 | { |
| 798 | struct device *dev = &pdev->dev; |
| 799 | struct samsung_pin_group *groups; |
| 800 | struct samsung_pmx_func *functions; |
| 801 | unsigned int grp_cnt = 0, func_cnt = 0; |
| 802 | |
| 803 | groups = samsung_pinctrl_create_groups(dev, drvdata, &grp_cnt); |
| 804 | if (IS_ERR(groups)) { |
| 805 | dev_err(dev, "failed to parse pin groups\n"); |
| 806 | return PTR_ERR(groups); |
| 807 | } |
| 808 | |
| 809 | functions = samsung_pinctrl_create_functions(dev, drvdata, &func_cnt); |
| 810 | if (IS_ERR(functions)) { |
| 811 | dev_err(dev, "failed to parse pin functions\n"); |
Fabio Estevam | 44a074f | 2015-06-01 09:57:04 -0300 | [diff] [blame] | 812 | return PTR_ERR(functions); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | drvdata->pin_groups = groups; |
| 816 | drvdata->nr_groups = grp_cnt; |
| 817 | drvdata->pmx_functions = functions; |
Tomasz Figa | 9a2c1c3 | 2014-07-02 17:41:03 +0200 | [diff] [blame] | 818 | drvdata->nr_functions = func_cnt; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | /* register the pinctrl interface with the pinctrl subsystem */ |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 824 | static int samsung_pinctrl_register(struct platform_device *pdev, |
| 825 | struct samsung_pinctrl_drv_data *drvdata) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 826 | { |
| 827 | struct pinctrl_desc *ctrldesc = &drvdata->pctl; |
| 828 | struct pinctrl_pin_desc *pindesc, *pdesc; |
| 829 | struct samsung_pin_bank *pin_bank; |
| 830 | char *pin_names; |
| 831 | int pin, bank, ret; |
| 832 | |
| 833 | ctrldesc->name = "samsung-pinctrl"; |
| 834 | ctrldesc->owner = THIS_MODULE; |
| 835 | ctrldesc->pctlops = &samsung_pctrl_ops; |
| 836 | ctrldesc->pmxops = &samsung_pinmux_ops; |
| 837 | ctrldesc->confops = &samsung_pinconf_ops; |
| 838 | |
| 839 | pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) * |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 840 | drvdata->nr_pins, GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 841 | if (!pindesc) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 842 | return -ENOMEM; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 843 | ctrldesc->pins = pindesc; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 844 | ctrldesc->npins = drvdata->nr_pins; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 845 | |
| 846 | /* dynamically populate the pin number and pin name for pindesc */ |
| 847 | for (pin = 0, pdesc = pindesc; pin < ctrldesc->npins; pin++, pdesc++) |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 848 | pdesc->number = pin + drvdata->pin_base; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 849 | |
| 850 | /* |
| 851 | * allocate space for storing the dynamically generated names for all |
| 852 | * the pins which belong to this pin-controller. |
| 853 | */ |
| 854 | pin_names = devm_kzalloc(&pdev->dev, sizeof(char) * PIN_NAME_LENGTH * |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 855 | drvdata->nr_pins, GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 856 | if (!pin_names) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 857 | return -ENOMEM; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 858 | |
| 859 | /* for each pin, the name of the pin is pin-bank name + pin number */ |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 860 | for (bank = 0; bank < drvdata->nr_banks; bank++) { |
| 861 | pin_bank = &drvdata->pin_banks[bank]; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 862 | for (pin = 0; pin < pin_bank->nr_pins; pin++) { |
| 863 | sprintf(pin_names, "%s-%d", pin_bank->name, pin); |
| 864 | pdesc = pindesc + pin_bank->pin_base + pin; |
| 865 | pdesc->name = pin_names; |
| 866 | pin_names += PIN_NAME_LENGTH; |
| 867 | } |
| 868 | } |
| 869 | |
Tomasz Figa | 529301c | 2013-08-20 18:16:21 +0200 | [diff] [blame] | 870 | ret = samsung_pinctrl_parse_dt(pdev, drvdata); |
| 871 | if (ret) |
| 872 | return ret; |
| 873 | |
Laxman Dewangan | 9ed19e0 | 2016-02-28 14:36:42 +0530 | [diff] [blame] | 874 | drvdata->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, |
| 875 | drvdata); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 876 | if (IS_ERR(drvdata->pctl_dev)) { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 877 | dev_err(&pdev->dev, "could not register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 878 | return PTR_ERR(drvdata->pctl_dev); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 879 | } |
| 880 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 881 | for (bank = 0; bank < drvdata->nr_banks; ++bank) { |
| 882 | pin_bank = &drvdata->pin_banks[bank]; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 883 | pin_bank->grange.name = pin_bank->name; |
| 884 | pin_bank->grange.id = bank; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 885 | pin_bank->grange.pin_base = drvdata->pin_base |
Tomasz Figa | 6c6ce62 | 2014-07-02 17:41:00 +0200 | [diff] [blame] | 886 | + pin_bank->pin_base; |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 887 | pin_bank->grange.base = pin_bank->grange.pin_base; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 888 | pin_bank->grange.npins = pin_bank->gpio_chip.ngpio; |
| 889 | pin_bank->grange.gc = &pin_bank->gpio_chip; |
| 890 | pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange); |
| 891 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 892 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 893 | return 0; |
| 894 | } |
| 895 | |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 896 | /* unregister the pinctrl interface with the pinctrl subsystem */ |
| 897 | static int samsung_pinctrl_unregister(struct platform_device *pdev, |
| 898 | struct samsung_pinctrl_drv_data *drvdata) |
| 899 | { |
| 900 | struct samsung_pin_bank *bank = drvdata->pin_banks; |
| 901 | int i; |
| 902 | |
| 903 | for (i = 0; i < drvdata->nr_banks; ++i, ++bank) |
| 904 | pinctrl_remove_gpio_range(drvdata->pctl_dev, &bank->grange); |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 909 | static const struct gpio_chip samsung_gpiolib_chip = { |
Jonas Gorski | 98c85d5 | 2015-10-11 17:34:19 +0200 | [diff] [blame] | 910 | .request = gpiochip_generic_request, |
| 911 | .free = gpiochip_generic_free, |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 912 | .set = samsung_gpio_set, |
| 913 | .get = samsung_gpio_get, |
| 914 | .direction_input = samsung_gpio_direction_input, |
| 915 | .direction_output = samsung_gpio_direction_output, |
Tomasz Figa | a19fe2d | 2012-10-11 10:11:20 +0200 | [diff] [blame] | 916 | .to_irq = samsung_gpio_to_irq, |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 917 | .owner = THIS_MODULE, |
| 918 | }; |
| 919 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 920 | /* register the gpiolib interface with the gpiolib subsystem */ |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 921 | static int samsung_gpiolib_register(struct platform_device *pdev, |
| 922 | struct samsung_pinctrl_drv_data *drvdata) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 923 | { |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 924 | struct samsung_pin_bank *bank = drvdata->pin_banks; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 925 | struct gpio_chip *gc; |
| 926 | int ret; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 927 | int i; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 928 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 929 | for (i = 0; i < drvdata->nr_banks; ++i, ++bank) { |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 930 | bank->gpio_chip = samsung_gpiolib_chip; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 931 | |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 932 | gc = &bank->gpio_chip; |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 933 | gc->base = bank->grange.base; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 934 | gc->ngpio = bank->nr_pins; |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 935 | gc->parent = &pdev->dev; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 936 | gc->of_node = bank->of_node; |
| 937 | gc->label = bank->name; |
| 938 | |
Charles Keepax | f69ae4f | 2017-03-22 17:15:35 +0000 | [diff] [blame] | 939 | ret = devm_gpiochip_add_data(&pdev->dev, gc, bank); |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 940 | if (ret) { |
| 941 | dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n", |
| 942 | gc->label, ret); |
Charles Keepax | f69ae4f | 2017-03-22 17:15:35 +0000 | [diff] [blame] | 943 | return ret; |
Tomasz Figa | d3a7b9e | 2012-10-11 10:11:17 +0200 | [diff] [blame] | 944 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | return 0; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 948 | } |
| 949 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 950 | /* retrieve the soc specific data */ |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 951 | static const struct samsung_pin_ctrl * |
| 952 | samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, |
| 953 | struct platform_device *pdev) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 954 | { |
| 955 | int id; |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 956 | struct device_node *node = pdev->dev.of_node; |
Tomasz Figa | ab66378 | 2012-10-11 10:11:13 +0200 | [diff] [blame] | 957 | struct device_node *np; |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 958 | const struct samsung_pin_bank_data *bdata; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 959 | const struct samsung_pin_ctrl *ctrl; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 960 | struct samsung_pin_bank *bank; |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 961 | struct resource *res; |
| 962 | void __iomem *virt_base[SAMSUNG_PINCTRL_NUM_RESOURCES]; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 963 | int i; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 964 | |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 965 | id = of_alias_get_id(node, "pinctrl"); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 966 | if (id < 0) { |
| 967 | dev_err(&pdev->dev, "failed to get alias id\n"); |
Tomasz Figa | 8799327 | 2014-09-23 21:05:37 +0200 | [diff] [blame] | 968 | return ERR_PTR(-ENOENT); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 969 | } |
Marek Szyprowski | 9abc2b9 | 2017-01-26 10:29:23 +0100 | [diff] [blame] | 970 | ctrl = of_device_get_match_data(&pdev->dev); |
| 971 | ctrl += id; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 972 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 973 | d->suspend = ctrl->suspend; |
| 974 | d->resume = ctrl->resume; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 975 | d->nr_banks = ctrl->nr_banks; |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 976 | d->pin_banks = devm_kcalloc(&pdev->dev, d->nr_banks, |
| 977 | sizeof(*d->pin_banks), GFP_KERNEL); |
| 978 | if (!d->pin_banks) |
| 979 | return ERR_PTR(-ENOMEM); |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 980 | |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 981 | if (ctrl->nr_ext_resources + 1 > SAMSUNG_PINCTRL_NUM_RESOURCES) |
| 982 | return ERR_PTR(-EINVAL); |
| 983 | |
| 984 | for (i = 0; i < ctrl->nr_ext_resources + 1; i++) { |
| 985 | res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
Andrzej Hajda | 59f34e8 | 2017-02-23 11:12:40 +0100 | [diff] [blame] | 986 | if (!res) { |
| 987 | dev_err(&pdev->dev, "failed to get mem%d resource\n", i); |
| 988 | return ERR_PTR(-EINVAL); |
| 989 | } |
| 990 | virt_base[i] = devm_ioremap(&pdev->dev, res->start, |
| 991 | resource_size(res)); |
| 992 | if (!virt_base[i]) { |
| 993 | dev_err(&pdev->dev, "failed to ioremap %pR\n", res); |
| 994 | return ERR_PTR(-EIO); |
| 995 | } |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 996 | } |
| 997 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 998 | bank = d->pin_banks; |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 999 | bdata = ctrl->pin_banks; |
| 1000 | for (i = 0; i < ctrl->nr_banks; ++i, ++bdata, ++bank) { |
| 1001 | bank->type = bdata->type; |
| 1002 | bank->pctl_offset = bdata->pctl_offset; |
| 1003 | bank->nr_pins = bdata->nr_pins; |
| 1004 | bank->eint_func = bdata->eint_func; |
| 1005 | bank->eint_type = bdata->eint_type; |
| 1006 | bank->eint_mask = bdata->eint_mask; |
| 1007 | bank->eint_offset = bdata->eint_offset; |
| 1008 | bank->name = bdata->name; |
| 1009 | |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 1010 | spin_lock_init(&bank->slock); |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 1011 | bank->drvdata = d; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1012 | bank->pin_base = d->nr_pins; |
| 1013 | d->nr_pins += bank->nr_pins; |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 1014 | |
| 1015 | bank->eint_base = virt_base[0]; |
| 1016 | bank->pctl_base = virt_base[bdata->pctl_res_idx]; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 1017 | } |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 1018 | /* |
| 1019 | * Legacy platforms should provide only one resource with IO memory. |
| 1020 | * Store it as virt_base because legacy driver needs to access it |
| 1021 | * through samsung_pinctrl_drv_data. |
| 1022 | */ |
| 1023 | d->virt_base = virt_base[0]; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 1024 | |
Tomasz Figa | ab66378 | 2012-10-11 10:11:13 +0200 | [diff] [blame] | 1025 | for_each_child_of_node(node, np) { |
| 1026 | if (!of_find_property(np, "gpio-controller", NULL)) |
| 1027 | continue; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1028 | bank = d->pin_banks; |
| 1029 | for (i = 0; i < d->nr_banks; ++i, ++bank) { |
Tomasz Figa | ab66378 | 2012-10-11 10:11:13 +0200 | [diff] [blame] | 1030 | if (!strcmp(bank->name, np->name)) { |
| 1031 | bank->of_node = np; |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1037 | d->pin_base = pin_base; |
| 1038 | pin_base += d->nr_pins; |
Tomasz Figa | 40ba622 | 2012-10-11 10:11:09 +0200 | [diff] [blame] | 1039 | |
| 1040 | return ctrl; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1041 | } |
| 1042 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 1043 | static int samsung_pinctrl_probe(struct platform_device *pdev) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1044 | { |
| 1045 | struct samsung_pinctrl_drv_data *drvdata; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1046 | const struct samsung_pin_ctrl *ctrl; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1047 | struct device *dev = &pdev->dev; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1048 | struct resource *res; |
| 1049 | int ret; |
| 1050 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1051 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); |
Sylwester Nawrocki | b09eed7 | 2016-09-01 13:59:00 +0200 | [diff] [blame] | 1052 | if (!drvdata) |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1053 | return -ENOMEM; |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 1054 | |
| 1055 | ctrl = samsung_pinctrl_get_soc_data(drvdata, pdev); |
Tomasz Figa | 8799327 | 2014-09-23 21:05:37 +0200 | [diff] [blame] | 1056 | if (IS_ERR(ctrl)) { |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 1057 | dev_err(&pdev->dev, "driver data not available\n"); |
Tomasz Figa | 8799327 | 2014-09-23 21:05:37 +0200 | [diff] [blame] | 1058 | return PTR_ERR(ctrl); |
Tomasz Figa | 6defe9a | 2012-10-11 10:11:14 +0200 | [diff] [blame] | 1059 | } |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1060 | drvdata->dev = dev; |
| 1061 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1062 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1063 | if (res) |
| 1064 | drvdata->irq = res->start; |
| 1065 | |
Marek Szyprowski | 1fc8ad8 | 2017-01-26 10:29:24 +0100 | [diff] [blame] | 1066 | if (ctrl->retention_data) { |
| 1067 | drvdata->retention_ctrl = ctrl->retention_data->init(drvdata, |
| 1068 | ctrl->retention_data); |
| 1069 | if (IS_ERR(drvdata->retention_ctrl)) |
| 1070 | return PTR_ERR(drvdata->retention_ctrl); |
| 1071 | } |
| 1072 | |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 1073 | ret = samsung_pinctrl_register(pdev, drvdata); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1074 | if (ret) |
| 1075 | return ret; |
| 1076 | |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 1077 | ret = samsung_gpiolib_register(pdev, drvdata); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1078 | if (ret) { |
Charles Keepax | 1abd18d | 2017-03-22 17:15:34 +0000 | [diff] [blame] | 1079 | samsung_pinctrl_unregister(pdev, drvdata); |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1080 | return ret; |
| 1081 | } |
| 1082 | |
| 1083 | if (ctrl->eint_gpio_init) |
| 1084 | ctrl->eint_gpio_init(drvdata); |
| 1085 | if (ctrl->eint_wkup_init) |
| 1086 | ctrl->eint_wkup_init(drvdata); |
| 1087 | |
| 1088 | platform_set_drvdata(pdev, drvdata); |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1089 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1090 | return 0; |
| 1091 | } |
| 1092 | |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1093 | /** |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1094 | * samsung_pinctrl_suspend - save pinctrl state for suspend |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1095 | * |
| 1096 | * Save data for all banks handled by this device. |
| 1097 | */ |
Arnd Bergmann | 304c92e | 2017-02-01 17:16:24 +0100 | [diff] [blame] | 1098 | static int __maybe_unused samsung_pinctrl_suspend(struct device *dev) |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1099 | { |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1100 | struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev); |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1101 | int i; |
| 1102 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1103 | for (i = 0; i < drvdata->nr_banks; i++) { |
| 1104 | struct samsung_pin_bank *bank = &drvdata->pin_banks[i]; |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 1105 | void __iomem *reg = bank->pctl_base + bank->pctl_offset; |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 1106 | const u8 *offs = bank->type->reg_offset; |
| 1107 | const u8 *widths = bank->type->fld_width; |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1108 | enum pincfg_type type; |
| 1109 | |
| 1110 | /* Registers without a powerdown config aren't lost */ |
| 1111 | if (!widths[PINCFG_TYPE_CON_PDN]) |
| 1112 | continue; |
| 1113 | |
| 1114 | for (type = 0; type < PINCFG_TYPE_NUM; type++) |
| 1115 | if (widths[type]) |
| 1116 | bank->pm_save[type] = readl(reg + offs[type]); |
| 1117 | |
| 1118 | if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) { |
| 1119 | /* Some banks have two config registers */ |
| 1120 | bank->pm_save[PINCFG_TYPE_NUM] = |
| 1121 | readl(reg + offs[PINCFG_TYPE_FUNC] + 4); |
| 1122 | pr_debug("Save %s @ %p (con %#010x %08x)\n", |
| 1123 | bank->name, reg, |
| 1124 | bank->pm_save[PINCFG_TYPE_FUNC], |
| 1125 | bank->pm_save[PINCFG_TYPE_NUM]); |
| 1126 | } else { |
| 1127 | pr_debug("Save %s @ %p (con %#010x)\n", bank->name, |
| 1128 | reg, bank->pm_save[PINCFG_TYPE_FUNC]); |
| 1129 | } |
| 1130 | } |
Tomasz Figa | 21c2199 | 2013-05-17 18:24:30 +0200 | [diff] [blame] | 1131 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1132 | if (drvdata->suspend) |
| 1133 | drvdata->suspend(drvdata); |
Marek Szyprowski | 1fc8ad8 | 2017-01-26 10:29:24 +0100 | [diff] [blame] | 1134 | if (drvdata->retention_ctrl && drvdata->retention_ctrl->enable) |
| 1135 | drvdata->retention_ctrl->enable(drvdata); |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1136 | |
| 1137 | return 0; |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1141 | * samsung_pinctrl_resume - restore pinctrl state from suspend |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1142 | * |
| 1143 | * Restore one of the banks that was saved during suspend. |
| 1144 | * |
| 1145 | * We don't bother doing anything complicated to avoid glitching lines since |
| 1146 | * we're called before pad retention is turned off. |
| 1147 | */ |
Arnd Bergmann | 304c92e | 2017-02-01 17:16:24 +0100 | [diff] [blame] | 1148 | static int __maybe_unused samsung_pinctrl_resume(struct device *dev) |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1149 | { |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1150 | struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev); |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1151 | int i; |
| 1152 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1153 | if (drvdata->resume) |
| 1154 | drvdata->resume(drvdata); |
Tomasz Figa | 21c2199 | 2013-05-17 18:24:30 +0200 | [diff] [blame] | 1155 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 1156 | for (i = 0; i < drvdata->nr_banks; i++) { |
| 1157 | struct samsung_pin_bank *bank = &drvdata->pin_banks[i]; |
Chanwoo Choi | 8b1bd11c | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 1158 | void __iomem *reg = bank->pctl_base + bank->pctl_offset; |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 1159 | const u8 *offs = bank->type->reg_offset; |
| 1160 | const u8 *widths = bank->type->fld_width; |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1161 | enum pincfg_type type; |
| 1162 | |
| 1163 | /* Registers without a powerdown config aren't lost */ |
| 1164 | if (!widths[PINCFG_TYPE_CON_PDN]) |
| 1165 | continue; |
| 1166 | |
| 1167 | if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) { |
| 1168 | /* Some banks have two config registers */ |
| 1169 | pr_debug("%s @ %p (con %#010x %08x => %#010x %08x)\n", |
| 1170 | bank->name, reg, |
| 1171 | readl(reg + offs[PINCFG_TYPE_FUNC]), |
| 1172 | readl(reg + offs[PINCFG_TYPE_FUNC] + 4), |
| 1173 | bank->pm_save[PINCFG_TYPE_FUNC], |
| 1174 | bank->pm_save[PINCFG_TYPE_NUM]); |
| 1175 | writel(bank->pm_save[PINCFG_TYPE_NUM], |
| 1176 | reg + offs[PINCFG_TYPE_FUNC] + 4); |
| 1177 | } else { |
| 1178 | pr_debug("%s @ %p (con %#010x => %#010x)\n", bank->name, |
| 1179 | reg, readl(reg + offs[PINCFG_TYPE_FUNC]), |
| 1180 | bank->pm_save[PINCFG_TYPE_FUNC]); |
| 1181 | } |
| 1182 | for (type = 0; type < PINCFG_TYPE_NUM; type++) |
| 1183 | if (widths[type]) |
| 1184 | writel(bank->pm_save[type], reg + offs[type]); |
| 1185 | } |
Marek Szyprowski | 1fc8ad8 | 2017-01-26 10:29:24 +0100 | [diff] [blame] | 1186 | |
| 1187 | if (drvdata->retention_ctrl && drvdata->retention_ctrl->disable) |
| 1188 | drvdata->retention_ctrl->disable(drvdata); |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1189 | |
| 1190 | return 0; |
| 1191 | } |
Doug Anderson | d9f9986 | 2013-05-16 21:33:18 -0700 | [diff] [blame] | 1192 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1193 | static const struct of_device_id samsung_pinctrl_dt_match[] = { |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 1194 | #ifdef CONFIG_PINCTRL_EXYNOS_ARM |
Tomasz Figa | d97f5b9 | 2014-04-14 10:45:47 +0900 | [diff] [blame] | 1195 | { .compatible = "samsung,exynos3250-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1196 | .data = exynos3250_pin_ctrl }, |
Kukjin Kim | b533c86 | 2013-01-02 16:05:42 -0800 | [diff] [blame] | 1197 | { .compatible = "samsung,exynos4210-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1198 | .data = exynos4210_pin_ctrl }, |
Kukjin Kim | b533c86 | 2013-01-02 16:05:42 -0800 | [diff] [blame] | 1199 | { .compatible = "samsung,exynos4x12-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1200 | .data = exynos4x12_pin_ctrl }, |
Thomas Abraham | f67faf4 | 2012-12-28 10:37:27 -0800 | [diff] [blame] | 1201 | { .compatible = "samsung,exynos5250-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1202 | .data = exynos5250_pin_ctrl }, |
Young-Gun Jang | 9a8b607 | 2014-02-05 11:51:28 +0530 | [diff] [blame] | 1203 | { .compatible = "samsung,exynos5260-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1204 | .data = exynos5260_pin_ctrl }, |
Hakjoo Kim | 023e06d | 2015-03-15 23:00:32 +0100 | [diff] [blame] | 1205 | { .compatible = "samsung,exynos5410-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1206 | .data = exynos5410_pin_ctrl }, |
Leela Krishna Amudala | 983dbeb | 2013-06-19 22:16:26 +0900 | [diff] [blame] | 1207 | { .compatible = "samsung,exynos5420-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1208 | .data = exynos5420_pin_ctrl }, |
Mateusz Krawczuk | 608a26a | 2013-08-27 15:08:10 +0200 | [diff] [blame] | 1209 | { .compatible = "samsung,s5pv210-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1210 | .data = s5pv210_pin_ctrl }, |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 1211 | #endif |
| 1212 | #ifdef CONFIG_PINCTRL_EXYNOS_ARM64 |
| 1213 | { .compatible = "samsung,exynos5433-pinctrl", |
| 1214 | .data = exynos5433_pin_ctrl }, |
Naveen Krishna Ch | 50cea0c | 2014-10-09 19:24:32 +0530 | [diff] [blame] | 1215 | { .compatible = "samsung,exynos7-pinctrl", |
Masahiro Yamada | 7ddaa43 | 2017-04-26 06:34:23 +0900 | [diff] [blame] | 1216 | .data = exynos7_pin_ctrl }, |
Tomasz Figa | d5517be | 2013-03-18 22:31:51 +0100 | [diff] [blame] | 1217 | #endif |
Tomasz Figa | 61dd726 | 2013-03-18 22:31:55 +0100 | [diff] [blame] | 1218 | #ifdef CONFIG_PINCTRL_S3C64XX |
| 1219 | { .compatible = "samsung,s3c64xx-pinctrl", |
| 1220 | .data = s3c64xx_pin_ctrl }, |
| 1221 | #endif |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 1222 | #ifdef CONFIG_PINCTRL_S3C24XX |
| 1223 | { .compatible = "samsung,s3c2412-pinctrl", |
| 1224 | .data = s3c2412_pin_ctrl }, |
| 1225 | { .compatible = "samsung,s3c2416-pinctrl", |
| 1226 | .data = s3c2416_pin_ctrl }, |
| 1227 | { .compatible = "samsung,s3c2440-pinctrl", |
| 1228 | .data = s3c2440_pin_ctrl }, |
| 1229 | { .compatible = "samsung,s3c2450-pinctrl", |
| 1230 | .data = s3c2450_pin_ctrl }, |
| 1231 | #endif |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1232 | {}, |
| 1233 | }; |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1234 | |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1235 | static const struct dev_pm_ops samsung_pinctrl_pm_ops = { |
| 1236 | SET_LATE_SYSTEM_SLEEP_PM_OPS(samsung_pinctrl_suspend, |
| 1237 | samsung_pinctrl_resume) |
| 1238 | }; |
| 1239 | |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1240 | static struct platform_driver samsung_pinctrl_driver = { |
| 1241 | .probe = samsung_pinctrl_probe, |
| 1242 | .driver = { |
| 1243 | .name = "samsung-pinctrl", |
Sachin Kamat | 606fca9 | 2013-09-28 17:38:48 +0530 | [diff] [blame] | 1244 | .of_match_table = samsung_pinctrl_dt_match, |
Krzysztof Kozlowski | a0ee2ac | 2016-05-17 08:02:06 +0200 | [diff] [blame] | 1245 | .suppress_bind_attrs = true, |
Marek Szyprowski | 2b24efa | 2017-01-26 10:29:27 +0100 | [diff] [blame] | 1246 | .pm = &samsung_pinctrl_pm_ops, |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1247 | }, |
| 1248 | }; |
| 1249 | |
| 1250 | static int __init samsung_pinctrl_drv_register(void) |
| 1251 | { |
Thomas Abraham | 30574f0 | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 1252 | return platform_driver_register(&samsung_pinctrl_driver); |
| 1253 | } |
| 1254 | postcore_initcall(samsung_pinctrl_drv_register); |