Lines Matching +full:msc313 +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/gpio/driver.h>
15 #include <dt-bindings/gpio/msc313-gpio.h>
16 #include <dt-bindings/interrupt-controller/arm-gic.h>
18 #define DRIVER_NAME "gpio-msc313"
26 * gpio state when resuming from suspend to memory.
223 MSC313_GPIO_CHIPDATA(msc313);
226 * Unlike the msc313(e) the ssd20xd have a bunch of pins
227 * that are actually called gpio probably because they
446 * of the registers that control the gpio.
491 struct msc313_gpio *gpio = gpiochip_get_data(chip); in msc313_gpio_set() local
492 u8 gpioreg = readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_set()
499 writeb_relaxed(gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_set()
504 struct msc313_gpio *gpio = gpiochip_get_data(chip); in msc313_gpio_get() local
506 return readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]) & MSC313_GPIO_IN; in msc313_gpio_get()
511 struct msc313_gpio *gpio = gpiochip_get_data(chip); in msc313_gpio_direction_input() local
512 u8 gpioreg = readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_direction_input()
515 writeb_relaxed(gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_direction_input()
522 struct msc313_gpio *gpio = gpiochip_get_data(chip); in msc313_gpio_direction_output() local
523 u8 gpioreg = readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_direction_output()
530 writeb_relaxed(gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); in msc313_gpio_direction_output()
540 gpiochip_disable_irq(gc, d->hwirq); in msc313_gpio_irq_mask()
547 gpiochip_enable_irq(gc, d->hwirq); in msc313_gpio_irq_unmask()
556 .name = "GPIO",
576 struct irq_fwspec *fwspec = &gfwspec->fwspec; in msc313_gpio_populate_parent_fwspec()
578 fwspec->fwnode = gc->irq.parent_domain->fwnode; in msc313_gpio_populate_parent_fwspec()
579 fwspec->param_count = 3; in msc313_gpio_populate_parent_fwspec()
580 fwspec->param[0] = GIC_SPI; in msc313_gpio_populate_parent_fwspec()
581 fwspec->param[1] = parent_hwirq; in msc313_gpio_populate_parent_fwspec()
582 fwspec->param[2] = parent_type; in msc313_gpio_populate_parent_fwspec()
594 unsigned int offset = priv->gpio_data->offsets[child]; in msc313e_gpio_child_to_parent_hwirq()
603 *parent = ((offset - OFF_SPI0_CZ) >> 2) + 28; in msc313e_gpio_child_to_parent_hwirq()
607 return -EINVAL; in msc313e_gpio_child_to_parent_hwirq()
613 struct msc313_gpio *gpio; in msc313_gpio_probe() local
618 struct device *dev = &pdev->dev; in msc313_gpio_probe()
622 return -EINVAL; in msc313_gpio_probe()
624 parent_node = of_irq_find_parent(dev->of_node); in msc313_gpio_probe()
626 return -ENODEV; in msc313_gpio_probe()
630 return -ENODEV; in msc313_gpio_probe()
632 gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); in msc313_gpio_probe()
633 if (!gpio) in msc313_gpio_probe()
634 return -ENOMEM; in msc313_gpio_probe()
636 gpio->gpio_data = match_data; in msc313_gpio_probe()
638 gpio->saved = devm_kcalloc(dev, gpio->gpio_data->num, sizeof(*gpio->saved), GFP_KERNEL); in msc313_gpio_probe()
639 if (!gpio->saved) in msc313_gpio_probe()
640 return -ENOMEM; in msc313_gpio_probe()
642 gpio->base = devm_platform_ioremap_resource(pdev, 0); in msc313_gpio_probe()
643 if (IS_ERR(gpio->base)) in msc313_gpio_probe()
644 return PTR_ERR(gpio->base); in msc313_gpio_probe()
646 platform_set_drvdata(pdev, gpio); in msc313_gpio_probe()
650 return -ENOMEM; in msc313_gpio_probe()
652 gpiochip->label = DRIVER_NAME; in msc313_gpio_probe()
653 gpiochip->parent = dev; in msc313_gpio_probe()
654 gpiochip->request = gpiochip_generic_request; in msc313_gpio_probe()
655 gpiochip->free = gpiochip_generic_free; in msc313_gpio_probe()
656 gpiochip->direction_input = msc313_gpio_direction_input; in msc313_gpio_probe()
657 gpiochip->direction_output = msc313_gpio_direction_output; in msc313_gpio_probe()
658 gpiochip->get = msc313_gpio_get; in msc313_gpio_probe()
659 gpiochip->set = msc313_gpio_set; in msc313_gpio_probe()
660 gpiochip->base = -1; in msc313_gpio_probe()
661 gpiochip->ngpio = gpio->gpio_data->num; in msc313_gpio_probe()
662 gpiochip->names = gpio->gpio_data->names; in msc313_gpio_probe()
664 gpioirqchip = &gpiochip->irq; in msc313_gpio_probe()
666 gpioirqchip->fwnode = dev_fwnode(dev); in msc313_gpio_probe()
667 gpioirqchip->parent_domain = parent_domain; in msc313_gpio_probe()
668 gpioirqchip->child_to_parent_hwirq = msc313e_gpio_child_to_parent_hwirq; in msc313_gpio_probe()
669 gpioirqchip->populate_parent_alloc_arg = msc313_gpio_populate_parent_fwspec; in msc313_gpio_probe()
670 gpioirqchip->handler = handle_bad_irq; in msc313_gpio_probe()
671 gpioirqchip->default_type = IRQ_TYPE_NONE; in msc313_gpio_probe()
673 return devm_gpiochip_add_data(dev, gpiochip, gpio); in msc313_gpio_probe()
679 .compatible = "mstar,msc313-gpio",
683 .compatible = "sstar,ssd20xd-gpio",
691 * The GPIO controller loses the state of the registers when the
697 struct msc313_gpio *gpio = dev_get_drvdata(dev); in msc313_gpio_suspend() local
700 for (i = 0; i < gpio->gpio_data->num; i++) in msc313_gpio_suspend()
701 gpio->saved[i] = readb_relaxed(gpio->base + gpio->gpio_data->offsets[i]) & MSC313_GPIO_BITSTOSAVE; in msc313_gpio_suspend()
708 struct msc313_gpio *gpio = dev_get_drvdata(dev); in msc313_gpio_resume() local
711 for (i = 0; i < gpio->gpio_data->num; i++) in msc313_gpio_resume()
712 writeb_relaxed(gpio->saved[i], gpio->base + gpio->gpio_data->offsets[i]); in msc313_gpio_resume()