blob: 9f0f4085ce2da59c6496858bc1a79bdc18fd96a7 [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
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030010#include <common.h>
Caleb Connolly506eb532023-11-14 12:55:40 +000011#include <dm.h>
12
13#include "pinctrl-qcom.h"
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030014
Caleb Connollyfabb8972023-11-14 12:55:42 +000015#define NORTH 0x00500000
16#define SOUTH 0x00900000
17#define EAST 0x00100000
18
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030019#define MAX_PIN_NAME_LEN 32
20static char pin_name[MAX_PIN_NAME_LEN] __section(".data");
21
22static const struct pinctrl_function msm_pinctrl_functions[] = {
23 {"qup9", 1},
24 {"gpio", 0},
25};
26
Caleb Connollyfabb8972023-11-14 12:55:42 +000027static const unsigned int sdm845_pin_offsets[] = {
28 [0] = EAST, [1] = EAST, [2] = EAST, [3] = EAST, [4] = NORTH,
29 [5] = NORTH, [6] = NORTH, [7] = NORTH, [8] = EAST, [9] = EAST,
30 [10] = EAST, [11] = EAST, [12] = SOUTH, [13] = SOUTH, [14] = SOUTH,
31 [15] = SOUTH, [16] = SOUTH, [17] = SOUTH, [18] = SOUTH, [19] = SOUTH,
32 [20] = SOUTH, [21] = SOUTH, [22] = SOUTH, [23] = SOUTH, [24] = SOUTH,
33 [25] = SOUTH, [26] = SOUTH, [27] = EAST, [28] = EAST, [29] = EAST,
34 [30] = EAST, [31] = NORTH, [32] = NORTH, [33] = NORTH, [34] = NORTH,
35 [35] = SOUTH, [36] = SOUTH, [37] = SOUTH, [38] = NORTH, [39] = EAST,
36 [40] = SOUTH, [41] = EAST, [42] = EAST, [43] = EAST, [44] = EAST,
37 [45] = EAST, [46] = EAST, [47] = EAST, [48] = EAST, [49] = NORTH,
38 [50] = NORTH, [51] = NORTH, [52] = NORTH, [53] = NORTH, [54] = NORTH,
39 [55] = NORTH, [56] = NORTH, [57] = NORTH, [58] = NORTH, [59] = NORTH,
40 [60] = NORTH, [61] = NORTH, [62] = NORTH, [63] = NORTH, [64] = NORTH,
41 [65] = NORTH, [66] = NORTH, [67] = NORTH, [68] = NORTH, [69] = EAST,
42 [70] = EAST, [71] = EAST, [72] = EAST, [73] = EAST, [74] = EAST,
43 [75] = EAST, [76] = EAST, [77] = EAST, [78] = EAST, [79] = NORTH,
44 [80] = NORTH, [81] = NORTH, [82] = NORTH, [83] = NORTH, [84] = NORTH,
45 [85] = EAST, [86] = EAST, [87] = EAST, [88] = EAST, [89] = SOUTH,
46 [90] = SOUTH, [91] = SOUTH, [92] = SOUTH, [93] = SOUTH, [94] = SOUTH,
47 [95] = SOUTH, [96] = SOUTH, [97] = NORTH, [98] = NORTH, [99] = NORTH,
48 [100] = NORTH, [101] = NORTH, [102] = NORTH, [103] = NORTH, [104] = NORTH,
49 [105] = NORTH, [106] = NORTH, [107] = NORTH, [108] = NORTH, [109] = NORTH,
50 [110] = NORTH, [111] = NORTH, [112] = NORTH, [113] = NORTH, [114] = NORTH,
51 [115] = NORTH, [116] = NORTH, [117] = NORTH, [118] = NORTH, [119] = NORTH,
52 [120] = NORTH, [121] = NORTH, [122] = EAST, [123] = EAST, [124] = EAST,
53 [125] = EAST, [126] = EAST, [127] = NORTH, [128] = NORTH, [129] = NORTH,
54 [130] = NORTH, [131] = NORTH, [132] = NORTH, [133] = NORTH, [134] = NORTH,
55 [135] = NORTH, [136] = NORTH, [137] = NORTH, [138] = NORTH, [139] = NORTH,
56 [140] = NORTH, [141] = NORTH, [142] = NORTH, [143] = NORTH, [144] = NORTH,
57 [145] = NORTH, [146] = NORTH, [147] = NORTH, [148] = NORTH, [149] = NORTH,
58};
59
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030060static const char *sdm845_get_function_name(struct udevice *dev,
61 unsigned int selector)
62{
63 return msm_pinctrl_functions[selector].name;
64}
65
66static const char *sdm845_get_pin_name(struct udevice *dev,
67 unsigned int selector)
68{
Caleb Connollyfabb8972023-11-14 12:55:42 +000069 snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector);
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030070 return pin_name;
71}
72
73static unsigned int sdm845_get_function_mux(unsigned int selector)
74{
75 return msm_pinctrl_functions[selector].val;
76}
77
Caleb Connolly506eb532023-11-14 12:55:40 +000078static struct msm_pinctrl_data sdm845_data = {
Caleb Connollyfabb8972023-11-14 12:55:42 +000079 .pin_data = {
80 .pin_offsets = sdm845_pin_offsets,
81 .pin_count = ARRAY_SIZE(sdm845_pin_offsets),
82 },
Dzmitry Sankouskie9be2042021-10-17 13:44:29 +030083 .functions_count = ARRAY_SIZE(msm_pinctrl_functions),
84 .get_function_name = sdm845_get_function_name,
85 .get_function_mux = sdm845_get_function_mux,
86 .get_pin_name = sdm845_get_pin_name,
87};
Caleb Connolly506eb532023-11-14 12:55:40 +000088
89static const struct udevice_id msm_pinctrl_ids[] = {
90 { .compatible = "qcom,sdm845-pinctrl", .data = (ulong)&sdm845_data },
91 { /* Sentinal */ }
92};
93
94U_BOOT_DRIVER(pinctrl_sdm845) = {
95 .name = "pinctrl_sdm845",
96 .id = UCLASS_NOP,
97 .of_match = msm_pinctrl_ids,
98 .ops = &msm_pinctrl_ops,
99 .bind = msm_pinctrl_bind,
100};