io_uring: do not always copy iovec in io_req_map_rw()
[linux/fpc-iii.git] / drivers / gpio / gpio-mlxbf.c
blob894aaf55fc96c1fc5a45b399d8e16790dc251519
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/acpi.h>
4 #include <linux/bitops.h>
5 #include <linux/device.h>
6 #include <linux/gpio/driver.h>
7 #include <linux/io.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/pm.h>
12 #include <linux/resource.h>
13 #include <linux/types.h>
15 /* Number of pins on BlueField */
16 #define MLXBF_GPIO_NR 54
18 /* Pad Electrical Controls. */
19 #define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700
20 #define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708
21 #define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710
22 #define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718
24 #define MLXBF_GPIO_PIN_DIR_I 0x1040
25 #define MLXBF_GPIO_PIN_DIR_O 0x1048
26 #define MLXBF_GPIO_PIN_STATE 0x1000
27 #define MLXBF_GPIO_SCRATCHPAD 0x20
29 #ifdef CONFIG_PM
30 struct mlxbf_gpio_context_save_regs {
31 u64 scratchpad;
32 u64 pad_control[MLXBF_GPIO_NR];
33 u64 pin_dir_i;
34 u64 pin_dir_o;
36 #endif
38 /* Device state structure. */
39 struct mlxbf_gpio_state {
40 struct gpio_chip gc;
42 /* Memory Address */
43 void __iomem *base;
45 #ifdef CONFIG_PM
46 struct mlxbf_gpio_context_save_regs csave_regs;
47 #endif
50 static int mlxbf_gpio_probe(struct platform_device *pdev)
52 struct mlxbf_gpio_state *gs;
53 struct device *dev = &pdev->dev;
54 struct gpio_chip *gc;
55 int ret;
57 gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL);
58 if (!gs)
59 return -ENOMEM;
61 gs->base = devm_platform_ioremap_resource(pdev, 0);
62 if (IS_ERR(gs->base))
63 return PTR_ERR(gs->base);
65 gc = &gs->gc;
66 ret = bgpio_init(gc, dev, 8,
67 gs->base + MLXBF_GPIO_PIN_STATE,
68 NULL,
69 NULL,
70 gs->base + MLXBF_GPIO_PIN_DIR_O,
71 gs->base + MLXBF_GPIO_PIN_DIR_I,
72 0);
73 if (ret)
74 return -ENODEV;
76 gc->owner = THIS_MODULE;
77 gc->ngpio = MLXBF_GPIO_NR;
79 ret = devm_gpiochip_add_data(dev, &gs->gc, gs);
80 if (ret) {
81 dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n");
82 return ret;
85 platform_set_drvdata(pdev, gs);
86 dev_info(&pdev->dev, "registered Mellanox BlueField GPIO");
87 return 0;
90 #ifdef CONFIG_PM
91 static int mlxbf_gpio_suspend(struct platform_device *pdev, pm_message_t state)
93 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
95 gs->csave_regs.scratchpad = readq(gs->base + MLXBF_GPIO_SCRATCHPAD);
96 gs->csave_regs.pad_control[0] =
97 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
98 gs->csave_regs.pad_control[1] =
99 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
100 gs->csave_regs.pad_control[2] =
101 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
102 gs->csave_regs.pad_control[3] =
103 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
104 gs->csave_regs.pin_dir_i = readq(gs->base + MLXBF_GPIO_PIN_DIR_I);
105 gs->csave_regs.pin_dir_o = readq(gs->base + MLXBF_GPIO_PIN_DIR_O);
107 return 0;
110 static int mlxbf_gpio_resume(struct platform_device *pdev)
112 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
114 writeq(gs->csave_regs.scratchpad, gs->base + MLXBF_GPIO_SCRATCHPAD);
115 writeq(gs->csave_regs.pad_control[0],
116 gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
117 writeq(gs->csave_regs.pad_control[1],
118 gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
119 writeq(gs->csave_regs.pad_control[2],
120 gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
121 writeq(gs->csave_regs.pad_control[3],
122 gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
123 writeq(gs->csave_regs.pin_dir_i, gs->base + MLXBF_GPIO_PIN_DIR_I);
124 writeq(gs->csave_regs.pin_dir_o, gs->base + MLXBF_GPIO_PIN_DIR_O);
126 return 0;
128 #endif
130 static const struct acpi_device_id mlxbf_gpio_acpi_match[] = {
131 { "MLNXBF02", 0 },
134 MODULE_DEVICE_TABLE(acpi, mlxbf_gpio_acpi_match);
136 static struct platform_driver mlxbf_gpio_driver = {
137 .driver = {
138 .name = "mlxbf_gpio",
139 .acpi_match_table = ACPI_PTR(mlxbf_gpio_acpi_match),
141 .probe = mlxbf_gpio_probe,
142 #ifdef CONFIG_PM
143 .suspend = mlxbf_gpio_suspend,
144 .resume = mlxbf_gpio_resume,
145 #endif
148 module_platform_driver(mlxbf_gpio_driver);
150 MODULE_DESCRIPTION("Mellanox BlueField GPIO Driver");
151 MODULE_AUTHOR("Mellanox Technologies");
152 MODULE_LICENSE("GPL");