Commit 852bd07c80b27f330da8da367989bcd8121569a7

Authored by Minkyu Kang
1 parent d93d0f0cfe

ARMV7: S5P: make s5p-common for sharing the code between s5pc1xx and s5pc2xx

This patch adds basic support for s5pc210.
s5p-common will be used by all of s5p SoCs.

Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>

Showing 7 changed files with 302 additions and 251 deletions Side-by-side Diff

... ... @@ -253,6 +253,13 @@
253 253 LIBS += $(CPUDIR)/omap-common/libomap-common.a
254 254 endif
255 255  
  256 +ifeq ($(SOC),s5pc1xx)
  257 +LIBS += $(CPUDIR)/s5p-common/libs5p-common.a
  258 +endif
  259 +ifeq ($(SOC),s5pc2xx)
  260 +LIBS += $(CPUDIR)/s5p-common/libs5p-common.a
  261 +endif
  262 +
256 263 LIBS := $(addprefix $(obj),$(LIBS))
257 264 .PHONY : $(LIBS) $(TIMESTAMP_FILE) $(VERSION_FILE)
258 265  
arch/arm/cpu/armv7/s5p-common/Makefile
  1 +#
  2 +# Copyright (C) 2009 Samsung Electronics
  3 +# Minkyu Kang <mk7.kang@samsung.com>
  4 +#
  5 +# See file CREDITS for list of people who contributed to this
  6 +# project.
  7 +#
  8 +# This program is free software; you can redistribute it and/or
  9 +# modify it under the terms of the GNU General Public License as
  10 +# published by the Free Software Foundation; either version 2 of
  11 +# the License, or (at your option) any later version.
  12 +#
  13 +# This program is distributed in the hope that it will be useful,
  14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 +# GNU General Public License for more details.
  17 +#
  18 +# You should have received a copy of the GNU General Public License
  19 +# along with this program; if not, write to the Free Software
  20 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 +# MA 02111-1307 USA
  22 +#
  23 +
  24 +include $(TOPDIR)/config.mk
  25 +
  26 +LIB = $(obj)libs5p-common.a
  27 +
  28 +COBJS-y += cpu_info.o
  29 +COBJS-y += timer.o
  30 +
  31 +SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
  32 +OBJS := $(addprefix $(obj),$(COBJS-y) $(SOBJS))
  33 +
  34 +all: $(obj).depend $(LIB)
  35 +
  36 +$(LIB): $(OBJS)
  37 + $(AR) $(ARFLAGS) $@ $(OBJS)
  38 +
  39 +#########################################################################
  40 +
  41 +# defines $(obj).depend target
  42 +include $(SRCTREE)/rules.mk
  43 +
  44 +sinclude $(obj).depend
  45 +
  46 +#########################################################################
arch/arm/cpu/armv7/s5p-common/cpu_info.c
  1 +/*
  2 + * Copyright (C) 2009 Samsung Electronics
  3 + * Minkyu Kang <mk7.kang@samsung.com>
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + */
  23 +#include <common.h>
  24 +#include <asm/io.h>
  25 +#include <asm/arch/clk.h>
  26 +
  27 +/* Default is s5pc100 */
  28 +unsigned int s5pc1xx_cpu_id = 0xC100;
  29 +
  30 +#ifdef CONFIG_ARCH_CPU_INIT
  31 +int arch_cpu_init(void)
  32 +{
  33 + s5pc1xx_cpu_id = readl(samsung_get_base_pro_id());
  34 + s5pc1xx_cpu_id = 0xC000 | ((s5pc1xx_cpu_id & 0x00FFF000) >> 12);
  35 +
  36 + s5pc1xx_clock_init();
  37 +
  38 + return 0;
  39 +}
  40 +#endif
  41 +
  42 +u32 get_device_type(void)
  43 +{
  44 + return s5pc1xx_cpu_id;
  45 +}
  46 +
  47 +#ifdef CONFIG_DISPLAY_CPUINFO
  48 +int print_cpuinfo(void)
  49 +{
  50 + char buf[32];
  51 +
  52 + printf("CPU:\tS5P%X@%sMHz\n",
  53 + s5pc1xx_cpu_id, strmhz(buf, get_arm_clk()));
  54 +
  55 + return 0;
  56 +}
  57 +#endif
