Caleb Connolly | 022ba9b | 2024-04-10 19:52:38 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Qualcomm sm8250 pinctrl |
| 4 | * |
| 5 | * (C) Copyright 2024 Linaro Ltd. |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <dm.h> |
| 10 | |
| 11 | #include "pinctrl-qcom.h" |
| 12 | |
| 13 | #define WEST 0x00000000 |
| 14 | #define SOUTH 0x00400000 |
| 15 | #define NORTH 0x00800000 |
| 16 | |
| 17 | #define MAX_PIN_NAME_LEN 32 |
| 18 | static char pin_name[MAX_PIN_NAME_LEN] __section(".data"); |
| 19 | |
| 20 | static const struct pinctrl_function msm_pinctrl_functions[] = { { "qup12", 1 }, |
Neil Armstrong | 2837f94 | 2024-09-11 20:07:15 +0200 | [diff] [blame] | 21 | { "gpio", 0 }, }; |
| 22 | #define SDC_PINGROUP(pg_name, ctl, pull, drv) \ |
| 23 | { \ |
| 24 | .name = pg_name, \ |
| 25 | .ctl_reg = ctl, \ |
| 26 | .io_reg = 0, \ |
| 27 | .pull_bit = pull, \ |
| 28 | .drv_bit = drv, \ |
| 29 | .oe_bit = -1, \ |
| 30 | .in_bit = -1, \ |
| 31 | .out_bit = -1, \ |
| 32 | } |
| 33 | |
| 34 | #define UFS_RESET(pg_name, offset) \ |
| 35 | { \ |
| 36 | .name = pg_name, \ |
| 37 | .ctl_reg = offset, \ |
| 38 | .io_reg = offset + 0x4, \ |
| 39 | .pull_bit = 3, \ |
| 40 | .drv_bit = 0, \ |
| 41 | .oe_bit = -1, \ |
| 42 | .in_bit = -1, \ |
| 43 | .out_bit = 0, \ |
| 44 | } |
| 45 | |
| 46 | static const struct msm_special_pin_data sm8250_special_pins_data[] = { |
| 47 | [0] = UFS_RESET("ufs_reset", SOUTH + 0xb8000), |
| 48 | [1] = SDC_PINGROUP("sdc2_clk", NORTH + 0xb7000, 14, 6), |
| 49 | [2] = SDC_PINGROUP("sdc2_cmd", NORTH + 0xb7000, 11, 3), |
| 50 | [3] = SDC_PINGROUP("sdc2_data", NORTH + 0xb7000, 9, 0), |
| 51 | }; |
Caleb Connolly | 022ba9b | 2024-04-10 19:52:38 +0200 | [diff] [blame] | 52 | |
| 53 | static const unsigned int sm8250_pin_offsets[] = { |
| 54 | [0] = SOUTH, [1] = SOUTH, [2] = SOUTH, [3] = SOUTH, [4] = NORTH, [5] = NORTH, |
| 55 | [6] = NORTH, [7] = NORTH, [8] = NORTH, [9] = NORTH, [10] = NORTH, [11] = NORTH, |
| 56 | [12] = NORTH, [13] = NORTH, [14] = NORTH, [15] = NORTH, [16] = NORTH, [17] = NORTH, |
| 57 | [18] = NORTH, [19] = NORTH, [20] = NORTH, [21] = NORTH, [22] = NORTH, [23] = NORTH, |
| 58 | [24] = SOUTH, [25] = SOUTH, [26] = SOUTH, [27] = SOUTH, [28] = NORTH, [29] = NORTH, |
| 59 | [30] = NORTH, [31] = NORTH, [32] = SOUTH, [33] = SOUTH, [34] = SOUTH, [35] = SOUTH, |
| 60 | [36] = SOUTH, [37] = SOUTH, [38] = SOUTH, [39] = SOUTH, [40] = SOUTH, [41] = SOUTH, |
| 61 | [42] = SOUTH, [43] = SOUTH, [44] = SOUTH, [45] = SOUTH, [46] = SOUTH, [47] = SOUTH, |
| 62 | [48] = SOUTH, [49] = SOUTH, [50] = SOUTH, [51] = SOUTH, [52] = SOUTH, [53] = SOUTH, |
| 63 | [54] = SOUTH, [55] = SOUTH, [56] = SOUTH, [57] = SOUTH, [58] = SOUTH, [59] = SOUTH, |
| 64 | [60] = SOUTH, [61] = SOUTH, [62] = SOUTH, [63] = SOUTH, [64] = SOUTH, [65] = SOUTH, |
| 65 | [66] = NORTH, [67] = NORTH, [68] = NORTH, [69] = SOUTH, [70] = SOUTH, [71] = SOUTH, |
| 66 | [72] = SOUTH, [73] = SOUTH, [74] = SOUTH, [75] = SOUTH, [76] = SOUTH, [77] = NORTH, |
| 67 | [78] = NORTH, [79] = NORTH, [80] = NORTH, [81] = NORTH, [82] = NORTH, [83] = NORTH, |
| 68 | [84] = NORTH, [85] = SOUTH, [86] = SOUTH, [87] = SOUTH, [88] = SOUTH, [89] = SOUTH, |
| 69 | [90] = SOUTH, [91] = SOUTH, [92] = NORTH, [93] = NORTH, [94] = NORTH, [95] = NORTH, |
| 70 | [96] = NORTH, [97] = NORTH, [98] = NORTH, [99] = NORTH, [100] = NORTH, [101] = NORTH, |
| 71 | [102] = NORTH, [103] = NORTH, [104] = NORTH, [105] = NORTH, [106] = NORTH, [107] = NORTH, |
| 72 | [108] = NORTH, [109] = NORTH, [110] = NORTH, [111] = NORTH, [112] = NORTH, [113] = NORTH, |
| 73 | [114] = NORTH, [115] = NORTH, [116] = NORTH, [117] = NORTH, [118] = NORTH, [119] = NORTH, |
| 74 | [120] = NORTH, [121] = NORTH, [122] = NORTH, [123] = NORTH, [124] = NORTH, [125] = SOUTH, |
| 75 | [126] = SOUTH, [127] = SOUTH, [128] = SOUTH, [129] = SOUTH, [130] = SOUTH, [131] = SOUTH, |
| 76 | [132] = SOUTH, [133] = WEST, [134] = WEST, [135] = WEST, [136] = WEST, [137] = WEST, |
| 77 | [138] = WEST, [139] = WEST, [140] = WEST, [141] = WEST, [142] = WEST, [143] = WEST, |
| 78 | [144] = WEST, [145] = WEST, [146] = WEST, [147] = WEST, [148] = WEST, [149] = WEST, |
| 79 | [150] = WEST, [151] = WEST, [152] = WEST, [153] = WEST, [154] = WEST, [155] = WEST, |
| 80 | [156] = WEST, [157] = WEST, [158] = WEST, [159] = WEST, [160] = WEST, [161] = WEST, |
| 81 | [162] = WEST, [163] = WEST, [164] = WEST, [165] = WEST, [166] = WEST, [167] = WEST, |
| 82 | [168] = WEST, [169] = WEST, [170] = WEST, [171] = WEST, [172] = WEST, [173] = WEST, |
| 83 | [174] = WEST, [175] = WEST, [176] = WEST, [177] = WEST, [178] = WEST, [179] = WEST, |
Caleb Connolly | 022ba9b | 2024-04-10 19:52:38 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static const char *sm8250_get_function_name(struct udevice *dev, unsigned int selector) |
| 87 | { |
| 88 | return msm_pinctrl_functions[selector].name; |
| 89 | } |
| 90 | |
| 91 | static const char *sm8250_get_pin_name(struct udevice *dev, unsigned int selector) |
| 92 | { |
Neil Armstrong | 2837f94 | 2024-09-11 20:07:15 +0200 | [diff] [blame] | 93 | if (selector >= 180 && selector <= 183) |
| 94 | snprintf(pin_name, MAX_PIN_NAME_LEN, |
| 95 | sm8250_special_pins_data[selector - 180].name); |
| 96 | else |
| 97 | snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector); |
| 98 | |
Caleb Connolly | 022ba9b | 2024-04-10 19:52:38 +0200 | [diff] [blame] | 99 | return pin_name; |
| 100 | } |
| 101 | |
| 102 | static unsigned int sm8250_get_function_mux(__maybe_unused unsigned int pin, unsigned int selector) |
| 103 | { |
| 104 | return msm_pinctrl_functions[selector].val; |
| 105 | } |
| 106 | |
| 107 | static struct msm_pinctrl_data sm8250_data = { |
| 108 | .pin_data = { |
| 109 | .pin_offsets = sm8250_pin_offsets, |
| 110 | .pin_count = ARRAY_SIZE(sm8250_pin_offsets), |
| 111 | .special_pins_start = 180, |
Neil Armstrong | 2837f94 | 2024-09-11 20:07:15 +0200 | [diff] [blame] | 112 | .special_pins_data = sm8250_special_pins_data, |
Caleb Connolly | 022ba9b | 2024-04-10 19:52:38 +0200 | [diff] [blame] | 113 | }, |
| 114 | .functions_count = ARRAY_SIZE(msm_pinctrl_functions), |
| 115 | .get_function_name = sm8250_get_function_name, |
| 116 | .get_function_mux = sm8250_get_function_mux, |
| 117 | .get_pin_name = sm8250_get_pin_name, |
| 118 | }; |
| 119 | |
| 120 | static const struct udevice_id msm_pinctrl_ids[] = { |
| 121 | { |
| 122 | .compatible = "qcom,sm8250-pinctrl", |
| 123 | .data = (ulong)&sm8250_data |
| 124 | }, |
| 125 | { /* Sentinel */ } }; |
| 126 | |
| 127 | U_BOOT_DRIVER(pinctrl_sm8250) = { |
| 128 | .name = "pinctrl_sm8250", |
| 129 | .id = UCLASS_NOP, |
| 130 | .of_match = msm_pinctrl_ids, |
| 131 | .ops = &msm_pinctrl_ops, |
| 132 | .bind = msm_pinctrl_bind, |
| 133 | }; |