Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Donghwa Lee | 3f12928 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 2 | /* |
| 3 | * header file for pwm driver. |
| 4 | * |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 5 | * Copyright 2016 Google Inc. |
Donghwa Lee | 3f12928 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 6 | * Copyright (c) 2011 samsung electronics |
| 7 | * Donghwa Lee <dh09.lee@samsung.com> |
Donghwa Lee | 3f12928 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef _pwm_h_ |
| 11 | #define _pwm_h_ |
| 12 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | struct udevice; |
| 14 | |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 15 | /* struct pwm_ops: Operations for the PWM uclass */ |
| 16 | struct pwm_ops { |
| 17 | /** |
| 18 | * set_config() - Set the PWM configuration |
| 19 | * |
Alper Nebi Yasak | fefa713 | 2020-10-22 23:49:26 +0300 | [diff] [blame] | 20 | * 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 Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 24 | * @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 Yang | 0b60111 | 2017-04-24 10:27:49 +0800 | [diff] [blame] | 42 | /** |
| 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); |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops) |
| 54 | |
| 55 | /** |
| 56 | * pwm_set_config() - Set the PWM configuration |
| 57 | * |
Alper Nebi Yasak | fefa713 | 2020-10-22 23:49:26 +0300 | [diff] [blame] | 58 | * Change both the PWM device's period and it's duty period if |
| 59 | * possible. Otherwise, set an appropriate duty period that best |
| 60 | * matches the given period_ns / duty_ns ratio for the device. |
| 61 | * |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 62 | * @dev: PWM device to update |
| 63 | * @channel: PWM channel to update |
| 64 | * @period_ns: PWM period in nanoseconds |
| 65 | * @duty_ns: PWM duty period in nanoseconds |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 66 | * Return: 0 if OK, -ve on error |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 67 | */ |
| 68 | int pwm_set_config(struct udevice *dev, uint channel, uint period_ns, |
| 69 | uint duty_ns); |
| 70 | |
| 71 | /** |
| 72 | * pwm_set_enable() - Enable or disable the PWM |
| 73 | * |
| 74 | * @dev: PWM device to update |
| 75 | * @channel: PWM channel to update |
| 76 | * @enable: true to enable, false to disable |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 77 | * Return: 0 if OK, -ve on error |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 78 | */ |
| 79 | int pwm_set_enable(struct udevice *dev, uint channel, bool enable); |
| 80 | |
Kever Yang | 0b60111 | 2017-04-24 10:27:49 +0800 | [diff] [blame] | 81 | /** |
| 82 | * pwm_set_invert() - Set pwm default polarity |
| 83 | * |
| 84 | * @dev: PWM device to update |
| 85 | * @channel: PWM channel to update |
| 86 | * @polarity: true to invert, false to keep normal polarity |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 87 | * Return: 0 if OK, -ve on error |
Kever Yang | 0b60111 | 2017-04-24 10:27:49 +0800 | [diff] [blame] | 88 | */ |
| 89 | int pwm_set_invert(struct udevice *dev, uint channel, bool polarity); |
| 90 | |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 91 | /* Legacy interface */ |
| 92 | #ifndef CONFIG_DM_PWM |
Donghwa Lee | 3f12928 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 93 | int pwm_init (int pwm_id, int div, int invert); |
| 94 | int pwm_config (int pwm_id, int duty_ns, int period_ns); |
| 95 | int pwm_enable (int pwm_id); |
| 96 | void pwm_disable (int pwm_id); |
Simon Glass | fc760cb | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 97 | #endif |
Donghwa Lee | 3f12928 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 98 | |
| 99 | #endif /* _pwm_h_ */ |