summaryrefslogtreecommitdiff
path: root/drivers/media/dvb-frontends/drx39xyj/drx_dap_fasi.c
blob: 5bf4771a4c4959caf56b0fee5e5c30cba099737f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/*
  Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc.
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.
  * Neither the name of Trident Microsystems nor Hauppauge Computer Works
    nor the names of its contributors may be used to endorse or promote
	products derived from this software without specific prior written
	permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.
*/

/*******************************************************************************
* FILENAME: $Id: drx_dap_fasi.c,v 1.7 2009/12/28 14:36:21 carlo Exp $
*
* DESCRIPTION:
* Part of DRX driver.
* Data access protocol: Fast Access Sequential Interface (fasi)
* Fast access, because of short addressing format (16 instead of 32 bits addr)
* Sequential, because of I2C.
* These functions know how the chip's memory and registers are to be accessed,
* but nothing more.
*
* These functions should not need adapting to a new platform.
*
* USAGE:
* -
*
* NOTES:
*
*
*******************************************************************************/

#include "drx_dap_fasi.h"
#include "bsp_host.h"		/* for DRXBSP_HST_Memcpy() */

/*============================================================================*/

/* Function prototypes */
static DRXStatus_t DRXDAP_FASI_WriteBlock(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					  DRXaddr_t addr,	/* address of register/memory   */
					  u16 datasize,	/* size of data                 */
					  u8 *data,	/* data to send                 */
					  DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadBlock(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					 DRXaddr_t addr,	/* address of register/memory   */
					 u16 datasize,	/* size of data                 */
					 u8 *data,	/* data to send                 */
					 DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_WriteReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					 DRXaddr_t addr,	/* address of register          */
					 u8 data,	/* data to write                */
					 DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					DRXaddr_t addr,	/* address of register          */
					u8 *data,	/* buffer to receive data       */
					DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
						   DRXaddr_t waddr,	/* address of register          */
						   DRXaddr_t raddr,	/* address to read back from    */
						   u8 datain,	/* data to send                 */
						   u8 *dataout);	/* data to receive back         */

static DRXStatus_t DRXDAP_FASI_WriteReg16(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					  DRXaddr_t addr,	/* address of register          */
					  u16 data,	/* data to write                */
					  DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadReg16(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					 DRXaddr_t addr,	/* address of register          */
					 u16 *data,	/* buffer to receive data       */
					 DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg16(struct i2c_device_addr *devAddr,	/* address of I2C device        */
						    DRXaddr_t waddr,	/* address of register          */
						    DRXaddr_t raddr,	/* address to read back from    */
						    u16 datain,	/* data to send                 */
						    u16 *dataout);	/* data to receive back         */

static DRXStatus_t DRXDAP_FASI_WriteReg32(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					  DRXaddr_t addr,	/* address of register          */
					  u32 data,	/* data to write                */
					  DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadReg32(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					 DRXaddr_t addr,	/* address of register          */
					 u32 *data,	/* buffer to receive data       */
					 DRXflags_t flags);	/* special device flags         */

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg32(struct i2c_device_addr *devAddr,	/* address of I2C device        */
						    DRXaddr_t waddr,	/* address of register          */
						    DRXaddr_t raddr,	/* address to read back from    */
						    u32 datain,	/* data to send                 */
						    u32 *dataout);	/* data to receive back         */

/* The version structure of this protocol implementation */
char drxDapFASIModuleName[] = "FASI Data Access Protocol";
char drxDapFASIVersionText[] = "";

DRXVersion_t drxDapFASIVersion = {
	DRX_MODULE_DAP,	      /**< type identifier of the module */
	drxDapFASIModuleName, /**< name or description of module */

	0,		      /**< major version number */
	0,		      /**< minor version number */
	0,		      /**< patch version number */
	drxDapFASIVersionText /**< version as text string */
};

/* The structure containing the protocol interface */
DRXAccessFunc_t drxDapFASIFunct_g = {
	&drxDapFASIVersion,
	DRXDAP_FASI_WriteBlock,	/* Supported */
	DRXDAP_FASI_ReadBlock,	/* Supported */
	DRXDAP_FASI_WriteReg8,	/* Not supported */
	DRXDAP_FASI_ReadReg8,	/* Not supported */
	DRXDAP_FASI_ReadModifyWriteReg8,	/* Not supported */
	DRXDAP_FASI_WriteReg16,	/* Supported */
	DRXDAP_FASI_ReadReg16,	/* Supported */
	DRXDAP_FASI_ReadModifyWriteReg16,	/* Supported */
	DRXDAP_FASI_WriteReg32,	/* Supported */
	DRXDAP_FASI_ReadReg32,	/* Supported */
	DRXDAP_FASI_ReadModifyWriteReg32	/* Not supported */
};

/*============================================================================*/

/* Functions not supported by protocol*/

static DRXStatus_t DRXDAP_FASI_WriteReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					 DRXaddr_t addr,	/* address of register          */
					 u8 data,	/* data to write                */
					 DRXflags_t flags)
{				/* special device flags         */
	return DRX_STS_ERROR;
}

static DRXStatus_t DRXDAP_FASI_ReadReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
					DRXaddr_t addr,	/* address of register          */
					u8 *data,	/* buffer to receive data       */
					DRXflags_t flags)
{				/* special device flags         */
	return DRX_STS_ERROR;
}

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg8(struct i2c_device_addr *devAddr,	/* address of I2C device        */
						   DRXaddr_t waddr,	/* address of register          */
						   DRXaddr_t raddr,	/* address to read back from    */
						   u8 datain,	/* data to send                 */
						   u8 *dataout)
{				/* data to receive back         */
	return DRX_STS_ERROR;
}

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg32(struct i2c_device_addr *devAddr,	/* address of I2C device        */
						    DRXaddr_t waddr,	/* address of register          */
						    DRXaddr_t raddr,	/* address to read back from    */
						    u32 datain,	/* data to send                 */
						    u32 *dataout)
{				/* data to receive back         */
	return DRX_STS_ERROR;
}

/*============================================================================*/

/******************************
*
* DRXStatus_t DRXDAP_FASI_ReadBlock (
*      struct i2c_device_addr *devAddr,      -- address of I2C device
*      DRXaddr_t        addr,         -- address of chip register/memory
*      u16            datasize,     -- number of bytes to read
*      u8 *data,         -- data to receive
*      DRXflags_t       flags)        -- special device flags
*
* Read block data from chip address. Because the chip is word oriented,
* the number of bytes to read must be even.
*
* Make sure that the buffer to receive the data is large enough.
*
* Although this function expects an even number of bytes, it is still byte
* oriented, and the data read back is NOT translated to the endianness of
* the target platform.
*
* Output:
* - DRX_STS_OK     if reading was successful
*                  in that case: data read is in *data.
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_ReadBlock(struct i2c_device_addr *devAddr,
					 DRXaddr_t addr,
					 u16 datasize,
					 u8 *data, DRXflags_t flags)
{
	u8 buf[4];
	u16 bufx;
	DRXStatus_t rc;
	u16 overheadSize = 0;

	/* Check parameters ******************************************************* */
	if (devAddr == NULL) {
		return DRX_STS_INVALID_ARG;
	}

	overheadSize = (IS_I2C_10BIT(devAddr->i2cAddr) ? 2 : 1) +
	    (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2);

	if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) ||
	    ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) &&
	     DRXDAP_FASI_LONG_FORMAT(addr)) ||
	    (overheadSize > (DRXDAP_MAX_WCHUNKSIZE)) ||
	    ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1)) {
		return DRX_STS_INVALID_ARG;
	}

	/* ReadModifyWrite & mode flag bits are not allowed */
	flags &= (~DRXDAP_FASI_RMW & ~DRXDAP_FASI_MODEFLAGS);
