1 From 7f4f2744f9788312e12940b516b51a0a466b137e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org>
3 Date: Mon, 1 Jul 2024 13:30:05 +0200
4 Subject: [PATCH 03/11] platform: cznic: turris-omnia-mcu: Add support for MCU
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Add support for GPIOs connected to the MCU on the Turris Omnia board.
14 - enable pins for USB regulators
15 - MiniPCIe / mSATA card presence pins in MiniPCIe port 0
16 - LED output pins from WAN ethernet PHY, LAN switch and MiniPCIe ports
17 - on board revisions 32+ also various peripheral resets and another
18 voltage regulator enable pin
20 Signed-off-by: Marek Behún <kabel@kernel.org>
21 Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
22 Link: https://lore.kernel.org/r/20240701113010.16447-4-kabel@kernel.org
23 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
25 .../sysfs-bus-i2c-devices-turris-omnia-mcu | 16 +
26 drivers/platform/cznic/Kconfig | 15 +
27 drivers/platform/cznic/Makefile | 1 +
28 .../platform/cznic/turris-omnia-mcu-base.c | 3 +-
29 .../platform/cznic/turris-omnia-mcu-gpio.c | 1094 +++++++++++++++++
30 drivers/platform/cznic/turris-omnia-mcu.h | 68 +
31 6 files changed, 1196 insertions(+), 1 deletion(-)
32 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-gpio.c
34 --- a/Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu
35 +++ b/Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu
36 @@ -22,6 +22,22 @@ Description: (RO) Contains device first
40 +What: /sys/bus/i2c/devices/<mcu_device>/front_button_mode
43 +Contact: Marek Behún <kabel@kernel.org>
44 +Description: (RW) The front button on the Turris Omnia router can be
45 + configured either to change the intensity of all the LEDs on the
46 + front panel, or to send the press event to the CPU as an
49 + This file switches between these two modes:
50 + - "mcu" makes the button press event be handled by the MCU to
51 + change the LEDs panel intensity.
52 + - "cpu" makes the button press event be handled by the CPU.
56 What: /sys/bus/i2c/devices/<mcu_device>/fw_features
59 --- a/drivers/platform/cznic/Kconfig
60 +++ b/drivers/platform/cznic/Kconfig
61 @@ -16,9 +16,24 @@ config TURRIS_OMNIA_MCU
62 tristate "Turris Omnia MCU driver"
63 depends on MACH_ARMADA_38X || COMPILE_TEST
66 + select GPIOLIB_IRQCHIP
68 Say Y here to add support for the features implemented by the
69 microcontroller on the CZ.NIC's Turris Omnia SOHO router.
70 + The features include:
72 + - to get front button press events (the front button can be
73 + configured either to generate press events to the CPU or to change
74 + front LEDs panel brightness)
75 + - to enable / disable USB port voltage regulators and to detect
77 + - to detect MiniPCIe / mSATA card presence in MiniPCIe port 0
78 + - to configure resets of various peripherals on board revisions 32+
79 + - to enable / disable the VHV voltage regulator to the SOC in order
80 + to be able to program SOC's OTP on board revisions 32+
81 + - to get input from the LED output pins of the WAN ethernet PHY, LAN
82 + switch and MiniPCIe ports
83 To compile this driver as a module, choose M here; the module will be
84 called turris-omnia-mcu.
86 --- a/drivers/platform/cznic/Makefile
87 +++ b/drivers/platform/cznic/Makefile
90 obj-$(CONFIG_TURRIS_OMNIA_MCU) += turris-omnia-mcu.o
91 turris-omnia-mcu-y := turris-omnia-mcu-base.o
92 +turris-omnia-mcu-y += turris-omnia-mcu-gpio.o
93 --- a/drivers/platform/cznic/turris-omnia-mcu-base.c
94 +++ b/drivers/platform/cznic/turris-omnia-mcu-base.c
95 @@ -196,6 +196,7 @@ static const struct attribute_group omni
97 static const struct attribute_group *omnia_mcu_groups[] = {
98 &omnia_mcu_base_group,
99 + &omnia_mcu_gpio_group,
103 @@ -370,7 +371,7 @@ static int omnia_mcu_probe(struct i2c_cl
104 "Cannot read board info\n");
108 + return omnia_mcu_register_gpiochip(mcu);
111 static const struct of_device_id of_omnia_mcu_match[] = {
113 +++ b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
115 +// SPDX-License-Identifier: GPL-2.0
117 + * CZ.NIC's Turris Omnia MCU GPIO and IRQ driver
119 + * 2024 by Marek Behún <kabel@kernel.org>
122 +#include <linux/bitfield.h>
123 +#include <linux/bitops.h>
124 +#include <linux/bug.h>
125 +#include <linux/cleanup.h>
126 +#include <linux/device.h>
127 +#include <linux/devm-helpers.h>
128 +#include <linux/errno.h>
129 +#include <linux/gpio/driver.h>
130 +#include <linux/i2c.h>
131 +#include <linux/interrupt.h>
132 +#include <linux/mutex.h>
133 +#include <linux/sysfs.h>
134 +#include <linux/types.h>
135 +#include <linux/workqueue.h>
136 +#include <asm/unaligned.h>
138 +#include <linux/turris-omnia-mcu-interface.h>
139 +#include "turris-omnia-mcu.h"
141 +#define OMNIA_CMD_INT_ARG_LEN 8
142 +#define FRONT_BUTTON_RELEASE_DELAY_MS 50
144 +static const char * const omnia_mcu_gpio_templates[64] = {
145 + /* GPIOs with value read from the 16-bit wide status */
146 + [4] = "MiniPCIe0 Card Detect",
147 + [5] = "MiniPCIe0 mSATA Indicator",
148 + [6] = "Front USB3 port over-current",
149 + [7] = "Rear USB3 port over-current",
150 + [8] = "Front USB3 port power",
151 + [9] = "Rear USB3 port power",
152 + [12] = "Front Button",
154 + /* GPIOs with value read from the 32-bit wide extended status */
156 + [28] = "MiniPCIe0 LED",
157 + [29] = "MiniPCIe1 LED",
158 + [30] = "MiniPCIe2 LED",
159 + [31] = "MiniPCIe0 PAN LED",
160 + [32] = "MiniPCIe1 PAN LED",
161 + [33] = "MiniPCIe2 PAN LED",
162 + [34] = "WAN PHY LED0",
163 + [35] = "WAN PHY LED1",
164 + [36] = "LAN switch p0 LED0",
165 + [37] = "LAN switch p0 LED1",
166 + [38] = "LAN switch p1 LED0",
167 + [39] = "LAN switch p1 LED1",
168 + [40] = "LAN switch p2 LED0",
169 + [41] = "LAN switch p2 LED1",
170 + [42] = "LAN switch p3 LED0",
171 + [43] = "LAN switch p3 LED1",
172 + [44] = "LAN switch p4 LED0",
173 + [45] = "LAN switch p4 LED1",
174 + [46] = "LAN switch p5 LED0",
175 + [47] = "LAN switch p5 LED1",
177 + /* GPIOs with value read from the 16-bit wide extended control status */
178 + [48] = "eMMC nRESET",
179 + [49] = "LAN switch nRESET",
180 + [50] = "WAN PHY nRESET",
181 + [51] = "MiniPCIe0 nPERST",
182 + [52] = "MiniPCIe1 nPERST",
183 + [53] = "MiniPCIe2 nPERST",
184 + [54] = "WAN PHY SFP mux",
185 + [56] = "VHV power disable",
198 +#define OMNIA_GPIO_INVALID_INT_BIT 0xff
200 +#define _DEF_GPIO(_cmd, _ctl_cmd, _bit, _ctl_bit, _int_bit, _feat, _feat_mask) \
203 + .ctl_cmd = _ctl_cmd, \
205 + .ctl_bit = _ctl_bit, \
206 + .int_bit = (_int_bit) < 0 ? OMNIA_GPIO_INVALID_INT_BIT \
209 + .feat_mask = _feat_mask, \
212 +#define _DEF_GPIO_STS(_name) \
213 + _DEF_GPIO(OMNIA_CMD_GET_STATUS_WORD, 0, __bf_shf(OMNIA_STS_ ## _name), \
214 + 0, __bf_shf(OMNIA_INT_ ## _name), 0, 0)
216 +#define _DEF_GPIO_CTL(_name) \
217 + _DEF_GPIO(OMNIA_CMD_GET_STATUS_WORD, OMNIA_CMD_GENERAL_CONTROL, \
218 + __bf_shf(OMNIA_STS_ ## _name), __bf_shf(OMNIA_CTL_ ## _name), \
221 +#define _DEF_GPIO_EXT_STS(_name, _feat) \
222 + _DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
223 + __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
224 + __bf_shf(OMNIA_INT_ ## _name), \
225 + OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS, \
226 + OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS)
228 +#define _DEF_GPIO_EXT_STS_LED(_name, _ledext) \
229 + _DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
230 + __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
231 + __bf_shf(OMNIA_INT_ ## _name), \
232 + OMNIA_FEAT_LED_STATE_ ## _ledext, \
233 + OMNIA_FEAT_LED_STATE_EXT_MASK)
235 +#define _DEF_GPIO_EXT_STS_LEDALL(_name) \
236 + _DEF_GPIO(OMNIA_CMD_GET_EXT_STATUS_DWORD, 0, \
237 + __bf_shf(OMNIA_EXT_STS_ ## _name), 0, \
238 + __bf_shf(OMNIA_INT_ ## _name), \
239 + OMNIA_FEAT_LED_STATE_EXT_MASK, 0)
241 +#define _DEF_GPIO_EXT_CTL(_name, _feat) \
242 + _DEF_GPIO(OMNIA_CMD_GET_EXT_CONTROL_STATUS, OMNIA_CMD_EXT_CONTROL, \
243 + __bf_shf(OMNIA_EXT_CTL_ ## _name), \
244 + __bf_shf(OMNIA_EXT_CTL_ ## _name), -1, \
245 + OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS, \
246 + OMNIA_FEAT_ ## _feat | OMNIA_FEAT_EXT_CMDS)
248 +#define _DEF_INT(_name) \
249 + _DEF_GPIO(0, 0, 0, 0, __bf_shf(OMNIA_INT_ ## _name), 0, 0)
251 +static inline bool is_int_bit_valid(const struct omnia_gpio *gpio)
253 + return gpio->int_bit != OMNIA_GPIO_INVALID_INT_BIT;
256 +static const struct omnia_gpio omnia_gpios[64] = {
257 + /* GPIOs with value read from the 16-bit wide status */
258 + [4] = _DEF_GPIO_STS(CARD_DET),
259 + [5] = _DEF_GPIO_STS(MSATA_IND),
260 + [6] = _DEF_GPIO_STS(USB30_OVC),
261 + [7] = _DEF_GPIO_STS(USB31_OVC),
262 + [8] = _DEF_GPIO_CTL(USB30_PWRON),
263 + [9] = _DEF_GPIO_CTL(USB31_PWRON),
265 + /* brightness changed interrupt, no GPIO */
266 + [11] = _DEF_INT(BRIGHTNESS_CHANGED),
268 + [12] = _DEF_GPIO_STS(BUTTON_PRESSED),
270 + /* TRNG interrupt, no GPIO */
271 + [13] = _DEF_INT(TRNG),
273 + /* MESSAGE_SIGNED interrupt, no GPIO */
274 + [14] = _DEF_INT(MESSAGE_SIGNED),
276 + /* GPIOs with value read from the 32-bit wide extended status */
277 + [16] = _DEF_GPIO_EXT_STS(SFP_nDET, PERIPH_MCU),
278 + [28] = _DEF_GPIO_EXT_STS_LEDALL(WLAN0_MSATA_LED),
279 + [29] = _DEF_GPIO_EXT_STS_LEDALL(WLAN1_LED),
280 + [30] = _DEF_GPIO_EXT_STS_LEDALL(WLAN2_LED),
281 + [31] = _DEF_GPIO_EXT_STS_LED(WPAN0_LED, EXT),
282 + [32] = _DEF_GPIO_EXT_STS_LED(WPAN1_LED, EXT),
283 + [33] = _DEF_GPIO_EXT_STS_LED(WPAN2_LED, EXT),
284 + [34] = _DEF_GPIO_EXT_STS_LEDALL(WAN_LED0),
285 + [35] = _DEF_GPIO_EXT_STS_LED(WAN_LED1, EXT_V32),
286 + [36] = _DEF_GPIO_EXT_STS_LEDALL(LAN0_LED0),
287 + [37] = _DEF_GPIO_EXT_STS_LEDALL(LAN0_LED1),
288 + [38] = _DEF_GPIO_EXT_STS_LEDALL(LAN1_LED0),
289 + [39] = _DEF_GPIO_EXT_STS_LEDALL(LAN1_LED1),
290 + [40] = _DEF_GPIO_EXT_STS_LEDALL(LAN2_LED0),
291 + [41] = _DEF_GPIO_EXT_STS_LEDALL(LAN2_LED1),
292 + [42] = _DEF_GPIO_EXT_STS_LEDALL(LAN3_LED0),
293 + [43] = _DEF_GPIO_EXT_STS_LEDALL(LAN3_LED1),
294 + [44] = _DEF_GPIO_EXT_STS_LEDALL(LAN4_LED0),
295 + [45] = _DEF_GPIO_EXT_STS_LEDALL(LAN4_LED1),
296 + [46] = _DEF_GPIO_EXT_STS_LEDALL(LAN5_LED0),
297 + [47] = _DEF_GPIO_EXT_STS_LEDALL(LAN5_LED1),
299 + /* GPIOs with value read from the 16-bit wide extended control status */
300 + [48] = _DEF_GPIO_EXT_CTL(nRES_MMC, PERIPH_MCU),
301 + [49] = _DEF_GPIO_EXT_CTL(nRES_LAN, PERIPH_MCU),
302 + [50] = _DEF_GPIO_EXT_CTL(nRES_PHY, PERIPH_MCU),
303 + [51] = _DEF_GPIO_EXT_CTL(nPERST0, PERIPH_MCU),
304 + [52] = _DEF_GPIO_EXT_CTL(nPERST1, PERIPH_MCU),
305 + [53] = _DEF_GPIO_EXT_CTL(nPERST2, PERIPH_MCU),
306 + [54] = _DEF_GPIO_EXT_CTL(PHY_SFP, PERIPH_MCU),
307 + [56] = _DEF_GPIO_EXT_CTL(nVHV_CTRL, PERIPH_MCU),
310 +/* mapping from interrupts to indexes of GPIOs in the omnia_gpios array */
311 +static const u8 omnia_int_to_gpio_idx[32] = {
312 + [__bf_shf(OMNIA_INT_CARD_DET)] = 4,
313 + [__bf_shf(OMNIA_INT_MSATA_IND)] = 5,
314 + [__bf_shf(OMNIA_INT_USB30_OVC)] = 6,
315 + [__bf_shf(OMNIA_INT_USB31_OVC)] = 7,
316 + [__bf_shf(OMNIA_INT_BUTTON_PRESSED)] = 12,
317 + [__bf_shf(OMNIA_INT_TRNG)] = 13,
318 + [__bf_shf(OMNIA_INT_MESSAGE_SIGNED)] = 14,
319 + [__bf_shf(OMNIA_INT_SFP_nDET)] = 16,
320 + [__bf_shf(OMNIA_INT_BRIGHTNESS_CHANGED)] = 11,
321 + [__bf_shf(OMNIA_INT_WLAN0_MSATA_LED)] = 28,
322 + [__bf_shf(OMNIA_INT_WLAN1_LED)] = 29,
323 + [__bf_shf(OMNIA_INT_WLAN2_LED)] = 30,
324 + [__bf_shf(OMNIA_INT_WPAN0_LED)] = 31,
325 + [__bf_shf(OMNIA_INT_WPAN1_LED)] = 32,
326 + [__bf_shf(OMNIA_INT_WPAN2_LED)] = 33,
327 + [__bf_shf(OMNIA_INT_WAN_LED0)] = 34,
328 + [__bf_shf(OMNIA_INT_WAN_LED1)] = 35,
329 + [__bf_shf(OMNIA_INT_LAN0_LED0)] = 36,
330 + [__bf_shf(OMNIA_INT_LAN0_LED1)] = 37,
331 + [__bf_shf(OMNIA_INT_LAN1_LED0)] = 38,
332 + [__bf_shf(OMNIA_INT_LAN1_LED1)] = 39,
333 + [__bf_shf(OMNIA_INT_LAN2_LED0)] = 40,
334 + [__bf_shf(OMNIA_INT_LAN2_LED1)] = 41,
335 + [__bf_shf(OMNIA_INT_LAN3_LED0)] = 42,
336 + [__bf_shf(OMNIA_INT_LAN3_LED1)] = 43,
337 + [__bf_shf(OMNIA_INT_LAN4_LED0)] = 44,
338 + [__bf_shf(OMNIA_INT_LAN4_LED1)] = 45,
339 + [__bf_shf(OMNIA_INT_LAN5_LED0)] = 46,
340 + [__bf_shf(OMNIA_INT_LAN5_LED1)] = 47,
343 +/* index of PHY_SFP GPIO in the omnia_gpios array */
344 +#define OMNIA_GPIO_PHY_SFP_OFFSET 54
346 +static int omnia_ctl_cmd_locked(struct omnia_mcu *mcu, u8 cmd, u16 val, u16 mask)
354 + case OMNIA_CMD_GENERAL_CONTROL:
360 + case OMNIA_CMD_EXT_CONTROL:
361 + put_unaligned_le16(val, &buf[1]);
362 + put_unaligned_le16(mask, &buf[3]);
370 + return omnia_cmd_write(mcu->client, buf, len);
373 +static int omnia_ctl_cmd(struct omnia_mcu *mcu, u8 cmd, u16 val, u16 mask)
375 + guard(mutex)(&mcu->lock);
377 + return omnia_ctl_cmd_locked(mcu, cmd, val, mask);
380 +static int omnia_gpio_request(struct gpio_chip *gc, unsigned int offset)
382 + if (!omnia_gpios[offset].cmd)
388 +static int omnia_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
390 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
392 + if (offset == OMNIA_GPIO_PHY_SFP_OFFSET) {
395 + scoped_guard(mutex, &mcu->lock) {
396 + val = omnia_cmd_read_bit(mcu->client,
397 + OMNIA_CMD_GET_EXT_CONTROL_STATUS,
398 + OMNIA_EXT_CTL_PHY_SFP_AUTO);
404 + return GPIO_LINE_DIRECTION_IN;
406 + return GPIO_LINE_DIRECTION_OUT;
409 + if (omnia_gpios[offset].ctl_cmd)
410 + return GPIO_LINE_DIRECTION_OUT;
412 + return GPIO_LINE_DIRECTION_IN;
415 +static int omnia_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
417 + const struct omnia_gpio *gpio = &omnia_gpios[offset];
418 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
420 + if (offset == OMNIA_GPIO_PHY_SFP_OFFSET)
421 + return omnia_ctl_cmd(mcu, OMNIA_CMD_EXT_CONTROL,
422 + OMNIA_EXT_CTL_PHY_SFP_AUTO,
423 + OMNIA_EXT_CTL_PHY_SFP_AUTO);
431 +static int omnia_gpio_direction_output(struct gpio_chip *gc,
432 + unsigned int offset, int value)
434 + const struct omnia_gpio *gpio = &omnia_gpios[offset];
435 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
438 + if (!gpio->ctl_cmd)
441 + mask = BIT(gpio->ctl_bit);
442 + val = value ? mask : 0;
444 + if (offset == OMNIA_GPIO_PHY_SFP_OFFSET)
445 + mask |= OMNIA_EXT_CTL_PHY_SFP_AUTO;
447 + return omnia_ctl_cmd(mcu, gpio->ctl_cmd, val, mask);
450 +static int omnia_gpio_get(struct gpio_chip *gc, unsigned int offset)
452 + const struct omnia_gpio *gpio = &omnia_gpios[offset];
453 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
456 + * If firmware does not support the new interrupt API, we are informed
457 + * of every change of the status word by an interrupt from MCU and save
458 + * its value in the interrupt service routine. Simply return the saved
461 + if (gpio->cmd == OMNIA_CMD_GET_STATUS_WORD &&
462 + !(mcu->features & OMNIA_FEAT_NEW_INT_API))
463 + return test_bit(gpio->bit, &mcu->last_status);
465 + guard(mutex)(&mcu->lock);
468 + * If firmware does support the new interrupt API, we may have cached
469 + * the value of a GPIO in the interrupt service routine. If not, read
470 + * the relevant bit now.
472 + if (is_int_bit_valid(gpio) && test_bit(gpio->int_bit, &mcu->is_cached))
473 + return test_bit(gpio->int_bit, &mcu->cached);
475 + return omnia_cmd_read_bit(mcu->client, gpio->cmd, BIT(gpio->bit));
478 +static unsigned long *
479 +_relevant_field_for_sts_cmd(u8 cmd, unsigned long *sts, unsigned long *ext_sts,
480 + unsigned long *ext_ctl)
483 + case OMNIA_CMD_GET_STATUS_WORD:
485 + case OMNIA_CMD_GET_EXT_STATUS_DWORD:
487 + case OMNIA_CMD_GET_EXT_CONTROL_STATUS:
494 +static int omnia_gpio_get_multiple(struct gpio_chip *gc, unsigned long *mask,
495 + unsigned long *bits)
497 + unsigned long sts = 0, ext_sts = 0, ext_ctl = 0, *field;
498 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
499 + struct i2c_client *client = mcu->client;
503 + /* determine which bits to read from the 3 possible commands */
504 + for_each_set_bit(i, mask, ARRAY_SIZE(omnia_gpios)) {
505 + field = _relevant_field_for_sts_cmd(omnia_gpios[i].cmd,
506 + &sts, &ext_sts, &ext_ctl);
510 + __set_bit(omnia_gpios[i].bit, field);
513 + guard(mutex)(&mcu->lock);
515 + if (mcu->features & OMNIA_FEAT_NEW_INT_API) {
516 + /* read relevant bits from status */
517 + err = omnia_cmd_read_bits(client, OMNIA_CMD_GET_STATUS_WORD,
523 + * Use status word value cached in the interrupt service routine
524 + * if firmware does not support the new interrupt API.
526 + sts = mcu->last_status;
529 + /* read relevant bits from extended status */
530 + err = omnia_cmd_read_bits(client, OMNIA_CMD_GET_EXT_STATUS_DWORD,
531 + ext_sts, &ext_sts);
535 + /* read relevant bits from extended control */
536 + err = omnia_cmd_read_bits(client, OMNIA_CMD_GET_EXT_CONTROL_STATUS,
537 + ext_ctl, &ext_ctl);
541 + /* assign relevant bits in result */
542 + for_each_set_bit(i, mask, ARRAY_SIZE(omnia_gpios)) {
543 + field = _relevant_field_for_sts_cmd(omnia_gpios[i].cmd,
544 + &sts, &ext_sts, &ext_ctl);
548 + __assign_bit(i, bits, test_bit(omnia_gpios[i].bit, field));
554 +static void omnia_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
556 + const struct omnia_gpio *gpio = &omnia_gpios[offset];
557 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
560 + if (!gpio->ctl_cmd)
563 + mask = BIT(gpio->ctl_bit);
564 + val = value ? mask : 0;
566 + omnia_ctl_cmd(mcu, gpio->ctl_cmd, val, mask);
569 +static void omnia_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
570 + unsigned long *bits)
572 + unsigned long ctl = 0, ctl_mask = 0, ext_ctl = 0, ext_ctl_mask = 0;
573 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
576 + for_each_set_bit(i, mask, ARRAY_SIZE(omnia_gpios)) {
577 + unsigned long *field, *field_mask;
578 + u8 bit = omnia_gpios[i].ctl_bit;
580 + switch (omnia_gpios[i].ctl_cmd) {
581 + case OMNIA_CMD_GENERAL_CONTROL:
583 + field_mask = &ctl_mask;
585 + case OMNIA_CMD_EXT_CONTROL:
587 + field_mask = &ext_ctl_mask;
590 + field = field_mask = NULL;
597 + __set_bit(bit, field_mask);
598 + __assign_bit(bit, field, test_bit(i, bits));
601 + guard(mutex)(&mcu->lock);
604 + omnia_ctl_cmd_locked(mcu, OMNIA_CMD_GENERAL_CONTROL,
608 + omnia_ctl_cmd_locked(mcu, OMNIA_CMD_EXT_CONTROL,
609 + ext_ctl, ext_ctl_mask);
612 +static bool omnia_gpio_available(struct omnia_mcu *mcu,
613 + const struct omnia_gpio *gpio)
615 + if (gpio->feat_mask)
616 + return (mcu->features & gpio->feat_mask) == gpio->feat;
619 + return mcu->features & gpio->feat;
624 +static int omnia_gpio_init_valid_mask(struct gpio_chip *gc,
625 + unsigned long *valid_mask,
626 + unsigned int ngpios)
628 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
630 + for (unsigned int i = 0; i < ngpios; i++) {
631 + const struct omnia_gpio *gpio = &omnia_gpios[i];
633 + if (gpio->cmd || is_int_bit_valid(gpio))
634 + __assign_bit(i, valid_mask,
635 + omnia_gpio_available(mcu, gpio));
637 + __clear_bit(i, valid_mask);
643 +static int omnia_gpio_of_xlate(struct gpio_chip *gc,
644 + const struct of_phandle_args *gpiospec,
649 + if (WARN_ON(gpiospec->args_count != 3))
653 + *flags = gpiospec->args[2];
655 + bank = gpiospec->args[0];
656 + gpio = gpiospec->args[1];
660 + return gpio < 16 ? gpio : -EINVAL;
662 + return gpio < 32 ? 16 + gpio : -EINVAL;
664 + return gpio < 16 ? 48 + gpio : -EINVAL;
670 +static void omnia_irq_shutdown(struct irq_data *d)
672 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
673 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
674 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
675 + u8 bit = omnia_gpios[hwirq].int_bit;
677 + __clear_bit(bit, &mcu->rising);
678 + __clear_bit(bit, &mcu->falling);
681 +static void omnia_irq_mask(struct irq_data *d)
683 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
684 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
685 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
686 + u8 bit = omnia_gpios[hwirq].int_bit;
688 + if (!omnia_gpios[hwirq].cmd)
689 + __clear_bit(bit, &mcu->rising);
690 + __clear_bit(bit, &mcu->mask);
691 + gpiochip_disable_irq(gc, hwirq);
694 +static void omnia_irq_unmask(struct irq_data *d)
696 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
697 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
698 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
699 + u8 bit = omnia_gpios[hwirq].int_bit;
701 + gpiochip_enable_irq(gc, hwirq);
702 + __set_bit(bit, &mcu->mask);
703 + if (!omnia_gpios[hwirq].cmd)
704 + __set_bit(bit, &mcu->rising);
707 +static int omnia_irq_set_type(struct irq_data *d, unsigned int type)
709 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
710 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
711 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
712 + struct device *dev = &mcu->client->dev;
713 + u8 bit = omnia_gpios[hwirq].int_bit;
715 + if (!(type & IRQ_TYPE_EDGE_BOTH)) {
716 + dev_err(dev, "irq %u: unsupported type %u\n", d->irq, type);
720 + __assign_bit(bit, &mcu->rising, type & IRQ_TYPE_EDGE_RISING);
721 + __assign_bit(bit, &mcu->falling, type & IRQ_TYPE_EDGE_FALLING);
726 +static void omnia_irq_bus_lock(struct irq_data *d)
728 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
729 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
731 + /* nothing to do if MCU firmware does not support new interrupt API */
732 + if (!(mcu->features & OMNIA_FEAT_NEW_INT_API))
735 + mutex_lock(&mcu->lock);
739 + * omnia_mask_interleave - Interleaves the bytes from @rising and @falling
740 + * @dst: the destination u8 array of interleaved bytes
741 + * @rising: rising mask
742 + * @falling: falling mask
744 + * Interleaves the little-endian bytes from @rising and @falling words.
746 + * If @rising = (r0, r1, r2, r3) and @falling = (f0, f1, f2, f3), the result is
747 + * @dst = (r0, f0, r1, f1, r2, f2, r3, f3).
749 + * The MCU receives an interrupt mask and reports a pending interrupt bitmap in
750 + * this interleaved format. The rationale behind this is that the low-indexed
751 + * bits are more important - in many cases, the user will be interested only in
752 + * interrupts with indexes 0 to 7, and so the system can stop reading after
753 + * first 2 bytes (r0, f0), to save time on the slow I2C bus.
755 + * Feel free to remove this function and its inverse, omnia_mask_deinterleave,
756 + * and use an appropriate bitmap_*() function once such a function exists.
759 +omnia_mask_interleave(u8 *dst, unsigned long rising, unsigned long falling)
761 + for (unsigned int i = 0; i < sizeof(u32); i++) {
762 + dst[2 * i] = rising >> (8 * i);
763 + dst[2 * i + 1] = falling >> (8 * i);
768 + * omnia_mask_deinterleave - Deinterleaves the bytes into @rising and @falling
769 + * @src: the source u8 array containing the interleaved bytes
770 + * @rising: pointer where to store the rising mask gathered from @src
771 + * @falling: pointer where to store the falling mask gathered from @src
773 + * This is the inverse function to omnia_mask_interleave.
775 +static void omnia_mask_deinterleave(const u8 *src, unsigned long *rising,
776 + unsigned long *falling)
778 + *rising = *falling = 0;
780 + for (unsigned int i = 0; i < sizeof(u32); i++) {
781 + *rising |= src[2 * i] << (8 * i);
782 + *falling |= src[2 * i + 1] << (8 * i);
786 +static void omnia_irq_bus_sync_unlock(struct irq_data *d)
788 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
789 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
790 + struct device *dev = &mcu->client->dev;
791 + u8 cmd[1 + OMNIA_CMD_INT_ARG_LEN];
792 + unsigned long rising, falling;
795 + /* nothing to do if MCU firmware does not support new interrupt API */
796 + if (!(mcu->features & OMNIA_FEAT_NEW_INT_API))
799 + cmd[0] = OMNIA_CMD_SET_INT_MASK;
801 + rising = mcu->rising & mcu->mask;
802 + falling = mcu->falling & mcu->mask;
804 + /* interleave the rising and falling bytes into the command arguments */
805 + omnia_mask_interleave(&cmd[1], rising, falling);
807 + dev_dbg(dev, "set int mask %8ph\n", &cmd[1]);
809 + err = omnia_cmd_write(mcu->client, cmd, sizeof(cmd));
811 + dev_err(dev, "Cannot set mask: %d\n", err);
816 + * Remember which GPIOs have both rising and falling interrupts enabled.
817 + * For those we will cache their value so that .get() method is faster.
818 + * We also need to forget cached values of GPIOs that aren't cached
821 + mcu->both = rising & falling;
822 + mcu->is_cached &= mcu->both;
825 + mutex_unlock(&mcu->lock);
828 +static const struct irq_chip omnia_mcu_irq_chip = {
829 + .name = "Turris Omnia MCU interrupts",
830 + .irq_shutdown = omnia_irq_shutdown,
831 + .irq_mask = omnia_irq_mask,
832 + .irq_unmask = omnia_irq_unmask,
833 + .irq_set_type = omnia_irq_set_type,
834 + .irq_bus_lock = omnia_irq_bus_lock,
835 + .irq_bus_sync_unlock = omnia_irq_bus_sync_unlock,
836 + .flags = IRQCHIP_IMMUTABLE,
837 + GPIOCHIP_IRQ_RESOURCE_HELPERS,
840 +static void omnia_irq_init_valid_mask(struct gpio_chip *gc,
841 + unsigned long *valid_mask,
842 + unsigned int ngpios)
844 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
846 + for (unsigned int i = 0; i < ngpios; i++) {
847 + const struct omnia_gpio *gpio = &omnia_gpios[i];
849 + if (is_int_bit_valid(gpio))
850 + __assign_bit(i, valid_mask,
851 + omnia_gpio_available(mcu, gpio));
853 + __clear_bit(i, valid_mask);
857 +static int omnia_irq_init_hw(struct gpio_chip *gc)
859 + struct omnia_mcu *mcu = gpiochip_get_data(gc);
860 + u8 cmd[1 + OMNIA_CMD_INT_ARG_LEN] = {};
862 + cmd[0] = OMNIA_CMD_SET_INT_MASK;
864 + return omnia_cmd_write(mcu->client, cmd, sizeof(cmd));
868 + * Determine how many bytes we need to read from the reply to the
869 + * OMNIA_CMD_GET_INT_AND_CLEAR command in order to retrieve all unmasked
873 +omnia_irq_compute_pending_length(unsigned long rising, unsigned long falling)
875 + return max(omnia_compute_reply_length(rising, true, 0),
876 + omnia_compute_reply_length(falling, true, 1));
879 +static bool omnia_irq_read_pending_new(struct omnia_mcu *mcu,
880 + unsigned long *pending)
882 + struct device *dev = &mcu->client->dev;
883 + u8 reply[OMNIA_CMD_INT_ARG_LEN] = {};
884 + unsigned long rising, falling;
888 + len = omnia_irq_compute_pending_length(mcu->rising & mcu->mask,
889 + mcu->falling & mcu->mask);
893 + guard(mutex)(&mcu->lock);
895 + err = omnia_cmd_read(mcu->client, OMNIA_CMD_GET_INT_AND_CLEAR, reply,
898 + dev_err(dev, "Cannot read pending IRQs: %d\n", err);
902 + /* deinterleave the reply bytes into rising and falling */
903 + omnia_mask_deinterleave(reply, &rising, &falling);
905 + rising &= mcu->mask;
906 + falling &= mcu->mask;
907 + *pending = rising | falling;
909 + /* cache values for GPIOs that have both edges enabled */
910 + mcu->is_cached &= ~(rising & falling);
911 + mcu->is_cached |= mcu->both & (rising ^ falling);
912 + mcu->cached = (mcu->cached | rising) & ~falling;
917 +static int omnia_read_status_word_old_fw(struct omnia_mcu *mcu,
918 + unsigned long *status)
923 + err = omnia_cmd_read_u16(mcu->client, OMNIA_CMD_GET_STATUS_WORD,
929 + * Old firmware has a bug wherein it never resets the USB port
930 + * overcurrent bits back to zero. Ignore them.
932 + *status = raw_status & ~(OMNIA_STS_USB30_OVC | OMNIA_STS_USB31_OVC);
937 +static void button_release_emul_fn(struct work_struct *work)
939 + struct omnia_mcu *mcu = container_of(to_delayed_work(work),
941 + button_release_emul_work);
943 + mcu->button_pressed_emul = false;
944 + generic_handle_irq_safe(mcu->client->irq);
948 +fill_int_from_sts(unsigned long *rising, unsigned long *falling,
949 + unsigned long rising_sts, unsigned long falling_sts,
950 + unsigned long sts_bit, unsigned long int_bit)
952 + if (rising_sts & sts_bit)
953 + *rising |= int_bit;
954 + if (falling_sts & sts_bit)
955 + *falling |= int_bit;
958 +static bool omnia_irq_read_pending_old(struct omnia_mcu *mcu,
959 + unsigned long *pending)
961 + unsigned long status, rising_sts, falling_sts, rising, falling;
962 + struct device *dev = &mcu->client->dev;
965 + guard(mutex)(&mcu->lock);
967 + err = omnia_read_status_word_old_fw(mcu, &status);
969 + dev_err(dev, "Cannot read pending IRQs: %d\n", err);
974 + * The old firmware triggers an interrupt whenever status word changes,
975 + * but does not inform about which bits rose or fell. We need to compute
976 + * this here by comparing with the last status word value.
978 + * The OMNIA_STS_BUTTON_PRESSED bit needs special handling, because the
979 + * old firmware clears the OMNIA_STS_BUTTON_PRESSED bit on successful
980 + * completion of the OMNIA_CMD_GET_STATUS_WORD command, resulting in
981 + * another interrupt:
982 + * - first we get an interrupt, we read the status word where
983 + * OMNIA_STS_BUTTON_PRESSED is present,
984 + * - MCU clears the OMNIA_STS_BUTTON_PRESSED bit because we read the
986 + * - we get another interrupt because the status word changed again
987 + * (the OMNIA_STS_BUTTON_PRESSED bit was cleared).
989 + * The gpiolib-cdev, gpiolib-sysfs and gpio-keys input driver all call
990 + * the gpiochip's .get() method after an edge event on a requested GPIO
993 + * We ensure that the .get() method reads 1 for the button GPIO for some
997 + if (status & OMNIA_STS_BUTTON_PRESSED) {
998 + mcu->button_pressed_emul = true;
999 + mod_delayed_work(system_wq, &mcu->button_release_emul_work,
1000 + msecs_to_jiffies(FRONT_BUTTON_RELEASE_DELAY_MS));
1001 + } else if (mcu->button_pressed_emul) {
1002 + status |= OMNIA_STS_BUTTON_PRESSED;
1005 + rising_sts = ~mcu->last_status & status;
1006 + falling_sts = mcu->last_status & ~status;
1008 + mcu->last_status = status;
1011 + * Fill in the relevant interrupt bits from status bits for CARD_DET,
1012 + * MSATA_IND and BUTTON_PRESSED.
1016 + fill_int_from_sts(&rising, &falling, rising_sts, falling_sts,
1017 + OMNIA_STS_CARD_DET, OMNIA_INT_CARD_DET);
1018 + fill_int_from_sts(&rising, &falling, rising_sts, falling_sts,
1019 + OMNIA_STS_MSATA_IND, OMNIA_INT_MSATA_IND);
1020 + fill_int_from_sts(&rising, &falling, rising_sts, falling_sts,
1021 + OMNIA_STS_BUTTON_PRESSED, OMNIA_INT_BUTTON_PRESSED);
1023 + /* Use only bits that are enabled */
1024 + rising &= mcu->rising & mcu->mask;
1025 + falling &= mcu->falling & mcu->mask;
1026 + *pending = rising | falling;
1031 +static bool omnia_irq_read_pending(struct omnia_mcu *mcu,
1032 + unsigned long *pending)
1034 + if (mcu->features & OMNIA_FEAT_NEW_INT_API)
1035 + return omnia_irq_read_pending_new(mcu, pending);
1037 + return omnia_irq_read_pending_old(mcu, pending);
1040 +static irqreturn_t omnia_irq_thread_handler(int irq, void *dev_id)
1042 + struct omnia_mcu *mcu = dev_id;
1043 + struct irq_domain *domain;
1044 + unsigned long pending;
1047 + if (!omnia_irq_read_pending(mcu, &pending))
1050 + domain = mcu->gc.irq.domain;
1052 + for_each_set_bit(i, &pending, 32) {
1053 + unsigned int nested_irq;
1055 + nested_irq = irq_find_mapping(domain, omnia_int_to_gpio_idx[i]);
1057 + handle_nested_irq(nested_irq);
1060 + return IRQ_RETVAL(pending);
1063 +static const char * const front_button_modes[] = { "mcu", "cpu" };
1065 +static ssize_t front_button_mode_show(struct device *dev,
1066 + struct device_attribute *a, char *buf)
1068 + struct omnia_mcu *mcu = dev_get_drvdata(dev);
1071 + if (mcu->features & OMNIA_FEAT_NEW_INT_API) {
1072 + val = omnia_cmd_read_bit(mcu->client, OMNIA_CMD_GET_STATUS_WORD,
1073 + OMNIA_STS_BUTTON_MODE);
1077 + val = !!(mcu->last_status & OMNIA_STS_BUTTON_MODE);
1080 + return sysfs_emit(buf, "%s\n", front_button_modes[val]);
1083 +static ssize_t front_button_mode_store(struct device *dev,
1084 + struct device_attribute *a,
1085 + const char *buf, size_t count)
1087 + struct omnia_mcu *mcu = dev_get_drvdata(dev);
1090 + i = sysfs_match_string(front_button_modes, buf);
1094 + err = omnia_ctl_cmd_locked(mcu, OMNIA_CMD_GENERAL_CONTROL,
1095 + i ? OMNIA_CTL_BUTTON_MODE : 0,
1096 + OMNIA_CTL_BUTTON_MODE);
1102 +static DEVICE_ATTR_RW(front_button_mode);
1104 +static struct attribute *omnia_mcu_gpio_attrs[] = {
1105 + &dev_attr_front_button_mode.attr,
1109 +const struct attribute_group omnia_mcu_gpio_group = {
1110 + .attrs = omnia_mcu_gpio_attrs,
1113 +int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)
1115 + bool new_api = mcu->features & OMNIA_FEAT_NEW_INT_API;
1116 + struct device *dev = &mcu->client->dev;
1117 + unsigned long irqflags;
1120 + err = devm_mutex_init(dev, &mcu->lock);
1124 + mcu->gc.request = omnia_gpio_request;
1125 + mcu->gc.get_direction = omnia_gpio_get_direction;
1126 + mcu->gc.direction_input = omnia_gpio_direction_input;
1127 + mcu->gc.direction_output = omnia_gpio_direction_output;
1128 + mcu->gc.get = omnia_gpio_get;
1129 + mcu->gc.get_multiple = omnia_gpio_get_multiple;
1130 + mcu->gc.set = omnia_gpio_set;
1131 + mcu->gc.set_multiple = omnia_gpio_set_multiple;
1132 + mcu->gc.init_valid_mask = omnia_gpio_init_valid_mask;
1133 + mcu->gc.can_sleep = true;
1134 + mcu->gc.names = omnia_mcu_gpio_templates;
1135 + mcu->gc.base = -1;
1136 + mcu->gc.ngpio = ARRAY_SIZE(omnia_gpios);
1137 + mcu->gc.label = "Turris Omnia MCU GPIOs";
1138 + mcu->gc.parent = dev;
1139 + mcu->gc.owner = THIS_MODULE;
1140 + mcu->gc.of_gpio_n_cells = 3;
1141 + mcu->gc.of_xlate = omnia_gpio_of_xlate;
1143 + gpio_irq_chip_set_chip(&mcu->gc.irq, &omnia_mcu_irq_chip);
1144 + /* This will let us handle the parent IRQ in the driver */
1145 + mcu->gc.irq.parent_handler = NULL;
1146 + mcu->gc.irq.num_parents = 0;
1147 + mcu->gc.irq.parents = NULL;
1148 + mcu->gc.irq.default_type = IRQ_TYPE_NONE;
1149 + mcu->gc.irq.handler = handle_bad_irq;
1150 + mcu->gc.irq.threaded = true;
1152 + mcu->gc.irq.init_hw = omnia_irq_init_hw;
1153 + mcu->gc.irq.init_valid_mask = omnia_irq_init_valid_mask;
1155 + err = devm_gpiochip_add_data(dev, &mcu->gc, mcu);
1157 + return dev_err_probe(dev, err, "Cannot add GPIO chip\n");
1160 + * Before requesting the interrupt, if firmware does not support the new
1161 + * interrupt API, we need to cache the value of the status word, so that
1162 + * when it changes, we may compare the new value with the cached one in
1163 + * the interrupt handler.
1166 + err = omnia_read_status_word_old_fw(mcu, &mcu->last_status);
1168 + return dev_err_probe(dev, err,
1169 + "Cannot read status word\n");
1171 + INIT_DELAYED_WORK(&mcu->button_release_emul_work,
1172 + button_release_emul_fn);
1175 + irqflags = IRQF_ONESHOT;
1177 + irqflags |= IRQF_TRIGGER_LOW;
1179 + irqflags |= IRQF_TRIGGER_FALLING;
1181 + err = devm_request_threaded_irq(dev, mcu->client->irq, NULL,
1182 + omnia_irq_thread_handler, irqflags,
1183 + "turris-omnia-mcu", mcu);
1185 + return dev_err_probe(dev, err, "Cannot request IRQ\n");
1189 + * The button_release_emul_work has to be initialized before the
1190 + * thread is requested, and on driver remove it needs to be
1191 + * canceled before the thread is freed. Therefore we can't use
1192 + * devm_delayed_work_autocancel() directly, because the order
1193 + * devm_delayed_work_autocancel();
1194 + * devm_request_threaded_irq();
1195 + * would cause improper release order:
1197 + * cancel_delayed_work_sync();
1198 + * Instead we first initialize the work above, and only now
1199 + * after IRQ is requested we add the work devm action.
1201 + err = devm_add_action(dev, devm_delayed_work_drop,
1202 + &mcu->button_release_emul_work);
1209 --- a/drivers/platform/cznic/turris-omnia-mcu.h
1210 +++ b/drivers/platform/cznic/turris-omnia-mcu.h
1212 #ifndef __TURRIS_OMNIA_MCU_H
1213 #define __TURRIS_OMNIA_MCU_H
1215 +#include <linux/bitops.h>
1216 +#include <linux/gpio/driver.h>
1217 #include <linux/if_ether.h>
1218 +#include <linux/mutex.h>
1219 #include <linux/types.h>
1220 +#include <linux/workqueue.h>
1221 #include <asm/byteorder.h>
1224 @@ -23,18 +27,78 @@ struct omnia_mcu {
1225 u64 board_serial_number;
1226 u8 board_first_mac[ETH_ALEN];
1230 + struct gpio_chip gc;
1231 + struct mutex lock;
1232 + unsigned long mask, rising, falling, both, cached, is_cached;
1233 + /* Old MCU firmware handling needs the following */
1234 + struct delayed_work button_release_emul_work;
1235 + unsigned long last_status;
1236 + bool button_pressed_emul;
1239 int omnia_cmd_write_read(const struct i2c_client *client,
1240 void *cmd, unsigned int cmd_len,
1241 void *reply, unsigned int reply_len);
1243 +static inline int omnia_cmd_write(const struct i2c_client *client, void *cmd,
1246 + return omnia_cmd_write_read(client, cmd, len, NULL, 0);
1249 static inline int omnia_cmd_read(const struct i2c_client *client, u8 cmd,
1250 void *reply, unsigned int len)
1252 return omnia_cmd_write_read(client, &cmd, 1, reply, len);
1255 +static inline unsigned int
1256 +omnia_compute_reply_length(unsigned long mask, bool interleaved,
1257 + unsigned int offset)
1262 + return ((__fls(mask) >> 3) << interleaved) + 1 + offset;
1265 +/* Returns 0 on success */
1266 +static inline int omnia_cmd_read_bits(const struct i2c_client *client, u8 cmd,
1267 + unsigned long bits, unsigned long *dst)
1277 + err = omnia_cmd_read(client, cmd, &reply,
1278 + omnia_compute_reply_length(bits, false, 0));
1282 + *dst = le32_to_cpu(reply) & bits;
1287 +static inline int omnia_cmd_read_bit(const struct i2c_client *client, u8 cmd,
1288 + unsigned long bit)
1290 + unsigned long reply;
1293 + err = omnia_cmd_read_bits(client, cmd, bit, &reply);
1300 static inline int omnia_cmd_read_u32(const struct i2c_client *client, u8 cmd,
1303 @@ -71,4 +135,8 @@ static inline int omnia_cmd_read_u8(cons
1304 return omnia_cmd_read(client, cmd, reply, sizeof(*reply));
1307 +extern const struct attribute_group omnia_mcu_gpio_group;
1309 +int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu);
1311 #endif /* __TURRIS_OMNIA_MCU_H */