2 * Tegra2 pulse width frequency modulator definitions
4 * Copyright (c) 2011 The Chromium OS Authors.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/arch/clock.h>
28 #include <asm/arch/pwm.h>
31 struct pwm_ctlr *pwm; /* Registers for our pwm controller */
32 int pwm_node; /* PWM device tree node */
35 void pwm_enable(unsigned channel, int rate, int pulse_width, int freq_divider)
39 assert(channel < PWM_NUM_CHANNELS);
41 /* TODO: Can we use clock_adjust_periph_pll_div() here? */
42 clock_start_periph_pll(PERIPH_ID_PWM, CLOCK_ID_SFROM32KHZ, rate);
44 reg = PWM_ENABLE_MASK;
45 reg |= pulse_width << PWM_WIDTH_SHIFT;
46 reg |= freq_divider << PWM_DIVIDER_SHIFT;
47 writel(reg, &local.pwm[channel].control);
48 debug("%s: channel=%d, rate=%d\n", __func__, channel, rate);
51 int pwm_request(const void *blob, int node, const char *prop_name)
56 if (fdtdec_get_int_array(blob, node, prop_name, data,
58 debug("%s: Cannot decode PWM property '%s'\n", __func__,
63 pwm_node = fdt_node_offset_by_phandle(blob, data[0]);
64 if (pwm_node != local.pwm_node) {
65 debug("%s: PWM property '%s' phandle %d not recognised"
66 "- expecting %d\n", __func__, prop_name, data[0],
70 if (data[1] >= PWM_NUM_CHANNELS) {
71 debug("%s: PWM property '%s': invalid channel %u\n", __func__,
77 * TODO: We could maintain a list of requests, but it might not be
78 * worth it for U-Boot.
83 int pwm_init(const void *blob)
85 local.pwm_node = fdtdec_next_compatible(blob, 0,
86 COMPAT_NVIDIA_TEGRA20_PWM);
87 if (local.pwm_node < 0) {
88 debug("%s: Cannot find device tree node\n", __func__);
92 local.pwm = (struct pwm_ctlr *)fdtdec_get_addr(blob, local.pwm_node,
94 if (local.pwm == (struct pwm_ctlr *)FDT_ADDR_T_NONE) {
95 debug("%s: Cannot find pwm reg address\n", __func__);
98 debug("Tegra PWM at %p, node %d\n", local.pwm, local.pwm_node);