aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/hp6xx/pm.c
blob: 6a2112aeb7c041ab5bb7c2d0108e73f636838662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * hp6x0 Power Management Routines
 *
 * Copyright (c) 2006 Andriy Skulysh <askulsyh@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License.
 */
#include <linux/init.h>
#include <linux/suspend.h>
#include <linux/errno.h>
#include <linux/time.h>
#include <linux/apm-emulation.h>
#include <asm/io.h>
#include <asm/hd64461.h>
#include <asm/hp6xx.h>
#include <asm/cpu/dac.h>
#include <asm/pm.h>

#define STBCR		0xffffff82	/* STBCR  (Standby control register) SH7709A  */
#define STBCR2		0xffffff88	/* STBCR2 (Standby control register 2) SH7709A */
/* 1 = true, 0 = false
	bit 0 - Clock supply to SCI1 (IRDA) halted
	bit 1 - Clock supply to SCI2 (SCIF) halted
	bit 2 - Clock supply to ADC halted and all registers initialized
	bit 3 - Clock supply to DAC halted
	bit 4 - Clock supply to DMAC halted
	bit 5 - Clock supply to UBC is halted
	bit 6 - Pins MD5 to MD0 are changed in standby mode
	bit 7 - Reserved
*/

static int hp6x0_pm_enter(suspend_state_t state)
{
	u8 stbcr, stbcr2;
#ifdef CONFIG_HD64461_ENABLER
	u8 scr;
	u16 hd64461_stbcr;
#endif

#ifdef CONFIG_HD64461_ENABLER
	/* disable all CF interrupts */
	outb(0, HD64461_PCC1CSCIER);
	scr = inb(HD64461_PCC1SCR);
	scr |= HD64461_PCCSCR_VCC1;
	outb(scr, HD64461_PCC1SCR);

	/* get standby status of all devices */
	hd64461_stbcr = inw(HD64461_STBCR);
	/* add standby mode to CF slot */
	hd64461_stbcr |= HD64461_STBCR_SPC1ST;
	outw(hd64461_stbcr, HD64461_STBCR);
#endif

	/* chan 0/1 D/A conversion and DA 0/1 output are enabled */
	outb(0x1f, DACR);

	/* halt clocksupply to SCI */
	stbcr = inb(STBCR);
	outb(0x01, STBCR);

	/* state and drop all clocksupply */
	stbcr2 = inb(STBCR2);
	outb(0x7f , STBCR2);

	/* allow IO Ports D + C, disallow A + B */
	outw(0xf07f, HD64461_SCPUCR);

	/* Zzzzz */
	pm_enter();

	/* wakeup, Lets restore the old values */
	outw(0, HD64461_SCPUCR);
	outb(stbcr, STBCR);
	outb(stbcr2, STBCR2);

#ifdef CONFIG_HD64461_ENABLER
	/* get standby status of all devices */
	hd64461_stbcr = inw(HD64461_STBCR);
	/* remove standby mode for CF slot */
	hd64461_stbcr &= ~HD64461_STBCR_SPC1ST;
	outw(hd64461_stbcr, HD64461_STBCR);
	/* turn on CF interrupt again */
	outb(0x4c, HD64461_PCC1CSCIER);
	outb(0x00, HD64461_PCC1CSCR);
#endif

	return 0;
}

static struct platform_suspend_ops hp6x0_pm_ops = {
	.enter		= hp6x0_pm_enter,
	.valid		= suspend_valid_only_mem,
};

static int __init hp6x0_pm_init(void)
{
	suspend_set_ops(&hp6x0_pm_ops);
	return 0;
}

late_initcall(hp6x0_pm_init);