| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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> | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 18 | #include <linux/module.h> | 
|  | 19 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/amigayle.h> | 
|  | 21 | #include <asm/amipcmcia.h> | 
|  | 22 |  | 
|  | 23 | /* gayle config byte for program voltage and access speed */ | 
|  | 24 | static unsigned char cfg_byte = GAYLE_CFG_0V|GAYLE_CFG_150NS; | 
|  | 25 |  | 
|  | 26 | void pcmcia_reset(void) | 
|  | 27 | { | 
|  | 28 | unsigned long reset_start_time = jiffies; | 
|  | 29 | unsigned char b; | 
|  | 30 |  | 
|  | 31 | gayle_reset = 0x00; | 
|  | 32 | while (time_before(jiffies, reset_start_time + 1*HZ/100)); | 
|  | 33 | b = gayle_reset; | 
|  | 34 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 35 | EXPORT_SYMBOL(pcmcia_reset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 |  | 
|  | 37 |  | 
|  | 38 | /* copy a tuple, including tuple header. return nb bytes copied */ | 
| Simon Arlott | 0c79cf6 | 2007-10-20 01:20:32 +0200 | [diff] [blame] | 39 | /* be careful as this may trigger a GAYLE_IRQ_WR interrupt ! */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 |  | 
|  | 41 | int pcmcia_copy_tuple(unsigned char tuple_id, void *tuple, int max_len) | 
|  | 42 | { | 
|  | 43 | unsigned char id, *dest; | 
|  | 44 | int cnt, pos, len; | 
|  | 45 |  | 
|  | 46 | dest = tuple; | 
|  | 47 | pos = 0; | 
|  | 48 |  | 
|  | 49 | id = gayle_attribute[pos]; | 
|  | 50 |  | 
|  | 51 | while((id != CISTPL_END) && (pos < 0x10000)) { | 
|  | 52 | len = (int)gayle_attribute[pos+2] + 2; | 
|  | 53 | if (id == tuple_id) { | 
|  | 54 | len = (len > max_len)?max_len:len; | 
|  | 55 | for (cnt = 0; cnt < len; cnt++) { | 
|  | 56 | *dest++ = gayle_attribute[pos+(cnt<<1)]; | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | return len; | 
|  | 60 | } | 
|  | 61 | pos += len<<1; | 
|  | 62 | id = gayle_attribute[pos]; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | return 0; | 
|  | 66 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 67 | EXPORT_SYMBOL(pcmcia_copy_tuple); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
|  | 69 | void pcmcia_program_voltage(int voltage) | 
|  | 70 | { | 
|  | 71 | unsigned char v; | 
|  | 72 |  | 
|  | 73 | switch (voltage) { | 
|  | 74 | case PCMCIA_0V: | 
|  | 75 | v = GAYLE_CFG_0V; | 
|  | 76 | break; | 
|  | 77 | case PCMCIA_5V: | 
|  | 78 | v = GAYLE_CFG_5V; | 
|  | 79 | break; | 
|  | 80 | case PCMCIA_12V: | 
|  | 81 | v = GAYLE_CFG_12V; | 
|  | 82 | break; | 
|  | 83 | default: | 
|  | 84 | v = GAYLE_CFG_0V; | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | cfg_byte = (cfg_byte & 0xfc) | v; | 
|  | 88 | gayle.config = cfg_byte; | 
|  | 89 |  | 
|  | 90 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 91 | EXPORT_SYMBOL(pcmcia_program_voltage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | void pcmcia_access_speed(int speed) | 
|  | 94 | { | 
|  | 95 | unsigned char s; | 
|  | 96 |  | 
|  | 97 | if (speed <= PCMCIA_SPEED_100NS) | 
|  | 98 | s = GAYLE_CFG_100NS; | 
|  | 99 | else if (speed <= PCMCIA_SPEED_150NS) | 
|  | 100 | s = GAYLE_CFG_150NS; | 
|  | 101 | else if (speed <= PCMCIA_SPEED_250NS) | 
|  | 102 | s = GAYLE_CFG_250NS; | 
|  | 103 | else | 
|  | 104 | s = GAYLE_CFG_720NS; | 
|  | 105 |  | 
|  | 106 | cfg_byte = (cfg_byte & 0xf3) | s; | 
|  | 107 | gayle.config = cfg_byte; | 
|  | 108 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 109 | EXPORT_SYMBOL(pcmcia_access_speed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  | 
|  | 111 | void pcmcia_write_enable(void) | 
|  | 112 | { | 
|  | 113 | gayle.cardstatus = GAYLE_CS_WR|GAYLE_CS_DA; | 
|  | 114 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 115 | EXPORT_SYMBOL(pcmcia_write_enable); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
|  | 117 | void pcmcia_write_disable(void) | 
|  | 118 | { | 
|  | 119 | gayle.cardstatus = 0; | 
|  | 120 | } | 
| Adrian Bunk | 8b169fa | 2008-02-04 22:30:25 -0800 | [diff] [blame] | 121 | EXPORT_SYMBOL(pcmcia_write_disable); | 
|  | 122 |  |