162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * ricoh.h 1.9 1999/10/25 20:03:34
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * The contents of this file are subject to the Mozilla Public License
562306a36Sopenharmony_ci * Version 1.1 (the "License"); you may not use this file except in
662306a36Sopenharmony_ci * compliance with the License. You may obtain a copy of the License
762306a36Sopenharmony_ci * at http://www.mozilla.org/MPL/
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Software distributed under the License is distributed on an "AS IS"
1062306a36Sopenharmony_ci * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
1162306a36Sopenharmony_ci * the License for the specific language governing rights and
1262306a36Sopenharmony_ci * limitations under the License.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * The initial developer of the original code is David A. Hinds
1562306a36Sopenharmony_ci * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
1662306a36Sopenharmony_ci * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * Alternatively, the contents of this file may be used under the
1962306a36Sopenharmony_ci * terms of the GNU General Public License version 2 (the "GPL"), in which
2062306a36Sopenharmony_ci * case the provisions of the GPL are applicable instead of the
2162306a36Sopenharmony_ci * above.  If you wish to allow the use of your version of this file
2262306a36Sopenharmony_ci * only under the terms of the GPL and not to allow others to use
2362306a36Sopenharmony_ci * your version of this file under the MPL, indicate your decision by
2462306a36Sopenharmony_ci * deleting the provisions above and replace them with the notice and
2562306a36Sopenharmony_ci * other provisions required by the GPL.  If you do not delete the
2662306a36Sopenharmony_ci * provisions above, a recipient may use your version of this file
2762306a36Sopenharmony_ci * under either the MPL or the GPL.
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#ifndef _LINUX_RICOH_H
3162306a36Sopenharmony_ci#define _LINUX_RICOH_H
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define RF5C_MODE_CTL		0x1f	/* Mode control */
3562306a36Sopenharmony_ci#define RF5C_PWR_CTL		0x2f	/* Mixed voltage control */
3662306a36Sopenharmony_ci#define RF5C_CHIP_ID		0x3a	/* Chip identification */
3762306a36Sopenharmony_ci#define RF5C_MODE_CTL_3		0x3b	/* Mode control 3 */
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* I/O window address offset */
4062306a36Sopenharmony_ci#define RF5C_IO_OFF(w)		(0x36+((w)<<1))
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* Flags for RF5C_MODE_CTL */
4362306a36Sopenharmony_ci#define RF5C_MODE_ATA		0x01	/* ATA mode */
4462306a36Sopenharmony_ci#define RF5C_MODE_LED_ENA	0x02	/* IRQ 12 is LED */
4562306a36Sopenharmony_ci#define RF5C_MODE_CA21		0x04
4662306a36Sopenharmony_ci#define RF5C_MODE_CA22		0x08
4762306a36Sopenharmony_ci#define RF5C_MODE_CA23		0x10
4862306a36Sopenharmony_ci#define RF5C_MODE_CA24		0x20
4962306a36Sopenharmony_ci#define RF5C_MODE_CA25		0x40
5062306a36Sopenharmony_ci#define RF5C_MODE_3STATE_BIT7	0x80
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* Flags for RF5C_PWR_CTL */
5362306a36Sopenharmony_ci#define RF5C_PWR_VCC_3V		0x01
5462306a36Sopenharmony_ci#define RF5C_PWR_IREQ_HIGH	0x02
5562306a36Sopenharmony_ci#define RF5C_PWR_INPACK_ENA	0x04
5662306a36Sopenharmony_ci#define RF5C_PWR_5V_DET		0x08
5762306a36Sopenharmony_ci#define RF5C_PWR_TC_SEL		0x10	/* Terminal Count: irq 11 or 15 */
5862306a36Sopenharmony_ci#define RF5C_PWR_DREQ_LOW	0x20
5962306a36Sopenharmony_ci#define RF5C_PWR_DREQ_OFF	0x00	/* DREQ steering control */
6062306a36Sopenharmony_ci#define RF5C_PWR_DREQ_INPACK	0x40
6162306a36Sopenharmony_ci#define RF5C_PWR_DREQ_SPKR	0x80
6262306a36Sopenharmony_ci#define RF5C_PWR_DREQ_IOIS16	0xc0
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/* Values for RF5C_CHIP_ID */
6562306a36Sopenharmony_ci#define RF5C_CHIP_RF5C296	0x32
6662306a36Sopenharmony_ci#define RF5C_CHIP_RF5C396	0xb2
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* Flags for RF5C_MODE_CTL_3 */
6962306a36Sopenharmony_ci#define RF5C_MCTL3_DISABLE	0x01	/* Disable PCMCIA interface */
7062306a36Sopenharmony_ci#define RF5C_MCTL3_DMA_ENA	0x02
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Register definitions for Ricoh PCI-to-CardBus bridges */
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* Extra bits in CB_BRIDGE_CONTROL */
7562306a36Sopenharmony_ci#define RL5C46X_BCR_3E0_ENA		0x0800
7662306a36Sopenharmony_ci#define RL5C46X_BCR_3E2_ENA		0x1000
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* Bridge Configuration Register */
7962306a36Sopenharmony_ci#define RL5C4XX_CONFIG			0x80	/* 16 bit */
8062306a36Sopenharmony_ci#define  RL5C4XX_CONFIG_IO_1_MODE	0x0200
8162306a36Sopenharmony_ci#define  RL5C4XX_CONFIG_IO_0_MODE	0x0100
8262306a36Sopenharmony_ci#define  RL5C4XX_CONFIG_PREFETCH	0x0001
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/* Misc Control Register */
8562306a36Sopenharmony_ci#define RL5C4XX_MISC			0x0082	/* 16 bit */
8662306a36Sopenharmony_ci#define  RL5C4XX_MISC_HW_SUSPEND_ENA	0x0002
8762306a36Sopenharmony_ci#define  RL5C4XX_MISC_VCCEN_POL		0x0100
8862306a36Sopenharmony_ci#define  RL5C4XX_MISC_VPPEN_POL		0x0200
8962306a36Sopenharmony_ci#define  RL5C46X_MISC_SUSPEND		0x0001
9062306a36Sopenharmony_ci#define  RL5C46X_MISC_PWR_SAVE_2	0x0004
9162306a36Sopenharmony_ci#define  RL5C46X_MISC_IFACE_BUSY	0x0008
9262306a36Sopenharmony_ci#define  RL5C46X_MISC_B_LOCK		0x0010
9362306a36Sopenharmony_ci#define  RL5C46X_MISC_A_LOCK		0x0020
9462306a36Sopenharmony_ci#define  RL5C46X_MISC_PCI_LOCK		0x0040
9562306a36Sopenharmony_ci#define  RL5C47X_MISC_IFACE_BUSY	0x0004
9662306a36Sopenharmony_ci#define  RL5C47X_MISC_PCI_INT_MASK	0x0018
9762306a36Sopenharmony_ci#define  RL5C47X_MISC_PCI_INT_DIS	0x0020
9862306a36Sopenharmony_ci#define  RL5C47X_MISC_SUBSYS_WR		0x0040
9962306a36Sopenharmony_ci#define  RL5C47X_MISC_SRIRQ_ENA		0x0080
10062306a36Sopenharmony_ci#define  RL5C47X_MISC_5V_DISABLE	0x0400
10162306a36Sopenharmony_ci#define  RL5C47X_MISC_LED_POL		0x0800
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* 16-bit Interface Control Register */
10462306a36Sopenharmony_ci#define RL5C4XX_16BIT_CTL		0x0084	/* 16 bit */
10562306a36Sopenharmony_ci#define  RL5C4XX_16CTL_IO_TIMING	0x0100
10662306a36Sopenharmony_ci#define  RL5C4XX_16CTL_MEM_TIMING	0x0200
10762306a36Sopenharmony_ci#define  RL5C46X_16CTL_LEVEL_1		0x0010
10862306a36Sopenharmony_ci#define  RL5C46X_16CTL_LEVEL_2		0x0020
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/* 16-bit IO and memory timing registers */
11162306a36Sopenharmony_ci#define RL5C4XX_16BIT_IO_0		0x0088	/* 16 bit */
11262306a36Sopenharmony_ci#define RL5C4XX_16BIT_MEM_0		0x008a	/* 16 bit */
11362306a36Sopenharmony_ci#define  RL5C4XX_SETUP_MASK		0x0007
11462306a36Sopenharmony_ci#define  RL5C4XX_SETUP_SHIFT		0
11562306a36Sopenharmony_ci#define  RL5C4XX_CMD_MASK		0x01f0
11662306a36Sopenharmony_ci#define  RL5C4XX_CMD_SHIFT		4
11762306a36Sopenharmony_ci#define  RL5C4XX_HOLD_MASK		0x1c00
11862306a36Sopenharmony_ci#define  RL5C4XX_HOLD_SHIFT		10
11962306a36Sopenharmony_ci#define  RL5C4XX_MISC_CONTROL           0x2F /* 8 bit */
12062306a36Sopenharmony_ci#define  RL5C4XX_ZV_ENABLE              0x08
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/* Misc Control 3 Register */
12362306a36Sopenharmony_ci#define RL5C4XX_MISC3			0x00A2 /* 16 bit */
12462306a36Sopenharmony_ci#define  RL5C47X_MISC3_CB_CLKRUN_DIS	BIT(1)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#ifdef __YENTA_H
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#define rl_misc(socket)		((socket)->private[0])
12962306a36Sopenharmony_ci#define rl_ctl(socket)		((socket)->private[1])
13062306a36Sopenharmony_ci#define rl_io(socket)		((socket)->private[2])
13162306a36Sopenharmony_ci#define rl_mem(socket)		((socket)->private[3])
13262306a36Sopenharmony_ci#define rl_config(socket)	((socket)->private[4])
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_cistatic void ricoh_zoom_video(struct pcmcia_socket *sock, int onoff)
13562306a36Sopenharmony_ci{
13662306a36Sopenharmony_ci        u8 reg;
13762306a36Sopenharmony_ci	struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci        reg = config_readb(socket, RL5C4XX_MISC_CONTROL);
14062306a36Sopenharmony_ci        if (onoff)
14162306a36Sopenharmony_ci                /* Zoom zoom, we will all go together, zoom zoom, zoom zoom */
14262306a36Sopenharmony_ci                reg |=  RL5C4XX_ZV_ENABLE;
14362306a36Sopenharmony_ci        else
14462306a36Sopenharmony_ci                reg &= ~RL5C4XX_ZV_ENABLE;
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci        config_writeb(socket, RL5C4XX_MISC_CONTROL, reg);
14762306a36Sopenharmony_ci}
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistatic void ricoh_set_zv(struct yenta_socket *socket)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci        if(socket->dev->vendor == PCI_VENDOR_ID_RICOH)
15262306a36Sopenharmony_ci        {
15362306a36Sopenharmony_ci                switch(socket->dev->device)
15462306a36Sopenharmony_ci                {
15562306a36Sopenharmony_ci                        /* There may be more .. */
15662306a36Sopenharmony_ci		case  PCI_DEVICE_ID_RICOH_RL5C478:
15762306a36Sopenharmony_ci			socket->socket.zoom_video = ricoh_zoom_video;
15862306a36Sopenharmony_ci			break;
15962306a36Sopenharmony_ci                }
16062306a36Sopenharmony_ci        }
16162306a36Sopenharmony_ci}
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_cistatic void ricoh_set_clkrun(struct yenta_socket *socket, bool quiet)
16462306a36Sopenharmony_ci{
16562306a36Sopenharmony_ci	u16 misc3;
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	/*
16862306a36Sopenharmony_ci	 * RL5C475II likely has this setting, too, however no datasheet
16962306a36Sopenharmony_ci	 * is publicly available for this chip
17062306a36Sopenharmony_ci	 */
17162306a36Sopenharmony_ci	if (socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C476 &&
17262306a36Sopenharmony_ci	    socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C478)
17362306a36Sopenharmony_ci		return;
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	if (socket->dev->revision < 0x80)
17662306a36Sopenharmony_ci		return;
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	misc3 = config_readw(socket, RL5C4XX_MISC3);
17962306a36Sopenharmony_ci	if (misc3 & RL5C47X_MISC3_CB_CLKRUN_DIS) {
18062306a36Sopenharmony_ci		if (!quiet)
18162306a36Sopenharmony_ci			dev_dbg(&socket->dev->dev,
18262306a36Sopenharmony_ci				"CLKRUN feature already disabled\n");
18362306a36Sopenharmony_ci	} else if (disable_clkrun) {
18462306a36Sopenharmony_ci		if (!quiet)
18562306a36Sopenharmony_ci			dev_info(&socket->dev->dev,
18662306a36Sopenharmony_ci				 "Disabling CLKRUN feature\n");
18762306a36Sopenharmony_ci		misc3 |= RL5C47X_MISC3_CB_CLKRUN_DIS;
18862306a36Sopenharmony_ci		config_writew(socket, RL5C4XX_MISC3, misc3);
18962306a36Sopenharmony_ci	}
19062306a36Sopenharmony_ci}
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_cistatic void ricoh_save_state(struct yenta_socket *socket)
19362306a36Sopenharmony_ci{
19462306a36Sopenharmony_ci	rl_misc(socket) = config_readw(socket, RL5C4XX_MISC);
19562306a36Sopenharmony_ci	rl_ctl(socket) = config_readw(socket, RL5C4XX_16BIT_CTL);
19662306a36Sopenharmony_ci	rl_io(socket) = config_readw(socket, RL5C4XX_16BIT_IO_0);
19762306a36Sopenharmony_ci	rl_mem(socket) = config_readw(socket, RL5C4XX_16BIT_MEM_0);
19862306a36Sopenharmony_ci	rl_config(socket) = config_readw(socket, RL5C4XX_CONFIG);
19962306a36Sopenharmony_ci}
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_cistatic void ricoh_restore_state(struct yenta_socket *socket)
20262306a36Sopenharmony_ci{
20362306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_MISC, rl_misc(socket));
20462306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_CTL, rl_ctl(socket));
20562306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_IO_0, rl_io(socket));
20662306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_MEM_0, rl_mem(socket));
20762306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_CONFIG, rl_config(socket));
20862306a36Sopenharmony_ci	ricoh_set_clkrun(socket, true);
20962306a36Sopenharmony_ci}
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci/*
21362306a36Sopenharmony_ci * Magic Ricoh initialization code..
21462306a36Sopenharmony_ci */
21562306a36Sopenharmony_cistatic int ricoh_override(struct yenta_socket *socket)
21662306a36Sopenharmony_ci{
21762306a36Sopenharmony_ci	u16 config, ctl;
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	config = config_readw(socket, RL5C4XX_CONFIG);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci	/* Set the default timings, don't trust the original values */
22262306a36Sopenharmony_ci	ctl = RL5C4XX_16CTL_IO_TIMING | RL5C4XX_16CTL_MEM_TIMING;
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci	if(socket->dev->device < PCI_DEVICE_ID_RICOH_RL5C475) {
22562306a36Sopenharmony_ci		ctl |= RL5C46X_16CTL_LEVEL_1 | RL5C46X_16CTL_LEVEL_2;
22662306a36Sopenharmony_ci	} else {
22762306a36Sopenharmony_ci		config |= RL5C4XX_CONFIG_PREFETCH;
22862306a36Sopenharmony_ci	}
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_CTL, ctl);
23162306a36Sopenharmony_ci	config_writew(socket, RL5C4XX_CONFIG, config);
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci	ricoh_set_zv(socket);
23462306a36Sopenharmony_ci	ricoh_set_clkrun(socket, false);
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci	return 0;
23762306a36Sopenharmony_ci}
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci#endif /* CONFIG_CARDBUS */
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci#endif /* _LINUX_RICOH_H */
242