Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: stm32: add pm_runtime support

Use pm_runtime for clock management.

Signed-off-by: Bich Hemon <bich.hemon@st.com>
Signed-off-by: Erwan Le Ray <erwan.leray@st.com>

Link: https://lore.kernel.org/r/1560433800-12255-5-git-send-email-erwan.leray@st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Erwan Le Ray and committed by
Greg Kroah-Hartman
fb6dcef6 94616d9a

+38 -3
+38 -3
drivers/tty/serial/stm32-usart.c
··· 882 882 883 883 switch (state) { 884 884 case UART_PM_STATE_ON: 885 - clk_prepare_enable(stm32port->clk); 885 + pm_runtime_get_sync(port->dev); 886 886 break; 887 887 case UART_PM_STATE_OFF: 888 888 spin_lock_irqsave(&port->lock, flags); 889 889 stm32_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); 890 890 spin_unlock_irqrestore(&port->lock, flags); 891 - clk_disable_unprepare(stm32port->clk); 891 + pm_runtime_put_sync(port->dev); 892 892 break; 893 893 } 894 894 } ··· 1186 1186 1187 1187 platform_set_drvdata(pdev, &stm32port->port); 1188 1188 1189 + pm_runtime_get_noresume(&pdev->dev); 1190 + pm_runtime_set_active(&pdev->dev); 1191 + pm_runtime_enable(&pdev->dev); 1192 + pm_runtime_put_sync(&pdev->dev); 1193 + 1189 1194 return 0; 1190 1195 1191 1196 err_wirq: ··· 1212 1207 struct uart_port *port = platform_get_drvdata(pdev); 1213 1208 struct stm32_port *stm32_port = to_stm32_port(port); 1214 1209 struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1210 + int err; 1211 + 1212 + pm_runtime_get_sync(&pdev->dev); 1215 1213 1216 1214 stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAR); 1217 1215 ··· 1243 1235 1244 1236 clk_disable_unprepare(stm32_port->clk); 1245 1237 1246 - return uart_remove_one_port(&stm32_usart_driver, port); 1238 + err = uart_remove_one_port(&stm32_usart_driver, port); 1239 + 1240 + pm_runtime_disable(&pdev->dev); 1241 + pm_runtime_put_noidle(&pdev->dev); 1242 + 1243 + return err; 1247 1244 } 1248 1245 1249 1246 ··· 1405 1392 } 1406 1393 #endif /* CONFIG_PM_SLEEP */ 1407 1394 1395 + static int __maybe_unused stm32_serial_runtime_suspend(struct device *dev) 1396 + { 1397 + struct uart_port *port = dev_get_drvdata(dev); 1398 + struct stm32_port *stm32port = container_of(port, 1399 + struct stm32_port, port); 1400 + 1401 + clk_disable_unprepare(stm32port->clk); 1402 + 1403 + return 0; 1404 + } 1405 + 1406 + static int __maybe_unused stm32_serial_runtime_resume(struct device *dev) 1407 + { 1408 + struct uart_port *port = dev_get_drvdata(dev); 1409 + struct stm32_port *stm32port = container_of(port, 1410 + struct stm32_port, port); 1411 + 1412 + return clk_prepare_enable(stm32port->clk); 1413 + } 1414 + 1408 1415 static const struct dev_pm_ops stm32_serial_pm_ops = { 1416 + SET_RUNTIME_PM_OPS(stm32_serial_runtime_suspend, 1417 + stm32_serial_runtime_resume, NULL) 1409 1418 SET_SYSTEM_SLEEP_PM_OPS(stm32_serial_suspend, stm32_serial_resume) 1410 1419 }; 1411 1420