Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010, 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 __PMIC8058_PWM_H__ |
| 14 | #define __PMIC8058_PWM_H__ |
| 15 | |
| 16 | /* The MAX value is computation limit. Hardware limit is 393 seconds. */ |
| 17 | #define PM_PWM_PERIOD_MAX (274 * USEC_PER_SEC) |
| 18 | /* The MIN value is hardware limit. */ |
| 19 | #define PM_PWM_PERIOD_MIN 7 /* micro seconds */ |
| 20 | |
| 21 | struct pm8058_pwm_pdata { |
| 22 | int (*config)(struct pwm_device *pwm, int ch, int on); |
| 23 | int (*enable)(struct pwm_device *pwm, int ch, int on); |
| 24 | }; |
| 25 | |
| 26 | #define PM_PWM_LUT_SIZE 64 |
| 27 | #define PM_PWM_LUT_DUTY_TIME_MAX 512 /* ms */ |
| 28 | #define PM_PWM_LUT_PAUSE_MAX (7000 * PM_PWM_LUT_DUTY_TIME_MAX) |
| 29 | |
| 30 | /* Flags for Look Up Table */ |
| 31 | #define PM_PWM_LUT_LOOP 0x01 |
| 32 | #define PM_PWM_LUT_RAMP_UP 0x02 |
| 33 | #define PM_PWM_LUT_REVERSE 0x04 |
| 34 | #define PM_PWM_LUT_PAUSE_HI_EN 0x10 |
| 35 | #define PM_PWM_LUT_PAUSE_LO_EN 0x20 |
| 36 | |
| 37 | #define PM_PWM_LUT_NO_TABLE 0x100 |
| 38 | |
| 39 | /* PWM LED ID */ |
| 40 | #define PM_PWM_LED_0 0 |
| 41 | #define PM_PWM_LED_1 1 |
| 42 | #define PM_PWM_LED_2 2 |
| 43 | #define PM_PWM_LED_KPD 3 |
| 44 | #define PM_PWM_LED_FLASH 4 |
| 45 | #define PM_PWM_LED_FLASH1 5 |
| 46 | |
| 47 | /* PWM LED configuration mode */ |
| 48 | #define PM_PWM_CONF_NONE 0x0 |
| 49 | #define PM_PWM_CONF_PWM1 0x1 |
| 50 | #define PM_PWM_CONF_PWM2 0x2 |
| 51 | #define PM_PWM_CONF_PWM3 0x3 |
| 52 | #define PM_PWM_CONF_DTEST1 0x4 |
| 53 | #define PM_PWM_CONF_DTEST2 0x5 |
| 54 | #define PM_PWM_CONF_DTEST3 0x6 |
| 55 | #define PM_PWM_CONF_DTEST4 0x7 |
| 56 | |
Willie Ruan | d3337ed | 2011-07-04 23:16:22 -0700 | [diff] [blame] | 57 | /** |
| 58 | * PWM frequency/period control |
| 59 | * |
| 60 | * PWM Frequency = ClockFrequency / (N * T) |
| 61 | * or |
| 62 | * PWM Period = Clock Period * (N * T) |
| 63 | * where |
| 64 | * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size |
| 65 | * T = Pre-divide * 2^m, m = 0..7 (exponent) |
| 66 | * |
| 67 | */ |
| 68 | |
| 69 | enum pm_pwm_size { |
| 70 | PM_PWM_SIZE_6BIT = 6, |
| 71 | PM_PWM_SIZE_9BIT = 9, |
| 72 | }; |
| 73 | |
| 74 | enum pm_pwm_clk { |
| 75 | PM_PWM_CLK_1KHZ, |
| 76 | PM_PWM_CLK_32KHZ, |
| 77 | PM_PWM_CLK_19P2MHZ, |
| 78 | }; |
| 79 | |
| 80 | enum pm_pwm_pre_div { |
| 81 | PM_PWM_PDIV_2, |
| 82 | PM_PWM_PDIV_3, |
| 83 | PM_PWM_PDIV_5, |
| 84 | PM_PWM_PDIV_6, |
| 85 | }; |
| 86 | |
Willie Ruan | 368db79 | 2011-07-05 08:09:58 -0700 | [diff] [blame] | 87 | /** |
| 88 | * struct pm8058_pwm_period - PWM period structure |
| 89 | * @pwm_size: enum pm_pwm_size |
| 90 | * @clk: enum pm_pwm_clk |
| 91 | * @pre_div: enum pm_pwm_pre_div |
| 92 | * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7 |
| 93 | */ |
Willie Ruan | d3337ed | 2011-07-04 23:16:22 -0700 | [diff] [blame] | 94 | struct pm8058_pwm_period { |
| 95 | enum pm_pwm_size pwm_size; |
| 96 | enum pm_pwm_clk clk; |
| 97 | enum pm_pwm_pre_div pre_div; |
Willie Ruan | 368db79 | 2011-07-05 08:09:58 -0700 | [diff] [blame] | 98 | int pre_div_exp; |
Willie Ruan | d3337ed | 2011-07-04 23:16:22 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Willie Ruan | 368db79 | 2011-07-05 08:09:58 -0700 | [diff] [blame] | 101 | /** |
| 102 | * pm8058_pwm_config_period - change PWM period |
| 103 | * |
| 104 | * @pwm: the PWM device |
| 105 | * @pwm_p: period in struct pm8058_pwm_period |
| 106 | */ |
| 107 | int pm8058_pwm_config_period(struct pwm_device *pwm, |
| 108 | struct pm8058_pwm_period *pwm_p); |
| 109 | |
| 110 | /** |
| 111 | * pm8058_pwm_config_duty_cycle - change PWM duty cycle |
| 112 | * |
| 113 | * @pwm: the PWM device |
| 114 | * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size) |
| 115 | */ |
| 116 | int pm8058_pwm_config_duty_cycle(struct pwm_device *pwm, int pwm_value); |
| 117 | |
| 118 | /** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | * pm8058_pwm_lut_config - change a PWM device configuration to use LUT |
| 120 | * |
| 121 | * @pwm: the PWM device |
| 122 | * @period_us: period in micro second |
| 123 | * @duty_pct: arrary of duty cycles in percent, like 20, 50. |
| 124 | * @duty_time_ms: time for each duty cycle in millisecond |
| 125 | * @start_idx: start index in lookup table from 0 to MAX-1 |
| 126 | * @idx_len: number of index |
| 127 | * @pause_lo: pause time in millisecond at low index |
| 128 | * @pause_hi: pause time in millisecond at high index |
| 129 | * @flags: control flags |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 130 | */ |
| 131 | int pm8058_pwm_lut_config(struct pwm_device *pwm, int period_us, |
| 132 | int duty_pct[], int duty_time_ms, int start_idx, |
| 133 | int len, int pause_lo, int pause_hi, int flags); |
| 134 | |
Willie Ruan | 368db79 | 2011-07-05 08:09:58 -0700 | [diff] [blame] | 135 | /** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | * pm8058_pwm_lut_enable - control a PWM device to start/stop LUT ramp |
| 137 | * |
| 138 | * @pwm: the PWM device |
| 139 | * @start: to start (1), or stop (0) |
| 140 | */ |
| 141 | int pm8058_pwm_lut_enable(struct pwm_device *pwm, int start); |
| 142 | |
| 143 | int pm8058_pwm_set_dtest(struct pwm_device *pwm, int enable); |
| 144 | |
| 145 | int pm8058_pwm_config_led(struct pwm_device *pwm, int id, |
| 146 | int mode, int max_current); |
| 147 | |
| 148 | #endif /* __PMIC8058_PWM_H__ */ |