blob: 2eca994b559bbd3fed707f4a68791cf1b2762def [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/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081 * pm8xxx_pwm_lut_config - change a PWM device configuration to use LUT
82 * @pwm: the PWM device
83 * @period_us: period in micro second
84 * @duty_pct: arrary of duty cycles in percent, like 20, 50.
85 * @duty_time_ms: time for each duty cycle in millisecond
86 * @start_idx: start index in lookup table from 0 to MAX-1
87 * @idx_len: number of index
88 * @pause_lo: pause time in millisecond at low index
89 * @pause_hi: pause time in millisecond at high index
90 * @flags: control flags
91 */
92int pm8xxx_pwm_lut_config(struct pwm_device *pwm, int period_us,
93 int duty_pct[], int duty_time_ms, int start_idx,
94 int len, int pause_lo, int pause_hi, int flags);
95
96/**
97 * pm8xxx_pwm_lut_enable - control a PWM device to start/stop LUT ramp
98 * @pwm: the PWM device
99 * @start: to start (1), or stop (0)
100 */
101int pm8xxx_pwm_lut_enable(struct pwm_device *pwm, int start);
102
103/* Standard APIs supported */
104/**
105 * pwm_request - request a PWM device
106 * @pwm_id: PWM id or channel
107 * @label: the label to identify the user
108 */
109
110/**
111 * pwm_free - free a PWM device
112 * @pwm: the PWM device
113 */
114
115/**
116 * pwm_config - change a PWM device configuration
117 * @pwm: the PWM device
118 * @period_us: period in microsecond
119 * @duty_us: duty cycle in microsecond
120 */
121
122/**
123 * pwm_enable - start a PWM output toggling
124 * @pwm: the PWM device
125 */
126
127/**
128 * pwm_disable - stop a PWM output toggling
129 * @pwm: the PWM device
130 */
131
132#endif /* __PM8XXX_PWM_H__ */