#if DRXDAP_SINGLE_MASTER
	flags |= DRXDAP_FASI_SINGLE_MASTER;
#endif

	/* Read block from I2C **************************************************** */
	do {
		u16 todo = (datasize < DRXDAP_MAX_RCHUNKSIZE ?
			      datasize : DRXDAP_MAX_RCHUNKSIZE);

		bufx = 0;

		addr &= ~DRXDAP_FASI_FLAGS;
		addr |= flags;

#if ( ( DRXDAPFASI_LONG_ADDR_ALLOWED==1 ) && \
      ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 ) )
		/* short format address preferred but long format otherwise */
		if (DRXDAP_FASI_LONG_FORMAT(addr)) {
#endif
#if ( DRXDAPFASI_LONG_ADDR_ALLOWED==1 )
			buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01);
			buf[bufx++] = (u8) ((addr >> 16) & 0xFF);
			buf[bufx++] = (u8) ((addr >> 24) & 0xFF);
			buf[bufx++] = (u8) ((addr >> 7) & 0xFF);
#endif
#if ( ( DRXDAPFASI_LONG_ADDR_ALLOWED==1 ) && \
      ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 ) )
		} else {
#endif
#if ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 )
			buf[bufx++] = (u8) ((addr << 1) & 0xFF);
			buf[bufx++] =
			    (u8) (((addr >> 16) & 0x0F) |
				    ((addr >> 18) & 0xF0));
#endif
#if ( ( DRXDAPFASI_LONG_ADDR_ALLOWED==1 ) && \
      ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 ) )
		}
