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