Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 21 | #include "stdbool.h" |
Linus Nielsen Feltzing | f1e9de5 | 2002-07-29 09:34:44 +0000 | [diff] [blame] | 22 | #include "config.h" |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 23 | #include "sh7034.h" |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 24 | #include "i2c.h" |
| 25 | #include "debug.h" |
| 26 | #include "mas.h" |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 27 | #include "kernel.h" |
Jörg Hohensohn | 75bab49 | 2003-11-06 01:34:50 +0000 | [diff] [blame] | 28 | #include "system.h" |
Jens Arnold | 8c3f068 | 2006-11-12 14:17:49 +0000 | [diff] [blame] | 29 | #include "hwcompat.h" |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 30 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 31 | static int mas_devread(unsigned long *dest, int len); |
| 32 | |
Linus Nielsen Feltzing | 0e08599 | 2002-05-16 21:12:57 +0000 | [diff] [blame] | 33 | int mas_default_read(unsigned short *buf) |
Linus Nielsen Feltzing | 0bd77a6 | 2002-05-03 13:12:21 +0000 | [diff] [blame] | 34 | { |
Linus Nielsen Feltzing | 0e08599 | 2002-05-16 21:12:57 +0000 | [diff] [blame] | 35 | unsigned char *dest = (unsigned char *)buf; |
| 36 | int ret = 0; |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 37 | |
| 38 | i2c_begin(); |
Linus Nielsen Feltzing | 0e08599 | 2002-05-16 21:12:57 +0000 | [diff] [blame] | 39 | |
| 40 | i2c_start(); |
| 41 | i2c_outb(MAS_DEV_WRITE); |
| 42 | if (i2c_getack()) { |
| 43 | i2c_outb(MAS_DATA_READ); |
| 44 | if (i2c_getack()) { |
| 45 | i2c_start(); |
| 46 | i2c_outb(MAS_DEV_READ); |
| 47 | if (i2c_getack()) { |
| 48 | dest[0] = i2c_inb(0); |
| 49 | dest[1] = i2c_inb(1); |
| 50 | } |
| 51 | else |
| 52 | ret = -3; |
| 53 | } |
| 54 | else |
| 55 | ret = -2; |
| 56 | } |
| 57 | else |
| 58 | ret = -1; |
| 59 | |
| 60 | i2c_stop(); |
| 61 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 62 | i2c_end(); |
Linus Nielsen Feltzing | 0e08599 | 2002-05-16 21:12:57 +0000 | [diff] [blame] | 63 | return ret; |
Linus Nielsen Feltzing | 0bd77a6 | 2002-05-03 13:12:21 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | int mas_run(unsigned short address) |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 67 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 68 | int ret = 0; |
| 69 | unsigned char buf[3]; |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 70 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 71 | i2c_begin(); |
| 72 | |
| 73 | buf[0] = MAS_DATA_WRITE; |
Linus Nielsen Feltzing | 5c682fb | 2002-07-28 11:45:52 +0000 | [diff] [blame] | 74 | buf[1] = address >> 8; |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 75 | buf[2] = address & 0xff; |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 76 | |
| 77 | /* send run command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 78 | if (i2c_write(MAS_DEV_WRITE,buf,3)) |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 79 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 80 | ret = -1; |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 83 | i2c_end(); |
| 84 | return ret; |
Linus Nielsen Feltzing | 611a7c5 | 2002-05-02 23:01:10 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 87 | /* note: 'len' is number of 32-bit words, not number of bytes! */ |
| 88 | int mas_readmem(int bank, int addr, unsigned long* dest, int len) |
| 89 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 90 | int ret = 0; |
| 91 | unsigned char buf[7]; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 92 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 93 | i2c_begin(); |
| 94 | |
| 95 | buf[0] = MAS_DATA_WRITE; |
| 96 | buf[1] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM; |
| 97 | buf[2] = 0x00; |
| 98 | buf[3] = (len & 0xff00) >> 8; |
| 99 | buf[4] = len & 0xff; |
| 100 | buf[5] = (addr & 0xff00) >> 8; |
| 101 | buf[6] = addr & 0xff; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 102 | |
| 103 | /* send read command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 104 | if (i2c_write(MAS_DEV_WRITE,buf,7)) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 105 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 106 | ret = -1; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 109 | ret = mas_devread(dest, len); |
| 110 | |
| 111 | i2c_end(); |
| 112 | return ret; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* note: 'len' is number of 32-bit words, not number of bytes! */ |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 116 | int mas_writemem(int bank, int addr, const unsigned long* src, int len) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 117 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 118 | int ret = 0; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 119 | int i, j; |
| 120 | unsigned char buf[60]; |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 121 | const unsigned char* ptr = (const unsigned char*)src; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 122 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 123 | i2c_begin(); |
| 124 | |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 125 | i=0; |
| 126 | buf[i++] = MAS_DATA_WRITE; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 127 | buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 128 | buf[i++] = 0x00; |
| 129 | buf[i++] = (len & 0xff00) >> 8; |
| 130 | buf[i++] = len & 0xff; |
| 131 | buf[i++] = (addr & 0xff00) >> 8; |
| 132 | buf[i++] = addr & 0xff; |
| 133 | |
| 134 | j = 0; |
| 135 | while(len--) { |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 136 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 137 | buf[i++] = 0; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 138 | buf[i++] = ptr[j+1]; |
| 139 | buf[i++] = ptr[j+2]; |
| 140 | buf[i++] = ptr[j+3]; |
| 141 | #else |
| 142 | buf[i++] = ptr[j+2]; |
| 143 | buf[i++] = ptr[j+3]; |
| 144 | buf[i++] = 0; |
| 145 | buf[i++] = ptr[j+1]; |
| 146 | #endif |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 147 | j += 4; |
| 148 | } |
| 149 | |
| 150 | /* send write command */ |
| 151 | if (i2c_write(MAS_DEV_WRITE,buf,i)) |
| 152 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 153 | ret = -1; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 156 | i2c_end(); |
| 157 | return ret; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | int mas_readreg(int reg) |
| 161 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 162 | int ret = 0; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 163 | unsigned char buf[16]; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 164 | unsigned long value; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 165 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 166 | i2c_begin(); |
| 167 | |
| 168 | buf[0] = MAS_DATA_WRITE; |
| 169 | buf[1] = MAS_CMD_READ_REG | (reg >> 4); |
| 170 | buf[2] = (reg & 0x0f) << 4; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 171 | |
| 172 | /* send read command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 173 | if (i2c_write(MAS_DEV_WRITE,buf,3)) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 174 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 175 | ret = -1; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | if(mas_devread(&value, 1)) |
| 180 | { |
| 181 | ret = -2; |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | ret = value; |
| 186 | } |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 189 | i2c_end(); |
| 190 | return ret; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Linus Nielsen Feltzing | 0e08599 | 2002-05-16 21:12:57 +0000 | [diff] [blame] | 193 | int mas_writereg(int reg, unsigned int val) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 194 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 195 | int ret = 0; |
| 196 | unsigned char buf[5]; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 197 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 198 | i2c_begin(); |
| 199 | |
| 200 | buf[0] = MAS_DATA_WRITE; |
| 201 | buf[1] = MAS_CMD_WRITE_REG | (reg >> 4); |
Jens Arnold | 6a5ef8e | 2006-03-24 07:57:55 +0000 | [diff] [blame] | 202 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 203 | buf[2] = ((reg & 0x0f) << 4) | (val >> 16 & 0x0f); |
| 204 | buf[3] = (val >> 8) & 0xff; |
| 205 | buf[4] = val & 0xff; |
| 206 | #else |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 207 | buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f); |
| 208 | buf[3] = (val >> 12) & 0xff; |
| 209 | buf[4] = (val >> 4) & 0xff; |
Jens Arnold | 6a5ef8e | 2006-03-24 07:57:55 +0000 | [diff] [blame] | 210 | #endif |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 211 | |
| 212 | /* send write command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 213 | if (i2c_write(MAS_DEV_WRITE,buf,5)) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 214 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 215 | ret = -1; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 216 | } |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 217 | |
| 218 | i2c_end(); |
| 219 | return ret; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* note: 'len' is number of 32-bit words, not number of bytes! */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 223 | static int mas_devread(unsigned long *dest, int len) |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 224 | { |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 225 | int ret = 0; |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 226 | unsigned char* ptr = (unsigned char*)dest; |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 227 | int i; |
| 228 | |
| 229 | /* handle read-back */ |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 230 | /* Remember, the MAS values are only 20 bits, so we set |
| 231 | the upper 12 bits to 0 */ |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 232 | i2c_start(); |
| 233 | i2c_outb(MAS_DEV_WRITE); |
| 234 | if (i2c_getack()) { |
| 235 | i2c_outb(MAS_DATA_READ); |
| 236 | if (i2c_getack()) { |
| 237 | i2c_start(); |
| 238 | i2c_outb(MAS_DEV_READ); |
| 239 | if (i2c_getack()) { |
| 240 | for (i=0;len;i++) { |
| 241 | len--; |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 242 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 243 | i2c_inb(0); /* Dummy read */ |
| 244 | ptr[i*4+0] = 0; |
| 245 | ptr[i*4+1] = i2c_inb(0) & 0x0f; |
| 246 | ptr[i*4+2] = i2c_inb(0); |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 247 | if(len) |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 248 | ptr[i*4+3] = i2c_inb(0); |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 249 | else |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 250 | ptr[i*4+3] = i2c_inb(1); /* NAK the last byte */ |
| 251 | #else |
| 252 | ptr[i*4+2] = i2c_inb(0); |
| 253 | ptr[i*4+3] = i2c_inb(0); |
| 254 | ptr[i*4+0] = i2c_inb(0); |
| 255 | if(len) |
| 256 | ptr[i*4+1] = i2c_inb(0); |
| 257 | else |
| 258 | ptr[i*4+1] = i2c_inb(1); /* NAK the last byte */ |
| 259 | #endif |
Linus Nielsen Feltzing | 257d17d | 2002-04-20 23:18:14 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | else |
| 263 | ret = -3; |
| 264 | } |
| 265 | else |
| 266 | ret = -2; |
| 267 | } |
| 268 | else |
| 269 | ret = -1; |
| 270 | |
| 271 | i2c_stop(); |
| 272 | |
| 273 | return ret; |
| 274 | } |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 275 | |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 276 | void mas_reset(void) |
| 277 | { |
Linus Nielsen Feltzing | bef7ab0 | 2003-11-07 12:15:24 +0000 | [diff] [blame] | 278 | or_b(0x01, &PAIORH); |
Jens Arnold | dbd11c9 | 2004-11-22 01:54:26 +0000 | [diff] [blame] | 279 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 280 | #if CONFIG_CODEC == MAS3507D |
Jens Arnold | c42a1a0 | 2005-05-07 22:29:35 +0000 | [diff] [blame] | 281 | /* PB5 is "MAS enable". make it GPIO output and high */ |
| 282 | PBCR2 &= ~0x0c00; |
| 283 | or_b(0x20, &PBIORL); |
| 284 | or_b(0x20, &PBDRL); |
| 285 | |
Jens Arnold | dbd11c9 | 2004-11-22 01:54:26 +0000 | [diff] [blame] | 286 | and_b(~0x01, &PADRH); |
| 287 | sleep(HZ/100); |
| 288 | or_b(0x01, &PADRH); |
| 289 | sleep(HZ/5); |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 290 | #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Jens Arnold | 8636e69 | 2007-04-11 23:51:00 +0000 | [diff] [blame] | 291 | if (HW_MASK & ATA_ADDRESS_200) |
Jens Arnold | 8c3f068 | 2006-11-12 14:17:49 +0000 | [diff] [blame] | 292 | { |
| 293 | and_b(~0x01, &PADRH); |
| 294 | sleep(HZ/100); |
| 295 | or_b(0x01, &PADRH); |
| 296 | sleep(HZ/5); |
| 297 | } |
| 298 | else |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 299 | { |
| 300 | /* Older recorder models don't invert the POR signal */ |
Linus Nielsen Feltzing | bef7ab0 | 2003-11-07 12:15:24 +0000 | [diff] [blame] | 301 | or_b(0x01, &PADRH); |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 302 | sleep(HZ/100); |
Linus Nielsen Feltzing | bef7ab0 | 2003-11-07 12:15:24 +0000 | [diff] [blame] | 303 | and_b(~0x01, &PADRH); |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 304 | sleep(HZ/5); |
| 305 | } |
Jens Arnold | dbd11c9 | 2004-11-22 01:54:26 +0000 | [diff] [blame] | 306 | #endif |
Linus Nielsen Feltzing | d1d6396 | 2002-06-26 12:39:49 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 309 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 310 | int mas_direct_config_read(unsigned char reg) |
| 311 | { |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 312 | int ret = 0; |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 313 | unsigned char tmp[2]; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 314 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 315 | i2c_begin(); |
| 316 | |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 317 | i2c_start(); |
| 318 | i2c_outb(MAS_DEV_WRITE); |
| 319 | if (i2c_getack()) { |
| 320 | i2c_outb(reg); |
| 321 | if (i2c_getack()) { |
| 322 | i2c_start(); |
| 323 | i2c_outb(MAS_DEV_READ); |
| 324 | if (i2c_getack()) { |
| 325 | tmp[0] = i2c_inb(0); |
| 326 | tmp[1] = i2c_inb(1); /* NAK the last byte */ |
| 327 | ret = (tmp[0] << 8) | tmp[1]; |
| 328 | } |
| 329 | else |
| 330 | ret = -3; |
| 331 | } |
| 332 | else |
| 333 | ret = -2; |
| 334 | } |
| 335 | else |
| 336 | ret = -1; |
| 337 | |
| 338 | i2c_stop(); |
| 339 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 340 | i2c_end(); |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | int mas_direct_config_write(unsigned char reg, unsigned int val) |
| 345 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 346 | int ret = 0; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 347 | unsigned char buf[3]; |
| 348 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 349 | i2c_begin(); |
| 350 | |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 351 | buf[0] = reg; |
| 352 | buf[1] = (val >> 8) & 0xff; |
| 353 | buf[2] = val & 0xff; |
| 354 | |
| 355 | /* send write command */ |
| 356 | if (i2c_write(MAS_DEV_WRITE,buf,3)) |
| 357 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 358 | ret = -1; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 359 | } |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 360 | |
| 361 | i2c_end(); |
Linus Nielsen Feltzing | 417685f | 2002-06-25 14:12:37 +0000 | [diff] [blame] | 362 | return ret; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | int mas_codec_writereg(int reg, unsigned int val) |
| 366 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 367 | int ret = 0; |
| 368 | unsigned char buf[5]; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 369 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 370 | i2c_begin(); |
| 371 | |
| 372 | buf[0] = MAS_CODEC_WRITE; |
| 373 | buf[1] = (reg >> 8) & 0xff; |
| 374 | buf[2] = reg & 0xff; |
| 375 | buf[3] = (val >> 8) & 0xff; |
| 376 | buf[4] = val & 0xff; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 377 | |
| 378 | /* send write command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 379 | if (i2c_write(MAS_DEV_WRITE,buf,5)) |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 380 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 381 | ret = -1; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 382 | } |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 383 | |
| 384 | i2c_end(); |
| 385 | return ret; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | int mas_codec_readreg(int reg) |
| 389 | { |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 390 | int ret = 0; |
| 391 | unsigned char buf[16]; |
| 392 | unsigned char tmp[2]; |
| 393 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 394 | i2c_begin(); |
| 395 | |
| 396 | buf[0] = MAS_CODEC_WRITE; |
| 397 | buf[1] = (reg >> 8) & 0xff; |
| 398 | buf[2] = reg & 0xff; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 399 | |
| 400 | /* send read command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 401 | if (i2c_write(MAS_DEV_WRITE,buf,3)) |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 402 | { |
Linus Nielsen Feltzing | 63f0b5e | 2002-11-24 11:47:24 +0000 | [diff] [blame] | 403 | ret = -1; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 404 | } |
Linus Nielsen Feltzing | 63f0b5e | 2002-11-24 11:47:24 +0000 | [diff] [blame] | 405 | else |
| 406 | { |
| 407 | i2c_start(); |
| 408 | i2c_outb(MAS_DEV_WRITE); |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 409 | if (i2c_getack()) { |
Linus Nielsen Feltzing | 63f0b5e | 2002-11-24 11:47:24 +0000 | [diff] [blame] | 410 | i2c_outb(MAS_CODEC_READ); |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 411 | if (i2c_getack()) { |
Linus Nielsen Feltzing | 63f0b5e | 2002-11-24 11:47:24 +0000 | [diff] [blame] | 412 | i2c_start(); |
| 413 | i2c_outb(MAS_DEV_READ); |
| 414 | if (i2c_getack()) { |
| 415 | tmp[0] = i2c_inb(0); |
| 416 | tmp[1] = i2c_inb(1); /* NAK the last byte */ |
| 417 | ret = (tmp[0] << 8) | tmp[1]; |
| 418 | } |
| 419 | else |
| 420 | ret = -4; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 421 | } |
| 422 | else |
| 423 | ret = -3; |
| 424 | } |
| 425 | else |
| 426 | ret = -2; |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 427 | |
Linus Nielsen Feltzing | 63f0b5e | 2002-11-24 11:47:24 +0000 | [diff] [blame] | 428 | i2c_stop(); |
| 429 | } |
| 430 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 431 | i2c_end(); |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 432 | return ret; |
| 433 | } |
Linus Nielsen Feltzing | d5bb9a4 | 2002-11-20 22:22:13 +0000 | [diff] [blame] | 434 | |
| 435 | unsigned long mas_readver(void) |
| 436 | { |
| 437 | int ret = 0; |
| 438 | unsigned char buf[16]; |
| 439 | unsigned long value; |
| 440 | |
| 441 | i2c_begin(); |
| 442 | |
| 443 | buf[0] = MAS_DATA_WRITE; |
| 444 | buf[1] = MAS_CMD_READ_IC_VER; |
| 445 | buf[2] = 0; |
| 446 | |
| 447 | /* send read command */ |
| 448 | if (i2c_write(MAS_DEV_WRITE,buf,3)) |
| 449 | { |
| 450 | ret = -1; |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | if(mas_devread(&value, 1)) |
| 455 | { |
| 456 | ret = -2; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | ret = value; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | i2c_end(); |
| 465 | return ret; |
| 466 | } |
| 467 | |
Linus Nielsen Feltzing | 9c0e5d8 | 2002-06-19 12:03:41 +0000 | [diff] [blame] | 468 | #endif |