#endif

#if DRXDAP_SINGLE_MASTER
		/*
		 * In single master mode, split the read and write actions.
		 * No special action is needed for write chunks here.
		 */
		rc = DRXBSP_I2C_WriteRead(devAddr, bufx, buf, 0, 0, 0);
		if (rc == DRX_STS_OK) {
			rc = DRXBSP_I2C_WriteRead(0, 0, 0, devAddr, todo, data);
		}
#else
		/* In multi master mode, do everything in one RW action */
		rc = DRXBSP_I2C_WriteRead(devAddr, bufx, buf, devAddr, todo,
					  data);
#endif
		data += todo;
		addr += (todo >> 1);
		datasize -= todo;
	} while (datasize && rc == DRX_STS_OK);

	return rc;
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg16 (
*      struct i2c_device_addr *devAddr,   -- address of I2C device
*      DRXaddr_t        waddr,     -- address of chip register/memory
*      DRXaddr_t        raddr,     -- chip address to read back from
*      u16            wdata,     -- data to send
*      u16 *rdata)     -- data to receive back
*
* Write 16-bit data, then read back the original contents of that location.
* Requires long addressing format to be allowed.
*
* Before sending data, the data is converted to little endian. The
* data received back is converted back to the target platform's endianness.
*
* WARNING: This function is only guaranteed to work if there is one
* master on the I2C bus.
*
* Output:
* - DRX_STS_OK     if reading was successful
*                  in that case: read back data is at *rdata
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_ReadModifyWriteReg16(struct i2c_device_addr *devAddr,
						    DRXaddr_t waddr,
						    DRXaddr_t raddr,
						    u16 wdata, u16 *rdata)
{
	DRXStatus_t rc = DRX_STS_ERROR;

#if ( DRXDAPFASI_LONG_ADDR_ALLOWED==1 )
	if (rdata == NULL) {
		return DRX_STS_INVALID_ARG;
	}

	rc = DRXDAP_FASI_WriteReg16(devAddr, waddr, wdata, DRXDAP_FASI_RMW);
	if (rc == DRX_STS_OK) {
		rc = DRXDAP_FASI_ReadReg16(devAddr, raddr, rdata, 0);
	}
#endif

	return rc;
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_ReadReg16 (
*     struct i2c_device_addr *devAddr, -- address of I2C device
*     DRXaddr_t        addr,    -- address of chip register/memory
*     u16 *data,    -- data to receive
*     DRXflags_t       flags)   -- special device flags
*
* Read one 16-bit register or memory location. The data received back is
* converted back to the target platform's endianness.
*
* Output:
* - DRX_STS_OK     if reading was successful
*                  in that case: read data is at *data
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_ReadReg16(struct i2c_device_addr *devAddr,
					 DRXaddr_t addr,
					 u16 *data, DRXflags_t flags)
{
	u8 buf[sizeof(*data)];
	DRXStatus_t rc;

	if (!data) {
		return DRX_STS_INVALID_ARG;
	}
	rc = DRXDAP_FASI_ReadBlock(devAddr, addr, sizeof(*data), buf, flags);
	*data = buf[0] + (((u16) buf[1]) << 8);
	return rc;
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_ReadReg32 (
*     struct i2c_device_addr *devAddr, -- address of I2C device
*     DRXaddr_t        addr,    -- address of chip register/memory
*     u32 *data,    -- data to receive
*     DRXflags_t       flags)   -- special device flags
*
* Read one 32-bit register or memory location. The data received back is
* converted back to the target platform's endianness.
*
* Output:
* - DRX_STS_OK     if reading was successful
*                  in that case: read data is at *data
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_ReadReg32(struct i2c_device_addr *devAddr,
					 DRXaddr_t addr,
					 u32 *data, DRXflags_t flags)
{
	u8 buf[sizeof(*data)];
	DRXStatus_t rc;

	if (!data) {
		return DRX_STS_INVALID_ARG;
	}
	rc = DRXDAP_FASI_ReadBlock(devAddr, addr, sizeof(*data), buf, flags);
	*data = (((u32) buf[0]) << 0) +
	    (((u32) buf[1]) << 8) +
	    (((u32) buf[2]) << 16) + (((u32) buf[3]) << 24);
	return rc;
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_WriteBlock (
*      struct i2c_device_addr *devAddr,    -- address of I2C device
*      DRXaddr_t        addr,       -- address of chip register/memory
*      u16            datasize,   -- number of bytes to read
*      u8 *data,       -- data to receive
*      DRXflags_t       flags)      -- special device flags
*
* Write block data to chip address. Because the chip is word oriented,
* the number of bytes to write must be even.
*
* Although this function expects an even number of bytes, it is still byte
* oriented, and the data being written is NOT translated from the endianness of
* the target platform.
*
* Output:
* - DRX_STS_OK     if writing was successful
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_WriteBlock(struct i2c_device_addr *devAddr,
					  DRXaddr_t addr,
					  u16 datasize,
					  u8 *data, DRXflags_t flags)
{
	u8 buf[DRXDAP_MAX_WCHUNKSIZE];
	DRXStatus_t st = DRX_STS_ERROR;
	DRXStatus_t firstErr = DRX_STS_OK;
	u16 overheadSize = 0;
	u16 blockSize = 0;

	/* Check parameters ******************************************************* */
	if (devAddr == NULL) {
		return DRX_STS_INVALID_ARG;
	}

	overheadSize = (IS_I2C_10BIT(devAddr->i2cAddr) ? 2 : 1) +
	    (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2);

	if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) ||
	    ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) &&
	     DRXDAP_FASI_LONG_FORMAT(addr)) ||
	    (overheadSize > (DRXDAP_MAX_WCHUNKSIZE)) ||
	    ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1)) {
		return DRX_STS_INVALID_ARG;
	}

	flags &= DRXDAP_FASI_FLAGS;
	flags &= ~DRXDAP_FASI_MODEFLAGS;
