public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.net>
To: "Eugeny S. Mints" <eugeny.mints@gmail.com>
Cc: pm list <linux-pm@lists.osdl.org>
Subject: Re: Alternative Concept [Was: Re: [RFC] CPUFreq PowerOP integration, Intro 0/3]
Date: Fri, 6 Oct 2006 23:15:01 -0400	[thread overview]
Message-ID: <20061007031501.GA1404@dominikbrodowski.de> (raw)
In-Reply-To: <20061007023620.GD30380@dominikbrodowski.de>

Hi,

Some very basic incomplete sketch of how some of my ideas might look in
code:

 /*
 * OMAP PM Core implementation by Eugeny S. Mints <eugeny.mints@gmail.com>,
 * modified by Dominik Brodowski.
 *
 * Copyright (C) 2006, Nomad Global Solutions, Inc.
 * Copyright (C) 2006  Dominik Brodowski
 *
 * Based on code by Todd Poynor, Matthew Locke, Dmitry Chigirev, and
 * Bishop Brock.
 *
 * Copyright (C) 2002, 2004 MontaVista Software <source@mvista.com>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

/* Number of colums in operating points table */
#define OP_VALUES  4


/* GENERIC PART BEGINS HERE */

struct op_entry {
	unsigned int value[OP_VALUES];
	struct op_entry *next;
};

int pm_core_verify_value(unsigned int what, unsigned int value,
			 struct op_entry *table,
			 int set_other(unsigned int, unsigned int))
{
	int i, colum = -1;
	struct op_entry *table_entry = table->next;

	for (i=0; i<OP_VALUES; i++) {
		if (table->value[i] == what)
			colum = i;
	}
	if (colum == -1)
		return -EINVAL;

	while (table_entry) {
		/* very easy algorithm at first: use the first
		   operating point which matches what we are looking
		   for
		*/
		if (table_entry->value[colum] == value)
			goto found_it;

		table_entry = table_entry->next;
	};
	return -EINVAL;

 found_it:
	for (i=0; i<OP_VALUES; i++) {
		if (i==colum)
			continue;
		/* FIXME: error handling */
		set_other(table->value[i], table_entry->value[i]);
	}
	return 0;
}

/* GENERIC PART ENDS HERE */



/* dummy */
static int set_cpu_vltg(unsigned int value)
{
	return 0;
}

static int set_dpll(unsigned int value)
{
	return 0;
}

static int set_cpu_freq(unsigned int value)
{
	return 0;
}

enum {
	CPU_VLTG = 0,
	DPLL = 1,
	CPU_FREQ = 2,
	OPPOINT_NR = 3,
};

static int set_pm(unsigned int what, unsigned int value)
{
	int ret = -ENODEV;

	/* FIXME
	pm_core_notify_prechange(what, value);
	*/

	switch (what) {
	case CPU_VLTG:
		/* FIXME: only set it if it is really different
		 * from current level */
		ret = set_cpu_vltg(value);
		break;
	case DPLL:
		ret = set_dpll(value);
		break;
	case CPU_FREQ:
		ret = set_cpu_freq(value);
		break;
	case OPPOINT_NR:
		/* ignore */
		break;
	}

	/* FIXME
	if (!ret)
		pm_core_notify_postchange(what, value);
	else
		pm_core_notify_failed_change(what, value);
	*/

	return ret;
}

/* THE TABLE CONTAING PRE-DEFINED OPERATING POINTS */


/* FIXME: think of a better way to set up a static table */
struct op_entry omap_op_static_entry4 = {
	.value = {2, 3, 2, 4},
};

struct op_entry omap_op_static_entry3 = {
	.value = {1, 2, 2, 3},
	.next = &omap_op_static_entry4,
};

struct op_entry omap_op_static_entry2 = {
	.value = {2, 1, 1, 2},
	.next = &omap_op_static_entry3,
};

struct op_entry omap_op_static_entry1 = {
	.value = {1, 1, 1, 1},
	.next = &omap_op_static_entry2,
};

struct op_entry omap_op_table = {
	.value = {CPU_VLTG, DPLL, CPU_FREQ, OPPOINT_NR},
	.next = &omap_op_static_entry1,
};


/* function being called by external interface. You can add
   whatever userspace API on top of it you like -- configfs,
   sysfs, module parameter, syscall, ... */

int omap_set(unsigned int what, unsigned int value)
{
	int ret;

	ret = pm_core_verify_value(what, value, &omap_op_table, set_pm);
	if (ret)
		return ret;

	return set_pm(what, value);
}


