[RESEND PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-04-09 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger 
Reviewed-by: Alex Elder 
Reviewed-by: Markus Mayer 
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate "Kona PWM support"
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate "Blackfin PWM support"
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan) << 2)
+#define PRESCALE_MASK(chan)(0x7 << PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan) << 3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan) << 3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan)
+{
+   unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET);
+
+   /* Clear trigger bit but set smooth bit to maintain old output */
+   value |= 

[RESEND PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-04-09 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger tim.kry...@linaro.org
Reviewed-by: Alex Elder el...@linaro.org
Reviewed-by: Markus Mayer markus.ma...@linaro.org
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate Kona PWM support
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate Blackfin PWM support
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/err.h
+#include linux/io.h
+#include linux/ioport.h
+#include linux/math64.h
+#include linux/module.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/pwm.h
+#include linux/slab.h
+#include linux/types.h
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan)  2)
+#define PRESCALE_MASK(chan)(0x7  PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan)  3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan)  3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void 

[RESEND PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-04-02 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger 
Reviewed-by: Alex Elder 
Reviewed-by: Markus Mayer 
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate "Kona PWM support"
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate "Blackfin PWM support"
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan) << 2)
+#define PRESCALE_MASK(chan)(0x7 << PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan) << 3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan) << 3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan)
+{
+   unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET);
+
+   /* Clear trigger bit but set smooth bit to maintain old output */
+   value |= 

[RESEND PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-04-02 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger tim.kry...@linaro.org
Reviewed-by: Alex Elder el...@linaro.org
Reviewed-by: Markus Mayer markus.ma...@linaro.org
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate Kona PWM support
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate Blackfin PWM support
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/err.h
+#include linux/io.h
+#include linux/ioport.h
+#include linux/math64.h
+#include linux/module.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/pwm.h
+#include linux/slab.h
+#include linux/types.h
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan)  2)
+#define PRESCALE_MASK(chan)(0x7  PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan)  3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan)  3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void 

[PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-03-26 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger 
Reviewed-by: Alex Elder 
Reviewed-by: Markus Mayer 
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate "Kona PWM support"
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate "Blackfin PWM support"
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan) << 2)
+#define PRESCALE_MASK(chan)(0x7 << PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan) << 3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan) << 3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan)
+{
+   unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET);
+
+   /* Clear trigger bit but set smooth bit to maintain old output */
+   value |= 

[PATCH v5 2/5] pwm: kona: Introduce Kona PWM controller support

2014-03-26 Thread Tim Kryger
Add support for the six-channel Kona PWM controller found on Broadcom
mobile SoCs like bcm281xx.

Signed-off-by: Tim Kryger tim.kry...@linaro.org
Reviewed-by: Alex Elder el...@linaro.org
Reviewed-by: Markus Mayer markus.ma...@linaro.org
---
 drivers/pwm/Kconfig|9 ++
 drivers/pwm/Makefile   |1 +
 drivers/pwm/pwm-bcm-kona.c |  319 
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/pwm/pwm-bcm-kona.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 22f2f28..777d87dd 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
  To compile this driver as a module, choose M here: the module
  will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+   tristate Kona PWM support
+   depends on ARCH_BCM_MOBILE
+   help
+ Generic PWM framework driver for Broadcom Kona PWM block.
+
+ To compile this driver as a module, choose M here: the module
+ will be called pwm-bcm-kona.
+
 config PWM_BFIN
tristate Blackfin PWM support
depends on BFIN_GPTIMERS
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index d8906ec..7413090 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o
 obj-$(CONFIG_PWM_AB8500)   += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)  += pwm-imx.o
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644
index 000..ee8a59d
--- /dev/null
+++ b/drivers/pwm/pwm-bcm-kona.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/err.h
+#include linux/io.h
+#include linux/ioport.h
+#include linux/math64.h
+#include linux/module.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/pwm.h
+#include linux/slab.h
+#include linux/types.h
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *will transition to the new settings on a period boundary (which could be
+ *seconds away).  If the smooth bit is clear, new settings will be applied
+ *as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET (0x)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)   (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)   (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)(chan)
+
+#define PRESCALE_OFFSET(0x0004)
+#define PRESCALE_SHIFT(chan)   ((chan)  2)
+#define PRESCALE_MASK(chan)(0x7  PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN   (0x)
+#define PRESCALE_MAX   (0x0007)
+
+#define PERIOD_COUNT_OFFSET(chan)  (0x0008 + ((chan)  3))
+#define PERIOD_COUNT_MIN   (0x0002)
+#define PERIOD_COUNT_MAX   (0x00ff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)   (0x000c + ((chan)  3))
+#define DUTY_CYCLE_HIGH_MIN(0x)
+#define DUTY_CYCLE_HIGH_MAX(0x00ff)
+
+struct kona_pwmc {
+   struct pwm_chip chip;
+   void __iomem *base;
+   struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+   return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void