blob: fb6defaeddf0237105e194ca9b4825b4a90528e4 [file] [log] [blame]
Sumit Garg46ad40b2022-07-12 12:42:10 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Qualcomm QCS404 pinctrl
4 *
5 * (C) Copyright 2022 Sumit Garg <sumit.garg@linaro.org>
6 */
7
Caleb Connolly506eb532023-11-14 12:55:40 +00008#include <dm.h>
9
10#include "pinctrl-qcom.h"
Sumit Garg46ad40b2022-07-12 12:42:10 +053011
Caleb Connollyab6a1ac2024-02-26 17:26:18 +000012#define NORTH 0x00300000
13#define SOUTH 0x00000000
14#define EAST 0x06b00000
15
Sumit Garg46ad40b2022-07-12 12:42:10 +053016#define MAX_PIN_NAME_LEN 32
17static char pin_name[MAX_PIN_NAME_LEN] __section(".data");
18static const char * const msm_pinctrl_pins[] = {
Caleb Connollyab6a1ac2024-02-26 17:26:18 +000019 "sdc1_rclk",
20 "sdc1_clk",
21 "sdc1_cmd",
22 "sdc1_data",
23 "sdc2_clk",
24 "sdc2_cmd",
25 "sdc2_data",
Sumit Garg46ad40b2022-07-12 12:42:10 +053026};
27
28static const struct pinctrl_function msm_pinctrl_functions[] = {
Caleb Connollyab6a1ac2024-02-26 17:26:18 +000029 {"gpio", 0},
Sumit Garg09aea5d2023-02-01 19:28:51 +053030 {"rgmii_int", 1},
31 {"rgmii_ck", 1},
32 {"rgmii_tx", 1},
33 {"rgmii_ctl", 1},
34 {"rgmii_rx", 1},
35 {"rgmii_mdio", 1},
36 {"rgmii_mdc", 1},
Sumit Garg00e84692023-02-01 19:28:59 +053037 {"blsp_i2c0", 3},
38 {"blsp_i2c1", 2},
39 {"blsp_i2c_sda_a2", 3},
40 {"blsp_i2c_scl_a2", 3},
41 {"blsp_i2c3", 2},
42 {"blsp_i2c4", 1},
Caleb Connollyab6a1ac2024-02-26 17:26:18 +000043 {"blsp_uart_tx_a2", 1},
44 {"blsp_uart_rx_a2", 1},
45};
46
47static const unsigned int qcs404_pin_offsets[] = {
48 [0] = SOUTH, [1] = SOUTH, [2] = SOUTH, [3] = SOUTH, [4] = SOUTH,
49 [5] = SOUTH, [6] = SOUTH, [7] = SOUTH, [8] = SOUTH, [9] = SOUTH,
50 [10] = SOUTH, [11] = SOUTH, [12] = SOUTH, [13] = SOUTH, [14] = SOUTH,
51 [15] = SOUTH, [16] = SOUTH, [17] = NORTH, [18] = NORTH, [19] = NORTH,
52 [20] = NORTH, [21] = SOUTH, [22] = NORTH, [23] = NORTH, [24] = NORTH,
53 [25] = NORTH, [26] = EAST, [27] = EAST, [28] = EAST, [29] = EAST,
54 [30] = NORTH, [31] = NORTH, [32] = NORTH, [33] = NORTH, [34] = SOUTH,
55 [35] = SOUTH, [36] = NORTH, [37] = NORTH, [38] = NORTH, [39] = EAST,
56 [40] = EAST, [41] = EAST, [42] = EAST, [43] = EAST, [44] = EAST,
57 [45] = EAST, [46] = EAST, [47] = EAST, [48] = EAST, [49] = EAST,
58 [50] = EAST, [51] = EAST, [52] = EAST, [53] = EAST, [54] = EAST,
59 [55] = EAST, [56] = EAST, [57] = EAST, [58] = EAST, [59] = EAST,
60 [60] = NORTH, [61] = NORTH, [62] = NORTH, [63] = NORTH, [64] = NORTH,
61 [65] = NORTH, [66] = NORTH, [67] = NORTH, [68] = NORTH, [69] = NORTH,
62 [70] = NORTH, [71] = NORTH, [72] = NORTH, [73] = NORTH, [74] = NORTH,
63 [75] = NORTH, [76] = NORTH, [77] = NORTH, [78] = EAST, [79] = EAST,
64 [80] = EAST, [81] = EAST, [82] = NORTH, [83] = NORTH, [84] = NORTH,
65 [85] = NORTH, [86] = EAST, [87] = EAST, [88] = EAST, [89] = EAST,
66 [90] = EAST, [91] = EAST, [92] = EAST, [93] = EAST, [94] = EAST,
67 [95] = EAST, [96] = EAST, [97] = EAST, [98] = EAST, [99] = EAST,
68 [100] = EAST, [101] = EAST, [102] = EAST, [103] = EAST, [104] = EAST,
69 [105] = EAST, [106] = EAST, [107] = EAST, [108] = EAST, [109] = EAST,
70 [110] = EAST, [111] = EAST, [112] = EAST, [113] = EAST, [114] = EAST,
71 [115] = EAST, [116] = EAST, [117] = NORTH, [118] = NORTH, [119] = EAST,
72 /*
73 * There's 126 pins but the last ones are special and have non-standard registers
74 * so we leave them out here. The pinctrl and GPIO drivers both currently ignore
75 * these pins.
76 */
Sumit Garg46ad40b2022-07-12 12:42:10 +053077};
78
79static const char *qcs404_get_function_name(struct udevice *dev,
80 unsigned int selector)
81{
82 return msm_pinctrl_functions[selector].name;
83}
84
85static const char *qcs404_get_pin_name(struct udevice *dev,
86 unsigned int selector)
87{
88 if (selector < 120) {
Caleb Connollyab6a1ac2024-02-26 17:26:18 +000089 snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector);
Sumit Garg46ad40b2022-07-12 12:42:10 +053090 return pin_name;
91 } else {
92 return msm_pinctrl_pins[selector - 120];
93 }
94}
95
Volodymyr Babchukc4cc9792024-03-11 21:33:46 +000096static unsigned int qcs404_get_function_mux(__maybe_unused unsigned int pin,
97 unsigned int selector)
Sumit Garg46ad40b2022-07-12 12:42:10 +053098{
99 return msm_pinctrl_functions[selector].val;
100}
101
Caleb Connolly190005c2024-02-26 17:26:17 +0000102static const struct msm_pinctrl_data qcs404_data = {
103 .pin_data = {
104 .pin_count = 126,
Caleb Connollyab6a1ac2024-02-26 17:26:18 +0000105 .pin_offsets = qcs404_pin_offsets,
Caleb Connolly190005c2024-02-26 17:26:17 +0000106 .special_pins_start = 120,
107 },
Sumit Garg46ad40b2022-07-12 12:42:10 +0530108 .functions_count = ARRAY_SIZE(msm_pinctrl_functions),
109 .get_function_name = qcs404_get_function_name,
110 .get_function_mux = qcs404_get_function_mux,
111 .get_pin_name = qcs404_get_pin_name,
112};
Caleb Connolly506eb532023-11-14 12:55:40 +0000113
114static const struct udevice_id msm_pinctrl_ids[] = {
115 { .compatible = "qcom,qcs404-pinctrl", .data = (ulong)&qcs404_data },
116 { /* Sentinal */ }
117};
118
119U_BOOT_DRIVER(pinctrl_qcs404) = {
120 .name = "pinctrl_qcs404",
121 .id = UCLASS_NOP,
122 .of_match = msm_pinctrl_ids,
123 .ops = &msm_pinctrl_ops,
124 .bind = msm_pinctrl_bind,
125};