1 /*
2  * Tegra pulse width frequency modulator definitions
3  *
4  * Copyright (c) 2011 The Chromium OS Authors.
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 #ifndef __ASM_ARCH_TEGRA_PWM_H
10 #define __ASM_ARCH_TEGRA_PWM_H
11 
12 /* This is a single PWM channel */
13 struct pwm_ctlr {
14 	uint control;		/* Control register */
15 	uint reserved[3];	/* Space space */
16 };
17 
18 #define PWM_NUM_CHANNELS	4
19 
20 /* PWM_CONTROLLER_PWM_CSR_0/1/2/3_0 */
21 #define PWM_ENABLE_SHIFT	31
22 #define PWM_ENABLE_MASK	(0x1 << PWM_ENABLE_SHIFT)
23 
24 #define PWM_WIDTH_SHIFT	16
25 #define PWM_WIDTH_MASK		(0x7FFF << PWM_WIDTH_SHIFT)
26 
27 #define PWM_DIVIDER_SHIFT	0
28 #define PWM_DIVIDER_MASK	(0x1FFF << PWM_DIVIDER_SHIFT)
29 
30 /**
31  * Program the PWM with the given parameters.
32  *
33  * @param channel	PWM channel to update
34  * @param rate		Clock rate to use for PWM, or 0 to leave alone
35  * @param pulse_width	high pulse width: 0=always low, 1=1/256 pulse high,
36  *			n = n/256 pulse high
37  * @param freq_divider	frequency divider value (1 to use rate as is)
38  */
39 void pwm_enable(unsigned channel, int rate, int pulse_width, int freq_divider);
40 
41 /**
42  * Request a pwm channel as referenced by a device tree node.
43  *
44  * This channel can then be passed to pwm_enable().
45  *
46  * @param blob		Device tree blob
47  * @param node		Node containing reference to pwm
48  * @param prop_name	Property name of pwm reference
49  * @return channel number, if ok, else -1
50  */
51 int pwm_request(const void *blob, int node, const char *prop_name);
52 
53 /**
54  * Set up the pwm controller, by looking it up in the fdt.
55  *
56  * @return 0 if ok, -1 if the device tree node was not found or invalid.
57  */
58 int pwm_init(const void *blob);
59 
60 #endif	/* __ASM_ARCH_TEGRA_PWM_H */
61