blob: de89a375b44befd5ec18fce55b8f02be81fe29b3 [file] [log] [blame]
Jay Chokshi12cc1dd2012-04-30 17:07:35 -07001/* Copyright (c) 2012, 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 __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 */
57enum 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 */
69enum 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 */
76enum 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 */
90struct 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 */
104struct pwm_duty_cycles {
105 int *duty_pcts;
106 int num_duty_pcts;
107 int duty_ms;
108 int start_idx;
109};
110
111int pwm_config_period(struct pwm_device *pwm,
112 struct pwm_period_config *pwm_p);
113
114int pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value);
115
116/*
117 * lut_params: Lookup table (LUT) parameters
118 * @start_idx: start index in lookup table from 0 to MAX-1
119 * @idx_len: number of index
120 * @pause_lo: pause time in millisecond at low index
121 * @pause_hi: pause time in millisecond at high index
122 * @ramp_step_ms: time before loading next LUT pattern in millisecond
123 * @flags: control flags
124 */
125struct lut_params {
126 int start_idx;
127 int idx_len;
128 int lut_pause_hi;
129 int lut_pause_lo;
130 int ramp_step_ms;
131 int flags;
132};
133
134int pwm_lut_config(struct pwm_device *pwm, int period_us,
135 int duty_pct[], struct lut_params lut_params);
136
137int pwm_lut_enable(struct pwm_device *pwm, int start);
138
139/* Standard APIs supported */
140/*
141 * pwm_request - request a PWM device
142 * @pwm_id: PWM id or channel
143 * @label: the label to identify the user
144 */
145
146/*
147 * pwm_free - free a PWM device
148 * @pwm: the PWM device
149 */
150
151/*
152 * pwm_config - change a PWM device configuration
153 * @pwm: the PWM device
154 * @period_us: period in microsecond
155 * @duty_us: duty cycle in microsecond
156 */
157
158/*
159 * pwm_enable - start a PWM output toggling
160 * @pwm: the PWM device
161 */
162
163/*
164 * pwm_disable - stop a PWM output toggling
165 * @pwm: the PWM device
166 */
167
168#endif /* __QPNP_PWM_H__ */