162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Helper methods for MSM-specific DSC calculations that are common between timing engine,
662306a36Sopenharmony_ci * DSI, and DP.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef MSM_DSC_HELPER_H_
1062306a36Sopenharmony_ci#define MSM_DSC_HELPER_H_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/math.h>
1362306a36Sopenharmony_ci#include <drm/display/drm_dsc_helper.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/**
1662306a36Sopenharmony_ci * msm_dsc_get_slices_per_intf() - calculate number of slices per interface
1762306a36Sopenharmony_ci * @dsc: Pointer to drm dsc config struct
1862306a36Sopenharmony_ci * @intf_width: interface width in pixels
1962306a36Sopenharmony_ci * Returns: Integer representing the number of slices for the given interface
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_cistatic inline u32 msm_dsc_get_slices_per_intf(const struct drm_dsc_config *dsc, u32 intf_width)
2262306a36Sopenharmony_ci{
2362306a36Sopenharmony_ci	return DIV_ROUND_UP(intf_width, dsc->slice_width);
2462306a36Sopenharmony_ci}
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/**
2762306a36Sopenharmony_ci * msm_dsc_get_bytes_per_line() - calculate bytes per line
2862306a36Sopenharmony_ci * @dsc: Pointer to drm dsc config struct
2962306a36Sopenharmony_ci * Returns: Integer value representing bytes per line. DSI and DP need
3062306a36Sopenharmony_ci *          to perform further calculations to turn this into pclk_per_intf,
3162306a36Sopenharmony_ci *          such as dividing by different values depending on if widebus is enabled.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistatic inline u32 msm_dsc_get_bytes_per_line(const struct drm_dsc_config *dsc)
3462306a36Sopenharmony_ci{
3562306a36Sopenharmony_ci	return dsc->slice_count * dsc->slice_chunk_size;
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#endif /* MSM_DSC_HELPER_H_ */
39