.. | .. |
---|
38 | 38 | #include <linux/err.h> |
---|
39 | 39 | #include <linux/gpio/driver.h> |
---|
40 | 40 | #include <linux/gpio/consumer.h> |
---|
| 41 | +#include <linux/gpio/machine.h> |
---|
41 | 42 | #include <linux/init.h> |
---|
42 | 43 | #include <linux/io.h> |
---|
43 | 44 | #include <linux/irq.h> |
---|
.. | .. |
---|
45 | 46 | #include <linux/irqdomain.h> |
---|
46 | 47 | #include <linux/mfd/syscon.h> |
---|
47 | 48 | #include <linux/of_device.h> |
---|
48 | | -#include <linux/of_irq.h> |
---|
49 | 49 | #include <linux/pinctrl/consumer.h> |
---|
50 | 50 | #include <linux/platform_device.h> |
---|
51 | 51 | #include <linux/pwm.h> |
---|
.. | .. |
---|
376 | 376 | return 0; |
---|
377 | 377 | } |
---|
378 | 378 | |
---|
| 379 | +static int mvebu_gpio_get_direction(struct gpio_chip *chip, unsigned int pin) |
---|
| 380 | +{ |
---|
| 381 | + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); |
---|
| 382 | + u32 u; |
---|
| 383 | + |
---|
| 384 | + regmap_read(mvchip->regs, GPIO_IO_CONF_OFF + mvchip->offset, &u); |
---|
| 385 | + |
---|
| 386 | + if (u & BIT(pin)) |
---|
| 387 | + return GPIO_LINE_DIRECTION_IN; |
---|
| 388 | + |
---|
| 389 | + return GPIO_LINE_DIRECTION_OUT; |
---|
| 390 | +} |
---|
| 391 | + |
---|
379 | 392 | static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned int pin) |
---|
380 | 393 | { |
---|
381 | 394 | struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); |
---|
.. | .. |
---|
418 | 431 | u32 mask = d->mask; |
---|
419 | 432 | |
---|
420 | 433 | irq_gc_lock(gc); |
---|
| 434 | + mvebu_gpio_write_edge_cause(mvchip, ~mask); |
---|
421 | 435 | ct->mask_cache_priv |= mask; |
---|
422 | 436 | mvebu_gpio_write_edge_mask(mvchip, ct->mask_cache_priv); |
---|
423 | 437 | irq_gc_unlock(gc); |
---|
.. | .. |
---|
608 | 622 | ret = -EBUSY; |
---|
609 | 623 | } else { |
---|
610 | 624 | desc = gpiochip_request_own_desc(&mvchip->chip, |
---|
611 | | - pwm->hwpwm, "mvebu-pwm"); |
---|
| 625 | + pwm->hwpwm, "mvebu-pwm", |
---|
| 626 | + GPIO_ACTIVE_HIGH, |
---|
| 627 | + GPIOD_OUT_LOW); |
---|
612 | 628 | if (IS_ERR(desc)) { |
---|
613 | 629 | ret = PTR_ERR(desc); |
---|
614 | | - goto out; |
---|
615 | | - } |
---|
616 | | - |
---|
617 | | - ret = gpiod_direction_output(desc, 0); |
---|
618 | | - if (ret) { |
---|
619 | | - gpiochip_free_own_desc(desc); |
---|
620 | 630 | goto out; |
---|
621 | 631 | } |
---|
622 | 632 | |
---|
.. | .. |
---|
682 | 692 | } |
---|
683 | 693 | |
---|
684 | 694 | static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, |
---|
685 | | - struct pwm_state *state) |
---|
| 695 | + const struct pwm_state *state) |
---|
686 | 696 | { |
---|
687 | 697 | struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); |
---|
688 | 698 | struct mvebu_gpio_chip *mvchip = mvpwm->mvchip; |
---|
689 | 699 | unsigned long long val; |
---|
690 | 700 | unsigned long flags; |
---|
691 | 701 | unsigned int on, off; |
---|
| 702 | + |
---|
| 703 | + if (state->polarity != PWM_POLARITY_NORMAL) |
---|
| 704 | + return -EINVAL; |
---|
692 | 705 | |
---|
693 | 706 | val = (unsigned long long) mvpwm->clk_rate * state->duty_cycle; |
---|
694 | 707 | do_div(val, NSEC_PER_SEC); |
---|
.. | .. |
---|
761 | 774 | { |
---|
762 | 775 | struct device *dev = &pdev->dev; |
---|
763 | 776 | struct mvebu_pwm *mvpwm; |
---|
764 | | - struct resource *res; |
---|
765 | 777 | u32 set; |
---|
766 | 778 | |
---|
767 | 779 | if (!of_device_is_compatible(mvchip->chip.of_node, |
---|
.. | .. |
---|
774 | 786 | * for the first two GPIO chips. So if the resource is missing |
---|
775 | 787 | * we can't treat it as an error. |
---|
776 | 788 | */ |
---|
777 | | - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm"); |
---|
778 | | - if (!res) |
---|
| 789 | + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm")) |
---|
779 | 790 | return 0; |
---|
780 | 791 | |
---|
781 | 792 | if (IS_ERR(mvchip->clk)) |
---|
.. | .. |
---|
800 | 811 | mvchip->mvpwm = mvpwm; |
---|
801 | 812 | mvpwm->mvchip = mvchip; |
---|
802 | 813 | |
---|
803 | | - mvpwm->membase = devm_ioremap_resource(dev, res); |
---|
| 814 | + mvpwm->membase = devm_platform_ioremap_resource_byname(pdev, "pwm"); |
---|
804 | 815 | if (IS_ERR(mvpwm->membase)) |
---|
805 | 816 | return PTR_ERR(mvpwm->membase); |
---|
806 | 817 | |
---|
.. | .. |
---|
833 | 844 | { |
---|
834 | 845 | struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); |
---|
835 | 846 | u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk; |
---|
| 847 | + const char *label; |
---|
836 | 848 | int i; |
---|
837 | 849 | |
---|
838 | 850 | regmap_read(mvchip->regs, GPIO_OUT_OFF + mvchip->offset, &out); |
---|
.. | .. |
---|
844 | 856 | edg_msk = mvebu_gpio_read_edge_mask(mvchip); |
---|
845 | 857 | lvl_msk = mvebu_gpio_read_level_mask(mvchip); |
---|
846 | 858 | |
---|
847 | | - for (i = 0; i < chip->ngpio; i++) { |
---|
848 | | - const char *label; |
---|
| 859 | + for_each_requested_gpio(chip, i, label) { |
---|
849 | 860 | u32 msk; |
---|
850 | 861 | bool is_out; |
---|
851 | | - |
---|
852 | | - label = gpiochip_is_requested(chip, i); |
---|
853 | | - if (!label) |
---|
854 | | - continue; |
---|
855 | 862 | |
---|
856 | 863 | msk = BIT(i); |
---|
857 | 864 | is_out = !(io_conf & msk); |
---|
.. | .. |
---|
1023 | 1030 | static int mvebu_gpio_probe_raw(struct platform_device *pdev, |
---|
1024 | 1031 | struct mvebu_gpio_chip *mvchip) |
---|
1025 | 1032 | { |
---|
1026 | | - struct resource *res; |
---|
1027 | 1033 | void __iomem *base; |
---|
1028 | 1034 | |
---|
1029 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1030 | | - base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 1035 | + base = devm_platform_ioremap_resource(pdev, 0); |
---|
1031 | 1036 | if (IS_ERR(base)) |
---|
1032 | 1037 | return PTR_ERR(base); |
---|
1033 | 1038 | |
---|
.. | .. |
---|
1047 | 1052 | * per-CPU registers |
---|
1048 | 1053 | */ |
---|
1049 | 1054 | if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { |
---|
1050 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
1051 | | - base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 1055 | + base = devm_platform_ioremap_resource(pdev, 1); |
---|
1052 | 1056 | if (IS_ERR(base)) |
---|
1053 | 1057 | return PTR_ERR(base); |
---|
1054 | 1058 | |
---|
.. | .. |
---|
1095 | 1099 | soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; |
---|
1096 | 1100 | |
---|
1097 | 1101 | /* Some gpio controllers do not provide irq support */ |
---|
1098 | | - have_irqs = of_irq_count(np) != 0; |
---|
| 1102 | + err = platform_irq_count(pdev); |
---|
| 1103 | + if (err < 0) |
---|
| 1104 | + return err; |
---|
| 1105 | + |
---|
| 1106 | + have_irqs = err != 0; |
---|
1099 | 1107 | |
---|
1100 | 1108 | mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), |
---|
1101 | 1109 | GFP_KERNEL); |
---|
.. | .. |
---|
1125 | 1133 | mvchip->chip.parent = &pdev->dev; |
---|
1126 | 1134 | mvchip->chip.request = gpiochip_generic_request; |
---|
1127 | 1135 | mvchip->chip.free = gpiochip_generic_free; |
---|
| 1136 | + mvchip->chip.get_direction = mvebu_gpio_get_direction; |
---|
1128 | 1137 | mvchip->chip.direction_input = mvebu_gpio_direction_input; |
---|
1129 | 1138 | mvchip->chip.get = mvebu_gpio_get; |
---|
1130 | 1139 | mvchip->chip.direction_output = mvebu_gpio_direction_output; |
---|
.. | .. |
---|
1243 | 1252 | * pins. |
---|
1244 | 1253 | */ |
---|
1245 | 1254 | for (i = 0; i < 4; i++) { |
---|
1246 | | - int irq = platform_get_irq(pdev, i); |
---|
| 1255 | + int irq = platform_get_irq_optional(pdev, i); |
---|
1247 | 1256 | |
---|
1248 | 1257 | if (irq < 0) |
---|
1249 | 1258 | continue; |
---|