Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
common.c
Go to the documentation of this file.
1 /*
2  * arch/arm/mach-mv78xx0/common.c
3  *
4  * Core functions for Marvell MV78xx0 SoCs
5  *
6  * This file is licensed under the terms of the GNU General Public
7  * License version 2. This program is licensed "as is" without any
8  * warranty of any kind, whether express or implied.
9  */
10 
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/serial_8250.h>
15 #include <linux/ata_platform.h>
16 #include <linux/clk-provider.h>
17 #include <linux/ethtool.h>
18 #include <asm/mach/map.h>
19 #include <asm/mach/time.h>
20 #include <mach/mv78xx0.h>
21 #include <mach/bridge-regs.h>
22 #include <plat/cache-feroceon-l2.h>
25 #include <plat/time.h>
26 #include <plat/common.h>
27 #include <plat/addr-map.h>
28 #include "common.h"
29 
30 static int get_tclk(void);
31 
32 /*****************************************************************************
33  * Common bits
34  ****************************************************************************/
36 {
37  u32 extra;
38 
39  /*
40  * Read Extra Features register.
41  */
42  __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
43 
44  return !!(extra & 0x00004000);
45 }
46 
47 static int get_hclk(void)
48 {
49  int hclk;
50 
51  /*
52  * HCLK tick rate is configured by DEV_D[7:5] pins.
53  */
54  switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
55  case 0:
56  hclk = 166666667;
57  break;
58  case 1:
59  hclk = 200000000;
60  break;
61  case 2:
62  hclk = 266666667;
63  break;
64  case 3:
65  hclk = 333333333;
66  break;
67  case 4:
68  hclk = 400000000;
69  break;
70  default:
71  panic("unknown HCLK PLL setting: %.8x\n",
73  }
74 
75  return hclk;
76 }
77 
78 static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
79 {
80  u32 cfg;
81 
82  /*
83  * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
84  * PCLK/L2CLK by bits [19:14].
85  */
86  if (core_index == 0) {
87  cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
88  } else {
89  cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
90  }
91 
92  /*
93  * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
94  * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
95  */
96  *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
97 
98  /*
99  * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
100  * ratio (1, 2, 3).
101  */
102  *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
103 }
104 
105 static int get_tclk(void)
106 {
107  int tclk_freq;
108 
109  /*
110  * TCLK tick rate is configured by DEV_A[2:0] strap pins.
111  */
112  switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
113  case 1:
114  tclk_freq = 166666667;
115  break;
116  case 3:
117  tclk_freq = 200000000;
118  break;
119  default:
120  panic("unknown TCLK PLL setting: %.8x\n",
122  }
123 
124  return tclk_freq;
125 }
126 
127 
128 /*****************************************************************************
129  * I/O Address Mapping
130  ****************************************************************************/
131 static struct map_desc mv78xx0_io_desc[] __initdata = {
132  {
133  .virtual = (unsigned long) MV78XX0_CORE_REGS_VIRT_BASE,
134  .pfn = 0,
136  .type = MT_DEVICE,
137  }, {
138  .virtual = (unsigned long) MV78XX0_REGS_VIRT_BASE,
140  .length = MV78XX0_REGS_SIZE,
141  .type = MT_DEVICE,
142  },
143 };
144 
146 {
147  unsigned long phys;
148 
149  /*
150  * Map the right set of per-core registers depending on
151  * which core we are running on.
152  */
153  if (mv78xx0_core_index() == 0) {
155  } else {
157  }
158  mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
159 
160  iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
161 }
162 
163 
164 /*****************************************************************************
165  * CLK tree
166  ****************************************************************************/
167 static struct clk *tclk;
168 
169 static void __init clk_init(void)
170 {
171  tclk = clk_register_fixed_rate(NULL, "tclk", NULL, CLK_IS_ROOT,
172  get_tclk());
173 
174  orion_clkdev_init(tclk);
175 }
176 
177 /*****************************************************************************
178  * EHCI
179  ****************************************************************************/
181 {
183 }
184 
185 
186 /*****************************************************************************
187  * EHCI1
188  ****************************************************************************/
190 {
192 }
193 
194 
195 /*****************************************************************************
196  * EHCI2
197  ****************************************************************************/
199 {
201 }
202 
203 
204 /*****************************************************************************
205  * GE00
206  ****************************************************************************/
208 {
209  orion_ge00_init(eth_data,
213 }
214 
215 
216 /*****************************************************************************
217  * GE01
218  ****************************************************************************/
220 {
221  orion_ge01_init(eth_data,
223  NO_IRQ,
225 }
226 
227 
228 /*****************************************************************************
229  * GE10
230  ****************************************************************************/
232 {
233  u32 dev, rev;
234 
235  /*
236  * On the Z0, ge10 and ge11 are internally connected back
237  * to back, and not brought out.
238  */
239  mv78xx0_pcie_id(&dev, &rev);
240  if (dev == MV78X00_Z0_DEV_ID) {
241  eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
242  eth_data->speed = SPEED_1000;
243  eth_data->duplex = DUPLEX_FULL;
244  }
245 
246  orion_ge10_init(eth_data,
248  NO_IRQ);
249 }
250 
251 
252 /*****************************************************************************
253  * GE11
254  ****************************************************************************/
256 {
257  u32 dev, rev;
258 
259  /*
260  * On the Z0, ge10 and ge11 are internally connected back
261  * to back, and not brought out.
262  */
263  mv78xx0_pcie_id(&dev, &rev);
264  if (dev == MV78X00_Z0_DEV_ID) {
265  eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
266  eth_data->speed = SPEED_1000;
267  eth_data->duplex = DUPLEX_FULL;
268  }
269 
270  orion_ge11_init(eth_data,
272  NO_IRQ);
273 }
274 
275 /*****************************************************************************
276  * I2C
277  ****************************************************************************/
279 {
282 }
283 
284 /*****************************************************************************
285  * SATA
286  ****************************************************************************/
288 {
290 }
291 
292 
293 /*****************************************************************************
294  * UART0
295  ****************************************************************************/
297 {
299  IRQ_MV78XX0_UART_0, tclk);
300 }
301 
302 
303 /*****************************************************************************
304  * UART1
305  ****************************************************************************/
307 {
309  IRQ_MV78XX0_UART_1, tclk);
310 }
311 
312 
313 /*****************************************************************************
314  * UART2
315  ****************************************************************************/
317 {
319  IRQ_MV78XX0_UART_2, tclk);
320 }
321 
322 /*****************************************************************************
323  * UART3
324  ****************************************************************************/
326 {
328  IRQ_MV78XX0_UART_3, tclk);
329 }
330 
331 /*****************************************************************************
332  * Time handling
333  ****************************************************************************/
335 {
337 }
338 
339 static void __init_refok mv78xx0_timer_init(void)
340 {
342  IRQ_MV78XX0_TIMER_1, get_tclk());
343 }
344 
346  .init = mv78xx0_timer_init,
347 };
348 
349 
350 /*****************************************************************************
351  * General
352  ****************************************************************************/
353 static char * __init mv78xx0_id(void)
354 {
355  u32 dev, rev;
356 
357  mv78xx0_pcie_id(&dev, &rev);
358 
359  if (dev == MV78X00_Z0_DEV_ID) {
360  if (rev == MV78X00_REV_Z0)
361  return "MV78X00-Z0";
362  else
363  return "MV78X00-Rev-Unsupported";
364  } else if (dev == MV78100_DEV_ID) {
365  if (rev == MV78100_REV_A0)
366  return "MV78100-A0";
367  else if (rev == MV78100_REV_A1)
368  return "MV78100-A1";
369  else
370  return "MV78100-Rev-Unsupported";
371  } else if (dev == MV78200_DEV_ID) {
372  if (rev == MV78100_REV_A0)
373  return "MV78200-A0";
374  else
375  return "MV78200-Rev-Unsupported";
376  } else {
377  return "Device-Unknown";
378  }
379 }
380 
381 static int __init is_l2_writethrough(void)
382 {
383  return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
384 }
385 
387 {
388  int core_index;
389  int hclk;
390  int pclk;
391  int l2clk;
392 
393  core_index = mv78xx0_core_index();
394  hclk = get_hclk();
395  get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
396 
397  printk(KERN_INFO "%s ", mv78xx0_id());
398  printk("core #%d, ", core_index);
399  printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
400  printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
401  printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
402  printk("TCLK = %dMHz\n", (get_tclk() + 499999) / 1000000);
403 
405 
406 #ifdef CONFIG_CACHE_FEROCEON_L2
407  feroceon_l2_init(is_l2_writethrough());
408 #endif
409 
410  /* Setup root of clk tree */
411  clk_init();
412 }
413 
414 void mv78xx0_restart(char mode, const char *cmd)
415 {
416  /*
417  * Enable soft reset to assert RSTOUTn.
418  */
420 
421  /*
422  * Assert soft reset.
423  */
425 
426  while (1)
427  ;
428 }