]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
serial: sc16is7xx: use device_property APIs when configuring irda mode
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Wed, 27 Sep 2023 16:01:52 +0000 (12:01 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Oct 2023 12:59:08 +0000 (14:59 +0200)
Convert driver to be property provider agnostic and allow it to be
used on non-OF platforms.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://lore.kernel.org/r/20230927160153.2717788-2-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/sc16is7xx.c

index 1fe2c3e08a351bebe30d8c91bbcf7f83cfb3aa98..db2bb1c0d36c264648a16898904f7a50d07a317b 100644 (file)
@@ -1408,6 +1408,29 @@ static int sc16is7xx_setup_gpio_chip(struct sc16is7xx_port *s)
 }
 #endif
 
+static void sc16is7xx_setup_irda_ports(struct sc16is7xx_port *s)
+{
+       int i;
+       int ret;
+       int count;
+       u32 irda_port[2];
+       struct device *dev = s->p[0].port.dev;
+
+       count = device_property_count_u32(dev, "irda-mode-ports");
+       if (count < 0 || count > ARRAY_SIZE(irda_port))
+               return;
+
+       ret = device_property_read_u32_array(dev, "irda-mode-ports",
+                                            irda_port, count);
+       if (ret)
+               return;
+
+       for (i = 0; i < count; i++) {
+               if (irda_port[i] < s->devtype->nr_uart)
+                       s->p[irda_port[i]].irda_mode = true;
+       }
+}
+
 /*
  * Configure ports designated to operate as modem control lines.
  */
@@ -1590,16 +1613,7 @@ static int sc16is7xx_probe(struct device *dev,
                sc16is7xx_power(&s->p[i].port, 0);
        }
 
-       if (dev->of_node) {
-               struct property *prop;
-               const __be32 *p;
-               u32 u;
-
-               of_property_for_each_u32(dev->of_node, "irda-mode-ports",
-                                        prop, p, u)
-                       if (u < devtype->nr_uart)
-                               s->p[u].irda_mode = true;
-       }
+       sc16is7xx_setup_irda_ports(s);
 
        ret = sc16is7xx_setup_mctrl_ports(s);
        if (ret)