git: 2a6580e15b62 - main - mmccam: Add a helper to change the host settings

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 30 Oct 2026 07:35:54 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=2a6580e15b62da11dbe728c6c4f512c15283cd49

commit 2a6580e15b62da11dbe728c6c4f512c15283cd49
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-20 17:41:01 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-10-30 07:35:35 +0000

    mmccam: Add a helper to change the host settings
    
    The same five lines to build and send an XPT_SET_TRAN_SETTINGS request to the
    controller were repeated for the bus timing, bus width, VCCQ and clock
    changes.  Add sdda_set_host_ios() and use it at those places.
    
    No functional change.
    
    Reviewed by:    bz
    Differential Revision:  https://reviews.freebsd.org/D60921
---
 sys/cam/mmc/mmc_da.c | 58 ++++++++++++++++++++--------------------------------
 1 file changed, 22 insertions(+), 36 deletions(-)

diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c
index 3a5a7eedb4a1..aa7d876d067e 100644
--- a/sys/cam/mmc/mmc_da.c
+++ b/sys/cam/mmc/mmc_da.c
@@ -1030,6 +1030,22 @@ mmc_sd_switch(struct cam_periph *periph, union ccb *ccb,
 	return (err);
 }
 
+/*
+ * Send the host settings of the ccb (ios, with ios_valid telling which ones
+ * to change) to the controller.
+ */
+static void
+sdda_set_host_ios(union ccb *ccb)
+{
+
+	ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
+	ccb->ccb_h.flags = CAM_DIR_NONE;
+	ccb->ccb_h.retry_count = 0;
+	ccb->ccb_h.timeout = 100;
+	ccb->ccb_h.cbfcnp = NULL;
+	xpt_action(ccb);
+}
+
 static int
 mmc_set_timing(struct cam_periph *periph,
 	       union ccb *ccb,
@@ -1063,14 +1079,9 @@ mmc_set_timing(struct cam_periph *periph,
 	/* Set high-speed timing on the host */
 	struct ccb_trans_settings_mmc *cts;
 	cts = &ccb->cts.proto_specific.mmc;
-	ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-	ccb->ccb_h.flags = CAM_DIR_NONE;
-	ccb->ccb_h.retry_count = 0;
-	ccb->ccb_h.timeout = 100;
-	ccb->ccb_h.cbfcnp = NULL;
 	cts->ios.timing = timing;
 	cts->ios_valid = MMC_BT;
-	xpt_action(ccb);
+	sdda_set_host_ios(ccb);
 
 	return (err);
 }
@@ -1139,14 +1150,9 @@ sdda_set_bus_width(struct cam_periph *periph, union ccb *ccb, int width)
 	/* Now card is done, set the host to the same width */
 	struct ccb_trans_settings_mmc *cts;
 	cts = &ccb->cts.proto_specific.mmc;
-	ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-	ccb->ccb_h.flags = CAM_DIR_NONE;
-	ccb->ccb_h.retry_count = 0;
-	ccb->ccb_h.timeout = 100;
-	ccb->ccb_h.cbfcnp = NULL;
 	cts->ios.bus_width = width;
 	cts->ios_valid = MMC_BW;
-	xpt_action(ccb);
+	sdda_set_host_ios(ccb);
 }
 
 static inline const char
@@ -1393,49 +1399,29 @@ finish_hs_tests:
 	for (timing = bus_timing_mmc_ddr52; timing > bus_timing_normal; timing--) {
 		if (isset(&softc->vccq_120, timing)) {
 			/* Set VCCQ = 1.2V */
-			start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-			start_ccb->ccb_h.flags = CAM_DIR_NONE;
-			start_ccb->ccb_h.retry_count = 0;
-			start_ccb->ccb_h.timeout = 100;
-			start_ccb->ccb_h.cbfcnp = NULL;
 			cts->ios.vccq = vccq_120;
 			cts->ios_valid = MMC_VCCQ;
-			xpt_action(start_ccb);
+			sdda_set_host_ios(start_ccb);
 			break;
 		} else if (isset(&softc->vccq_180, timing)) {
 			/* Set VCCQ = 1.8V */
-			start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-			start_ccb->ccb_h.flags = CAM_DIR_NONE;
-			start_ccb->ccb_h.retry_count = 0;
-			start_ccb->ccb_h.timeout = 100;
-			start_ccb->ccb_h.cbfcnp = NULL;
 			cts->ios.vccq = vccq_180;
 			cts->ios_valid = MMC_VCCQ;
-			xpt_action(start_ccb);
+			sdda_set_host_ios(start_ccb);
 			break;
 		} else {
 			/* Set VCCQ = 3.3V */
-			start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-			start_ccb->ccb_h.flags = CAM_DIR_NONE;
-			start_ccb->ccb_h.retry_count = 0;
-			start_ccb->ccb_h.timeout = 100;
-			start_ccb->ccb_h.cbfcnp = NULL;
 			cts->ios.vccq = vccq_330;
 			cts->ios_valid = MMC_VCCQ;
-			xpt_action(start_ccb);
+			sdda_set_host_ios(start_ccb);
 			break;
 		}
 	}
 
 	/* Set frequency on the controller */
-	start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
-	start_ccb->ccb_h.flags = CAM_DIR_NONE;
-	start_ccb->ccb_h.retry_count = 0;
-	start_ccb->ccb_h.timeout = 100;
-	start_ccb->ccb_h.cbfcnp = NULL;
 	cts->ios.clock = f_max;
 	cts->ios_valid = MMC_CLK;
-	xpt_action(start_ccb);
+	sdda_set_host_ios(start_ccb);
 
 	/* Set bus width */
 	enum mmc_bus_width desired_bus_width = bus_width_1;