/*
To set a specific operating point, let's say, oppoint 3, the
yet-to-be-defined interface needs to call:

omap_set(OPPOINT_NR, 3);


Setting up a cpufreq interaction is quite easy, as it basically only
needs to call

omap_set(CPU_FREQ, validated_target_freq);

You only need to make sure that you're not using in-kernel CPU
frequency scaling parallel to setting oppoints. But such a validation
should be trivial to add.
*/



IT COMPILES!!! SHIP IT! ;)

Thanks,
	Dominik

  reply	other threads:[~2006-10-07  3:15 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-24  1:23 [RFC] CPUFreq PowerOP integration, Intro 0/3 Eugeny S. Mints
2006-10-07  2:36 ` Alternative Concept [Was: Re: [RFC] CPUFreq PowerOP integration, Intro 0/3] Dominik Brodowski
2006-10-07  3:15   ` Dominik Brodowski [this message]
2006-10-08  7:16   ` Pavel Machek
2006-10-12 15:38     ` Mark Gross
2006-10-12 16:02       ` Dominik Brodowski
2006-10-16 21:56         ` Mark Gross
2006-10-17 21:40           ` Matthew Locke
2006-10-12 16:48       ` Pavel Machek
2006-10-12 17:12         ` Vitaly Wool
2006-10-12 17:23           ` Pavel Machek
2006-10-09 18:21   ` Mark Gross
2006-10-26  3:06     ` Dominik Brodowski
2006-10-12 22:43   ` Eugeny S. Mints
2006-10-13 10:55     ` Pavel Machek
2006-10-16 21:44       ` Mark Gross
2006-10-17  8:26         ` Pavel Machek
2006-10-26  3:05     ` Dominik Brodowski
2007-03-13  0:57   ` Alternative Concept Matthew Locke
2007-03-13 11:08     ` Pavel Machek
2007-03-13 20:34       ` Mark Gross
2007-03-14  2:30         ` Ikhwan Lee
2007-03-14 10:43           ` Eugeny S. Mints
2007-03-14 17:19             ` David Brownell
2007-03-14 18:12               ` Igor Stoppa
2007-03-14 18:45                 ` David Brownell
2007-03-15  9:53               ` Eugeny S. Mints
2007-03-15 13:04                 ` Igor Stoppa
2007-03-16  2:21                   ` David Brownell
2007-03-16  3:56                     ` Ikhwan Lee
2007-03-16  6:17                       ` David Brownell
2007-03-19  2:27                         ` Ikhwan Lee
2007-03-19  6:07                           ` David Brownell
2007-03-16 13:06                     ` Dmitry Krivoschekov
2007-03-16 18:03                       ` David Brownell
2007-03-18 20:25                         ` Dmitry Krivoschekov
2007-03-19  4:04                           ` David Brownell
2007-03-20  0:03                             ` Dmitry Krivoschekov
2007-03-20  8:07                               ` David Brownell
2007-03-20  9:45                                 ` Dmitry Krivoschekov
2007-03-20 10:30                                   ` Igor Stoppa
2007-03-20 12:13                                     ` Eugeny S. Mints
2007-03-20 12:39                                       ` Igor Stoppa
2007-03-20 13:44                                         ` Dmitry Krivoschekov
2007-03-20 21:03                                         ` David Brownell
2007-03-20 13:07                                     ` Dmitry Krivoschekov
2007-03-20 13:52                                       ` Igor Stoppa
2007-03-20 14:58                                         ` Dmitry Krivoschekov
2007-03-20 15:36                                           ` Pavel Machek
2007-03-20 19:16                                             ` Dmitry Krivoschekov
2007-03-20 20:45                                               ` Pavel Machek
2007-03-20 22:04                                                 ` David Brownell
2007-03-20 22:06                                                   ` Pavel Machek
2007-03-20 23:29                                                     ` David Brownell
2007-03-20 15:36                                           ` Igor Stoppa
2007-03-20 19:17                                             ` Dmitry Krivoschekov
2007-03-20 20:17                                             ` David Brownell
2007-03-20 20:21                                       ` David Brownell
2007-03-20 19:58                                   ` David Brownell
2007-03-24  0:47                                     ` charging batteries from USB [was: Re: Alternative Concept] Dmitry Krivoschekov
2007-03-24  1:17                                       ` David Brownell
2007-03-24  1:48                                         ` Dmitry Krivoschekov
2007-03-24  2:35                                           ` David Brownell
2007-03-24 10:20                                             ` Oliver Neukum
2007-03-24  8:36                                       ` Oliver Neukum
2007-03-14  3:19       ` Alternative Concept Dominik Brodowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061007031501.GA1404@dominikbrodowski.de \
    --to=linux@dominikbrodowski.net \
    --cc=eugeny.mints@gmail.com \
    --cc=linux-pm@lists.osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox