Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * Copyright (c) 2014 MediaTek Inc. |
| 4 | * Author: James Liao <jamesjj.liao@mediatek.com> |
| 5 | */ |
| 6 | |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 7 | #include <linux/delay.h> |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 8 | #include <linux/device.h> |
Yongqiang Niu | 51c0e61 | 2020-10-06 21:33:17 +0200 | [diff] [blame] | 9 | #include <linux/io.h> |
Yongqiang Niu | a7596e6 | 2022-11-18 14:30:18 +0800 | [diff] [blame] | 10 | #include <linux/module.h> |
Rob Herring | d01e0ae | 2023-08-03 16:42:59 -0600 | [diff] [blame] | 11 | #include <linux/of.h> |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 13 | #include <linux/reset-controller.h> |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 14 | #include <linux/soc/mediatek/mtk-mmsys.h> |
| 15 | |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 16 | #include "mtk-mmsys.h" |
Fabien Parent | 060f787 | 2021-04-05 22:03:53 +0200 | [diff] [blame] | 17 | #include "mt8167-mmsys.h" |
AngeloGioacchino Del Regno | 2a0a8d8 | 2023-03-09 11:26:16 +0100 | [diff] [blame] | 18 | #include "mt8173-mmsys.h" |
Hsin-Yi Wang | 1ff1270 | 2021-03-30 19:04:23 +0800 | [diff] [blame] | 19 | #include "mt8183-mmsys.h" |
Yongqiang Niu | 5f9b5b7 | 2022-02-22 13:28:01 +0800 | [diff] [blame] | 20 | #include "mt8186-mmsys.h" |
Nathan Lu | 3b1a57c | 2022-12-06 10:00:44 +0800 | [diff] [blame] | 21 | #include "mt8188-mmsys.h" |
Yongqiang Niu | d687e05 | 2021-08-02 16:59:33 +0800 | [diff] [blame] | 22 | #include "mt8192-mmsys.h" |
Jason-JH.Lin | b2b99a7 | 2022-09-27 23:27:01 +0800 | [diff] [blame] | 23 | #include "mt8195-mmsys.h" |
Fabien Parent | bc3fc5c | 2021-05-19 18:18:46 +0200 | [diff] [blame] | 24 | #include "mt8365-mmsys.h" |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 25 | |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 26 | #define MMSYS_SW_RESET_PER_REG 32 |
| 27 | |
Enric Balletbo i Serra | c292b13 | 2020-04-01 22:17:35 +0200 | [diff] [blame] | 28 | static const struct mtk_mmsys_driver_data mt2701_mmsys_driver_data = { |
| 29 | .clk_driver = "clk-mt2701-mm", |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 30 | .routes = mmsys_default_routing_table, |
| 31 | .num_routes = ARRAY_SIZE(mmsys_default_routing_table), |
Enric Balletbo i Serra | c292b13 | 2020-04-01 22:17:35 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
Enric Balletbo i Serra | 9c5a0a3 | 2020-04-01 22:17:34 +0200 | [diff] [blame] | 34 | static const struct mtk_mmsys_driver_data mt2712_mmsys_driver_data = { |
| 35 | .clk_driver = "clk-mt2712-mm", |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 36 | .routes = mmsys_default_routing_table, |
| 37 | .num_routes = ARRAY_SIZE(mmsys_default_routing_table), |
Enric Balletbo i Serra | 9c5a0a3 | 2020-04-01 22:17:34 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
Matthias Brugger | 32956dd | 2020-05-18 13:31:55 +0200 | [diff] [blame] | 40 | static const struct mtk_mmsys_driver_data mt6779_mmsys_driver_data = { |
| 41 | .clk_driver = "clk-mt6779-mm", |
| 42 | }; |
| 43 | |
AngeloGioacchino Del Regno | e9a6f5b | 2023-03-09 11:26:18 +0100 | [diff] [blame] | 44 | static const struct mtk_mmsys_driver_data mt6795_mmsys_driver_data = { |
| 45 | .clk_driver = "clk-mt6795-mm", |
| 46 | .routes = mt8173_mmsys_routing_table, |
| 47 | .num_routes = ARRAY_SIZE(mt8173_mmsys_routing_table), |
| 48 | .sw0_rst_offset = MT8183_MMSYS_SW0_RST_B, |
| 49 | .num_resets = 64, |
| 50 | }; |
| 51 | |
Matthias Brugger | cad4e37 | 2020-05-18 13:31:54 +0200 | [diff] [blame] | 52 | static const struct mtk_mmsys_driver_data mt6797_mmsys_driver_data = { |
| 53 | .clk_driver = "clk-mt6797-mm", |
| 54 | }; |
| 55 | |
Fabien Parent | 060f787 | 2021-04-05 22:03:53 +0200 | [diff] [blame] | 56 | static const struct mtk_mmsys_driver_data mt8167_mmsys_driver_data = { |
| 57 | .clk_driver = "clk-mt8167-mm", |
| 58 | .routes = mt8167_mmsys_routing_table, |
| 59 | .num_routes = ARRAY_SIZE(mt8167_mmsys_routing_table), |
| 60 | }; |
| 61 | |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 62 | static const struct mtk_mmsys_driver_data mt8173_mmsys_driver_data = { |
| 63 | .clk_driver = "clk-mt8173-mm", |
AngeloGioacchino Del Regno | 2a0a8d8 | 2023-03-09 11:26:16 +0100 | [diff] [blame] | 64 | .routes = mt8173_mmsys_routing_table, |
| 65 | .num_routes = ARRAY_SIZE(mt8173_mmsys_routing_table), |
Rex-BC Chen | 62dc301 | 2022-02-17 16:26:25 +0800 | [diff] [blame] | 66 | .sw0_rst_offset = MT8183_MMSYS_SW0_RST_B, |
AngeloGioacchino Del Regno | b427d85 | 2023-03-09 11:26:17 +0100 | [diff] [blame] | 67 | .num_resets = 64, |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
Matthias Brugger | 1f9adbc | 2020-05-18 13:31:53 +0200 | [diff] [blame] | 70 | static const struct mtk_mmsys_driver_data mt8183_mmsys_driver_data = { |
| 71 | .clk_driver = "clk-mt8183-mm", |
Hsin-Yi Wang | 1ff1270 | 2021-03-30 19:04:23 +0800 | [diff] [blame] | 72 | .routes = mmsys_mt8183_routing_table, |
| 73 | .num_routes = ARRAY_SIZE(mmsys_mt8183_routing_table), |
Rex-BC Chen | 62dc301 | 2022-02-17 16:26:25 +0800 | [diff] [blame] | 74 | .sw0_rst_offset = MT8183_MMSYS_SW0_RST_B, |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 75 | .num_resets = 32, |
Matthias Brugger | 1f9adbc | 2020-05-18 13:31:53 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Yongqiang Niu | 5f9b5b7 | 2022-02-22 13:28:01 +0800 | [diff] [blame] | 78 | static const struct mtk_mmsys_driver_data mt8186_mmsys_driver_data = { |
| 79 | .clk_driver = "clk-mt8186-mm", |
| 80 | .routes = mmsys_mt8186_routing_table, |
| 81 | .num_routes = ARRAY_SIZE(mmsys_mt8186_routing_table), |
Rex-BC Chen | 831785f | 2022-02-17 16:26:26 +0800 | [diff] [blame] | 82 | .sw0_rst_offset = MT8186_MMSYS_SW0_RST_B, |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 83 | .num_resets = 32, |
Yongqiang Niu | 5f9b5b7 | 2022-02-22 13:28:01 +0800 | [diff] [blame] | 84 | }; |
| 85 | |
Nathan Lu | 3b1a57c | 2022-12-06 10:00:44 +0800 | [diff] [blame] | 86 | static const struct mtk_mmsys_driver_data mt8188_vdosys0_driver_data = { |
| 87 | .clk_driver = "clk-mt8188-vdo0", |
| 88 | .routes = mmsys_mt8188_routing_table, |
| 89 | .num_routes = ARRAY_SIZE(mmsys_mt8188_routing_table), |
Hsiao Chien Sung | 27222a7 | 2023-10-24 21:00:35 +0800 | [diff] [blame] | 90 | .sw0_rst_offset = MT8188_VDO0_SW0_RST_B, |
| 91 | .rst_tb = mmsys_mt8188_vdo0_rst_tb, |
| 92 | .num_resets = ARRAY_SIZE(mmsys_mt8188_vdo0_rst_tb), |
Nathan Lu | 3b1a57c | 2022-12-06 10:00:44 +0800 | [diff] [blame] | 93 | }; |
| 94 | |
Hsiao Chien Sung | c034931 | 2023-10-24 21:00:32 +0800 | [diff] [blame] | 95 | static const struct mtk_mmsys_driver_data mt8188_vdosys1_driver_data = { |
| 96 | .clk_driver = "clk-mt8188-vdo1", |
| 97 | .routes = mmsys_mt8188_vdo1_routing_table, |
| 98 | .num_routes = ARRAY_SIZE(mmsys_mt8188_vdo1_routing_table), |
Hsiao Chien Sung | 27222a7 | 2023-10-24 21:00:35 +0800 | [diff] [blame] | 99 | .sw0_rst_offset = MT8188_VDO1_SW0_RST_B, |
| 100 | .rst_tb = mmsys_mt8188_vdo1_rst_tb, |
| 101 | .num_resets = ARRAY_SIZE(mmsys_mt8188_vdo1_rst_tb), |
Hsiao Chien Sung | c034931 | 2023-10-24 21:00:32 +0800 | [diff] [blame] | 102 | .vsync_len = 1, |
| 103 | }; |
| 104 | |
yu-chang.lee | dfd78c1 | 2023-11-17 13:43:45 +0800 | [diff] [blame] | 105 | static const struct mtk_mmsys_driver_data mt8188_vppsys0_driver_data = { |
| 106 | .clk_driver = "clk-mt8188-vpp0", |
| 107 | .is_vppsys = true, |
| 108 | }; |
| 109 | |
| 110 | static const struct mtk_mmsys_driver_data mt8188_vppsys1_driver_data = { |
| 111 | .clk_driver = "clk-mt8188-vpp1", |
| 112 | .is_vppsys = true, |
| 113 | }; |
| 114 | |
Yongqiang Niu | d687e05 | 2021-08-02 16:59:33 +0800 | [diff] [blame] | 115 | static const struct mtk_mmsys_driver_data mt8192_mmsys_driver_data = { |
| 116 | .clk_driver = "clk-mt8192-mm", |
| 117 | .routes = mmsys_mt8192_routing_table, |
| 118 | .num_routes = ARRAY_SIZE(mmsys_mt8192_routing_table), |
AngeloGioacchino Del Regno | 9d7370a | 2022-03-23 10:19:32 +0100 | [diff] [blame] | 119 | .sw0_rst_offset = MT8186_MMSYS_SW0_RST_B, |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 120 | .num_resets = 32, |
Yongqiang Niu | d687e05 | 2021-08-02 16:59:33 +0800 | [diff] [blame] | 121 | }; |
| 122 | |
Jason-JH.Lin | b2b99a7 | 2022-09-27 23:27:01 +0800 | [diff] [blame] | 123 | static const struct mtk_mmsys_driver_data mt8195_vdosys0_driver_data = { |
| 124 | .clk_driver = "clk-mt8195-vdo0", |
| 125 | .routes = mmsys_mt8195_routing_table, |
| 126 | .num_routes = ARRAY_SIZE(mmsys_mt8195_routing_table), |
| 127 | }; |
| 128 | |
Nancy.Lin | 3917012 | 2023-01-13 18:44:27 +0800 | [diff] [blame] | 129 | static const struct mtk_mmsys_driver_data mt8195_vdosys1_driver_data = { |
| 130 | .clk_driver = "clk-mt8195-vdo1", |
| 131 | .routes = mmsys_mt8195_vdo1_routing_table, |
| 132 | .num_routes = ARRAY_SIZE(mmsys_mt8195_vdo1_routing_table), |
Nancy.Lin | 7f0a38f | 2023-01-13 18:44:32 +0800 | [diff] [blame] | 133 | .sw0_rst_offset = MT8195_VDO1_SW0_RST_B, |
| 134 | .num_resets = 64, |
Nancy.Lin | 3917012 | 2023-01-13 18:44:27 +0800 | [diff] [blame] | 135 | }; |
| 136 | |
Roy-CW.Yeh | 78ce309 | 2023-01-18 11:15:09 +0800 | [diff] [blame] | 137 | static const struct mtk_mmsys_driver_data mt8195_vppsys0_driver_data = { |
| 138 | .clk_driver = "clk-mt8195-vpp0", |
| 139 | .is_vppsys = true, |
| 140 | }; |
| 141 | |
| 142 | static const struct mtk_mmsys_driver_data mt8195_vppsys1_driver_data = { |
| 143 | .clk_driver = "clk-mt8195-vpp1", |
| 144 | .is_vppsys = true, |
| 145 | }; |
| 146 | |
Fabien Parent | bc3fc5c | 2021-05-19 18:18:46 +0200 | [diff] [blame] | 147 | static const struct mtk_mmsys_driver_data mt8365_mmsys_driver_data = { |
| 148 | .clk_driver = "clk-mt8365-mm", |
| 149 | .routes = mt8365_mmsys_routing_table, |
| 150 | .num_routes = ARRAY_SIZE(mt8365_mmsys_routing_table), |
| 151 | }; |
| 152 | |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 153 | struct mtk_mmsys { |
| 154 | void __iomem *regs; |
| 155 | const struct mtk_mmsys_driver_data *data; |
AngeloGioacchino Del Regno | 1ef3e78 | 2023-02-22 10:42:45 +0100 | [diff] [blame] | 156 | struct platform_device *clks_pdev; |
| 157 | struct platform_device *drm_pdev; |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 158 | spinlock_t lock; /* protects mmsys_sw_rst_b reg */ |
| 159 | struct reset_controller_dev rcdev; |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 160 | struct cmdq_client_reg cmdq_base; |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 163 | static void mtk_mmsys_update_bits(struct mtk_mmsys *mmsys, u32 offset, u32 mask, u32 val, |
| 164 | struct cmdq_pkt *cmdq_pkt) |
Nancy.Lin | 0a81503 | 2023-01-13 18:44:28 +0800 | [diff] [blame] | 165 | { |
AngeloGioacchino Del Regno | b34884b | 2023-02-22 10:42:53 +0100 | [diff] [blame] | 166 | int ret; |
Nancy.Lin | 0a81503 | 2023-01-13 18:44:28 +0800 | [diff] [blame] | 167 | u32 tmp; |
| 168 | |
AngeloGioacchino Del Regno | b34884b | 2023-02-22 10:42:53 +0100 | [diff] [blame] | 169 | if (mmsys->cmdq_base.size && cmdq_pkt) { |
| 170 | ret = cmdq_pkt_write_mask(cmdq_pkt, mmsys->cmdq_base.subsys, |
| 171 | mmsys->cmdq_base.offset + offset, val, |
| 172 | mask); |
| 173 | if (ret) |
| 174 | pr_debug("CMDQ unavailable: using CPU write\n"); |
| 175 | else |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 176 | return; |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 177 | } |
Nancy.Lin | 0a81503 | 2023-01-13 18:44:28 +0800 | [diff] [blame] | 178 | tmp = readl_relaxed(mmsys->regs + offset); |
| 179 | tmp = (tmp & ~mask) | (val & mask); |
| 180 | writel_relaxed(tmp, mmsys->regs + offset); |
| 181 | } |
| 182 | |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 183 | void mtk_mmsys_ddp_connect(struct device *dev, |
| 184 | enum mtk_ddp_comp_id cur, |
| 185 | enum mtk_ddp_comp_id next) |
| 186 | { |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 187 | struct mtk_mmsys *mmsys = dev_get_drvdata(dev); |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 188 | const struct mtk_mmsys_routes *routes = mmsys->data->routes; |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 189 | int i; |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 190 | |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 191 | for (i = 0; i < mmsys->data->num_routes; i++) |
Nancy.Lin | 0a81503 | 2023-01-13 18:44:28 +0800 | [diff] [blame] | 192 | if (cur == routes[i].from_comp && next == routes[i].to_comp) |
| 193 | mtk_mmsys_update_bits(mmsys, routes[i].addr, routes[i].mask, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 194 | routes[i].val, NULL); |
Hsiao Chien Sung | c034931 | 2023-10-24 21:00:32 +0800 | [diff] [blame] | 195 | |
| 196 | if (mmsys->data->vsync_len) |
| 197 | mtk_mmsys_update_bits(mmsys, MT8188_VDO1_MIXER_VSYNC_LEN, GENMASK(31, 0), |
| 198 | mmsys->data->vsync_len, NULL); |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 199 | } |
| 200 | EXPORT_SYMBOL_GPL(mtk_mmsys_ddp_connect); |
| 201 | |
| 202 | void mtk_mmsys_ddp_disconnect(struct device *dev, |
| 203 | enum mtk_ddp_comp_id cur, |
| 204 | enum mtk_ddp_comp_id next) |
| 205 | { |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 206 | struct mtk_mmsys *mmsys = dev_get_drvdata(dev); |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 207 | const struct mtk_mmsys_routes *routes = mmsys->data->routes; |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 208 | int i; |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 209 | |
CK Hu | 4401476 | 2021-03-17 19:17:10 +0100 | [diff] [blame] | 210 | for (i = 0; i < mmsys->data->num_routes; i++) |
Nancy.Lin | 0a81503 | 2023-01-13 18:44:28 +0800 | [diff] [blame] | 211 | if (cur == routes[i].from_comp && next == routes[i].to_comp) |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 212 | mtk_mmsys_update_bits(mmsys, routes[i].addr, routes[i].mask, 0, NULL); |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 213 | } |
| 214 | EXPORT_SYMBOL_GPL(mtk_mmsys_ddp_disconnect); |
| 215 | |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 216 | void mtk_mmsys_merge_async_config(struct device *dev, int idx, int width, int height, |
| 217 | struct cmdq_pkt *cmdq_pkt) |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 218 | { |
| 219 | mtk_mmsys_update_bits(dev_get_drvdata(dev), MT8195_VDO1_MERGE0_ASYNC_CFG_WD + 0x10 * idx, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 220 | ~0, height << 16 | width, cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 221 | } |
| 222 | EXPORT_SYMBOL_GPL(mtk_mmsys_merge_async_config); |
| 223 | |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 224 | void mtk_mmsys_hdr_config(struct device *dev, int be_width, int be_height, |
| 225 | struct cmdq_pkt *cmdq_pkt) |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 226 | { |
| 227 | mtk_mmsys_update_bits(dev_get_drvdata(dev), MT8195_VDO1_HDRBE_ASYNC_CFG_WD, ~0, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 228 | be_height << 16 | be_width, cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 229 | } |
| 230 | EXPORT_SYMBOL_GPL(mtk_mmsys_hdr_config); |
| 231 | |
| 232 | void mtk_mmsys_mixer_in_config(struct device *dev, int idx, bool alpha_sel, u16 alpha, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 233 | u8 mode, u32 biwidth, struct cmdq_pkt *cmdq_pkt) |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 234 | { |
| 235 | struct mtk_mmsys *mmsys = dev_get_drvdata(dev); |
| 236 | |
| 237 | mtk_mmsys_update_bits(mmsys, MT8195_VDO1_MIXER_IN1_ALPHA + (idx - 1) * 4, ~0, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 238 | alpha << 16 | alpha, cmdq_pkt); |
Hsiao Chien Sung | 7cc069d | 2024-06-20 00:50:24 +0800 | [diff] [blame] | 239 | mtk_mmsys_update_bits(mmsys, MT8195_VDO1_HDR_TOP_CFG, BIT(15 + idx), 0, cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 240 | mtk_mmsys_update_bits(mmsys, MT8195_VDO1_HDR_TOP_CFG, BIT(19 + idx), |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 241 | alpha_sel << (19 + idx), cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 242 | mtk_mmsys_update_bits(mmsys, MT8195_VDO1_MIXER_IN1_PAD + (idx - 1) * 4, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 243 | GENMASK(31, 16) | GENMASK(1, 0), biwidth << 16 | mode, cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 244 | } |
| 245 | EXPORT_SYMBOL_GPL(mtk_mmsys_mixer_in_config); |
| 246 | |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 247 | void mtk_mmsys_mixer_in_channel_swap(struct device *dev, int idx, bool channel_swap, |
| 248 | struct cmdq_pkt *cmdq_pkt) |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 249 | { |
| 250 | mtk_mmsys_update_bits(dev_get_drvdata(dev), MT8195_VDO1_MIXER_IN1_PAD + (idx - 1) * 4, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 251 | BIT(4), channel_swap << 4, cmdq_pkt); |
Nancy.Lin | 3dd20b7 | 2023-01-13 18:44:29 +0800 | [diff] [blame] | 252 | } |
| 253 | EXPORT_SYMBOL_GPL(mtk_mmsys_mixer_in_channel_swap); |
| 254 | |
Xinlei Lee | b404cb4 | 2022-09-14 21:21:00 +0800 | [diff] [blame] | 255 | void mtk_mmsys_ddp_dpi_fmt_config(struct device *dev, u32 val) |
| 256 | { |
Xinlei Lee | e6c7e62 | 2022-11-08 19:23:27 +0100 | [diff] [blame] | 257 | struct mtk_mmsys *mmsys = dev_get_drvdata(dev); |
| 258 | |
| 259 | switch (val) { |
| 260 | case MTK_DPI_RGB888_SDR_CON: |
| 261 | mtk_mmsys_update_bits(mmsys, MT8186_MMSYS_DPI_OUTPUT_FORMAT, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 262 | MT8186_DPI_FORMAT_MASK, MT8186_DPI_RGB888_SDR_CON, NULL); |
Xinlei Lee | e6c7e62 | 2022-11-08 19:23:27 +0100 | [diff] [blame] | 263 | break; |
| 264 | case MTK_DPI_RGB565_SDR_CON: |
| 265 | mtk_mmsys_update_bits(mmsys, MT8186_MMSYS_DPI_OUTPUT_FORMAT, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 266 | MT8186_DPI_FORMAT_MASK, MT8186_DPI_RGB565_SDR_CON, NULL); |
Xinlei Lee | e6c7e62 | 2022-11-08 19:23:27 +0100 | [diff] [blame] | 267 | break; |
| 268 | case MTK_DPI_RGB565_DDR_CON: |
| 269 | mtk_mmsys_update_bits(mmsys, MT8186_MMSYS_DPI_OUTPUT_FORMAT, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 270 | MT8186_DPI_FORMAT_MASK, MT8186_DPI_RGB565_DDR_CON, NULL); |
Xinlei Lee | e6c7e62 | 2022-11-08 19:23:27 +0100 | [diff] [blame] | 271 | break; |
| 272 | case MTK_DPI_RGB888_DDR_CON: |
| 273 | default: |
| 274 | mtk_mmsys_update_bits(mmsys, MT8186_MMSYS_DPI_OUTPUT_FORMAT, |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 275 | MT8186_DPI_FORMAT_MASK, MT8186_DPI_RGB888_DDR_CON, NULL); |
Xinlei Lee | e6c7e62 | 2022-11-08 19:23:27 +0100 | [diff] [blame] | 276 | break; |
| 277 | } |
Xinlei Lee | b404cb4 | 2022-09-14 21:21:00 +0800 | [diff] [blame] | 278 | } |
| 279 | EXPORT_SYMBOL_GPL(mtk_mmsys_ddp_dpi_fmt_config); |
| 280 | |
Roy-CW.Yeh | dd4f373 | 2023-02-06 17:11:07 +0800 | [diff] [blame] | 281 | void mtk_mmsys_vpp_rsz_merge_config(struct device *dev, u32 id, bool enable, |
| 282 | struct cmdq_pkt *cmdq_pkt) |
| 283 | { |
| 284 | u32 reg; |
| 285 | |
| 286 | switch (id) { |
| 287 | case 2: |
| 288 | reg = MT8195_SVPP2_BUF_BF_RSZ_SWITCH; |
| 289 | break; |
| 290 | case 3: |
| 291 | reg = MT8195_SVPP3_BUF_BF_RSZ_SWITCH; |
| 292 | break; |
| 293 | default: |
| 294 | dev_err(dev, "Invalid id %d\n", id); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | mtk_mmsys_update_bits(dev_get_drvdata(dev), reg, ~0, enable, cmdq_pkt); |
| 299 | } |
| 300 | EXPORT_SYMBOL_GPL(mtk_mmsys_vpp_rsz_merge_config); |
| 301 | |
| 302 | void mtk_mmsys_vpp_rsz_dcm_config(struct device *dev, bool enable, |
| 303 | struct cmdq_pkt *cmdq_pkt) |
| 304 | { |
| 305 | u32 client; |
| 306 | |
| 307 | client = MT8195_SVPP1_MDP_RSZ; |
| 308 | mtk_mmsys_update_bits(dev_get_drvdata(dev), |
| 309 | MT8195_VPP1_HW_DCM_1ST_DIS0, client, |
| 310 | ((enable) ? client : 0), cmdq_pkt); |
| 311 | mtk_mmsys_update_bits(dev_get_drvdata(dev), |
| 312 | MT8195_VPP1_HW_DCM_2ND_DIS0, client, |
| 313 | ((enable) ? client : 0), cmdq_pkt); |
| 314 | |
| 315 | client = MT8195_SVPP2_MDP_RSZ | MT8195_SVPP3_MDP_RSZ; |
| 316 | mtk_mmsys_update_bits(dev_get_drvdata(dev), |
| 317 | MT8195_VPP1_HW_DCM_1ST_DIS1, client, |
| 318 | ((enable) ? client : 0), cmdq_pkt); |
| 319 | mtk_mmsys_update_bits(dev_get_drvdata(dev), |
| 320 | MT8195_VPP1_HW_DCM_2ND_DIS1, client, |
| 321 | ((enable) ? client : 0), cmdq_pkt); |
| 322 | } |
| 323 | EXPORT_SYMBOL_GPL(mtk_mmsys_vpp_rsz_dcm_config); |
| 324 | |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 325 | static int mtk_mmsys_reset_update(struct reset_controller_dev *rcdev, unsigned long id, |
| 326 | bool assert) |
| 327 | { |
| 328 | struct mtk_mmsys *mmsys = container_of(rcdev, struct mtk_mmsys, rcdev); |
| 329 | unsigned long flags; |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 330 | u32 offset; |
| 331 | u32 reg; |
| 332 | |
Hsiao Chien Sung | 67637de | 2023-10-24 21:00:34 +0800 | [diff] [blame] | 333 | if (mmsys->data->rst_tb) { |
| 334 | if (id >= mmsys->data->num_resets) { |
| 335 | dev_err(rcdev->dev, "Invalid reset ID: %lu (>=%u)\n", |
| 336 | id, mmsys->data->num_resets); |
| 337 | return -EINVAL; |
| 338 | } |
| 339 | id = mmsys->data->rst_tb[id]; |
| 340 | } |
| 341 | |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 342 | offset = (id / MMSYS_SW_RESET_PER_REG) * sizeof(u32); |
| 343 | id = id % MMSYS_SW_RESET_PER_REG; |
| 344 | reg = mmsys->data->sw0_rst_offset + offset; |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 345 | |
| 346 | spin_lock_irqsave(&mmsys->lock, flags); |
| 347 | |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 348 | if (assert) |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 349 | mtk_mmsys_update_bits(mmsys, reg, BIT(id), 0, NULL); |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 350 | else |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 351 | mtk_mmsys_update_bits(mmsys, reg, BIT(id), BIT(id), NULL); |
Enric Balletbo i Serra | f27ef28 | 2021-09-30 10:31:49 +0200 | [diff] [blame] | 352 | |
| 353 | spin_unlock_irqrestore(&mmsys->lock, flags); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int mtk_mmsys_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) |
| 359 | { |
| 360 | return mtk_mmsys_reset_update(rcdev, id, true); |
| 361 | } |
| 362 | |
| 363 | static int mtk_mmsys_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) |
| 364 | { |
| 365 | return mtk_mmsys_reset_update(rcdev, id, false); |
| 366 | } |
| 367 | |
| 368 | static int mtk_mmsys_reset(struct reset_controller_dev *rcdev, unsigned long id) |
| 369 | { |
| 370 | int ret; |
| 371 | |
| 372 | ret = mtk_mmsys_reset_assert(rcdev, id); |
| 373 | if (ret) |
| 374 | return ret; |
| 375 | |
| 376 | usleep_range(1000, 1100); |
| 377 | |
| 378 | return mtk_mmsys_reset_deassert(rcdev, id); |
| 379 | } |
| 380 | |
| 381 | static const struct reset_control_ops mtk_mmsys_reset_ops = { |
| 382 | .assert = mtk_mmsys_reset_assert, |
| 383 | .deassert = mtk_mmsys_reset_deassert, |
| 384 | .reset = mtk_mmsys_reset, |
| 385 | }; |
| 386 | |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 387 | static int mtk_mmsys_probe(struct platform_device *pdev) |
| 388 | { |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 389 | struct device *dev = &pdev->dev; |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 390 | struct platform_device *clks; |
Enric Balletbo i Serra | 667c769 | 2020-03-25 18:31:23 +0100 | [diff] [blame] | 391 | struct platform_device *drm; |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 392 | struct mtk_mmsys *mmsys; |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 393 | int ret; |
| 394 | |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 395 | mmsys = devm_kzalloc(dev, sizeof(*mmsys), GFP_KERNEL); |
| 396 | if (!mmsys) |
| 397 | return -ENOMEM; |
| 398 | |
| 399 | mmsys->regs = devm_platform_ioremap_resource(pdev, 0); |
| 400 | if (IS_ERR(mmsys->regs)) { |
| 401 | ret = PTR_ERR(mmsys->regs); |
Enric Balletbo i Serra | cc65760 | 2020-10-06 21:33:18 +0200 | [diff] [blame] | 402 | dev_err(dev, "Failed to ioremap mmsys registers: %d\n", ret); |
Enric Balletbo i Serra | 2c758e3 | 2020-03-25 18:31:22 +0100 | [diff] [blame] | 403 | return ret; |
| 404 | } |
| 405 | |
Jason-JH.Lin | 8d8ccdd | 2022-09-27 23:27:00 +0800 | [diff] [blame] | 406 | mmsys->data = of_device_get_match_data(&pdev->dev); |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 407 | |
Nancy.Lin | 2004f8b | 2023-01-13 18:44:31 +0800 | [diff] [blame] | 408 | if (mmsys->data->num_resets > 0) { |
| 409 | spin_lock_init(&mmsys->lock); |
| 410 | |
| 411 | mmsys->rcdev.owner = THIS_MODULE; |
| 412 | mmsys->rcdev.nr_resets = mmsys->data->num_resets; |
| 413 | mmsys->rcdev.ops = &mtk_mmsys_reset_ops; |
| 414 | mmsys->rcdev.of_node = pdev->dev.of_node; |
| 415 | ret = devm_reset_controller_register(&pdev->dev, &mmsys->rcdev); |
| 416 | if (ret) { |
| 417 | dev_err(&pdev->dev, "Couldn't register mmsys reset controller: %d\n", ret); |
| 418 | return ret; |
| 419 | } |
| 420 | } |
| 421 | |
AngeloGioacchino Del Regno | b34884b | 2023-02-22 10:42:53 +0100 | [diff] [blame] | 422 | /* CMDQ is optional */ |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 423 | ret = cmdq_dev_get_client_reg(dev, &mmsys->cmdq_base, 0); |
| 424 | if (ret) |
| 425 | dev_dbg(dev, "No mediatek,gce-client-reg!\n"); |
Nancy.Lin | 8af1f6b | 2023-01-13 18:44:30 +0800 | [diff] [blame] | 426 | |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 427 | platform_set_drvdata(pdev, mmsys); |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 428 | |
CK Hu | ce15e7f | 2021-03-17 19:17:09 +0100 | [diff] [blame] | 429 | clks = platform_device_register_data(&pdev->dev, mmsys->data->clk_driver, |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 430 | PLATFORM_DEVID_AUTO, NULL, 0); |
| 431 | if (IS_ERR(clks)) |
| 432 | return PTR_ERR(clks); |
AngeloGioacchino Del Regno | 1ef3e78 | 2023-02-22 10:42:45 +0100 | [diff] [blame] | 433 | mmsys->clks_pdev = clks; |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 434 | |
Roy-CW.Yeh | 78ce309 | 2023-01-18 11:15:09 +0800 | [diff] [blame] | 435 | if (mmsys->data->is_vppsys) |
| 436 | goto out_probe_done; |
| 437 | |
Enric Balletbo i Serra | 667c769 | 2020-03-25 18:31:23 +0100 | [diff] [blame] | 438 | drm = platform_device_register_data(&pdev->dev, "mediatek-drm", |
| 439 | PLATFORM_DEVID_AUTO, NULL, 0); |
Wei Yongjun | ff34e17 | 2020-05-06 14:13:17 +0000 | [diff] [blame] | 440 | if (IS_ERR(drm)) { |
| 441 | platform_device_unregister(clks); |
Enric Balletbo i Serra | 667c769 | 2020-03-25 18:31:23 +0100 | [diff] [blame] | 442 | return PTR_ERR(drm); |
Wei Yongjun | ff34e17 | 2020-05-06 14:13:17 +0000 | [diff] [blame] | 443 | } |
AngeloGioacchino Del Regno | 1ef3e78 | 2023-02-22 10:42:45 +0100 | [diff] [blame] | 444 | mmsys->drm_pdev = drm; |
Enric Balletbo i Serra | 667c769 | 2020-03-25 18:31:23 +0100 | [diff] [blame] | 445 | |
Roy-CW.Yeh | 78ce309 | 2023-01-18 11:15:09 +0800 | [diff] [blame] | 446 | out_probe_done: |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
Uwe Kleine-König | 630cc5e | 2023-09-25 11:55:06 +0200 | [diff] [blame] | 450 | static void mtk_mmsys_remove(struct platform_device *pdev) |
AngeloGioacchino Del Regno | 1ef3e78 | 2023-02-22 10:42:45 +0100 | [diff] [blame] | 451 | { |
| 452 | struct mtk_mmsys *mmsys = platform_get_drvdata(pdev); |
| 453 | |
| 454 | platform_device_unregister(mmsys->drm_pdev); |
| 455 | platform_device_unregister(mmsys->clks_pdev); |
AngeloGioacchino Del Regno | 1ef3e78 | 2023-02-22 10:42:45 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 458 | static const struct of_device_id of_match_mtk_mmsys[] = { |
AngeloGioacchino Del Regno | 0fe09bf | 2023-02-22 10:42:47 +0100 | [diff] [blame] | 459 | { .compatible = "mediatek,mt2701-mmsys", .data = &mt2701_mmsys_driver_data }, |
| 460 | { .compatible = "mediatek,mt2712-mmsys", .data = &mt2712_mmsys_driver_data }, |
| 461 | { .compatible = "mediatek,mt6779-mmsys", .data = &mt6779_mmsys_driver_data }, |
AngeloGioacchino Del Regno | e9a6f5b | 2023-03-09 11:26:18 +0100 | [diff] [blame] | 462 | { .compatible = "mediatek,mt6795-mmsys", .data = &mt6795_mmsys_driver_data }, |
AngeloGioacchino Del Regno | 0fe09bf | 2023-02-22 10:42:47 +0100 | [diff] [blame] | 463 | { .compatible = "mediatek,mt6797-mmsys", .data = &mt6797_mmsys_driver_data }, |
| 464 | { .compatible = "mediatek,mt8167-mmsys", .data = &mt8167_mmsys_driver_data }, |
| 465 | { .compatible = "mediatek,mt8173-mmsys", .data = &mt8173_mmsys_driver_data }, |
| 466 | { .compatible = "mediatek,mt8183-mmsys", .data = &mt8183_mmsys_driver_data }, |
| 467 | { .compatible = "mediatek,mt8186-mmsys", .data = &mt8186_mmsys_driver_data }, |
| 468 | { .compatible = "mediatek,mt8188-vdosys0", .data = &mt8188_vdosys0_driver_data }, |
Hsiao Chien Sung | c034931 | 2023-10-24 21:00:32 +0800 | [diff] [blame] | 469 | { .compatible = "mediatek,mt8188-vdosys1", .data = &mt8188_vdosys1_driver_data }, |
yu-chang.lee | dfd78c1 | 2023-11-17 13:43:45 +0800 | [diff] [blame] | 470 | { .compatible = "mediatek,mt8188-vppsys0", .data = &mt8188_vppsys0_driver_data }, |
| 471 | { .compatible = "mediatek,mt8188-vppsys1", .data = &mt8188_vppsys1_driver_data }, |
AngeloGioacchino Del Regno | 0fe09bf | 2023-02-22 10:42:47 +0100 | [diff] [blame] | 472 | { .compatible = "mediatek,mt8192-mmsys", .data = &mt8192_mmsys_driver_data }, |
| 473 | /* "mediatek,mt8195-mmsys" compatible is deprecated */ |
| 474 | { .compatible = "mediatek,mt8195-mmsys", .data = &mt8195_vdosys0_driver_data }, |
| 475 | { .compatible = "mediatek,mt8195-vdosys0", .data = &mt8195_vdosys0_driver_data }, |
| 476 | { .compatible = "mediatek,mt8195-vdosys1", .data = &mt8195_vdosys1_driver_data }, |
| 477 | { .compatible = "mediatek,mt8195-vppsys0", .data = &mt8195_vppsys0_driver_data }, |
| 478 | { .compatible = "mediatek,mt8195-vppsys1", .data = &mt8195_vppsys1_driver_data }, |
| 479 | { .compatible = "mediatek,mt8365-mmsys", .data = &mt8365_mmsys_driver_data }, |
| 480 | { /* sentinel */ } |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 481 | }; |
AngeloGioacchino Del Regno | 1068763 | 2023-02-22 10:42:48 +0100 | [diff] [blame] | 482 | MODULE_DEVICE_TABLE(of, of_match_mtk_mmsys); |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 483 | |
| 484 | static struct platform_driver mtk_mmsys_drv = { |
| 485 | .driver = { |
| 486 | .name = "mtk-mmsys", |
| 487 | .of_match_table = of_match_mtk_mmsys, |
| 488 | }, |
| 489 | .probe = mtk_mmsys_probe, |
Uwe Kleine-König | 630cc5e | 2023-09-25 11:55:06 +0200 | [diff] [blame] | 490 | .remove_new = mtk_mmsys_remove, |
Matthias Brugger | 1303270 | 2020-03-25 18:31:21 +0100 | [diff] [blame] | 491 | }; |
AngeloGioacchino Del Regno | 683c7d3 | 2023-02-22 10:42:46 +0100 | [diff] [blame] | 492 | module_platform_driver(mtk_mmsys_drv); |
Yongqiang Niu | a7596e6 | 2022-11-18 14:30:18 +0800 | [diff] [blame] | 493 | |
| 494 | MODULE_AUTHOR("Yongqiang Niu <yongqiang.niu@mediatek.com>"); |
| 495 | MODULE_DESCRIPTION("MediaTek SoC MMSYS driver"); |
| 496 | MODULE_LICENSE("GPL"); |