blob: 0f6e9305fec58c7bef531d8ff8714a2392f27cb3 [file] [log] [blame]
Krzysztof Kozlowski221173a2017-12-26 19:09:42 +01001// SPDX-License-Identifier: GPL-2.0+
2//
3// pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's.
4//
5// Copyright (c) 2012 Samsung Electronics Co., Ltd.
6// http://www.samsung.com
7// Copyright (c) 2012 Linaro Ltd
8// http://www.linaro.org
9//
10// Author: Thomas Abraham <thomas.ab@samsung.com>
11//
12// This driver implements the Samsung pinctrl driver. It supports setting up of
13// pinmux and pinconf configurations. The gpiolib interface is also included.
14// External interrupt (gpio and wakeup) support are not included in this driver
15// but provides extensions to which platform specific implementation of the gpio
16// and wakeup interrupts can be hooked to.
Thomas Abraham30574f02012-09-07 06:07:19 +090017
Paul Gortmaker8208b282017-05-22 16:56:46 -040018#include <linux/init.h>
Thomas Abraham30574f02012-09-07 06:07:19 +090019#include <linux/platform_device.h>
20#include <linux/io.h>
21#include <linux/slab.h>
22#include <linux/err.h>
Linus Walleij1c5fb662018-09-13 13:58:21 +020023#include <linux/gpio/driver.h>
Tomasz Figaa19fe2d2012-10-11 10:11:20 +020024#include <linux/irqdomain.h>
Marek Szyprowski9abc2b92017-01-26 10:29:23 +010025#include <linux/of_device.h>
Tomasz Figa19846952013-03-18 22:31:50 +010026#include <linux/spinlock.h>
Thomas Abraham30574f02012-09-07 06:07:19 +090027
Krzysztof Kozlowski4460dc22017-06-15 17:06:28 +020028#include <dt-bindings/pinctrl/samsung.h>
29
Sachin Kamatebe629a2014-07-10 17:33:27 +053030#include "../core.h"
Thomas Abraham30574f02012-09-07 06:07:19 +090031#include "pinctrl-samsung.h"
32
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +090033/* maximum number of the memory resources */
34#define SAMSUNG_PINCTRL_NUM_RESOURCES 2
35
Thomas Abraham30574f02012-09-07 06:07:19 +090036/* list of all possible config options supported */
Axel Lind5fd5da2012-12-10 09:54:03 +090037static struct pin_config {
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020038 const char *property;
39 enum pincfg_type param;
40} cfg_params[] = {
Thomas Abraham30574f02012-09-07 06:07:19 +090041 { "samsung,pin-pud", PINCFG_TYPE_PUD },
42 { "samsung,pin-drv", PINCFG_TYPE_DRV },
43 { "samsung,pin-con-pdn", PINCFG_TYPE_CON_PDN },
44 { "samsung,pin-pud-pdn", PINCFG_TYPE_PUD_PDN },
Tomasz Figa2700bc02014-07-02 17:41:04 +020045 { "samsung,pin-val", PINCFG_TYPE_DAT },
Thomas Abraham30574f02012-09-07 06:07:19 +090046};
47
Sachin Kamat6fb6f1ba2012-11-24 11:20:51 +090048static unsigned int pin_base;
Tomasz Figa40ba6222012-10-11 10:11:09 +020049
Thomas Abraham30574f02012-09-07 06:07:19 +090050static int samsung_get_group_count(struct pinctrl_dev *pctldev)
51{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020052 struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
Thomas Abraham30574f02012-09-07 06:07:19 +090053
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020054 return pmx->nr_groups;
Thomas Abraham30574f02012-09-07 06:07:19 +090055}
56
Thomas Abraham30574f02012-09-07 06:07:19 +090057static const char *samsung_get_group_name(struct pinctrl_dev *pctldev,
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020058 unsigned group)
Thomas Abraham30574f02012-09-07 06:07:19 +090059{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020060 struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
Thomas Abraham30574f02012-09-07 06:07:19 +090061
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020062 return pmx->pin_groups[group].name;
Thomas Abraham30574f02012-09-07 06:07:19 +090063}
64
Thomas Abraham30574f02012-09-07 06:07:19 +090065static int samsung_get_group_pins(struct pinctrl_dev *pctldev,
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020066 unsigned group,
67 const unsigned **pins,
68 unsigned *num_pins)
Thomas Abraham30574f02012-09-07 06:07:19 +090069{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020070 struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
Thomas Abraham30574f02012-09-07 06:07:19 +090071
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020072 *pins = pmx->pin_groups[group].pins;
73 *num_pins = pmx->pin_groups[group].num_pins;
74
Thomas Abraham30574f02012-09-07 06:07:19 +090075 return 0;
76}
77
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020078static int reserve_map(struct device *dev, struct pinctrl_map **map,
79 unsigned *reserved_maps, unsigned *num_maps,
80 unsigned reserve)
Thomas Abraham30574f02012-09-07 06:07:19 +090081{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020082 unsigned old_num = *reserved_maps;
83 unsigned new_num = *num_maps + reserve;
84 struct pinctrl_map *new_map;
Thomas Abraham30574f02012-09-07 06:07:19 +090085
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020086 if (old_num >= new_num)
87 return 0;
Thomas Abraham30574f02012-09-07 06:07:19 +090088
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020089 new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +010090 if (!new_map)
Thomas Abraham30574f02012-09-07 06:07:19 +090091 return -ENOMEM;
Thomas Abraham30574f02012-09-07 06:07:19 +090092
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020093 memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
Thomas Abraham30574f02012-09-07 06:07:19 +090094
Tomasz Figa9a2c1c32014-07-02 17:41:03 +020095 *map = new_map;
96 *reserved_maps = new_num;
Thomas Abraham30574f02012-09-07 06:07:19 +090097
Thomas Abraham30574f02012-09-07 06:07:19 +090098 return 0;
Thomas Abraham30574f02012-09-07 06:07:19 +090099}
100
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200101static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
102 unsigned *num_maps, const char *group,
103 const char *function)
Thomas Abraham30574f02012-09-07 06:07:19 +0900104{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200105 if (WARN_ON(*num_maps == *reserved_maps))
106 return -ENOSPC;
Thomas Abraham30574f02012-09-07 06:07:19 +0900107
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200108 (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
109 (*map)[*num_maps].data.mux.group = group;
110 (*map)[*num_maps].data.mux.function = function;
111 (*num_maps)++;
112
113 return 0;
114}
115
116static int add_map_configs(struct device *dev, struct pinctrl_map **map,
117 unsigned *reserved_maps, unsigned *num_maps,
118 const char *group, unsigned long *configs,
119 unsigned num_configs)
120{
121 unsigned long *dup_configs;
122
123 if (WARN_ON(*num_maps == *reserved_maps))
124 return -ENOSPC;
125
126 dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
127 GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +0100128 if (!dup_configs)
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200129 return -ENOMEM;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200130
131 (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
132 (*map)[*num_maps].data.configs.group_or_pin = group;
133 (*map)[*num_maps].data.configs.configs = dup_configs;
134 (*map)[*num_maps].data.configs.num_configs = num_configs;
135 (*num_maps)++;
136
137 return 0;
138}
139
140static int add_config(struct device *dev, unsigned long **configs,
141 unsigned *num_configs, unsigned long config)
142{
143 unsigned old_num = *num_configs;
144 unsigned new_num = old_num + 1;
145 unsigned long *new_configs;
146
147 new_configs = krealloc(*configs, sizeof(*new_configs) * new_num,
148 GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +0100149 if (!new_configs)
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200150 return -ENOMEM;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200151
152 new_configs[old_num] = config;
153
154 *configs = new_configs;
155 *num_configs = new_num;
156
157 return 0;
158}
159
160static void samsung_dt_free_map(struct pinctrl_dev *pctldev,
161 struct pinctrl_map *map,
162 unsigned num_maps)
163{
164 int i;
165
166 for (i = 0; i < num_maps; i++)
167 if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
168 kfree(map[i].data.configs.configs);
Thomas Abraham30574f02012-09-07 06:07:19 +0900169
170 kfree(map);
171}
172
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200173static int samsung_dt_subnode_to_map(struct samsung_pinctrl_drv_data *drvdata,
174 struct device *dev,
175 struct device_node *np,
176 struct pinctrl_map **map,
177 unsigned *reserved_maps,
178 unsigned *num_maps)
179{
180 int ret, i;
181 u32 val;
182 unsigned long config;
183 unsigned long *configs = NULL;
184 unsigned num_configs = 0;
185 unsigned reserve;
186 struct property *prop;
187 const char *group;
188 bool has_func = false;
189
190 ret = of_property_read_u32(np, "samsung,pin-function", &val);
191 if (!ret)
192 has_func = true;
193
194 for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
195 ret = of_property_read_u32(np, cfg_params[i].property, &val);
196 if (!ret) {
197 config = PINCFG_PACK(cfg_params[i].param, val);
198 ret = add_config(dev, &configs, &num_configs, config);
199 if (ret < 0)
200 goto exit;
201 /* EINVAL=missing, which is fine since it's optional */
202 } else if (ret != -EINVAL) {
203 dev_err(dev, "could not parse property %s\n",
204 cfg_params[i].property);
205 }
206 }
207
208 reserve = 0;
209 if (has_func)
210 reserve++;
211 if (num_configs)
212 reserve++;
213 ret = of_property_count_strings(np, "samsung,pins");
214 if (ret < 0) {
215 dev_err(dev, "could not parse property samsung,pins\n");
216 goto exit;
217 }
218 reserve *= ret;
219
220 ret = reserve_map(dev, map, reserved_maps, num_maps, reserve);
221 if (ret < 0)
222 goto exit;
223
224 of_property_for_each_string(np, "samsung,pins", prop, group) {
225 if (has_func) {
226 ret = add_map_mux(map, reserved_maps,
227 num_maps, group, np->full_name);
228 if (ret < 0)
229 goto exit;
230 }
231
232 if (num_configs) {
233 ret = add_map_configs(dev, map, reserved_maps,
234 num_maps, group, configs,
235 num_configs);
236 if (ret < 0)
237 goto exit;
238 }
239 }
240
241 ret = 0;
242
243exit:
244 kfree(configs);
245 return ret;
246}
247
248static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
249 struct device_node *np_config,
250 struct pinctrl_map **map,
251 unsigned *num_maps)
252{
253 struct samsung_pinctrl_drv_data *drvdata;
254 unsigned reserved_maps;
255 struct device_node *np;
256 int ret;
257
258 drvdata = pinctrl_dev_get_drvdata(pctldev);
259
260 reserved_maps = 0;
261 *map = NULL;
262 *num_maps = 0;
263
264 if (!of_get_child_count(np_config))
265 return samsung_dt_subnode_to_map(drvdata, pctldev->dev,
266 np_config, map,
267 &reserved_maps,
268 num_maps);
269
270 for_each_child_of_node(np_config, np) {
271 ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map,
272 &reserved_maps, num_maps);
273 if (ret < 0) {
274 samsung_dt_free_map(pctldev, *map, *num_maps);
Krzysztof Kozlowskia322b332019-08-05 18:27:10 +0200275 of_node_put(np);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200276 return ret;
277 }
278 }
279
280 return 0;
281}
282
Chanho Park4e212642018-03-27 22:58:01 +0900283#ifdef CONFIG_DEBUG_FS
284/* Forward declaration which can be used by samsung_pin_dbg_show */
285static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
286 unsigned long *config);
287static const char * const reg_names[] = {"CON", "DAT", "PUD", "DRV", "CON_PDN",
288 "PUD_PDN"};
289
290static void samsung_pin_dbg_show(struct pinctrl_dev *pctldev,
291 struct seq_file *s, unsigned int pin)
292{
293 enum pincfg_type cfg_type;
294 unsigned long config;
295 int ret;
296
297 for (cfg_type = 0; cfg_type < PINCFG_TYPE_NUM; cfg_type++) {
298 config = PINCFG_PACK(cfg_type, 0);
299 ret = samsung_pinconf_get(pctldev, pin, &config);
300 if (ret < 0)
301 continue;
302
303 seq_printf(s, " %s(0x%lx)", reg_names[cfg_type],
304 PINCFG_UNPACK_VALUE(config));
305 }
306}
307#endif
308
Thomas Abraham30574f02012-09-07 06:07:19 +0900309/* list of pinctrl callbacks for the pinctrl core */
Laurent Pinchart022ab142013-02-16 10:25:07 +0100310static const struct pinctrl_ops samsung_pctrl_ops = {
Thomas Abraham30574f02012-09-07 06:07:19 +0900311 .get_groups_count = samsung_get_group_count,
312 .get_group_name = samsung_get_group_name,
313 .get_group_pins = samsung_get_group_pins,
314 .dt_node_to_map = samsung_dt_node_to_map,
315 .dt_free_map = samsung_dt_free_map,
Chanho Park4e212642018-03-27 22:58:01 +0900316#ifdef CONFIG_DEBUG_FS
317 .pin_dbg_show = samsung_pin_dbg_show,
318#endif
Thomas Abraham30574f02012-09-07 06:07:19 +0900319};
320
321/* check if the selector is a valid pin function selector */
322static int samsung_get_functions_count(struct pinctrl_dev *pctldev)
323{
324 struct samsung_pinctrl_drv_data *drvdata;
325
326 drvdata = pinctrl_dev_get_drvdata(pctldev);
327 return drvdata->nr_functions;
328}
329
330/* return the name of the pin function specified */
331static const char *samsung_pinmux_get_fname(struct pinctrl_dev *pctldev,
332 unsigned selector)
333{
334 struct samsung_pinctrl_drv_data *drvdata;
335
336 drvdata = pinctrl_dev_get_drvdata(pctldev);
337 return drvdata->pmx_functions[selector].name;
338}
339
340/* return the groups associated for the specified function selector */
341static int samsung_pinmux_get_groups(struct pinctrl_dev *pctldev,
342 unsigned selector, const char * const **groups,
343 unsigned * const num_groups)
344{
345 struct samsung_pinctrl_drv_data *drvdata;
346
347 drvdata = pinctrl_dev_get_drvdata(pctldev);
348 *groups = drvdata->pmx_functions[selector].groups;
349 *num_groups = drvdata->pmx_functions[selector].num_groups;
350 return 0;
351}
352
353/*
354 * given a pin number that is local to a pin controller, find out the pin bank
355 * and the register base of the pin bank.
356 */
Tomasz Figa62f14c02012-10-11 10:11:08 +0200357static void pin_to_reg_bank(struct samsung_pinctrl_drv_data *drvdata,
358 unsigned pin, void __iomem **reg, u32 *offset,
Thomas Abraham30574f02012-09-07 06:07:19 +0900359 struct samsung_pin_bank **bank)
360{
Thomas Abraham30574f02012-09-07 06:07:19 +0900361 struct samsung_pin_bank *b;
362
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200363 b = drvdata->pin_banks;
Thomas Abraham30574f02012-09-07 06:07:19 +0900364
365 while ((pin >= b->pin_base) &&
366 ((b->pin_base + b->nr_pins - 1) < pin))
367 b++;
368
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +0900369 *reg = b->pctl_base + b->pctl_offset;
Thomas Abraham30574f02012-09-07 06:07:19 +0900370 *offset = pin - b->pin_base;
371 if (bank)
372 *bank = b;
Thomas Abraham30574f02012-09-07 06:07:19 +0900373}
374
375/* enable or disable a pinmux function */
376static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector,
Marek Szyprowski991efb02017-01-26 10:29:22 +0100377 unsigned group)
Thomas Abraham30574f02012-09-07 06:07:19 +0900378{
379 struct samsung_pinctrl_drv_data *drvdata;
Tomasz Figa94ce9442014-09-23 21:05:39 +0200380 const struct samsung_pin_bank_type *type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900381 struct samsung_pin_bank *bank;
382 void __iomem *reg;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200383 u32 mask, shift, data, pin_offset;
Tomasz Figa19846952013-03-18 22:31:50 +0100384 unsigned long flags;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200385 const struct samsung_pmx_func *func;
386 const struct samsung_pin_group *grp;
Thomas Abraham30574f02012-09-07 06:07:19 +0900387
388 drvdata = pinctrl_dev_get_drvdata(pctldev);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200389 func = &drvdata->pmx_functions[selector];
390 grp = &drvdata->pin_groups[group];
Thomas Abraham30574f02012-09-07 06:07:19 +0900391
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200392 pin_to_reg_bank(drvdata, grp->pins[0] - drvdata->pin_base,
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200393 &reg, &pin_offset, &bank);
394 type = bank->type;
395 mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
396 shift = pin_offset * type->fld_width[PINCFG_TYPE_FUNC];
397 if (shift >= 32) {
398 /* Some banks have two config registers */
399 shift -= 32;
400 reg += 4;
Thomas Abraham30574f02012-09-07 06:07:19 +0900401 }
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200402
Chanho Park1f306ec2021-01-21 12:00:09 +0900403 raw_spin_lock_irqsave(&bank->slock, flags);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200404
405 data = readl(reg + type->reg_offset[PINCFG_TYPE_FUNC]);
406 data &= ~(mask << shift);
Marek Szyprowski991efb02017-01-26 10:29:22 +0100407 data |= func->val << shift;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200408 writel(data, reg + type->reg_offset[PINCFG_TYPE_FUNC]);
409
Chanho Park1f306ec2021-01-21 12:00:09 +0900410 raw_spin_unlock_irqrestore(&bank->slock, flags);
Thomas Abraham30574f02012-09-07 06:07:19 +0900411}
412
413/* enable a specified pinmux by writing to registers */
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200414static int samsung_pinmux_set_mux(struct pinctrl_dev *pctldev,
415 unsigned selector,
416 unsigned group)
Thomas Abraham30574f02012-09-07 06:07:19 +0900417{
Marek Szyprowski991efb02017-01-26 10:29:22 +0100418 samsung_pinmux_setup(pctldev, selector, group);
Thomas Abraham30574f02012-09-07 06:07:19 +0900419 return 0;
420}
421
Thomas Abraham30574f02012-09-07 06:07:19 +0900422/* list of pinmux callbacks for the pinmux vertical in pinctrl core */
Laurent Pinchart022ab142013-02-16 10:25:07 +0100423static const struct pinmux_ops samsung_pinmux_ops = {
Thomas Abraham30574f02012-09-07 06:07:19 +0900424 .get_functions_count = samsung_get_functions_count,
425 .get_function_name = samsung_pinmux_get_fname,
426 .get_function_groups = samsung_pinmux_get_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200427 .set_mux = samsung_pinmux_set_mux,
Thomas Abraham30574f02012-09-07 06:07:19 +0900428};
429
430/* set or get the pin config settings for a specified pin */
431static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin,
432 unsigned long *config, bool set)
433{
434 struct samsung_pinctrl_drv_data *drvdata;
Tomasz Figa94ce9442014-09-23 21:05:39 +0200435 const struct samsung_pin_bank_type *type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900436 struct samsung_pin_bank *bank;
437 void __iomem *reg_base;
438 enum pincfg_type cfg_type = PINCFG_UNPACK_TYPE(*config);
439 u32 data, width, pin_offset, mask, shift;
440 u32 cfg_value, cfg_reg;
Tomasz Figa19846952013-03-18 22:31:50 +0100441 unsigned long flags;
Thomas Abraham30574f02012-09-07 06:07:19 +0900442
443 drvdata = pinctrl_dev_get_drvdata(pctldev);
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200444 pin_to_reg_bank(drvdata, pin - drvdata->pin_base, &reg_base,
Thomas Abraham30574f02012-09-07 06:07:19 +0900445 &pin_offset, &bank);
Tomasz Figa499147c2013-03-18 22:31:52 +0100446 type = bank->type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900447
Tomasz Figa499147c2013-03-18 22:31:52 +0100448 if (cfg_type >= PINCFG_TYPE_NUM || !type->fld_width[cfg_type])
Tomasz Figa7c367d32012-10-11 10:11:07 +0200449 return -EINVAL;
450
Tomasz Figa499147c2013-03-18 22:31:52 +0100451 width = type->fld_width[cfg_type];
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100452 cfg_reg = type->reg_offset[cfg_type];
Tomasz Figa499147c2013-03-18 22:31:52 +0100453
Chanho Park1f306ec2021-01-21 12:00:09 +0900454 raw_spin_lock_irqsave(&bank->slock, flags);
Tomasz Figa19846952013-03-18 22:31:50 +0100455
Thomas Abraham30574f02012-09-07 06:07:19 +0900456 mask = (1 << width) - 1;
457 shift = pin_offset * width;
458 data = readl(reg_base + cfg_reg);
459
460 if (set) {
461 cfg_value = PINCFG_UNPACK_VALUE(*config);
462 data &= ~(mask << shift);
463 data |= (cfg_value << shift);
464 writel(data, reg_base + cfg_reg);
465 } else {
466 data >>= shift;
467 data &= mask;
468 *config = PINCFG_PACK(cfg_type, data);
469 }
Tomasz Figa19846952013-03-18 22:31:50 +0100470
Chanho Park1f306ec2021-01-21 12:00:09 +0900471 raw_spin_unlock_irqrestore(&bank->slock, flags);
Tomasz Figa19846952013-03-18 22:31:50 +0100472
Thomas Abraham30574f02012-09-07 06:07:19 +0900473 return 0;
474}
475
476/* set the pin config settings for a specified pin */
477static int samsung_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Sherman Yin03b054e2013-08-27 11:32:12 -0700478 unsigned long *configs, unsigned num_configs)
Thomas Abraham30574f02012-09-07 06:07:19 +0900479{
Sherman Yin03b054e2013-08-27 11:32:12 -0700480 int i, ret;
481
482 for (i = 0; i < num_configs; i++) {
483 ret = samsung_pinconf_rw(pctldev, pin, &configs[i], true);
484 if (ret < 0)
485 return ret;
486 } /* for each config */
487
488 return 0;
Thomas Abraham30574f02012-09-07 06:07:19 +0900489}
490
491/* get the pin config settings for a specified pin */
492static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
493 unsigned long *config)
494{
495 return samsung_pinconf_rw(pctldev, pin, config, false);
496}
497
498/* set the pin config settings for a specified pin group */
499static int samsung_pinconf_group_set(struct pinctrl_dev *pctldev,
Sherman Yin03b054e2013-08-27 11:32:12 -0700500 unsigned group, unsigned long *configs,
501 unsigned num_configs)
Thomas Abraham30574f02012-09-07 06:07:19 +0900502{
503 struct samsung_pinctrl_drv_data *drvdata;
504 const unsigned int *pins;
505 unsigned int cnt;
506
507 drvdata = pinctrl_dev_get_drvdata(pctldev);
508 pins = drvdata->pin_groups[group].pins;
509
510 for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++)
Sherman Yin03b054e2013-08-27 11:32:12 -0700511 samsung_pinconf_set(pctldev, pins[cnt], configs, num_configs);
Thomas Abraham30574f02012-09-07 06:07:19 +0900512
513 return 0;
514}
515
516/* get the pin config settings for a specified pin group */
517static int samsung_pinconf_group_get(struct pinctrl_dev *pctldev,
518 unsigned int group, unsigned long *config)
519{
520 struct samsung_pinctrl_drv_data *drvdata;
521 const unsigned int *pins;
522
523 drvdata = pinctrl_dev_get_drvdata(pctldev);
524 pins = drvdata->pin_groups[group].pins;
525 samsung_pinconf_get(pctldev, pins[0], config);
526 return 0;
527}
528
529/* list of pinconfig callbacks for pinconfig vertical in the pinctrl code */
Laurent Pinchart022ab142013-02-16 10:25:07 +0100530static const struct pinconf_ops samsung_pinconf_ops = {
Thomas Abraham30574f02012-09-07 06:07:19 +0900531 .pin_config_get = samsung_pinconf_get,
532 .pin_config_set = samsung_pinconf_set,
533 .pin_config_group_get = samsung_pinconf_group_get,
534 .pin_config_group_set = samsung_pinconf_group_set,
535};
536
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900537/*
538 * The samsung_gpio_set_vlaue() should be called with "bank->slock" held
539 * to avoid race condition.
540 */
541static void samsung_gpio_set_value(struct gpio_chip *gc,
542 unsigned offset, int value)
Thomas Abraham30574f02012-09-07 06:07:19 +0900543{
Linus Walleij9f57f812015-12-08 10:18:50 +0100544 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
Tomasz Figa94ce9442014-09-23 21:05:39 +0200545 const struct samsung_pin_bank_type *type = bank->type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900546 void __iomem *reg;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200547 u32 data;
Thomas Abraham30574f02012-09-07 06:07:19 +0900548
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +0900549 reg = bank->pctl_base + bank->pctl_offset;
Tomasz Figa62f14c02012-10-11 10:11:08 +0200550
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100551 data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200552 data &= ~(1 << offset);
Thomas Abraham30574f02012-09-07 06:07:19 +0900553 if (value)
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200554 data |= 1 << offset;
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100555 writel(data, reg + type->reg_offset[PINCFG_TYPE_DAT]);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900556}
Tomasz Figa19846952013-03-18 22:31:50 +0100557
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900558/* gpiolib gpio_set callback function */
559static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
560{
561 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
562 unsigned long flags;
563
Chanho Park1f306ec2021-01-21 12:00:09 +0900564 raw_spin_lock_irqsave(&bank->slock, flags);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900565 samsung_gpio_set_value(gc, offset, value);
Chanho Park1f306ec2021-01-21 12:00:09 +0900566 raw_spin_unlock_irqrestore(&bank->slock, flags);
Thomas Abraham30574f02012-09-07 06:07:19 +0900567}
568
569/* gpiolib gpio_get callback function */
570static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset)
571{
572 void __iomem *reg;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200573 u32 data;
Linus Walleij9f57f812015-12-08 10:18:50 +0100574 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
Tomasz Figa94ce9442014-09-23 21:05:39 +0200575 const struct samsung_pin_bank_type *type = bank->type;
Thomas Abraham30574f02012-09-07 06:07:19 +0900576
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +0900577 reg = bank->pctl_base + bank->pctl_offset;
Tomasz Figa62f14c02012-10-11 10:11:08 +0200578
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100579 data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200580 data >>= offset;
Thomas Abraham30574f02012-09-07 06:07:19 +0900581 data &= 1;
582 return data;
583}
584
585/*
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900586 * The samsung_gpio_set_direction() should be called with "bank->slock" held
587 * to avoid race condition.
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200588 * The calls to gpio_direction_output() and gpio_direction_input()
589 * leads to this function call.
Thomas Abraham30574f02012-09-07 06:07:19 +0900590 */
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200591static int samsung_gpio_set_direction(struct gpio_chip *gc,
592 unsigned offset, bool input)
Thomas Abraham30574f02012-09-07 06:07:19 +0900593{
Tomasz Figa94ce9442014-09-23 21:05:39 +0200594 const struct samsung_pin_bank_type *type;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200595 struct samsung_pin_bank *bank;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200596 void __iomem *reg;
597 u32 data, mask, shift;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200598
Linus Walleij9f57f812015-12-08 10:18:50 +0100599 bank = gpiochip_get_data(gc);
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200600 type = bank->type;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200601
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +0900602 reg = bank->pctl_base + bank->pctl_offset
603 + type->reg_offset[PINCFG_TYPE_FUNC];
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200604
605 mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
606 shift = offset * type->fld_width[PINCFG_TYPE_FUNC];
607 if (shift >= 32) {
608 /* Some banks have two config registers */
609 shift -= 32;
610 reg += 4;
611 }
612
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200613 data = readl(reg);
614 data &= ~(mask << shift);
615 if (!input)
Krzysztof Kozlowski4460dc22017-06-15 17:06:28 +0200616 data |= EXYNOS_PIN_FUNC_OUTPUT << shift;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200617 writel(data, reg);
618
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200619 return 0;
Thomas Abraham30574f02012-09-07 06:07:19 +0900620}
621
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200622/* gpiolib gpio_direction_input callback function. */
623static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
624{
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900625 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
626 unsigned long flags;
627 int ret;
628
Chanho Park1f306ec2021-01-21 12:00:09 +0900629 raw_spin_lock_irqsave(&bank->slock, flags);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900630 ret = samsung_gpio_set_direction(gc, offset, true);
Chanho Park1f306ec2021-01-21 12:00:09 +0900631 raw_spin_unlock_irqrestore(&bank->slock, flags);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900632 return ret;
Tomasz Figa18c28ca2014-07-02 17:40:59 +0200633}
634
635/* gpiolib gpio_direction_output callback function. */
Thomas Abraham30574f02012-09-07 06:07:19 +0900636static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
637 int value)
638{
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900639 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
640 unsigned long flags;
641 int ret;
642
Chanho Park1f306ec2021-01-21 12:00:09 +0900643 raw_spin_lock_irqsave(&bank->slock, flags);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900644 samsung_gpio_set_value(gc, offset, value);
645 ret = samsung_gpio_set_direction(gc, offset, false);
Chanho Park1f306ec2021-01-21 12:00:09 +0900646 raw_spin_unlock_irqrestore(&bank->slock, flags);
Youngmin Namd9ff0eb2016-02-09 00:49:28 +0900647
648 return ret;
Thomas Abraham30574f02012-09-07 06:07:19 +0900649}
650
651/*
Tomasz Figaa19fe2d2012-10-11 10:11:20 +0200652 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
653 * and a virtual IRQ, if not already present.
654 */
655static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
656{
Linus Walleij9f57f812015-12-08 10:18:50 +0100657 struct samsung_pin_bank *bank = gpiochip_get_data(gc);
Tomasz Figaa19fe2d2012-10-11 10:11:20 +0200658 unsigned int virq;
659
660 if (!bank->irq_domain)
661 return -ENXIO;
662
663 virq = irq_create_mapping(bank->irq_domain, offset);
664
665 return (virq) ? : -ENXIO;
666}
667
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200668static struct samsung_pin_group *samsung_pinctrl_create_groups(
669 struct device *dev,
670 struct samsung_pinctrl_drv_data *drvdata,
671 unsigned int *cnt)
Thomas Abraham30574f02012-09-07 06:07:19 +0900672{
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200673 struct pinctrl_desc *ctrldesc = &drvdata->pctl;
Thomas Abraham30574f02012-09-07 06:07:19 +0900674 struct samsung_pin_group *groups, *grp;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200675 const struct pinctrl_pin_desc *pdesc;
676 int i;
Thomas Abraham30574f02012-09-07 06:07:19 +0900677
Kees Cooka86854d2018-06-12 14:07:58 -0700678 groups = devm_kcalloc(dev, ctrldesc->npins, sizeof(*groups),
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200679 GFP_KERNEL);
680 if (!groups)
681 return ERR_PTR(-EINVAL);
Thomas Abraham30574f02012-09-07 06:07:19 +0900682 grp = groups;
683
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200684 pdesc = ctrldesc->pins;
685 for (i = 0; i < ctrldesc->npins; ++i, ++pdesc, ++grp) {
686 grp->name = pdesc->name;
687 grp->pins = &pdesc->number;
688 grp->num_pins = 1;
689 }
690
691 *cnt = ctrldesc->npins;
692 return groups;
693}
694
695static int samsung_pinctrl_create_function(struct device *dev,
696 struct samsung_pinctrl_drv_data *drvdata,
697 struct device_node *func_np,
698 struct samsung_pmx_func *func)
699{
700 int npins;
701 int ret;
702 int i;
703
704 if (of_property_read_u32(func_np, "samsung,pin-function", &func->val))
705 return 0;
706
707 npins = of_property_count_strings(func_np, "samsung,pins");
708 if (npins < 1) {
Rob Herringf5292d02017-07-18 16:43:23 -0500709 dev_err(dev, "invalid pin list in %pOFn node", func_np);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200710 return -EINVAL;
711 }
712
713 func->name = func_np->full_name;
714
Kees Cooka86854d2018-06-12 14:07:58 -0700715 func->groups = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200716 if (!func->groups)
717 return -ENOMEM;
718
719 for (i = 0; i < npins; ++i) {
720 const char *gname;
721
722 ret = of_property_read_string_index(func_np, "samsung,pins",
723 i, &gname);
724 if (ret) {
725 dev_err(dev,
Rob Herringf5292d02017-07-18 16:43:23 -0500726 "failed to read pin name %d from %pOFn node\n",
727 i, func_np);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200728 return ret;
729 }
730
731 func->groups[i] = gname;
732 }
733
734 func->num_groups = npins;
735 return 1;
736}
737
738static struct samsung_pmx_func *samsung_pinctrl_create_functions(
739 struct device *dev,
740 struct samsung_pinctrl_drv_data *drvdata,
741 unsigned int *cnt)
742{
743 struct samsung_pmx_func *functions, *func;
744 struct device_node *dev_np = dev->of_node;
745 struct device_node *cfg_np;
746 unsigned int func_cnt = 0;
747 int ret;
748
749 /*
750 * Iterate over all the child nodes of the pin controller node
751 * and create pin groups and pin function lists.
752 */
753 for_each_child_of_node(dev_np, cfg_np) {
754 struct device_node *func_np;
755
756 if (!of_get_child_count(cfg_np)) {
757 if (!of_find_property(cfg_np,
758 "samsung,pin-function", NULL))
759 continue;
760 ++func_cnt;
761 continue;
762 }
763
764 for_each_child_of_node(cfg_np, func_np) {
765 if (!of_find_property(func_np,
766 "samsung,pin-function", NULL))
767 continue;
768 ++func_cnt;
769 }
770 }
771
Kees Cooka86854d2018-06-12 14:07:58 -0700772 functions = devm_kcalloc(dev, func_cnt, sizeof(*functions),
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200773 GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +0100774 if (!functions)
Marek Szyprowski1f7b8ea2017-01-19 14:48:46 +0100775 return ERR_PTR(-ENOMEM);
Thomas Abraham30574f02012-09-07 06:07:19 +0900776 func = functions;
777
778 /*
779 * Iterate over all the child nodes of the pin controller node
780 * and create pin groups and pin function lists.
781 */
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200782 func_cnt = 0;
Thomas Abraham30574f02012-09-07 06:07:19 +0900783 for_each_child_of_node(dev_np, cfg_np) {
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200784 struct device_node *func_np;
785
786 if (!of_get_child_count(cfg_np)) {
787 ret = samsung_pinctrl_create_function(dev, drvdata,
788 cfg_np, func);
Krzysztof Kozlowskia322b332019-08-05 18:27:10 +0200789 if (ret < 0) {
790 of_node_put(cfg_np);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200791 return ERR_PTR(ret);
Krzysztof Kozlowskia322b332019-08-05 18:27:10 +0200792 }
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200793 if (ret > 0) {
794 ++func;
795 ++func_cnt;
796 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900797 continue;
Thomas Abraham30574f02012-09-07 06:07:19 +0900798 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900799
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200800 for_each_child_of_node(cfg_np, func_np) {
801 ret = samsung_pinctrl_create_function(dev, drvdata,
802 func_np, func);
Krzysztof Kozlowskia322b332019-08-05 18:27:10 +0200803 if (ret < 0) {
804 of_node_put(func_np);
805 of_node_put(cfg_np);
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200806 return ERR_PTR(ret);
Krzysztof Kozlowskia322b332019-08-05 18:27:10 +0200807 }
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200808 if (ret > 0) {
809 ++func;
810 ++func_cnt;
811 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900812 }
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200813 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900814
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200815 *cnt = func_cnt;
816 return functions;
817}
818
819/*
820 * Parse the information about all the available pin groups and pin functions
821 * from device node of the pin-controller. A pin group is formed with all
822 * the pins listed in the "samsung,pins" property.
823 */
824
825static int samsung_pinctrl_parse_dt(struct platform_device *pdev,
826 struct samsung_pinctrl_drv_data *drvdata)
827{
828 struct device *dev = &pdev->dev;
829 struct samsung_pin_group *groups;
830 struct samsung_pmx_func *functions;
831 unsigned int grp_cnt = 0, func_cnt = 0;
832
833 groups = samsung_pinctrl_create_groups(dev, drvdata, &grp_cnt);
834 if (IS_ERR(groups)) {
835 dev_err(dev, "failed to parse pin groups\n");
836 return PTR_ERR(groups);
837 }
838
839 functions = samsung_pinctrl_create_functions(dev, drvdata, &func_cnt);
840 if (IS_ERR(functions)) {
841 dev_err(dev, "failed to parse pin functions\n");
Fabio Estevam44a074f2015-06-01 09:57:04 -0300842 return PTR_ERR(functions);
Thomas Abraham30574f02012-09-07 06:07:19 +0900843 }
844
845 drvdata->pin_groups = groups;
846 drvdata->nr_groups = grp_cnt;
847 drvdata->pmx_functions = functions;
Tomasz Figa9a2c1c32014-07-02 17:41:03 +0200848 drvdata->nr_functions = func_cnt;
Thomas Abraham30574f02012-09-07 06:07:19 +0900849
850 return 0;
851}
852
853/* register the pinctrl interface with the pinctrl subsystem */
Greg Kroah-Hartman150632b2012-12-21 13:10:23 -0800854static int samsung_pinctrl_register(struct platform_device *pdev,
855 struct samsung_pinctrl_drv_data *drvdata)
Thomas Abraham30574f02012-09-07 06:07:19 +0900856{
857 struct pinctrl_desc *ctrldesc = &drvdata->pctl;
858 struct pinctrl_pin_desc *pindesc, *pdesc;
859 struct samsung_pin_bank *pin_bank;
860 char *pin_names;
861 int pin, bank, ret;
862
863 ctrldesc->name = "samsung-pinctrl";
864 ctrldesc->owner = THIS_MODULE;
865 ctrldesc->pctlops = &samsung_pctrl_ops;
866 ctrldesc->pmxops = &samsung_pinmux_ops;
867 ctrldesc->confops = &samsung_pinconf_ops;
868
Kees Cooka86854d2018-06-12 14:07:58 -0700869 pindesc = devm_kcalloc(&pdev->dev,
870 drvdata->nr_pins, sizeof(*pindesc),
871 GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +0100872 if (!pindesc)
Thomas Abraham30574f02012-09-07 06:07:19 +0900873 return -ENOMEM;
Thomas Abraham30574f02012-09-07 06:07:19 +0900874 ctrldesc->pins = pindesc;
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200875 ctrldesc->npins = drvdata->nr_pins;
Thomas Abraham30574f02012-09-07 06:07:19 +0900876
877 /* dynamically populate the pin number and pin name for pindesc */
878 for (pin = 0, pdesc = pindesc; pin < ctrldesc->npins; pin++, pdesc++)
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200879 pdesc->number = pin + drvdata->pin_base;
Thomas Abraham30574f02012-09-07 06:07:19 +0900880
881 /*
882 * allocate space for storing the dynamically generated names for all
883 * the pins which belong to this pin-controller.
884 */
Kees Cooka86854d2018-06-12 14:07:58 -0700885 pin_names = devm_kzalloc(&pdev->dev,
886 array3_size(sizeof(char), PIN_NAME_LENGTH,
887 drvdata->nr_pins),
888 GFP_KERNEL);
Marek Szyprowskifa5c0f42017-01-19 14:48:45 +0100889 if (!pin_names)
Thomas Abraham30574f02012-09-07 06:07:19 +0900890 return -ENOMEM;
Thomas Abraham30574f02012-09-07 06:07:19 +0900891
892 /* for each pin, the name of the pin is pin-bank name + pin number */
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200893 for (bank = 0; bank < drvdata->nr_banks; bank++) {
894 pin_bank = &drvdata->pin_banks[bank];
Thomas Abraham30574f02012-09-07 06:07:19 +0900895 for (pin = 0; pin < pin_bank->nr_pins; pin++) {
896 sprintf(pin_names, "%s-%d", pin_bank->name, pin);
897 pdesc = pindesc + pin_bank->pin_base + pin;
898 pdesc->name = pin_names;
899 pin_names += PIN_NAME_LENGTH;
900 }
901 }
902
Tomasz Figa529301c2013-08-20 18:16:21 +0200903 ret = samsung_pinctrl_parse_dt(pdev, drvdata);
904 if (ret)
905 return ret;
906
Laxman Dewangan9ed19e02016-02-28 14:36:42 +0530907 drvdata->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc,
908 drvdata);
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900909 if (IS_ERR(drvdata->pctl_dev)) {
Thomas Abraham30574f02012-09-07 06:07:19 +0900910 dev_err(&pdev->dev, "could not register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900911 return PTR_ERR(drvdata->pctl_dev);
Thomas Abraham30574f02012-09-07 06:07:19 +0900912 }
913
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200914 for (bank = 0; bank < drvdata->nr_banks; ++bank) {
915 pin_bank = &drvdata->pin_banks[bank];
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200916 pin_bank->grange.name = pin_bank->name;
917 pin_bank->grange.id = bank;
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200918 pin_bank->grange.pin_base = drvdata->pin_base
Tomasz Figa6c6ce622014-07-02 17:41:00 +0200919 + pin_bank->pin_base;
Charles Keepax1abd18d2017-03-22 17:15:34 +0000920 pin_bank->grange.base = pin_bank->grange.pin_base;
Jaehyoung Choi70115552021-07-30 22:29:05 +0300921 pin_bank->grange.npins = pin_bank->nr_pins;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200922 pin_bank->grange.gc = &pin_bank->gpio_chip;
923 pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange);
924 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900925
Thomas Abraham30574f02012-09-07 06:07:19 +0900926 return 0;
927}
928
Charles Keepax1abd18d2017-03-22 17:15:34 +0000929/* unregister the pinctrl interface with the pinctrl subsystem */
930static int samsung_pinctrl_unregister(struct platform_device *pdev,
931 struct samsung_pinctrl_drv_data *drvdata)
932{
933 struct samsung_pin_bank *bank = drvdata->pin_banks;
934 int i;
935
936 for (i = 0; i < drvdata->nr_banks; ++i, ++bank)
937 pinctrl_remove_gpio_range(drvdata->pctl_dev, &bank->grange);
938
939 return 0;
940}
941
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200942static const struct gpio_chip samsung_gpiolib_chip = {
Jonas Gorski98c85d52015-10-11 17:34:19 +0200943 .request = gpiochip_generic_request,
944 .free = gpiochip_generic_free,
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200945 .set = samsung_gpio_set,
946 .get = samsung_gpio_get,
947 .direction_input = samsung_gpio_direction_input,
948 .direction_output = samsung_gpio_direction_output,
Tomasz Figaa19fe2d2012-10-11 10:11:20 +0200949 .to_irq = samsung_gpio_to_irq,
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200950 .owner = THIS_MODULE,
951};
952
Thomas Abraham30574f02012-09-07 06:07:19 +0900953/* register the gpiolib interface with the gpiolib subsystem */
Greg Kroah-Hartman150632b2012-12-21 13:10:23 -0800954static int samsung_gpiolib_register(struct platform_device *pdev,
955 struct samsung_pinctrl_drv_data *drvdata)
Thomas Abraham30574f02012-09-07 06:07:19 +0900956{
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200957 struct samsung_pin_bank *bank = drvdata->pin_banks;
Thomas Abraham30574f02012-09-07 06:07:19 +0900958 struct gpio_chip *gc;
959 int ret;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200960 int i;
Thomas Abraham30574f02012-09-07 06:07:19 +0900961
Tomasz Figa1bf00d72014-09-23 21:05:40 +0200962 for (i = 0; i < drvdata->nr_banks; ++i, ++bank) {
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200963 bank->gpio_chip = samsung_gpiolib_chip;
Thomas Abraham30574f02012-09-07 06:07:19 +0900964
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200965 gc = &bank->gpio_chip;
Charles Keepax1abd18d2017-03-22 17:15:34 +0000966 gc->base = bank->grange.base;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200967 gc->ngpio = bank->nr_pins;
Linus Walleij58383c782015-11-04 09:56:26 +0100968 gc->parent = &pdev->dev;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200969 gc->of_node = bank->of_node;
970 gc->label = bank->name;
971
Charles Keepaxf69ae4f2017-03-22 17:15:35 +0000972 ret = devm_gpiochip_add_data(&pdev->dev, gc, bank);
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200973 if (ret) {
974 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
975 gc->label, ret);
Charles Keepaxf69ae4f2017-03-22 17:15:35 +0000976 return ret;
Tomasz Figad3a7b9e2012-10-11 10:11:17 +0200977 }
Thomas Abraham30574f02012-09-07 06:07:19 +0900978 }
979
980 return 0;
Thomas Abraham30574f02012-09-07 06:07:19 +0900981}
982
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +0100983static const struct samsung_pin_ctrl *
984samsung_pinctrl_get_soc_data_for_of_alias(struct platform_device *pdev)
985{
986 struct device_node *node = pdev->dev.of_node;
987 const struct samsung_pinctrl_of_match_data *of_data;
988 int id;
989
990 id = of_alias_get_id(node, "pinctrl");
991 if (id < 0) {
992 dev_err(&pdev->dev, "failed to get alias id\n");
993 return NULL;
994 }
995
996 of_data = of_device_get_match_data(&pdev->dev);
997 if (id >= of_data->num_ctrl) {
998 dev_err(&pdev->dev, "invalid alias id %d\n", id);
999 return NULL;
1000 }
1001
1002 return &(of_data->ctrl[id]);
1003}
1004
Thomas Abraham30574f02012-09-07 06:07:19 +09001005/* retrieve the soc specific data */
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001006static const struct samsung_pin_ctrl *
1007samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
1008 struct platform_device *pdev)
Thomas Abraham30574f02012-09-07 06:07:19 +09001009{
Tomasz Figa6defe9a2012-10-11 10:11:14 +02001010 struct device_node *node = pdev->dev.of_node;
Tomasz Figaab663782012-10-11 10:11:13 +02001011 struct device_node *np;
Tomasz Figa8100cf42014-09-23 21:05:41 +02001012 const struct samsung_pin_bank_data *bdata;
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001013 const struct samsung_pin_ctrl *ctrl;
Tomasz Figa40ba6222012-10-11 10:11:09 +02001014 struct samsung_pin_bank *bank;
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001015 struct resource *res;
1016 void __iomem *virt_base[SAMSUNG_PINCTRL_NUM_RESOURCES];
Krzysztof Kozlowski52d0ed02017-06-15 18:33:15 +02001017 unsigned int i;
Thomas Abraham30574f02012-09-07 06:07:19 +09001018
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001019 ctrl = samsung_pinctrl_get_soc_data_for_of_alias(pdev);
1020 if (!ctrl)
Tomasz Figa87993272014-09-23 21:05:37 +02001021 return ERR_PTR(-ENOENT);
Tomasz Figa40ba6222012-10-11 10:11:09 +02001022
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001023 d->suspend = ctrl->suspend;
1024 d->resume = ctrl->resume;
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001025 d->nr_banks = ctrl->nr_banks;
Tomasz Figa8100cf42014-09-23 21:05:41 +02001026 d->pin_banks = devm_kcalloc(&pdev->dev, d->nr_banks,
1027 sizeof(*d->pin_banks), GFP_KERNEL);
1028 if (!d->pin_banks)
1029 return ERR_PTR(-ENOMEM);
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001030
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001031 if (ctrl->nr_ext_resources + 1 > SAMSUNG_PINCTRL_NUM_RESOURCES)
1032 return ERR_PTR(-EINVAL);
1033
1034 for (i = 0; i < ctrl->nr_ext_resources + 1; i++) {
1035 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
Andrzej Hajda59f34e82017-02-23 11:12:40 +01001036 if (!res) {
1037 dev_err(&pdev->dev, "failed to get mem%d resource\n", i);
1038 return ERR_PTR(-EINVAL);
1039 }
1040 virt_base[i] = devm_ioremap(&pdev->dev, res->start,
1041 resource_size(res));
1042 if (!virt_base[i]) {
1043 dev_err(&pdev->dev, "failed to ioremap %pR\n", res);
1044 return ERR_PTR(-EIO);
1045 }
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001046 }
1047
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001048 bank = d->pin_banks;
Tomasz Figa8100cf42014-09-23 21:05:41 +02001049 bdata = ctrl->pin_banks;
1050 for (i = 0; i < ctrl->nr_banks; ++i, ++bdata, ++bank) {
1051 bank->type = bdata->type;
1052 bank->pctl_offset = bdata->pctl_offset;
1053 bank->nr_pins = bdata->nr_pins;
1054 bank->eint_func = bdata->eint_func;
1055 bank->eint_type = bdata->eint_type;
1056 bank->eint_mask = bdata->eint_mask;
1057 bank->eint_offset = bdata->eint_offset;
1058 bank->name = bdata->name;
1059
Chanho Park1f306ec2021-01-21 12:00:09 +09001060 raw_spin_lock_init(&bank->slock);
Tomasz Figa6defe9a2012-10-11 10:11:14 +02001061 bank->drvdata = d;
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001062 bank->pin_base = d->nr_pins;
1063 d->nr_pins += bank->nr_pins;
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001064
1065 bank->eint_base = virt_base[0];
1066 bank->pctl_base = virt_base[bdata->pctl_res_idx];
Tomasz Figa40ba6222012-10-11 10:11:09 +02001067 }
Krzysztof Kozlowskicee74132017-06-15 17:46:37 +02001068 /*
1069 * Legacy platforms should provide only one resource with IO memory.
1070 * Store it as virt_base because legacy driver needs to access it
1071 * through samsung_pinctrl_drv_data.
1072 */
1073 d->virt_base = virt_base[0];
Tomasz Figa40ba6222012-10-11 10:11:09 +02001074
Tomasz Figaab663782012-10-11 10:11:13 +02001075 for_each_child_of_node(node, np) {
1076 if (!of_find_property(np, "gpio-controller", NULL))
1077 continue;
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001078 bank = d->pin_banks;
1079 for (i = 0; i < d->nr_banks; ++i, ++bank) {
Rob Herringeaeee372018-12-05 13:50:36 -06001080 if (of_node_name_eq(np, bank->name)) {
Tomasz Figaab663782012-10-11 10:11:13 +02001081 bank->of_node = np;
1082 break;
1083 }
1084 }
1085 }
1086
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001087 d->pin_base = pin_base;
1088 pin_base += d->nr_pins;
Tomasz Figa40ba6222012-10-11 10:11:09 +02001089
1090 return ctrl;
Thomas Abraham30574f02012-09-07 06:07:19 +09001091}
1092
Greg Kroah-Hartman150632b2012-12-21 13:10:23 -08001093static int samsung_pinctrl_probe(struct platform_device *pdev)
Thomas Abraham30574f02012-09-07 06:07:19 +09001094{
1095 struct samsung_pinctrl_drv_data *drvdata;
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001096 const struct samsung_pin_ctrl *ctrl;
Thomas Abraham30574f02012-09-07 06:07:19 +09001097 struct device *dev = &pdev->dev;
Thomas Abraham30574f02012-09-07 06:07:19 +09001098 int ret;
1099
Thomas Abraham30574f02012-09-07 06:07:19 +09001100 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
Sylwester Nawrockib09eed72016-09-01 13:59:00 +02001101 if (!drvdata)
Thomas Abraham30574f02012-09-07 06:07:19 +09001102 return -ENOMEM;
Tomasz Figa6defe9a2012-10-11 10:11:14 +02001103
1104 ctrl = samsung_pinctrl_get_soc_data(drvdata, pdev);
Tomasz Figa87993272014-09-23 21:05:37 +02001105 if (IS_ERR(ctrl)) {
Tomasz Figa6defe9a2012-10-11 10:11:14 +02001106 dev_err(&pdev->dev, "driver data not available\n");
Tomasz Figa87993272014-09-23 21:05:37 +02001107 return PTR_ERR(ctrl);
Tomasz Figa6defe9a2012-10-11 10:11:14 +02001108 }
Thomas Abraham30574f02012-09-07 06:07:19 +09001109 drvdata->dev = dev;
1110
Lad Prabhakara382d562021-12-24 14:57:47 +00001111 ret = platform_get_irq_optional(pdev, 0);
1112 if (ret < 0 && ret != -ENXIO)
1113 return ret;
1114 if (ret > 0)
1115 drvdata->irq = ret;
Thomas Abraham30574f02012-09-07 06:07:19 +09001116
Marek Szyprowski1fc8ad82017-01-26 10:29:24 +01001117 if (ctrl->retention_data) {
1118 drvdata->retention_ctrl = ctrl->retention_data->init(drvdata,
1119 ctrl->retention_data);
1120 if (IS_ERR(drvdata->retention_ctrl))
1121 return PTR_ERR(drvdata->retention_ctrl);
1122 }
1123
Charles Keepax1abd18d2017-03-22 17:15:34 +00001124 ret = samsung_pinctrl_register(pdev, drvdata);
Thomas Abraham30574f02012-09-07 06:07:19 +09001125 if (ret)
1126 return ret;
1127
Charles Keepax1abd18d2017-03-22 17:15:34 +00001128 ret = samsung_gpiolib_register(pdev, drvdata);
Thomas Abraham30574f02012-09-07 06:07:19 +09001129 if (ret) {
Charles Keepax1abd18d2017-03-22 17:15:34 +00001130 samsung_pinctrl_unregister(pdev, drvdata);
Thomas Abraham30574f02012-09-07 06:07:19 +09001131 return ret;
1132 }
1133
1134 if (ctrl->eint_gpio_init)
1135 ctrl->eint_gpio_init(drvdata);
1136 if (ctrl->eint_wkup_init)
1137 ctrl->eint_wkup_init(drvdata);
1138
1139 platform_set_drvdata(pdev, drvdata);
Doug Andersond9f99862013-05-16 21:33:18 -07001140
Thomas Abraham30574f02012-09-07 06:07:19 +09001141 return 0;
1142}
1143
Lee Jones84a3fce2020-07-13 15:49:11 +01001144/*
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001145 * samsung_pinctrl_suspend - save pinctrl state for suspend
Doug Andersond9f99862013-05-16 21:33:18 -07001146 *
1147 * Save data for all banks handled by this device.
1148 */
Arnd Bergmann304c92e2017-02-01 17:16:24 +01001149static int __maybe_unused samsung_pinctrl_suspend(struct device *dev)
Doug Andersond9f99862013-05-16 21:33:18 -07001150{
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001151 struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev);
Doug Andersond9f99862013-05-16 21:33:18 -07001152 int i;
1153
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001154 for (i = 0; i < drvdata->nr_banks; i++) {
1155 struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001156 void __iomem *reg = bank->pctl_base + bank->pctl_offset;
Tomasz Figa94ce9442014-09-23 21:05:39 +02001157 const u8 *offs = bank->type->reg_offset;
1158 const u8 *widths = bank->type->fld_width;
Doug Andersond9f99862013-05-16 21:33:18 -07001159 enum pincfg_type type;
1160
1161 /* Registers without a powerdown config aren't lost */
1162 if (!widths[PINCFG_TYPE_CON_PDN])
1163 continue;
1164
1165 for (type = 0; type < PINCFG_TYPE_NUM; type++)
1166 if (widths[type])
1167 bank->pm_save[type] = readl(reg + offs[type]);
1168
1169 if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
1170 /* Some banks have two config registers */
1171 bank->pm_save[PINCFG_TYPE_NUM] =
1172 readl(reg + offs[PINCFG_TYPE_FUNC] + 4);
1173 pr_debug("Save %s @ %p (con %#010x %08x)\n",
1174 bank->name, reg,
1175 bank->pm_save[PINCFG_TYPE_FUNC],
1176 bank->pm_save[PINCFG_TYPE_NUM]);
1177 } else {
1178 pr_debug("Save %s @ %p (con %#010x)\n", bank->name,
1179 reg, bank->pm_save[PINCFG_TYPE_FUNC]);
1180 }
1181 }
Tomasz Figa21c21992013-05-17 18:24:30 +02001182
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001183 if (drvdata->suspend)
1184 drvdata->suspend(drvdata);
Marek Szyprowski1fc8ad82017-01-26 10:29:24 +01001185 if (drvdata->retention_ctrl && drvdata->retention_ctrl->enable)
1186 drvdata->retention_ctrl->enable(drvdata);
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001187
1188 return 0;
Doug Andersond9f99862013-05-16 21:33:18 -07001189}
1190
Lee Jones84a3fce2020-07-13 15:49:11 +01001191/*
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001192 * samsung_pinctrl_resume - restore pinctrl state from suspend
Doug Andersond9f99862013-05-16 21:33:18 -07001193 *
1194 * Restore one of the banks that was saved during suspend.
1195 *
1196 * We don't bother doing anything complicated to avoid glitching lines since
1197 * we're called before pad retention is turned off.
1198 */
Arnd Bergmann304c92e2017-02-01 17:16:24 +01001199static int __maybe_unused samsung_pinctrl_resume(struct device *dev)
Doug Andersond9f99862013-05-16 21:33:18 -07001200{
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001201 struct samsung_pinctrl_drv_data *drvdata = dev_get_drvdata(dev);
Doug Andersond9f99862013-05-16 21:33:18 -07001202 int i;
1203
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001204 if (drvdata->resume)
1205 drvdata->resume(drvdata);
Tomasz Figa21c21992013-05-17 18:24:30 +02001206
Tomasz Figa1bf00d72014-09-23 21:05:40 +02001207 for (i = 0; i < drvdata->nr_banks; i++) {
1208 struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
Chanwoo Choi8b1bd11c2016-11-09 17:40:10 +09001209 void __iomem *reg = bank->pctl_base + bank->pctl_offset;
Tomasz Figa94ce9442014-09-23 21:05:39 +02001210 const u8 *offs = bank->type->reg_offset;
1211 const u8 *widths = bank->type->fld_width;
Doug Andersond9f99862013-05-16 21:33:18 -07001212 enum pincfg_type type;
1213
1214 /* Registers without a powerdown config aren't lost */
1215 if (!widths[PINCFG_TYPE_CON_PDN])
1216 continue;
1217
1218 if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
1219 /* Some banks have two config registers */
1220 pr_debug("%s @ %p (con %#010x %08x => %#010x %08x)\n",
1221 bank->name, reg,
1222 readl(reg + offs[PINCFG_TYPE_FUNC]),
1223 readl(reg + offs[PINCFG_TYPE_FUNC] + 4),
1224 bank->pm_save[PINCFG_TYPE_FUNC],
1225 bank->pm_save[PINCFG_TYPE_NUM]);
1226 writel(bank->pm_save[PINCFG_TYPE_NUM],
1227 reg + offs[PINCFG_TYPE_FUNC] + 4);
1228 } else {
1229 pr_debug("%s @ %p (con %#010x => %#010x)\n", bank->name,
1230 reg, readl(reg + offs[PINCFG_TYPE_FUNC]),
1231 bank->pm_save[PINCFG_TYPE_FUNC]);
1232 }
1233 for (type = 0; type < PINCFG_TYPE_NUM; type++)
1234 if (widths[type])
1235 writel(bank->pm_save[type], reg + offs[type]);
1236 }
Marek Szyprowski1fc8ad82017-01-26 10:29:24 +01001237
1238 if (drvdata->retention_ctrl && drvdata->retention_ctrl->disable)
1239 drvdata->retention_ctrl->disable(drvdata);
Doug Andersond9f99862013-05-16 21:33:18 -07001240
1241 return 0;
1242}
Doug Andersond9f99862013-05-16 21:33:18 -07001243
Thomas Abraham30574f02012-09-07 06:07:19 +09001244static const struct of_device_id samsung_pinctrl_dt_match[] = {
Krzysztof Kozlowskicfa76dd2017-05-16 20:56:27 +02001245#ifdef CONFIG_PINCTRL_EXYNOS_ARM
Tomasz Figad97f5b92014-04-14 10:45:47 +09001246 { .compatible = "samsung,exynos3250-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001247 .data = &exynos3250_of_data },
Kukjin Kimb533c862013-01-02 16:05:42 -08001248 { .compatible = "samsung,exynos4210-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001249 .data = &exynos4210_of_data },
Kukjin Kimb533c862013-01-02 16:05:42 -08001250 { .compatible = "samsung,exynos4x12-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001251 .data = &exynos4x12_of_data },
Thomas Abrahamf67faf42012-12-28 10:37:27 -08001252 { .compatible = "samsung,exynos5250-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001253 .data = &exynos5250_of_data },
Young-Gun Jang9a8b6072014-02-05 11:51:28 +05301254 { .compatible = "samsung,exynos5260-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001255 .data = &exynos5260_of_data },
Hakjoo Kim023e06d2015-03-15 23:00:32 +01001256 { .compatible = "samsung,exynos5410-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001257 .data = &exynos5410_of_data },
Leela Krishna Amudala983dbeb2013-06-19 22:16:26 +09001258 { .compatible = "samsung,exynos5420-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001259 .data = &exynos5420_of_data },
Mateusz Krawczuk608a26a2013-08-27 15:08:10 +02001260 { .compatible = "samsung,s5pv210-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001261 .data = &s5pv210_of_data },
Krzysztof Kozlowskicfa76dd2017-05-16 20:56:27 +02001262#endif
1263#ifdef CONFIG_PINCTRL_EXYNOS_ARM64
1264 { .compatible = "samsung,exynos5433-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001265 .data = &exynos5433_of_data },
Naveen Krishna Ch50cea0c2014-10-09 19:24:32 +05301266 { .compatible = "samsung,exynos7-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001267 .data = &exynos7_of_data },
David Viragb0ef7b12021-11-01 00:17:19 +01001268 { .compatible = "samsung,exynos7885-pinctrl",
1269 .data = &exynos7885_of_data },
Sam Protsenkocdd3d942021-08-11 14:48:22 +03001270 { .compatible = "samsung,exynos850-pinctrl",
1271 .data = &exynos850_of_data },
Chanho Park02725b02021-10-17 19:19:12 +02001272 { .compatible = "samsung,exynosautov9-pinctrl",
1273 .data = &exynosautov9_of_data },
Tomasz Figad5517be2013-03-18 22:31:51 +01001274#endif
Tomasz Figa61dd7262013-03-18 22:31:55 +01001275#ifdef CONFIG_PINCTRL_S3C64XX
1276 { .compatible = "samsung,s3c64xx-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001277 .data = &s3c64xx_of_data },
Tomasz Figa61dd7262013-03-18 22:31:55 +01001278#endif
Heiko Stuebneraf99a752013-05-21 00:56:13 +09001279#ifdef CONFIG_PINCTRL_S3C24XX
1280 { .compatible = "samsung,s3c2412-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001281 .data = &s3c2412_of_data },
Heiko Stuebneraf99a752013-05-21 00:56:13 +09001282 { .compatible = "samsung,s3c2416-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001283 .data = &s3c2416_of_data },
Heiko Stuebneraf99a752013-05-21 00:56:13 +09001284 { .compatible = "samsung,s3c2440-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001285 .data = &s3c2440_of_data },
Heiko Stuebneraf99a752013-05-21 00:56:13 +09001286 { .compatible = "samsung,s3c2450-pinctrl",
Krzysztof Kozlowski93b0bea2018-02-20 19:17:51 +01001287 .data = &s3c2450_of_data },
Heiko Stuebneraf99a752013-05-21 00:56:13 +09001288#endif
Thomas Abraham30574f02012-09-07 06:07:19 +09001289 {},
1290};
Thomas Abraham30574f02012-09-07 06:07:19 +09001291
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001292static const struct dev_pm_ops samsung_pinctrl_pm_ops = {
1293 SET_LATE_SYSTEM_SLEEP_PM_OPS(samsung_pinctrl_suspend,
1294 samsung_pinctrl_resume)
1295};
1296
Thomas Abraham30574f02012-09-07 06:07:19 +09001297static struct platform_driver samsung_pinctrl_driver = {
1298 .probe = samsung_pinctrl_probe,
1299 .driver = {
1300 .name = "samsung-pinctrl",
Sachin Kamat606fca92013-09-28 17:38:48 +05301301 .of_match_table = samsung_pinctrl_dt_match,
Krzysztof Kozlowskia0ee2ac2016-05-17 08:02:06 +02001302 .suppress_bind_attrs = true,
Marek Szyprowski2b24efa2017-01-26 10:29:27 +01001303 .pm = &samsung_pinctrl_pm_ops,
Thomas Abraham30574f02012-09-07 06:07:19 +09001304 },
1305};
1306
1307static int __init samsung_pinctrl_drv_register(void)
1308{
Thomas Abraham30574f02012-09-07 06:07:19 +09001309 return platform_driver_register(&samsung_pinctrl_driver);
1310}
1311postcore_initcall(samsung_pinctrl_drv_register);