blob: fc57c6e72acf10d2bd30997f25cc222488f07813 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2** asm-m68k/pcmcia.c -- Amiga Linux PCMCIA support
3** most information was found by disassembling card.resource
4** I'm still looking for an official doc !
5**
6** Copyright 1997 by Alain Malek
7**
8** This file is subject to the terms and conditions of the GNU General Public
9** License. See the file COPYING in the main directory of this archive
10** for more details.
11**
12** Created: 12/10/97 by Alain Malek
13*/
14
15#include <linux/types.h>
16#include <linux/jiffies.h>
17#include <linux/timer.h>
18#include <asm/amigayle.h>
19#include <asm/amipcmcia.h>
20
21/* gayle config byte for program voltage and access speed */
22static unsigned char cfg_byte = GAYLE_CFG_0V|GAYLE_CFG_150NS;
23
24void pcmcia_reset(void)
25{
26 unsigned long reset_start_time = jiffies;
27 unsigned char b;
28
29 gayle_reset = 0x00;
30 while (time_before(jiffies, reset_start_time + 1*HZ/100));
31 b = gayle_reset;
32}
33
34
35/* copy a tuple, including tuple header. return nb bytes copied */
36/* be carefull as this may trigger a GAYLE_IRQ_WR interrupt ! */
37
38int pcmcia_copy_tuple(unsigned char tuple_id, void *tuple, int max_len)
39{
40 unsigned char id, *dest;
41 int cnt, pos, len;
42
43 dest = tuple;
44 pos = 0;
45
46 id = gayle_attribute[pos];
47
48 while((id != CISTPL_END) && (pos < 0x10000)) {
49 len = (int)gayle_attribute[pos+2] + 2;
50 if (id == tuple_id) {
51 len = (len > max_len)?max_len:len;
52 for (cnt = 0; cnt < len; cnt++) {
53 *dest++ = gayle_attribute[pos+(cnt<<1)];
54 }
55
56 return len;
57 }
58 pos += len<<1;
59 id = gayle_attribute[pos];
60 }
61
62 return 0;
63}
64
65void pcmcia_program_voltage(int voltage)
66{
67 unsigned char v;
68
69 switch (voltage) {
70 case PCMCIA_0V:
71 v = GAYLE_CFG_0V;
72 break;
73 case PCMCIA_5V:
74 v = GAYLE_CFG_5V;
75 break;
76 case PCMCIA_12V:
77 v = GAYLE_CFG_12V;
78 break;
79 default:
80 v = GAYLE_CFG_0V;
81 }
82
83 cfg_byte = (cfg_byte & 0xfc) | v;
84 gayle.config = cfg_byte;
85
86}
87
88void pcmcia_access_speed(int speed)
89{
90 unsigned char s;
91
92 if (speed <= PCMCIA_SPEED_100NS)
93 s = GAYLE_CFG_100NS;
94 else if (speed <= PCMCIA_SPEED_150NS)
95 s = GAYLE_CFG_150NS;
96 else if (speed <= PCMCIA_SPEED_250NS)
97 s = GAYLE_CFG_250NS;
98 else
99 s = GAYLE_CFG_720NS;
100
101 cfg_byte = (cfg_byte & 0xf3) | s;
102 gayle.config = cfg_byte;
103}
104
105void pcmcia_write_enable(void)
106{
107 gayle.cardstatus = GAYLE_CS_WR|GAYLE_CS_DA;
108}
109
110void pcmcia_write_disable(void)
111{
112 gayle.cardstatus = 0;
113}