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