arch/arm/cpu/armv7/s5p-common/timer.c
  1 +/*
  2 + * Copyright (C) 2009 Samsung Electronics
  3 + * Heungjun Kim <riverful.kim@samsung.com>
  4 + * Inki Dae <inki.dae@samsung.com>
  5 + * Minkyu Kang <mk7.kang@samsung.com>
  6 + *
  7 + * See file CREDITS for list of people who contributed to this
  8 + * project.
  9 + *
  10 + * This program is free software; you can redistribute it and/or
  11 + * modify it under the terms of the GNU General Public License as
  12 + * published by the Free Software Foundation; either version 2 of
  13 + * the License, or (at your option) any later version.
  14 + *
  15 + * This program is distributed in the hope that it will be useful,
  16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 + * GNU General Public License for more details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program; if not, write to the Free Software
  22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23 + * MA 02111-1307 USA
  24 + */
  25 +
  26 +#include <common.h>
  27 +#include <asm/io.h>
  28 +#include <asm/arch/pwm.h>
  29 +#include <asm/arch/clk.h>
  30 +
  31 +#define PRESCALER_1 (16 - 1) /* prescaler of timer 2, 3, 4 */
  32 +#define MUX_DIV_2 1 /* 1/2 period */
  33 +#define MUX_DIV_4 2 /* 1/4 period */
  34 +#define MUX_DIV_8 3 /* 1/8 period */
  35 +#define MUX_DIV_16 4 /* 1/16 period */
  36 +#define MUX4_DIV_SHIFT 16
  37 +
  38 +#define TCON_TIMER4_SHIFT 20
  39 +
  40 +static unsigned long count_value;
  41 +
  42 +/* Internal tick units */
  43 +static unsigned long long timestamp; /* Monotonic incrementing timer */
  44 +static unsigned long lastdec; /* Last decremneter snapshot */
  45 +
  46 +/* macro to read the 16 bit timer */
  47 +static inline struct s5pc1xx_timer *s5pc1xx_get_base_timer(void)
  48 +{
  49 + return (struct s5pc1xx_timer *)samsung_get_base_timer();
  50 +}
  51 +
  52 +int timer_init(void)
  53 +{
  54 + struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
  55 + u32 val;
  56 +
  57 + /*
  58 + * @ PWM Timer 4
  59 + * Timer Freq(HZ) =
  60 + * PCLK / { (prescaler_value + 1) * (divider_value) }
  61 + */
  62 +
  63 + /* set prescaler : 16 */
  64 + /* set divider : 2 */
  65 + writel((PRESCALER_1 & 0xff) << 8, &timer->tcfg0);
  66 + writel((MUX_DIV_2 & 0xf) << MUX4_DIV_SHIFT, &timer->tcfg1);
  67 +
  68 + if (count_value == 0) {
  69 + /* reset initial value */
  70 + /* count_value = 2085937.5(HZ) (per 1 sec)*/
  71 + count_value = get_pclk() / ((PRESCALER_1 + 1) *
  72 + (MUX_DIV_2 + 1));
  73 +
  74 + /* count_value / 100 = 20859.375(HZ) (per 10 msec) */
  75 + count_value = count_value / 100;
  76 + }
  77 +
  78 + /* set count value */
  79 + writel(count_value, &timer->tcntb4);
  80 + lastdec = count_value;
  81 +
  82 + val = (readl(&timer->tcon) & ~(0x07 << TCON_TIMER4_SHIFT)) |
  83 + S5PC1XX_TCON4_AUTO_RELOAD;
  84 +
  85 + /* auto reload & manual update */
  86 + writel(val | S5PC1XX_TCON4_UPDATE, &timer->tcon);
  87 +
  88 + /* start PWM timer 4 */
  89 + writel(val | S5PC1XX_TCON4_START, &timer->tcon);
  90 +
  91 + timestamp = 0;
  92 +
  93 + return 0;
  94 +}
  95 +
  96 +/*
  97 + * timer without interrupts
  98 + */
  99 +void reset_timer(void)
  100 +{
  101 + reset_timer_masked();
  102 +}
  103 +
  104 +unsigned long get_timer(unsigned long base)
  105 +{
  106 + return get_timer_masked() - base;
  107 +}
  108 +
  109 +void set_timer(unsigned long t)
  110 +{
  111 + timestamp = t;
  112 +}
  113 +
  114 +/* delay x useconds */
  115 +void __udelay(unsigned long usec)
  116 +{
  117 + unsigned long tmo, tmp;
  118 +
  119 + if (usec >= 1000) {
  120 + /*
  121 + * if "big" number, spread normalization
  122 + * to seconds
  123 + * 1. start to normalize for usec to ticks per sec
  124 + * 2. find number of "ticks" to wait to achieve target
  125 + * 3. finish normalize.
  126 + */
  127 + tmo = usec / 1000;
  128 + tmo *= (CONFIG_SYS_HZ * count_value / 10);
  129 + tmo /= 1000;
  130 + } else {
  131 + /* else small number, don't kill it prior to HZ multiply */
  132 + tmo = usec * CONFIG_SYS_HZ * count_value / 10;
  133 + tmo /= (1000 * 1000);
  134 + }
  135 +
  136 + /* get current timestamp */
  137 + tmp = get_timer(0);
  138 +
  139 + /* if setting this fordward will roll time stamp */
  140 + /* reset "advancing" timestamp to 0, set lastdec value */
  141 + /* else, set advancing stamp wake up time */
  142 + if ((tmo + tmp + 1) < tmp)
  143 + reset_timer_masked();
  144 + else
  145 + tmo += tmp;
  146 +
  147 + /* loop till event */
  148 + while (get_timer_masked() < tmo)
  149 + ; /* nop */
  150 +}
  151 +
  152 +void reset_timer_masked(void)
  153 +{
  154 + struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
  155 +
  156 + /* reset time */
  157 + lastdec = readl(&timer->tcnto4);
  158 + timestamp = 0;
  159 +}
  160 +
  161 +unsigned long get_timer_masked(void)
  162 +{
  163 + struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
  164 + unsigned long now = readl(&timer->tcnto4);
  165 +
  166 + if (lastdec >= now)
  167 + timestamp += lastdec - now;
  168 + else
  169 + timestamp += lastdec + count_value - now;
  170 +
  171 + lastdec = now;
  172 +
  173 + return timestamp;
  174 +}
  175 +
  176 +/*
  177 + * This function is derived from PowerPC code (read timebase as long long).
  178 + * On ARM it just returns the timer value.
  179 + */
  180 +unsigned long long get_ticks(void)
  181 +{
  182 + return get_timer(0);
  183 +}
  184 +
  185 +/*
  186 + * This function is derived from PowerPC code (timebase clock frequency).
  187 + * On ARM it returns the number of timer ticks per second.
  188 + */
  189 +unsigned long get_tbclk(void)
  190 +{
  191 + return CONFIG_SYS_HZ;
  192 +}
