Fixes/Cleanup for vt8500 serial driver
PATCH RESEND 1/1 Fixes/Cleanup for vt8500 serial driver
Apologies Greg,
Stupid mistake.
This is a resend of the two patches you sent back as 'me being useless'. Tidied up now.
Regards
Tony P
PATCH v4 3/4 serial: vt8500: UART uses gated clock rather than 24Mhz reference
UART modules on Wondermedia SoCs are connected via a gated clock source, rather than directly to the 24Mhz reference clock. While uboot enables UART0 for debugging, other UART ports are unavailable until the clock is enabled.
This patch checks that a valid clock is actually passed from devicetree, enables the clock in probe. This change removes the fallback when a clock was not specified as it doesn't apply any longer (and would only work if the UART clock was already enabled).
DTSI files are updated for VT8500, WM8505 and WM8650.
--- arch/arm/boot/dts/vt8500.dtsi | 40 +++++++++++++++++++++--- arch/arm/boot/dts/wm8505.dtsi | 60 ++++++++++++++++++++++++++++++++---- arch/arm/boot/dts/wm8650.dtsi | 20 ++++++++++-- drivers/tty/serial/vt8500_serial.c | 34 +++++++++++--------- 4 files changed, 127 insertions(+), 27 deletions(-)
arch/arm/boot/dts/vt8500.dtsi +36 -4
@@ -45,6 +45,38 @@ compatible = "fixed-clock"; clock-frequency = <24000000>; }; + + clkuart0: uart0 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <1>; + }; + + clkuart1: uart1 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <2>; + }; + + clkuart2: uart2 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <3>; + }; + + clkuart3: uart3 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <4>; + }; }; };
@@ -83,28 +115,28 @@ compatible = "via,vt8500-uart"; reg = <0xd8200000 0x1040>; interrupts = <32>; - clocks = <&ref24>; + clocks = <&clkuart0>; }; uart@d82b0000 { compatible = "via,vt8500-uart"; reg = <0xd82b0000 0x1040>; interrupts = <33>; - clocks = <&ref24>; + clocks = <&clkuart1>; }; uart@d8210000 { compatible = "via,vt8500-uart"; reg = <0xd8210000 0x1040>; interrupts = <47>; - clocks = <&ref24>; + clocks = <&clkuart2>; }; uart@d82c0000 { compatible = "via,vt8500-uart"; reg = <0xd82c0000 0x1040>; interrupts = <50>; - clocks = <&ref24>; + clocks = <&clkuart3>; }; rtc@d8100000 {
arch/arm/boot/dts/wm8505.dtsi +54 -6
102 lines not on this page · raw message
arch/arm/boot/dts/wm8650.dtsi +18 -2
@@ -75,6 +75,22 @@ reg = <0x204>; }; + clkuart0: uart0 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <1>; + }; + + clkuart1: uart1 { + #clock-cells = <0>; + compatible = "via,vt8500-device-clock"; + clocks = <&ref24>; + enable-reg = <0x250>; + enable-bit = <2>; + }; + arm: arm { #clock-cells = <0>; compatible = "via,vt8500-device-clock";
@@ -128,14 +144,14 @@ compatible = "via,vt8500-uart"; reg = <0xd8200000 0x1040>; interrupts = <32>; - clocks = <&ref24>; + clocks = <&clkuart0>; }; uart@d82b0000 { compatible = "via,vt8500-uart"; reg = <0xd82b0000 0x1040>; interrupts = <33>; - clocks = <&ref24>; + clocks = <&clkuart1>; }; rtc@d8100000 {
drivers/tty/serial/vt8500_serial.c +19 -15
@@ -593,6 +593,23 @@ static int vt8500_serial_probe(struct platform_device *pdev)if (!vt8500_port)return -ENOMEM ; + vt8500_port->uart.membase =devm_request_and_ioremap (&pdev->dev, mmres); +if (!vt8500_port->uart.membase) +return -EADDRNOTAVAIL ; + + vt8500_port->clk =of_clk_get (pdev->dev.of_node,0 ); +if (IS_ERR (vt8500_port->clk)) { +dev_err (&pdev->dev,"failed to get clock\n" ); + ret = -EINVAL ; + goto err; + } + + ret =clk_prepare_enable (vt8500_port->clk); +if (ret) { +dev_err (&pdev->dev,"failed to enable clock\n" ); + goto err; + } + vt8500_port->uart.type =PORT_VT8500 ; vt8500_port->uart.iotype =UPIO_MEM ; vt8500_port->uart.mapbase = mmres->start;
@@ -602,25 +619,11 @@ static int vt8500_serial_probe(struct platform_device *pdev) vt8500_port->uart.line = port; vt8500_port->uart.dev = &pdev->dev; vt8500_port->uart.flags =UPF_IOREMAP |UPF_BOOT_AUTOCONF ; - - vt8500_port->clk =of_clk_get (pdev->dev.of_node,0 ); -if (vt8500_port->clk) { - vt8500_port->uart.uartclk =clk_get_rate (vt8500_port->clk); - }else { -/* use the default of 24Mhz if not specified and warn */ -pr_warn ("%s: serial clock source not specified\n" , __func__); - vt8500_port->uart.uartclk =24000000 ; - } + vt8500_port->uart.uartclk =clk_get_rate (vt8500_port->clk);snprintf (vt8500_port->name,sizeof (vt8500_port->name),"VT8500 UART%d" , pdev->id); - vt8500_port->uart.membase =devm_request_and_ioremap (&pdev->dev, mmres); -if (!vt8500_port->uart.membase) { - ret = -EADDRNOTAVAIL ; - goto err; - } - vt8500_uart_ports[port] = vt8500_port;uart_add_one_port (&vt8500_uart_driver, &vt8500_port->uart);
@@ -639,6 +642,7 @@ static int vt8500_serial_remove(struct platform_device *pdev)struct vt8500_port *vt8500_port =platform_get_drvdata (pdev);platform_set_drvdata (pdev,NULL ); +clk_disable_unprepare (vt8500_port->clk);uart_remove_one_port (&vt8500_uart_driver, &vt8500_port->uart);kfree (vt8500_port);
Signature · 1 line
1.7.9.5
PATCH v4 4/4 serial: tty: Cleanup code using devm_ function
In reply to Tony PriskConvert the last memory allocation (vt8500_port) to use devm_kzalloc and remove the fail path cleanup code from vt8500_serial_probe.
Reorder iomem mapping above clk_enable to simplify fail code. The clock is only enabled if all other resources are available.
--- drivers/tty/serial/vt8500_serial.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/tty/serial/vt8500_serial.c +4 -9
@@ -589,7 +589,8 @@ static int vt8500_serial_probe(struct platform_device *pdev)return -EBUSY ; } - vt8500_port =kzalloc (sizeof (struct vt8500_port ),GFP_KERNEL ); + vt8500_port =devm_kzalloc (&pdev->dev,sizeof (struct vt8500_port ), +GFP_KERNEL );if (!vt8500_port)return -ENOMEM ;
@@ -600,14 +601,13 @@ static int vt8500_serial_probe(struct platform_device *pdev) vt8500_port->clk =of_clk_get (pdev->dev.of_node,0 );if (IS_ERR (vt8500_port->clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); - ret = -EINVAL ; - goto err; +return -EINVAL ; } ret =clk_prepare_enable (vt8500_port->clk);if (ret) {dev_err (&pdev->dev,"failed to enable clock\n" ); - goto err; +return ret; } vt8500_port->uart.type =PORT_VT8500 ;
@@ -631,10 +631,6 @@ static int vt8500_serial_probe(struct platform_device *pdev)platform_set_drvdata (pdev, vt8500_port);return 0 ; - -err: -kfree (vt8500_port); -return ret; }static int vt8500_serial_remove (struct platform_device *pdev)
@@ -644,7 +640,6 @@ static int vt8500_serial_remove(struct platform_device *pdev)platform_set_drvdata (pdev,NULL );clk_disable_unprepare (vt8500_port->clk);uart_remove_one_port (&vt8500_uart_driver, &vt8500_port->uart); -kfree (vt8500_port);return 0 ; }
Signature · 1 line
1.7.9.5