Annotation of prex-old/dev/arm/cats/sapmc.c, Revision 1.2
1.1 nbrk 1: /*
1.2 ! nbrk 2: * $Id: sapmc.c,v 1.1 2008/07/23 20:58:35 nbrk Exp $
1.1 nbrk 3: */
4: /*
5: * StrongARM 11x0 Power Management Controller.
6: */
7: #include <driver.h>
8: #include <sys/ioctl.h>
9:
10: #include "sapmc_reg.h"
11:
12: int sapmc_init(void);
13: int sapmc_ioctl(device_t, int, u_long);
14: void sapmc_setfreq(int mode);
15: uint32_t sapmc_getfreq(void);
16:
17: /*
18: * Driver structure
19: */
20: struct driver sapmc_drv = {
21: /* name */ "SA-11x0 PMC",
22: /* order */ 1,
23: /* init */sapmc_init,
24: };
25:
26: struct devio sapmc_io = {
27: /* open */ NULL,
28: /* close */ NULL,
29: /* read */ NULL,
30: /* write */ NULL,
31: /* ioctl */ sapmc_ioctl,
32: /* event */ NULL,
33: };
34:
35: device_t sapmc_dev;
36:
37:
38: /*
39: * XXX PLL controlled Core Clock Frequencies with 3686400 Hz oscillator.
40: */
41: #define SAPMC_NFREQMODES 12
42:
43: uint32_t sapmc_ccfmodes[SAPMC_NFREQMODES] = {
44: /* 0 */ 59000000,
45: /* 1 */ 73700000,
46: /* 2 */ 88500000,
47: /* 3 */ 103200000,
48: 118000000,
49: 132700000,
50: 147500000,
51: 162200000,
52: 176900000,
53: 191700000,
54: 206400000,
55: 221200000
56: };
57:
58: int
59: sapmc_init(void)
60: {
61: /* register device */
62: sapmc_dev = device_create(&sapmc_io, "sapmc", DF_CHR);
63:
64: return(0);
65: }
66:
67:
68: int
69: sapmc_ioctl(device_t dev, int cmd, u_long arg)
70: {
71: /*
1.2 ! nbrk 72: * ioctl() arg is a CCF mode (see datasheet).
1.1 nbrk 73: */
74: uint32_t freq;
75:
76: switch(cmd) {
77: case CPUIOC_SET_FREQ:
78: umem_copyin((uint32_t *)arg, &freq, sizeof(uint32_t));
79: if (freq > SAPMC_NFREQMODES)
80: return(EINVAL);
81:
82: sapmc_setfreq(freq);
83: break;
84:
85: case CPUIOC_GET_FREQ:
86: freq = sapmc_getfreq();
87: umem_copyout(&freq, (uint32_t *)arg, sizeof(uint32_t));
88: break;
89: }
90:
91: return(0);
92: }
93:
94:
95: void
96: sapmc_setfreq(int mode)
97: {
98: *(volatile uint32_t *)(SAPMC_BASE + SAPMC_PPCR) = (mode & CCF);
99: }
100:
101:
102: uint32_t
103: sapmc_getfreq(void)
104: {
105: int mode;
106:
107: mode = *(volatile uint32_t *)(SAPMC_BASE + SAPMC_PPCR);
108:
109: return(sapmc_ccfmodes[mode]);
110: }
CVSweb