Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * TLMM driver for Qualcomm APQ8016, APQ8096 |
| 4 | * |
| 5 | * (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <asm/io.h> |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 13 | #include <dm/device_compat.h> |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 14 | #include <dm/device-internal.h> |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 15 | #include <dm/lists.h> |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 16 | #include <asm/gpio.h> |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 17 | #include <dm/pinctrl.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 19 | #include <mach/gpio.h> |
| 20 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 21 | #include "pinctrl-qcom.h" |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 22 | |
| 23 | struct msm_pinctrl_priv { |
| 24 | phys_addr_t base; |
| 25 | struct msm_pinctrl_data *data; |
| 26 | }; |
| 27 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 28 | #define GPIO_CONFIG_REG(priv, x) \ |
| 29 | (qcom_pin_offset((priv)->data->pin_data.pin_offsets, x)) |
| 30 | |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 31 | #define TLMM_GPIO_PULL_MASK GENMASK(1, 0) |
| 32 | #define TLMM_FUNC_SEL_MASK GENMASK(5, 2) |
| 33 | #define TLMM_DRV_STRENGTH_MASK GENMASK(8, 6) |
Ramon Fried | 772a99a | 2019-01-12 11:47:27 +0200 | [diff] [blame] | 34 | #define TLMM_GPIO_DISABLE BIT(9) |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 35 | |
| 36 | static const struct pinconf_param msm_conf_params[] = { |
Sumit Garg | fd1ad93 | 2023-02-01 19:28:52 +0530 | [diff] [blame] | 37 | { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 2 }, |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 38 | { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, |
Sumit Garg | fd1ad93 | 2023-02-01 19:28:52 +0530 | [diff] [blame] | 39 | { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 3 }, |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | static int msm_get_functions_count(struct udevice *dev) |
| 43 | { |
| 44 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 45 | |
| 46 | return priv->data->functions_count; |
| 47 | } |
| 48 | |
| 49 | static int msm_get_pins_count(struct udevice *dev) |
| 50 | { |
| 51 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 52 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 53 | return priv->data->pin_data.pin_count; |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static const char *msm_get_function_name(struct udevice *dev, |
| 57 | unsigned int selector) |
| 58 | { |
| 59 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 60 | |
| 61 | return priv->data->get_function_name(dev, selector); |
| 62 | } |
| 63 | |
| 64 | static int msm_pinctrl_probe(struct udevice *dev) |
| 65 | { |
| 66 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 67 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 68 | priv->base = dev_read_addr(dev); |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 69 | priv->data = (struct msm_pinctrl_data *)dev_get_driver_data(dev); |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 70 | |
| 71 | return priv->base == FDT_ADDR_T_NONE ? -EINVAL : 0; |
| 72 | } |
| 73 | |
| 74 | static const char *msm_get_pin_name(struct udevice *dev, unsigned int selector) |
| 75 | { |
| 76 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 77 | |
| 78 | return priv->data->get_pin_name(dev, selector); |
| 79 | } |
| 80 | |
| 81 | static int msm_pinmux_set(struct udevice *dev, unsigned int pin_selector, |
| 82 | unsigned int func_selector) |
| 83 | { |
| 84 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 85 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 86 | clrsetbits_le32(priv->base + GPIO_CONFIG_REG(priv, pin_selector), |
Ramon Fried | 772a99a | 2019-01-12 11:47:27 +0200 | [diff] [blame] | 87 | TLMM_FUNC_SEL_MASK | TLMM_GPIO_DISABLE, |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 88 | priv->data->get_function_mux(func_selector) << 2); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static int msm_pinconf_set(struct udevice *dev, unsigned int pin_selector, |
| 93 | unsigned int param, unsigned int argument) |
| 94 | { |
| 95 | struct msm_pinctrl_priv *priv = dev_get_priv(dev); |
| 96 | |
| 97 | switch (param) { |
| 98 | case PIN_CONFIG_DRIVE_STRENGTH: |
Sumit Garg | fd1ad93 | 2023-02-01 19:28:52 +0530 | [diff] [blame] | 99 | argument = (argument / 2) - 1; |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 100 | clrsetbits_le32(priv->base + GPIO_CONFIG_REG(priv, pin_selector), |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 101 | TLMM_DRV_STRENGTH_MASK, argument << 6); |
| 102 | break; |
| 103 | case PIN_CONFIG_BIAS_DISABLE: |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 104 | clrbits_le32(priv->base + GPIO_CONFIG_REG(priv, pin_selector), |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 105 | TLMM_GPIO_PULL_MASK); |
| 106 | break; |
Sumit Garg | fd1ad93 | 2023-02-01 19:28:52 +0530 | [diff] [blame] | 107 | case PIN_CONFIG_BIAS_PULL_UP: |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 108 | clrsetbits_le32(priv->base + GPIO_CONFIG_REG(priv, pin_selector), |
Sumit Garg | fd1ad93 | 2023-02-01 19:28:52 +0530 | [diff] [blame] | 109 | TLMM_GPIO_PULL_MASK, argument); |
| 110 | break; |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 111 | default: |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 118 | struct pinctrl_ops msm_pinctrl_ops = { |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 119 | .get_pins_count = msm_get_pins_count, |
| 120 | .get_pin_name = msm_get_pin_name, |
| 121 | .set_state = pinctrl_generic_set_state, |
| 122 | .pinmux_set = msm_pinmux_set, |
| 123 | .pinconf_num_params = ARRAY_SIZE(msm_conf_params), |
| 124 | .pinconf_params = msm_conf_params, |
| 125 | .pinconf_set = msm_pinconf_set, |
| 126 | .get_functions_count = msm_get_functions_count, |
| 127 | .get_function_name = msm_get_function_name, |
| 128 | }; |
| 129 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 130 | int msm_pinctrl_bind(struct udevice *dev) |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 131 | { |
| 132 | ofnode node = dev_ofnode(dev); |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 133 | struct msm_pinctrl_data *data = (struct msm_pinctrl_data *)dev_get_driver_data(dev); |
| 134 | struct driver *drv; |
| 135 | struct udevice *pinctrl_dev; |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 136 | const char *name; |
| 137 | int ret; |
| 138 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 139 | drv = lists_driver_lookup_name("pinctrl_qcom"); |
| 140 | if (!drv) |
| 141 | return -ENOENT; |
| 142 | |
| 143 | ret = device_bind_with_driver_data(dev_get_parent(dev), drv, ofnode_get_name(node), (ulong)data, |
| 144 | dev_ofnode(dev), &pinctrl_dev); |
| 145 | if (ret) |
| 146 | return ret; |
| 147 | |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 148 | ofnode_get_property(node, "gpio-controller", &ret); |
| 149 | if (ret < 0) |
| 150 | return 0; |
| 151 | |
| 152 | /* Get the name of gpio node */ |
| 153 | name = ofnode_get_name(node); |
| 154 | if (!name) |
| 155 | return -EINVAL; |
| 156 | |
Caleb Connolly | fabb897 | 2023-11-14 12:55:42 +0000 | [diff] [blame] | 157 | drv = lists_driver_lookup_name("gpio_msm"); |
| 158 | if (!drv) { |
| 159 | printf("Can't find gpio_msm driver\n"); |
| 160 | return -ENODEV; |
| 161 | } |
| 162 | |
| 163 | /* Bind gpio device as a child of the pinctrl device */ |
| 164 | ret = device_bind_with_driver_data(pinctrl_dev, drv, |
| 165 | name, (ulong)&data->pin_data, node, NULL); |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 166 | if (ret) { |
| 167 | device_unbind(pinctrl_dev); |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 168 | return ret; |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 169 | } |
Sumit Garg | b7572e5 | 2022-07-27 13:52:04 +0530 | [diff] [blame] | 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Caleb Connolly | 506eb53 | 2023-11-14 12:55:40 +0000 | [diff] [blame] | 174 | U_BOOT_DRIVER(pinctrl_qcom) = { |
| 175 | .name = "pinctrl_qcom", |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 176 | .id = UCLASS_PINCTRL, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 177 | .priv_auto = sizeof(struct msm_pinctrl_priv), |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 178 | .ops = &msm_pinctrl_ops, |
| 179 | .probe = msm_pinctrl_probe, |
Ramon Fried | e43d8e7 | 2018-05-16 12:13:40 +0300 | [diff] [blame] | 180 | }; |