arch/arm/cpu/armv7/s5pc1xx/Makefile
... ... @@ -32,9 +32,7 @@
32 32 SOBJS += reset.o
33 33  
34 34 COBJS += clock.o
35   -COBJS += cpu_info.o
36 35 COBJS += sromc.o
37   -COBJS += timer.o
38 36  
39 37 SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)
40 38 OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS))
arch/arm/cpu/armv7/s5pc1xx/cpu_info.c
1   -/*
2   - * Copyright (C) 2009 Samsung Electronics
3   - * Minkyu Kang <mk7.kang@samsung.com>
4   - *
5   - * See file CREDITS for list of people who contributed to this
6   - * project.
7   - *
8   - * This program is free software; you can redistribute it and/or
9   - * modify it under the terms of the GNU General Public License as
10   - * published by the Free Software Foundation; either version 2 of
11   - * the License, or (at your option) any later version.
12   - *
13   - * This program is distributed in the hope that it will be useful,
14   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   - * GNU General Public License for more details.
17   - *
18   - * You should have received a copy of the GNU General Public License
19   - * along with this program; if not, write to the Free Software
20   - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21   - * MA 02111-1307 USA
22   - */
23   -#include <common.h>
24   -#include <asm/io.h>
25   -#include <asm/arch/clk.h>
26   -
27   -/* Default is s5pc100 */
28   -unsigned int s5pc1xx_cpu_id = 0xC100;
29   -
30   -#ifdef CONFIG_ARCH_CPU_INIT
31   -int arch_cpu_init(void)
32   -{
33   - s5pc1xx_cpu_id = readl(samsung_get_base_pro_id());
34   - s5pc1xx_cpu_id = 0xC000 | ((s5pc1xx_cpu_id & 0x00FFF000) >> 12);
35   -
36   - s5pc1xx_clock_init();
37   -
38   - return 0;
39   -}
40   -#endif
41   -
42   -u32 get_device_type(void)
43   -{
44   - return s5pc1xx_cpu_id;
45   -}
46   -
47   -#ifdef CONFIG_DISPLAY_CPUINFO
48   -int print_cpuinfo(void)
49   -{
50   - char buf[32];
51   -
52   - printf("CPU:\tS5P%X@%sMHz\n",
53   - s5pc1xx_cpu_id, strmhz(buf, get_arm_clk()));
54   -
55   - return 0;
56   -}
57   -#endif
arch/arm/cpu/armv7/s5pc1xx/timer.c
1   -/*
2   - * Copyright (C) 2009 Samsung Electronics
3   - * Heungjun Kim <riverful.kim@samsung.com>
4   - * Inki Dae <inki.dae@samsung.com>
5   - * Minkyu Kang <mk7.kang@samsung.com>
6   - *
7   - * See file CREDITS for list of people who contributed to this
8   - * project.
9   - *
10   - * This program is free software; you can redistribute it and/or
11   - * modify it under the terms of the GNU General Public License as
12   - * published by the Free Software Foundation; either version 2 of
13   - * the License, or (at your option) any later version.
14   - *
15   - * This program is distributed in the hope that it will be useful,
16   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18   - * GNU General Public License for more details.
19   - *
20   - * You should have received a copy of the GNU General Public License
21   - * along with this program; if not, write to the Free Software
22   - * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23   - * MA 02111-1307 USA
24   - */
25   -
26   -#include <common.h>
27   -#include <asm/io.h>
28   -#include <asm/arch/pwm.h>
29   -#include <asm/arch/clk.h>
30   -
31   -#define PRESCALER_1 (16 - 1) /* prescaler of timer 2, 3, 4 */
32   -#define MUX_DIV_2 1 /* 1/2 period */
33   -#define MUX_DIV_4 2 /* 1/4 period */
34   -#define MUX_DIV_8 3 /* 1/8 period */
35   -#define MUX_DIV_16 4 /* 1/16 period */
36   -#define MUX4_DIV_SHIFT 16
37   -
38   -#define TCON_TIMER4_SHIFT 20
39   -
40   -static unsigned long count_value;
41   -
42   -/* Internal tick units */
43   -static unsigned long long timestamp; /* Monotonic incrementing timer */
44   -static unsigned long lastdec; /* Last decremneter snapshot */
45   -
46   -/* macro to read the 16 bit timer */
47   -static inline struct s5pc1xx_timer *s5pc1xx_get_base_timer(void)
48   -{
49   - return (struct s5pc1xx_timer *)samsung_get_base_timer();
50   -}
51   -
52   -int timer_init(void)
53   -{
54   - struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
55   - u32 val;
56   -
57   - /*
58   - * @ PWM Timer 4
59   - * Timer Freq(HZ) =
60   - * PCLK / { (prescaler_value + 1) * (divider_value) }
61   - */
62   -
63   - /* set prescaler : 16 */
64   - /* set divider : 2 */
65   - writel((PRESCALER_1 & 0xff) << 8, &timer->tcfg0);
66   - writel((MUX_DIV_2 & 0xf) << MUX4_DIV_SHIFT, &timer->tcfg1);
67   -
68   - if (count_value == 0) {
69   - /* reset initial value */
70   - /* count_value = 2085937.5(HZ) (per 1 sec)*/
71   - count_value = get_pclk() / ((PRESCALER_1 + 1) *
72   - (MUX_DIV_2 + 1));
73   -
74   - /* count_value / 100 = 20859.375(HZ) (per 10 msec) */
75   - count_value = count_value / 100;
76   - }
77   -
78   - /* set count value */
79   - writel(count_value, &timer->tcntb4);
80   - lastdec = count_value;
81   -
82   - val = (readl(&timer->tcon) & ~(0x07 << TCON_TIMER4_SHIFT)) |
83   - S5PC1XX_TCON4_AUTO_RELOAD;
84   -
85   - /* auto reload & manual update */
86   - writel(val | S5PC1XX_TCON4_UPDATE, &timer->tcon);
87   -
88   - /* start PWM timer 4 */
89   - writel(val | S5PC1XX_TCON4_START, &timer->tcon);
90   -
91   - timestamp = 0;
92   -
93   - return 0;
94   -}
95   -
96   -/*
97   - * timer without interrupts
98   - */
99   -void reset_timer(void)
100   -{
101   - reset_timer_masked();
102   -}
103   -
104   -unsigned long get_timer(unsigned long base)
105   -{
106   - return get_timer_masked() - base;
107   -}
108   -
109   -void set_timer(unsigned long t)
110   -{
111   - timestamp = t;
112   -}
113   -
114   -/* delay x useconds */
115   -void __udelay(unsigned long usec)
116   -{
117   - unsigned long tmo, tmp;
118   -
119   - if (usec >= 1000) {
120   - /*
121   - * if "big" number, spread normalization
122   - * to seconds
123   - * 1. start to normalize for usec to ticks per sec
124   - * 2. find number of "ticks" to wait to achieve target
125   - * 3. finish normalize.
126   - */
127   - tmo = usec / 1000;
128   - tmo *= (CONFIG_SYS_HZ * count_value / 10);
129   - tmo /= 1000;
130   - } else {
131   - /* else small number, don't kill it prior to HZ multiply */
132   - tmo = usec * CONFIG_SYS_HZ * count_value / 10;
133   - tmo /= (1000 * 1000);
134   - }
135   -
136   - /* get current timestamp */
137   - tmp = get_timer(0);
138   -
139   - /* if setting this fordward will roll time stamp */
140   - /* reset "advancing" timestamp to 0, set lastdec value */
141   - /* else, set advancing stamp wake up time */
142   - if ((tmo + tmp + 1) < tmp)
143   - reset_timer_masked();
144   - else
145   - tmo += tmp;
146   -
147   - /* loop till event */
148   - while (get_timer_masked() < tmo)
149   - ; /* nop */
150   -}
151   -
152   -void reset_timer_masked(void)
153   -{
154   - struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
155   -
156   - /* reset time */
157   - lastdec = readl(&timer->tcnto4);
158   - timestamp = 0;
159   -}
160   -
161   -unsigned long get_timer_masked(void)
162   -{
163   - struct s5pc1xx_timer *const timer = s5pc1xx_get_base_timer();
164   - unsigned long now = readl(&timer->tcnto4);
165   -
166   - if (lastdec >= now)
167   - timestamp += lastdec - now;
168   - else
169   - timestamp += lastdec + count_value - now;
170   -
171   - lastdec = now;
172   -
173   - return timestamp;
174   -}
175   -
176   -/*
177   - * This function is derived from PowerPC code (read timebase as long long).
178   - * On ARM it just returns the timer value.
179   - */
180   -unsigned long long get_ticks(void)
181   -{
182   - return get_timer(0);
183   -}
184   -
185   -/*
186   - * This function is derived from PowerPC code (timebase clock frequency).
187   - * On ARM it returns the number of timer ticks per second.
188   - */
189   -unsigned long get_tbclk(void)
190   -{
191   - return CONFIG_SYS_HZ;
192   -}