Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Donghwa Lee | 85f5df2 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 2 | /* |
| 3 | * header file for pwm driver. |
| 4 | * |
Simon Glass | b3f0756 | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 5 | * Copyright 2016 Google Inc. |
Donghwa Lee | 85f5df2 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 6 | * Copyright (c) 2011 samsung electronics |
| 7 | * Donghwa Lee <dh09.lee@samsung.com> |
Donghwa Lee | 85f5df2 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef _pwm_h_ |
| 11 | #define _pwm_h_ |
| 12 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | struct udevice; |
| 14 | |
Simon Glass | b3f0756 | 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 | * |
| 20 | * @dev: PWM device to update |
| 21 | * @channel: PWM channel to update |
| 22 | * @period_ns: PWM period in nanoseconds |
| 23 | * @duty_ns: PWM duty period in nanoseconds |
| 24 | * @return 0 if OK, -ve on error |
| 25 | */ |
| 26 | int (*set_config)(struct udevice *dev, uint channel, uint period_ns, |
| 27 | uint duty_ns); |
| 28 | |
| 29 | /** |
| 30 | * set_enable() - Enable or disable the PWM |
| 31 | * |
| 32 | * @dev: PWM device to update |
| 33 | * @channel: PWM channel to update |
| 34 | * @enable: true to enable, false to disable |
| 35 | * @return 0 if OK, -ve on error |
| 36 | */ |
| 37 | int (*set_enable)(struct udevice *dev, uint channel, bool enable); |
Kever Yang | 4c08742 | 2017-04-24 10:27:49 +0800 | [diff] [blame] | 38 | /** |
| 39 | * set_invert() - Set the PWM invert |
| 40 | * |
| 41 | * @dev: PWM device to update |
| 42 | * @channel: PWM channel to update |
| 43 | * @polarity: true to invert, false to keep normal polarity |
| 44 | * @return 0 if OK, -ve on error |
| 45 | */ |
| 46 | int (*set_invert)(struct udevice *dev, uint channel, bool polarity); |
Simon Glass | b3f0756 | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | #define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops) |
| 50 | |
| 51 | /** |
| 52 | * pwm_set_config() - Set the PWM configuration |
| 53 | * |
| 54 | * @dev: PWM device to update |
| 55 | * @channel: PWM channel to update |
| 56 | * @period_ns: PWM period in nanoseconds |
| 57 | * @duty_ns: PWM duty period in nanoseconds |
| 58 | * @return 0 if OK, -ve on error |
| 59 | */ |
| 60 | int pwm_set_config(struct udevice *dev, uint channel, uint period_ns, |
| 61 | uint duty_ns); |
| 62 | |
| 63 | /** |
| 64 | * pwm_set_enable() - Enable or disable the PWM |
| 65 | * |
| 66 | * @dev: PWM device to update |
| 67 | * @channel: PWM channel to update |
| 68 | * @enable: true to enable, false to disable |
| 69 | * @return 0 if OK, -ve on error |
| 70 | */ |
| 71 | int pwm_set_enable(struct udevice *dev, uint channel, bool enable); |
| 72 | |
Kever Yang | 4c08742 | 2017-04-24 10:27:49 +0800 | [diff] [blame] | 73 | /** |
| 74 | * pwm_set_invert() - Set pwm default polarity |
| 75 | * |
| 76 | * @dev: PWM device to update |
| 77 | * @channel: PWM channel to update |
| 78 | * @polarity: true to invert, false to keep normal polarity |
| 79 | * @return 0 if OK, -ve on error |
| 80 | */ |
| 81 | int pwm_set_invert(struct udevice *dev, uint channel, bool polarity); |
| 82 | |
Simon Glass | b3f0756 | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 83 | /* Legacy interface */ |
| 84 | #ifndef CONFIG_DM_PWM |
Donghwa Lee | 85f5df2 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 85 | int pwm_init (int pwm_id, int div, int invert); |
| 86 | int pwm_config (int pwm_id, int duty_ns, int period_ns); |
| 87 | int pwm_enable (int pwm_id); |
| 88 | void pwm_disable (int pwm_id); |
Simon Glass | b3f0756 | 2016-01-21 19:44:54 -0700 | [diff] [blame] | 89 | #endif |
Donghwa Lee | 85f5df2 | 2011-03-07 21:11:42 +0000 | [diff] [blame] | 90 | |
| 91 | #endif /* _pwm_h_ */ |