Skip to content

Commit 0d410bd

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: mtk_hdmi: Improve mtk_hdmi_get_all_clk() flexibility
In preparation for splitting common bits of this driver and for introducing a new version of the MediaTek HDMI Encoder IP, improve the flexibility of function mtk_hdmi_get_all_clk() by adding a pointer to the clock names array and size of it to its parameters. Also change the array of struct clock pointers in the mtk_hdmi structure to be dynamically allocated, and allocate it in probe. Reviewed-by: CK Hu <ck.hu@mediatek.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com> Link: https://patchwork.kernel.org/project/linux-mediatek/patch/20251023-mediatek-drm-hdmi-v2-v11-2-7873ec4a1edf@collabora.com/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent 257dfd9 commit 0d410bd

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

drivers/gpu/drm/mediatek/mtk_hdmi.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct mtk_hdmi {
159159
struct phy *phy;
160160
struct device *cec_dev;
161161
struct i2c_adapter *ddc_adpt;
162-
struct clk *clk[MTK_HDMI_CLK_COUNT];
162+
struct clk **clk;
163163
struct drm_display_mode mode;
164164
bool dvi_mode;
165165
struct regmap *sys_regmap;
@@ -1072,17 +1072,18 @@ static const char * const mtk_hdmi_clk_names[MTK_HDMI_CLK_COUNT] = {
10721072
[MTK_HDMI_CLK_AUD_SPDIF] = "spdif",
10731073
};
10741074

1075-
static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi,
1076-
struct device_node *np)
1075+
static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi, struct device_node *np,
1076+
const char * const *clock_names, size_t num_clocks)
10771077
{
10781078
int i;
10791079

1080-
for (i = 0; i < ARRAY_SIZE(mtk_hdmi_clk_names); i++) {
1081-
hdmi->clk[i] = of_clk_get_by_name(np,
1082-
mtk_hdmi_clk_names[i]);
1080+
for (i = 0; i < num_clocks; i++) {
1081+
hdmi->clk[i] = of_clk_get_by_name(np, clock_names[i]);
1082+
10831083
if (IS_ERR(hdmi->clk[i]))
10841084
return PTR_ERR(hdmi->clk[i]);
10851085
}
1086+
10861087
return 0;
10871088
}
10881089

@@ -1391,15 +1392,15 @@ static int mtk_hdmi_get_cec_dev(struct mtk_hdmi *hdmi, struct device *dev, struc
13911392
return 0;
13921393
}
13931394

1394-
static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
1395-
struct platform_device *pdev)
1395+
static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev,
1396+
const char * const *clk_names, size_t num_clocks)
13961397
{
13971398
struct device *dev = &pdev->dev;
13981399
struct device_node *np = dev->of_node;
13991400
struct device_node *remote, *i2c_np;
14001401
int ret;
14011402

1402-
ret = mtk_hdmi_get_all_clk(hdmi, np);
1403+
ret = mtk_hdmi_get_all_clk(hdmi, np, clk_names, num_clocks);
14031404
if (ret)
14041405
return dev_err_probe(dev, ret, "Failed to get clocks\n");
14051406

@@ -1652,6 +1653,7 @@ static int mtk_hdmi_probe(struct platform_device *pdev)
16521653
{
16531654
struct mtk_hdmi *hdmi;
16541655
struct device *dev = &pdev->dev;
1656+
const int num_clocks = MTK_HDMI_CLK_COUNT;
16551657
int ret;
16561658

16571659
hdmi = devm_drm_bridge_alloc(dev, struct mtk_hdmi, bridge,
@@ -1662,7 +1664,11 @@ static int mtk_hdmi_probe(struct platform_device *pdev)
16621664
hdmi->dev = dev;
16631665
hdmi->conf = of_device_get_match_data(dev);
16641666

1665-
ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev);
1667+
hdmi->clk = devm_kcalloc(dev, num_clocks, sizeof(*hdmi->clk), GFP_KERNEL);
1668+
if (!hdmi->clk)
1669+
return -ENOMEM;
1670+
1671+
ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev, mtk_hdmi_clk_names, num_clocks);
16661672
if (ret)
16671673
return ret;
16681674

0 commit comments

Comments
 (0)