blob: f1a23f510999da4329074c15ab7ee5bbdf0fa44f [file] [log] [blame]
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Qualcomm SDM845 pinctrl
4 *
5 * (C) Copyright 2021 Dzmitry Sankouski <dsankouski@gmail.com>
Caleb Connollyfabb8972023-11-14 12:55:42 +00006 * (C) Copyright 2023 Linaro Ltd.
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +03007 *
8 */
9
Caleb Connolly506eb532023-11-14 12:55:40 +000010#include <dm.h>
11
12#include "pinctrl-qcom.h"
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030013
Caleb Connollyfabb8972023-11-14 12:55:42 +000014#define NORTH 0x00500000
15#define SOUTH 0x00900000
16#define EAST 0x00100000
17
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030018#define MAX_PIN_NAME_LEN 32
19static char pin_name[MAX_PIN_NAME_LEN] __section(".data");
20
21static const struct pinctrl_function msm_pinctrl_functions[] = {
22 {"qup9", 1},
23 {"gpio", 0},
24};
25
Caleb Connollyfabb8972023-11-14 12:55:42 +000026static const unsigned int sdm845_pin_offsets[] = {
27 [0] = EAST, [1] = EAST, [2] = EAST, [3] = EAST, [4] = NORTH,
28 [5] = NORTH, [6] = NORTH, [7] = NORTH, [8] = EAST, [9] = EAST,
29 [10] = EAST, [11] = EAST, [12] = SOUTH, [13] = SOUTH, [14] = SOUTH,
30 [15] = SOUTH, [16] = SOUTH, [17] = SOUTH, [18] = SOUTH, [19] = SOUTH,
31 [20] = SOUTH, [21] = SOUTH, [22] = SOUTH, [23] = SOUTH, [24] = SOUTH,
32 [25] = SOUTH, [26] = SOUTH, [27] = EAST, [28] = EAST, [29] = EAST,
33 [30] = EAST, [31] = NORTH, [32] = NORTH, [33] = NORTH, [34] = NORTH,
34 [35] = SOUTH, [36] = SOUTH, [37] = SOUTH, [38] = NORTH, [39] = EAST,
35 [40] = SOUTH, [41] = EAST, [42] = EAST, [43] = EAST, [44] = EAST,
36 [45] = EAST, [46] = EAST, [47] = EAST, [48] = EAST, [49] = NORTH,
37 [50] = NORTH, [51] = NORTH, [52] = NORTH, [53] = NORTH, [54] = NORTH,
38 [55] = NORTH, [56] = NORTH, [57] = NORTH, [58] = NORTH, [59] = NORTH,
39 [60] = NORTH, [61] = NORTH, [62] = NORTH, [63] = NORTH, [64] = NORTH,
40 [65] = NORTH, [66] = NORTH, [67] = NORTH, [68] = NORTH, [69] = EAST,
41 [70] = EAST, [71] = EAST, [72] = EAST, [73] = EAST, [74] = EAST,
42 [75] = EAST, [76] = EAST, [77] = EAST, [78] = EAST, [79] = NORTH,
43 [80] = NORTH, [81] = NORTH, [82] = NORTH, [83] = NORTH, [84] = NORTH,
44 [85] = EAST, [86] = EAST, [87] = EAST, [88] = EAST, [89] = SOUTH,
45 [90] = SOUTH, [91] = SOUTH, [92] = SOUTH, [93] = SOUTH, [94] = SOUTH,
46 [95] = SOUTH, [96] = SOUTH, [97] = NORTH, [98] = NORTH, [99] = NORTH,
47 [100] = NORTH, [101] = NORTH, [102] = NORTH, [103] = NORTH, [104] = NORTH,
48 [105] = NORTH, [106] = NORTH, [107] = NORTH, [108] = NORTH, [109] = NORTH,
49 [110] = NORTH, [111] = NORTH, [112] = NORTH, [113] = NORTH, [114] = NORTH,
50 [115] = NORTH, [116] = NORTH, [117] = NORTH, [118] = NORTH, [119] = NORTH,
51 [120] = NORTH, [121] = NORTH, [122] = EAST, [123] = EAST, [124] = EAST,
52 [125] = EAST, [126] = EAST, [127] = NORTH, [128] = NORTH, [129] = NORTH,
53 [130] = NORTH, [131] = NORTH, [132] = NORTH, [133] = NORTH, [134] = NORTH,
54 [135] = NORTH, [136] = NORTH, [137] = NORTH, [138] = NORTH, [139] = NORTH,
55 [140] = NORTH, [141] = NORTH, [142] = NORTH, [143] = NORTH, [144] = NORTH,
56 [145] = NORTH, [146] = NORTH, [147] = NORTH, [148] = NORTH, [149] = NORTH,
57};
58
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030059static const char *sdm845_get_function_name(struct udevice *dev,
60 unsigned int selector)
61{
62 return msm_pinctrl_functions[selector].name;
63}
64
65static const char *sdm845_get_pin_name(struct udevice *dev,
66 unsigned int selector)
67{
Caleb Connollydab0d502024-04-09 20:03:05 +020068 static const char *special_pins_names[] = {
69 "ufs_reset",
70 "sdc2_clk",
71 "sdc2_cmd",
72 "sdc2_data",
73 };
74
75 if (selector >= 150 && selector <= 154)
76 snprintf(pin_name, MAX_PIN_NAME_LEN, special_pins_names[selector - 150]);
77 else
78 snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector);
79
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030080 return pin_name;
81}
82
Volodymyr Babchukc4cc9792024-03-11 21:33:46 +000083static unsigned int sdm845_get_function_mux(__maybe_unused unsigned int pin,
84 unsigned int selector)
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030085{
86 return msm_pinctrl_functions[selector].val;
87}
88
Caleb Connolly190005c2024-02-26 17:26:17 +000089static const struct msm_pinctrl_data sdm845_data = {
Caleb Connollyfabb8972023-11-14 12:55:42 +000090 .pin_data = {
91 .pin_offsets = sdm845_pin_offsets,
Caleb Connolly190005c2024-02-26 17:26:17 +000092 .pin_count = 154,
93 .special_pins_start = 150,
Caleb Connollyfabb8972023-11-14 12:55:42 +000094 },
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030095 .functions_count = ARRAY_SIZE(msm_pinctrl_functions),
96 .get_function_name = sdm845_get_function_name,
97 .get_function_mux = sdm845_get_function_mux,
98 .get_pin_name = sdm845_get_pin_name,
99};
Caleb Connolly506eb532023-11-14 12:55:40 +0000100
101static const struct udevice_id msm_pinctrl_ids[] = {
102 { .compatible = "qcom,sdm845-pinctrl", .data = (ulong)&sdm845_data },
103 { /* Sentinal */ }
104};
105
106U_BOOT_DRIVER(pinctrl_sdm845) = {
107 .name = "pinctrl_sdm845",
108 .id = UCLASS_NOP,
109 .of_match = msm_pinctrl_ids,
110 .ops = &msm_pinctrl_ops,
111 .bind = msm_pinctrl_bind,
112};