.. | .. |
---|
27 | 27 | static const struct { |
---|
28 | 28 | const char *name; |
---|
29 | 29 | unsigned int mctrl; |
---|
30 | | - bool dir_out; |
---|
| 30 | + enum gpiod_flags flags; |
---|
31 | 31 | } 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, }, |
---|
38 | 38 | }; |
---|
| 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 | +} |
---|
39 | 44 | |
---|
40 | 45 | void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) |
---|
41 | 46 | { |
---|
42 | 47 | enum mctrl_gpio_idx i; |
---|
43 | 48 | struct gpio_desc *desc_array[UART_GPIO_MAX]; |
---|
44 | | - int value_array[UART_GPIO_MAX]; |
---|
| 49 | + DECLARE_BITMAP(values, UART_GPIO_MAX); |
---|
45 | 50 | unsigned int count = 0; |
---|
46 | 51 | |
---|
47 | 52 | if (gpios == NULL) |
---|
48 | 53 | return; |
---|
49 | 54 | |
---|
50 | 55 | 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)) { |
---|
52 | 57 | 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); |
---|
54 | 60 | count++; |
---|
55 | 61 | } |
---|
56 | | - gpiod_set_array_value(count, desc_array, value_array); |
---|
| 62 | + gpiod_set_array_value(count, desc_array, NULL, values); |
---|
57 | 63 | } |
---|
58 | 64 | EXPORT_SYMBOL_GPL(mctrl_gpio_set); |
---|
59 | 65 | |
---|
.. | .. |
---|
75 | 81 | return *mctrl; |
---|
76 | 82 | |
---|
77 | 83 | 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)) { |
---|
79 | 85 | if (gpiod_get_value(gpios->gpio[i])) |
---|
80 | 86 | *mctrl |= mctrl_gpios_desc[i].mctrl; |
---|
81 | 87 | else |
---|
.. | .. |
---|
96 | 102 | return *mctrl; |
---|
97 | 103 | |
---|
98 | 104 | 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)) { |
---|
100 | 106 | if (gpiod_get_value(gpios->gpio[i])) |
---|
101 | 107 | *mctrl |= mctrl_gpios_desc[i].mctrl; |
---|
102 | 108 | else |
---|
.. | .. |
---|
118 | 124 | return ERR_PTR(-ENOMEM); |
---|
119 | 125 | |
---|
120 | 126 | for (i = 0; i < UART_GPIO_MAX; i++) { |
---|
121 | | - enum gpiod_flags flags; |
---|
122 | 127 | char *gpio_str; |
---|
123 | 128 | bool present; |
---|
124 | 129 | |
---|
.. | .. |
---|
133 | 138 | if (!present) |
---|
134 | 139 | continue; |
---|
135 | 140 | |
---|
136 | | - if (mctrl_gpios_desc[i].dir_out) |
---|
137 | | - flags = GPIOD_OUT_LOW; |
---|
138 | | - else |
---|
139 | | - flags = GPIOD_IN; |
---|
140 | | - |
---|
141 | 141 | gpios->gpio[i] = |
---|
142 | 142 | devm_gpiod_get_index_optional(dev, |
---|
143 | 143 | mctrl_gpios_desc[i].name, |
---|
144 | | - idx, flags); |
---|
| 144 | + idx, |
---|
| 145 | + mctrl_gpios_desc[i].flags); |
---|
145 | 146 | |
---|
146 | 147 | if (IS_ERR(gpios->gpio[i])) |
---|
147 | 148 | return ERR_CAST(gpios->gpio[i]); |
---|
.. | .. |
---|
202 | 203 | for (i = 0; i < UART_GPIO_MAX; ++i) { |
---|
203 | 204 | int ret; |
---|
204 | 205 | |
---|
205 | | - if (!gpios->gpio[i] || mctrl_gpios_desc[i].dir_out) |
---|
| 206 | + if (!gpios->gpio[i] || mctrl_gpio_flags_is_dir_out(i)) |
---|
206 | 207 | continue; |
---|
207 | 208 | |
---|
208 | 209 | ret = gpiod_to_irq(gpios->gpio[i]); |
---|