Xu Kai | 0e8f316 | 2013-12-04 18:25:30 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Jay Chokshi | 12cc1dd | 2012-04-30 17:07:35 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __QPNP_PWM_H__ |
| 14 | #define __QPNP_PWM_H__ |
| 15 | |
| 16 | #include <linux/pwm.h> |
| 17 | |
| 18 | /* usec: 19.2M, n=6, m=0, pre=2 */ |
| 19 | #define PM_PWM_PERIOD_MIN 7 |
| 20 | /* 1K, n=9, m=7, pre=6 */ |
| 21 | #define PM_PWM_PERIOD_MAX (384 * USEC_PER_SEC) |
| 22 | #define PM_PWM_LUT_RAMP_STEP_TIME_MAX 499 |
| 23 | #define PM_PWM_MAX_PAUSE_CNT 8191 |
| 24 | /* |
| 25 | * Formula from HSID, |
| 26 | * pause_time (hi/lo) = (pause_code - 1)*(duty_ms) |
| 27 | */ |
| 28 | #define PM_PWM_LUT_PAUSE_MAX \ |
| 29 | ((PM_PWM_MAX_PAUSE_CNT - 1) * PM_PWM_LUT_RAMP_STEP_TIME_MAX) /* ms */ |
| 30 | |
| 31 | /* Flags for Look Up Table */ |
| 32 | #define PM_PWM_LUT_LOOP 0x01 |
| 33 | #define PM_PWM_LUT_RAMP_UP 0x02 |
| 34 | #define PM_PWM_LUT_REVERSE 0x04 |
| 35 | #define PM_PWM_LUT_PAUSE_HI_EN 0x08 |
| 36 | #define PM_PWM_LUT_PAUSE_LO_EN 0x10 |
| 37 | |
| 38 | #define PM_PWM_LUT_NO_TABLE 0x20 |
| 39 | #define PM_PWM_LUT_USE_RAW_VALUE 0x40 |
| 40 | |
| 41 | /* |
| 42 | * PWM frequency/period control |
| 43 | * |
| 44 | * PWM Frequency = ClockFrequency / (N * T) |
| 45 | * or |
| 46 | * PWM Period = Clock Period * (N * T) |
| 47 | * where |
| 48 | * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size |
| 49 | * T = Pre-divide * 2^m, m = 0..7 (exponent) |
| 50 | */ |
| 51 | |
| 52 | /* |
| 53 | * enum pm_pwm_size - PWM bit mode selection |
| 54 | * %PM_PWM_SIZE_6BIT - Select 6 bit mode; 64 levels |
| 55 | * %PM_PWM_SIZE_9BIT - Select 9 bit mode; 512 levels |
| 56 | */ |
| 57 | enum pm_pwm_size { |
| 58 | PM_PWM_SIZE_6BIT = 6, |
| 59 | PM_PWM_SIZE_9BIT = 9, |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * enum pm_pwm_clk - PWM clock selection |
| 64 | * %PM_PWM_CLK_1KHZ - 1KHz clock |
| 65 | * %PM_PWM_CLK_32KHZ - 32KHz clock |
| 66 | * %PM_PWM_CLK_19P2MHZ - 19.2MHz clock |
| 67 | * Note: Here 1KHz = 1024Hz |
| 68 | */ |
| 69 | enum pm_pwm_clk { |
| 70 | PM_PWM_CLK_1KHZ, |
| 71 | PM_PWM_CLK_32KHZ, |
| 72 | PM_PWM_CLK_19P2MHZ, |
| 73 | }; |
| 74 | |
| 75 | /* PWM pre-divider selection */ |
| 76 | enum pm_pwm_pre_div { |
| 77 | PM_PWM_PDIV_2, |
| 78 | PM_PWM_PDIV_3, |
| 79 | PM_PWM_PDIV_5, |
| 80 | PM_PWM_PDIV_6, |
| 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * struct pwm_period_config - PWM period configuration |
| 85 | * @pwm_size: enum pm_pwm_size |
| 86 | * @clk: enum pm_pwm_clk |
| 87 | * @pre_div: enum pm_pwm_pre_div |
| 88 | * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7 |
| 89 | */ |
| 90 | struct pwm_period_config { |
| 91 | enum pm_pwm_size pwm_size; |
| 92 | enum pm_pwm_clk clk; |
| 93 | enum pm_pwm_pre_div pre_div; |
| 94 | int pre_div_exp; |
| 95 | }; |
| 96 | |
| 97 | /* |
| 98 | * struct pwm_duty_cycles - PWM duty cycle info |
| 99 | * duty_pcts - pointer to an array of duty percentage for a pwm period |
| 100 | * num_duty_pcts - total entries in duty_pcts array |
| 101 | * duty_ms - duty cycle time in ms |
| 102 | * start_idx - index in the LUT |
| 103 | */ |
| 104 | struct pwm_duty_cycles { |
| 105 | int *duty_pcts; |
| 106 | int num_duty_pcts; |
| 107 | int duty_ms; |
| 108 | int start_idx; |
| 109 | }; |
| 110 | |
| 111 | int pwm_config_period(struct pwm_device *pwm, |
| 112 | struct pwm_period_config *pwm_p); |
| 113 | |
| 114 | int pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value); |
| 115 | |
| 116 | /* |
Jay Chokshi | 219fcfc | 2012-07-27 17:39:15 -0700 | [diff] [blame] | 117 | * enum pm_pwm_mode - PWM mode selection |
| 118 | * %PM_PWM_MODE_PWM - Select PWM mode |
| 119 | * %PM_PWM_MODE_LPG - Select LPG mode |
| 120 | */ |
| 121 | enum pm_pwm_mode { |
| 122 | PM_PWM_MODE_PWM, |
| 123 | PM_PWM_MODE_LPG, |
| 124 | }; |
| 125 | |
| 126 | int pwm_change_mode(struct pwm_device *pwm, enum pm_pwm_mode mode); |
| 127 | |
| 128 | /* |
Jay Chokshi | 12cc1dd | 2012-04-30 17:07:35 -0700 | [diff] [blame] | 129 | * lut_params: Lookup table (LUT) parameters |
| 130 | * @start_idx: start index in lookup table from 0 to MAX-1 |
| 131 | * @idx_len: number of index |
| 132 | * @pause_lo: pause time in millisecond at low index |
| 133 | * @pause_hi: pause time in millisecond at high index |
| 134 | * @ramp_step_ms: time before loading next LUT pattern in millisecond |
| 135 | * @flags: control flags |
| 136 | */ |
| 137 | struct lut_params { |
| 138 | int start_idx; |
| 139 | int idx_len; |
| 140 | int lut_pause_hi; |
| 141 | int lut_pause_lo; |
| 142 | int ramp_step_ms; |
| 143 | int flags; |
| 144 | }; |
| 145 | |
| 146 | int pwm_lut_config(struct pwm_device *pwm, int period_us, |
| 147 | int duty_pct[], struct lut_params lut_params); |
| 148 | |
Xu Kai | 0e8f316 | 2013-12-04 18:25:30 +0800 | [diff] [blame] | 149 | /* |
| 150 | * support microsecond level configuration |
| 151 | */ |
| 152 | int pwm_config_us(struct pwm_device *pwm, |
| 153 | int duty_us, int period_us); |
| 154 | |
Jay Chokshi | 12cc1dd | 2012-04-30 17:07:35 -0700 | [diff] [blame] | 155 | /* Standard APIs supported */ |
| 156 | /* |
| 157 | * pwm_request - request a PWM device |
| 158 | * @pwm_id: PWM id or channel |
| 159 | * @label: the label to identify the user |
| 160 | */ |
| 161 | |
| 162 | /* |
| 163 | * pwm_free - free a PWM device |
| 164 | * @pwm: the PWM device |
| 165 | */ |
| 166 | |
| 167 | /* |
| 168 | * pwm_config - change a PWM device configuration |
| 169 | * @pwm: the PWM device |
Xu Kai | 0e8f316 | 2013-12-04 18:25:30 +0800 | [diff] [blame] | 170 | * @period_ns: period in nanosecond |
| 171 | * @duty_ns: duty cycle in nanosecond |
Jay Chokshi | 12cc1dd | 2012-04-30 17:07:35 -0700 | [diff] [blame] | 172 | */ |
| 173 | |
| 174 | /* |
| 175 | * pwm_enable - start a PWM output toggling |
| 176 | * @pwm: the PWM device |
| 177 | */ |
| 178 | |
| 179 | /* |
| 180 | * pwm_disable - stop a PWM output toggling |
| 181 | * @pwm: the PWM device |
| 182 | */ |
| 183 | |
| 184 | #endif /* __QPNP_PWM_H__ */ |