Skip to contentSkip to conversation

ARM: samsung-time: Prepare for multiplatform support

PATCH New Tomasz Figa 7 participants 29 messages Apr 12, 2013 – Apr 22, 2013

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

Changes since v4:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/17464)
- Changed the design again - now clocksource driver is considered the master and exports a single function to get access to things like base address, hardware variant information, shared spinlock for register access synchronization and interrupt numbers
- Renamed the clocksource driver to samsung_pwm
- Cleaned up the code a bit more
- Added clocksource_of_init support

Changes since v3:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16664/)
- Changed the design to use common (master) driver for operations that can be done from both clocksource and PWM drivers (as suggested by Arnd Bergmann) - needed to properly synchronize access to PWM registers
- Moved handling of PWM prescaler and divider to master driver

Changes since v2:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16158)
- Addressed comments from Rob Herring and Mark Rutland
- Removed unused register definitions
- Replaced samsung,source-timer and samsung,event-timer properties with samsung,pwm-outputs property that defines which PWM channels are reserved for PWM outputs on particular platform
- Split non-DT and DT initialization into two functions
- Fixed a copy paste error

Changes since v1:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16005)
- Addressed comments from Mark Rutland
- Documented struct samsung_timer_variant
- Dropped inactive mail addresses from CC

Tomasz Figa (14):
ARM: SAMSUNG: Move samsung-time to drivers/clocksource
clocksource: samsung-pwm: Clean up platform header
clocksource: samsung-pwm: Add infrastructure to share PWM hardware
ARM: SAMSUNG: Unify base address definitions of timer block
ARM: SAMSUNG: Add new PWM platform device
ARM: SAMSUNG: Set PWM platform data
clocksource: samsung-pwm: Use platform data to setup the clocksource
clocksource: samsung-pwm: Synchronize register accesses
clocksource: samsung-pwm: Move IRQ mask/ack handling to the driver
ARM: SAMSUNG: Remove unused PWM timer IRQ chip code
clocksource: samsung-pwm: Configure dividers directly
clocksource: samsung-pwm: Do not use static mapping of registers
clocksource: samsung-pwm: Drop unnecessary includes
clocksource: samsung-pwm: Prepare for clocksource_of_init

 .../devicetree/bindings/pwm/pwm-samsung.txt        |  43 ++
 arch/arm/Kconfig                                   |   1 -
 arch/arm/mach-exynos/common.c                      |  10 +
 arch/arm/mach-exynos/include/mach/irqs.h           |   3 +-
 arch/arm/mach-exynos/include/mach/map.h            |   1 +
 arch/arm/mach-s3c24xx/common.c                     |  10 +
 arch/arm/mach-s3c24xx/include/mach/irqs.h          |   6 +
 arch/arm/mach-s3c24xx/include/mach/map.h           |   2 +
 arch/arm/mach-s3c64xx/common.c                     |  14 +-
 arch/arm/mach-s3c64xx/include/mach/irqs.h          |   8 -
 arch/arm/mach-s3c64xx/include/mach/map.h           |   1 +
 arch/arm/mach-s5p64x0/common.c                     |  10 +
 arch/arm/mach-s5p64x0/include/mach/irqs.h          |   2 -
 arch/arm/mach-s5p64x0/include/mach/map.h           |   1 +
 arch/arm/mach-s5pc100/common.c                     |  10 +
 arch/arm/mach-s5pc100/include/mach/irqs.h          |   2 -
 arch/arm/mach-s5pc100/include/mach/map.h           |   1 +
 arch/arm/mach-s5pv210/common.c                     |  10 +
 arch/arm/mach-s5pv210/include/mach/irqs.h          |   2 -
 arch/arm/mach-s5pv210/include/mach/map.h           |   1 +
 arch/arm/plat-samsung/Kconfig                      |  14 -
 arch/arm/plat-samsung/Makefile                     |   2 -
 arch/arm/plat-samsung/devs.c                       |  33 +-
 arch/arm/plat-samsung/include/plat/devs.h          |   1 +
 arch/arm/plat-samsung/include/plat/irq-vic-timer.h |  13 -
 arch/arm/plat-samsung/include/plat/irqs.h          |   9 -
 arch/arm/plat-samsung/include/plat/samsung-time.h  |  38 +-
 arch/arm/plat-samsung/irq-vic-timer.c              |  98 ----
 arch/arm/plat-samsung/s5p-irq.c                    |   3 -
 arch/arm/plat-samsung/samsung-time.c               | 394 -------------
 drivers/clocksource/Kconfig                        |   7 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/samsung_pwm.c                  | 636 +++++++++++++++++++++
 include/clocksource/samsung_pwm.h                  |  45 ++
 34 files changed, 849 insertions(+), 583 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pwm/pwm-samsung.txt
 delete mode 100644 arch/arm/plat-samsung/include/plat/irq-vic-timer.h
 delete mode 100644 arch/arm/plat-samsung/irq-vic-timer.c
 delete mode 100644 arch/arm/plat-samsung/samsung-time.c
 create mode 100644 drivers/clocksource/samsung_pwm.c
 create mode 100644 include/clocksource/samsung_pwm.h
Signature · 1 line
1.8.1.5
#1 lore raw

PATCH v5 1/14 ARM: SAMSUNG: Move samsung-time to drivers/clocksource

This patch moves the Samsung PWM-based high resolution timer support code from arch/arm/plat-samsung to drivers/clocksource.

This is a prerequisite for further work on making the driver more multiplatform and Device Tree friendly.

In addition, the driver is renamed to samsung_pwm, since it uses PWM timers available on Samsung SoCs for timekeeping purposes.

---
 arch/arm/plat-samsung/Kconfig        |   8 -
 arch/arm/plat-samsung/Makefile       |   1 -
 arch/arm/plat-samsung/samsung-time.c | 394 -----------------------------------
 drivers/clocksource/Kconfig          |   7 +
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/samsung_pwm.c    | 394 +++++++++++++++++++++++++++++++++++
 6 files changed, 402 insertions(+), 403 deletions(-)
 delete mode 100644 arch/arm/plat-samsung/samsung-time.c
 create mode 100644 drivers/clocksource/samsung_pwm.c
arch/arm/plat-samsung/Kconfig +0 -8
index 54d1861..6f632ba 100644
@@ -60,14 +60,6 @@ config S3C_LOWLEVEL_UART_PORT
 	  this configuration should be between zero and two. The port
 	  must have been initialised by the boot-loader before use.
 
-# timer options
-
-config SAMSUNG_HRT
-	bool
-	select SAMSUNG_DEV_PWM
-	help
-	  Use the High Resolution timer support
-
 # clock options
 
 config SAMSUNG_CLOCK
arch/arm/plat-samsung/Makefile +0 -1
index a23c460..87494e1 100644
@@ -12,7 +12,6 @@ obj-				:=
 # Objects we always build independent of SoC choice
 
 obj-y				+= init.o cpu.o
-obj-$(CONFIG_SAMSUNG_HRT) 	+= samsung-time.o
 
 obj-$(CONFIG_SAMSUNG_CLOCK)	+= clock.o
 obj-$(CONFIG_SAMSUNG_CLOCK)	+= pwm-clock.o
arch/arm/plat-samsung/samsung-time.c deleted +0 -394

394 lines not on this page · raw message

drivers/clocksource/Kconfig +7 -0
index e8c4532..dd20f6a 100644
@@ -25,6 +25,13 @@ config DW_APB_TIMER_OF
 config ARMADA_370_XP_TIMER
 	bool
 
+config SAMSUNG_HRT
+	bool
+	depends on PLAT_SAMSUNG
+	select SAMSUNG_DEV_PWM
+	help
+	  Use the high resolution timer support on Samsung platforms.
+
 config SUNXI_TIMER
 	bool
 
drivers/clocksource/Makefile +1 -0
index 1c1b15d..c0a1945 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_CLKSRC_NOMADIK_MTU)	+= nomadik-mtu.o
 obj-$(CONFIG_CLKSRC_DBX500_PRCMU)	+= clksrc-dbx500-prcmu.o
 obj-$(CONFIG_ARMADA_370_XP_TIMER)	+= time-armada-370-xp.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835_timer.o
+obj-$(CONFIG_SAMSUNG_HRT) 	+= samsung_pwm.o
 obj-$(CONFIG_SUNXI_TIMER)	+= sunxi_timer.o
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra20_timer.o
 obj-$(CONFIG_VT8500_TIMER)	+= vt8500_timer.o
drivers/clocksource/samsung_pwm.c new file +394 -0

394 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#2 lore raw

PATCH v5 1/14 ARM: SAMSUNG: Move samsung-time to drivers/clocksource

Quoted 7 lines · Tomasz Figa
---
 arch/arm/plat-samsung/Kconfig        |   8 -
 arch/arm/plat-samsung/Makefile       |   1 -
 arch/arm/plat-samsung/samsung-time.c | 394 -----------------------------------
 drivers/clocksource/Kconfig          |   7 +
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/samsung_pwm.c    | 394 +++++++++++++++++++++++++++++++++++

In general, please send patches generated with 'git format-patch -M'. You can set that as a default using 'git config diff.renames true'.

Arnd

#3 lore raw

PATCH v5 1/14 ARM: SAMSUNG: Move samsung-time to drivers/clocksource

Quoted 11 lines · On Friday 12 of April 2013 22:44:03 Arnd Bergmann wrote:
Quoted 10 lines · Tomasz Figa

---

 arch/arm/plat-samsung/Kconfig        |   8 -
 arch/arm/plat-samsung/Makefile       |   1 -
 arch/arm/plat-samsung/samsung-time.c | 394
 ----------------------------------- drivers/clocksource/Kconfig     
     |   7 +
 drivers/clocksource/Makefile         |   1 +
 drivers/clocksource/samsung_pwm.c    | 394

+++++++++++++++++++++++++++++++++++

Quoted 2 lines

In general, please send patches generated with 'git format-patch -M'. You can set that as a default using 'git config diff.renames true'.

Oops, I forgot to add the switch, sorry. Setting it as default might be a good idea indeed.

Best regards,
Tomasz

#4 lore raw

PATCH v5 2/14 clocksource: samsung-pwm: Clean up platform header

In reply to Tomasz Figa

This patch moves private definitions out of the public platform header and also cleans it up from unused and/or unnecessary ones.

