[U-Boot] [PATCH 06/17] tegra: Add support for PWFM

Simon Glass sjg at chromium.org
Sun Jan 15 01:47:18 CET 2012


The pulse width/frequency modulation peripheral supports generating
a repeating pulse. It is useful for controlling LCD brightness.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 arch/arm/cpu/armv7/tegra2/Makefile      |    1 +
 arch/arm/cpu/armv7/tegra2/pwfm.c        |   40 +++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/pwfm.h |   54 +++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/pwfm.c
 create mode 100644 arch/arm/include/asm/arch-tegra2/pwfm.h

diff --git a/arch/arm/cpu/armv7/tegra2/Makefile b/arch/arm/cpu/armv7/tegra2/Makefile
index 08c4137..9779e9e 100644
--- a/arch/arm/cpu/armv7/tegra2/Makefile
+++ b/arch/arm/cpu/armv7/tegra2/Makefile
@@ -39,6 +39,7 @@ COBJS-$(CONFIG_TEGRA_CLOCK_SCALING) += emc.o
 COBJS-$(CONFIG_TEGRA_PMU) += pmu.o
 COBJS-$(CONFIG_USB_EHCI_TEGRA) += usb.o
 COBJS-$(CONFIG_TEGRA2_LP0) += crypto.o warmboot.o warmboot_avp.o
+COBJS-$(CONFIG_VIDEO_TEGRA) += pwfm.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
diff --git a/arch/arm/cpu/armv7/tegra2/pwfm.c b/arch/arm/cpu/armv7/tegra2/pwfm.c
new file mode 100644
index 0000000..cdb0cbe
--- /dev/null
+++ b/arch/arm/cpu/armv7/tegra2/pwfm.c
@@ -0,0 +1,40 @@
+/*
+ * Tegra2 pulse width frequency modulator definitions
+ *
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/pwfm.h>
+
+void pwfm_enable(struct pwfm_ctlr *pwfm, int rate, int pulse_width,
+		int freq_divider)
+{
+	u32 reg;
+
+	/* TODO: Can we use clock_adjust_periph_pll_div() here? */
+	clock_start_periph_pll(PERIPH_ID_PWM, CLOCK_ID_SFROM32KHZ, rate);
+
+	reg = PWFM_ENABLE_MASK;
+	reg |= pulse_width << PWFM_WIDTH_SHIFT;
+	reg |= freq_divider << PWFM_DIVIDER_SHIFT;
+	writel(reg, &pwfm->control);
+}
diff --git a/arch/arm/include/asm/arch-tegra2/pwfm.h b/arch/arm/include/asm/arch-tegra2/pwfm.h
new file mode 100644
index 0000000..69e2edd
--- /dev/null
+++ b/arch/arm/include/asm/arch-tegra2/pwfm.h
@@ -0,0 +1,54 @@
+/*
+ * Tegra pulse width frequency modulator definitions
+ *
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __ASM_ARCH_TEGRA_PWFM_H
+#define __ASM_ARCH_TEGRA_PWFM_H
+
+/* This is a single PWFM channel */
+struct pwfm_ctlr {
+	uint control;		/* Control register */
+};
+
+/* PWM_CONTROLLER_PWM_CSR_0/1/2/3_0 */
+#define PWFM_ENABLE_SHIFT	31
+#define PWFM_ENABLE_MASK	(0x1 << PWFM_ENABLE_SHIFT)
+
+#define PWFM_WIDTH_SHIFT	16
+#define PWFM_WIDTH_MASK		(0x7FFF << PWFM_WIDTH_SHIFT)
+
+#define PWFM_DIVIDER_SHIFT	0
+#define PWFM_DIVIDER_MASK	(0x1FFF << PWFM_DIVIDER_SHIFT)
+
+/**
+ * Program the PWFM with the given parameters.
+ *
+ * @param pwfm		Pointer to PWFM register
+ * @param rate		Clock rate to use for PWFM
+ * @param pulse_width	high pulse width: 0=always low, 1=1/256 pulse high,
+ *			n = n/256 pulse high
+ * @param freq_divider	frequency divider value (1 to use rate as is)
+ */
+void pwfm_enable(struct pwfm_ctlr *pwfm, int rate, int pulse_width,
+		int freq_divider);
+
+#endif	/* __ASM_ARCH_TEGRA_PWFM_H */
-- 
1.7.7.3



More information about the U-Boot mailing list