3 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Based on sc520cdp.c from rolo 1.6:
26 *----------------------------------------------------------------------
28 * Sysgo Real-Time Solutions GmbH
29 * Klein-Winternheim, Germany
30 *----------------------------------------------------------------------
39 #include <asm/ic/ali512x.h>
42 /* ALI M5123 Logical device numbers:
55 ************************************************************
56 * Some access primitives for the ALi chip: *
57 ************************************************************
60 static void ali_write(u8 index, u8 value)
62 /* write an arbirary register */
63 outb(index, ALI_INDEX);
64 outb(value, ALI_DATA);
68 static int ali_read(u8 index)
70 outb(index, ALI_INDEX);
76 outb(0x51, ALI_INDEX); \
83 /* Select a logical device */
84 #define ALI_SELDEV(dev) \
88 void ali512x_init(void)
92 ali_write(0x02, 0x01); /* soft reset */
93 ali_write(0x03, 0x03); /* disable access to CIOs */
94 ali_write(0x22, 0x00); /* disable direct powerdown */
95 ali_write(0x23, 0x00); /* disable auto powerdown */
96 ali_write(0x24, 0x00); /* IR 8 is active hi, pin26 is PDIR */
101 void ali512x_set_fdc(int enabled, u16 io, u8 irq, u8 dma_channel)
106 ali_write(0x30, enabled?1:0);
108 ali_write(0x60, io >> 8);
109 ali_write(0x61, io & 0xff);
110 ali_write(0x70, irq);
111 ali_write(0x74, dma_channel);
113 /* AT mode, no drive swap */
114 ali_write(0xf0, 0x08);
115 ali_write(0xf1, 0x00);
116 ali_write(0xf2, 0xff);
117 ali_write(0xf4, 0x00);
123 void ali512x_set_pp(int enabled, u16 io, u8 irq, u8 dma_channel)
128 ali_write(0x30, enabled?1:0);
130 ali_write(0x60, io >> 8);
131 ali_write(0x61, io & 0xff);
132 ali_write(0x70, irq);
133 ali_write(0x74, dma_channel);
135 /* mode: EPP 1.9, ECP FIFO threshold = 7, IRQ active low */
136 ali_write(0xf0, 0xbc);
137 /* 12 MHz, Burst DMA in ECP */
138 ali_write(0xf1, 0x05);
144 void ali512x_set_uart(int enabled, int index, u16 io, u8 irq)
147 ALI_SELDEV(index?5:4);
149 ali_write(0x30, enabled?1:0);
151 ali_write(0x60, io >> 8);
152 ali_write(0x61, io & 0xff);
153 ali_write(0x70, irq);
155 ali_write(0xf0, 0x00);
156 ali_write(0xf1, 0x00);
158 /* huh? write 0xf2 twice - a typo in rolo
159 * or some secret ali errata? Who knows?
162 ali_write(0xf2, 0x00);
164 ali_write(0xf2, 0x0c);
170 void ali512x_set_uart2_irda(int enabled)
175 ali_write(0xf1, enabled?0x48:0x00); /* fullduplex IrDa */
180 void ali512x_set_rtc(int enabled, u16 io, u8 irq)
185 ali_write(0x30, enabled?1:0);
187 ali_write(0x60, io >> 8);
188 ali_write(0x61, io & 0xff);
189 ali_write(0x70, irq);
191 ali_write(0xf0, 0x00);
196 void ali512x_set_kbc(int enabled, u8 kbc_irq, u8 mouse_irq)
201 ali_write(0x30, enabled?1:0);
203 ali_write(0x70, kbc_irq);
204 ali_write(0x72, mouse_irq);
206 ali_write(0xf0, 0x00);
214 * (This descripotsion is base on several incompete sources
215 * since I have not been able to obtain any datasheet for the device
216 * there may be some mis-understandings burried in here.
217 * -- Daniel daniel@omicron.se)
219 * There are 22 CIO pins numbered
224 * 20-24 are dedicated CIO pins, the other 17 are muliplexed with
228 * CIO Pin Function Decription
229 * =======================================================
230 * CIO10 IRQIN1 Interrupt input 1?
231 * CIO11 IRQIN2 Interrupt input 2?
232 * CIO12 IRRX IrDa Receive
233 * CIO13 IRTX IrDa Transmit
234 * CIO14 P21 KBC P21 fucntion
235 * CIO15 P20 KBC P21 fucntion
236 * CIO16 I2C_CLK I2C Clock
237 * CIO17 I2C_DAT I2C Data
246 * CIO30 KBC_CLK Keybaord Clock
247 * CIO31 CS0J General Chip Select decoder CS0J
248 * CIO32 CS1J General Chip Select decoder CS1J
249 * CIO33 ALT_KCLK Alternative Keyboard Clock
250 * CIO34 ALT_KDAT Alternative Keyboard Data
251 * CIO35 ALT_MCLK Alternative Mouse Clock
252 * CIO36 ALT_MDAT Alternative Mouse Data
253 * CIO37 ALT_KBC Alternative KBC select
255 * The CIO use an indirect address scheme.
257 * Reigster 3 in the SIO is used to select the index and data
258 * port addresses where the CIO I/O registers show up.
259 * The function selection registers are accessible under
262 * SIO reigster 3 (CIO Address Selection) bit definitions:
263 * bit 7 CIO index and data registers enabled
264 * bit 1-0 CIO indirect registers port address select
265 * 0 index = 0xE0 data = 0xE1
266 * 1 index = 0xE2 data = 0xE3
267 * 2 index = 0xE4 data = 0xE5
268 * 3 index = 0xEA data = 0xEB
270 * There are three CIO I/O register accessed via CIO index port and CIO data port
271 * 0x01 CIO 10-17 data
272 * 0x02 CIO 20-25 data (bits 7-6 unused)
273 * 0x03 CIO 30-37 data
276 * The pin function is accessed through normal
277 * SIO registers, each register have the same format:
280 * 0 Input/output 1=input
281 * 1 Polarity of signal 1=inverted
283 * 3 Function (normal or special) 1=special
314 #define ALI_CIO_PORT_SEL 0x83
315 #define ALI_CIO_INDEX 0xea
316 #define ALI_CIO_DATA 0xeb
318 void ali512x_set_cio(int enabled)
325 ali_write(0x3, ALI_CIO_PORT_SEL); /* Enable CIO data register */
327 ali_write(0x3, ALI_CIO_PORT_SEL & ~0x80);
332 ali_write(0x30, enabled?1:0);
334 /* set all pins to input to start with */
335 for (i=0xe0;i<0xee;i++) {
339 for (i=0xf5;i<0xfe;i++) {
347 void ali512x_cio_function(int pin, int special, int inv, int input)
352 /* valid pins are 10-17, 20-25 and 30-37 */
353 if (pin >= 10 && pin <= 17) {
355 } else if (pin >= 20 && pin <= 25) {
357 } else if (pin >= 30 && pin <= 37) {
380 ali_write(addr, data);
385 void ali512x_cio_out(int pin, int value)
395 outb(reg, ALI_CIO_INDEX); /* select I/O register */
396 data = inb(ALI_CIO_DATA);
402 outb(data, ALI_CIO_DATA);
405 int ali512x_cio_in(int pin)
411 /* valid pins are 10-17, 20-25 and 30-37 */
416 outb(reg, ALI_CIO_INDEX); /* select I/O register */
417 data = inb(ALI_CIO_DATA);