---
 arch/arm/plat-samsung/include/plat/samsung-time.h | 11 -----------
 drivers/clocksource/samsung_pwm.c                 | 15 ++++++++++-----
 2 files changed, 10 insertions(+), 16 deletions(-)
arch/arm/plat-samsung/include/plat/samsung-time.h +0 -11
index 4cc99bb..ecc423c 100644
@@ -22,14 +22,6 @@ enum samsung_timer_mode {
 	SAMSUNG_PWM4,
 };
 
-struct samsung_timer_source {
-	unsigned int event_id;
-	unsigned int source_id;
-};
-
-/* Be able to sleep for atleast 4 seconds (usually more) */
-#define SAMSUNG_TIMER_MIN_RANGE	4
-
 #if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S5PC100)
 #define TCNT_MAX		0xffff
 #define TSCALER_DIV		25
@@ -42,9 +34,6 @@ struct samsung_timer_source {
 #define TSIZE			32
 #endif
 
-#define NON_PERIODIC		0
-#define PERIODIC		1
-
 extern void __init samsung_set_timer_source(enum samsung_timer_mode event,
 					enum samsung_timer_mode source);
 
drivers/clocksource/samsung_pwm.c +10 -5
index f899cbc..974675b 100644
@@ -27,6 +27,11 @@
 #include <plat/regs-timer.h>
 #include <plat/samsung-time.h>
 
+struct samsung_timer_source {
+	unsigned int event_id;
+	unsigned int source_id;
+};
+
 static struct clk *tin_event;
 static struct clk *tin_source;
 static struct clk *tdiv_event;
@@ -182,7 +187,7 @@ static int samsung_set_next_event(unsigned long cycles,
 				struct clock_event_device *evt)
 {
 	samsung_time_setup(timer_source.event_id, cycles);
-	samsung_time_start(timer_source.event_id, NON_PERIODIC);
+	samsung_time_start(timer_source.event_id, false);
 
 	return 0;
 }
@@ -195,7 +200,7 @@ static void samsung_set_mode(enum clock_event_mode mode,
 	switch (mode) {
 	case CLOCK_EVT_MODE_PERIODIC:
 		samsung_time_setup(timer_source.event_id, clock_count_per_tick);
-		samsung_time_start(timer_source.event_id, PERIODIC);
+		samsung_time_start(timer_source.event_id, true);
 		break;
 
 	case CLOCK_EVT_MODE_ONESHOT:
@@ -215,11 +220,11 @@ static void samsung_timer_resume(void)
 {
 	/* event timer restart */
 	samsung_time_setup(timer_source.event_id, clock_count_per_tick);
-	samsung_time_start(timer_source.event_id, PERIODIC);
+	samsung_time_start(timer_source.event_id, true);
 
 	/* source timer restart */
 	samsung_time_setup(timer_source.source_id, TCNT_MAX);
-	samsung_time_start(timer_source.source_id, PERIODIC);
+	samsung_time_start(timer_source.source_id, true);
 }
 
 void __init samsung_set_timer_source(enum samsung_timer_mode event,
@@ -335,7 +340,7 @@ static void __init samsung_clocksource_init(void)
 	clock_rate = clk_get_rate(tin_source);
 
 	samsung_time_setup(timer_source.source_id, TCNT_MAX);
-	samsung_time_start(timer_source.source_id, PERIODIC);
+	samsung_time_start(timer_source.source_id, true);
 
 	setup_sched_clock(samsung_read_sched_clock, TSIZE, clock_rate);
 
Signature · 1 line
1.8.1.5
#5 lore raw

PATCH v5 3/14 clocksource: samsung-pwm: Add infrastructure to share PWM hardware

In reply to Tomasz Figa

This patch extends samsung PWM clocksource driver with infrastructure that allows sharing of PWM hardware between clocksource and PWM drivers.

---
 .../devicetree/bindings/pwm/pwm-samsung.txt        |  43 ++++
 drivers/clocksource/samsung_pwm.c                  | 250 +++++++++++++++++++++
 include/clocksource/samsung_pwm.h                  |  44 ++++
 3 files changed, 337 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/pwm-samsung.txt
 create mode 100644 include/clocksource/samsung_pwm.h
Documentation/devicetree/bindings/pwm/pwm-samsung.txt new file +43 -0
new file mode 100644
index 0000000..cc17c4c
@@ -0,0 +1,43 @@
+* Samsung PWM timers
+
+Samsung SoCs contain PWM timer blocks which can be used for system clock source
+and clock event timers, as well as to drive SoC outputs with PWM signal. Each
+PWM timer block provides 5 PWM channels (not all of them can drive physical
+outputs - see SoC and board manual).
+
+Be aware that the clocksource driver supports only uniprocessor systems.
+
+Required properties:
+- compatible : should be one of following:
+    samsung,s3c2410-pwm - for 16-bit timers present on S3C24xx SoCs
+    samsung,s3c6400-pwm - for 32-bit timers present on S3C64xx SoCs
+    samsung,s5p6440-pwm - for 32-bit timers present on S5P64x0 SoCs
+    samsung,s5pc100-pwm - for 32-bit timers present on S5PC100, S5PV210,
+			  Exynos4210 rev0 SoCs
+    samsung,exynos4210-pwm - for 32-bit timers present on Exynos4210,
+                          Exynos4x12 and Exynos5250 SoCs
+- reg: base address and size of register area
+- interrupts: list of timer interrupts (one interrupt per timer, starting at
+  timer 0)
+- #pwm-cells: number of cells used for PWM specifier - must be 4
+   the specifier format is as follows:
+     - phandle to PWM controller node
+     - index of PWM channel (from 0 to 4)
+     - PWM signal period in nanoseconds
+     - bitmask of PWM flags:
+        0x1 - invert PWM signal
+
+Optional properties:
+- samsung,pwm-outputs: list of PWM channels used as PWM outputs on particular
+    platform - an array of up to 5 elements being indices of PWM channels
+    (from 0 to 4), the order does not matter.
+
+Example:
+	pwm at 7f006000 {
+		compatible = "samsung,s3c6400-pwm";
+		reg = <0x7f006000 0x1000>;
+		interrupt-parent = <&vic0>;
+		interrupts = <23>, <24>, <25>, <27>, <28>;
+		samsung,pwm-outputs = <0>, <1>;
+		#pwm-cells = <2>;
+	}
drivers/clocksource/samsung_pwm.c +250 -0

263 lines not on this page · raw message

include/clocksource/samsung_pwm.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#6 lore raw

PATCH v5 3/14 clocksource: samsung-pwm: Add infrastructure to share PWM hardware

Quoted 6 lines · Tomasz Figa
Documentation/devicetree/bindings/pwm/pwm-samsung.txt new file +6 -0
+
+Samsung SoCs contain PWM timer blocks which can be used for system clock source
+and clock event timers, as well as to drive SoC outputs with PWM signal. Each
+PWM timer block provides 5 PWM channels (not all of them can drive physical
+outputs - see SoC and board manual).
+

...

Documentation/devicetree/bindings/pwm/pwm-samsung.txt line 34

Quoted 5 lines
Documentation/devicetree/bindings/pwm/pwm-samsung.txt new file +5 -0
+Optional properties:
+- samsung,pwm-outputs: list of PWM channels used as PWM outputs on particular
+    platform - an array of up to 5 elements being indices of PWM channels
+    (from 0 to 4), the order does not matter.
+

There is probably a good reason, but can you explain why this is actually required to be a property? Wouldn't it be enough to just not refer to the PWM outputs from other devices when they are not used?

Arnd

#7 lore raw

PATCH v5 3/14 clocksource: samsung-pwm: Add infrastructure to share PWM hardware

Hi Arnd,

Quoted 10 lines · On Friday 12 of April 2013 22:42:36 Arnd Bergmann wrote:
Quoted 6 lines · Tomasz Figa
(quoted diff) +2 -0
+
+Samsung SoCs contain PWM timer blocks which can be used for system

clock source +and clock event timers, as well as to drive SoC outputs with PWM signal. Each +PWM timer block provides 5 PWM channels (not all of them can drive physical +outputs - see SoC and board manual). +

...

Quoted 9 lines
Quoted 5 lines

+Optional properties:

+- samsung,pwm-outputs: list of PWM channels used as PWM outputs on
particular +    platform - an array of up to 5 elements being indices
of PWM channels +    (from 0 to 4), the order does not matter.

+

There is probably a good reason, but can you explain why this is actually required to be a property? Wouldn't it be enough to just not refer to the PWM outputs from other devices when they are not used?

It is needed for the clocksource driver, to select unused channels for clocksource and clock event purposes.

Best regards,
Tomasz

#8 lore raw

PATCH v5 4/14 ARM: SAMSUNG: Unify base address definitions of timer block

In reply to Tomasz Figa

This patch makes all defintions of timer block base address use the same prefix to allow using the common name to define platform device resource.

---
 arch/arm/mach-exynos/include/mach/map.h  | 1 +
 arch/arm/mach-s3c24xx/include/mach/map.h | 2 ++
 arch/arm/mach-s3c64xx/include/mach/map.h | 1 +
 arch/arm/mach-s5p64x0/include/mach/map.h | 1 +
 arch/arm/mach-s5pc100/include/mach/map.h | 1 +
 arch/arm/mach-s5pv210/include/mach/map.h | 1 +
 6 files changed, 7 insertions(+)
arch/arm/mach-exynos/include/mach/map.h +1 -0
index 99e0a79..7167aba 100644
@@ -272,6 +272,7 @@
 #define SAMSUNG_PA_ADC			EXYNOS4_PA_ADC
 #define SAMSUNG_PA_ADC1			EXYNOS4_PA_ADC1
 #define SAMSUNG_PA_KEYPAD		EXYNOS4_PA_KEYPAD
+#define SAMSUNG_PA_TIMER		EXYNOS4_PA_TIMER
 
 /* Compatibility UART */
 
arch/arm/mach-s3c24xx/include/mach/map.h +2 -0
index 8ba381f..444793f 100644
@@ -167,4 +167,6 @@
 #define S3C_PA_SPI0		S3C2443_PA_SPI0
 #define S3C_PA_SPI1		S3C2443_PA_SPI1
 
+#define SAMSUNG_PA_TIMER	S3C2410_PA_TIMER
+
 #endif /* __ASM_ARCH_MAP_H */
arch/arm/mach-s3c64xx/include/mach/map.h +1 -0
index 8e2097b..f55ccb1 100644
@@ -121,5 +121,6 @@
 #define SAMSUNG_PA_ADC		S3C64XX_PA_ADC
 #define SAMSUNG_PA_CFCON	S3C64XX_PA_CFCON
 #define SAMSUNG_PA_KEYPAD	S3C64XX_PA_KEYPAD
+#define SAMSUNG_PA_TIMER	S3C64XX_PA_TIMER
 
 #endif /* __ASM_ARCH_6400_MAP_H */
arch/arm/mach-s5p64x0/include/mach/map.h +1 -0
index 0c0175d..50a6e96 100644
@@ -76,6 +76,7 @@
 #define S5P_PA_TIMER		S5P64X0_PA_TIMER
 
 #define SAMSUNG_PA_ADC		S5P64X0_PA_ADC
+#define SAMSUNG_PA_TIMER	S5P64X0_PA_TIMER
 
 /* UART */
 
arch/arm/mach-s5pc100/include/mach/map.h +1 -0
index 54bc4f8..2550b61 100644
@@ -116,6 +116,7 @@
 #define SAMSUNG_PA_ADC			S5PC100_PA_TSADC
 #define SAMSUNG_PA_CFCON		S5PC100_PA_CFCON
 #define SAMSUNG_PA_KEYPAD		S5PC100_PA_KEYPAD
+#define SAMSUNG_PA_TIMER		S5PC100_PA_TIMER
 
 #define S5PC100_VA_OTHERS		(S3C_VA_SYS + 0x10000)
 
arch/arm/mach-s5pv210/include/mach/map.h +1 -0
index b7c8a19..763929a 100644
@@ -139,6 +139,7 @@
 #define SAMSUNG_PA_ADC			S5PV210_PA_ADC
 #define SAMSUNG_PA_CFCON		S5PV210_PA_CFCON
 #define SAMSUNG_PA_KEYPAD		S5PV210_PA_KEYPAD
+#define SAMSUNG_PA_TIMER		S5PV210_PA_TIMER
 
 /* UART */
 
Signature · 1 line
1.8.1.5
#9 lore raw

PATCH v5 5/14 ARM: SAMSUNG: Add new PWM platform device

In reply to Tomasz Figa

This patch adds new samsung_device_pwm platform device that represents the whole PWM/timer block and includes memory and IRQ resources.

---
 arch/arm/plat-samsung/devs.c              | 16 ++++++++++++++++
 arch/arm/plat-samsung/include/plat/devs.h |  1 +
 2 files changed, 17 insertions(+)
arch/arm/plat-samsung/devs.c +16 -0
index e1124d9..bfae4dd 100644
@@ -1168,6 +1168,22 @@ struct platform_device s3c_device_timer[] = {
 };
 #endif /* CONFIG_SAMSUNG_DEV_PWM */
 
+static struct resource samsung_pwm_resource[] = {
+	DEFINE_RES_IRQ(IRQ_TIMER0),
+	DEFINE_RES_IRQ(IRQ_TIMER1),
+	DEFINE_RES_IRQ(IRQ_TIMER2),
+	DEFINE_RES_IRQ(IRQ_TIMER3),
+	DEFINE_RES_IRQ(IRQ_TIMER4),
+	DEFINE_RES_MEM(SAMSUNG_PA_TIMER, SZ_4K),
+};
+
+struct platform_device samsung_device_pwm = {
+	.name		= "samsung-pwm",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(samsung_pwm_resource),
+	.resource	= samsung_pwm_resource,
+};
+
 /* RTC */
 
 #ifdef CONFIG_PLAT_S3C24XX
arch/arm/plat-samsung/include/plat/devs.h +1 -0
index 87d501f..0dc4ac4 100644
@@ -134,6 +134,7 @@ extern struct platform_device exynos4_device_spdif;
 
 extern struct platform_device samsung_asoc_idma;
 extern struct platform_device samsung_device_keypad;
+extern struct platform_device samsung_device_pwm;
 
 /* s3c2440 specific devices */
 
Signature · 1 line
1.8.1.5
#10 lore raw

PATCH v5 6/14 ARM: SAMSUNG: Set PWM platform data

In reply to Tomasz Figa

This patch adds PWM platform data needed for legacy (non-DT) platforms to handle SoC-specific bits of the PWM/timer block.

---
 arch/arm/mach-exynos/common.c  | 10 ++++++++++
 arch/arm/mach-s3c24xx/common.c | 10 ++++++++++
 arch/arm/mach-s3c64xx/common.c | 10 ++++++++++
 arch/arm/mach-s5p64x0/common.c | 10 ++++++++++
 arch/arm/mach-s5pc100/common.c | 10 ++++++++++
 arch/arm/mach-s5pv210/common.c | 10 ++++++++++
 6 files changed, 60 insertions(+)
arch/arm/mach-exynos/common.c +10 -0
index a8570bf..b65229d 100644
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include <linux/device.h>
 #include <linux/gpio.h>
+#include <clocksource/samsung_pwm.h>
 #include <linux/sched.h>
 #include <linux/serial_core.h>
 #include <linux/of.h>
@@ -378,6 +379,13 @@ void __init exynos_init_io(struct map_desc *mach_desc, int size)
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
 }
 
+static struct samsung_pwm_variant exynos4_pwm_variant = {
+	.bits		= 32,
+	.div_base	= 0,
+	.has_tint_cstat	= true,
+	.tclk_mask	= (1 << 5),
+};
+
 static void __init exynos4_map_io(void)
 {
 	iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
@@ -419,6 +427,8 @@ static void __init exynos4_map_io(void)
 	s5p_hdmi_setname("exynos4-hdmi");
 
 	s3c64xx_spi_setname("exynos4210-spi");
+
+	samsung_device_pwm.dev.platform_data = &exynos4_pwm_variant;
 }
 
 static void __init exynos5_map_io(void)
arch/arm/mach-s3c24xx/common.c +10 -0
index d97533d..a01cccb 100644
@@ -27,6 +27,7 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/serial_core.h>
+#include <clocksource/samsung_pwm.h>
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/io.h>
@@ -216,6 +217,13 @@ static void s3c24xx_default_idle(void)
 		     S3C2410_CLKCON);
 }
 
+static struct samsung_pwm_variant s3c24xx_pwm_variant = {
+	.bits		= 16,
+	.div_base	= 1,
+	.has_tint_cstat	= false,
+	.tclk_mask	= (1 << 4),
+};
+
 void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
 {
 	arm_pm_idle = s3c24xx_default_idle;
@@ -232,6 +240,8 @@ void __init s3c24xx_init_io(struct map_desc *mach_desc, int size)
 	s3c24xx_init_cpu();
 
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
+
+	samsung_device_pwm.dev.platform_data = &s3c24xx_pwm_variant;
 }
 
 /* Serial port registrations */
arch/arm/mach-s3c64xx/common.c +10 -0
index 0b9c0ba..89d2823 100644
@@ -26,6 +26,7 @@
 #include <linux/irq.h>
 #include <linux/gpio.h>
 #include <linux/irqchip/arm-vic.h>
+#include <clocksource/samsung_pwm.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -148,6 +149,13 @@ static struct device s3c64xx_dev = {
 	.bus	= &s3c64xx_subsys,
 };
 
