1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-w90x900/clksel.c
5 * Copyright (c) 2008 Nuvoton technology corporation
7 * Wan ZongShun <mcuos.com@gmail.com>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/device.h>
13 #include <linux/list.h>
14 #include <linux/errno.h>
15 #include <linux/err.h>
16 #include <linux/string.h>
17 #include <linux/clk.h>
18 #include <linux/mutex.h>
21 #include <mach/hardware.h>
22 #include <mach/regs-clock.h>
29 #define ATAOFFSET 0x0a
30 #define LCDOFFSET 0x06
31 #define AUDOFFSET 0x04
32 #define CPUOFFSET 0x00
34 static DEFINE_MUTEX(clksel_sem
);
36 static void clock_source_select(const char *dev_id
, unsigned int clkval
)
38 unsigned int clksel
, offset
;
40 clksel
= __raw_readl(REG_CLKSEL
);
42 if (strcmp(dev_id
, "nuc900-ms") == 0)
44 else if (strcmp(dev_id
, "nuc900-atapi") == 0)
46 else if (strcmp(dev_id
, "nuc900-lcd") == 0)
48 else if (strcmp(dev_id
, "nuc900-ac97") == 0)
53 clksel
&= ~(0x03 << offset
);
54 clksel
|= (clkval
<< offset
);
56 __raw_writel(clksel
, REG_CLKSEL
);
59 void nuc900_clock_source(struct device
*dev
, unsigned char *src
)
67 mutex_lock(&clksel_sem
);
70 dev_id
= dev_name(dev
);
74 if (strcmp(src
, "pll0") == 0)
76 else if (strcmp(src
, "pll1") == 0)
78 else if (strcmp(src
, "ext") == 0)
80 else if (strcmp(src
, "oth") == 0)
83 clock_source_select(dev_id
, clkval
);
85 mutex_unlock(&clksel_sem
);
87 EXPORT_SYMBOL(nuc900_clock_source
);