Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Qualcomm sm8650 pinctrl |
| 4 | * |
| 5 | * (C) Copyright 2024 Linaro Ltd. |
| 6 | * |
| 7 | */ |
| 8 | |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | |
| 11 | #include "pinctrl-qcom.h" |
| 12 | |
| 13 | #define MAX_PIN_NAME_LEN 32 |
| 14 | static char pin_name[MAX_PIN_NAME_LEN] __section(".data"); |
| 15 | |
| 16 | static const struct pinctrl_function msm_pinctrl_functions[] = { |
| 17 | {"qup2_se7", 1}, |
| 18 | {"gpio", 0}, |
Neil Armstrong | b7d0bb1 | 2024-11-25 09:29:11 +0100 | [diff] [blame] | 19 | {"pcie0_clk_req_n", 1}, |
| 20 | {"pcie1_clk_req_n", 1}, |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 21 | }; |
| 22 | |
Neil Armstrong | 219e52c | 2024-05-28 10:31:57 +0200 | [diff] [blame] | 23 | #define SDC_QDSD_PINGROUP(pg_name, ctl, pull, drv) \ |
| 24 | { \ |
| 25 | .name = pg_name, \ |
| 26 | .ctl_reg = ctl, \ |
| 27 | .io_reg = 0, \ |
| 28 | .pull_bit = pull, \ |
| 29 | .drv_bit = drv, \ |
| 30 | .oe_bit = -1, \ |
| 31 | .in_bit = -1, \ |
| 32 | .out_bit = -1, \ |
| 33 | } |
| 34 | |
| 35 | #define UFS_RESET(pg_name, ctl, io) \ |
| 36 | { \ |
| 37 | .name = pg_name, \ |
| 38 | .ctl_reg = ctl, \ |
| 39 | .io_reg = io, \ |
| 40 | .pull_bit = 3, \ |
| 41 | .drv_bit = 0, \ |
| 42 | .oe_bit = -1, \ |
| 43 | .in_bit = -1, \ |
| 44 | .out_bit = 0, \ |
| 45 | } |
| 46 | |
| 47 | static const struct msm_special_pin_data msm_special_pins_data[] = { |
| 48 | [0] = UFS_RESET("ufs_reset", 0xde004, 0xdf000), |
| 49 | [1] = SDC_QDSD_PINGROUP("sdc2_clk", 0xd6000, 14, 6), |
| 50 | [2] = SDC_QDSD_PINGROUP("sdc2_cmd", 0xd6000, 11, 3), |
| 51 | [3] = SDC_QDSD_PINGROUP("sdc2_data", 0xd6000, 9, 0), |
| 52 | }; |
| 53 | |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 54 | static const char *sm8650_get_function_name(struct udevice *dev, |
| 55 | unsigned int selector) |
| 56 | { |
| 57 | return msm_pinctrl_functions[selector].name; |
| 58 | } |
| 59 | |
| 60 | static const char *sm8650_get_pin_name(struct udevice *dev, |
| 61 | unsigned int selector) |
| 62 | { |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 63 | if (selector >= 210 && selector <= 213) |
Neil Armstrong | 219e52c | 2024-05-28 10:31:57 +0200 | [diff] [blame] | 64 | snprintf(pin_name, MAX_PIN_NAME_LEN, |
| 65 | msm_special_pins_data[selector - 210].name); |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 66 | else |
| 67 | snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector); |
| 68 | |
| 69 | return pin_name; |
| 70 | } |
| 71 | |
| 72 | static unsigned int sm8650_get_function_mux(__maybe_unused unsigned int pin, |
| 73 | unsigned int selector) |
| 74 | { |
| 75 | return msm_pinctrl_functions[selector].val; |
| 76 | } |
| 77 | |
| 78 | static struct msm_pinctrl_data sm8650_data = { |
| 79 | .pin_data = { |
| 80 | .pin_count = 214, |
| 81 | .special_pins_start = 210, |
Neil Armstrong | 219e52c | 2024-05-28 10:31:57 +0200 | [diff] [blame] | 82 | .special_pins_data = msm_special_pins_data, |
Neil Armstrong | 0653472 | 2024-04-05 10:15:11 +0200 | [diff] [blame] | 83 | }, |
| 84 | .functions_count = ARRAY_SIZE(msm_pinctrl_functions), |
| 85 | .get_function_name = sm8650_get_function_name, |
| 86 | .get_function_mux = sm8650_get_function_mux, |
| 87 | .get_pin_name = sm8650_get_pin_name, |
| 88 | }; |
| 89 | |
| 90 | static const struct udevice_id msm_pinctrl_ids[] = { |
| 91 | { .compatible = "qcom,sm8650-tlmm", .data = (ulong)&sm8650_data }, |
| 92 | { /* Sentinel */ } |
| 93 | }; |
| 94 | |
| 95 | U_BOOT_DRIVER(pinctrl_sm8650) = { |
| 96 | .name = "pinctrl_sm8650", |
| 97 | .id = UCLASS_NOP, |
| 98 | .of_match = msm_pinctrl_ids, |
| 99 | .ops = &msm_pinctrl_ops, |
| 100 | .bind = msm_pinctrl_bind, |
| 101 | }; |
| 102 | |