blob: 692361078cb8fd2c1f5e07331afb640947ef6257 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Donghwa Lee3f129282011-03-07 21:11:42 +00002/*
3 * header file for pwm driver.
4 *
Simon Glassfc760cb2016-01-21 19:44:54 -07005 * Copyright 2016 Google Inc.
Donghwa Lee3f129282011-03-07 21:11:42 +00006 * Copyright (c) 2011 samsung electronics
7 * Donghwa Lee <dh09.lee@samsung.com>
Donghwa Lee3f129282011-03-07 21:11:42 +00008 */
9
10#ifndef _pwm_h_
11#define _pwm_h_
12
Simon Glass401d1c42020-10-30 21:38:53 -060013struct udevice;
14
Simon Glassfc760cb2016-01-21 19:44:54 -070015/* struct pwm_ops: Operations for the PWM uclass */
16struct pwm_ops {
17 /**
18 * set_config() - Set the PWM configuration
19 *
Alper Nebi Yasakfefa7132020-10-22 23:49:26 +030020 * Change both the PWM device's period and it's duty period if
21 * possible. Otherwise, set an appropriate duty period that best
22 * matches the given period_ns / duty_ns ratio for the device.
23 *
Simon Glassfc760cb2016-01-21 19:44:54 -070024 * @dev: PWM device to update
25 * @channel: PWM channel to update
26 * @period_ns: PWM period in nanoseconds
27 * @duty_ns: PWM duty period in nanoseconds
28 * @return 0 if OK, -ve on error
29 */
30 int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
31 uint duty_ns);
32
33 /**
34 * set_enable() - Enable or disable the PWM
35 *
36 * @dev: PWM device to update
37 * @channel: PWM channel to update
38 * @enable: true to enable, false to disable
39 * @return 0 if OK, -ve on error
40 */
41 int (*set_enable)(struct udevice *dev, uint channel, bool enable);
Kever Yang0b601112017-04-24 10:27:49 +080042 /**
43 * set_invert() - Set the PWM invert
44 *
45 * @dev: PWM device to update
46 * @channel: PWM channel to update
47 * @polarity: true to invert, false to keep normal polarity
48 * @return 0 if OK, -ve on error
49 */
50 int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
junyi.zhao0cbb4ed2023-02-08 17:32:25 +080051#ifdef CONFIG_PWM_MESON
52 /**
53 * set_times() - Set the PWM times
54 *
55 * @dev: PWM device to update
56 * @channel: PWM channel to update
57 * @times: dual channel to set times
58 * @return 0 if OK, -ve on error
59 */
60 int (*set_times)(struct udevice *dev, uint channel, uint times);
61 /**
62 * set_blink_times() - Set the PWM blink times
63 *
64 * @dev: PWM device to update
65 * @channel: PWM channel to update
66 * @times: set blink times
67 * @return 0 if OK, -ve on error
68 */
69 int (*set_blink_times)(struct udevice *dev, uint channel, uint times);
70 /**
71 * set_blink_enable() - Enable or disable the PWM blink
72 *
73 * @dev: PWM device to update
74 * @channel: PWM channel to update
75 * @enable: true to enable, false to disable
76 * @return 0 if OK, -ve on error
77 */
78 int (*set_blink_enable)(struct udevice *dev, uint channel, bool enable);
79#endif
Simon Glassfc760cb2016-01-21 19:44:54 -070080};
81
82#define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops)
83
84/**
85 * pwm_set_config() - Set the PWM configuration
86 *
Alper Nebi Yasakfefa7132020-10-22 23:49:26 +030087 * Change both the PWM device's period and it's duty period if
88 * possible. Otherwise, set an appropriate duty period that best
89 * matches the given period_ns / duty_ns ratio for the device.
90 *
Simon Glassfc760cb2016-01-21 19:44:54 -070091 * @dev: PWM device to update
92 * @channel: PWM channel to update
93 * @period_ns: PWM period in nanoseconds
94 * @duty_ns: PWM duty period in nanoseconds
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010095 * Return: 0 if OK, -ve on error
Simon Glassfc760cb2016-01-21 19:44:54 -070096 */
97int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
98 uint duty_ns);
99
100/**
101 * pwm_set_enable() - Enable or disable the PWM
102 *
103 * @dev: PWM device to update
104 * @channel: PWM channel to update
105 * @enable: true to enable, false to disable
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100106 * Return: 0 if OK, -ve on error
Simon Glassfc760cb2016-01-21 19:44:54 -0700107 */
108int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
109
Kever Yang0b601112017-04-24 10:27:49 +0800110/**
111 * pwm_set_invert() - Set pwm default polarity
112 *
113 * @dev: PWM device to update
114 * @channel: PWM channel to update
115 * @polarity: true to invert, false to keep normal polarity
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100116 * Return: 0 if OK, -ve on error
Kever Yang0b601112017-04-24 10:27:49 +0800117 */
118int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
119
Simon Glassfc760cb2016-01-21 19:44:54 -0700120/* Legacy interface */
121#ifndef CONFIG_DM_PWM
Donghwa Lee3f129282011-03-07 21:11:42 +0000122int pwm_init (int pwm_id, int div, int invert);
123int pwm_config (int pwm_id, int duty_ns, int period_ns);
124int pwm_enable (int pwm_id);
125void pwm_disable (int pwm_id);
Simon Glassfc760cb2016-01-21 19:44:54 -0700126#endif
Donghwa Lee3f129282011-03-07 21:11:42 +0000127
128#endif /* _pwm_h_ */