blob: b15645d00289faf33a0aa5c80a7105d4d7acc034 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* 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 Ruan719c6762011-08-25 11:03:14 -070037 * 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
48enum pm_pwm_size {
49 PM_PWM_SIZE_6BIT = 6,
50 PM_PWM_SIZE_9BIT = 9,
51};
52
53enum pm_pwm_clk {
54 PM_PWM_CLK_1KHZ,
55 PM_PWM_CLK_32KHZ,
56 PM_PWM_CLK_19P2MHZ,
57};
58
59enum 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 */
73struct 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 Chokshi4acbdd52011-09-16 17:09:44 -070081 * pm8xxx_pwm_config_period - change PWM period
82 *
83 * @pwm: the PWM device
84 * @pwm_p: period in struct pm8xxx_pwm_period
85 */
86int pm8xxx_pwm_config_period(struct pwm_device *pwm,
87 struct pm8xxx_pwm_period *pwm_p);
88
89/**
90 * pm8xxx_pwm_config_pwm_value - change a PWM device configuration
91 * @pwm: the PWM device
92 * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size)
93 */
94int pm8xxx_pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value);
95
96/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 * pm8xxx_pwm_lut_config - change a PWM device configuration to use LUT
98 * @pwm: the PWM device
99 * @period_us: period in micro second
100 * @duty_pct: arrary of duty cycles in percent, like 20, 50.
101 * @duty_time_ms: time for each duty cycle in millisecond
102 * @start_idx: start index in lookup table from 0 to MAX-1
103 * @idx_len: number of index
104 * @pause_lo: pause time in millisecond at low index
105 * @pause_hi: pause time in millisecond at high index
106 * @flags: control flags
107 */
108int pm8xxx_pwm_lut_config(struct pwm_device *pwm, int period_us,
109 int duty_pct[], int duty_time_ms, int start_idx,
110 int len, int pause_lo, int pause_hi, int flags);
111
112/**
113 * pm8xxx_pwm_lut_enable - control a PWM device to start/stop LUT ramp
114 * @pwm: the PWM device
115 * @start: to start (1), or stop (0)
116 */
117int pm8xxx_pwm_lut_enable(struct pwm_device *pwm, int start);
118
119/* Standard APIs supported */
120/**
121 * pwm_request - request a PWM device
122 * @pwm_id: PWM id or channel
123 * @label: the label to identify the user
124 */
125
126/**
127 * pwm_free - free a PWM device
128 * @pwm: the PWM device
129 */
130
131/**
132 * pwm_config - change a PWM device configuration
133 * @pwm: the PWM device
134 * @period_us: period in microsecond
135 * @duty_us: duty cycle in microsecond
136 */
137
138/**
139 * pwm_enable - start a PWM output toggling
140 * @pwm: the PWM device
141 */
142
143/**
144 * pwm_disable - stop a PWM output toggling
145 * @pwm: the PWM device
146 */
147
148#endif /* __PM8XXX_PWM_H__ */