+static struct samsung_pwm_variant s3c64xx_pwm_variant = {
+	.bits		= 32,
+	.div_base	= 0,
+	.has_tint_cstat	= true,
+	.tclk_mask	= (1 << 7) | (1 << 6) | (1 << 5),
+};
+
 /* read cpu identification code */
 
 void __init s3c64xx_init_io(struct map_desc *mach_desc, int size)
@@ -160,6 +168,8 @@ void __init s3c64xx_init_io(struct map_desc *mach_desc, int size)
 	s3c64xx_init_cpu();
 
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
+
+	samsung_device_pwm.dev.platform_data = &s3c64xx_pwm_variant;
 }
 
 static __init int s3c64xx_dev_init(void)
arch/arm/mach-s5p64x0/common.c +10 -0
index 8ae5800..cef1d3a 100644
@@ -19,6 +19,7 @@
 #include <linux/io.h>
 #include <linux/device.h>
 #include <linux/serial_core.h>
+#include <clocksource/samsung_pwm.h>
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/dma-mapping.h>
@@ -156,6 +157,13 @@ static void s5p64x0_idle(void)
 	cpu_do_idle();
 }
 
+static struct samsung_pwm_variant s5p64x0_pwm_variant = {
+	.bits		= 32,
+	.div_base	= 0,
+	.has_tint_cstat	= true,
+	.tclk_mask	= 0,
+};
+
 /*
  * s5p64x0_map_io
  *
@@ -173,6 +181,8 @@ void __init s5p64x0_init_io(struct map_desc *mach_desc, int size)
 	s5p_init_cpu(S5P64X0_SYS_ID);
 
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
+
+	samsung_device_pwm.dev.platform_data = &s5p64x0_pwm_variant;
 }
 
 void __init s5p6440_map_io(void)
arch/arm/mach-s5pc100/common.c +10 -0
index cc6e561..3ccbd43 100644
@@ -22,6 +22,7 @@
 #include <linux/io.h>
 #include <linux/device.h>
 #include <linux/serial_core.h>
+#include <clocksource/samsung_pwm.h>
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 
@@ -131,6 +132,13 @@ static struct map_desc s5pc100_iodesc[] __initdata = {
 	}
 };
 
+static struct samsung_pwm_variant s5pc100_pwm_variant = {
+	.bits		= 32,
+	.div_base	= 0,
+	.has_tint_cstat	= true,
+	.tclk_mask	= (1 << 5),
+};
+
 /*
  * s5pc100_map_io
  *
@@ -148,6 +156,8 @@ void __init s5pc100_init_io(struct map_desc *mach_desc, int size)
 	s5p_init_cpu(S5P_VA_CHIPID);
 
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
+
+	samsung_device_pwm.dev.platform_data = &s5pc100_pwm_variant;
 }
 
 void __init s5pc100_map_io(void)
arch/arm/mach-s5pv210/common.c +10 -0
index 9dfe93e..bfd918f 100644
@@ -19,6 +19,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/device.h>
+#include <clocksource/samsung_pwm.h>
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/dma-mapping.h>
@@ -148,6 +149,13 @@ void s5pv210_restart(char mode, const char *cmd)
 	__raw_writel(0x1, S5P_SWRESET);
 }
 
+static struct samsung_pwm_variant s5pv210_pwm_variant = {
+	.bits		= 32,
+	.div_base	= 0,
+	.has_tint_cstat	= true,
+	.tclk_mask	= (1 << 5),
+};
+
 /*
  * s5pv210_map_io
  *
@@ -165,6 +173,8 @@ void __init s5pv210_init_io(struct map_desc *mach_desc, int size)
 	s5p_init_cpu(S5P_VA_CHIPID);
 
 	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
+
+	samsung_device_pwm.dev.platform_data = &s5pv210_pwm_variant;
 }
 
 void __init s5pv210_map_io(void)
Signature · 1 line
1.8.1.5
#11 lore raw

PATCH v5 7/14 clocksource: samsung-pwm: Use platform data to setup the clocksource

In reply to Tomasz Figa

This patch modifies the clocksource registration code to use data taken from platform data instead of statically hardcoded defines.

---
 arch/arm/plat-samsung/devs.c                      |  7 +++
 arch/arm/plat-samsung/include/plat/samsung-time.h | 29 +++++-----
 drivers/clocksource/samsung_pwm.c                 | 70 ++++++++++++++++-------
 include/clocksource/samsung_pwm.h                 |  1 +
 4 files changed, 73 insertions(+), 34 deletions(-)
arch/arm/plat-samsung/devs.c +7 -0
index bfae4dd..fbfabd2 100644
@@ -32,6 +32,8 @@
 #include <linux/platform_data/s3c-hsudc.h>
 #include <linux/platform_data/s3c-hsotg.h>
 
+#include <clocksource/samsung_pwm.h>
+
 #include <media/s5p_hdmi.h>
 
 #include <asm/irq.h>
@@ -1184,6 +1186,11 @@ struct platform_device samsung_device_pwm = {
 	.resource	= samsung_pwm_resource,
 };
 
+void samsung_timer_init(void)
+{
+	samsung_pwm_clocksource_init(&samsung_device_pwm);
+}
+
 /* RTC */
 
 #ifdef CONFIG_PLAT_S3C24XX
