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

serial: stm32: Use of_device_get_match_data()

This driver casts away the constness of struct stm32_usart_info that is
pointed to by the of match table. Use of_device_get_match_data() instead
of of_match_device() here and push the const throughout the code so that
we don't cast away const. This nicely avoids referencing the match table
when it is undefined with configurations where CONFIG_OF=n and fixes the
const issues.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: <linux-serial@vger.kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20210123034428.2841052-4-swboyd@chromium.org

authored by

Stephen Boyd and committed by
Rob Herring
d825f0be 0e658fdd

+35 -38
+34 -37
drivers/tty/serial/stm32-usart.c
··· 99 99 struct serial_rs485 *rs485conf) 100 100 { 101 101 struct stm32_port *stm32_port = to_stm32_port(port); 102 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 103 - struct stm32_usart_config *cfg = &stm32_port->info->cfg; 102 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 103 + const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 104 104 u32 usartdiv, baud, cr1, cr3; 105 105 bool over8; 106 106 ··· 166 166 bool threaded) 167 167 { 168 168 struct stm32_port *stm32_port = to_stm32_port(port); 169 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 169 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 170 170 enum dma_status status; 171 171 struct dma_tx_state state; 172 172 ··· 191 191 int *last_res) 192 192 { 193 193 struct stm32_port *stm32_port = to_stm32_port(port); 194 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 194 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 195 195 unsigned long c; 196 196 197 197 if (stm32_port->rx_ch) { ··· 211 211 { 212 212 struct tty_port *tport = &port->state->port; 213 213 struct stm32_port *stm32_port = to_stm32_port(port); 214 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 214 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 215 215 unsigned long c; 216 216 u32 sr; 217 217 char flag; ··· 282 282 { 283 283 struct uart_port *port = arg; 284 284 struct stm32_port *stm32port = to_stm32_port(port); 285 - struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 285 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 286 286 287 287 stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); 288 288 stm32port->tx_dma_busy = false; ··· 294 294 static void stm32_tx_interrupt_enable(struct uart_port *port) 295 295 { 296 296 struct stm32_port *stm32_port = to_stm32_port(port); 297 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 297 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 298 298 299 299 /* 300 300 * Enables TX FIFO threashold irq when FIFO is enabled, ··· 309 309 static void stm32_tx_interrupt_disable(struct uart_port *port) 310 310 { 311 311 struct stm32_port *stm32_port = to_stm32_port(port); 312 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 312 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 313 313 314 314 if (stm32_port->fifoen) 315 315 stm32_clr_bits(port, ofs->cr3, USART_CR3_TXFTIE); ··· 320 320 static void stm32_transmit_chars_pio(struct uart_port *port) 321 321 { 322 322 struct stm32_port *stm32_port = to_stm32_port(port); 323 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 323 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 324 324 struct circ_buf *xmit = &port->state->xmit; 325 325 326 326 if (stm32_port->tx_dma_busy) { ··· 347 347 static void stm32_transmit_chars_dma(struct uart_port *port) 348 348 { 349 349 struct stm32_port *stm32port = to_stm32_port(port); 350 - struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 350 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 351 351 struct circ_buf *xmit = &port->state->xmit; 352 352 struct dma_async_tx_descriptor *desc = NULL; 353 353 unsigned int count, i; ··· 407 407 static void stm32_transmit_chars(struct uart_port *port) 408 408 { 409 409 struct stm32_port *stm32_port = to_stm32_port(port); 410 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 410 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 411 411 struct circ_buf *xmit = &port->state->xmit; 412 412 413 413 if (port->x_char) { ··· 447 447 { 448 448 struct uart_port *port = ptr; 449 449 struct stm32_port *stm32_port = to_stm32_port(port); 450 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 450 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 451 451 u32 sr; 452 452 453 453 spin_lock(&port->lock); ··· 494 494 static unsigned int stm32_tx_empty(struct uart_port *port) 495 495 { 496 496 struct stm32_port *stm32_port = to_stm32_port(port); 497 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 497 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 498 498 499 499 return readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE; 500 500 } ··· 502 502 static void stm32_set_mctrl(struct uart_port *port, unsigned int mctrl) 503 503 { 504 504 struct stm32_port *stm32_port = to_stm32_port(port); 505 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 505 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 506 506 507 507 if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) 508 508 stm32_set_bits(port, ofs->cr3, USART_CR3_RTSE); ··· 579 579 static void stm32_throttle(struct uart_port *port) 580 580 { 581 581 struct stm32_port *stm32_port = to_stm32_port(port); 582 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 582 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 583 583 unsigned long flags; 584 584 585 585 spin_lock_irqsave(&port->lock, flags); ··· 594 594 static void stm32_unthrottle(struct uart_port *port) 595 595 { 596 596 struct stm32_port *stm32_port = to_stm32_port(port); 597 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 597 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 598 598 unsigned long flags; 599 599 600 600 spin_lock_irqsave(&port->lock, flags); ··· 609 609 static void stm32_stop_rx(struct uart_port *port) 610 610 { 611 611 struct stm32_port *stm32_port = to_stm32_port(port); 612 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 612 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 613 613 614 614 stm32_clr_bits(port, ofs->cr1, stm32_port->cr1_irq); 615 615 if (stm32_port->cr3_irq) ··· 625 625 static int stm32_startup(struct uart_port *port) 626 626 { 627 627 struct stm32_port *stm32_port = to_stm32_port(port); 628 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 628 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 629 629 const char *name = to_platform_device(port->dev)->name; 630 630 u32 val; 631 631 int ret; ··· 661 661 static void stm32_shutdown(struct uart_port *port) 662 662 { 663 663 struct stm32_port *stm32_port = to_stm32_port(port); 664 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 665 - struct stm32_usart_config *cfg = &stm32_port->info->cfg; 664 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 665 + const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 666 666 u32 val, isr; 667 667 int ret; 668 668 ··· 721 721 struct ktermios *old) 722 722 { 723 723 struct stm32_port *stm32_port = to_stm32_port(port); 724 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 725 - struct stm32_usart_config *cfg = &stm32_port->info->cfg; 724 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 725 + const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 726 726 struct serial_rs485 *rs485conf = &port->rs485; 727 727 unsigned int baud, bits; 728 728 u32 usartdiv, mantissa, fraction, oversampling; ··· 921 921 { 922 922 struct stm32_port *stm32port = container_of(port, 923 923 struct stm32_port, port); 924 - struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 925 - struct stm32_usart_config *cfg = &stm32port->info->cfg; 924 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 925 + const struct stm32_usart_config *cfg = &stm32port->info->cfg; 926 926 unsigned long flags = 0; 927 927 928 928 switch (state) { ··· 1081 1081 static int stm32_of_dma_rx_probe(struct stm32_port *stm32port, 1082 1082 struct platform_device *pdev) 1083 1083 { 1084 - struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 1084 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 1085 1085 struct uart_port *port = &stm32port->port; 1086 1086 struct device *dev = &pdev->dev; 1087 1087 struct dma_slave_config config; ··· 1152 1152 static int stm32_of_dma_tx_probe(struct stm32_port *stm32port, 1153 1153 struct platform_device *pdev) 1154 1154 { 1155 - struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 1155 + const struct stm32_usart_offsets *ofs = &stm32port->info->ofs; 1156 1156 struct uart_port *port = &stm32port->port; 1157 1157 struct device *dev = &pdev->dev; 1158 1158 struct dma_slave_config config; ··· 1202 1202 1203 1203 static int stm32_serial_probe(struct platform_device *pdev) 1204 1204 { 1205 - const struct of_device_id *match; 1206 1205 struct stm32_port *stm32port; 1207 1206 int ret; 1208 1207 ··· 1209 1210 if (!stm32port) 1210 1211 return -ENODEV; 1211 1212 1212 - match = of_match_device(stm32_match, &pdev->dev); 1213 - if (match && match->data) 1214 - stm32port->info = (struct stm32_usart_info *)match->data; 1215 - else 1213 + stm32port->info = of_device_get_match_data(&pdev->dev); 1214 + if (!stm32port->info) 1216 1215 return -EINVAL; 1217 1216 1218 1217 ret = stm32_init_port(stm32port, pdev); ··· 1269 1272 { 1270 1273 struct uart_port *port = platform_get_drvdata(pdev); 1271 1274 struct stm32_port *stm32_port = to_stm32_port(port); 1272 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1275 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1273 1276 int err; 1274 1277 1275 1278 pm_runtime_get_sync(&pdev->dev); ··· 1314 1317 static void stm32_console_putchar(struct uart_port *port, int ch) 1315 1318 { 1316 1319 struct stm32_port *stm32_port = to_stm32_port(port); 1317 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1320 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1318 1321 1319 1322 while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) 1320 1323 cpu_relax(); ··· 1326 1329 { 1327 1330 struct uart_port *port = &stm32_ports[co->index].port; 1328 1331 struct stm32_port *stm32_port = to_stm32_port(port); 1329 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1330 - struct stm32_usart_config *cfg = &stm32_port->info->cfg; 1332 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1333 + const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 1331 1334 unsigned long flags; 1332 1335 u32 old_cr1, new_cr1; 1333 1336 int locked = 1; ··· 1413 1416 bool enable) 1414 1417 { 1415 1418 struct stm32_port *stm32_port = to_stm32_port(port); 1416 - struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1417 - struct stm32_usart_config *cfg = &stm32_port->info->cfg; 1419 + const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 1420 + const struct stm32_usart_config *cfg = &stm32_port->info->cfg; 1418 1421 u32 val; 1419 1422 1420 1423 if (stm32_port->wakeirq <= 0)
+1 -1
drivers/tty/serial/stm32-usart.h
··· 259 259 struct stm32_port { 260 260 struct uart_port port; 261 261 struct clk *clk; 262 - struct stm32_usart_info *info; 262 + const struct stm32_usart_info *info; 263 263 struct dma_chan *rx_ch; /* dma rx channel */ 264 264 dma_addr_t rx_dma_buf; /* dma rx buffer bus address */ 265 265 unsigned char *rx_buf; /* dma rx buffer cpu address */