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

Configure Feed

Select the types of activity you want to include in your feed.

i3c: mipi-i3c-hci: Factor out IO mode setting into helper

Prepare for future reuse. Move the IO mode setting logic from
i3c_hci_init() into a dedicated helper function, i3c_hci_set_io_mode().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260113072702.16268-16-adrian.hunter@intel.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Adrian Hunter and committed by
Alexandre Belloni
e4269df5 57a2f976

+31 -14
+31 -14
drivers/i3c/master/mipi-i3c-hci/core.c
··· 613 613 return 0; 614 614 } 615 615 616 + static inline bool is_version_1_1_or_newer(struct i3c_hci *hci) 617 + { 618 + return hci->version_major > 1 || (hci->version_major == 1 && hci->version_minor > 0); 619 + } 620 + 621 + static int i3c_hci_set_io_mode(struct i3c_hci *hci, bool dma) 622 + { 623 + bool pio_mode; 624 + 625 + if (dma) 626 + reg_clear(HC_CONTROL, HC_CONTROL_PIO_MODE); 627 + else 628 + reg_set(HC_CONTROL, HC_CONTROL_PIO_MODE); 629 + 630 + if (!is_version_1_1_or_newer(hci)) 631 + return 0; 632 + 633 + pio_mode = reg_read(HC_CONTROL) & HC_CONTROL_PIO_MODE; 634 + if ((dma && pio_mode) || (!dma && !pio_mode)) { 635 + dev_err(&hci->master.dev, "%s mode is stuck\n", pio_mode ? "PIO" : "DMA"); 636 + return -EIO; 637 + } 638 + 639 + return 0; 640 + } 641 + 616 642 static int i3c_hci_init(struct i3c_hci *hci) 617 643 { 618 - bool size_in_dwords, mode_selector; 644 + bool size_in_dwords; 619 645 u32 regval, offset; 620 646 int ret; 621 647 ··· 758 732 return -EINVAL; 759 733 } 760 734 761 - mode_selector = hci->version_major > 1 || 762 - (hci->version_major == 1 && hci->version_minor > 0); 763 - 764 735 /* Quirk for HCI_QUIRK_PIO_MODE on AMD platforms */ 765 736 if (hci->quirks & HCI_QUIRK_PIO_MODE) 766 737 hci->RHS_regs = NULL; 767 738 768 739 /* Try activating DMA operations first */ 769 740 if (hci->RHS_regs) { 770 - reg_clear(HC_CONTROL, HC_CONTROL_PIO_MODE); 771 - if (mode_selector && (reg_read(HC_CONTROL) & HC_CONTROL_PIO_MODE)) { 772 - dev_err(&hci->master.dev, "PIO mode is stuck\n"); 773 - ret = -EIO; 774 - } else { 741 + ret = i3c_hci_set_io_mode(hci, true); 742 + if (!ret) { 775 743 hci->io = &mipi_i3c_hci_dma; 776 744 dev_dbg(&hci->master.dev, "Using DMA\n"); 777 745 } ··· 773 753 774 754 /* If no DMA, try PIO */ 775 755 if (!hci->io && hci->PIO_regs) { 776 - reg_set(HC_CONTROL, HC_CONTROL_PIO_MODE); 777 - if (mode_selector && !(reg_read(HC_CONTROL) & HC_CONTROL_PIO_MODE)) { 778 - dev_err(&hci->master.dev, "DMA mode is stuck\n"); 779 - ret = -EIO; 780 - } else { 756 + ret = i3c_hci_set_io_mode(hci, false); 757 + if (!ret) { 781 758 hci->io = &mipi_i3c_hci_pio; 782 759 dev_dbg(&hci->master.dev, "Using PIO\n"); 783 760 }