hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/tty/serial/serial_mctrl_gpio.c
....@@ -27,33 +27,39 @@
2727 static const struct {
2828 const char *name;
2929 unsigned int mctrl;
30
- bool dir_out;
30
+ enum gpiod_flags flags;
3131 } mctrl_gpios_desc[UART_GPIO_MAX] = {
32
- { "cts", TIOCM_CTS, false, },
33
- { "dsr", TIOCM_DSR, false, },
34
- { "dcd", TIOCM_CD, false, },
35
- { "rng", TIOCM_RNG, false, },
36
- { "rts", TIOCM_RTS, true, },
37
- { "dtr", TIOCM_DTR, true, },
32
+ { "cts", TIOCM_CTS, GPIOD_IN, },
33
+ { "dsr", TIOCM_DSR, GPIOD_IN, },
34
+ { "dcd", TIOCM_CD, GPIOD_IN, },
35
+ { "rng", TIOCM_RNG, GPIOD_IN, },
36
+ { "rts", TIOCM_RTS, GPIOD_OUT_LOW, },
37
+ { "dtr", TIOCM_DTR, GPIOD_OUT_LOW, },
3838 };
39
+
40
+static bool mctrl_gpio_flags_is_dir_out(unsigned int idx)
41
+{
42
+ return mctrl_gpios_desc[idx].flags & GPIOD_FLAGS_BIT_DIR_OUT;
43
+}
3944
4045 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
4146 {
4247 enum mctrl_gpio_idx i;
4348 struct gpio_desc *desc_array[UART_GPIO_MAX];
44
- int value_array[UART_GPIO_MAX];
49
+ DECLARE_BITMAP(values, UART_GPIO_MAX);
4550 unsigned int count = 0;
4651
4752 if (gpios == NULL)
4853 return;
4954
5055 for (i = 0; i < UART_GPIO_MAX; i++)
51
- if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) {
56
+ if (gpios->gpio[i] && mctrl_gpio_flags_is_dir_out(i)) {
5257 desc_array[count] = gpios->gpio[i];
53
- value_array[count] = !!(mctrl & mctrl_gpios_desc[i].mctrl);
58
+ __assign_bit(count, values,
59
+ mctrl & mctrl_gpios_desc[i].mctrl);
5460 count++;
5561 }
56
- gpiod_set_array_value(count, desc_array, value_array);
62
+ gpiod_set_array_value(count, desc_array, NULL, values);
5763 }
5864 EXPORT_SYMBOL_GPL(mctrl_gpio_set);
5965
....@@ -75,7 +81,7 @@
7581 return *mctrl;
7682
7783 for (i = 0; i < UART_GPIO_MAX; i++) {
78
- if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) {
84
+ if (gpios->gpio[i] && !mctrl_gpio_flags_is_dir_out(i)) {
7985 if (gpiod_get_value(gpios->gpio[i]))
8086 *mctrl |= mctrl_gpios_desc[i].mctrl;
8187 else
....@@ -96,7 +102,7 @@
96102 return *mctrl;
97103
98104 for (i = 0; i < UART_GPIO_MAX; i++) {
99
- if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) {
105
+ if (gpios->gpio[i] && mctrl_gpio_flags_is_dir_out(i)) {
100106 if (gpiod_get_value(gpios->gpio[i]))
101107 *mctrl |= mctrl_gpios_desc[i].mctrl;
102108 else
....@@ -118,7 +124,6 @@
118124 return ERR_PTR(-ENOMEM);
119125
120126 for (i = 0; i < UART_GPIO_MAX; i++) {
121
- enum gpiod_flags flags;
122127 char *gpio_str;
123128 bool present;
124129
....@@ -133,15 +138,11 @@
133138 if (!present)
134139 continue;
135140
136
- if (mctrl_gpios_desc[i].dir_out)
137
- flags = GPIOD_OUT_LOW;
138
- else
139
- flags = GPIOD_IN;
140
-
141141 gpios->gpio[i] =
142142 devm_gpiod_get_index_optional(dev,
143143 mctrl_gpios_desc[i].name,
144
- idx, flags);
144
+ idx,
145
+ mctrl_gpios_desc[i].flags);
145146
146147 if (IS_ERR(gpios->gpio[i]))
147148 return ERR_CAST(gpios->gpio[i]);
....@@ -202,7 +203,7 @@
202203 for (i = 0; i < UART_GPIO_MAX; ++i) {
203204 int ret;
204205
205
- if (!gpios->gpio[i] || mctrl_gpios_desc[i].dir_out)
206
+ if (!gpios->gpio[i] || mctrl_gpio_flags_is_dir_out(i))
206207 continue;
207208
208209 ret = gpiod_to_irq(gpios->gpio[i]);