1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * ricoh.h 1.9 1999/10/25 20:03:34
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * The contents of this file are subject to the Mozilla Public License
5*4882a593Smuzhiyun * Version 1.1 (the "License"); you may not use this file except in
6*4882a593Smuzhiyun * compliance with the License. You may obtain a copy of the License
7*4882a593Smuzhiyun * at http://www.mozilla.org/MPL/
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Software distributed under the License is distributed on an "AS IS"
10*4882a593Smuzhiyun * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11*4882a593Smuzhiyun * the License for the specific language governing rights and
12*4882a593Smuzhiyun * limitations under the License.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The initial developer of the original code is David A. Hinds
15*4882a593Smuzhiyun * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
16*4882a593Smuzhiyun * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * Alternatively, the contents of this file may be used under the
19*4882a593Smuzhiyun * terms of the GNU General Public License version 2 (the "GPL"), in which
20*4882a593Smuzhiyun * case the provisions of the GPL are applicable instead of the
21*4882a593Smuzhiyun * above. If you wish to allow the use of your version of this file
22*4882a593Smuzhiyun * only under the terms of the GPL and not to allow others to use
23*4882a593Smuzhiyun * your version of this file under the MPL, indicate your decision by
24*4882a593Smuzhiyun * deleting the provisions above and replace them with the notice and
25*4882a593Smuzhiyun * other provisions required by the GPL. If you do not delete the
26*4882a593Smuzhiyun * provisions above, a recipient may use your version of this file
27*4882a593Smuzhiyun * under either the MPL or the GPL.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #ifndef _LINUX_RICOH_H
31*4882a593Smuzhiyun #define _LINUX_RICOH_H
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define RF5C_MODE_CTL 0x1f /* Mode control */
35*4882a593Smuzhiyun #define RF5C_PWR_CTL 0x2f /* Mixed voltage control */
36*4882a593Smuzhiyun #define RF5C_CHIP_ID 0x3a /* Chip identification */
37*4882a593Smuzhiyun #define RF5C_MODE_CTL_3 0x3b /* Mode control 3 */
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /* I/O window address offset */
40*4882a593Smuzhiyun #define RF5C_IO_OFF(w) (0x36+((w)<<1))
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /* Flags for RF5C_MODE_CTL */
43*4882a593Smuzhiyun #define RF5C_MODE_ATA 0x01 /* ATA mode */
44*4882a593Smuzhiyun #define RF5C_MODE_LED_ENA 0x02 /* IRQ 12 is LED */
45*4882a593Smuzhiyun #define RF5C_MODE_CA21 0x04
46*4882a593Smuzhiyun #define RF5C_MODE_CA22 0x08
47*4882a593Smuzhiyun #define RF5C_MODE_CA23 0x10
48*4882a593Smuzhiyun #define RF5C_MODE_CA24 0x20
49*4882a593Smuzhiyun #define RF5C_MODE_CA25 0x40
50*4882a593Smuzhiyun #define RF5C_MODE_3STATE_BIT7 0x80
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun /* Flags for RF5C_PWR_CTL */
53*4882a593Smuzhiyun #define RF5C_PWR_VCC_3V 0x01
54*4882a593Smuzhiyun #define RF5C_PWR_IREQ_HIGH 0x02
55*4882a593Smuzhiyun #define RF5C_PWR_INPACK_ENA 0x04
56*4882a593Smuzhiyun #define RF5C_PWR_5V_DET 0x08
57*4882a593Smuzhiyun #define RF5C_PWR_TC_SEL 0x10 /* Terminal Count: irq 11 or 15 */
58*4882a593Smuzhiyun #define RF5C_PWR_DREQ_LOW 0x20
59*4882a593Smuzhiyun #define RF5C_PWR_DREQ_OFF 0x00 /* DREQ steering control */
60*4882a593Smuzhiyun #define RF5C_PWR_DREQ_INPACK 0x40
61*4882a593Smuzhiyun #define RF5C_PWR_DREQ_SPKR 0x80
62*4882a593Smuzhiyun #define RF5C_PWR_DREQ_IOIS16 0xc0
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Values for RF5C_CHIP_ID */
65*4882a593Smuzhiyun #define RF5C_CHIP_RF5C296 0x32
66*4882a593Smuzhiyun #define RF5C_CHIP_RF5C396 0xb2
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun /* Flags for RF5C_MODE_CTL_3 */
69*4882a593Smuzhiyun #define RF5C_MCTL3_DISABLE 0x01 /* Disable PCMCIA interface */
70*4882a593Smuzhiyun #define RF5C_MCTL3_DMA_ENA 0x02
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /* Register definitions for Ricoh PCI-to-CardBus bridges */
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /* Extra bits in CB_BRIDGE_CONTROL */
75*4882a593Smuzhiyun #define RL5C46X_BCR_3E0_ENA 0x0800
76*4882a593Smuzhiyun #define RL5C46X_BCR_3E2_ENA 0x1000
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /* Bridge Configuration Register */
79*4882a593Smuzhiyun #define RL5C4XX_CONFIG 0x80 /* 16 bit */
80*4882a593Smuzhiyun #define RL5C4XX_CONFIG_IO_1_MODE 0x0200
81*4882a593Smuzhiyun #define RL5C4XX_CONFIG_IO_0_MODE 0x0100
82*4882a593Smuzhiyun #define RL5C4XX_CONFIG_PREFETCH 0x0001
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /* Misc Control Register */
85*4882a593Smuzhiyun #define RL5C4XX_MISC 0x0082 /* 16 bit */
86*4882a593Smuzhiyun #define RL5C4XX_MISC_HW_SUSPEND_ENA 0x0002
87*4882a593Smuzhiyun #define RL5C4XX_MISC_VCCEN_POL 0x0100
88*4882a593Smuzhiyun #define RL5C4XX_MISC_VPPEN_POL 0x0200
89*4882a593Smuzhiyun #define RL5C46X_MISC_SUSPEND 0x0001
90*4882a593Smuzhiyun #define RL5C46X_MISC_PWR_SAVE_2 0x0004
91*4882a593Smuzhiyun #define RL5C46X_MISC_IFACE_BUSY 0x0008
92*4882a593Smuzhiyun #define RL5C46X_MISC_B_LOCK 0x0010
93*4882a593Smuzhiyun #define RL5C46X_MISC_A_LOCK 0x0020
94*4882a593Smuzhiyun #define RL5C46X_MISC_PCI_LOCK 0x0040
95*4882a593Smuzhiyun #define RL5C47X_MISC_IFACE_BUSY 0x0004
96*4882a593Smuzhiyun #define RL5C47X_MISC_PCI_INT_MASK 0x0018
97*4882a593Smuzhiyun #define RL5C47X_MISC_PCI_INT_DIS 0x0020
98*4882a593Smuzhiyun #define RL5C47X_MISC_SUBSYS_WR 0x0040
99*4882a593Smuzhiyun #define RL5C47X_MISC_SRIRQ_ENA 0x0080
100*4882a593Smuzhiyun #define RL5C47X_MISC_5V_DISABLE 0x0400
101*4882a593Smuzhiyun #define RL5C47X_MISC_LED_POL 0x0800
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* 16-bit Interface Control Register */
104*4882a593Smuzhiyun #define RL5C4XX_16BIT_CTL 0x0084 /* 16 bit */
105*4882a593Smuzhiyun #define RL5C4XX_16CTL_IO_TIMING 0x0100
106*4882a593Smuzhiyun #define RL5C4XX_16CTL_MEM_TIMING 0x0200
107*4882a593Smuzhiyun #define RL5C46X_16CTL_LEVEL_1 0x0010
108*4882a593Smuzhiyun #define RL5C46X_16CTL_LEVEL_2 0x0020
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun /* 16-bit IO and memory timing registers */
111*4882a593Smuzhiyun #define RL5C4XX_16BIT_IO_0 0x0088 /* 16 bit */
112*4882a593Smuzhiyun #define RL5C4XX_16BIT_MEM_0 0x008a /* 16 bit */
113*4882a593Smuzhiyun #define RL5C4XX_SETUP_MASK 0x0007
114*4882a593Smuzhiyun #define RL5C4XX_SETUP_SHIFT 0
115*4882a593Smuzhiyun #define RL5C4XX_CMD_MASK 0x01f0
116*4882a593Smuzhiyun #define RL5C4XX_CMD_SHIFT 4
117*4882a593Smuzhiyun #define RL5C4XX_HOLD_MASK 0x1c00
118*4882a593Smuzhiyun #define RL5C4XX_HOLD_SHIFT 10
119*4882a593Smuzhiyun #define RL5C4XX_MISC_CONTROL 0x2F /* 8 bit */
120*4882a593Smuzhiyun #define RL5C4XX_ZV_ENABLE 0x08
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Misc Control 3 Register */
123*4882a593Smuzhiyun #define RL5C4XX_MISC3 0x00A2 /* 16 bit */
124*4882a593Smuzhiyun #define RL5C47X_MISC3_CB_CLKRUN_DIS BIT(1)
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun #ifdef __YENTA_H
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define rl_misc(socket) ((socket)->private[0])
129*4882a593Smuzhiyun #define rl_ctl(socket) ((socket)->private[1])
130*4882a593Smuzhiyun #define rl_io(socket) ((socket)->private[2])
131*4882a593Smuzhiyun #define rl_mem(socket) ((socket)->private[3])
132*4882a593Smuzhiyun #define rl_config(socket) ((socket)->private[4])
133*4882a593Smuzhiyun
ricoh_zoom_video(struct pcmcia_socket * sock,int onoff)134*4882a593Smuzhiyun static void ricoh_zoom_video(struct pcmcia_socket *sock, int onoff)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun u8 reg;
137*4882a593Smuzhiyun struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun reg = config_readb(socket, RL5C4XX_MISC_CONTROL);
140*4882a593Smuzhiyun if (onoff)
141*4882a593Smuzhiyun /* Zoom zoom, we will all go together, zoom zoom, zoom zoom */
142*4882a593Smuzhiyun reg |= RL5C4XX_ZV_ENABLE;
143*4882a593Smuzhiyun else
144*4882a593Smuzhiyun reg &= ~RL5C4XX_ZV_ENABLE;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun config_writeb(socket, RL5C4XX_MISC_CONTROL, reg);
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
ricoh_set_zv(struct yenta_socket * socket)149*4882a593Smuzhiyun static void ricoh_set_zv(struct yenta_socket *socket)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun if(socket->dev->vendor == PCI_VENDOR_ID_RICOH)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun switch(socket->dev->device)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun /* There may be more .. */
156*4882a593Smuzhiyun case PCI_DEVICE_ID_RICOH_RL5C478:
157*4882a593Smuzhiyun socket->socket.zoom_video = ricoh_zoom_video;
158*4882a593Smuzhiyun break;
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun
ricoh_set_clkrun(struct yenta_socket * socket,bool quiet)163*4882a593Smuzhiyun static void ricoh_set_clkrun(struct yenta_socket *socket, bool quiet)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun u16 misc3;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /*
168*4882a593Smuzhiyun * RL5C475II likely has this setting, too, however no datasheet
169*4882a593Smuzhiyun * is publicly available for this chip
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun if (socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C476 &&
172*4882a593Smuzhiyun socket->dev->device != PCI_DEVICE_ID_RICOH_RL5C478)
173*4882a593Smuzhiyun return;
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun if (socket->dev->revision < 0x80)
176*4882a593Smuzhiyun return;
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun misc3 = config_readw(socket, RL5C4XX_MISC3);
179*4882a593Smuzhiyun if (misc3 & RL5C47X_MISC3_CB_CLKRUN_DIS) {
180*4882a593Smuzhiyun if (!quiet)
181*4882a593Smuzhiyun dev_dbg(&socket->dev->dev,
182*4882a593Smuzhiyun "CLKRUN feature already disabled\n");
183*4882a593Smuzhiyun } else if (disable_clkrun) {
184*4882a593Smuzhiyun if (!quiet)
185*4882a593Smuzhiyun dev_info(&socket->dev->dev,
186*4882a593Smuzhiyun "Disabling CLKRUN feature\n");
187*4882a593Smuzhiyun misc3 |= RL5C47X_MISC3_CB_CLKRUN_DIS;
188*4882a593Smuzhiyun config_writew(socket, RL5C4XX_MISC3, misc3);
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun
ricoh_save_state(struct yenta_socket * socket)192*4882a593Smuzhiyun static void ricoh_save_state(struct yenta_socket *socket)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun rl_misc(socket) = config_readw(socket, RL5C4XX_MISC);
195*4882a593Smuzhiyun rl_ctl(socket) = config_readw(socket, RL5C4XX_16BIT_CTL);
196*4882a593Smuzhiyun rl_io(socket) = config_readw(socket, RL5C4XX_16BIT_IO_0);
197*4882a593Smuzhiyun rl_mem(socket) = config_readw(socket, RL5C4XX_16BIT_MEM_0);
198*4882a593Smuzhiyun rl_config(socket) = config_readw(socket, RL5C4XX_CONFIG);
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
ricoh_restore_state(struct yenta_socket * socket)201*4882a593Smuzhiyun static void ricoh_restore_state(struct yenta_socket *socket)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun config_writew(socket, RL5C4XX_MISC, rl_misc(socket));
204*4882a593Smuzhiyun config_writew(socket, RL5C4XX_16BIT_CTL, rl_ctl(socket));
205*4882a593Smuzhiyun config_writew(socket, RL5C4XX_16BIT_IO_0, rl_io(socket));
206*4882a593Smuzhiyun config_writew(socket, RL5C4XX_16BIT_MEM_0, rl_mem(socket));
207*4882a593Smuzhiyun config_writew(socket, RL5C4XX_CONFIG, rl_config(socket));
208*4882a593Smuzhiyun ricoh_set_clkrun(socket, true);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun /*
213*4882a593Smuzhiyun * Magic Ricoh initialization code..
214*4882a593Smuzhiyun */
ricoh_override(struct yenta_socket * socket)215*4882a593Smuzhiyun static int ricoh_override(struct yenta_socket *socket)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun u16 config, ctl;
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun config = config_readw(socket, RL5C4XX_CONFIG);
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* Set the default timings, don't trust the original values */
222*4882a593Smuzhiyun ctl = RL5C4XX_16CTL_IO_TIMING | RL5C4XX_16CTL_MEM_TIMING;
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun if(socket->dev->device < PCI_DEVICE_ID_RICOH_RL5C475) {
225*4882a593Smuzhiyun ctl |= RL5C46X_16CTL_LEVEL_1 | RL5C46X_16CTL_LEVEL_2;
226*4882a593Smuzhiyun } else {
227*4882a593Smuzhiyun config |= RL5C4XX_CONFIG_PREFETCH;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun config_writew(socket, RL5C4XX_16BIT_CTL, ctl);
231*4882a593Smuzhiyun config_writew(socket, RL5C4XX_CONFIG, config);
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun ricoh_set_zv(socket);
234*4882a593Smuzhiyun ricoh_set_clkrun(socket, false);
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun return 0;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun #endif /* CONFIG_CARDBUS */
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun #endif /* _LINUX_RICOH_H */
242