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