blob: 47ebe06a16b77dea0b212a6edae196fc8fa45666 [file] [log] [blame]
Prasad Sodagudib0769af2013-05-31 12:37:53 +05301/* Copyright (c) 2011-2013, 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
Prasad Sodagudib0769af2013-05-31 12:37:53 +053035#define PM_PWM_BANK_LO 0x1000
36#define PM_PWM_BANK_HI 0x2000
37
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038/**
Willie Ruan719c6762011-08-25 11:03:14 -070039 * PWM frequency/period control
40 *
41 * PWM Frequency = ClockFrequency / (N * T)
42 * or
43 * PWM Period = Clock Period * (N * T)
44 * where
45 * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size
46 * T = Pre-divide * 2^m, m = 0..7 (exponent)
47 *
48 */
49
50enum pm_pwm_size {
51 PM_PWM_SIZE_6BIT = 6,
52 PM_PWM_SIZE_9BIT = 9,
53};
54
55enum pm_pwm_clk {
56 PM_PWM_CLK_1KHZ,
57 PM_PWM_CLK_32KHZ,
58 PM_PWM_CLK_19P2MHZ,
59};
60
61enum pm_pwm_pre_div {
62 PM_PWM_PDIV_2,
63 PM_PWM_PDIV_3,
64 PM_PWM_PDIV_5,
65 PM_PWM_PDIV_6,
66};
67
68/**
69 * struct pm8xxx_pwm_period - PWM period structure
70 * @pwm_size: enum pm_pwm_size
71 * @clk: enum pm_pwm_clk
72 * @pre_div: enum pm_pwm_pre_div
73 * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7
74 */
75struct pm8xxx_pwm_period {
76 enum pm_pwm_size pwm_size;
77 enum pm_pwm_clk clk;
78 enum pm_pwm_pre_div pre_div;
79 int pre_div_exp;
80};
81
82/**
Jay Chokshi868312e2011-09-16 13:57:13 -070083 * struct pm8xxx_pwm_duty_cycles - PWM duty cycle info
84 * duty_pcts - pointer to an array of duty percentage for a pwm period
85 * num_duty_pcts - total entries in duty_pcts array
86 * duty_ms - duty cycle time in ms
87 * start_idx - index in the LUT
88 */
89struct pm8xxx_pwm_duty_cycles {
90 int *duty_pcts;
91 int num_duty_pcts;
92 int duty_ms;
93 int start_idx;
94};
95
96/**
Jay Chokshib0a0fa52012-02-23 16:18:44 -080097 * struct pm8xxx_pwm_platform_data - PWM platform data
98 * dtest_channel - Enable LPG DTEST mode for this LPG channel
99 */
100struct pm8xxx_pwm_platform_data {
101 int dtest_channel;
102};
103
104/**
Jay Chokshi4acbdd52011-09-16 17:09:44 -0700105 * pm8xxx_pwm_config_period - change PWM period
106 *
107 * @pwm: the PWM device
108 * @pwm_p: period in struct pm8xxx_pwm_period
109 */
110int pm8xxx_pwm_config_period(struct pwm_device *pwm,
111 struct pm8xxx_pwm_period *pwm_p);
112
113/**
114 * pm8xxx_pwm_config_pwm_value - change a PWM device configuration
115 * @pwm: the PWM device
116 * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size)
117 */
118int pm8xxx_pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value);
119
120/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121 * pm8xxx_pwm_lut_config - change a PWM device configuration to use LUT
122 * @pwm: the PWM device
123 * @period_us: period in micro second
124 * @duty_pct: arrary of duty cycles in percent, like 20, 50.
125 * @duty_time_ms: time for each duty cycle in millisecond
126 * @start_idx: start index in lookup table from 0 to MAX-1
127 * @idx_len: number of index
128 * @pause_lo: pause time in millisecond at low index
129 * @pause_hi: pause time in millisecond at high index
130 * @flags: control flags
131 */
132int pm8xxx_pwm_lut_config(struct pwm_device *pwm, int period_us,
133 int duty_pct[], int duty_time_ms, int start_idx,
134 int len, int pause_lo, int pause_hi, int flags);
135
136/**
137 * pm8xxx_pwm_lut_enable - control a PWM device to start/stop LUT ramp
138 * @pwm: the PWM device
139 * @start: to start (1), or stop (0)
140 */
141int pm8xxx_pwm_lut_enable(struct pwm_device *pwm, int start);
142
143/* Standard APIs supported */
144/**
145 * pwm_request - request a PWM device
146 * @pwm_id: PWM id or channel
147 * @label: the label to identify the user
148 */
149
150/**
151 * pwm_free - free a PWM device
152 * @pwm: the PWM device
153 */
154
155/**
156 * pwm_config - change a PWM device configuration
157 * @pwm: the PWM device
158 * @period_us: period in microsecond
159 * @duty_us: duty cycle in microsecond
160 */
161
162/**
163 * pwm_enable - start a PWM output toggling
164 * @pwm: the PWM device
165 */
166
167/**
168 * pwm_disable - stop a PWM output toggling
169 * @pwm: the PWM device
170 */
171
172#endif /* __PM8XXX_PWM_H__ */