コード例 #1
0
static int switch_memory_state(int mask, int new_state, int start_region,
				int end_region)
{
	int final_mask = 0;
	int i;

	mutex_lock(&mem_regions_mutex);

	for (i = start_region; i <= end_region; i++) {
		if (new_state == mem_regions[i].state)
			goto no_change;
		
		if (mem_regions[i].state != mem_regions[start_region].state)
			goto no_change;
	}

	if (new_state == STATE_POWER_DOWN)
		final_mask = mem_regions_mask & mask;
	else if (new_state == STATE_ACTIVE)
		final_mask = mem_regions_mask | ~mask;
	else
		goto no_change;

	pr_info("request memory %d to %d state switch (%d->%d)\n",
		start_region, end_region, mem_regions[start_region].state,
		new_state);
	if (rpm_change_memory_state(final_mask, final_mask) == 0) {
		for (i = start_region; i <= end_region; i++)
			mem_regions[i].state = new_state;
		mem_regions_mask = final_mask;

		pr_info("completed memory %d to %d state switch to %d\n",
			start_region, end_region, new_state);
		mutex_unlock(&mem_regions_mutex);
		return 0;
	}

	pr_err("failed memory %d to %d state switch (%d->%d)\n",
		start_region, end_region, mem_regions[start_region].state,
		new_state);

no_change:
	mutex_unlock(&mem_regions_mutex);
	return -EINVAL;
}
コード例 #2
0
static int switch_memory_state(int id, int new_state)
{
	int mask = 0;
	int power_down_masks[MAX_NR_REGIONS] = { 0xFFFFFF00, 0xFFFF00FF,
						0xFF00FFFF, 0x00FFFFFF };
	int self_refresh_masks[MAX_NR_REGIONS] = { 0xFFFFFFF0, 0xFFFFFF0F,
						0xFFFFF0FF, 0xFFFF0FFF };
	mutex_lock(&mem_regions[id].state_mutex);

	if (new_state == mem_regions[id].state)
		goto no_change;

	pr_info("request memory %d state switch (%d->%d) mode %d\n", id,
			mem_regions[id].state, new_state, dmm_mode);
	if (new_state == STATE_POWER_DOWN) {
		if (dmm_mode == MEM_DEEP_POWER_DOWN)
			mask = mem_regions[id].mask & power_down_masks[id];
		else
			mask = mem_regions[id].mask & self_refresh_masks[id];
	} else if (new_state == STATE_ACTIVE) {
		if (dmm_mode == MEM_DEEP_POWER_DOWN)
			mask = mem_regions[id].mask | (~power_down_masks[id]);
		else
			mask = mem_regions[id].mask | (~self_refresh_masks[id]);
	}

	if (rpm_change_memory_state(mask, mask) == 0) {
		mem_regions[id].state = new_state;
		mem_regions[id].mask = mask;
		pr_info("completed memory %d state switch to %d mode %d\n",
				id, new_state, dmm_mode);
		mutex_unlock(&mem_regions[id].state_mutex);
		return 0;
	}

	pr_err("failed memory %d state switch (%d->%d) mode %d\n", id,
			mem_regions[id].state, new_state, dmm_mode);
no_change:
	mutex_unlock(&mem_regions[id].state_mutex);
	return -EINVAL;
}