diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 8453c8668542..081866aa68ab 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -964,6 +964,7 @@ V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bit
 
 	constexpr float penaltyAr = 1500.0;
 	constexpr float penaltyBitDepth = 500.0;
+	constexpr float penaltyNonGeneric = 1.0;
 
 	/* Calculate the closest/best mode from the user requested size. */
 	for (const auto &[mbusCode, sizes] : sensorFormats_) {
@@ -987,14 +988,19 @@ V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bit
 			/* Add any penalties... this is not an exact science! */
 			score += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth;
 
+			/* Break ties when sensor advertises both legacy and generic codes */
+			if (MediaBusFormatInfo::info(mbusCode).genericRaw == false)
+				score += penaltyNonGeneric;
+
 			if (score <= bestScore) {
 				bestScore = score;
 				bestFormat.code = mbusCode;
 				bestFormat.size = size;
 			}
 
-			LOG(RPI, Debug) << "Format: " << size
-					<< " fmt " << *format
+			LOG(RPI, Debug) << "Format: " << *format
+					<< "_" << utils::hex(mbusCode, 4)
+					<< "_" << size
 					<< " Score: " << score
 					<< " (best " << bestScore << ")";
 		}
