blob: f0a47d8b9c5836b57438f0e619b73fe18c58b803 [file] [log] [blame]
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -07001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * * Copyright (c) 2011, The Linux Foundation. All rights reserved.
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -07003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080013 * * Neither the name of The Linux Foundation nor the names of its
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -070014 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __PMIC_PWM_H
31#define __PMIC_PWM_H
32
33#define USEC_PER_SEC 1000000L
34#define NSEC_PER_SEC 1000000000L
35#define NSEC_PER_USEC 1000
36
37#define PWM_FREQ_HZ 300
38#define PWM_LEVEL 15
39
40#define NUM_CLOCKS 3
41#define NUM_PRE_DIVIDE 3
42
43#define NUM_LPG_CTL_REGS 7
44
45#define PRE_DIVIDE_0 2
46#define PRE_DIVIDE_1 3
47#define PRE_DIVIDE_2 5
48
49#define PRE_DIVIDE_MIN PRE_DIVIDE_0
50#define PRE_DIVIDE_MAX PRE_DIVIDE_2
51
52#define PM_PWM_M_MIN 0
53#define PM_PWM_M_MAX 7
54
55#define NSEC_1000HZ (NSEC_PER_SEC / 1000)
56#define NSEC_32768HZ (NSEC_PER_SEC / 32768)
57#define NSEC_19P2MHZ (NSEC_PER_SEC / 19200000)
58
59#define CLK_PERIOD_MIN NSEC_19P2MHZ
60#define CLK_PERIOD_MAX NSEC_1000HZ
61
62#define MIN_MPT ((PRE_DIVIDE_MIN * CLK_PERIOD_MIN) << PM_PWM_M_MIN)
63#define MAX_MPT ((PRE_DIVIDE_MAX * CLK_PERIOD_MAX) << PM_PWM_M_MAX)
64
65/* The MAX value is computation limit. Hardware limit is 393 seconds. */
66#define PM_PWM_PERIOD_MAX (274 * USEC_PER_SEC)
67/* The MIN value is hardware limit. */
Ajay Dudanib01e5062011-12-03 23:23:42 -080068#define PM_PWM_PERIOD_MIN 7 /* micro seconds */
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -070069
70#define PWM_PERIOD_USEC (USEC_PER_SEC / PWM_FREQ_HZ)
71#define PWM_DUTY_LEVEL (PWM_PERIOD_USEC / PWM_LEVEL)
72
73/* Control 0 */
74#define PM_PWM_1KHZ_COUNT_MASK 0xF0
75#define PM_PWM_1KHZ_COUNT_SHIFT 4
76
77#define PM_PWM_1KHZ_COUNT_MAX 15
78
79#define PM_PWM_OUTPUT_EN 0x08
80#define PM_PWM_PWM_EN 0x04
81#define PM_PWM_RAMP_GEN_EN 0x02
82#define PM_PWM_RAMP_START 0x01
83
84#define PM_PWM_PWM_START (PM_PWM_OUTPUT_EN \
85 | PM_PWM_PWM_EN)
86#define PM_PWM_RAMP_GEN_START (PM_PWM_RAMP_GEN_EN \
87 | PM_PWM_RAMP_START)
88
89/* Control 1 */
90#define PM_PWM_REVERSE_EN 0x80
91#define PM_PWM_BYPASS_LUT 0x40
92#define PM_PWM_HIGH_INDEX_MASK 0x3F
93
94/* Control 2 */
95#define PM_PWM_LOOP_EN 0x80
96#define PM_PWM_RAMP_UP 0x40
97#define PM_PWM_LOW_INDEX_MASK 0x3F
98
99/* Control 3 */
100#define PM_PWM_VALUE_BIT7_0 0xFF
101#define PM_PWM_VALUE_BIT5_0 0x3F
102
103/* Control 4 */
104#define PM_PWM_VALUE_BIT8 0x80
105
106#define PM_PWM_CLK_SEL_MASK 0x60
107#define PM_PWM_CLK_SEL_SHIFT 5
108
109#define PM_PWM_CLK_SEL_NO 0
110#define PM_PWM_CLK_SEL_1KHZ 1
111#define PM_PWM_CLK_SEL_32KHZ 2
112#define PM_PWM_CLK_SEL_19P2MHZ 3
113
114#define PM_PWM_PREDIVIDE_MASK 0x18
115#define PM_PWM_PREDIVIDE_SHIFT 3
116
117#define PM_PWM_PREDIVIDE_2 0
118#define PM_PWM_PREDIVIDE_3 1
119#define PM_PWM_PREDIVIDE_5 2
120#define PM_PWM_PREDIVIDE_6 3
121
122#define PM_PWM_M_MASK 0x07
123#define PM_PWM_M_MIN 0
124#define PM_PWM_M_MAX 7
125
126/* Control 5 */
127#define PM_PWM_PAUSE_COUNT_HI_MASK 0xFC
128#define PM_PWM_PAUSE_COUNT_HI_SHIFT 2
129
130#define PM_PWM_PAUSE_ENABLE_HIGH 0x02
131#define PM_PWM_SIZE_9_BIT 0x01
132
133/* Control 6 */
134#define PM_PWM_PAUSE_COUNT_LO_MASK 0xFC
135#define PM_PWM_PAUSE_COUNT_LO_SHIFT 2
136
137#define PM_PWM_PAUSE_ENABLE_LOW 0x02
138#define PM_PWM_RESERVED 0x01
139
Ajay Dudanib01e5062011-12-03 23:23:42 -0800140#define PM_PWM_PAUSE_COUNT_MAX 56 /* < 2^6 = 64 */
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -0700141
142struct pm_pwm_config {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800143 int pwm_size; /* round up to 6 or 9 for 6/9-bit PWM SIZE */
Subbaraman Narayanamurthy8f1ffa52011-06-03 12:33:01 -0700144 int clk;
145 int pre_div;
146 int pre_div_exp;
147 int pwm_value;
148 int bypass_lut;
149 uint8_t pwm_ctl[NUM_LPG_CTL_REGS];
150};
151
152#endif