Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Qualcomm SDM845 pinctrl |
| 4 | * |
| 5 | * (C) Copyright 2021 Dzmitry Sankouski <dsankouski@gmail.com> |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 6 | * (C) Copyright 2023 Linaro Ltd. |
Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 7 | * |
| 8 | */ |
| 9 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | |
| 12 | #include "pinctrl-qcom.h" |
Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 13 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 14 | #define NORTH 0x00500000 |
| 15 | #define SOUTH 0x00900000 |
| 16 | #define EAST 0x00100000 |
| 17 | |
Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 18 | #define MAX_PIN_NAME_LEN 32 |
| 19 | static char pin_name[MAX_PIN_NAME_LEN] __section(".data"); |
| 20 | |
| 21 | static const struct pinctrl_function msm_pinctrl_functions[] = { |
| 22 | {"qup9", 1}, |
| 23 | {"gpio", 0}, |
| 24 | }; |
| 25 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 26 | static 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 Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 59 | static const char *sdm845_get_function_name(struct udevice *dev, |
| 60 | unsigned int selector) |
| 61 | { |
| 62 | return msm_pinctrl_functions[selector].name; |
| 63 | } |
| 64 | |
| 65 | static const char *sdm845_get_pin_name(struct udevice *dev, |
| 66 | unsigned int selector) |
| 67 | { |
Caleb Connolly | dab0d50 | 2024-04-09 20:03:05 +0200 | [diff] [blame] | 68 | 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 Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 80 | return pin_name; |
| 81 | } |
| 82 | |
Volodymyr Babchuk | c4cc979 | 2024-03-11 21:33:46 +0000 | [diff] [blame] | 83 | static unsigned int sdm845_get_function_mux(__maybe_unused unsigned int pin, |
| 84 | unsigned int selector) |
Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 85 | { |
| 86 | return msm_pinctrl_functions[selector].val; |
| 87 | } |
| 88 | |
Caleb Connolly | 190005c | 2024-02-26 17:26:17 +0000 | [diff] [blame] | 89 | static const struct msm_pinctrl_data sdm845_data = { |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 90 | .pin_data = { |
| 91 | .pin_offsets = sdm845_pin_offsets, |
Caleb Connolly | 190005c | 2024-02-26 17:26:17 +0000 | [diff] [blame] | 92 | .pin_count = 154, |
| 93 | .special_pins_start = 150, |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 94 | }, |
Dzmitry Sankouski | e9be204 | 2021-10-17 13:44:29 +0300 | [diff] [blame] | 95 | .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 Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 100 | |
| 101 | static const struct udevice_id msm_pinctrl_ids[] = { |
| 102 | { .compatible = "qcom,sdm845-pinctrl", .data = (ulong)&sdm845_data }, |
| 103 | { /* Sentinal */ } |
| 104 | }; |
| 105 | |
| 106 | U_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 | }; |