// SPDX-License-Identifier: GPL-2.0 /* * GPIO latch driver * * Copyright (C) 2022 Sascha Hauer <[email protected]> * * This driver implements a GPIO (or better GPO as there is no input) * multiplexer based on latches like this: * * CLK0 ----------------------. ,--------. * CLK1 -------------------. `--------|> #0 | * | | | * OUT0 ----------------+--|-----------|D0 Q0|-----|< * OUT1 --------------+-|--|-----------|D1 Q1|-----|< * OUT2 ------------+-|-|--|-----------|D2 Q2|-----|< * OUT3 ----------+-|-|-|--|-----------|D3 Q3|-----|< * OUT4 --------+-|-|-|-|--|-----------|D4 Q4|-----|< * OUT5 ------+-|-|-|-|-|--|-----------|D5 Q5|-----|< * OUT6 ----+-|-|-|-|-|-|--|-----------|D6 Q6|-----|< * OUT7 --+-|-|-|-|-|-|-|--|-----------|D7 Q7|-----|< * | | | | | | | | | `--------' * | | | | | | | | | * | | | | | | | | | ,--------. * | | | | | | | | `-----------|> #1 | * | | | | | | | | | | * | | | | | | | `--------------|D0 Q0|-----|< * | | | | | | `----------------|D1 Q1|-----|< * | | | | | `------------------|D2 Q2|-----|< * | | | | `--------------------|D3 Q3|-----|< * | | | `----------------------|D4 Q4|-----|< * | | `------------------------|D5 Q5|-----|< * | `--------------------------|D6 Q6|-----|< * `----------------------------|D7 Q7|-----|< * `--------' * * The above is just an example. The actual number of number of latches and * the number of inputs per latch is derived from the number of GPIOs given * in the corresponding device tree properties. */ #include <linux/err.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/delay.h> #include "gpiolib.h" struct gpio_latch_priv { … }; static int gpio_latch_get_direction(struct gpio_chip *gc, unsigned int offset) { … } static void gpio_latch_set_unlocked(struct gpio_latch_priv *priv, void (*set)(struct gpio_desc *desc, int value), unsigned int offset, bool val) { … } static void gpio_latch_set(struct gpio_chip *gc, unsigned int offset, int val) { … } static void gpio_latch_set_can_sleep(struct gpio_chip *gc, unsigned int offset, int val) { … } static bool gpio_latch_can_sleep(struct gpio_latch_priv *priv, unsigned int n_latches) { … } /* * Some value which is still acceptable to delay in atomic context. * If we need to go higher we might have to switch to usleep_range(), * but that cannot ne used in atomic context and the driver would have * to be adjusted to support that. */ #define DURATION_NS_MAX … static int gpio_latch_probe(struct platform_device *pdev) { … } static const struct of_device_id gpio_latch_ids[] = …; MODULE_DEVICE_TABLE(of, gpio_latch_ids); static struct platform_driver gpio_latch_driver = …; module_platform_driver(…) …; MODULE_LICENSE(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …;