Lines Matching +full:ast2600 +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 #include <linux/gpio/driver.h>
49 * Note: The "value" register returns the input value when the GPIO is
52 * The "rdata" register returns the output value when the GPIO is
104 static void __iomem *bank_reg(struct aspeed_sgpio *gpio, in bank_reg() argument
110 return gpio->base + bank->val_regs + GPIO_VAL_VALUE; in bank_reg()
112 return gpio->base + bank->rdata_reg; in bank_reg()
114 return gpio->base + bank->irq_regs + GPIO_IRQ_ENABLE; in bank_reg()
116 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE0; in bank_reg()
118 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE1; in bank_reg()
120 return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2; in bank_reg()
122 return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS; in bank_reg()
124 return gpio->base + bank->tolerance_regs; in bank_reg()
171 struct aspeed_sgpio *gpio = gpiochip_get_data(gc); in aspeed_sgpio_get() local
177 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_get()
180 rc = !!(ioread32(bank_reg(gpio, bank, reg)) & GPIO_BIT(offset)); in aspeed_sgpio_get()
182 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_get()
189 struct aspeed_sgpio *gpio = gpiochip_get_data(gc); in sgpio_set_value() local
195 return -EINVAL; in sgpio_set_value()
199 addr_r = bank_reg(gpio, bank, reg_rdata); in sgpio_set_value()
200 addr_w = bank_reg(gpio, bank, reg_val); in sgpio_set_value()
216 struct aspeed_sgpio *gpio = gpiochip_get_data(gc); in aspeed_sgpio_set() local
219 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_set()
223 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_set()
228 return aspeed_sgpio_is_input(offset) ? 0 : -EINVAL; in aspeed_sgpio_dir_in()
233 struct aspeed_sgpio *gpio = gpiochip_get_data(gc); in aspeed_sgpio_dir_out() local
238 * error-out in sgpio_set_value if this isn't an output GPIO */ in aspeed_sgpio_dir_out()
240 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_dir_out()
242 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_dir_out()
253 struct aspeed_sgpio **gpio, in irqd_to_aspeed_sgpio_data() argument
263 *gpio = internal; in irqd_to_aspeed_sgpio_data()
271 struct aspeed_sgpio *gpio; in aspeed_sgpio_irq_ack() local
277 irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_sgpio_irq_ack()
279 status_addr = bank_reg(gpio, bank, reg_irq_status); in aspeed_sgpio_irq_ack()
281 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_irq_ack()
285 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_irq_ack()
291 struct aspeed_sgpio *gpio; in aspeed_sgpio_irq_set_mask() local
297 irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_sgpio_irq_set_mask()
298 addr = bank_reg(gpio, bank, reg_irq_enable); in aspeed_sgpio_irq_set_mask()
302 gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); in aspeed_sgpio_irq_set_mask()
304 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_irq_set_mask()
314 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_irq_set_mask()
318 gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); in aspeed_sgpio_irq_set_mask()
341 struct aspeed_sgpio *gpio; in aspeed_sgpio_set_type() local
346 irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_sgpio_set_type()
366 return -EINVAL; in aspeed_sgpio_set_type()
369 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_set_type()
371 addr = bank_reg(gpio, bank, reg_irq_type0); in aspeed_sgpio_set_type()
376 addr = bank_reg(gpio, bank, reg_irq_type1); in aspeed_sgpio_set_type()
381 addr = bank_reg(gpio, bank, reg_irq_type2); in aspeed_sgpio_set_type()
386 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_set_type()
409 generic_handle_domain_irq(gc->irq.domain, (i * 32 + p) * 2); in aspeed_sgpio_irq_handler()
418 struct aspeed_sgpio *gpio; in aspeed_sgpio_irq_print_chip() local
422 irqd_to_aspeed_sgpio_data(d, &gpio, &bank, &bit, &offset); in aspeed_sgpio_irq_print_chip()
423 seq_printf(p, dev_name(gpio->dev)); in aspeed_sgpio_irq_print_chip()
436 static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio, in aspeed_sgpio_setup_irqs() argument
447 gpio->irq = rc; in aspeed_sgpio_setup_irqs()
453 iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_enable)); in aspeed_sgpio_setup_irqs()
455 iowrite32(0xffffffff, bank_reg(gpio, bank, reg_irq_status)); in aspeed_sgpio_setup_irqs()
458 irq = &gpio->chip.irq; in aspeed_sgpio_setup_irqs()
460 irq->init_valid_mask = aspeed_sgpio_irq_init_valid_mask; in aspeed_sgpio_setup_irqs()
461 irq->handler = handle_bad_irq; in aspeed_sgpio_setup_irqs()
462 irq->default_type = IRQ_TYPE_NONE; in aspeed_sgpio_setup_irqs()
463 irq->parent_handler = aspeed_sgpio_irq_handler; in aspeed_sgpio_setup_irqs()
464 irq->parent_handler_data = gpio; in aspeed_sgpio_setup_irqs()
465 irq->parents = &gpio->irq; in aspeed_sgpio_setup_irqs()
466 irq->num_parents = 1; in aspeed_sgpio_setup_irqs()
471 /* set falling or level-low irq */ in aspeed_sgpio_setup_irqs()
472 iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type0)); in aspeed_sgpio_setup_irqs()
474 iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type1)); in aspeed_sgpio_setup_irqs()
476 iowrite32(0x00000000, bank_reg(gpio, bank, reg_irq_type2)); in aspeed_sgpio_setup_irqs()
489 struct aspeed_sgpio *gpio = gpiochip_get_data(chip); in aspeed_sgpio_reset_tolerance() local
494 reg = bank_reg(gpio, to_bank(offset), reg_tolerance); in aspeed_sgpio_reset_tolerance()
496 raw_spin_lock_irqsave(&gpio->lock, flags); in aspeed_sgpio_reset_tolerance()
507 raw_spin_unlock_irqrestore(&gpio->lock, flags); in aspeed_sgpio_reset_tolerance()
521 return -ENOTSUPP; in aspeed_sgpio_set_config()
529 { .compatible = "aspeed,ast2400-sgpio", .data = &ast2400_sgpio_pdata, },
530 { .compatible = "aspeed,ast2500-sgpio", .data = &ast2400_sgpio_pdata, },
531 { .compatible = "aspeed,ast2600-sgpiom", .data = &ast2600_sgpiom_pdata, },
541 struct aspeed_sgpio *gpio; in aspeed_sgpio_probe() local
545 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); in aspeed_sgpio_probe()
546 if (!gpio) in aspeed_sgpio_probe()
547 return -ENOMEM; in aspeed_sgpio_probe()
549 gpio->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_sgpio_probe()
550 if (IS_ERR(gpio->base)) in aspeed_sgpio_probe()
551 return PTR_ERR(gpio->base); in aspeed_sgpio_probe()
553 gpio->dev = &pdev->dev; in aspeed_sgpio_probe()
555 pdata = device_get_match_data(&pdev->dev); in aspeed_sgpio_probe()
557 return -EINVAL; in aspeed_sgpio_probe()
559 pin_mask = pdata->pin_mask; in aspeed_sgpio_probe()
561 rc = device_property_read_u32(&pdev->dev, "ngpios", &nr_gpios); in aspeed_sgpio_probe()
563 dev_err(&pdev->dev, "Could not read ngpios property\n"); in aspeed_sgpio_probe()
564 return -EINVAL; in aspeed_sgpio_probe()
566 dev_err(&pdev->dev, "Number of GPIOs not multiple of 8: %d\n", in aspeed_sgpio_probe()
568 return -EINVAL; in aspeed_sgpio_probe()
571 rc = device_property_read_u32(&pdev->dev, "bus-frequency", &sgpio_freq); in aspeed_sgpio_probe()
573 dev_err(&pdev->dev, "Could not read bus-frequency property\n"); in aspeed_sgpio_probe()
574 return -EINVAL; in aspeed_sgpio_probe()
577 gpio->pclk = devm_clk_get(&pdev->dev, NULL); in aspeed_sgpio_probe()
578 if (IS_ERR(gpio->pclk)) { in aspeed_sgpio_probe()
579 dev_err(&pdev->dev, "devm_clk_get failed\n"); in aspeed_sgpio_probe()
580 return PTR_ERR(gpio->pclk); in aspeed_sgpio_probe()
583 apb_freq = clk_get_rate(gpio->pclk); in aspeed_sgpio_probe()
592 * GPIO254[31:16] = PCLK / (frequency * 2) - 1 in aspeed_sgpio_probe()
595 return -EINVAL; in aspeed_sgpio_probe()
597 sgpio_clk_div = (apb_freq / (sgpio_freq * 2)) - 1; in aspeed_sgpio_probe()
599 if (sgpio_clk_div > (1 << 16) - 1) in aspeed_sgpio_probe()
600 return -EINVAL; in aspeed_sgpio_probe()
604 ASPEED_SGPIO_ENABLE, gpio->base + ASPEED_SGPIO_CTRL); in aspeed_sgpio_probe()
606 raw_spin_lock_init(&gpio->lock); in aspeed_sgpio_probe()
608 gpio->chip.parent = &pdev->dev; in aspeed_sgpio_probe()
609 gpio->chip.ngpio = nr_gpios * 2; in aspeed_sgpio_probe()
610 gpio->chip.init_valid_mask = aspeed_sgpio_init_valid_mask; in aspeed_sgpio_probe()
611 gpio->chip.direction_input = aspeed_sgpio_dir_in; in aspeed_sgpio_probe()
612 gpio->chip.direction_output = aspeed_sgpio_dir_out; in aspeed_sgpio_probe()
613 gpio->chip.get_direction = aspeed_sgpio_get_direction; in aspeed_sgpio_probe()
614 gpio->chip.request = NULL; in aspeed_sgpio_probe()
615 gpio->chip.free = NULL; in aspeed_sgpio_probe()
616 gpio->chip.get = aspeed_sgpio_get; in aspeed_sgpio_probe()
617 gpio->chip.set = aspeed_sgpio_set; in aspeed_sgpio_probe()
618 gpio->chip.set_config = aspeed_sgpio_set_config; in aspeed_sgpio_probe()
619 gpio->chip.label = dev_name(&pdev->dev); in aspeed_sgpio_probe()
620 gpio->chip.base = -1; in aspeed_sgpio_probe()
622 aspeed_sgpio_setup_irqs(gpio, pdev); in aspeed_sgpio_probe()
624 rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); in aspeed_sgpio_probe()
639 MODULE_DESCRIPTION("Aspeed Serial GPIO Driver");