xref: /kernel/linux/linux-5.10/drivers/pcmcia/ricoh.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * ricoh.h 1.9 1999/10/25 20:03:34
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * The contents of this file are subject to the Mozilla Public License
58c2ecf20Sopenharmony_ci * Version 1.1 (the "License"); you may not use this file except in
68c2ecf20Sopenharmony_ci * compliance with the License. You may obtain a copy of the License
78c2ecf20Sopenharmony_ci * at http://www.mozilla.org/MPL/
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Software distributed under the License is distributed on an "AS IS"
108c2ecf20Sopenharmony_ci * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
118c2ecf20Sopenharmony_ci * the License for the specific language governing rights and
128c2ecf20Sopenharmony_ci * limitations under the License.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The initial developer of the original code is David A. Hinds
158c2ecf20Sopenharmony_ci * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
168c2ecf20Sopenharmony_ci * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * Alternatively, the contents of this file may be used under the
198c2ecf20Sopenharmony_ci * terms of the GNU General Public License version 2 (the "GPL"), in which
208c2ecf20Sopenharmony_ci * case the provisions of the GPL are applicable instead of the
218c2ecf20Sopenharmony_ci * above.  If you wish to allow the use of your version of this file
228c2ecf20Sopenharmony_ci * only under the terms of the GPL and not to allow others to use
238c2ecf20Sopenharmony_ci * your version of this file under the MPL, indicate your decision by
248c2ecf20Sopenharmony_ci * deleting the provisions above and replace them with the notice and
258c2ecf20Sopenharmony_ci * other provisions required by the GPL.  If you do not delete the
268c2ecf20Sopenharmony_ci * provisions above, a recipient may use your version of this file
278c2ecf20Sopenharmony_ci * under either the MPL or the GPL.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#ifndef _LINUX_RICOH_H
318c2ecf20Sopenharmony_ci#define _LINUX_RICOH_H
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define RF5C_MODE_CTL		0x1f	/* Mode control */
358c2ecf20Sopenharmony_ci#define RF5C_PWR_CTL		0x2f	/* Mixed voltage control */
368c2ecf20Sopenharmony_ci#define RF5C_CHIP_ID		0x3a	/* Chip identification */
378c2ecf20Sopenharmony_ci#define RF5C_MODE_CTL_3		0x3b	/* Mode control 3 */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* I/O window address offset */
408c2ecf20Sopenharmony_ci#define RF5C_IO_OFF(w)		(0x36+((w)<<1))
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* Flags for RF5C_MODE_CTL */
438c2ecf20Sopenharmony_ci#define RF5C_MODE_ATA		0x01	/* ATA mode */
448c2ecf20Sopenharmony_ci#define RF5C_MODE_LED_ENA	0x02	/* IRQ 12 is LED */
458c2ecf20Sopenharmony_ci#define RF5C_MODE_CA21		0x04
468c2ecf20Sopenharmony_ci#define RF5C_MODE_CA22		0x08
478c2ecf20Sopenharmony_ci#define RF5C_MODE_CA23		0x10
488c2ecf20Sopenharmony_ci#define RF5C_MODE_CA24		0x20
498c2ecf20Sopenharmony_ci#define RF5C_MODE_CA25		0x40
508c2ecf20Sopenharmony_ci#define RF5C_MODE_3STATE_BIT7	0x80
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* Flags for RF5C_PWR_CTL */
538c2ecf20Sopenharmony_ci#define RF5C_PWR_VCC_3V		0x01
548c2ecf20Sopenharmony_ci#define RF5C_PWR_IREQ_HIGH	0x02
558c2ecf20Sopenharmony_ci#define RF5C_PWR_INPACK_ENA	0x04
568c2ecf20Sopenharmony_ci#define RF5C_PWR_5V_DET		0x08
578c2ecf20Sopenharmony_ci#define RF5C_PWR_TC_SEL		0x10	/* Terminal Count: irq 11 or 15 */
588c2ecf20Sopenharmony_ci#define RF5C_PWR_DREQ_LOW	0x20
598c2ecf20Sopenharmony_ci#define RF5C_PWR_DREQ_OFF	0x00	/* DREQ steering control */
608c2ecf20Sopenharmony_ci#define RF5C_PWR_DREQ_INPACK	0x40
618c2ecf20Sopenharmony_ci#define RF5C_PWR_DREQ_SPKR	0x80
628c2ecf20Sopenharmony_ci#define RF5C_PWR_DREQ_IOIS16	0xc0
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Values for RF5C_CHIP_ID */
658c2ecf20Sopenharmony_ci#define RF5C_CHIP_RF5C296	0x32
668c2ecf20Sopenharmony_ci#define RF5C_CHIP_RF5C396	0xb2
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Flags for RF5C_MODE_CTL_3 */
698c2ecf20Sopenharmony_ci#define RF5C_MCTL3_DISABLE	0x01	/* Disable PCMCIA interface */
708c2ecf20Sopenharmony_ci#define RF5C_MCTL3_DMA_ENA	0x02
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Register definitions for Ricoh PCI-to-CardBus bridges */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Extra bits in CB_BRIDGE_CONTROL */
758c2ecf20Sopenharmony_ci#define RL5C46X_BCR_3E0_ENA		0x0800
768c2ecf20Sopenharmony_ci#define RL5C46X_BCR_3E2_ENA		0x1000
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* Bridge Configuration Register */
798c2ecf20Sopenharmony_ci#define RL5C4XX_CONFIG			0x80	/* 16 bit */
808c2ecf20Sopenharmony_ci#define  RL5C4XX_CONFIG_IO_1_MODE	0x0200
818c2ecf20Sopenharmony_ci#define  RL5C4XX_CONFIG_IO_0_MODE	0x0100
828c2ecf20Sopenharmony_ci#define  RL5C4XX_CONFIG_PREFETCH	0x0001
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* Misc Control Register */
858c2ecf20Sopenharmony_ci#define RL5C4XX_MISC			0x0082	/* 16 bit */
868c2ecf20Sopenharmony_ci#define  RL5C4XX_MISC_HW_SUSPEND_ENA	0x0002
878c2ecf20Sopenharmony_ci#define  RL5C4XX_MISC_VCCEN_POL		0x0100
888c2ecf20Sopenharmony_ci#define  RL5C4XX_MISC_VPPEN_POL		0x0200
898c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_SUSPEND		0x0001
908c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_PWR_SAVE_2	0x0004
918c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_IFACE_BUSY	0x0008
928c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_B_LOCK		0x0010
938c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_A_LOCK		0x0020
948c2ecf20Sopenharmony_ci#define  RL5C46X_MISC_PCI_LOCK		0x0040
958c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_IFACE_BUSY	0x0004
968c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_PCI_INT_MASK	0x0018
978c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_PCI_INT_DIS	0x0020
988c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_SUBSYS_WR		0x0040
998c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_SRIRQ_ENA		0x0080
1008c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_5V_DISABLE	0x0400
1018c2ecf20Sopenharmony_ci#define  RL5C47X_MISC_LED_POL		0x0800
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* 16-bit Interface Control Register */
1048c2ecf20Sopenharmony_ci#define RL5C4XX_16BIT_CTL		0x0084	/* 16 bit */
1058c2ecf20Sopenharmony_ci#define  RL5C4XX_16CTL_IO_TIMING	0x0100
1068c2ecf20Sopenharmony_ci#define  RL5C4XX_16CTL_MEM_TIMING	0x0200
1078c2ecf20Sopenharmony_ci#define  RL5C46X_16CTL_LEVEL_1		0x0010
1088c2ecf20Sopenharmony_ci#define  RL5C46X_16CTL_LEVEL_2		0x0020
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/* 16-bit IO and memory timing registers */
1118c2ecf20Sopenharmony_ci#define RL5C4XX_16BIT_IO_0		0x0088	/* 16 bit */
1128c2ecf20Sopenharmony_ci#define RL5C4XX_16BIT_MEM_0		0x008a	/* 16 bit */
1138c2ecf20Sopenharmony_ci#define  RL5C4XX_SETUP_MASK		0x0007
1148c2ecf20Sopenharmony_ci#define  RL5C4XX_SETUP_SHIFT		0
1158c2ecf20Sopenharmony_ci#define  RL5C4XX_CMD_MASK		0x01f0
1168c2ecf20Sopenharmony_ci#define  RL5C4XX_CMD_SHIFT		4
1178c2ecf20Sopenharmony_ci#define  RL5C4XX_HOLD_MASK		0x1c00
1188c2ecf20Sopenharmony_ci#define  RL5C4XX_HOLD_SHIFT		10
1198c2ecf20Sopenharmony_ci#define  RL5C4XX_MISC_CONTROL           0x2F /* 8 bit */
1208c2ecf20Sopenharmony_ci#define  RL5C4XX_ZV_ENABLE              0x08
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/* Misc Control 3 Register */
1238c2ecf20Sopenharmony_ci#define RL5C4XX_MISC3			0x00A2 /* 16 bit */
1248c2ecf20Sopenharmony_ci#define  RL5C47X_MISC3_CB_CLKRUN_DIS	BIT(1)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#ifdef __YENTA_H
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define rl_misc(socket)		((socket)->private[0])
1298c2ecf20Sopenharmony_ci#define rl_ctl(socket)		((socket)->private[1])
1308c2ecf20Sopenharmony_ci#define rl_io(socket)		((socket)->private[2])
1318c2ecf20Sopenharmony_ci#define rl_mem(socket)		((socket)->private[3])
1328c2ecf20Sopenharmony_ci#define rl_config(socket)	((socket)->private[4])
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic void ricoh_zoom_video(struct pcmcia_socket *sock, int onoff)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci        u8 reg;
1378c2ecf20Sopenharmony_ci	struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci        reg = config_readb(socket, RL5C4XX_MISC_CONTROL);
1408c2ecf20Sopenharmony_ci        if (onoff)
1418c2ecf20Sopenharmony_ci                /* Zoom zoom, we will all go together, zoom zoom, zoom zoom */
1428c2ecf20Sopenharmony_ci                reg |=  RL5C4XX_ZV_ENABLE;
1438c2ecf20Sopenharmony_ci        else
1448c2ecf20Sopenharmony_ci                reg &= ~RL5C4XX_ZV_ENABLE;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci        config_writeb(socket, RL5C4XX_MISC_CONTROL, reg);
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic void ricoh_set_zv(struct yenta_socket *socket)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci        if(socket->dev->vendor == PCI_VENDOR_ID_RICOH)
1528c2ecf20Sopenharmony_ci        {
1538c2ecf20Sopenharmony_ci                switch(socket->dev->device)
1548c2ecf20Sopenharmony_ci                {
1558c2ecf20Sopenharmony_ci                        /* There may be more .. */
1568c2ecf20Sopenharmony_ci		case  PCI_DEVICE_ID_RICOH_RL5C478:
1578c2ecf20Sopenharmony_ci			socket->socket.zoom_video = ricoh_zoom_video;
1588c2ecf20Sopenharmony_ci			break;
1598c2ecf20Sopenharmony_ci                }
1608c2ecf20Sopenharmony_ci        }
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic void ricoh_set_clkrun(struct yenta_socket *socket, bool quiet)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	u16 misc3;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	/*
1688c2ecf20Sopenharmony_ci	 * RL5C475II likely has this setting, too, however no datasheet
1698c2ecf20Sopenharmony_ci	 * is publicly available for this chip
1708c2ecf20Sopenharmony_ci	 */
1718c2ecf20Sopenharmony_ci	if (socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C476 &&
1728c2ecf20Sopenharmony_ci	    socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C478)
1738c2ecf20Sopenharmony_ci		return;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (socket->dev->revision < 0x80)
1768c2ecf20Sopenharmony_ci		return;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	misc3 = config_readw(socket, RL5C4XX_MISC3);
1798c2ecf20Sopenharmony_ci	if (misc3 & RL5C47X_MISC3_CB_CLKRUN_DIS) {
1808c2ecf20Sopenharmony_ci		if (!quiet)
1818c2ecf20Sopenharmony_ci			dev_dbg(&socket->dev->dev,
1828c2ecf20Sopenharmony_ci				"CLKRUN feature already disabled\n");
1838c2ecf20Sopenharmony_ci	} else if (disable_clkrun) {
1848c2ecf20Sopenharmony_ci		if (!quiet)
1858c2ecf20Sopenharmony_ci			dev_info(&socket->dev->dev,
1868c2ecf20Sopenharmony_ci				 "Disabling CLKRUN feature\n");
1878c2ecf20Sopenharmony_ci		misc3 |= RL5C47X_MISC3_CB_CLKRUN_DIS;
1888c2ecf20Sopenharmony_ci		config_writew(socket, RL5C4XX_MISC3, misc3);
1898c2ecf20Sopenharmony_ci	}
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic void ricoh_save_state(struct yenta_socket *socket)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	rl_misc(socket) = config_readw(socket, RL5C4XX_MISC);
1958c2ecf20Sopenharmony_ci	rl_ctl(socket) = config_readw(socket, RL5C4XX_16BIT_CTL);
1968c2ecf20Sopenharmony_ci	rl_io(socket) = config_readw(socket, RL5C4XX_16BIT_IO_0);
1978c2ecf20Sopenharmony_ci	rl_mem(socket) = config_readw(socket, RL5C4XX_16BIT_MEM_0);
1988c2ecf20Sopenharmony_ci	rl_config(socket) = config_readw(socket, RL5C4XX_CONFIG);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic void ricoh_restore_state(struct yenta_socket *socket)
2028c2ecf20Sopenharmony_ci{
2038c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_MISC, rl_misc(socket));
2048c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_CTL, rl_ctl(socket));
2058c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_IO_0, rl_io(socket));
2068c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_MEM_0, rl_mem(socket));
2078c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_CONFIG, rl_config(socket));
2088c2ecf20Sopenharmony_ci	ricoh_set_clkrun(socket, true);
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/*
2138c2ecf20Sopenharmony_ci * Magic Ricoh initialization code..
2148c2ecf20Sopenharmony_ci */
2158c2ecf20Sopenharmony_cistatic int ricoh_override(struct yenta_socket *socket)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	u16 config, ctl;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	config = config_readw(socket, RL5C4XX_CONFIG);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	/* Set the default timings, don't trust the original values */
2228c2ecf20Sopenharmony_ci	ctl = RL5C4XX_16CTL_IO_TIMING | RL5C4XX_16CTL_MEM_TIMING;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	if(socket->dev->device < PCI_DEVICE_ID_RICOH_RL5C475) {
2258c2ecf20Sopenharmony_ci		ctl |= RL5C46X_16CTL_LEVEL_1 | RL5C46X_16CTL_LEVEL_2;
2268c2ecf20Sopenharmony_ci	} else {
2278c2ecf20Sopenharmony_ci		config |= RL5C4XX_CONFIG_PREFETCH;
2288c2ecf20Sopenharmony_ci	}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_16BIT_CTL, ctl);
2318c2ecf20Sopenharmony_ci	config_writew(socket, RL5C4XX_CONFIG, config);
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	ricoh_set_zv(socket);
2348c2ecf20Sopenharmony_ci	ricoh_set_clkrun(socket, false);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	return 0;
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#endif /* CONFIG_CARDBUS */
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci#endif /* _LINUX_RICOH_H */
242