arch/arm/plat-samsung/include/plat/samsung-time.h +15 -14
index ecc423c..633c151 100644
@@ -13,6 +13,10 @@
 #ifndef __ASM_PLAT_SAMSUNG_TIME_H
 #define __ASM_PLAT_SAMSUNG_TIME_H __FILE__
 
+#include <clocksource/samsung_pwm.h>
+
+#include <plat/devs.h>
+
 /* SAMSUNG HR-Timer Clock mode */
 enum samsung_timer_mode {
 	SAMSUNG_PWM0,
@@ -22,20 +26,17 @@ enum samsung_timer_mode {
 	SAMSUNG_PWM4,
 };
 
-#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S5PC100)
-#define TCNT_MAX		0xffff
-#define TSCALER_DIV		25
-#define TDIV			50
-#define TSIZE			16
-#else
-#define TCNT_MAX		0xffffffff
-#define TSCALER_DIV		2
-#define TDIV			2
-#define TSIZE			32
-#endif
-
-extern void __init samsung_set_timer_source(enum samsung_timer_mode event,
-					enum samsung_timer_mode source);
+static inline void samsung_set_timer_source(enum samsung_timer_mode event,
+						enum samsung_timer_mode source)
+{
+	struct samsung_pwm_variant *variant;
+
+	variant = samsung_device_pwm.dev.platform_data;
+	BUG_ON(!variant);
+
+	variant->output_mask = (1 << 5) - 1;
+	variant->output_mask &= ~((1 << event) | (1 << source));
+}
 
 extern void __init samsung_timer_init(void);
 
drivers/clocksource/samsung_pwm.c +50 -20

126 lines not on this page · raw message

include/clocksource/samsung_pwm.h +1 -0
index d16415f..a0449d5 100644
@@ -38,6 +38,7 @@ struct samsung_pwm {
 	int irq[SAMSUNG_PWM_NUM];
 };
 
+extern void samsung_pwm_clocksource_init(struct platform_device *);
 extern struct samsung_pwm *samsung_pwm_get(struct platform_device *,
 							struct device_node *);
 
Signature · 1 line
1.8.1.5
#12 lore raw

PATCH v5 8/14 clocksource: samsung-pwm: Synchronize register accesses

In reply to Tomasz Figa

Since the registers of PWM block are shared between two drivers, it is required to synchronize accesses to them. This patch introduces necessary synchronization using spin_{un,}lock_irq{save,restore} and a shared spinlock.

---
 drivers/clocksource/samsung_pwm.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/clocksource/samsung_pwm.c +15 -0
index 841d03c..bddf9aa 100644
@@ -299,6 +299,9 @@ static void samsung_timer_resume(void);
 static void samsung_time_stop(enum samsung_timer_mode mode)
 {
 	unsigned long tcon;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pwm->slock, flags);
 
 	tcon = __raw_readl(S3C2410_TCON);
 
@@ -328,11 +331,16 @@ static void samsung_time_stop(enum samsung_timer_mode mode)
 		break;
 	}
 	__raw_writel(tcon, S3C2410_TCON);
+
+	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
 static void samsung_time_setup(enum samsung_timer_mode mode, unsigned long tcnt)
 {
 	unsigned long tcon;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pwm->slock, flags);
 
 	tcon = __raw_readl(S3C2410_TCON);
 
@@ -372,11 +380,16 @@ static void samsung_time_setup(enum samsung_timer_mode mode, unsigned long tcnt)
 	__raw_writel(tcnt, S3C2410_TCNTB(mode));
 	__raw_writel(tcnt, S3C2410_TCMPB(mode));
 	__raw_writel(tcon, S3C2410_TCON);
+
+	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
 static void samsung_time_start(enum samsung_timer_mode mode, bool periodic)
 {
 	unsigned long tcon;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pwm->slock, flags);
 
 	tcon  = __raw_readl(S3C2410_TCON);
 
@@ -436,6 +449,8 @@ static void samsung_time_start(enum samsung_timer_mode mode, bool periodic)
 		break;
 	}
 	__raw_writel(tcon, S3C2410_TCON);
+
+	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
 static int samsung_set_next_event(unsigned long cycles,
Signature · 1 line
1.8.1.5
#13 lore raw

PATCH v5 9/14 clocksource: samsung-pwm: Move IRQ mask/ack handling to the driver

In reply to Tomasz Figa

Since the clocksource driver is the only user of PWM timer interrupts, there is no need to create an IRQ chip for handling them.

This patch changes the way of PWM timer interrupt handling to use real VIC/GIC interrupt requests and handle PWM mask/ack register internally in samsung-pwm clocksource driver.

---
 arch/arm/mach-exynos/include/mach/irqs.h  |  3 +--
 arch/arm/mach-s3c24xx/include/mach/irqs.h |  6 ++++++
 arch/arm/mach-s3c64xx/common.c            |  3 ---
 arch/arm/mach-s3c64xx/include/mach/irqs.h |  8 --------
 arch/arm/mach-s5p64x0/include/mach/irqs.h |  2 --
 arch/arm/mach-s5pc100/include/mach/irqs.h |  2 --
 arch/arm/mach-s5pv210/include/mach/irqs.h |  2 --
 arch/arm/plat-samsung/devs.c              | 20 ++++++++++----------
 arch/arm/plat-samsung/include/plat/irqs.h |  9 ---------
 arch/arm/plat-samsung/s5p-irq.c           |  2 --
 drivers/clocksource/samsung_pwm.c         | 10 ++++++++++
 11 files changed, 27 insertions(+), 40 deletions(-)
arch/arm/mach-exynos/include/mach/irqs.h +1 -2
index 35fe6d5..6fbe229 100644
@@ -464,10 +464,9 @@
 #define S5P_EINT_BASE2			(S5P_EINT_BASE1 + 16)
 #define S5P_GPIOINT_BASE		(S5P_EINT_BASE1 + 32)
 #define IRQ_GPIO_END			(S5P_GPIOINT_BASE + S5P_GPIOINT_COUNT)
-#define IRQ_TIMER_BASE			(IRQ_GPIO_END + 64)
 
 /* Set the default NR_IRQS */
 
-#define NR_IRQS				(IRQ_TIMER_BASE + IRQ_TIMER_COUNT)
+#define NR_IRQS				(IRQ_GPIO_END + 64)
 
 #endif /* __ASM_ARCH_IRQS_H */
arch/arm/mach-s3c24xx/include/mach/irqs.h +6 -0
index b6dd4cb..287545f 100644
@@ -205,6 +205,12 @@
 #define IRQ_LCD_VSYNC		IRQ_S3C2443_LCD3
 #define IRQ_LCD_SYSTEM		IRQ_S3C2443_LCD2
 
+#define IRQ_TIMER0_VIC		IRQ_TIMER0
+#define IRQ_TIMER1_VIC		IRQ_TIMER1
+#define IRQ_TIMER2_VIC		IRQ_TIMER2
+#define IRQ_TIMER3_VIC		IRQ_TIMER3
+#define IRQ_TIMER4_VIC		IRQ_TIMER4
+
 #ifdef CONFIG_CPU_S3C2440
 #define IRQ_S3C244X_AC97 IRQ_S3C2440_AC97
 #else
arch/arm/mach-s3c64xx/common.c +0 -3
index 89d2823..4cb9afe6 100644
@@ -198,9 +198,6 @@ void __init s3c64xx_init_irq(u32 vic0_valid, u32 vic1_valid)
 	/* initialise the pair of VICs */
 	vic_init(VA_VIC0, IRQ_VIC0_BASE, vic0_valid, IRQ_VIC0_RESUME);
 	vic_init(VA_VIC1, IRQ_VIC1_BASE, vic1_valid, IRQ_VIC1_RESUME);
-
-	/* add the timer sub-irqs */
-	s3c_init_vic_timer_irq(5, IRQ_TIMER0);
 }
 
 #define eint_offset(irq)	((irq) - IRQ_EINT(0))
arch/arm/mach-s3c64xx/include/mach/irqs.h +0 -8
index 96d60e0..67bbd1d 100644
@@ -107,14 +107,6 @@
 #define IRQ_TC			IRQ_PENDN
 #define IRQ_ADC			S3C64XX_IRQ_VIC1(31)
 
-#define S3C64XX_TIMER_IRQ(x)	S3C_IRQ(64 + (x))
-
-#define IRQ_TIMER0		S3C64XX_TIMER_IRQ(0)
-#define IRQ_TIMER1		S3C64XX_TIMER_IRQ(1)
-#define IRQ_TIMER2		S3C64XX_TIMER_IRQ(2)
-#define IRQ_TIMER3		S3C64XX_TIMER_IRQ(3)
-#define IRQ_TIMER4		S3C64XX_TIMER_IRQ(4)
-
 /* compatibility for device defines */
 
 #define IRQ_IIC1		IRQ_S3C6410_IIC1