#if DRXDAP_SINGLE_MASTER
	flags |= DRXDAP_FASI_SINGLE_MASTER;
#endif

	/* Write block to I2C ***************************************************** */
	blockSize = ((DRXDAP_MAX_WCHUNKSIZE) - overheadSize) & ~1;
	do {
		u16 todo = 0;
		u16 bufx = 0;

		/* Buffer device address */
		addr &= ~DRXDAP_FASI_FLAGS;
		addr |= flags;
#if ( ( (DRXDAPFASI_LONG_ADDR_ALLOWED)==1 ) && \
      ( (DRXDAPFASI_SHORT_ADDR_ALLOWED)==1 ) )
		/* short format address preferred but long format otherwise */
		if (DRXDAP_FASI_LONG_FORMAT(addr)) {
#endif
#if ( (DRXDAPFASI_LONG_ADDR_ALLOWED)==1 )
			buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01);
			buf[bufx++] = (u8) ((addr >> 16) & 0xFF);
			buf[bufx++] = (u8) ((addr >> 24) & 0xFF);
			buf[bufx++] = (u8) ((addr >> 7) & 0xFF);
#endif
#if ( ( (DRXDAPFASI_LONG_ADDR_ALLOWED)==1 ) && \
      ( (DRXDAPFASI_SHORT_ADDR_ALLOWED)==1 ) )
		} else {
#endif
#if ( (DRXDAPFASI_SHORT_ADDR_ALLOWED)==1 )
			buf[bufx++] = (u8) ((addr << 1) & 0xFF);
			buf[bufx++] =
			    (u8) (((addr >> 16) & 0x0F) |
				    ((addr >> 18) & 0xF0));
#endif
#if ( ( (DRXDAPFASI_LONG_ADDR_ALLOWED)==1 ) && \
      ( (DRXDAPFASI_SHORT_ADDR_ALLOWED)==1 ) )
		}
