Lines Matching +full:s5l +full:- +full:fpwm

1 // SPDX-License-Identifier: GPL-2.0 OR MIT
8 * - The writes to cycle registers are shadowed until a write to
10 * - If both OFF_CYCLES and ON_CYCLES are set to 0, the output
12 * - When APPLE_PWM_CTRL is set to 0, the output is constant low
48 struct apple_pwm *fpwm; in apple_pwm_apply() local
50 if (state->polarity == PWM_POLARITY_INVERSED) in apple_pwm_apply()
51 return -EINVAL; in apple_pwm_apply()
53 fpwm = to_apple_pwm(chip); in apple_pwm_apply()
54 if (state->enabled) { in apple_pwm_apply()
57 on_cycles = mul_u64_u64_div_u64(fpwm->clkrate, in apple_pwm_apply()
58 state->duty_cycle, NSEC_PER_SEC); in apple_pwm_apply()
62 off_cycles = mul_u64_u64_div_u64(fpwm->clkrate, in apple_pwm_apply()
63 state->period, NSEC_PER_SEC) - on_cycles; in apple_pwm_apply()
67 writel(on_cycles, fpwm->base + APPLE_PWM_ON_CYCLES); in apple_pwm_apply()
68 writel(off_cycles, fpwm->base + APPLE_PWM_OFF_CYCLES); in apple_pwm_apply()
70 fpwm->base + APPLE_PWM_CTRL); in apple_pwm_apply()
72 writel(0, fpwm->base + APPLE_PWM_CTRL); in apple_pwm_apply()
80 struct apple_pwm *fpwm; in apple_pwm_get_state() local
83 fpwm = to_apple_pwm(chip); in apple_pwm_get_state()
85 ctrl = readl(fpwm->base + APPLE_PWM_CTRL); in apple_pwm_get_state()
86 on_cycles = readl(fpwm->base + APPLE_PWM_ON_CYCLES); in apple_pwm_get_state()
87 off_cycles = readl(fpwm->base + APPLE_PWM_OFF_CYCLES); in apple_pwm_get_state()
89 state->enabled = (ctrl & APPLE_PWM_CTRL_ENABLE) && (ctrl & APPLE_PWM_CTRL_OUTPUT_ENABLE); in apple_pwm_get_state()
90 state->polarity = PWM_POLARITY_NORMAL; in apple_pwm_get_state()
92 state->duty_cycle = DIV64_U64_ROUND_UP((u64)on_cycles * NSEC_PER_SEC, fpwm->clkrate); in apple_pwm_get_state()
93 state->period = DIV64_U64_ROUND_UP(((u64)off_cycles + (u64)on_cycles) * in apple_pwm_get_state()
94 NSEC_PER_SEC, fpwm->clkrate); in apple_pwm_get_state()
107 struct apple_pwm *fpwm; in apple_pwm_probe() local
111 fpwm = devm_kzalloc(&pdev->dev, sizeof(*fpwm), GFP_KERNEL); in apple_pwm_probe()
112 if (!fpwm) in apple_pwm_probe()
113 return -ENOMEM; in apple_pwm_probe()
115 fpwm->base = devm_platform_ioremap_resource(pdev, 0); in apple_pwm_probe()
116 if (IS_ERR(fpwm->base)) in apple_pwm_probe()
117 return PTR_ERR(fpwm->base); in apple_pwm_probe()
119 clk = devm_clk_get_enabled(&pdev->dev, NULL); in apple_pwm_probe()
121 return dev_err_probe(&pdev->dev, PTR_ERR(clk), "unable to get the clock"); in apple_pwm_probe()
129 fpwm->clkrate = clk_get_rate(clk); in apple_pwm_probe()
130 if (fpwm->clkrate > NSEC_PER_SEC) in apple_pwm_probe()
131 return dev_err_probe(&pdev->dev, -EINVAL, "pwm clock out of range"); in apple_pwm_probe()
133 fpwm->chip.dev = &pdev->dev; in apple_pwm_probe()
134 fpwm->chip.npwm = 1; in apple_pwm_probe()
135 fpwm->chip.ops = &apple_pwm_ops; in apple_pwm_probe()
137 ret = devm_pwmchip_add(&pdev->dev, &fpwm->chip); in apple_pwm_probe()
139 return dev_err_probe(&pdev->dev, ret, "unable to add pwm chip"); in apple_pwm_probe()
145 { .compatible = "apple,s5l-fpwm" },
153 .name = "apple-pwm",