arch/arm/mach-s5p64x0/include/mach/irqs.h +0 -2
index 5b845e8..53982db 100644
@@ -141,8 +141,6 @@
 
 #define IRQ_EINT_GROUP(grp, x)	(IRQ_EINT_GROUP##grp##_BASE + (x))
 
-#define IRQ_TIMER_BASE		(11)
-
 /* Set the default NR_IRQS */
 
 #define NR_IRQS			(IRQ_EINT_GROUP8_BASE + IRQ_EINT_GROUP8_NR + 1)
arch/arm/mach-s5pc100/include/mach/irqs.h +0 -2
index 2870f12..d2eb475 100644
@@ -97,8 +97,6 @@
 #define IRQ_SDMFIQ		S5P_IRQ_VIC2(31)
 #define IRQ_VIC_END		S5P_IRQ_VIC2(31)
 
-#define IRQ_TIMER_BASE		(11)
-
 #define S5P_EINT_BASE1		(S5P_IRQ_VIC0(0))
 #define S5P_EINT_BASE2		(IRQ_VIC_END + 1)
 
arch/arm/mach-s5pv210/include/mach/irqs.h +0 -2
index e777e01..5e0de3a 100644
@@ -118,8 +118,6 @@
 #define IRQ_MDNIE3		S5P_IRQ_VIC3(8)
 #define IRQ_VIC_END		S5P_IRQ_VIC3(31)
 
-#define IRQ_TIMER_BASE		(11)
-
 #define S5P_EINT_BASE1		(S5P_IRQ_VIC0(0))
 #define S5P_EINT_BASE2		(IRQ_VIC_END + 1)
 
arch/arm/plat-samsung/devs.c +10 -10
index fbfabd2..68b163a 100644
@@ -1162,20 +1162,20 @@ arch_initcall(s5p_pmu_init);
  */
 
 struct platform_device s3c_device_timer[] = {
-	[0] = { DEFINE_S3C_TIMER(0, IRQ_TIMER0) },
-	[1] = { DEFINE_S3C_TIMER(1, IRQ_TIMER1) },
-	[2] = { DEFINE_S3C_TIMER(2, IRQ_TIMER2) },
-	[3] = { DEFINE_S3C_TIMER(3, IRQ_TIMER3) },
-	[4] = { DEFINE_S3C_TIMER(4, IRQ_TIMER4) },
+	[0] = { DEFINE_S3C_TIMER(0, IRQ_TIMER0_VIC) },
+	[1] = { DEFINE_S3C_TIMER(1, IRQ_TIMER1_VIC) },
+	[2] = { DEFINE_S3C_TIMER(2, IRQ_TIMER2_VIC) },
+	[3] = { DEFINE_S3C_TIMER(3, IRQ_TIMER3_VIC) },
+	[4] = { DEFINE_S3C_TIMER(4, IRQ_TIMER4_VIC) },
 };
 #endif /* CONFIG_SAMSUNG_DEV_PWM */
 
 static struct resource samsung_pwm_resource[] = {
-	DEFINE_RES_IRQ(IRQ_TIMER0),
-	DEFINE_RES_IRQ(IRQ_TIMER1),
-	DEFINE_RES_IRQ(IRQ_TIMER2),
-	DEFINE_RES_IRQ(IRQ_TIMER3),
-	DEFINE_RES_IRQ(IRQ_TIMER4),
+	DEFINE_RES_IRQ(IRQ_TIMER0_VIC),
+	DEFINE_RES_IRQ(IRQ_TIMER1_VIC),
+	DEFINE_RES_IRQ(IRQ_TIMER2_VIC),
+	DEFINE_RES_IRQ(IRQ_TIMER3_VIC),
+	DEFINE_RES_IRQ(IRQ_TIMER4_VIC),
 	DEFINE_RES_MEM(SAMSUNG_PA_TIMER, SZ_4K),
 };
 
arch/arm/plat-samsung/include/plat/irqs.h +0 -9
index df46b77..039001c 100644
@@ -44,15 +44,6 @@
 #define S5P_IRQ_VIC2(x)		(S5P_VIC2_BASE + (x))
 #define S5P_IRQ_VIC3(x)		(S5P_VIC3_BASE + (x))
 
-#define S5P_TIMER_IRQ(x)	(IRQ_TIMER_BASE + (x))
-
-#define IRQ_TIMER0		S5P_TIMER_IRQ(0)
-#define IRQ_TIMER1		S5P_TIMER_IRQ(1)
-#define IRQ_TIMER2		S5P_TIMER_IRQ(2)
-#define IRQ_TIMER3		S5P_TIMER_IRQ(3)
-#define IRQ_TIMER4		S5P_TIMER_IRQ(4)
-#define IRQ_TIMER_COUNT		(5)
-
 #define IRQ_EINT(x)		((x) < 16 ? ((x) + S5P_EINT_BASE1) \
 					: ((x) - 16 + S5P_EINT_BASE2))
 
arch/arm/plat-samsung/s5p-irq.c +0 -2
index 103e371..ce8564d 100644
@@ -29,6 +29,4 @@ void __init s5p_init_irq(u32 *vic, u32 num_vic)
 	for (irq = 0; irq < num_vic; irq++)
 		vic_init(VA_VIC(irq), VIC_BASE(irq), vic[irq], 0);
 #endif
-
-	s3c_init_vic_timer_irq(5, IRQ_TIMER0);
 }
drivers/clocksource/samsung_pwm.c +10 -0
index bddf9aa..3219ecc 100644
@@ -509,6 +509,11 @@ static irqreturn_t samsung_clock_event_isr(int irq, void *dev_id)
 {
 	struct clock_event_device *evt = dev_id;
 
+	if (pwm->variant.has_tint_cstat) {
+		u32 mask = (1 << timer_source.event_id);
+		writel(mask | (mask << 5), S3C64XX_TINT_CSTAT);
+	}
+
 	evt->event_handler(evt);
 
 	return IRQ_HANDLED;
@@ -545,6 +550,11 @@ static void __init samsung_clockevent_init(void)
 
 	irq_number = pwm->irq[timer_source.event_id];
 	setup_irq(irq_number, &samsung_clock_event_irq);
+
+	if (pwm->variant.has_tint_cstat) {
+		u32 mask = (1 << timer_source.event_id);
+		writel(mask | (mask << 5), S3C64XX_TINT_CSTAT);
+	}
 }
 
 static void __iomem *samsung_timer_reg(void)
Signature · 1 line
1.8.1.5
#14 lore raw

PATCH v5 10/14 ARM: SAMSUNG: Remove unused PWM timer IRQ chip code

In reply to Tomasz Figa

As the need for an IRQ chip handling PWM timer interrupt chaining is gone now, this patch removes all the code made unnecessary.

---
 arch/arm/Kconfig                                   |  1 -
 arch/arm/mach-s3c64xx/common.c                     |  1 -
 arch/arm/plat-samsung/Kconfig                      |  6 --
 arch/arm/plat-samsung/Makefile                     |  1 -
 arch/arm/plat-samsung/include/plat/irq-vic-timer.h | 13 ---
 arch/arm/plat-samsung/irq-vic-timer.c              | 98 ----------------------
 arch/arm/plat-samsung/s5p-irq.c                    |  1 -
 7 files changed, 121 deletions(-)
 delete mode 100644 arch/arm/plat-samsung/include/plat/irq-vic-timer.h
 delete mode 100644 arch/arm/plat-samsung/irq-vic-timer.c
arch/arm/Kconfig +0 -1
index a957aa0..648eda3 100644
@@ -806,7 +806,6 @@ config ARCH_S3C64XX
 	select S3C_GPIO_TRACK
 	select SAMSUNG_CLKSRC
 	select SAMSUNG_GPIOLIB_4BIT
-	select SAMSUNG_IRQ_VIC_TIMER
 	select USB_ARCH_HAS_OHCI
 	help
 	  Samsung S3C64XX series based systems
arch/arm/mach-s3c64xx/common.c +0 -1
index 4cb9afe6..e79ca92 100644
@@ -42,7 +42,6 @@
 #include <plat/pm.h>
 #include <plat/gpio-cfg.h>
 #include <plat/irq-uart.h>
-#include <plat/irq-vic-timer.h>
 #include <plat/regs-irqtype.h>
 #include <plat/regs-serial.h>
 #include <plat/watchdog-reset.h>
arch/arm/plat-samsung/Kconfig +0 -6
index 6f632ba..9951879 100644
@@ -27,7 +27,6 @@ config PLAT_S5P
 	select S5P_GPIO_DRVSTR
 	select SAMSUNG_CLKSRC if !COMMON_CLK
 	select SAMSUNG_GPIOLIB_4BIT
-	select SAMSUNG_IRQ_VIC_TIMER
 	help
 	  Base platform code for Samsung's S5P series SoC.
 
@@ -79,11 +78,6 @@ config S5P_CLOCK
 
 # options for IRQ support
 
-config SAMSUNG_IRQ_VIC_TIMER
-       bool
-       help
-         Internal configuration to build the VIC timer interrupt code.
-
 config S5P_IRQ
 	def_bool (ARCH_S5P64X0 || ARCH_S5PC100 || ARCH_S5PV210 || ARCH_EXYNOS)
 	help
arch/arm/plat-samsung/Makefile +0 -1
index 87494e1..ae2a0fd 100644
@@ -19,7 +19,6 @@ obj-$(CONFIG_SAMSUNG_CLOCK)	+= pwm-clock.o
 obj-$(CONFIG_SAMSUNG_CLKSRC)	+= clock-clksrc.o
 obj-$(CONFIG_S5P_CLOCK)		+= s5p-clock.o
 
-obj-$(CONFIG_SAMSUNG_IRQ_VIC_TIMER) += irq-vic-timer.o
 obj-$(CONFIG_S5P_IRQ)		+= s5p-irq.o
 obj-$(CONFIG_S5P_EXT_INT)	+= s5p-irq-eint.o
 obj-$(CONFIG_S5P_GPIO_INT)	+= s5p-irq-gpioint.o
