Annotation of prex-old/dev/power/cpufreq.c, Revision 1.1
1.1 ! nbrk 1: /*-
! 2: * Copyright (c) 2007, Kohsuke Ohtani
! 3: * All rights reserved.
! 4: *
! 5: * Redistribution and use in source and binary forms, with or without
! 6: * modification, are permitted provided that the following conditions
! 7: * are met:
! 8: * 1. Redistributions of source code must retain the above copyright
! 9: * notice, this list of conditions and the following disclaimer.
! 10: * 2. Redistributions in binary form must reproduce the above copyright
! 11: * notice, this list of conditions and the following disclaimer in the
! 12: * documentation and/or other materials provided with the distribution.
! 13: * 3. Neither the name of the author nor the names of any co-contributors
! 14: * may be used to endorse or promote products derived from this software
! 15: * without specific prior written permission.
! 16: *
! 17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 27: * SUCH DAMAGE.
! 28: */
! 29:
! 30: /*
! 31: * cpufreq.c - CPU frequency control
! 32: */
! 33:
! 34: #include <sys/ioctl.h>
! 35: #include <driver.h>
! 36: #include <pm.h>
! 37: #include "dvs.h"
! 38:
! 39: /* #define DEBUG_CPUFREQ 1 */
! 40:
! 41: #ifdef DEBUG_CPUFREQ
! 42: #define cf_printf(fmt, args...) printk("cpufreq: " fmt, ## args)
! 43: #else
! 44: #define cf_printf(fmt...) do {} while (0)
! 45: #endif
! 46:
! 47: static int cpufreq_open(device_t dev, int mode);
! 48: static int cpufreq_ioctl(device_t dev, int cmd, u_long arg);
! 49: static int cpufreq_close(device_t dev);
! 50: static int cpufreq_init(void);
! 51:
! 52: /*
! 53: * Driver structure
! 54: */
! 55: struct driver cpufreq_drv = {
! 56: /* name */ "CPU Frequency Control",
! 57: /* order */ 3, /* Must larger than pm driver */
! 58: /* init */ cpufreq_init,
! 59: };
! 60:
! 61: static struct devio cpufreq_io = {
! 62: /* open */ cpufreq_open,
! 63: /* close */ cpufreq_close,
! 64: /* read */ NULL,
! 65: /* write */ NULL,
! 66: /* ioctl */ cpufreq_ioctl,
! 67: /* event */ NULL,
! 68: };
! 69:
! 70: static device_t cpufreq_dev; /* Device object */
! 71:
! 72: /*
! 73: * Frequecy control policy
! 74: */
! 75: static int cpufreq_policy;
! 76:
! 77: static int
! 78: cpufreq_open(device_t dev, int mode)
! 79: {
! 80:
! 81: return 0;
! 82: }
! 83:
! 84: static int
! 85: cpufreq_close(device_t dev)
! 86: {
! 87:
! 88: return 0;
! 89: }
! 90:
! 91: static int
! 92: cpufreq_ioctl(device_t dev, int cmd, u_long arg)
! 93: {
! 94:
! 95: return 0;
! 96: }
! 97:
! 98: void
! 99: cpufreq_setpolicy(int policy)
! 100: {
! 101:
! 102: switch (cpufreq_policy) {
! 103: case CPUFREQ_ONDEMAND:
! 104: if (policy == PM_POWERSAVE)
! 105: dvs_enable();
! 106: else
! 107: dvs_disable();
! 108:
! 109: break;
! 110: case CPUFREQ_MAXSPEED:
! 111: break;
! 112: case CPUFREQ_MINSPEED:
! 113: break;
! 114: }
! 115: }
! 116:
! 117: static int
! 118: cpufreq_init(void)
! 119: {
! 120: int policy;
! 121:
! 122: /* Create device object */
! 123: cpufreq_dev = device_create(&cpufreq_io, "cpufreq", DF_CHR);
! 124: ASSERT(cpufreq_dev);
! 125:
! 126: dvs_init();
! 127:
! 128: policy = pm_getpolicy();
! 129: if (policy == PM_POWERSAVE)
! 130: dvs_enable();
! 131: return 0;
! 132: }
! 133:
CVSweb