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