Lines Matching +full:mt8173 +full:- +full:disp +full:- +full:pwm
1 // SPDX-License-Identifier: GPL-2.0-only
3 * MediaTek display pulse-width-modulation controller driver.
15 #include <linux/pwm.h>
25 #define PWM_PERIOD_MASK ((1 << PWM_PERIOD_BIT_WIDTH) - 1)
60 void __iomem *address = mdp->base + offset; in mtk_disp_pwm_update_bits()
69 static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in mtk_disp_pwm_apply() argument
77 if (state->polarity != PWM_POLARITY_NORMAL) in mtk_disp_pwm_apply()
78 return -EINVAL; in mtk_disp_pwm_apply()
80 if (!state->enabled && mdp->enabled) { in mtk_disp_pwm_apply()
82 mdp->data->enable_mask, 0x0); in mtk_disp_pwm_apply()
83 clk_disable_unprepare(mdp->clk_mm); in mtk_disp_pwm_apply()
84 clk_disable_unprepare(mdp->clk_main); in mtk_disp_pwm_apply()
86 mdp->enabled = false; in mtk_disp_pwm_apply()
90 if (!mdp->enabled) { in mtk_disp_pwm_apply()
91 err = clk_prepare_enable(mdp->clk_main); in mtk_disp_pwm_apply()
93 dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n", in mtk_disp_pwm_apply()
98 err = clk_prepare_enable(mdp->clk_mm); in mtk_disp_pwm_apply()
100 dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n", in mtk_disp_pwm_apply()
102 clk_disable_unprepare(mdp->clk_main); in mtk_disp_pwm_apply()
114 * period = (PWM_CLK_RATE * period_ns) / (10^9 * (clk_div + 1)) - 1 in mtk_disp_pwm_apply()
117 rate = clk_get_rate(mdp->clk_main); in mtk_disp_pwm_apply()
118 clk_div = mul_u64_u64_div_u64(state->period, rate, NSEC_PER_SEC) >> in mtk_disp_pwm_apply()
121 if (!mdp->enabled) { in mtk_disp_pwm_apply()
122 clk_disable_unprepare(mdp->clk_mm); in mtk_disp_pwm_apply()
123 clk_disable_unprepare(mdp->clk_main); in mtk_disp_pwm_apply()
125 return -EINVAL; in mtk_disp_pwm_apply()
129 period = mul_u64_u64_div_u64(state->period, rate, div); in mtk_disp_pwm_apply()
131 period--; in mtk_disp_pwm_apply()
133 high_width = mul_u64_u64_div_u64(state->duty_cycle, rate, div); in mtk_disp_pwm_apply()
136 if (mdp->data->bls_debug && !mdp->data->has_commit) { in mtk_disp_pwm_apply()
141 mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, in mtk_disp_pwm_apply()
142 mdp->data->bls_debug_mask, in mtk_disp_pwm_apply()
143 mdp->data->bls_debug_mask); in mtk_disp_pwm_apply()
144 mtk_disp_pwm_update_bits(mdp, mdp->data->con0, in mtk_disp_pwm_apply()
145 mdp->data->con0_sel, in mtk_disp_pwm_apply()
146 mdp->data->con0_sel); in mtk_disp_pwm_apply()
149 mtk_disp_pwm_update_bits(mdp, mdp->data->con0, in mtk_disp_pwm_apply()
152 mtk_disp_pwm_update_bits(mdp, mdp->data->con1, in mtk_disp_pwm_apply()
156 if (mdp->data->has_commit) { in mtk_disp_pwm_apply()
157 mtk_disp_pwm_update_bits(mdp, mdp->data->commit, in mtk_disp_pwm_apply()
158 mdp->data->commit_mask, in mtk_disp_pwm_apply()
159 mdp->data->commit_mask); in mtk_disp_pwm_apply()
160 mtk_disp_pwm_update_bits(mdp, mdp->data->commit, in mtk_disp_pwm_apply()
161 mdp->data->commit_mask, in mtk_disp_pwm_apply()
165 mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask, in mtk_disp_pwm_apply()
166 mdp->data->enable_mask); in mtk_disp_pwm_apply()
167 mdp->enabled = true; in mtk_disp_pwm_apply()
173 struct pwm_device *pwm, in mtk_disp_pwm_get_state() argument
181 err = clk_prepare_enable(mdp->clk_main); in mtk_disp_pwm_get_state()
183 dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err)); in mtk_disp_pwm_get_state()
187 err = clk_prepare_enable(mdp->clk_mm); in mtk_disp_pwm_get_state()
189 dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err)); in mtk_disp_pwm_get_state()
190 clk_disable_unprepare(mdp->clk_main); in mtk_disp_pwm_get_state()
199 if (mdp->data->bls_debug) in mtk_disp_pwm_get_state()
200 mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, in mtk_disp_pwm_get_state()
201 mdp->data->bls_debug_mask, in mtk_disp_pwm_get_state()
202 mdp->data->bls_debug_mask); in mtk_disp_pwm_get_state()
204 rate = clk_get_rate(mdp->clk_main); in mtk_disp_pwm_get_state()
205 con0 = readl(mdp->base + mdp->data->con0); in mtk_disp_pwm_get_state()
206 con1 = readl(mdp->base + mdp->data->con1); in mtk_disp_pwm_get_state()
207 pwm_en = readl(mdp->base + DISP_PWM_EN); in mtk_disp_pwm_get_state()
208 state->enabled = !!(pwm_en & mdp->data->enable_mask); in mtk_disp_pwm_get_state()
215 state->period = DIV64_U64_ROUND_UP(period * (clk_div + 1) * NSEC_PER_SEC, rate); in mtk_disp_pwm_get_state()
217 state->duty_cycle = DIV64_U64_ROUND_UP(high_width * (clk_div + 1) * NSEC_PER_SEC, in mtk_disp_pwm_get_state()
219 state->polarity = PWM_POLARITY_NORMAL; in mtk_disp_pwm_get_state()
220 clk_disable_unprepare(mdp->clk_mm); in mtk_disp_pwm_get_state()
221 clk_disable_unprepare(mdp->clk_main); in mtk_disp_pwm_get_state()
237 chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*mdp)); in mtk_disp_pwm_probe()
242 mdp->data = of_device_get_match_data(&pdev->dev); in mtk_disp_pwm_probe()
244 mdp->base = devm_platform_ioremap_resource(pdev, 0); in mtk_disp_pwm_probe()
245 if (IS_ERR(mdp->base)) in mtk_disp_pwm_probe()
246 return PTR_ERR(mdp->base); in mtk_disp_pwm_probe()
248 mdp->clk_main = devm_clk_get(&pdev->dev, "main"); in mtk_disp_pwm_probe()
249 if (IS_ERR(mdp->clk_main)) in mtk_disp_pwm_probe()
250 return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_main), in mtk_disp_pwm_probe()
253 mdp->clk_mm = devm_clk_get(&pdev->dev, "mm"); in mtk_disp_pwm_probe()
254 if (IS_ERR(mdp->clk_mm)) in mtk_disp_pwm_probe()
255 return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm), in mtk_disp_pwm_probe()
258 chip->ops = &mtk_disp_pwm_ops; in mtk_disp_pwm_probe()
260 ret = devm_pwmchip_add(&pdev->dev, chip); in mtk_disp_pwm_probe()
262 return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); in mtk_disp_pwm_probe()
298 { .compatible = "mediatek,mt2701-disp-pwm", .data = &mt2701_pwm_data},
299 { .compatible = "mediatek,mt6595-disp-pwm", .data = &mt8173_pwm_data},
300 { .compatible = "mediatek,mt8173-disp-pwm", .data = &mt8173_pwm_data},
301 { .compatible = "mediatek,mt8183-disp-pwm", .data = &mt8183_pwm_data},
308 .name = "mediatek-disp-pwm",
316 MODULE_DESCRIPTION("MediaTek SoC display PWM driver");