Re: [PATCH v2 2/2] pwm: pwm-tiehrpwm: PWM driver support for EHRPWM

2012-07-26 Thread Thierry Reding
On Wed, Jul 25, 2012 at 04:58:19PM +0530, Philip, Avinash wrote:
> Enhanced high resolution PWM module (EHRPWM) hardware can be used to
> generate PWM output over 2 channels. This commit adds PWM driver support
> for EHRPWM device present on AM33XX SOC. Current implementation supports
> simple PWM functionality.
> 
> Reviewed-by: Vaibhav Bedia 
> Signed-off-by: Philip, Avinash 

Applied, with a minor cosmetic fixup. Thanks.

Thierry


pgpYKCapCYVBF.pgp
Description: PGP signature


[PATCH v2 2/2] pwm: pwm-tiehrpwm: PWM driver support for EHRPWM

2012-07-25 Thread Philip, Avinash
Enhanced high resolution PWM module (EHRPWM) hardware can be used to
generate PWM output over 2 channels. This commit adds PWM driver support
for EHRPWM device present on AM33XX SOC. Current implementation supports
simple PWM functionality.

Reviewed-by: Vaibhav Bedia 
Signed-off-by: Philip, Avinash 
---
:100644 100644 2840747... 371a36c... M  drivers/pwm/Kconfig
:100644 100644 35fee43... e4b2c89... M  drivers/pwm/Makefile
:00 100644 000... 010d232... A  drivers/pwm/pwm-tiehrpwm.c
 drivers/pwm/Kconfig|   11 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-tiehrpwm.c |  411 
 3 files changed, 423 insertions(+), 0 deletions(-)

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 2840747..371a36c 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -87,6 +87,17 @@ config  PWM_TIECAP
  To compile this driver as a module, choose M here: the module
  will be called pwm-tiecap.
 
+config  PWM_TIEHRPWM
+   tristate "EHRPWM PWM support"
+   depends on SOC_AM33XX
+
+   help
+ PWM driver support for the EHRPWM controller found on AM33XX
+ TI SOC
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-tiehrpwm.
+
 config PWM_VT8500
tristate "vt8500 pwm support"
depends on ARCH_VT8500
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index 35fee43..e4b2c89 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -7,4 +7,5 @@ obj-$(CONFIG_PWM_PXA)   += pwm-pxa.o
 obj-$(CONFIG_PWM_SAMSUNG)  += pwm-samsung.o
 obj-$(CONFIG_PWM_TEGRA)+= pwm-tegra.o
 obj-$(CONFIG_PWM_TIECAP)   += pwm-tiecap.o
+obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o
 obj-$(CONFIG_PWM_VT8500)   += pwm-vt8500.o
diff --git a/drivers/pwm/pwm-tiehrpwm.c b/drivers/pwm/pwm-tiehrpwm.c
new file mode 100644
index 000..010d232
--- /dev/null
+++ b/drivers/pwm/pwm-tiehrpwm.c
@@ -0,0 +1,411 @@
+/*
+ * EHRPWM PWM driver
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc. - http://www.ti.com/
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* EHRPWM registers and bits definitions */
+
+/* Time base module registers */
+#define TBCTL  0x00
+#define TBPRD  0x0A
+
+#define TBCTL_RUN_MASK (BIT(15) | BIT(14))
+#define TBCTL_STOP_NEXT0
+#define TBCTL_STOP_ON_CYCLEBIT(14)
+#define TBCTL_FREE_RUN (BIT(15) | BIT(14))
+#define TBCTL_PRDLD_MASK   BIT(3)
+#define TBCTL_PRDLD_SHDW   0
+#define TBCTL_PRDLD_IMDT   BIT(3)
+#define TBCTL_CLKDIV_MASK  (BIT(12) | BIT(11) | BIT(10) | BIT(9) | \
+   BIT(8) | BIT(7))
+#define TBCTL_CTRMODE_MASK (BIT(1) | BIT(0))
+#define TBCTL_CTRMODE_UP   0
+#define TBCTL_CTRMODE_DOWN BIT(0)
+#define TBCTL_CTRMODE_UPDOWN   BIT(1)
+#define TBCTL_CTRMODE_FREEZE   (BIT(1) | BIT(0))
+
+#define TBCTL_HSPCLKDIV_SHIFT  7
+#define TBCTL_CLKDIV_SHIFT 10
+
+#define CLKDIV_MAX 7
+#define HSPCLKDIV_MAX  7
+#define PERIOD_MAX 0x
+
+/* compare module registers */
+#define CMPA   0x12
+#define CMPB   0x14
+
+/* Action qualifier module registers */
+#define AQCTLA 0x16
+#define AQCTLB 0x18
+#define AQSFRC 0x1A
+#define AQCSFRC0x1C
+
+#define AQCTL_CBU_MASK (BIT(9) | BIT(8))
+#define AQCTL_CBU_FRCLOW   BIT(8)
+#define AQCTL_CBU_FRCHIGH  BIT(9)
+#define AQCTL_CBU_FRCTOGGLE(BIT(9) | BIT(8))
+#define AQCTL_CAU_MASK (BIT(5) | BIT(4))
+#define AQCTL_CAU_FRCLOW   BIT(4)
+#define AQCTL_CAU_FRCHIGH  BIT(5)
+#define AQCTL_CAU_FRCTOGGLE(BIT(5) | BIT(4))
+#define AQCTL_PRD_MASK (BIT(3) | BIT(2))
+#define AQCTL_PRD_FRCLOW   BIT(2)
+#define AQCTL_PRD_FRCHIGH  BIT(3)
+#define AQCTL_PRD_FRCTOGGLE(BIT(3) | BIT(2))
+#define AQCTL_ZRO_MASK (BIT(1) | BIT(0))
+#define AQCTL_ZRO_FRCLOW   BIT(0)
+#define AQCTL_ZRO_FRCHIGH  BIT(1)
+#define AQCTL_ZRO_FRCTOGGLE(BIT(1) | BIT(0))
+
+#define AQSFRC_RLDCSF_MASK (BIT(7) | BIT(6))
+#define AQSFRC_RLDCSF_ZRO  0
+#define AQ