Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 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 __PM8XXX_PWM_H__ |
| 14 | #define __PM8XXX_PWM_H__ |
| 15 | |
| 16 | #include <linux/pwm.h> |
| 17 | |
| 18 | #define PM8XXX_PWM_DEV_NAME "pm8xxx-pwm" |
| 19 | |
| 20 | #define PM8XXX_PWM_PERIOD_MAX (327 * USEC_PER_SEC) |
| 21 | #define PM8XXX_PWM_PERIOD_MIN 7 /* micro seconds */ |
| 22 | |
| 23 | #define PM_PWM_LUT_SIZE 64 |
| 24 | #define PM_PWM_LUT_DUTY_TIME_MAX 512 /* ms */ |
| 25 | #define PM_PWM_LUT_PAUSE_MAX (7000 * PM_PWM_LUT_DUTY_TIME_MAX) |
| 26 | |
| 27 | /* Flags for Look Up Table */ |
| 28 | #define PM_PWM_LUT_LOOP 0x01 |
| 29 | #define PM_PWM_LUT_RAMP_UP 0x02 |
| 30 | #define PM_PWM_LUT_REVERSE 0x04 |
| 31 | #define PM_PWM_LUT_PAUSE_HI_EN 0x10 |
| 32 | #define PM_PWM_LUT_PAUSE_LO_EN 0x20 |
| 33 | |
| 34 | #define PM_PWM_LUT_NO_TABLE 0x100 |
| 35 | |
| 36 | /** |
Willie Ruan | 719c676 | 2011-08-25 11:03:14 -0700 | [diff] [blame] | 37 | * PWM frequency/period control |
| 38 | * |
| 39 | * PWM Frequency = ClockFrequency / (N * T) |
| 40 | * or |
| 41 | * PWM Period = Clock Period * (N * T) |
| 42 | * where |
| 43 | * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size |
| 44 | * T = Pre-divide * 2^m, m = 0..7 (exponent) |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | enum pm_pwm_size { |
| 49 | PM_PWM_SIZE_6BIT = 6, |
| 50 | PM_PWM_SIZE_9BIT = 9, |
| 51 | }; |
| 52 | |
| 53 | enum pm_pwm_clk { |
| 54 | PM_PWM_CLK_1KHZ, |
| 55 | PM_PWM_CLK_32KHZ, |
| 56 | PM_PWM_CLK_19P2MHZ, |
| 57 | }; |
| 58 | |
| 59 | enum pm_pwm_pre_div { |
| 60 | PM_PWM_PDIV_2, |
| 61 | PM_PWM_PDIV_3, |
| 62 | PM_PWM_PDIV_5, |
| 63 | PM_PWM_PDIV_6, |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct pm8xxx_pwm_period - PWM period structure |
| 68 | * @pwm_size: enum pm_pwm_size |
| 69 | * @clk: enum pm_pwm_clk |
| 70 | * @pre_div: enum pm_pwm_pre_div |
| 71 | * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7 |
| 72 | */ |
| 73 | struct pm8xxx_pwm_period { |
| 74 | enum pm_pwm_size pwm_size; |
| 75 | enum pm_pwm_clk clk; |
| 76 | enum pm_pwm_pre_div pre_div; |
| 77 | int pre_div_exp; |
| 78 | }; |
| 79 | |
| 80 | /** |
Jay Chokshi | 868312e | 2011-09-16 13:57:13 -0700 | [diff] [blame] | 81 | * struct pm8xxx_pwm_duty_cycles - PWM duty cycle info |
| 82 | * duty_pcts - pointer to an array of duty percentage for a pwm period |
| 83 | * num_duty_pcts - total entries in duty_pcts array |
| 84 | * duty_ms - duty cycle time in ms |
| 85 | * start_idx - index in the LUT |
| 86 | */ |
| 87 | struct pm8xxx_pwm_duty_cycles { |
| 88 | int *duty_pcts; |
| 89 | int num_duty_pcts; |
| 90 | int duty_ms; |
| 91 | int start_idx; |
| 92 | }; |
| 93 | |
| 94 | /** |
Jay Chokshi | 4acbdd5 | 2011-09-16 17:09:44 -0700 | [diff] [blame] | 95 | * pm8xxx_pwm_config_period - change PWM period |
| 96 | * |
| 97 | * @pwm: the PWM device |
| 98 | * @pwm_p: period in struct pm8xxx_pwm_period |
| 99 | */ |
| 100 | int pm8xxx_pwm_config_period(struct pwm_device *pwm, |
| 101 | struct pm8xxx_pwm_period *pwm_p); |
| 102 | |
| 103 | /** |
| 104 | * pm8xxx_pwm_config_pwm_value - change a PWM device configuration |
| 105 | * @pwm: the PWM device |
| 106 | * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size) |
| 107 | */ |
| 108 | int pm8xxx_pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value); |
| 109 | |
| 110 | /** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | * pm8xxx_pwm_lut_config - change a PWM device configuration to use LUT |
| 112 | * @pwm: the PWM device |
| 113 | * @period_us: period in micro second |
| 114 | * @duty_pct: arrary of duty cycles in percent, like 20, 50. |
| 115 | * @duty_time_ms: time for each duty cycle in millisecond |
| 116 | * @start_idx: start index in lookup table from 0 to MAX-1 |
| 117 | * @idx_len: number of index |
| 118 | * @pause_lo: pause time in millisecond at low index |
| 119 | * @pause_hi: pause time in millisecond at high index |
| 120 | * @flags: control flags |
| 121 | */ |
| 122 | int pm8xxx_pwm_lut_config(struct pwm_device *pwm, int period_us, |
| 123 | int duty_pct[], int duty_time_ms, int start_idx, |
| 124 | int len, int pause_lo, int pause_hi, int flags); |
| 125 | |
| 126 | /** |
| 127 | * pm8xxx_pwm_lut_enable - control a PWM device to start/stop LUT ramp |
| 128 | * @pwm: the PWM device |
| 129 | * @start: to start (1), or stop (0) |
| 130 | */ |
| 131 | int pm8xxx_pwm_lut_enable(struct pwm_device *pwm, int start); |
| 132 | |
| 133 | /* Standard APIs supported */ |
| 134 | /** |
| 135 | * pwm_request - request a PWM device |
| 136 | * @pwm_id: PWM id or channel |
| 137 | * @label: the label to identify the user |
| 138 | */ |
| 139 | |
| 140 | /** |
| 141 | * pwm_free - free a PWM device |
| 142 | * @pwm: the PWM device |
| 143 | */ |
| 144 | |
| 145 | /** |
| 146 | * pwm_config - change a PWM device configuration |
| 147 | * @pwm: the PWM device |
| 148 | * @period_us: period in microsecond |
| 149 | * @duty_us: duty cycle in microsecond |
| 150 | */ |
| 151 | |
| 152 | /** |
| 153 | * pwm_enable - start a PWM output toggling |
| 154 | * @pwm: the PWM device |
| 155 | */ |
| 156 | |
| 157 | /** |
| 158 | * pwm_disable - stop a PWM output toggling |
| 159 | * @pwm: the PWM device |
| 160 | */ |
| 161 | |
| 162 | #endif /* __PM8XXX_PWM_H__ */ |