split dev_queue
[cor.git] / drivers / gpio / gpio-74xx-mmio.c
blob173e06758e6c2a46e77442a2e9ad77df17f1b8dc
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * 74xx MMIO GPIO driver
5 * Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
6 */
8 #include <linux/err.h>
9 #include <linux/module.h>
10 #include <linux/of_device.h>
11 #include <linux/gpio/driver.h>
12 #include <linux/platform_device.h>
14 #define MMIO_74XX_DIR_IN (0 << 8)
15 #define MMIO_74XX_DIR_OUT (1 << 8)
16 #define MMIO_74XX_BIT_CNT(x) ((x) & 0xff)
18 struct mmio_74xx_gpio_priv {
19 struct gpio_chip gc;
20 unsigned flags;
23 static const struct of_device_id mmio_74xx_gpio_ids[] = {
25 .compatible = "ti,741g125",
26 .data = (const void *)(MMIO_74XX_DIR_IN | 1),
29 .compatible = "ti,742g125",
30 .data = (const void *)(MMIO_74XX_DIR_IN | 2),
33 .compatible = "ti,74125",
34 .data = (const void *)(MMIO_74XX_DIR_IN | 4),
37 .compatible = "ti,74365",
38 .data = (const void *)(MMIO_74XX_DIR_IN | 6),
41 .compatible = "ti,74244",
42 .data = (const void *)(MMIO_74XX_DIR_IN | 8),
45 .compatible = "ti,741624",
46 .data = (const void *)(MMIO_74XX_DIR_IN | 16),
49 .compatible = "ti,741g74",
50 .data = (const void *)(MMIO_74XX_DIR_OUT | 1),
53 .compatible = "ti,7474",
54 .data = (const void *)(MMIO_74XX_DIR_OUT | 2),
57 .compatible = "ti,74175",
58 .data = (const void *)(MMIO_74XX_DIR_OUT | 4),
61 .compatible = "ti,74174",
62 .data = (const void *)(MMIO_74XX_DIR_OUT | 6),
65 .compatible = "ti,74273",
66 .data = (const void *)(MMIO_74XX_DIR_OUT | 8),
69 .compatible = "ti,7416374",
70 .data = (const void *)(MMIO_74XX_DIR_OUT | 16),
72 { }
74 MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids);
76 static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset)
78 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
80 if (priv->flags & MMIO_74XX_DIR_OUT)
81 return GPIO_LINE_DIRECTION_OUT;
83 return GPIO_LINE_DIRECTION_IN;
86 static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
88 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
90 return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0;
93 static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
95 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
97 if (priv->flags & MMIO_74XX_DIR_OUT) {
98 gc->set(gc, gpio, val);
99 return 0;
102 return -ENOTSUPP;
105 static int mmio_74xx_gpio_probe(struct platform_device *pdev)
107 struct mmio_74xx_gpio_priv *priv;
108 void __iomem *dat;
109 int err;
111 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
112 if (!priv)
113 return -ENOMEM;
115 priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev);
117 dat = devm_platform_ioremap_resource(pdev, 0);
118 if (IS_ERR(dat))
119 return PTR_ERR(dat);
121 err = bgpio_init(&priv->gc, &pdev->dev,
122 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
123 dat, NULL, NULL, NULL, NULL, 0);
124 if (err)
125 return err;
127 priv->gc.direction_input = mmio_74xx_dir_in;
128 priv->gc.direction_output = mmio_74xx_dir_out;
129 priv->gc.get_direction = mmio_74xx_get_direction;
130 priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
131 priv->gc.owner = THIS_MODULE;
133 platform_set_drvdata(pdev, priv);
135 return devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv);
138 static struct platform_driver mmio_74xx_gpio_driver = {
139 .driver = {
140 .name = "74xx-mmio-gpio",
141 .of_match_table = mmio_74xx_gpio_ids,
143 .probe = mmio_74xx_gpio_probe,
145 module_platform_driver(mmio_74xx_gpio_driver);
147 MODULE_LICENSE("GPL");
148 MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
149 MODULE_DESCRIPTION("74xx MMIO GPIO driver");