arch/arm/plat-samsung/include/plat/irq-vic-timer.h deleted +0 -13
deleted file mode 100644
index 5b9c42f..0000000
@@ -1,13 +0,0 @@
-/* arch/arm/plat-samsung/include/plat/irq-vic-timer.h
- *
- * Copyright (c) 2010 Simtec Electronics
- *	Ben Dooks <[email protected]>
- *
- * Header file for Samsung SoC IRQ VIC timer
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
-*/
-
-extern void s3c_init_vic_timer_irq(unsigned int num, unsigned int timer_irq);
arch/arm/plat-samsung/irq-vic-timer.c deleted +0 -98

98 lines not on this page · raw message

arch/arm/plat-samsung/s5p-irq.c +0 -1
index ce8564d..b1e2a82 100644
@@ -18,7 +18,6 @@
 #include <mach/map.h>
 #include <plat/regs-timer.h>
 #include <plat/cpu.h>
-#include <plat/irq-vic-timer.h>
 
 void __init s5p_init_irq(u32 *vic, u32 num_vic)
 {
Signature · 1 line
1.8.1.5
#15 lore raw

PATCH v5 11/14 clocksource: samsung-pwm: Configure dividers directly

In reply to Tomasz Figa

Clock dividers present in the PWM blocks are used to generate signal for PWM timers internally, so there is no need to export them using clock API.

This patch moves handling of those dividers to the clocksource driver to not use the clock API anymore.

---
 drivers/clocksource/samsung_pwm.c | 111 ++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 51 deletions(-)
drivers/clocksource/samsung_pwm.c +60 -51
index 3219ecc..29b480a 100644
@@ -277,6 +277,15 @@ EXPORT_SYMBOL(samsung_pwm_get);
  * Clocksource driver
  */
 
+#define REG_TCFG0			0x00
+#define REG_TCFG1			0x04
+
+#define TCFG0_PRESCALER_MASK		0xff
+#define TCFG0_PRESCALER1_SHIFT		8
+
+#define TCFG1_SHIFT(x)	  		((x) * 4)
+#define TCFG1_MUX_MASK	  		0xf
+
 struct samsung_timer_source {
 	unsigned int event_id;
 	unsigned int source_id;
@@ -286,16 +295,51 @@ struct samsung_timer_source {
 };
 
 static struct samsung_pwm *pwm;
-
-static struct clk *tin_event;
-static struct clk *tin_source;
-static struct clk *tdiv_event;
-static struct clk *tdiv_source;
 static struct clk *timerclk;
 static struct samsung_timer_source timer_source;
 static unsigned long clock_count_per_tick;
 static void samsung_timer_resume(void);
 
+static void samsung_timer_set_prescale(struct samsung_pwm *pwm,
+					unsigned int channel, u16 prescale)
+{
+	unsigned long flags;
+	u8 shift = 0;
+	u32 reg;
+
+	if (channel >= 2)
+		shift = TCFG0_PRESCALER1_SHIFT;
+
+	spin_lock_irqsave(&pwm->slock, flags);
+
+	reg = readl(pwm->base + REG_TCFG0);
+	reg &= ~(TCFG0_PRESCALER_MASK << shift);
+	reg |= (prescale - 1) << shift;
+	writel(reg, pwm->base + REG_TCFG0);
+
+	spin_unlock_irqrestore(&pwm->slock, flags);
+}
+
+static void samsung_timer_set_divisor(struct samsung_pwm *pwm,
+					unsigned int channel, u8 divisor)
+{
+	u8 shift = TCFG1_SHIFT(channel);
+	unsigned long flags;
+	u32 reg;
+	u8 bits;
+
+	bits = (fls(divisor) - 1) - pwm->variant.div_base;
+
+	spin_lock_irqsave(&pwm->slock, flags);
+
+	reg = readl(pwm->base + REG_TCFG1);
+	reg &= ~(TCFG1_MUX_MASK << shift);
+	reg |= bits << shift;
+	writel(reg, pwm->base + REG_TCFG1);
+
+	spin_unlock_irqrestore(&pwm->slock, flags);
+}
+
 static void samsung_time_stop(enum samsung_timer_mode mode)
 {
 	unsigned long tcon;
@@ -531,18 +575,15 @@ static void __init samsung_clockevent_init(void)
 	unsigned long pclk;
 	unsigned long clock_rate;
 	unsigned int irq_number;
-	struct clk *tscaler;
 
 	pclk = clk_get_rate(timerclk);
 
-	tscaler = clk_get_parent(tdiv_event);
-
-	clk_set_rate(tscaler, pclk / timer_source.tscaler_div);
-	clk_set_rate(tdiv_event,
-			pclk / (timer_source.tdiv * timer_source.tscaler_div));
-	clk_set_parent(tin_event, tdiv_event);
+	samsung_timer_set_prescale(pwm, timer_source.event_id,
+						timer_source.tscaler_div);
+	samsung_timer_set_divisor(pwm, timer_source.event_id,
+						timer_source.tdiv);
 
-	clock_rate = clk_get_rate(tin_event);
+	clock_rate = pclk / (timer_source.tscaler_div * timer_source.tdiv);
 	clock_count_per_tick = clock_rate / HZ;
 
 	time_event_device.cpumask = cpumask_of(0);
@@ -607,11 +648,12 @@ static void __init samsung_clocksource_init(void)
 
 	pclk = clk_get_rate(timerclk);
 
-	clk_set_rate(tdiv_source,
-			pclk / (timer_source.tdiv * timer_source.tscaler_div));
-	clk_set_parent(tin_source, tdiv_source);
+	samsung_timer_set_prescale(pwm, timer_source.source_id,
+						timer_source.tscaler_div);
+	samsung_timer_set_divisor(pwm, timer_source.source_id,
+						timer_source.tdiv);
 
-	clock_rate = clk_get_rate(tin_source);
+	clock_rate = pclk / (timer_source.tscaler_div * timer_source.tdiv);
 
 	samsung_time_setup(timer_source.source_id, timer_source.tcnt_max);
 	samsung_time_start(timer_source.source_id, true);
@@ -628,44 +670,11 @@ static void __init samsung_clocksource_init(void)
 
 static void __init samsung_timer_resources(void)
 {
-
-	unsigned long event_id = timer_source.event_id;
-	unsigned long source_id = timer_source.source_id;
-	char devname[15];
-
 	timerclk = clk_get(NULL, "timers");
 	if (IS_ERR(timerclk))
 		panic("failed to get timers clock for timer");
 
-	clk_enable(timerclk);
-
-	sprintf(devname, "s3c24xx-pwm.%lu", event_id);
-	s3c_device_timer[event_id].id = event_id;
-	s3c_device_timer[event_id].dev.init_name = devname;
-
-	tin_event = clk_get(&s3c_device_timer[event_id].dev, "pwm-tin");
-	if (IS_ERR(tin_event))
-		panic("failed to get pwm-tin clock for event timer");
-
-	tdiv_event = clk_get(&s3c_device_timer[event_id].dev, "pwm-tdiv");
-	if (IS_ERR(tdiv_event))
-		panic("failed to get pwm-tdiv clock for event timer");
-
-	clk_enable(tin_event);
-
-	sprintf(devname, "s3c24xx-pwm.%lu", source_id);
-	s3c_device_timer[source_id].id = source_id;
-	s3c_device_timer[source_id].dev.init_name = devname;
-
-	tin_source = clk_get(&s3c_device_timer[source_id].dev, "pwm-tin");
-	if (IS_ERR(tin_source))
-		panic("failed to get pwm-tin clock for source timer");
-
-	tdiv_source = clk_get(&s3c_device_timer[source_id].dev, "pwm-tdiv");
-	if (IS_ERR(tdiv_source))
-		panic("failed to get pwm-tdiv clock for source timer");
-
-	clk_enable(tin_source);
+	clk_prepare_enable(timerclk);
 
 	timer_source.tcnt_max = (1UL << pwm->variant.bits) - 1;
 	if (pwm->variant.bits == 16) {
Signature · 1 line
1.8.1.5
#16 lore raw

PATCH v5 12/14 clocksource: samsung-pwm: Do not use static mapping of registers

In reply to Tomasz Figa

This patch modifies the samsung-pwm clocksource driver to use registers through the dynamic mapping created by the master driver, instead of static, hardcoded mapping.

By the way, register definitions and accesses are cleaned up.

---
 drivers/clocksource/samsung_pwm.c | 190 ++++++++++----------------------------
 1 file changed, 50 insertions(+), 140 deletions(-)
drivers/clocksource/samsung_pwm.c +50 -140
index 29b480a..99c376d 100644
@@ -27,12 +27,9 @@
 #include <asm/smp_twd.h>
 #include <asm/mach/time.h>
 #include <asm/mach/arch.h>
-#include <asm/mach/map.h>
 #include <asm/sched_clock.h>
 
-#include <mach/map.h>
 #include <plat/devs.h>
-#include <plat/regs-timer.h>
 #include <plat/samsung-time.h>
 
 /*
@@ -279,6 +276,11 @@ EXPORT_SYMBOL(samsung_pwm_get);
 
 #define REG_TCFG0			0x00
 #define REG_TCFG1			0x04
+#define REG_TCON			0x08
+#define REG_TINT_CSTAT			0x44
+
+#define REG_TCNTB(chan)			(0x0c + 12 * (chan))
+#define REG_TCMPB(chan)			(0x10 + 12 * (chan))
 
 #define TCFG0_PRESCALER_MASK		0xff
 #define TCFG0_PRESCALER1_SHIFT		8
@@ -286,6 +288,11 @@ EXPORT_SYMBOL(samsung_pwm_get);
 #define TCFG1_SHIFT(x)	  		((x) * 4)
 #define TCFG1_MUX_MASK	  		0xf
 
+#define TCON_START(chan)		(1 << (4 * (chan) + 0))
+#define TCON_MANUALUPDATE(chan)		(1 << (4 * (chan) + 1))
+#define TCON_INVERT(chan)		(1 << (4 * (chan) + 2))
+#define TCON_AUTORELOAD(chan)		(1 << (4 * (chan) + 3))
+
 struct samsung_timer_source {
 	unsigned int event_id;
 	unsigned int source_id;
@@ -340,159 +347,69 @@ static void samsung_timer_set_divisor(struct samsung_pwm *pwm,
 	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
-static void samsung_time_stop(enum samsung_timer_mode mode)
+static void samsung_time_stop(unsigned int channel)
 {
 	unsigned long tcon;
 	unsigned long flags;
 
-	spin_lock_irqsave(&pwm->slock, flags);
-
-	tcon = __raw_readl(S3C2410_TCON);
-
-	switch (mode) {
-	case SAMSUNG_PWM0:
-		tcon &= ~S3C2410_TCON_T0START;
-		break;
-
-	case SAMSUNG_PWM1:
-		tcon &= ~S3C2410_TCON_T1START;
-		break;
-
-	case SAMSUNG_PWM2:
-		tcon &= ~S3C2410_TCON_T2START;
-		break;
+	if (channel > 0)
+		++channel;
 
-	case SAMSUNG_PWM3:
-		tcon &= ~S3C2410_TCON_T3START;
-		break;
-
-	case SAMSUNG_PWM4:
-		tcon &= ~S3C2410_TCON_T4START;
-		break;
+	spin_lock_irqsave(&pwm->slock, flags);
 
-	default:
-		printk(KERN_ERR "Invalid Timer %d\n", mode);
-		break;
-	}
-	__raw_writel(tcon, S3C2410_TCON);
+	tcon = __raw_readl(pwm->base + REG_TCON);
+	tcon &= ~TCON_START(channel);
+	__raw_writel(tcon, pwm->base + REG_TCON);
 
 	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
-static void samsung_time_setup(enum samsung_timer_mode mode, unsigned long tcnt)
+static void samsung_time_setup(unsigned int channel, unsigned long tcnt)
 {
 	unsigned long tcon;
 	unsigned long flags;
+	unsigned int tcon_chan = channel;
+
+	if (tcon_chan > 0)
+		++tcon_chan;
 
 	spin_lock_irqsave(&pwm->slock, flags);
 
-	tcon = __raw_readl(S3C2410_TCON);
+	tcon = __raw_readl(pwm->base + REG_TCON);
 
 	tcnt--;
 
-	switch (mode) {
-	case SAMSUNG_PWM0:
-		tcon &= ~(0x0f << 0);
-		tcon |= S3C2410_TCON_T0MANUALUPD;
-		break;
-
-	case SAMSUNG_PWM1:
-		tcon &= ~(0x0f << 8);
-		tcon |= S3C2410_TCON_T1MANUALUPD;
-		break;
-
-	case SAMSUNG_PWM2:
-		tcon &= ~(0x0f << 12);
-		tcon |= S3C2410_TCON_T2MANUALUPD;
-		break;
+	tcon &= ~(TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan));
+	tcon |= TCON_MANUALUPDATE(tcon_chan);
 
-	case SAMSUNG_PWM3:
-		tcon &= ~(0x0f << 16);
-		tcon |= S3C2410_TCON_T3MANUALUPD;
-		break;
-
-	case SAMSUNG_PWM4:
-		tcon &= ~(0x07 << 20);
-		tcon |= S3C2410_TCON_T4MANUALUPD;
-		break;
-
-	default:
-		printk(KERN_ERR "Invalid Timer %d\n", mode);
-		break;
-	}
-
-	__raw_writel(tcnt, S3C2410_TCNTB(mode));
-	__raw_writel(tcnt, S3C2410_TCMPB(mode));
-	__raw_writel(tcon, S3C2410_TCON);
+	__raw_writel(tcnt, pwm->base + REG_TCNTB(channel));
+	__raw_writel(tcnt, pwm->base + REG_TCMPB(channel));
+	__raw_writel(tcon, pwm->base + REG_TCON);
 
 	spin_unlock_irqrestore(&pwm->slock, flags);
 }
 
-static void samsung_time_start(enum samsung_timer_mode mode, bool periodic)
+static void samsung_time_start(unsigned int channel, bool periodic)
 {
 	unsigned long tcon;
 	unsigned long flags;
 
-	spin_lock_irqsave(&pwm->slock, flags);
-
-	tcon  = __raw_readl(S3C2410_TCON);
-
-	switch (mode) {
-	case SAMSUNG_PWM0:
-		tcon |= S3C2410_TCON_T0START;
-		tcon &= ~S3C2410_TCON_T0MANUALUPD;
-
-		if (periodic)
-			tcon |= S3C2410_TCON_T0RELOAD;
-		else
-			tcon &= ~S3C2410_TCON_T0RELOAD;
-		break;
-
-	case SAMSUNG_PWM1:
-		tcon |= S3C2410_TCON_T1START;
-		tcon &= ~S3C2410_TCON_T1MANUALUPD;
-
-		if (periodic)
-			tcon |= S3C2410_TCON_T1RELOAD;
-		else
-			tcon &= ~S3C2410_TCON_T1RELOAD;
-		break;
-
-	case SAMSUNG_PWM2:
-		tcon |= S3C2410_TCON_T2START;
-		tcon &= ~S3C2410_TCON_T2MANUALUPD;
+	if (channel > 0)
+		++channel;
 
-		if (periodic)
-			tcon |= S3C2410_TCON_T2RELOAD;
-		else
-			tcon &= ~S3C2410_TCON_T2RELOAD;
-		break;
+	spin_lock_irqsave(&pwm->slock, flags);
 
-	case SAMSUNG_PWM3:
-		tcon |= S3C2410_TCON_T3START;
-		tcon &= ~S3C2410_TCON_T3MANUALUPD;
+	tcon = __raw_readl(pwm->base + REG_TCON);
 
-		if (periodic)
-			tcon |= S3C2410_TCON_T3RELOAD;
-		else
-			tcon &= ~S3C2410_TCON_T3RELOAD;
-		break;
+	tcon &= ~TCON_MANUALUPDATE(channel);
+	tcon |= TCON_START(channel);
 
-	case SAMSUNG_PWM4:
-		tcon |= S3C2410_TCON_T4START;
-		tcon &= ~S3C2410_TCON_T4MANUALUPD;
+	if (periodic)
+		tcon |= TCON_AUTORELOAD(channel);
+	else
+		tcon &= ~TCON_AUTORELOAD(channel);
 
-		if (periodic)
-			tcon |= S3C2410_TCON_T4RELOAD;
-		else
-			tcon &= ~S3C2410_TCON_T4RELOAD;
-		break;
-
-	default:
-		printk(KERN_ERR "Invalid Timer %d\n", mode);
-		break;
-	}
-	__raw_writel(tcon, S3C2410_TCON);
+	__raw_writel(tcon, pwm->base + REG_TCON);
 
 	spin_unlock_irqrestore(&pwm->slock, flags);
 }
@@ -555,7 +472,7 @@ static irqreturn_t samsung_clock_event_isr(int irq, void *dev_id)
 
 	if (pwm->variant.has_tint_cstat) {
 		u32 mask = (1 << timer_source.event_id);
-		writel(mask | (mask << 5), S3C64XX_TINT_CSTAT);
+		writel(mask | (mask << 5), pwm->base + REG_TINT_CSTAT);
 	}
 
 	evt->event_handler(evt);
@@ -594,32 +511,25 @@ static void __init samsung_clockevent_init(void)
 
 	if (pwm->variant.has_tint_cstat) {
 		u32 mask = (1 << timer_source.event_id);
-		writel(mask | (mask << 5), S3C64XX_TINT_CSTAT);
+		writel(mask | (mask << 5), pwm->base + REG_TINT_CSTAT);
 	}
 }
 
 static void __iomem *samsung_timer_reg(void)
 {
-	unsigned long offset = 0;
-
 	switch (timer_source.source_id) {
-	case SAMSUNG_PWM0:
-	case SAMSUNG_PWM1:
-	case SAMSUNG_PWM2:
-	case SAMSUNG_PWM3:
-		offset = (timer_source.source_id * 0x0c) + 0x14;
-		break;
+	case 0:
+	case 1:
+	case 2:
+	case 3:
+		return pwm->base + timer_source.source_id * 0x0c + 0x14;
 
-	case SAMSUNG_PWM4:
-		offset = 0x40;
-		break;
+	case 4:
+		return pwm->base + 0x40;
 
 	default:
-		printk(KERN_ERR "Invalid Timer %d\n", timer_source.source_id);
-		return NULL;
+		BUG();
 	}
-
-	return S3C_TIMERREG(offset);
 }
 
 /*
Signature · 1 line
1.8.1.5
#17 lore raw

PATCH v5 13/14 clocksource: samsung-pwm: Drop unnecessary includes

In reply to Tomasz Figa

This patch removes unneccessary header inclusions from the samsung-pwm clocksource driver.

---
 drivers/clocksource/samsung_pwm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/clocksource/samsung_pwm.c +0 -6
index 99c376d..b816b65 100644
@@ -24,14 +24,8 @@
 
 #include <clocksource/samsung_pwm.h>
 
-#include <asm/smp_twd.h>
-#include <asm/mach/time.h>
-#include <asm/mach/arch.h>
 #include <asm/sched_clock.h>
 
-#include <plat/devs.h>
-#include <plat/samsung-time.h>
-
 /*
  * PWM master driver
  */
Signature · 1 line
1.8.1.5
#18 lore raw

PATCH v5 14/14 clocksource: samsung-pwm: Prepare for clocksource_of_init

In reply to Tomasz Figa

This patch adds support for clocksource instantiation using clocksource_of_init, by declaring OF clocksources with CLOCKSOURCE_OF_DECLARE() macro.

---
 drivers/clocksource/samsung_pwm.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/clocksource/samsung_pwm.c +21 -2
index b816b65..a12ee08 100644
@@ -590,12 +590,13 @@ static void __init samsung_timer_resources(void)
 	}
 }
 
-void __init samsung_pwm_clocksource_init(struct platform_device *pdev)
+static void __init __samsung_pwm_clocksource_init(
+			struct platform_device *pdev, struct device_node *np)
 {
 	u8 mask;
 	int channel;
 
-	pwm = samsung_pwm_get(pdev, NULL);
+	pwm = samsung_pwm_get(pdev, np);
 	if (IS_ERR(pwm))
 		panic("failed to get PWM device");
 
@@ -615,3 +616,21 @@ void __init samsung_pwm_clocksource_init(struct platform_device *pdev)
 	samsung_clockevent_init();
 	samsung_clocksource_init();
 }
+
+static void __init samsung_pwm_clocksource_init_of(struct device_node *np)
+{
+	__samsung_pwm_clocksource_init(NULL, np);
+}
+CLOCKSOURCE_OF_DECLARE(s3c2410_pwm, "samsung,s3c2410-pwm",
+					samsung_pwm_clocksource_init_of);
+CLOCKSOURCE_OF_DECLARE(s3c6400_pwm, "samsung,s3c6400-pwm",
+					samsung_pwm_clocksource_init_of);
+CLOCKSOURCE_OF_DECLARE(s5p6440_pwm, "samsung,s5p6440-pwm",
+					samsung_pwm_clocksource_init_of);
+CLOCKSOURCE_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm",
+					samsung_pwm_clocksource_init_of);
+
+void __init samsung_pwm_clocksource_init(struct platform_device *pdev)
+{
+	__samsung_pwm_clocksource_init(pdev, NULL);
+}
Signature · 1 line
1.8.1.5
#19 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

In reply to Tomasz Figa
Quoted 12 lines · Tomasz Figa

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Quoted 3 lines

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

Applied
#20 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Tomasz Figa

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Quoted 5 lines
Quoted 3 lines

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

Applied, this whole series.

Thanks.

- Kukjin

#21 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

Quoted 19 lines · On Tuesday 23 of April 2013 02:37:33 Kukjin Kim wrote:
Quoted 18 lines · Arnd Bergmann
Quoted 17 lines · Tomasz Figa

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only
samsung-time driver is reworked to use the master driver at this time,
since the PWM driver can be already considered broken at the moment and
needs separate series of several patches to fix and clean it up, which
I am already working on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

Applied, this whole series.

It would be nice if we could still get this for 3.10, but AFAIK it is already much too late.

I've discussed this matter with Arnd and the solution that can be accepted by arm-soc maintainers is to send a subset of this series, like in the patch sent by Arnd (clocksource: add samsung pwm timer driver; it needs additional fixes, though.).

Best regards,
Tomasz

#22 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

In reply to Tomasz Figa

Hi Tomasz,

Am Freitag, 12. April 2013, 21:17:16 schrieb Tomasz Figa:

Quoted 12 lines

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Quoted 3 lines

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

On a s3c2416 based board with both non-dt and preliminary-dt support

One nitpick:

Without dt support, you get this:

CC drivers/clocksource/samsung_pwm.o
drivers/clocksource/samsung_pwm.c:620: warning: ?samsung_pwm_clocksource_init_of? defined but not used

So, something like the following might be necessary

-------------- 8< -------------------

drivers/clocksource/samsung_pwm.c +2 -0
index a12ee08..2bf8303 100644
@@ -617,6 +617,7 @@ static void __init __samsung_pwm_clocksource_init(
        samsung_clocksource_init();
 }
 
+#ifdef CONFIG_CLKSRC_OF
 static void __init samsung_pwm_clocksource_init_of(struct device_node *np)
 {
        __samsung_pwm_clocksource_init(NULL, np);
@@ -629,6 +630,7 @@ CLOCKSOURCE_OF_DECLARE(s5p6440_pwm, "samsung,s5p6440-pwm",
                                        samsung_pwm_clocksource_init_of);
 CLOCKSOURCE_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm",
                                        samsung_pwm_clocksource_init_of);
+#endif
 
 void __init samsung_pwm_clocksource_init(struct platform_device *pdev)
 {

-------------- 8< -------------------

Heiko

#23 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

Quoted 7 lines · On Saturday 13 April 2013 00:22:48 Heiko St?bner wrote:

Without dt support, you get this:

CC drivers/clocksource/samsung_pwm.o
drivers/clocksource/samsung_pwm.c:620: warning: ?samsung_pwm_clocksource_init_of? defined but not used

So, something like the following might be necessary

That patch should not be required any more with the definition

#ifdef CONFIG_CLKSRC_OF
extern void clocksource_of_init(void);

#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)                        \
        static const struct of_device_id __clksrc_of_table_##name       \
                __used __section(__clksrc_of_table)                     \
                 = { .compatible = compat,                              \
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }
#else
static inline void clocksource_of_init(void) {}
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)                        \
        static const struct of_device_id __clksrc_of_table_##name       \
                __attribute__((unused))                                 \
                 = { .compatible = compat,                              \
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }

#endif

which turns the ?samsung_pwm_clocksource_init_of? function into an unused symbol that gets silently dropped by gcc, at least in theory. Are you using the latest clksrc/cleanup branch as a base?

Arnd

#24 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

Am Samstag, 13. April 2013, 00:26:43 schrieb Arnd Bergmann:

Quoted 28 lines · On Saturday 13 April 2013 00:22:48 Heiko St?bner wrote:
Quoted 7 lines

Without dt support, you get this:
CC drivers/clocksource/samsung_pwm.o

drivers/clocksource/samsung_pwm.c:620: warning:
?samsung_pwm_clocksource_init_of? defined but not used

So, something like the following might be necessary

That patch should not be required any more with the definition

#ifdef CONFIG_CLKSRC_OF
extern void clocksource_of_init(void);

#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)                        \
        static const struct of_device_id __clksrc_of_table_##name       \
                __used __section(__clksrc_of_table)                     \
                 = { .compatible = compat,                              \
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn
} #else
static inline void clocksource_of_init(void) {}
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)                        \
        static const struct of_device_id __clksrc_of_table_##name       \
                __attribute__((unused))                                 \
                 = { .compatible = compat,                              \
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn
} #endif
Quoted 3 lines

which turns the ?samsung_pwm_clocksource_init_of? function into an unused symbol that gets silently dropped by gcc, at least in theory. Are you using the latest clksrc/cleanup branch as a base?

Nope, I just put the stuff on top of all the other changes. So it seems everything is fine and working ... very nice :-)

