1/*	$NetBSD: hd64461_machdep.c,v 1.6 2011/07/19 15:30:52 dyoung Exp $	*/
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: hd64461_machdep.c,v 1.6 2011/07/19 15:30:52 dyoung Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/bus.h>
38
39#include <machine/platid.h>
40#include <machine/platid_mask.h>
41
42#include <hpcsh/dev/hd64461/hd64461var.h>
43#include <hpcsh/dev/hd64461/hd64461pcmciavar.h>
44#include <hpcsh/dev/hd64461/hd64461pcmciareg.h>
45
46/*
47 * Platform dependent hooks.
48 */
49
50void
51hd64461pcmcia_power(int ch, enum pcmcia_voltage vol, int on)
52{
53#define VCC0_ON()							\
54do {									\
55	r = hd64461_reg_read_1(gcr);					\
56	r |= HD64461_PCCGCR_VCC0;					\
57	hd64461_reg_write_1(gcr, r);					\
58} while (/*CONSTCOND*/0)
59#define VCC0_OFF()							\
60do {									\
61	r = hd64461_reg_read_1(gcr);					\
62	r &= ~HD64461_PCCGCR_VCC0;					\
63	hd64461_reg_write_1(gcr, r);					\
64} while (/*CONSTCOND*/0)
65#define VCC1_ON()							\
66do {									\
67	r = hd64461_reg_read_1(scr);					\
68	r |= HD64461_PCCSCR_VCC1;					\
69	hd64461_reg_write_1(scr, r);					\
70} while (/*CONSTCOND*/0)
71#define VCC1_OFF()							\
72do {									\
73	r = hd64461_reg_read_1(scr);					\
74	r &= ~HD64461_PCCSCR_VCC1;					\
75	hd64461_reg_write_1(scr, r);					\
76} while (/*CONSTCOND*/0)
77	bus_addr_t gcr, scr;
78	uint8_t r;
79
80	(void)HD64461_PCCISR(ch);
81	gcr = HD64461_PCCGCR(ch);
82	scr = HD64461_PCCSCR(ch);
83
84	/* 3.3 V */
85	if (vol == V_3_3) {
86		if (ch == 1) {
87			if (on) {
88				VCC0_OFF();
89				VCC1_OFF();
90			} else {
91				VCC0_ON();
92				VCC1_ON();
93			}
94		} else {
95			if (on) {
96				VCC0_ON();
97				VCC1_OFF();
98			} else {
99				VCC0_OFF();
100				VCC1_ON();
101			}
102		}
103		return;
104	}
105
106	/* 5 V */
107	if (platid_match(&platid, &platid_mask_MACH_HP)) {
108		if (on) {
109			VCC0_OFF();
110			VCC1_OFF();
111		} else {
112			VCC0_ON();
113			VCC1_ON();
114		}
115		return;
116	} else if (platid_match(&platid, &platid_mask_MACH_HITACHI)) {
117		if (on) {
118			VCC0_OFF();
119			VCC1_ON();
120		} else {
121			VCC0_ON();
122			VCC1_OFF();
123		}
124		return;
125	}
126
127	/* x.x V, y.y V */
128	printf("x.x/y.y V not supported.\n");
129#undef VCC0_ON
130#undef VCC0_OFF
131#undef VCC1_ON
132#undef VCC1_OFF
133}
134