13f129280SDonghwa Lee /* 23f129280SDonghwa Lee * header file for pwm driver. 33f129280SDonghwa Lee * 4fc760cb8SSimon Glass * Copyright 2016 Google Inc. 53f129280SDonghwa Lee * Copyright (c) 2011 samsung electronics 63f129280SDonghwa Lee * Donghwa Lee <dh09.lee@samsung.com> 73f129280SDonghwa Lee * 81a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 93f129280SDonghwa Lee */ 103f129280SDonghwa Lee 113f129280SDonghwa Lee #ifndef _pwm_h_ 123f129280SDonghwa Lee #define _pwm_h_ 133f129280SDonghwa Lee 14fc760cb8SSimon Glass /* struct pwm_ops: Operations for the PWM uclass */ 15fc760cb8SSimon Glass struct pwm_ops { 16fc760cb8SSimon Glass /** 17fc760cb8SSimon Glass * set_config() - Set the PWM configuration 18fc760cb8SSimon Glass * 19fc760cb8SSimon Glass * @dev: PWM device to update 20fc760cb8SSimon Glass * @channel: PWM channel to update 21fc760cb8SSimon Glass * @period_ns: PWM period in nanoseconds 22fc760cb8SSimon Glass * @duty_ns: PWM duty period in nanoseconds 23fc760cb8SSimon Glass * @return 0 if OK, -ve on error 24fc760cb8SSimon Glass */ 25fc760cb8SSimon Glass int (*set_config)(struct udevice *dev, uint channel, uint period_ns, 26fc760cb8SSimon Glass uint duty_ns); 27fc760cb8SSimon Glass 28fc760cb8SSimon Glass /** 29fc760cb8SSimon Glass * set_enable() - Enable or disable the PWM 30fc760cb8SSimon Glass * 31fc760cb8SSimon Glass * @dev: PWM device to update 32fc760cb8SSimon Glass * @channel: PWM channel to update 33fc760cb8SSimon Glass * @enable: true to enable, false to disable 34fc760cb8SSimon Glass * @return 0 if OK, -ve on error 35fc760cb8SSimon Glass */ 36fc760cb8SSimon Glass int (*set_enable)(struct udevice *dev, uint channel, bool enable); 37*0b60111aSKever Yang /** 38*0b60111aSKever Yang * set_invert() - Set the PWM invert 39*0b60111aSKever Yang * 40*0b60111aSKever Yang * @dev: PWM device to update 41*0b60111aSKever Yang * @channel: PWM channel to update 42*0b60111aSKever Yang * @polarity: true to invert, false to keep normal polarity 43*0b60111aSKever Yang * @return 0 if OK, -ve on error 44*0b60111aSKever Yang */ 45*0b60111aSKever Yang int (*set_invert)(struct udevice *dev, uint channel, bool polarity); 46fc760cb8SSimon Glass }; 47fc760cb8SSimon Glass 48fc760cb8SSimon Glass #define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops) 49fc760cb8SSimon Glass 50fc760cb8SSimon Glass /** 51fc760cb8SSimon Glass * pwm_set_config() - Set the PWM configuration 52fc760cb8SSimon Glass * 53fc760cb8SSimon Glass * @dev: PWM device to update 54fc760cb8SSimon Glass * @channel: PWM channel to update 55fc760cb8SSimon Glass * @period_ns: PWM period in nanoseconds 56fc760cb8SSimon Glass * @duty_ns: PWM duty period in nanoseconds 57fc760cb8SSimon Glass * @return 0 if OK, -ve on error 58fc760cb8SSimon Glass */ 59fc760cb8SSimon Glass int pwm_set_config(struct udevice *dev, uint channel, uint period_ns, 60fc760cb8SSimon Glass uint duty_ns); 61fc760cb8SSimon Glass 62fc760cb8SSimon Glass /** 63fc760cb8SSimon Glass * pwm_set_enable() - Enable or disable the PWM 64fc760cb8SSimon Glass * 65fc760cb8SSimon Glass * @dev: PWM device to update 66fc760cb8SSimon Glass * @channel: PWM channel to update 67fc760cb8SSimon Glass * @enable: true to enable, false to disable 68fc760cb8SSimon Glass * @return 0 if OK, -ve on error 69fc760cb8SSimon Glass */ 70fc760cb8SSimon Glass int pwm_set_enable(struct udevice *dev, uint channel, bool enable); 71fc760cb8SSimon Glass 72*0b60111aSKever Yang /** 73*0b60111aSKever Yang * pwm_set_invert() - Set pwm default polarity 74*0b60111aSKever Yang * 75*0b60111aSKever Yang * @dev: PWM device to update 76*0b60111aSKever Yang * @channel: PWM channel to update 77*0b60111aSKever Yang * @polarity: true to invert, false to keep normal polarity 78*0b60111aSKever Yang * @return 0 if OK, -ve on error 79*0b60111aSKever Yang */ 80*0b60111aSKever Yang int pwm_set_invert(struct udevice *dev, uint channel, bool polarity); 81*0b60111aSKever Yang 82fc760cb8SSimon Glass /* Legacy interface */ 83fc760cb8SSimon Glass #ifndef CONFIG_DM_PWM 843f129280SDonghwa Lee int pwm_init (int pwm_id, int div, int invert); 853f129280SDonghwa Lee int pwm_config (int pwm_id, int duty_ns, int period_ns); 863f129280SDonghwa Lee int pwm_enable (int pwm_id); 873f129280SDonghwa Lee void pwm_disable (int pwm_id); 88fc760cb8SSimon Glass #endif 893f129280SDonghwa Lee 903f129280SDonghwa Lee #endif /* _pwm_h_ */ 91