pinctrl-samsung.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  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. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/io.h>
  25. #include <linux/slab.h>
  26. #include <linux/err.h>
  27. #include <linux/gpio.h>
  28. #include <linux/irqdomain.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/syscore_ops.h>
  31. #include "../core.h"
  32. #include "pinctrl-samsung.h"
  33. /* maximum number of the memory resources */
  34. #define SAMSUNG_PINCTRL_NUM_RESOURCES 2
  35. /* list of all possible config options supported */
  36. static struct pin_config {
  37. const char *property;
  38. enum pincfg_type param;
  39. } cfg_params[] = {
  40. { "samsung,pin-pud", PINCFG_TYPE_PUD },
  41. { "samsung,pin-drv", PINCFG_TYPE_DRV },
  42. { "samsung,pin-con-pdn", PINCFG_TYPE_CON_PDN },
  43. { "samsung,pin-pud-pdn", PINCFG_TYPE_PUD_PDN },
  44. { "samsung,pin-val", PINCFG_TYPE_DAT },
  45. };
  46. /* Global list of devices (struct samsung_pinctrl_drv_data) */
  47. static LIST_HEAD(drvdata_list);
  48. static unsigned int pin_base;
  49. static int samsung_get_group_count(struct pinctrl_dev *pctldev)
  50. {
  51. struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
  52. return pmx->nr_groups;
  53. }
  54. static const char *samsung_get_group_name(struct pinctrl_dev *pctldev,
  55. unsigned group)
  56. {
  57. struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
  58. return pmx->pin_groups[group].name;
  59. }
  60. static int samsung_get_group_pins(struct pinctrl_dev *pctldev,
  61. unsigned group,
  62. const unsigned **pins,
  63. unsigned *num_pins)
  64. {
  65. struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
  66. *pins = pmx->pin_groups[group].pins;
  67. *num_pins = pmx->pin_groups[group].num_pins;
  68. return 0;
  69. }
  70. static int reserve_map(struct device *dev, struct pinctrl_map **map,
  71. unsigned *reserved_maps, unsigned *num_maps,
  72. unsigned reserve)
  73. {
  74. unsigned old_num = *reserved_maps;
  75. unsigned new_num = *num_maps + reserve;
  76. struct pinctrl_map *new_map;
  77. if (old_num >= new_num)
  78. return 0;
  79. new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
  80. if (!new_map) {
  81. dev_err(dev, "krealloc(map) failed\n");
  82. return -ENOMEM;
  83. }
  84. memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
  85. *map = new_map;
  86. *reserved_maps = new_num;
  87. return 0;
  88. }
  89. static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
  90. unsigned *num_maps, const char *group,
  91. const char *function)
  92. {
  93. if (WARN_ON(*num_maps == *reserved_maps))
  94. return -ENOSPC;
  95. (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
  96. (*map)[*num_maps].data.mux.group = group;
  97. (*map)[*num_maps].data.mux.function = function;
  98. (*num_maps)++;
  99. return 0;
  100. }
  101. static int add_map_configs(struct device *dev, struct pinctrl_map **map,
  102. unsigned *reserved_maps, unsigned *num_maps,
  103. const char *group, unsigned long *configs,
  104. unsigned num_configs)
  105. {
  106. unsigned long *dup_configs;
  107. if (WARN_ON(*num_maps == *reserved_maps))
  108. return -ENOSPC;
  109. dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
  110. GFP_KERNEL);
  111. if (!dup_configs) {
  112. dev_err(dev, "kmemdup(configs) failed\n");
  113. return -ENOMEM;
  114. }
  115. (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
  116. (*map)[*num_maps].data.configs.group_or_pin = group;
  117. (*map)[*num_maps].data.configs.configs = dup_configs;
  118. (*map)[*num_maps].data.configs.num_configs = num_configs;
  119. (*num_maps)++;
  120. return 0;
  121. }
  122. static int add_config(struct device *dev, unsigned long **configs,
  123. unsigned *num_configs, unsigned long config)
  124. {
  125. unsigned old_num = *num_configs;
  126. unsigned new_num = old_num + 1;
  127. unsigned long *new_configs;
  128. new_configs = krealloc(*configs, sizeof(*new_configs) * new_num,
  129. GFP_KERNEL);
  130. if (!new_configs) {
  131. dev_err(dev, "krealloc(configs) failed\n");
  132. return -ENOMEM;
  133. }
  134. new_configs[old_num] = config;
  135. *configs = new_configs;
  136. *num_configs = new_num;
  137. return 0;
  138. }
  139. static void samsung_dt_free_map(struct pinctrl_dev *pctldev,
  140. struct pinctrl_map *map,
  141. unsigned num_maps)
  142. {
  143. int i;
  144. for (i = 0; i < num_maps; i++)
  145. if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
  146. kfree(map[i].data.configs.configs);
  147. kfree(map);
  148. }
  149. static int samsung_dt_subnode_to_map(struct samsung_pinctrl_drv_data *drvdata,
  150. struct device *dev,
  151. struct device_node *np,
  152. struct pinctrl_map **map,
  153. unsigned *reserved_maps,
  154. unsigned *num_maps)
  155. {
  156. int ret, i;
  157. u32 val;
  158. unsigned long config;
  159. unsigned long *configs = NULL;
  160. unsigned num_configs = 0;
  161. unsigned reserve;
  162. struct property *prop;
  163. const char *group;
  164. bool has_func = false;
  165. ret = of_property_read_u32(np, "samsung,pin-function", &val);
  166. if (!ret)
  167. has_func = true;
  168. for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
  169. ret = of_property_read_u32(np, cfg_params[i].property, &val);
  170. if (!ret) {
  171. config = PINCFG_PACK(cfg_params[i].param, val);
  172. ret = add_config(dev, &configs, &num_configs, config);
  173. if (ret < 0)
  174. goto exit;
  175. /* EINVAL=missing, which is fine since it's optional */
  176. } else if (ret != -EINVAL) {
  177. dev_err(dev, "could not parse property %s\n",
  178. cfg_params[i].property);
  179. }
  180. }
  181. reserve = 0;
  182. if (has_func)
  183. reserve++;
  184. if (num_configs)
  185. reserve++;
  186. ret = of_property_count_strings(np, "samsung,pins");
  187. if (ret < 0) {
  188. dev_err(dev, "could not parse property samsung,pins\n");
  189. goto exit;
  190. }
  191. reserve *= ret;
  192. ret = reserve_map(dev, map, reserved_maps, num_maps, reserve);
  193. if (ret < 0)
  194. goto exit;
  195. of_property_for_each_string(np, "samsung,pins", prop, group) {
  196. if (has_func) {
  197. ret = add_map_mux(map, reserved_maps,
  198. num_maps, group, np->full_name);
  199. if (ret < 0)
  200. goto exit;
  201. }
  202. if (num_configs) {
  203. ret = add_map_configs(dev, map, reserved_maps,
  204. num_maps, group, configs,
  205. num_configs);
  206. if (ret < 0)
  207. goto exit;
  208. }
  209. }
  210. ret = 0;
  211. exit:
  212. kfree(configs);
  213. return ret;
  214. }
  215. static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
  216. struct device_node *np_config,
  217. struct pinctrl_map **map,
  218. unsigned *num_maps)
  219. {
  220. struct samsung_pinctrl_drv_data *drvdata;
  221. unsigned reserved_maps;
  222. struct device_node *np;
  223. int ret;
  224. drvdata = pinctrl_dev_get_drvdata(pctldev);
  225. reserved_maps = 0;
  226. *map = NULL;
  227. *num_maps = 0;
  228. if (!of_get_child_count(np_config))
  229. return samsung_dt_subnode_to_map(drvdata, pctldev->dev,
  230. np_config, map,
  231. &reserved_maps,
  232. num_maps);
  233. for_each_child_of_node(np_config, np) {
  234. ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map,
  235. &reserved_maps, num_maps);
  236. if (ret < 0) {
  237. samsung_dt_free_map(pctldev, *map, *num_maps);
  238. return ret;
  239. }
  240. }
  241. return 0;
  242. }
  243. /* list of pinctrl callbacks for the pinctrl core */
  244. static const struct pinctrl_ops samsung_pctrl_ops = {
  245. .get_groups_count = samsung_get_group_count,
  246. .get_group_name = samsung_get_group_name,
  247. .get_group_pins = samsung_get_group_pins,
  248. .dt_node_to_map = samsung_dt_node_to_map,
  249. .dt_free_map = samsung_dt_free_map,
  250. };
  251. /* check if the selector is a valid pin function selector */
  252. static int samsung_get_functions_count(struct pinctrl_dev *pctldev)
  253. {
  254. struct samsung_pinctrl_drv_data *drvdata;
  255. drvdata = pinctrl_dev_get_drvdata(pctldev);
  256. return drvdata->nr_functions;
  257. }
  258. /* return the name of the pin function specified */
  259. static const char *samsung_pinmux_get_fname(struct pinctrl_dev *pctldev,
  260. unsigned selector)
  261. {
  262. struct samsung_pinctrl_drv_data *drvdata;
  263. drvdata = pinctrl_dev_get_drvdata(pctldev);
  264. return drvdata->pmx_functions[selector].name;
  265. }
  266. /* return the groups associated for the specified function selector */
  267. static int samsung_pinmux_get_groups(struct pinctrl_dev *pctldev,
  268. unsigned selector, const char * const **groups,
  269. unsigned * const num_groups)
  270. {
  271. struct samsung_pinctrl_drv_data *drvdata;
  272. drvdata = pinctrl_dev_get_drvdata(pctldev);
  273. *groups = drvdata->pmx_functions[selector].groups;
  274. *num_groups = drvdata->pmx_functions[selector].num_groups;
  275. return 0;
  276. }
  277. /*
  278. * given a pin number that is local to a pin controller, find out the pin bank
  279. * and the register base of the pin bank.
  280. */
  281. static void pin_to_reg_bank(struct samsung_pinctrl_drv_data *drvdata,
  282. unsigned pin, void __iomem **reg, u32 *offset,
  283. struct samsung_pin_bank **bank)
  284. {
  285. struct samsung_pin_bank *b;
  286. b = drvdata->pin_banks;
  287. while ((pin >= b->pin_base) &&
  288. ((b->pin_base + b->nr_pins - 1) < pin))
  289. b++;
  290. *reg = b->pctl_base + b->pctl_offset;
  291. *offset = pin - b->pin_base;
  292. if (bank)
  293. *bank = b;
  294. }
  295. /* enable or disable a pinmux function */
  296. static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector,
  297. unsigned group, bool enable)
  298. {
  299. struct samsung_pinctrl_drv_data *drvdata;
  300. const struct samsung_pin_bank_type *type;
  301. struct samsung_pin_bank *bank;
  302. void __iomem *reg;
  303. u32 mask, shift, data, pin_offset;
  304. unsigned long flags;
  305. const struct samsung_pmx_func *func;
  306. const struct samsung_pin_group *grp;
  307. drvdata = pinctrl_dev_get_drvdata(pctldev);
  308. func = &drvdata->pmx_functions[selector];
  309. grp = &drvdata->pin_groups[group];
  310. pin_to_reg_bank(drvdata, grp->pins[0] - drvdata->pin_base,
  311. &reg, &pin_offset, &bank);
  312. type = bank->type;
  313. mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
  314. shift = pin_offset * type->fld_width[PINCFG_TYPE_FUNC];
  315. if (shift >= 32) {
  316. /* Some banks have two config registers */
  317. shift -= 32;
  318. reg += 4;
  319. }
  320. spin_lock_irqsave(&bank->slock, flags);
  321. data = readl(reg + type->reg_offset[PINCFG_TYPE_FUNC]);
  322. data &= ~(mask << shift);
  323. if (enable)
  324. data |= func->val << shift;
  325. writel(data, reg + type->reg_offset[PINCFG_TYPE_FUNC]);
  326. spin_unlock_irqrestore(&bank->slock, flags);
  327. }
  328. /* enable a specified pinmux by writing to registers */
  329. static int samsung_pinmux_set_mux(struct pinctrl_dev *pctldev,
  330. unsigned selector,
  331. unsigned group)
  332. {
  333. samsung_pinmux_setup(pctldev, selector, group, true);
  334. return 0;
  335. }
  336. /* list of pinmux callbacks for the pinmux vertical in pinctrl core */
  337. static const struct pinmux_ops samsung_pinmux_ops = {
  338. .get_functions_count = samsung_get_functions_count,
  339. .get_function_name = samsung_pinmux_get_fname,
  340. .get_function_groups = samsung_pinmux_get_groups,
  341. .set_mux = samsung_pinmux_set_mux,
  342. };
  343. /* set or get the pin config settings for a specified pin */
  344. static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin,
  345. unsigned long *config, bool set)
  346. {
  347. struct samsung_pinctrl_drv_data *drvdata;
  348. const struct samsung_pin_bank_type *type;
  349. struct samsung_pin_bank *bank;
  350. void __iomem *reg_base;
  351. enum pincfg_type cfg_type = PINCFG_UNPACK_TYPE(*config);
  352. u32 data, width, pin_offset, mask, shift;
  353. u32 cfg_value, cfg_reg;
  354. unsigned long flags;
  355. drvdata = pinctrl_dev_get_drvdata(pctldev);
  356. pin_to_reg_bank(drvdata, pin - drvdata->pin_base, &reg_base,
  357. &pin_offset, &bank);
  358. type = bank->type;
  359. if (cfg_type >= PINCFG_TYPE_NUM || !type->fld_width[cfg_type])
  360. return -EINVAL;
  361. width = type->fld_width[cfg_type];
  362. cfg_reg = type->reg_offset[cfg_type];
  363. spin_lock_irqsave(&bank->slock, flags);
  364. mask = (1 << width) - 1;
  365. shift = pin_offset * width;
  366. data = readl(reg_base + cfg_reg);
  367. if (set) {
  368. cfg_value = PINCFG_UNPACK_VALUE(*config);
  369. data &= ~(mask << shift);
  370. data |= (cfg_value << shift);
  371. writel(data, reg_base + cfg_reg);
  372. } else {
  373. data >>= shift;
  374. data &= mask;
  375. *config = PINCFG_PACK(cfg_type, data);
  376. }
  377. spin_unlock_irqrestore(&bank->slock, flags);
  378. return 0;
  379. }
  380. /* set the pin config settings for a specified pin */
  381. static int samsung_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
  382. unsigned long *configs, unsigned num_configs)
  383. {
  384. int i, ret;
  385. for (i = 0; i < num_configs; i++) {
  386. ret = samsung_pinconf_rw(pctldev, pin, &configs[i], true);
  387. if (ret < 0)
  388. return ret;
  389. } /* for each config */
  390. return 0;
  391. }
  392. /* get the pin config settings for a specified pin */
  393. static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
  394. unsigned long *config)
  395. {
  396. return samsung_pinconf_rw(pctldev, pin, config, false);
  397. }
  398. /* set the pin config settings for a specified pin group */
  399. static int samsung_pinconf_group_set(struct pinctrl_dev *pctldev,
  400. unsigned group, unsigned long *configs,
  401. unsigned num_configs)
  402. {
  403. struct samsung_pinctrl_drv_data *drvdata;
  404. const unsigned int *pins;
  405. unsigned int cnt;
  406. drvdata = pinctrl_dev_get_drvdata(pctldev);
  407. pins = drvdata->pin_groups[group].pins;
  408. for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++)
  409. samsung_pinconf_set(pctldev, pins[cnt], configs, num_configs);
  410. return 0;
  411. }
  412. /* get the pin config settings for a specified pin group */
  413. static int samsung_pinconf_group_get(struct pinctrl_dev *pctldev,
  414. unsigned int group, unsigned long *config)
  415. {
  416. struct samsung_pinctrl_drv_data *drvdata;
  417. const unsigned int *pins;
  418. drvdata = pinctrl_dev_get_drvdata(pctldev);
  419. pins = drvdata->pin_groups[group].pins;
  420. samsung_pinconf_get(pctldev, pins[0], config);
  421. return 0;
  422. }
  423. /* list of pinconfig callbacks for pinconfig vertical in the pinctrl code */
  424. static const struct pinconf_ops samsung_pinconf_ops = {
  425. .pin_config_get = samsung_pinconf_get,
  426. .pin_config_set = samsung_pinconf_set,
  427. .pin_config_group_get = samsung_pinconf_group_get,
  428. .pin_config_group_set = samsung_pinconf_group_set,
  429. };
  430. /*
  431. * The samsung_gpio_set_vlaue() should be called with "bank->slock" held
  432. * to avoid race condition.
  433. */
  434. static void samsung_gpio_set_value(struct gpio_chip *gc,
  435. unsigned offset, int value)
  436. {
  437. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  438. const struct samsung_pin_bank_type *type = bank->type;
  439. void __iomem *reg;
  440. u32 data;
  441. reg = bank->pctl_base + bank->pctl_offset;
  442. data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
  443. data &= ~(1 << offset);
  444. if (value)
  445. data |= 1 << offset;
  446. writel(data, reg + type->reg_offset[PINCFG_TYPE_DAT]);
  447. }
  448. /* gpiolib gpio_set callback function */
  449. static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  450. {
  451. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  452. unsigned long flags;
  453. spin_lock_irqsave(&bank->slock, flags);
  454. samsung_gpio_set_value(gc, offset, value);
  455. spin_unlock_irqrestore(&bank->slock, flags);
  456. }
  457. /* gpiolib gpio_get callback function */
  458. static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset)
  459. {
  460. void __iomem *reg;
  461. u32 data;
  462. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  463. const struct samsung_pin_bank_type *type = bank->type;
  464. reg = bank->pctl_base + bank->pctl_offset;
  465. data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
  466. data >>= offset;
  467. data &= 1;
  468. return data;
  469. }
  470. /*
  471. * The samsung_gpio_set_direction() should be called with "bank->slock" held
  472. * to avoid race condition.
  473. * The calls to gpio_direction_output() and gpio_direction_input()
  474. * leads to this function call.
  475. */
  476. static int samsung_gpio_set_direction(struct gpio_chip *gc,
  477. unsigned offset, bool input)
  478. {
  479. const struct samsung_pin_bank_type *type;
  480. struct samsung_pin_bank *bank;
  481. struct samsung_pinctrl_drv_data *drvdata;
  482. void __iomem *reg;
  483. u32 data, mask, shift;
  484. bank = gpiochip_get_data(gc);
  485. type = bank->type;
  486. drvdata = bank->drvdata;
  487. reg = bank->pctl_base + bank->pctl_offset
  488. + type->reg_offset[PINCFG_TYPE_FUNC];
  489. mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
  490. shift = offset * type->fld_width[PINCFG_TYPE_FUNC];
  491. if (shift >= 32) {
  492. /* Some banks have two config registers */
  493. shift -= 32;
  494. reg += 4;
  495. }
  496. data = readl(reg);
  497. data &= ~(mask << shift);
  498. if (!input)
  499. data |= FUNC_OUTPUT << shift;
  500. writel(data, reg);
  501. return 0;
  502. }
  503. /* gpiolib gpio_direction_input callback function. */
  504. static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
  505. {
  506. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  507. unsigned long flags;
  508. int ret;
  509. spin_lock_irqsave(&bank->slock, flags);
  510. ret = samsung_gpio_set_direction(gc, offset, true);
  511. spin_unlock_irqrestore(&bank->slock, flags);
  512. return ret;
  513. }
  514. /* gpiolib gpio_direction_output callback function. */
  515. static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
  516. int value)
  517. {
  518. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  519. unsigned long flags;
  520. int ret;
  521. spin_lock_irqsave(&bank->slock, flags);
  522. samsung_gpio_set_value(gc, offset, value);
  523. ret = samsung_gpio_set_direction(gc, offset, false);
  524. spin_unlock_irqrestore(&bank->slock, flags);
  525. return ret;
  526. }
  527. /*
  528. * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
  529. * and a virtual IRQ, if not already present.
  530. */
  531. static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
  532. {
  533. struct samsung_pin_bank *bank = gpiochip_get_data(gc);
  534. unsigned int virq;
  535. if (!bank->irq_domain)
  536. return -ENXIO;
  537. virq = irq_create_mapping(bank->irq_domain, offset);
  538. return (virq) ? : -ENXIO;
  539. }
  540. static struct samsung_pin_group *samsung_pinctrl_create_groups(
  541. struct device *dev,
  542. struct samsung_pinctrl_drv_data *drvdata,
  543. unsigned int *cnt)
  544. {
  545. struct pinctrl_desc *ctrldesc = &drvdata->pctl;
  546. struct samsung_pin_group *groups, *grp;
  547. const struct pinctrl_pin_desc *pdesc;
  548. int i;
  549. groups = devm_kzalloc(dev, ctrldesc->npins * sizeof(*groups),
  550. GFP_KERNEL);
  551. if (!groups)
  552. return ERR_PTR(-EINVAL);
  553. grp = groups;
  554. pdesc = ctrldesc->pins;
  555. for (i = 0; i < ctrldesc->npins; ++i, ++pdesc, ++grp) {
  556. grp->name = pdesc->name;
  557. grp->pins = &pdesc->number;
  558. grp->num_pins = 1;
  559. }
  560. *cnt = ctrldesc->npins;
  561. return groups;
  562. }
  563. static int samsung_pinctrl_create_function(struct device *dev,
  564. struct samsung_pinctrl_drv_data *drvdata,
  565. struct device_node *func_np,
  566. struct samsung_pmx_func *func)
  567. {
  568. int npins;
  569. int ret;
  570. int i;
  571. if (of_property_read_u32(func_np, "samsung,pin-function", &func->val))
  572. return 0;
  573. npins = of_property_count_strings(func_np, "samsung,pins");
  574. if (npins < 1) {
  575. dev_err(dev, "invalid pin list in %s node", func_np->name);
  576. return -EINVAL;
  577. }
  578. func->name = func_np->full_name;
  579. func->groups = devm_kzalloc(dev, npins * sizeof(char *), GFP_KERNEL);
  580. if (!func->groups)
  581. return -ENOMEM;
  582. for (i = 0; i < npins; ++i) {
  583. const char *gname;
  584. ret = of_property_read_string_index(func_np, "samsung,pins",
  585. i, &gname);
  586. if (ret) {
  587. dev_err(dev,
  588. "failed to read pin name %d from %s node\n",
  589. i, func_np->name);
  590. return ret;
  591. }
  592. func->groups[i] = gname;
  593. }
  594. func->num_groups = npins;
  595. return 1;
  596. }
  597. static struct samsung_pmx_func *samsung_pinctrl_create_functions(
  598. struct device *dev,
  599. struct samsung_pinctrl_drv_data *drvdata,
  600. unsigned int *cnt)
  601. {
  602. struct samsung_pmx_func *functions, *func;
  603. struct device_node *dev_np = dev->of_node;
  604. struct device_node *cfg_np;
  605. unsigned int func_cnt = 0;
  606. int ret;
  607. /*
  608. * Iterate over all the child nodes of the pin controller node
  609. * and create pin groups and pin function lists.
  610. */
  611. for_each_child_of_node(dev_np, cfg_np) {
  612. struct device_node *func_np;
  613. if (!of_get_child_count(cfg_np)) {
  614. if (!of_find_property(cfg_np,
  615. "samsung,pin-function", NULL))
  616. continue;
  617. ++func_cnt;
  618. continue;
  619. }
  620. for_each_child_of_node(cfg_np, func_np) {
  621. if (!of_find_property(func_np,
  622. "samsung,pin-function", NULL))
  623. continue;
  624. ++func_cnt;
  625. }
  626. }
  627. functions = devm_kzalloc(dev, func_cnt * sizeof(*functions),
  628. GFP_KERNEL);
  629. if (!functions) {
  630. dev_err(dev, "failed to allocate memory for function list\n");
  631. return ERR_PTR(-EINVAL);
  632. }
  633. func = functions;
  634. /*
  635. * Iterate over all the child nodes of the pin controller node
  636. * and create pin groups and pin function lists.
  637. */
  638. func_cnt = 0;
  639. for_each_child_of_node(dev_np, cfg_np) {
  640. struct device_node *func_np;
  641. if (!of_get_child_count(cfg_np)) {
  642. ret = samsung_pinctrl_create_function(dev, drvdata,
  643. cfg_np, func);
  644. if (ret < 0)
  645. return ERR_PTR(ret);
  646. if (ret > 0) {
  647. ++func;
  648. ++func_cnt;
  649. }
  650. continue;
  651. }
  652. for_each_child_of_node(cfg_np, func_np) {
  653. ret = samsung_pinctrl_create_function(dev, drvdata,
  654. func_np, func);
  655. if (ret < 0)
  656. return ERR_PTR(ret);
  657. if (ret > 0) {
  658. ++func;
  659. ++func_cnt;
  660. }
  661. }
  662. }
  663. *cnt = func_cnt;
  664. return functions;
  665. }
  666. /*
  667. * Parse the information about all the available pin groups and pin functions
  668. * from device node of the pin-controller. A pin group is formed with all
  669. * the pins listed in the "samsung,pins" property.
  670. */
  671. static int samsung_pinctrl_parse_dt(struct platform_device *pdev,
  672. struct samsung_pinctrl_drv_data *drvdata)
  673. {
  674. struct device *dev = &pdev->dev;
  675. struct samsung_pin_group *groups;
  676. struct samsung_pmx_func *functions;
  677. unsigned int grp_cnt = 0, func_cnt = 0;
  678. groups = samsung_pinctrl_create_groups(dev, drvdata, &grp_cnt);
  679. if (IS_ERR(groups)) {
  680. dev_err(dev, "failed to parse pin groups\n");
  681. return PTR_ERR(groups);
  682. }
  683. functions = samsung_pinctrl_create_functions(dev, drvdata, &func_cnt);
  684. if (IS_ERR(functions)) {
  685. dev_err(dev, "failed to parse pin functions\n");
  686. return PTR_ERR(functions);
  687. }
  688. drvdata->pin_groups = groups;
  689. drvdata->nr_groups = grp_cnt;
  690. drvdata->pmx_functions = functions;
  691. drvdata->nr_functions = func_cnt;
  692. return 0;
  693. }
  694. /* register the pinctrl interface with the pinctrl subsystem */
  695. static int samsung_pinctrl_register(struct platform_device *pdev,
  696. struct samsung_pinctrl_drv_data *drvdata)
  697. {
  698. struct pinctrl_desc *ctrldesc = &drvdata->pctl;
  699. struct pinctrl_pin_desc *pindesc, *pdesc;
  700. struct samsung_pin_bank *pin_bank;
  701. char *pin_names;
  702. int pin, bank, ret;
  703. ctrldesc->name = "samsung-pinctrl";
  704. ctrldesc->owner = THIS_MODULE;
  705. ctrldesc->pctlops = &samsung_pctrl_ops;
  706. ctrldesc->pmxops = &samsung_pinmux_ops;
  707. ctrldesc->confops = &samsung_pinconf_ops;
  708. pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
  709. drvdata->nr_pins, GFP_KERNEL);
  710. if (!pindesc) {
  711. dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
  712. return -ENOMEM;
  713. }
  714. ctrldesc->pins = pindesc;
  715. ctrldesc->npins = drvdata->nr_pins;
  716. /* dynamically populate the pin number and pin name for pindesc */
  717. for (pin = 0, pdesc = pindesc; pin < ctrldesc->npins; pin++, pdesc++)
  718. pdesc->number = pin + drvdata->pin_base;
  719. /*
  720. * allocate space for storing the dynamically generated names for all
  721. * the pins which belong to this pin-controller.
  722. */
  723. pin_names = devm_kzalloc(&pdev->dev, sizeof(char) * PIN_NAME_LENGTH *
  724. drvdata->nr_pins, GFP_KERNEL);
  725. if (!pin_names) {
  726. dev_err(&pdev->dev, "mem alloc for pin names failed\n");
  727. return -ENOMEM;
  728. }
  729. /* for each pin, the name of the pin is pin-bank name + pin number */
  730. for (bank = 0; bank < drvdata->nr_banks; bank++) {
  731. pin_bank = &drvdata->pin_banks[bank];
  732. for (pin = 0; pin < pin_bank->nr_pins; pin++) {
  733. sprintf(pin_names, "%s-%d", pin_bank->name, pin);
  734. pdesc = pindesc + pin_bank->pin_base + pin;
  735. pdesc->name = pin_names;
  736. pin_names += PIN_NAME_LENGTH;
  737. }
  738. }
  739. ret = samsung_pinctrl_parse_dt(pdev, drvdata);
  740. if (ret)
  741. return ret;
  742. drvdata->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc,
  743. drvdata);
  744. if (IS_ERR(drvdata->pctl_dev)) {
  745. dev_err(&pdev->dev, "could not register pinctrl driver\n");
  746. return PTR_ERR(drvdata->pctl_dev);
  747. }
  748. for (bank = 0; bank < drvdata->nr_banks; ++bank) {
  749. pin_bank = &drvdata->pin_banks[bank];
  750. pin_bank->grange.name = pin_bank->name;
  751. pin_bank->grange.id = bank;
  752. pin_bank->grange.pin_base = drvdata->pin_base
  753. + pin_bank->pin_base;
  754. pin_bank->grange.base = pin_bank->gpio_chip.base;
  755. pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
  756. pin_bank->grange.gc = &pin_bank->gpio_chip;
  757. pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange);
  758. }
  759. return 0;
  760. }
  761. static const struct gpio_chip samsung_gpiolib_chip = {
  762. .request = gpiochip_generic_request,
  763. .free = gpiochip_generic_free,
  764. .set = samsung_gpio_set,
  765. .get = samsung_gpio_get,
  766. .direction_input = samsung_gpio_direction_input,
  767. .direction_output = samsung_gpio_direction_output,
  768. .to_irq = samsung_gpio_to_irq,
  769. .owner = THIS_MODULE,
  770. };
  771. /* register the gpiolib interface with the gpiolib subsystem */
  772. static int samsung_gpiolib_register(struct platform_device *pdev,
  773. struct samsung_pinctrl_drv_data *drvdata)
  774. {
  775. struct samsung_pin_bank *bank = drvdata->pin_banks;
  776. struct gpio_chip *gc;
  777. int ret;
  778. int i;
  779. for (i = 0; i < drvdata->nr_banks; ++i, ++bank) {
  780. bank->gpio_chip = samsung_gpiolib_chip;
  781. gc = &bank->gpio_chip;
  782. gc->base = drvdata->pin_base + bank->pin_base;
  783. gc->ngpio = bank->nr_pins;
  784. gc->parent = &pdev->dev;
  785. gc->of_node = bank->of_node;
  786. gc->label = bank->name;
  787. ret = gpiochip_add_data(gc, bank);
  788. if (ret) {
  789. dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
  790. gc->label, ret);
  791. goto fail;
  792. }
  793. }
  794. return 0;
  795. fail:
  796. for (--i, --bank; i >= 0; --i, --bank)
  797. gpiochip_remove(&bank->gpio_chip);
  798. return ret;
  799. }
  800. /* unregister the gpiolib interface with the gpiolib subsystem */
  801. static int samsung_gpiolib_unregister(struct platform_device *pdev,
  802. struct samsung_pinctrl_drv_data *drvdata)
  803. {
  804. struct samsung_pin_bank *bank = drvdata->pin_banks;
  805. int i;
  806. for (i = 0; i < drvdata->nr_banks; ++i, ++bank)
  807. gpiochip_remove(&bank->gpio_chip);
  808. return 0;
  809. }
  810. static const struct of_device_id samsung_pinctrl_dt_match[];
  811. /* retrieve the soc specific data */
  812. static const struct samsung_pin_ctrl *
  813. samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
  814. struct platform_device *pdev)
  815. {
  816. int id;
  817. const struct of_device_id *match;
  818. struct device_node *node = pdev->dev.of_node;
  819. struct device_node *np;
  820. const struct samsung_pin_bank_data *bdata;
  821. const struct samsung_pin_ctrl *ctrl;
  822. struct samsung_pin_bank *bank;
  823. struct resource *res;
  824. void __iomem *virt_base[SAMSUNG_PINCTRL_NUM_RESOURCES];
  825. int i;
  826. id = of_alias_get_id(node, "pinctrl");
  827. if (id < 0) {
  828. dev_err(&pdev->dev, "failed to get alias id\n");
  829. return ERR_PTR(-ENOENT);
  830. }
  831. match = of_match_node(samsung_pinctrl_dt_match, node);
  832. ctrl = (struct samsung_pin_ctrl *)match->data + id;
  833. d->suspend = ctrl->suspend;
  834. d->resume = ctrl->resume;
  835. d->nr_banks = ctrl->nr_banks;
  836. d->pin_banks = devm_kcalloc(&pdev->dev, d->nr_banks,
  837. sizeof(*d->pin_banks), GFP_KERNEL);
  838. if (!d->pin_banks)
  839. return ERR_PTR(-ENOMEM);
  840. if (ctrl->nr_ext_resources + 1 > SAMSUNG_PINCTRL_NUM_RESOURCES)
  841. return ERR_PTR(-EINVAL);
  842. for (i = 0; i < ctrl->nr_ext_resources + 1; i++) {
  843. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  844. virt_base[i] = devm_ioremap(&pdev->dev, res->start,
  845. resource_size(res));
  846. if (IS_ERR(virt_base[i]))
  847. return ERR_PTR(-EIO);
  848. }
  849. bank = d->pin_banks;
  850. bdata = ctrl->pin_banks;
  851. for (i = 0; i < ctrl->nr_banks; ++i, ++bdata, ++bank) {
  852. bank->type = bdata->type;
  853. bank->pctl_offset = bdata->pctl_offset;
  854. bank->nr_pins = bdata->nr_pins;
  855. bank->eint_func = bdata->eint_func;
  856. bank->eint_type = bdata->eint_type;
  857. bank->eint_mask = bdata->eint_mask;
  858. bank->eint_offset = bdata->eint_offset;
  859. bank->name = bdata->name;
  860. spin_lock_init(&bank->slock);
  861. bank->drvdata = d;
  862. bank->pin_base = d->nr_pins;
  863. d->nr_pins += bank->nr_pins;
  864. bank->eint_base = virt_base[0];
  865. bank->pctl_base = virt_base[bdata->pctl_res_idx];
  866. }
  867. for_each_child_of_node(node, np) {
  868. if (!of_find_property(np, "gpio-controller", NULL))
  869. continue;
  870. bank = d->pin_banks;
  871. for (i = 0; i < d->nr_banks; ++i, ++bank) {
  872. if (!strcmp(bank->name, np->name)) {
  873. bank->of_node = np;
  874. break;
  875. }
  876. }
  877. }
  878. d->pin_base = pin_base;
  879. pin_base += d->nr_pins;
  880. return ctrl;
  881. }
  882. static int samsung_pinctrl_probe(struct platform_device *pdev)
  883. {
  884. struct samsung_pinctrl_drv_data *drvdata;
  885. const struct samsung_pin_ctrl *ctrl;
  886. struct device *dev = &pdev->dev;
  887. struct resource *res;
  888. int ret;
  889. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  890. if (!drvdata)
  891. return -ENOMEM;
  892. ctrl = samsung_pinctrl_get_soc_data(drvdata, pdev);
  893. if (IS_ERR(ctrl)) {
  894. dev_err(&pdev->dev, "driver data not available\n");
  895. return PTR_ERR(ctrl);
  896. }
  897. drvdata->dev = dev;
  898. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  899. if (res)
  900. drvdata->irq = res->start;
  901. ret = samsung_gpiolib_register(pdev, drvdata);
  902. if (ret)
  903. return ret;
  904. ret = samsung_pinctrl_register(pdev, drvdata);
  905. if (ret) {
  906. samsung_gpiolib_unregister(pdev, drvdata);
  907. return ret;
  908. }
  909. if (ctrl->eint_gpio_init)
  910. ctrl->eint_gpio_init(drvdata);
  911. if (ctrl->eint_wkup_init)
  912. ctrl->eint_wkup_init(drvdata);
  913. platform_set_drvdata(pdev, drvdata);
  914. /* Add to the global list */
  915. list_add_tail(&drvdata->node, &drvdata_list);
  916. return 0;
  917. }
  918. #ifdef CONFIG_PM
  919. /**
  920. * samsung_pinctrl_suspend_dev - save pinctrl state for suspend for a device
  921. *
  922. * Save data for all banks handled by this device.
  923. */
  924. static void samsung_pinctrl_suspend_dev(
  925. struct samsung_pinctrl_drv_data *drvdata)
  926. {
  927. int i;
  928. for (i = 0; i < drvdata->nr_banks; i++) {
  929. struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
  930. void __iomem *reg = bank->pctl_base + bank->pctl_offset;
  931. const u8 *offs = bank->type->reg_offset;
  932. const u8 *widths = bank->type->fld_width;
  933. enum pincfg_type type;
  934. /* Registers without a powerdown config aren't lost */
  935. if (!widths[PINCFG_TYPE_CON_PDN])
  936. continue;
  937. for (type = 0; type < PINCFG_TYPE_NUM; type++)
  938. if (widths[type])
  939. bank->pm_save[type] = readl(reg + offs[type]);
  940. if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
  941. /* Some banks have two config registers */
  942. bank->pm_save[PINCFG_TYPE_NUM] =
  943. readl(reg + offs[PINCFG_TYPE_FUNC] + 4);
  944. pr_debug("Save %s @ %p (con %#010x %08x)\n",
  945. bank->name, reg,
  946. bank->pm_save[PINCFG_TYPE_FUNC],
  947. bank->pm_save[PINCFG_TYPE_NUM]);
  948. } else {
  949. pr_debug("Save %s @ %p (con %#010x)\n", bank->name,
  950. reg, bank->pm_save[PINCFG_TYPE_FUNC]);
  951. }
  952. }
  953. if (drvdata->suspend)
  954. drvdata->suspend(drvdata);
  955. }
  956. /**
  957. * samsung_pinctrl_resume_dev - restore pinctrl state from suspend for a device
  958. *
  959. * Restore one of the banks that was saved during suspend.
  960. *
  961. * We don't bother doing anything complicated to avoid glitching lines since
  962. * we're called before pad retention is turned off.
  963. */
  964. static void samsung_pinctrl_resume_dev(struct samsung_pinctrl_drv_data *drvdata)
  965. {
  966. int i;
  967. if (drvdata->resume)
  968. drvdata->resume(drvdata);
  969. for (i = 0; i < drvdata->nr_banks; i++) {
  970. struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
  971. void __iomem *reg = bank->pctl_base + bank->pctl_offset;
  972. const u8 *offs = bank->type->reg_offset;
  973. const u8 *widths = bank->type->fld_width;
  974. enum pincfg_type type;
  975. /* Registers without a powerdown config aren't lost */
  976. if (!widths[PINCFG_TYPE_CON_PDN])
  977. continue;
  978. if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
  979. /* Some banks have two config registers */
  980. pr_debug("%s @ %p (con %#010x %08x => %#010x %08x)\n",
  981. bank->name, reg,
  982. readl(reg + offs[PINCFG_TYPE_FUNC]),
  983. readl(reg + offs[PINCFG_TYPE_FUNC] + 4),
  984. bank->pm_save[PINCFG_TYPE_FUNC],
  985. bank->pm_save[PINCFG_TYPE_NUM]);
  986. writel(bank->pm_save[PINCFG_TYPE_NUM],
  987. reg + offs[PINCFG_TYPE_FUNC] + 4);
  988. } else {
  989. pr_debug("%s @ %p (con %#010x => %#010x)\n", bank->name,
  990. reg, readl(reg + offs[PINCFG_TYPE_FUNC]),
  991. bank->pm_save[PINCFG_TYPE_FUNC]);
  992. }
  993. for (type = 0; type < PINCFG_TYPE_NUM; type++)
  994. if (widths[type])
  995. writel(bank->pm_save[type], reg + offs[type]);
  996. }
  997. }
  998. /**
  999. * samsung_pinctrl_suspend - save pinctrl state for suspend
  1000. *
  1001. * Save data for all banks across all devices.
  1002. */
  1003. static int samsung_pinctrl_suspend(void)
  1004. {
  1005. struct samsung_pinctrl_drv_data *drvdata;
  1006. list_for_each_entry(drvdata, &drvdata_list, node) {
  1007. samsung_pinctrl_suspend_dev(drvdata);
  1008. }
  1009. return 0;
  1010. }
  1011. /**
  1012. * samsung_pinctrl_resume - restore pinctrl state for suspend
  1013. *
  1014. * Restore data for all banks across all devices.
  1015. */
  1016. static void samsung_pinctrl_resume(void)
  1017. {
  1018. struct samsung_pinctrl_drv_data *drvdata;
  1019. list_for_each_entry_reverse(drvdata, &drvdata_list, node) {
  1020. samsung_pinctrl_resume_dev(drvdata);
  1021. }
  1022. }
  1023. #else
  1024. #define samsung_pinctrl_suspend NULL
  1025. #define samsung_pinctrl_resume NULL
  1026. #endif
  1027. static struct syscore_ops samsung_pinctrl_syscore_ops = {
  1028. .suspend = samsung_pinctrl_suspend,
  1029. .resume = samsung_pinctrl_resume,
  1030. };
  1031. static const struct of_device_id samsung_pinctrl_dt_match[] = {
  1032. #ifdef CONFIG_PINCTRL_EXYNOS
  1033. { .compatible = "samsung,exynos3250-pinctrl",
  1034. .data = (void *)exynos3250_pin_ctrl },
  1035. { .compatible = "samsung,exynos4210-pinctrl",
  1036. .data = (void *)exynos4210_pin_ctrl },
  1037. { .compatible = "samsung,exynos4x12-pinctrl",
  1038. .data = (void *)exynos4x12_pin_ctrl },
  1039. { .compatible = "samsung,exynos4415-pinctrl",
  1040. .data = (void *)exynos4415_pin_ctrl },
  1041. { .compatible = "samsung,exynos5250-pinctrl",
  1042. .data = (void *)exynos5250_pin_ctrl },
  1043. { .compatible = "samsung,exynos5260-pinctrl",
  1044. .data = (void *)exynos5260_pin_ctrl },
  1045. { .compatible = "samsung,exynos5410-pinctrl",
  1046. .data = (void *)exynos5410_pin_ctrl },
  1047. { .compatible = "samsung,exynos5420-pinctrl",
  1048. .data = (void *)exynos5420_pin_ctrl },
  1049. { .compatible = "samsung,exynos5433-pinctrl",
  1050. .data = (void *)exynos5433_pin_ctrl },
  1051. { .compatible = "samsung,s5pv210-pinctrl",
  1052. .data = (void *)s5pv210_pin_ctrl },
  1053. { .compatible = "samsung,exynos7-pinctrl",
  1054. .data = (void *)exynos7_pin_ctrl },
  1055. #endif
  1056. #ifdef CONFIG_PINCTRL_S3C64XX
  1057. { .compatible = "samsung,s3c64xx-pinctrl",
  1058. .data = s3c64xx_pin_ctrl },
  1059. #endif
  1060. #ifdef CONFIG_PINCTRL_S3C24XX
  1061. { .compatible = "samsung,s3c2412-pinctrl",
  1062. .data = s3c2412_pin_ctrl },
  1063. { .compatible = "samsung,s3c2416-pinctrl",
  1064. .data = s3c2416_pin_ctrl },
  1065. { .compatible = "samsung,s3c2440-pinctrl",
  1066. .data = s3c2440_pin_ctrl },
  1067. { .compatible = "samsung,s3c2450-pinctrl",
  1068. .data = s3c2450_pin_ctrl },
  1069. #endif
  1070. {},
  1071. };
  1072. MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match);
  1073. static struct platform_driver samsung_pinctrl_driver = {
  1074. .probe = samsung_pinctrl_probe,
  1075. .driver = {
  1076. .name = "samsung-pinctrl",
  1077. .of_match_table = samsung_pinctrl_dt_match,
  1078. .suppress_bind_attrs = true,
  1079. },
  1080. };
  1081. static int __init samsung_pinctrl_drv_register(void)
  1082. {
  1083. /*
  1084. * Register syscore ops for save/restore of registers across suspend.
  1085. * It's important to ensure that this driver is running at an earlier
  1086. * initcall level than any arch-specific init calls that install syscore
  1087. * ops that turn off pad retention (like exynos_pm_resume).
  1088. */
  1089. register_syscore_ops(&samsung_pinctrl_syscore_ops);
  1090. return platform_driver_register(&samsung_pinctrl_driver);
  1091. }
  1092. postcore_initcall(samsung_pinctrl_drv_register);
  1093. static void __exit samsung_pinctrl_drv_unregister(void)
  1094. {
  1095. platform_driver_unregister(&samsung_pinctrl_driver);
  1096. }
  1097. module_exit(samsung_pinctrl_drv_unregister);
  1098. MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>");
  1099. MODULE_DESCRIPTION("Samsung pinctrl driver");
  1100. MODULE_LICENSE("GPL v2");