blob: 9d1761b419e5f56a4ecc9d7b603fa76a12c8f87e [file] [log] [blame]
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Feltzing257d17d2002-04-20 23:18:14 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +000021#include "stdbool.h"
Linus Nielsen Feltzingf1e9de52002-07-29 09:34:44 +000022#include "config.h"
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +000023#include "sh7034.h"
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000024#include "i2c.h"
25#include "debug.h"
26#include "mas.h"
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +000027#include "kernel.h"
Jörg Hohensohn75bab492003-11-06 01:34:50 +000028#include "system.h"
Jens Arnold8c3f0682006-11-12 14:17:49 +000029#include "hwcompat.h"
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000030
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000031static int mas_devread(unsigned long *dest, int len);
32
Linus Nielsen Feltzing0e085992002-05-16 21:12:57 +000033int mas_default_read(unsigned short *buf)
Linus Nielsen Feltzing0bd77a62002-05-03 13:12:21 +000034{
Linus Nielsen Feltzing0e085992002-05-16 21:12:57 +000035 unsigned char *dest = (unsigned char *)buf;
36 int ret = 0;
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000037
38 i2c_begin();
Linus Nielsen Feltzing0e085992002-05-16 21:12:57 +000039
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 Feltzinge1cb0542002-06-24 12:35:37 +000062 i2c_end();
Linus Nielsen Feltzing0e085992002-05-16 21:12:57 +000063 return ret;
Linus Nielsen Feltzing0bd77a62002-05-03 13:12:21 +000064}
65
66int mas_run(unsigned short address)
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000067{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000068 int ret = 0;
69 unsigned char buf[3];
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000070
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000071 i2c_begin();
72
73 buf[0] = MAS_DATA_WRITE;
Linus Nielsen Feltzing5c682fb2002-07-28 11:45:52 +000074 buf[1] = address >> 8;
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000075 buf[2] = address & 0xff;
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000076
77 /* send run command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000078 if (i2c_write(MAS_DEV_WRITE,buf,3))
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000079 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000080 ret = -1;
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000081 }
82
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000083 i2c_end();
84 return ret;
Linus Nielsen Feltzing611a7c52002-05-02 23:01:10 +000085}
86
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000087/* note: 'len' is number of 32-bit words, not number of bytes! */
88int mas_readmem(int bank, int addr, unsigned long* dest, int len)
89{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000090 int ret = 0;
91 unsigned char buf[7];
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +000092
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000093 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 Feltzing257d17d2002-04-20 23:18:14 +0000102
103 /* send read command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000104 if (i2c_write(MAS_DEV_WRITE,buf,7))
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000105 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000106 ret = -1;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000107 }
108
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000109 ret = mas_devread(dest, len);
110
111 i2c_end();
112 return ret;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000113}
114
115/* note: 'len' is number of 32-bit words, not number of bytes! */
Jens Arnold0ceaa5e2004-08-17 01:45:48 +0000116int mas_writemem(int bank, int addr, const unsigned long* src, int len)
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000117{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000118 int ret = 0;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000119 int i, j;
120 unsigned char buf[60];
Jens Arnold0ceaa5e2004-08-17 01:45:48 +0000121 const unsigned char* ptr = (const unsigned char*)src;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000122
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000123 i2c_begin();
124
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000125 i=0;
126 buf[i++] = MAS_DATA_WRITE;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000127 buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000128 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 Arnoldd6c05452005-08-29 21:15:27 +0000136#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000137 buf[i++] = 0;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000138 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 Feltzing257d17d2002-04-20 23:18:14 +0000147 j += 4;
148 }
149
150 /* send write command */
151 if (i2c_write(MAS_DEV_WRITE,buf,i))
152 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000153 ret = -1;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000154 }
155
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000156 i2c_end();
157 return ret;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000158}
159
160int mas_readreg(int reg)
161{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000162 int ret = 0;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000163 unsigned char buf[16];
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000164 unsigned long value;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000165
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000166 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 Feltzing257d17d2002-04-20 23:18:14 +0000171
172 /* send read command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000173 if (i2c_write(MAS_DEV_WRITE,buf,3))
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000174 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000175 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 Feltzing257d17d2002-04-20 23:18:14 +0000187 }
188
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000189 i2c_end();
190 return ret;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000191}
192
Linus Nielsen Feltzing0e085992002-05-16 21:12:57 +0000193int mas_writereg(int reg, unsigned int val)
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000194{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000195 int ret = 0;
196 unsigned char buf[5];
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000197
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000198 i2c_begin();
199
200 buf[0] = MAS_DATA_WRITE;
201 buf[1] = MAS_CMD_WRITE_REG | (reg >> 4);
Jens Arnold6a5ef8e2006-03-24 07:57:55 +0000202#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 Feltzinge1cb0542002-06-24 12:35:37 +0000207 buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f);
208 buf[3] = (val >> 12) & 0xff;
209 buf[4] = (val >> 4) & 0xff;
Jens Arnold6a5ef8e2006-03-24 07:57:55 +0000210#endif
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000211
212 /* send write command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000213 if (i2c_write(MAS_DEV_WRITE,buf,5))
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000214 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000215 ret = -1;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000216 }
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000217
218 i2c_end();
219 return ret;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000220}
221
222/* note: 'len' is number of 32-bit words, not number of bytes! */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000223static int mas_devread(unsigned long *dest, int len)
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000224{
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000225 int ret = 0;
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000226 unsigned char* ptr = (unsigned char*)dest;
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000227 int i;
228
229 /* handle read-back */
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000230 /* Remember, the MAS values are only 20 bits, so we set
231 the upper 12 bits to 0 */
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000232 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 Arnoldd6c05452005-08-29 21:15:27 +0000242#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000243 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 Feltzing257d17d2002-04-20 23:18:14 +0000247 if(len)
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000248 ptr[i*4+3] = i2c_inb(0);
Linus Nielsen Feltzing257d17d2002-04-20 23:18:14 +0000249 else
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000250 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 Feltzing257d17d2002-04-20 23:18:14 +0000260 }
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 Feltzing9c0e5d82002-06-19 12:03:41 +0000275
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +0000276void mas_reset(void)
277{
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000278 or_b(0x01, &PAIORH);
Jens Arnolddbd11c92004-11-22 01:54:26 +0000279
Jens Arnoldd6c05452005-08-29 21:15:27 +0000280#if CONFIG_CODEC == MAS3507D
Jens Arnoldc42a1a02005-05-07 22:29:35 +0000281 /* 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 Arnolddbd11c92004-11-22 01:54:26 +0000286 and_b(~0x01, &PADRH);
287 sleep(HZ/100);
288 or_b(0x01, &PADRH);
289 sleep(HZ/5);
Jens Arnoldd6c05452005-08-29 21:15:27 +0000290#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Jens Arnold8636e692007-04-11 23:51:00 +0000291 if (HW_MASK & ATA_ADDRESS_200)
Jens Arnold8c3f0682006-11-12 14:17:49 +0000292 {
293 and_b(~0x01, &PADRH);
294 sleep(HZ/100);
295 or_b(0x01, &PADRH);
296 sleep(HZ/5);
297 }
298 else
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +0000299 {
300 /* Older recorder models don't invert the POR signal */
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000301 or_b(0x01, &PADRH);
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +0000302 sleep(HZ/100);
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000303 and_b(~0x01, &PADRH);
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +0000304 sleep(HZ/5);
305 }
Jens Arnolddbd11c92004-11-22 01:54:26 +0000306#endif
Linus Nielsen Feltzingd1d63962002-06-26 12:39:49 +0000307}
308
Jens Arnoldd6c05452005-08-29 21:15:27 +0000309#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000310int mas_direct_config_read(unsigned char reg)
311{
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000312 int ret = 0;
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000313 unsigned char tmp[2];
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000314
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000315 i2c_begin();
316
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000317 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 Feltzinge1cb0542002-06-24 12:35:37 +0000340 i2c_end();
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000341 return ret;
342}
343
344int mas_direct_config_write(unsigned char reg, unsigned int val)
345{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000346 int ret = 0;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000347 unsigned char buf[3];
348
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000349 i2c_begin();
350
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000351 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 Feltzinge1cb0542002-06-24 12:35:37 +0000358 ret = -1;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000359 }
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000360
361 i2c_end();
Linus Nielsen Feltzing417685f2002-06-25 14:12:37 +0000362 return ret;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000363}
364
365int mas_codec_writereg(int reg, unsigned int val)
366{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000367 int ret = 0;
368 unsigned char buf[5];
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000369
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000370 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 Feltzing9c0e5d82002-06-19 12:03:41 +0000377
378 /* send write command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000379 if (i2c_write(MAS_DEV_WRITE,buf,5))
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000380 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000381 ret = -1;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000382 }
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000383
384 i2c_end();
385 return ret;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000386}
387
388int mas_codec_readreg(int reg)
389{
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000390 int ret = 0;
391 unsigned char buf[16];
392 unsigned char tmp[2];
393
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000394 i2c_begin();
395
396 buf[0] = MAS_CODEC_WRITE;
397 buf[1] = (reg >> 8) & 0xff;
398 buf[2] = reg & 0xff;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000399
400 /* send read command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000401 if (i2c_write(MAS_DEV_WRITE,buf,3))
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000402 {
Linus Nielsen Feltzing63f0b5e2002-11-24 11:47:24 +0000403 ret = -1;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000404 }
Linus Nielsen Feltzing63f0b5e2002-11-24 11:47:24 +0000405 else
406 {
407 i2c_start();
408 i2c_outb(MAS_DEV_WRITE);
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000409 if (i2c_getack()) {
Linus Nielsen Feltzing63f0b5e2002-11-24 11:47:24 +0000410 i2c_outb(MAS_CODEC_READ);
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000411 if (i2c_getack()) {
Linus Nielsen Feltzing63f0b5e2002-11-24 11:47:24 +0000412 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 Feltzing9c0e5d82002-06-19 12:03:41 +0000421 }
422 else
423 ret = -3;
424 }
425 else
426 ret = -2;
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000427
Linus Nielsen Feltzing63f0b5e2002-11-24 11:47:24 +0000428 i2c_stop();
429 }
430
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +0000431 i2c_end();
Linus Nielsen Feltzing9c0e5d82002-06-19 12:03:41 +0000432 return ret;
433}
Linus Nielsen Feltzingd5bb9a42002-11-20 22:22:13 +0000434
435unsigned 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 Feltzing9c0e5d82002-06-19 12:03:41 +0000468#endif