]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/gpio/gpio-74xx-mmio.c
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
[mirror_ubuntu-focal-kernel.git] / drivers / gpio / gpio-74xx-mmio.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
af0a33e2
AS
2/*
3 * 74xx MMIO GPIO driver
4 *
5 * Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
af0a33e2
AS
6 */
7
8#include <linux/err.h>
af0a33e2
AS
9#include <linux/module.h>
10#include <linux/of_device.h>
0f4630f3 11#include <linux/gpio/driver.h>
af0a33e2
AS
12#include <linux/platform_device.h>
13
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)
17
18struct mmio_74xx_gpio_priv {
0f4630f3 19 struct gpio_chip gc;
af0a33e2
AS
20 unsigned flags;
21};
22
23static const struct of_device_id mmio_74xx_gpio_ids[] = {
24 {
25 .compatible = "ti,741g125",
26 .data = (const void *)(MMIO_74XX_DIR_IN | 1),
27 },
28 {
29 .compatible = "ti,742g125",
30 .data = (const void *)(MMIO_74XX_DIR_IN | 2),
31 },
32 {
33 .compatible = "ti,74125",
34 .data = (const void *)(MMIO_74XX_DIR_IN | 4),
35 },
36 {
37 .compatible = "ti,74365",
38 .data = (const void *)(MMIO_74XX_DIR_IN | 6),
39 },
40 {
41 .compatible = "ti,74244",
42 .data = (const void *)(MMIO_74XX_DIR_IN | 8),
43 },
44 {
45 .compatible = "ti,741624",
46 .data = (const void *)(MMIO_74XX_DIR_IN | 16),
47 },
48 {
49 .compatible = "ti,741g74",
50 .data = (const void *)(MMIO_74XX_DIR_OUT | 1),
51 },
52 {
53 .compatible = "ti,7474",
54 .data = (const void *)(MMIO_74XX_DIR_OUT | 2),
55 },
56 {
57 .compatible = "ti,74175",
58 .data = (const void *)(MMIO_74XX_DIR_OUT | 4),
59 },
60 {
61 .compatible = "ti,74174",
62 .data = (const void *)(MMIO_74XX_DIR_OUT | 6),
63 },
64 {
65 .compatible = "ti,74273",
66 .data = (const void *)(MMIO_74XX_DIR_OUT | 8),
67 },
68 {
69 .compatible = "ti,7416374",
70 .data = (const void *)(MMIO_74XX_DIR_OUT | 16),
71 },
72 { }
73};
74MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids);
75
af0a33e2
AS
76static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset)
77{
0f4630f3 78 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
af0a33e2 79
0f4630f3 80 return !(priv->flags & MMIO_74XX_DIR_OUT);
af0a33e2
AS
81}
82
83static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
84{
0f4630f3 85 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
af0a33e2
AS
86
87 return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0;
88}
89
90static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
91{
0f4630f3 92 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
af0a33e2
AS
93
94 if (priv->flags & MMIO_74XX_DIR_OUT) {
95 gc->set(gc, gpio, val);
96 return 0;
97 }
98
99 return -ENOTSUPP;
100}
101
102static int mmio_74xx_gpio_probe(struct platform_device *pdev)
103{
af0a33e2 104 struct mmio_74xx_gpio_priv *priv;
af0a33e2
AS
105 void __iomem *dat;
106 int err;
107
108 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
109 if (!priv)
110 return -ENOMEM;
111
a23ffcf2
TR
112 priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev);
113
3faf1e6f 114 dat = devm_platform_ioremap_resource(pdev, 0);
af0a33e2
AS
115 if (IS_ERR(dat))
116 return PTR_ERR(dat);
117
0f4630f3 118 err = bgpio_init(&priv->gc, &pdev->dev,
af0a33e2
AS
119 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
120 dat, NULL, NULL, NULL, NULL, 0);
121 if (err)
122 return err;
123
0f4630f3
LW
124 priv->gc.direction_input = mmio_74xx_dir_in;
125 priv->gc.direction_output = mmio_74xx_dir_out;
126 priv->gc.get_direction = mmio_74xx_get_direction;
127 priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
128 priv->gc.owner = THIS_MODULE;
af0a33e2
AS
129
130 platform_set_drvdata(pdev, priv);
131
a718ed2c 132 return devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv);
af0a33e2
AS
133}
134
135static struct platform_driver mmio_74xx_gpio_driver = {
136 .driver = {
137 .name = "74xx-mmio-gpio",
138 .of_match_table = mmio_74xx_gpio_ids,
139 },
140 .probe = mmio_74xx_gpio_probe,
af0a33e2
AS
141};
142module_platform_driver(mmio_74xx_gpio_driver);
143
144MODULE_LICENSE("GPL");
145MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
146MODULE_DESCRIPTION("74xx MMIO GPIO driver");