pinctrl-eyeq5.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Pinctrl driver for the Mobileye EyeQ5 platform.
  4. *
  5. * The registers are located in a syscon region called OLB. There are two pin
  6. * banks, each being controlled by 5 registers (see enum eq5p_regs) for
  7. * pull-down, pull-up, drive strength and muxing.
  8. *
  9. * For each pin, muxing is between two functions: (0) GPIO or (1) another one
  10. * that is pin-dependent. Functions are declared statically in this driver.
  11. *
  12. * We create pinctrl groups that are 1:1 equivalent to pins: each group has a
  13. * single pin, and its index/selector is the pin number.
  14. *
  15. * We use eq5p_ as prefix, as-in "EyeQ5 Pinctrl", but way shorter.
  16. *
  17. * Copyright (C) 2024 Mobileye Vision Technologies Ltd.
  18. */
  19. #include <linux/array_size.h>
  20. #include <linux/auxiliary_bus.h>
  21. #include <linux/bits.h>
  22. #include <linux/bug.h>
  23. #include <linux/device.h>
  24. #include <linux/err.h>
  25. #include <linux/errno.h>
  26. #include <linux/io.h>
  27. #include <linux/mod_devicetable.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/slab.h>
  30. #include <linux/types.h>
  31. #include <linux/pinctrl/pinconf-generic.h>
  32. #include <linux/pinctrl/pinconf.h>
  33. #include <linux/pinctrl/pinctrl.h>
  34. #include <linux/pinctrl/pinmux.h>
  35. #include "core.h"
  36. #include "pinctrl-utils.h"
  37. struct eq5p_pinctrl {
  38. struct pinctrl_desc desc;
  39. void __iomem *base;
  40. };
  41. enum eq5p_bank {
  42. EQ5P_BANK_A,
  43. EQ5P_BANK_B,
  44. EQ5P_BANK_COUNT,
  45. };
  46. enum eq5p_regs {
  47. EQ5P_PD,
  48. EQ5P_PU,
  49. EQ5P_DS_LOW,
  50. EQ5P_DS_HIGH,
  51. EQ5P_IOCR,
  52. EQ5P_REG_COUNT,
  53. };
  54. static const unsigned int eq5p_regs[EQ5P_BANK_COUNT][EQ5P_REG_COUNT] = {
  55. [EQ5P_BANK_A] = {0x0C0, 0x0C4, 0x0D0, 0x0D4, 0x0B0},
  56. [EQ5P_BANK_B] = {0x0C8, 0x0CC, 0x0D8, 0x0DC, 0x0B4},
  57. };
  58. /*
  59. * Drive strength; two bits per pin.
  60. */
  61. #define EQ5P_DS_MASK GENMASK(1, 0)
  62. /*
  63. * Comments to the right of each pin are the "signal name" in the datasheet.
  64. */
  65. static const struct pinctrl_pin_desc eq5p_pins[] = {
  66. /* Bank A */
  67. PINCTRL_PIN(0, "PA0"), /* A0_TIMER0_CK */
  68. PINCTRL_PIN(1, "PA1"), /* A1_TIMER0_EOC */
  69. PINCTRL_PIN(2, "PA2"), /* A2_TIMER1_CK */
  70. PINCTRL_PIN(3, "PA3"), /* A3_TIMER1_EOC */
  71. PINCTRL_PIN(4, "PA4"), /* A4_TIMER2_CK */
  72. PINCTRL_PIN(5, "PA5"), /* A5_TIMER2_EOC */
  73. PINCTRL_PIN(6, "PA6"), /* A6_TIMER5_EXT_INCAP1 */
  74. PINCTRL_PIN(7, "PA7"), /* A7_TIMER5_EXT_INCAP2 */
  75. PINCTRL_PIN(8, "PA8"), /* A8_TIMER5_EXT_OUTCMP1 */
  76. PINCTRL_PIN(9, "PA9"), /* A9_TIMER5_EXT_OUTCMP2 */
  77. PINCTRL_PIN(10, "PA10"), /* A10_UART_0_TX */
  78. PINCTRL_PIN(11, "PA11"), /* A11_UART_0_RX */
  79. PINCTRL_PIN(12, "PA12"), /* A12_UART_1_TX */
  80. PINCTRL_PIN(13, "PA13"), /* A13_UART_1_RX */
  81. PINCTRL_PIN(14, "PA14"), /* A14_CAN_0_TX */
  82. PINCTRL_PIN(15, "PA15"), /* A15_CAN_0_RX */
  83. PINCTRL_PIN(16, "PA16"), /* A16_CAN_1_TX */
  84. PINCTRL_PIN(17, "PA17"), /* A17_CAN_1_RX */
  85. PINCTRL_PIN(18, "PA18"), /* A18_SPI_0_DO */
  86. PINCTRL_PIN(19, "PA19"), /* A19_SPI_0_DI */
  87. PINCTRL_PIN(20, "PA20"), /* A20_SPI_0_CK */
  88. PINCTRL_PIN(21, "PA21"), /* A21_SPI_0_CS0 */
  89. PINCTRL_PIN(22, "PA22"), /* A22_SPI_0_CS1 */
  90. PINCTRL_PIN(23, "PA23"), /* A23_SPI_1_DO */
  91. PINCTRL_PIN(24, "PA24"), /* A24_SPI_1_DI */
  92. PINCTRL_PIN(25, "PA25"), /* A25_SPI_1_CK */
  93. PINCTRL_PIN(26, "PA26"), /* A26_SPI_1_CS0 */
  94. PINCTRL_PIN(27, "PA27"), /* A27_SPI_1_CS1 */
  95. PINCTRL_PIN(28, "PA28"), /* A28_REF_CLK0 */
  96. #define EQ5P_PIN_OFFSET_BANK_B 29
  97. /* Bank B */
  98. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 0, "PB0"), /* B0_TIMER3_CK */
  99. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 1, "PB1"), /* B1_TIMER3_EOC */
  100. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 2, "PB2"), /* B2_TIMER4_CK */
  101. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 3, "PB3"), /* B3_TIMER4_EOC */
  102. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 4, "PB4"), /* B4_TIMER6_EXT_INCAP1 */
  103. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 5, "PB5"), /* B5_TIMER6_EXT_INCAP2 */
  104. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 6, "PB6"), /* B6_TIMER6_EXT_OUTCMP1 */
  105. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 7, "PB7"), /* B7_TIMER6_EXT_OUTCMP2 */
  106. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 8, "PB8"), /* B8_UART_2_TX */
  107. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 9, "PB9"), /* B9_UART_2_RX */
  108. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 10, "PB10"), /* B10_CAN_2_TX */
  109. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 11, "PB11"), /* B11_CAN_2_RX */
  110. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 12, "PB12"), /* B12_SPI_2_DO */
  111. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 13, "PB13"), /* B13_SPI_2_DI */
  112. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 14, "PB14"), /* B14_SPI_2_CK */
  113. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 15, "PB15"), /* B15_SPI_2_CS0 */
  114. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 16, "PB16"), /* B16_SPI_2_CS1 */
  115. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 17, "PB17"), /* B17_SPI_3_DO */
  116. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 18, "PB18"), /* B18_SPI_3_DI */
  117. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 19, "PB19"), /* B19_SPI_3_CK */
  118. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 20, "PB20"), /* B20_SPI_3_CS0 */
  119. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 21, "PB21"), /* B21_SPI_3_CS1 */
  120. PINCTRL_PIN(EQ5P_PIN_OFFSET_BANK_B + 22, "PB22"), /* B22_MCLK0 */
  121. };
  122. static const char * const gpio_groups[] = {
  123. /* Bank A */
  124. "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7",
  125. "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15",
  126. "PA16", "PA17", "PA18", "PA19", "PA20", "PA21", "PA22", "PA23",
  127. "PA24", "PA25", "PA26", "PA27", "PA28",
  128. /* Bank B */
  129. "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7",
  130. "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15",
  131. "PB16", "PB17", "PB18", "PB19", "PB20", "PB21", "PB22",
  132. };
  133. /* Groups of functions on bank A */
  134. static const char * const timer0_groups[] = { "PA0", "PA1" };
  135. static const char * const timer1_groups[] = { "PA2", "PA3" };
  136. static const char * const timer2_groups[] = { "PA4", "PA5" };
  137. static const char * const timer5_groups[] = { "PA6", "PA7", "PA8", "PA9" };
  138. static const char * const uart0_groups[] = { "PA10", "PA11" };
  139. static const char * const uart1_groups[] = { "PA12", "PA13" };
  140. static const char * const can0_groups[] = { "PA14", "PA15" };
  141. static const char * const can1_groups[] = { "PA16", "PA17" };
  142. static const char * const spi0_groups[] = { "PA18", "PA19", "PA20", "PA21", "PA22" };
  143. static const char * const spi1_groups[] = { "PA23", "PA24", "PA25", "PA26", "PA27" };
  144. static const char * const refclk0_groups[] = { "PA28" };
  145. /* Groups of functions on bank B */
  146. static const char * const timer3_groups[] = { "PB0", "PB1" };
  147. static const char * const timer4_groups[] = { "PB2", "PB3" };
  148. static const char * const timer6_groups[] = { "PB4", "PB5", "PB6", "PB7" };
  149. static const char * const uart2_groups[] = { "PB8", "PB9" };
  150. static const char * const can2_groups[] = { "PB10", "PB11" };
  151. static const char * const spi2_groups[] = { "PB12", "PB13", "PB14", "PB15", "PB16" };
  152. static const char * const spi3_groups[] = { "PB17", "PB18", "PB19", "PB20", "PB21" };
  153. static const char * const mclk0_groups[] = { "PB22" };
  154. static const struct pinfunction eq5p_functions[] = {
  155. /* GPIO having a fixed index is depended upon, see GPIO_FUNC_SELECTOR. */
  156. PINCTRL_PINFUNCTION("gpio", gpio_groups, ARRAY_SIZE(gpio_groups)),
  157. #define GPIO_FUNC_SELECTOR 0
  158. /* Bank A functions */
  159. PINCTRL_PINFUNCTION("timer0", timer0_groups, ARRAY_SIZE(timer0_groups)),
  160. PINCTRL_PINFUNCTION("timer1", timer1_groups, ARRAY_SIZE(timer1_groups)),
  161. PINCTRL_PINFUNCTION("timer2", timer2_groups, ARRAY_SIZE(timer2_groups)),
  162. PINCTRL_PINFUNCTION("timer5", timer5_groups, ARRAY_SIZE(timer5_groups)),
  163. PINCTRL_PINFUNCTION("uart0", uart0_groups, ARRAY_SIZE(uart0_groups)),
  164. PINCTRL_PINFUNCTION("uart1", uart1_groups, ARRAY_SIZE(uart1_groups)),
  165. PINCTRL_PINFUNCTION("can0", can0_groups, ARRAY_SIZE(can0_groups)),
  166. PINCTRL_PINFUNCTION("can1", can1_groups, ARRAY_SIZE(can1_groups)),
  167. PINCTRL_PINFUNCTION("spi0", spi0_groups, ARRAY_SIZE(spi0_groups)),
  168. PINCTRL_PINFUNCTION("spi1", spi1_groups, ARRAY_SIZE(spi1_groups)),
  169. PINCTRL_PINFUNCTION("refclk0", refclk0_groups, ARRAY_SIZE(refclk0_groups)),
  170. /* Bank B functions */
  171. PINCTRL_PINFUNCTION("timer3", timer3_groups, ARRAY_SIZE(timer3_groups)),
  172. PINCTRL_PINFUNCTION("timer4", timer4_groups, ARRAY_SIZE(timer4_groups)),
  173. PINCTRL_PINFUNCTION("timer6", timer6_groups, ARRAY_SIZE(timer6_groups)),
  174. PINCTRL_PINFUNCTION("uart2", uart2_groups, ARRAY_SIZE(uart2_groups)),
  175. PINCTRL_PINFUNCTION("can2", can2_groups, ARRAY_SIZE(can2_groups)),
  176. PINCTRL_PINFUNCTION("spi2", spi2_groups, ARRAY_SIZE(spi2_groups)),
  177. PINCTRL_PINFUNCTION("spi3", spi3_groups, ARRAY_SIZE(spi3_groups)),
  178. PINCTRL_PINFUNCTION("mclk0", mclk0_groups, ARRAY_SIZE(mclk0_groups)),
  179. };
  180. static void eq5p_update_bits(const struct eq5p_pinctrl *pctrl,
  181. enum eq5p_bank bank, enum eq5p_regs reg,
  182. u32 mask, u32 val)
  183. {
  184. void __iomem *ptr = pctrl->base + eq5p_regs[bank][reg];
  185. writel((readl(ptr) & ~mask) | (val & mask), ptr);
  186. }
  187. static bool eq5p_test_bit(const struct eq5p_pinctrl *pctrl,
  188. enum eq5p_bank bank, enum eq5p_regs reg, int offset)
  189. {
  190. u32 val = readl(pctrl->base + eq5p_regs[bank][reg]);
  191. if (WARN_ON(offset > 31))
  192. return false;
  193. return (val & BIT(offset)) != 0;
  194. }
  195. static enum eq5p_bank eq5p_pin_to_bank(unsigned int pin)
  196. {
  197. if (pin < EQ5P_PIN_OFFSET_BANK_B)
  198. return EQ5P_BANK_A;
  199. else
  200. return EQ5P_BANK_B;
  201. }
  202. static unsigned int eq5p_pin_to_offset(unsigned int pin)
  203. {
  204. if (pin < EQ5P_PIN_OFFSET_BANK_B)
  205. return pin;
  206. else
  207. return pin - EQ5P_PIN_OFFSET_BANK_B;
  208. }
  209. static int eq5p_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  210. {
  211. return ARRAY_SIZE(eq5p_pins);
  212. }
  213. static const char *eq5p_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  214. unsigned int selector)
  215. {
  216. return pctldev->desc->pins[selector].name;
  217. }
  218. static int eq5p_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  219. unsigned int selector,
  220. const unsigned int **pins,
  221. unsigned int *num_pins)
  222. {
  223. *pins = &pctldev->desc->pins[selector].number;
  224. *num_pins = 1;
  225. return 0;
  226. }
  227. static int eq5p_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
  228. unsigned long *config)
  229. {
  230. enum pin_config_param param = pinconf_to_config_param(*config);
  231. struct eq5p_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  232. unsigned int offset = eq5p_pin_to_offset(pin);
  233. enum eq5p_bank bank = eq5p_pin_to_bank(pin);
  234. u32 val_ds, arg;
  235. bool pd, pu;
  236. pd = eq5p_test_bit(pctrl, bank, EQ5P_PD, offset);
  237. pu = eq5p_test_bit(pctrl, bank, EQ5P_PU, offset);
  238. switch (param) {
  239. case PIN_CONFIG_BIAS_DISABLE:
  240. arg = !(pd || pu);
  241. break;
  242. case PIN_CONFIG_BIAS_PULL_DOWN:
  243. arg = pd;
  244. break;
  245. case PIN_CONFIG_BIAS_PULL_UP:
  246. arg = pu;
  247. break;
  248. case PIN_CONFIG_DRIVE_STRENGTH:
  249. offset *= 2; /* two bits per pin */
  250. if (offset >= 32) {
  251. val_ds = readl(pctrl->base + eq5p_regs[bank][EQ5P_DS_HIGH]);
  252. offset -= 32;
  253. } else {
  254. val_ds = readl(pctrl->base + eq5p_regs[bank][EQ5P_DS_LOW]);
  255. }
  256. arg = (val_ds >> offset) & EQ5P_DS_MASK;
  257. break;
  258. default:
  259. return -ENOTSUPP;
  260. }
  261. *config = pinconf_to_config_packed(param, arg);
  262. return 0;
  263. }
  264. static void eq5p_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
  265. struct seq_file *s,
  266. unsigned int pin)
  267. {
  268. struct eq5p_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  269. const char *pin_name = pctrl->desc.pins[pin].name;
  270. unsigned int offset = eq5p_pin_to_offset(pin);
  271. enum eq5p_bank bank = eq5p_pin_to_bank(pin);
  272. const char *func_name, *bias;
  273. unsigned long ds_config;
  274. u32 drive_strength;
  275. bool pd, pu;
  276. int i, j;
  277. /*
  278. * First, let's get the function name. All pins have only two functions:
  279. * GPIO (IOCR == 0) and something else (IOCR == 1).
  280. */
  281. if (eq5p_test_bit(pctrl, bank, EQ5P_IOCR, offset)) {
  282. func_name = NULL;
  283. for (i = 0; i < ARRAY_SIZE(eq5p_functions); i++) {
  284. if (i == GPIO_FUNC_SELECTOR)
  285. continue;
  286. for (j = 0; j < eq5p_functions[i].ngroups; j++) {
  287. /* Groups and pins are the same thing for us. */
  288. const char *x = eq5p_functions[i].groups[j];
  289. if (strcmp(x, pin_name) == 0) {
  290. func_name = eq5p_functions[i].name;
  291. break;
  292. }
  293. }
  294. if (func_name)
  295. break;
  296. }
  297. /*
  298. * We have not found the function attached to this pin, this
  299. * should never occur as all pins have exactly two functions.
  300. */
  301. if (!func_name)
  302. func_name = "unknown";
  303. } else {
  304. func_name = eq5p_functions[GPIO_FUNC_SELECTOR].name;
  305. }
  306. /* Second, we retrieve the bias. */
  307. pd = eq5p_test_bit(pctrl, bank, EQ5P_PD, offset);
  308. pu = eq5p_test_bit(pctrl, bank, EQ5P_PU, offset);
  309. if (pd && pu)
  310. bias = "both";
  311. else if (pd && !pu)
  312. bias = "pulldown";
  313. else if (!pd && pu)
  314. bias = "pullup";
  315. else
  316. bias = "none";
  317. /* Third, we get the drive strength. */
  318. ds_config = pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, 0);
  319. eq5p_pinconf_get(pctldev, pin, &ds_config);
  320. drive_strength = pinconf_to_config_argument(ds_config);
  321. seq_printf(s, "function=%s bias=%s drive_strength=%d",
  322. func_name, bias, drive_strength);
  323. }
  324. static const struct pinctrl_ops eq5p_pinctrl_ops = {
  325. .get_groups_count = eq5p_pinctrl_get_groups_count,
  326. .get_group_name = eq5p_pinctrl_get_group_name,
  327. .get_group_pins = eq5p_pinctrl_get_group_pins,
  328. .pin_dbg_show = eq5p_pinctrl_pin_dbg_show,
  329. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  330. .dt_free_map = pinctrl_utils_free_map,
  331. };
  332. static int eq5p_pinmux_get_functions_count(struct pinctrl_dev *pctldev)
  333. {
  334. return ARRAY_SIZE(eq5p_functions);
  335. }
  336. static const char *eq5p_pinmux_get_function_name(struct pinctrl_dev *pctldev,
  337. unsigned int selector)
  338. {
  339. return eq5p_functions[selector].name;
  340. }
  341. static int eq5p_pinmux_get_function_groups(struct pinctrl_dev *pctldev,
  342. unsigned int selector,
  343. const char * const **groups,
  344. unsigned int *num_groups)
  345. {
  346. *groups = eq5p_functions[selector].groups;
  347. *num_groups = eq5p_functions[selector].ngroups;
  348. return 0;
  349. }
  350. static int eq5p_pinmux_set_mux(struct pinctrl_dev *pctldev,
  351. unsigned int func_selector, unsigned int pin)
  352. {
  353. struct eq5p_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  354. const char *func_name = eq5p_functions[func_selector].name;
  355. const char *group_name = pctldev->desc->pins[pin].name;
  356. bool is_gpio = func_selector == GPIO_FUNC_SELECTOR;
  357. unsigned int offset = eq5p_pin_to_offset(pin);
  358. enum eq5p_bank bank = eq5p_pin_to_bank(pin);
  359. u32 mask, val;
  360. dev_dbg(pctldev->dev, "func=%s group=%s\n", func_name, group_name);
  361. mask = BIT(offset);
  362. val = is_gpio ? 0 : mask;
  363. eq5p_update_bits(pctrl, bank, EQ5P_IOCR, mask, val);
  364. return 0;
  365. }
  366. static int eq5p_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
  367. struct pinctrl_gpio_range *range,
  368. unsigned int pin)
  369. {
  370. /* Pin numbers and group selectors are the same thing in our case. */
  371. return eq5p_pinmux_set_mux(pctldev, GPIO_FUNC_SELECTOR, pin);
  372. }
  373. static const struct pinmux_ops eq5p_pinmux_ops = {
  374. .get_functions_count = eq5p_pinmux_get_functions_count,
  375. .get_function_name = eq5p_pinmux_get_function_name,
  376. .get_function_groups = eq5p_pinmux_get_function_groups,
  377. .set_mux = eq5p_pinmux_set_mux,
  378. .gpio_request_enable = eq5p_pinmux_gpio_request_enable,
  379. .strict = true,
  380. };
  381. static int eq5p_pinconf_set_drive_strength(struct pinctrl_dev *pctldev,
  382. unsigned int pin, u32 arg)
  383. {
  384. struct eq5p_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  385. unsigned int offset = eq5p_pin_to_offset(pin);
  386. enum eq5p_bank bank = eq5p_pin_to_bank(pin);
  387. unsigned int reg;
  388. u32 mask, val;
  389. if (arg & ~EQ5P_DS_MASK) {
  390. dev_err(pctldev->dev, "Unsupported drive strength: %u\n", arg);
  391. return -EINVAL;
  392. }
  393. offset *= 2; /* two bits per pin */
  394. if (offset >= 32) {
  395. reg = EQ5P_DS_HIGH;
  396. offset -= 32;
  397. } else {
  398. reg = EQ5P_DS_LOW;
  399. }
  400. mask = EQ5P_DS_MASK << offset;
  401. val = arg << offset;
  402. eq5p_update_bits(pctrl, bank, reg, mask, val);
  403. return 0;
  404. }
  405. static int eq5p_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
  406. unsigned long *configs, unsigned int num_configs)
  407. {
  408. struct eq5p_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  409. const char *pin_name = pctldev->desc->pins[pin].name;
  410. unsigned int offset = eq5p_pin_to_offset(pin);
  411. enum eq5p_bank bank = eq5p_pin_to_bank(pin);
  412. struct device *dev = pctldev->dev;
  413. u32 val = BIT(offset);
  414. unsigned int i;
  415. for (i = 0; i < num_configs; i++) {
  416. enum pin_config_param param = pinconf_to_config_param(configs[i]);
  417. u32 arg = pinconf_to_config_argument(configs[i]);
  418. switch (param) {
  419. case PIN_CONFIG_BIAS_DISABLE:
  420. dev_dbg(dev, "pin=%s bias_disable\n", pin_name);
  421. eq5p_update_bits(pctrl, bank, EQ5P_PD, val, 0);
  422. eq5p_update_bits(pctrl, bank, EQ5P_PU, val, 0);
  423. break;
  424. case PIN_CONFIG_BIAS_PULL_DOWN:
  425. dev_dbg(dev, "pin=%s bias_pull_down arg=%u\n",
  426. pin_name, arg);
  427. if (arg == 0) /* cannot connect to GND */
  428. return -ENOTSUPP;
  429. eq5p_update_bits(pctrl, bank, EQ5P_PD, val, val);
  430. eq5p_update_bits(pctrl, bank, EQ5P_PU, val, 0);
  431. break;
  432. case PIN_CONFIG_BIAS_PULL_UP:
  433. dev_dbg(dev, "pin=%s bias_pull_up arg=%u\n",
  434. pin_name, arg);
  435. if (arg == 0) /* cannot connect to VDD */
  436. return -ENOTSUPP;
  437. eq5p_update_bits(pctrl, bank, EQ5P_PD, val, 0);
  438. eq5p_update_bits(pctrl, bank, EQ5P_PU, val, val);
  439. break;
  440. case PIN_CONFIG_DRIVE_STRENGTH:
  441. dev_dbg(dev, "pin=%s drive_strength arg=%u\n",
  442. pin_name, arg);
  443. eq5p_pinconf_set_drive_strength(pctldev, pin, arg);
  444. break;
  445. default:
  446. dev_err(dev, "Unsupported pinconf %u\n", param);
  447. return -ENOTSUPP;
  448. }
  449. }
  450. return 0;
  451. }
  452. static const struct pinconf_ops eq5p_pinconf_ops = {
  453. .is_generic = true,
  454. .pin_config_get = eq5p_pinconf_get,
  455. .pin_config_set = eq5p_pinconf_set,
  456. /* Pins and groups are equivalent in this driver. */
  457. .pin_config_group_get = eq5p_pinconf_get,
  458. .pin_config_group_set = eq5p_pinconf_set,
  459. };
  460. static int eq5p_probe(struct auxiliary_device *adev,
  461. const struct auxiliary_device_id *id)
  462. {
  463. struct device *dev = &adev->dev;
  464. struct pinctrl_dev *pctldev;
  465. struct eq5p_pinctrl *pctrl;
  466. int ret;
  467. pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL);
  468. if (!pctrl)
  469. return -ENOMEM;
  470. pctrl->base = (void __iomem *)dev_get_platdata(dev);
  471. pctrl->desc.name = dev_name(dev);
  472. pctrl->desc.pins = eq5p_pins;
  473. pctrl->desc.npins = ARRAY_SIZE(eq5p_pins);
  474. pctrl->desc.pctlops = &eq5p_pinctrl_ops;
  475. pctrl->desc.pmxops = &eq5p_pinmux_ops;
  476. pctrl->desc.confops = &eq5p_pinconf_ops;
  477. pctrl->desc.owner = THIS_MODULE;
  478. ret = devm_pinctrl_register_and_init(dev, &pctrl->desc, pctrl, &pctldev);
  479. if (ret)
  480. return dev_err_probe(dev, ret, "failed registering pinctrl device\n");
  481. ret = pinctrl_enable(pctldev);
  482. if (ret)
  483. return dev_err_probe(dev, ret, "failed enabling pinctrl device\n");
  484. return 0;
  485. }
  486. static const struct auxiliary_device_id eq5p_id_table[] = {
  487. { .name = "clk_eyeq.pinctrl" },
  488. {}
  489. };
  490. MODULE_DEVICE_TABLE(auxiliary, eq5p_id_table);
  491. static struct auxiliary_driver eq5p_driver = {
  492. .probe = eq5p_probe,
  493. .id_table = eq5p_id_table,
  494. };
  495. module_auxiliary_driver(eq5p_driver);