#endif

		/*
		   In single master mode blockSize can be 0. In such a case this I2C
		   sequense will be visible: (1) write address {i2c addr,
		   4 bytes chip address} (2) write data {i2c addr, 4 bytes data }
		   (3) write address (4) write data etc...
		   Addres must be rewriten because HI is reset after data transport and
		   expects an address.
		 */
		todo = (blockSize < datasize ? blockSize : datasize);
		if (todo == 0) {
			u16 overheadSizeI2cAddr = 0;
			u16 dataBlockSize = 0;

			overheadSizeI2cAddr =
			    (IS_I2C_10BIT(devAddr->i2cAddr) ? 2 : 1);
			dataBlockSize =
			    (DRXDAP_MAX_WCHUNKSIZE - overheadSizeI2cAddr) & ~1;

			/* write device address */
			st = DRXBSP_I2C_WriteRead(devAddr,
						  (u16) (bufx),
						  buf,
						  (struct i2c_device_addr *) (NULL),
						  0, (u8 *) (NULL));

			if ((st != DRX_STS_OK) && (firstErr == DRX_STS_OK)) {
				/* at the end, return the first error encountered */
				firstErr = st;
			}
			bufx = 0;
			todo =
			    (dataBlockSize <
			     datasize ? dataBlockSize : datasize);
		}
		DRXBSP_HST_Memcpy(&buf[bufx], data, todo);
		/* write (address if can do and) data */
		st = DRXBSP_I2C_WriteRead(devAddr,
					  (u16) (bufx + todo),
					  buf,
					  (struct i2c_device_addr *) (NULL),
					  0, (u8 *) (NULL));

		if ((st != DRX_STS_OK) && (firstErr == DRX_STS_OK)) {
			/* at the end, return the first error encountered */
			firstErr = st;
		}
		datasize -= todo;
		data += todo;
		addr += (todo >> 1);
	} while (datasize);

	return firstErr;
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_WriteReg16 (
*     struct i2c_device_addr *devAddr, -- address of I2C device
*     DRXaddr_t        addr,    -- address of chip register/memory
*     u16            data,    -- data to send
*     DRXflags_t       flags)   -- special device flags
*
* Write one 16-bit register or memory location. The data being written is
* converted from the target platform's endianness to little endian.
*
* Output:
* - DRX_STS_OK     if writing was successful
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_WriteReg16(struct i2c_device_addr *devAddr,
					  DRXaddr_t addr,
					  u16 data, DRXflags_t flags)
{
	u8 buf[sizeof(data)];

	buf[0] = (u8) ((data >> 0) & 0xFF);
	buf[1] = (u8) ((data >> 8) & 0xFF);

	return DRXDAP_FASI_WriteBlock(devAddr, addr, sizeof(data), buf, flags);
}

/******************************
*
* DRXStatus_t DRXDAP_FASI_WriteReg32 (
*     struct i2c_device_addr *devAddr, -- address of I2C device
*     DRXaddr_t        addr,    -- address of chip register/memory
*     u32            data,    -- data to send
*     DRXflags_t       flags)   -- special device flags
*
* Write one 32-bit register or memory location. The data being written is
* converted from the target platform's endianness to little endian.
*
* Output:
* - DRX_STS_OK     if writing was successful
* - DRX_STS_ERROR  if anything went wrong
*
******************************/

static DRXStatus_t DRXDAP_FASI_WriteReg32(struct i2c_device_addr *devAddr,
					  DRXaddr_t addr,
					  u32 data, DRXflags_t flags)
{
	u8 buf[sizeof(data)];

	buf[0] = (u8) ((data >> 0) & 0xFF);
	buf[1] = (u8) ((data >> 8) & 0xFF);
	buf[2] = (u8) ((data >> 16) & 0xFF);
	buf[3] = (u8) ((data >> 24) & 0xFF);

	return DRXDAP_FASI_WriteBlock(devAddr, addr, sizeof(data), buf, flags);
}