Heiko

#25 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

Quoted 45 lines · On Saturday 13 of April 2013 00:39:24 Heiko St?bner wrote:

Am Samstag, 13. April 2013, 00:26:43 schrieb Arnd Bergmann:

Quoted 44 lines · On Saturday 13 April 2013 00:22:48 Heiko St?bner wrote:
Quoted 7 lines

Without dt support, you get this:
CC drivers/clocksource/samsung_pwm.o

drivers/clocksource/samsung_pwm.c:620: warning:
?samsung_pwm_clocksource_init_of? defined but not used

So, something like the following might be necessary

That patch should not be required any more with the definition

#ifdef CONFIG_CLKSRC_OF
extern void clocksource_of_init(void);

#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)
\>

        static const struct of_device_id __clksrc_of_table_##name     
         \
        
                __used __section(__clksrc_of_table)                   
                 \
                
                 = { .compatible = compat,                            
                  \
                 
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn
                     : fn

} #else
static inline void clocksource_of_init(void) {}
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn)
\>

        static const struct of_device_id __clksrc_of_table_##name     
         \
        
                __attribute__((unused))                               
                 \
                
                 = { .compatible = compat,                            
                  \
                 
                     .data = (fn == (clocksource_of_init_fn)NULL) ? fn
                     : fn
Quoted 8 lines
Quoted 5 lines

} #endif

