Lines Matching +full:gpio +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/gpio/driver.h>
15 * struct airoha_gpio_ctrl - Airoha GPIO driver data
34 static int airoha_dir_set(struct gpio_chip *gc, unsigned int gpio, in airoha_dir_set() argument
37 struct airoha_gpio_ctrl *ctrl = gc_to_ctrl(gc); in airoha_dir_set() local
38 u32 dir = ioread32(ctrl->dir[gpio / 16]); in airoha_dir_set()
39 u32 output = ioread32(ctrl->output); in airoha_dir_set()
40 u32 mask = BIT((gpio % 16) * 2); in airoha_dir_set()
44 output |= BIT(gpio); in airoha_dir_set()
47 output &= ~BIT(gpio); in airoha_dir_set()
50 iowrite32(dir, ctrl->dir[gpio / 16]); in airoha_dir_set()
53 gc->set(gc, gpio, val); in airoha_dir_set()
55 iowrite32(output, ctrl->output); in airoha_dir_set()
60 static int airoha_dir_out(struct gpio_chip *gc, unsigned int gpio, in airoha_dir_out() argument
63 return airoha_dir_set(gc, gpio, val, 1); in airoha_dir_out()
66 static int airoha_dir_in(struct gpio_chip *gc, unsigned int gpio) in airoha_dir_in() argument
68 return airoha_dir_set(gc, gpio, 0, 0); in airoha_dir_in()
71 static int airoha_get_dir(struct gpio_chip *gc, unsigned int gpio) in airoha_get_dir() argument
73 struct airoha_gpio_ctrl *ctrl = gc_to_ctrl(gc); in airoha_get_dir() local
74 u32 dir = ioread32(ctrl->dir[gpio / 16]); in airoha_get_dir()
75 u32 mask = BIT((gpio % 16) * 2); in airoha_get_dir()
82 struct device *dev = &pdev->dev; in airoha_gpio_probe()
83 struct airoha_gpio_ctrl *ctrl; in airoha_gpio_probe() local
86 ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); in airoha_gpio_probe()
87 if (!ctrl) in airoha_gpio_probe()
88 return -ENOMEM; in airoha_gpio_probe()
90 ctrl->data = devm_platform_ioremap_resource(pdev, 0); in airoha_gpio_probe()
91 if (IS_ERR(ctrl->data)) in airoha_gpio_probe()
92 return PTR_ERR(ctrl->data); in airoha_gpio_probe()
94 ctrl->dir[0] = devm_platform_ioremap_resource(pdev, 1); in airoha_gpio_probe()
95 if (IS_ERR(ctrl->dir[0])) in airoha_gpio_probe()
96 return PTR_ERR(ctrl->dir[0]); in airoha_gpio_probe()
98 ctrl->dir[1] = devm_platform_ioremap_resource(pdev, 2); in airoha_gpio_probe()
99 if (IS_ERR(ctrl->dir[1])) in airoha_gpio_probe()
100 return PTR_ERR(ctrl->dir[1]); in airoha_gpio_probe()
102 ctrl->output = devm_platform_ioremap_resource(pdev, 3); in airoha_gpio_probe()
103 if (IS_ERR(ctrl->output)) in airoha_gpio_probe()
104 return PTR_ERR(ctrl->output); in airoha_gpio_probe()
106 err = bgpio_init(&ctrl->gc, dev, 4, ctrl->data, NULL, in airoha_gpio_probe()
109 return dev_err_probe(dev, err, "unable to init generic GPIO"); in airoha_gpio_probe()
111 ctrl->gc.ngpio = AIROHA_GPIO_MAX; in airoha_gpio_probe()
112 ctrl->gc.owner = THIS_MODULE; in airoha_gpio_probe()
113 ctrl->gc.direction_output = airoha_dir_out; in airoha_gpio_probe()
114 ctrl->gc.direction_input = airoha_dir_in; in airoha_gpio_probe()
115 ctrl->gc.get_direction = airoha_get_dir; in airoha_gpio_probe()
117 return devm_gpiochip_add_data(dev, &ctrl->gc, ctrl); in airoha_gpio_probe()
121 { .compatible = "airoha,en7523-gpio" },
128 .name = "airoha-gpio",
135 MODULE_DESCRIPTION("Airoha GPIO support");