Message ID | 20250205093108.2027894-1-claudiu.beznea.uj@bp.renesas.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | [v5] serial: sh-sci: Update the suspend/resume support | expand |
Hi Claudiu, On Wed, 5 Feb 2025 at 10:31, Claudiu <claudiu.beznea@tuxon.dev> wrote: > From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> > > The Renesas RZ/G3S supports a power saving mode where power to most of the > SoC components is turned off. When returning from this power saving mode, > SoC components need to be re-configured. > > The SCIFs on the Renesas RZ/G3S need to be re-configured as well when > returning from this power saving mode. The sh-sci code already configures > the SCIF clocks, power domain and registers by calling uart_resume_port() > in sci_resume(). On suspend path the SCIF UART ports are suspended > accordingly (by calling uart_suspend_port() in sci_suspend()). The only > missing setting is the reset signal. For this assert/de-assert the reset > signal on driver suspend/resume. > > In case the no_console_suspend is specified by the user, the registers need > to be saved on suspend path and restore on resume path. To do this the > sci_console_save_restore() function was added. There is no need to > cache/restore the status or FIFO registers. Only the control registers. > The registers that will be saved/restored on suspend/resume are > specified by the struct sci_suspend_regs data structure. > > Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> > --- > > The v4 of this patch was part of a series with 4 patches. As the rest of > the patches were applied I dropped the cover letter. The v4 cover letter > is located here: > https://lore.kernel.org/all/20250120130936.1080069-1-claudiu.beznea.uj@bp.renesas.com > > Changes in v5: > - fixed typo in patch description > - adjusted the patch description to reflect the new patch content > - added struct sci_suspend_regs and dropped the suspend_cacheable > flag introduced previously in struct plat_sci_reg; along with it > the updates in sci_port_params[] were also dropped; > also, the function (now sci_console_save_restore()) that saves > and restores the registers content was adjusted accordingly > - s/sci_console_setup/sci_console_save_restore/g Thanks for the update! > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -3546,13 +3559,41 @@ static int sci_probe(struct platform_device *dev) > return 0; > } > > +static void sci_console_save_restore(struct sci_port *s, bool save) > +{ > + struct sci_suspend_regs *regs = &s->suspend_regs; > + struct uart_port *port = &s->port; > + > + if (save) { > + regs->scsmr = sci_serial_in(port, SCSMR); > + regs->scscr = sci_serial_in(port, SCSCR); > + regs->scfcr = sci_serial_in(port, SCFCR); > + regs->scsptr = sci_serial_in(port, SCSPTR); > + regs->scbrr = sci_serial_in(port, SCBRR); > + regs->semr = sci_serial_in(port, SEMR); The SCFCR, SCSPTR, and SEMR registers do not exist on all variants. Hence you should call sci_getreg() and check if plat_sci_reg.size is non-zero first, else you will trigger the WARN() in sci_serial_in(). > + } else { > + sci_serial_out(port, SCSMR, regs->scsmr); > + sci_serial_out(port, SCSCR, regs->scscr); > + sci_serial_out(port, SCFCR, regs->scfcr); > + sci_serial_out(port, SCSPTR, regs->scsptr); > + sci_serial_out(port, SCBRR, regs->scbrr); > + sci_serial_out(port, SEMR, regs->semr); Likewise for sci_serial_out(). > + } > +} Given there's nothing really shared anymore, I would split this in separate sci_console_save() and sci_console_restore() functions. The rest LGTM. Gr{oetje,eeting}s, Geert
Hi Claudiu, On Thu, 6 Feb 2025 at 13:47, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > On Wed, 5 Feb 2025 at 10:31, Claudiu <claudiu.beznea@tuxon.dev> wrote: > > @@ -3546,13 +3559,41 @@ static int sci_probe(struct platform_device *dev) > > return 0; > > } > > > > +static void sci_console_save_restore(struct sci_port *s, bool save) > > +{ > > + struct sci_suspend_regs *regs = &s->suspend_regs; > > + struct uart_port *port = &s->port; > > + > > + if (save) { > > + regs->scsmr = sci_serial_in(port, SCSMR); > > + regs->scscr = sci_serial_in(port, SCSCR); > > + regs->scfcr = sci_serial_in(port, SCFCR); > > + regs->scsptr = sci_serial_in(port, SCSPTR); > > + regs->scbrr = sci_serial_in(port, SCBRR); > > + regs->semr = sci_serial_in(port, SEMR); > > The SCFCR, SCSPTR, and SEMR registers do not exist on all > variants. Hence you should call sci_getreg() and check if > plat_sci_reg.size is non-zero first, else you will trigger the WARN() > in sci_serial_in(). As expected, the WARN() is triggered on any R-Car platform during system suspend. Gr{oetje,eeting}s, Geert
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index b1ea48f38248..03349bc31080 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -104,6 +104,15 @@ struct plat_sci_reg { u8 offset, size; }; +struct sci_suspend_regs { + u16 scsmr; + u16 scscr; + u16 scfcr; + u16 scsptr; + u8 scbrr; + u8 semr; +}; + struct sci_port_params { const struct plat_sci_reg regs[SCIx_NR_REGS]; unsigned int fifosize; @@ -134,6 +143,8 @@ struct sci_port { struct dma_chan *chan_tx; struct dma_chan *chan_rx; + struct reset_control *rstc; + #ifdef CONFIG_SERIAL_SH_SCI_DMA struct dma_chan *chan_tx_saved; struct dma_chan *chan_rx_saved; @@ -153,6 +164,7 @@ struct sci_port { int rx_trigger; struct timer_list rx_fifo_timer; int rx_fifo_timeout; + struct sci_suspend_regs suspend_regs; u16 hscif_tot; bool has_rtscts; @@ -3374,6 +3386,7 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev, } sp = &sci_ports[id]; + sp->rstc = rstc; *dev_id = id; p->type = SCI_OF_TYPE(data); @@ -3546,13 +3559,41 @@ static int sci_probe(struct platform_device *dev) return 0; } +static void sci_console_save_restore(struct sci_port *s, bool save) +{ + struct sci_suspend_regs *regs = &s->suspend_regs; + struct uart_port *port = &s->port; + + if (save) { + regs->scsmr = sci_serial_in(port, SCSMR); + regs->scscr = sci_serial_in(port, SCSCR); + regs->scfcr = sci_serial_in(port, SCFCR); + regs->scsptr = sci_serial_in(port, SCSPTR); + regs->scbrr = sci_serial_in(port, SCBRR); + regs->semr = sci_serial_in(port, SEMR); + } else { + sci_serial_out(port, SCSMR, regs->scsmr); + sci_serial_out(port, SCSCR, regs->scscr); + sci_serial_out(port, SCFCR, regs->scfcr); + sci_serial_out(port, SCSPTR, regs->scsptr); + sci_serial_out(port, SCBRR, regs->scbrr); + sci_serial_out(port, SEMR, regs->semr); + } +} + static __maybe_unused int sci_suspend(struct device *dev) { struct sci_port *sport = dev_get_drvdata(dev); - if (sport) + if (sport) { uart_suspend_port(&sci_uart_driver, &sport->port); + if (!console_suspend_enabled && uart_console(&sport->port)) + sci_console_save_restore(sport, true); + else + return reset_control_assert(sport->rstc); + } + return 0; } @@ -3560,8 +3601,18 @@ static __maybe_unused int sci_resume(struct device *dev) { struct sci_port *sport = dev_get_drvdata(dev); - if (sport) + if (sport) { + if (!console_suspend_enabled && uart_console(&sport->port)) { + sci_console_save_restore(sport, false); + } else { + int ret = reset_control_deassert(sport->rstc); + + if (ret) + return ret; + } + uart_resume_port(&sci_uart_driver, &sport->port); + } return 0; }