which turns the ?samsung_pwm_clocksource_init_of? function into an unused symbol that gets silently dropped by gcc, at least in theory. Are you using the latest clksrc/cleanup branch as a base?

Nope, I just put the stuff on top of all the other changes. So it seems everything is fine and working ... very nice :-)

Great. Thanks for testing.

I will try to rebase my patches for s3c64xx on top of this and do some testing as well.

Best regards,
Tomasz

#26 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

In reply to Tomasz Figa
Quoted 51 lines · On Friday 12 of April 2013 21:17:16 Tomasz Figa wrote:

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

Changes since v4:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/17464)
- Changed the design again - now clocksource driver is considered the
master and exports a single function to get access to things like base address, hardware variant information, shared spinlock for register access synchronization and interrupt numbers
- Renamed the clocksource driver to samsung_pwm
- Cleaned up the code a bit more
- Added clocksource_of_init support

Changes since v3:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16664/)
- Changed the design to use common (master) driver for operations that can be done from both clocksource and PWM drivers (as suggested by Arnd Bergmann) - needed to properly synchronize access to PWM
registers - Moved handling of PWM prescaler and divider to master driver

Changes since v2:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16158)
- Addressed comments from Rob Herring and Mark Rutland
- Removed unused register definitions
- Replaced samsung,source-timer and samsung,event-timer properties with samsung,pwm-outputs property that defines which PWM channels are reserved for PWM outputs on particular platform
- Split non-DT and DT initialization into two functions
- Fixed a copy paste error

Changes since v1:
(http://thread.gmane.org/gmane.linux.kernel.samsung-soc/16005)
- Addressed comments from Mark Rutland
- Documented struct samsung_timer_variant
- Dropped inactive mail addresses from CC

Quoted 15 lines

Tomasz Figa (14):
ARM: SAMSUNG: Move samsung-time to drivers/clocksource
clocksource: samsung-pwm: Clean up platform header
clocksource: samsung-pwm: Add infrastructure to share PWM hardware
ARM: SAMSUNG: Unify base address definitions of timer block
ARM: SAMSUNG: Add new PWM platform device
ARM: SAMSUNG: Set PWM platform data
clocksource: samsung-pwm: Use platform data to setup the clocksource
clocksource: samsung-pwm: Synchronize register accesses
clocksource: samsung-pwm: Move IRQ mask/ack handling to the driver
ARM: SAMSUNG: Remove unused PWM timer IRQ chip code
clocksource: samsung-pwm: Configure dividers directly
clocksource: samsung-pwm: Do not use static mapping of registers
clocksource: samsung-pwm: Drop unnecessary includes
clocksource: samsung-pwm: Prepare for clocksource_of_init

On S3C6410-based Tiny6410 (Mini6410-compatible) board, both with and without Device Tree:

Best regards,
Tomasz

#27 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

In reply to Tomasz Figa
Quoted 4 lines · Tomasz Figa

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130416/4c95907a/attachment-0001.sig>

#28 lore raw

v5 cover ARM: samsung-time: Prepare for multiplatform support

In reply to Tomasz Figa
Quoted 12 lines · Tomasz Figa

This series is an attempt to make the samsung-time clocksource driver ready for multiplatform kernels. It moves the driver to drivers/clocksource, cleans it up from uses of static platform-specific definitions, simplifies timer interrupt handling and adds Device Tree support.

The samsung_pwm clocksource driver is made the master driver, which exposes a single function to the PWM driver to get required data. Only samsung-time driver is reworked to use the master driver at this time, since the PWM driver can be already considered broken at the moment and needs separate series of several patches to fix and clean it up, which I am already working on.

Quoted 3 lines

Tested on Universal C210 board with Device Tree. Not tested without Device Tree, since it has been already broken before this series. Compile tested for other related SoCs.

On s3c2440 based board