162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc. 362306a36Sopenharmony_ci All rights reserved. 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci Redistribution and use in source and binary forms, with or without 662306a36Sopenharmony_ci modification, are permitted provided that the following conditions are met: 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci * Redistributions of source code must retain the above copyright notice, 962306a36Sopenharmony_ci this list of conditions and the following disclaimer. 1062306a36Sopenharmony_ci * Redistributions in binary form must reproduce the above copyright notice, 1162306a36Sopenharmony_ci this list of conditions and the following disclaimer in the documentation 1262306a36Sopenharmony_ci and/or other materials provided with the distribution. 1362306a36Sopenharmony_ci * Neither the name of Trident Microsystems nor Hauppauge Computer Works 1462306a36Sopenharmony_ci nor the names of its contributors may be used to endorse or promote 1562306a36Sopenharmony_ci products derived from this software without specific prior written 1662306a36Sopenharmony_ci permission. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1962306a36Sopenharmony_ci AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2062306a36Sopenharmony_ci IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2162306a36Sopenharmony_ci ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2262306a36Sopenharmony_ci LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2362306a36Sopenharmony_ci CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2462306a36Sopenharmony_ci SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2562306a36Sopenharmony_ci INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2662306a36Sopenharmony_ci CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2762306a36Sopenharmony_ci ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2862306a36Sopenharmony_ci POSSIBILITY OF SUCH DAMAGE. 2962306a36Sopenharmony_ci*/ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/******************************************************************************* 3262306a36Sopenharmony_ci* FILENAME: $Id: drx_dap_fasi.h,v 1.5 2009/07/07 14:21:40 justin Exp $ 3362306a36Sopenharmony_ci* 3462306a36Sopenharmony_ci* DESCRIPTION: 3562306a36Sopenharmony_ci* Part of DRX driver. 3662306a36Sopenharmony_ci* Data access protocol: Fast Access Sequential Interface (fasi) 3762306a36Sopenharmony_ci* Fast access, because of short addressing format (16 instead of 32 bits addr) 3862306a36Sopenharmony_ci* Sequential, because of I2C. 3962306a36Sopenharmony_ci* 4062306a36Sopenharmony_ci* USAGE: 4162306a36Sopenharmony_ci* Include. 4262306a36Sopenharmony_ci* 4362306a36Sopenharmony_ci* NOTES: 4462306a36Sopenharmony_ci* 4562306a36Sopenharmony_ci* 4662306a36Sopenharmony_ci*******************************************************************************/ 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/*-------- compilation control switches --------------------------------------*/ 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#ifndef __DRX_DAP_FASI_H__ 5162306a36Sopenharmony_ci#define __DRX_DAP_FASI_H__ 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/*-------- Required includes -------------------------------------------------*/ 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#include "drx_driver.h" 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/*-------- Defines, configuring the API --------------------------------------*/ 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/******************************************** 6062306a36Sopenharmony_ci* Allowed address formats 6162306a36Sopenharmony_ci********************************************/ 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* 6462306a36Sopenharmony_ci* Comments about short/long addressing format: 6562306a36Sopenharmony_ci* 6662306a36Sopenharmony_ci* The DAP FASI offers long address format (4 bytes) and short address format 6762306a36Sopenharmony_ci* (2 bytes). The DAP can operate in 3 modes: 6862306a36Sopenharmony_ci* (1) only short 6962306a36Sopenharmony_ci* (2) only long 7062306a36Sopenharmony_ci* (3) both long and short but short preferred and long only when necessary 7162306a36Sopenharmony_ci* 7262306a36Sopenharmony_ci* These modes must be selected compile time via compile switches. 7362306a36Sopenharmony_ci* Compile switch settings for the different modes: 7462306a36Sopenharmony_ci* (1) DRXDAPFASI_LONG_ADDR_ALLOWED=0, DRXDAPFASI_SHORT_ADDR_ALLOWED=1 7562306a36Sopenharmony_ci* (2) DRXDAPFASI_LONG_ADDR_ALLOWED=1, DRXDAPFASI_SHORT_ADDR_ALLOWED=0 7662306a36Sopenharmony_ci* (3) DRXDAPFASI_LONG_ADDR_ALLOWED=1, DRXDAPFASI_SHORT_ADDR_ALLOWED=1 7762306a36Sopenharmony_ci* 7862306a36Sopenharmony_ci* The default setting will be (3) both long and short. 7962306a36Sopenharmony_ci* The default setting will need no compile switches. 8062306a36Sopenharmony_ci* The default setting must be overridden if compile switches are already 8162306a36Sopenharmony_ci* defined. 8262306a36Sopenharmony_ci* 8362306a36Sopenharmony_ci*/ 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* set default */ 8662306a36Sopenharmony_ci#if !defined(DRXDAPFASI_LONG_ADDR_ALLOWED) 8762306a36Sopenharmony_ci#define DRXDAPFASI_LONG_ADDR_ALLOWED 1 8862306a36Sopenharmony_ci#endif 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* set default */ 9162306a36Sopenharmony_ci#if !defined(DRXDAPFASI_SHORT_ADDR_ALLOWED) 9262306a36Sopenharmony_ci#define DRXDAPFASI_SHORT_ADDR_ALLOWED 1 9362306a36Sopenharmony_ci#endif 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci/* check */ 9662306a36Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && \ 9762306a36Sopenharmony_ci (DRXDAPFASI_SHORT_ADDR_ALLOWED == 0)) 9862306a36Sopenharmony_ci#error At least one of short- or long-addressing format must be allowed. 9962306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 10062306a36Sopenharmony_ci#endif 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/******************************************** 10362306a36Sopenharmony_ci* Single/master multi master setting 10462306a36Sopenharmony_ci********************************************/ 10562306a36Sopenharmony_ci/* 10662306a36Sopenharmony_ci* Comments about SINGLE MASTER/MULTI MASTER modes: 10762306a36Sopenharmony_ci* 10862306a36Sopenharmony_ci* Consider the two sides:1) the master and 2)the slave. 10962306a36Sopenharmony_ci* 11062306a36Sopenharmony_ci* Master: 11162306a36Sopenharmony_ci* Single/multimaster operation set via DRXDAP_SINGLE_MASTER compile switch 11262306a36Sopenharmony_ci* + single master mode means no use of repeated starts 11362306a36Sopenharmony_ci* + multi master mode means use of repeated starts 11462306a36Sopenharmony_ci* Default is single master. 11562306a36Sopenharmony_ci* Default can be overridden by setting the compile switch DRXDAP_SINGLE_MASTER. 11662306a36Sopenharmony_ci* 11762306a36Sopenharmony_ci* Slave: 11862306a36Sopenharmony_ci* Single/multi master selected via the flags in the FASI protocol. 11962306a36Sopenharmony_ci* + single master means remember memory address between i2c packets 12062306a36Sopenharmony_ci* + multimaster means flush memory address between i2c packets 12162306a36Sopenharmony_ci* Default is single master, DAP FASI changes multi-master setting silently 12262306a36Sopenharmony_ci* into single master setting. This cannot be overridden. 12362306a36Sopenharmony_ci* 12462306a36Sopenharmony_ci*/ 12562306a36Sopenharmony_ci/* set default */ 12662306a36Sopenharmony_ci#ifndef DRXDAP_SINGLE_MASTER 12762306a36Sopenharmony_ci#define DRXDAP_SINGLE_MASTER 0 12862306a36Sopenharmony_ci#endif 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/******************************************** 13162306a36Sopenharmony_ci* Chunk/mode checking 13262306a36Sopenharmony_ci********************************************/ 13362306a36Sopenharmony_ci/* 13462306a36Sopenharmony_ci* Comments about DRXDAP_MAX_WCHUNKSIZE in single or multi master mode and 13562306a36Sopenharmony_ci* in combination with short and long addressing format. All text below 13662306a36Sopenharmony_ci* assumes long addressing format. The table also includes information 13762306a36Sopenharmony_ci* for short ADDRessing format. 13862306a36Sopenharmony_ci* 13962306a36Sopenharmony_ci* In single master mode, data can be written by sending the register address 14062306a36Sopenharmony_ci* first, then two or four bytes of data in the next packet. 14162306a36Sopenharmony_ci* Because the device address plus a register address equals five bytes, 14262306a36Sopenharmony_ci* the minimum chunk size must be five. 14362306a36Sopenharmony_ci* If ten-bit I2C device addresses are used, the minimum chunk size must be six, 14462306a36Sopenharmony_ci* because the I2C device address will then occupy two bytes when writing. 14562306a36Sopenharmony_ci* 14662306a36Sopenharmony_ci* Data in single master mode is transferred as follows: 14762306a36Sopenharmony_ci* <S> <devW> a0 a1 a2 a3 <P> 14862306a36Sopenharmony_ci* <S> <devW> d0 d1 [d2 d3] <P> 14962306a36Sopenharmony_ci* .. 15062306a36Sopenharmony_ci* or 15162306a36Sopenharmony_ci* .. 15262306a36Sopenharmony_ci* <S> <devW> a0 a1 a2 a3 <P> 15362306a36Sopenharmony_ci* <S> <devR> --- <P> 15462306a36Sopenharmony_ci* 15562306a36Sopenharmony_ci* In multi-master mode, the data must immediately follow the address (an I2C 15662306a36Sopenharmony_ci* stop resets the internal address), and hence the minimum chunk size is 15762306a36Sopenharmony_ci* 1 <I2C address> + 4 (register address) + 2 (data to send) = 7 bytes (8 if 15862306a36Sopenharmony_ci* 10-bit I2C device addresses are used). 15962306a36Sopenharmony_ci* 16062306a36Sopenharmony_ci* The 7-bit or 10-bit i2c address parameters is a runtime parameter. 16162306a36Sopenharmony_ci* The other parameters can be limited via compile time switches. 16262306a36Sopenharmony_ci* 16362306a36Sopenharmony_ci*------------------------------------------------------------------------------- 16462306a36Sopenharmony_ci* 16562306a36Sopenharmony_ci* Minimum chunk size table (in bytes): 16662306a36Sopenharmony_ci* 16762306a36Sopenharmony_ci* +----------------+----------------+ 16862306a36Sopenharmony_ci* | 7b i2c addr | 10b i2c addr | 16962306a36Sopenharmony_ci* +----------------+----------------+ 17062306a36Sopenharmony_ci* | single | multi | single | multi | 17162306a36Sopenharmony_ci* ------+--------+-------+--------+-------+ 17262306a36Sopenharmony_ci* short | 3 | 5 | 4 | 6 | 17362306a36Sopenharmony_ci* long | 5 | 7 | 6 | 8 | 17462306a36Sopenharmony_ci* ------+--------+-------+--------+-------+ 17562306a36Sopenharmony_ci* 17662306a36Sopenharmony_ci*/ 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* set default */ 17962306a36Sopenharmony_ci#if !defined(DRXDAP_MAX_WCHUNKSIZE) 18062306a36Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE 254 18162306a36Sopenharmony_ci#endif 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci/* check */ 18462306a36Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) 18562306a36Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 18662306a36Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 3 18762306a36Sopenharmony_ci#else 18862306a36Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 5 18962306a36Sopenharmony_ci#endif 19062306a36Sopenharmony_ci#else 19162306a36Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 19262306a36Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 5 19362306a36Sopenharmony_ci#else 19462306a36Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 7 19562306a36Sopenharmony_ci#endif 19662306a36Sopenharmony_ci#endif 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#if DRXDAP_MAX_WCHUNKSIZE < DRXDAP_MAX_WCHUNKSIZE_MIN 19962306a36Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) 20062306a36Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 20162306a36Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 3 in single master mode 20262306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 20362306a36Sopenharmony_ci#else 20462306a36Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 5 in multi master mode 20562306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 20662306a36Sopenharmony_ci#endif 20762306a36Sopenharmony_ci#else 20862306a36Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 20962306a36Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 5 in single master mode 21062306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 21162306a36Sopenharmony_ci#else 21262306a36Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 7 in multi master mode 21362306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 21462306a36Sopenharmony_ci#endif 21562306a36Sopenharmony_ci#endif 21662306a36Sopenharmony_ci#endif 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci/* set default */ 21962306a36Sopenharmony_ci#if !defined(DRXDAP_MAX_RCHUNKSIZE) 22062306a36Sopenharmony_ci#define DRXDAP_MAX_RCHUNKSIZE 254 22162306a36Sopenharmony_ci#endif 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* check */ 22462306a36Sopenharmony_ci#if DRXDAP_MAX_RCHUNKSIZE < 2 22562306a36Sopenharmony_ci#error DRXDAP_MAX_RCHUNKSIZE must be at least 2 22662306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 22762306a36Sopenharmony_ci#endif 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci/* check */ 23062306a36Sopenharmony_ci#if DRXDAP_MAX_RCHUNKSIZE & 1 23162306a36Sopenharmony_ci#error DRXDAP_MAX_RCHUNKSIZE must be even 23262306a36Sopenharmony_ci*; /* illegal statement to force compiler error */ 23362306a36Sopenharmony_ci#endif 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci/*-------- Public API functions ----------------------------------------------*/ 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci#define DRXDAP_FASI_RMW 0x10000000 23862306a36Sopenharmony_ci#define DRXDAP_FASI_BROADCAST 0x20000000 23962306a36Sopenharmony_ci#define DRXDAP_FASI_CLEARCRC 0x80000000 24062306a36Sopenharmony_ci#define DRXDAP_FASI_SINGLE_MASTER 0xC0000000 24162306a36Sopenharmony_ci#define DRXDAP_FASI_MULTI_MASTER 0x40000000 24262306a36Sopenharmony_ci#define DRXDAP_FASI_SMM_SWITCH 0x40000000 /* single/multi master switch */ 24362306a36Sopenharmony_ci#define DRXDAP_FASI_MODEFLAGS 0xC0000000 24462306a36Sopenharmony_ci#define DRXDAP_FASI_FLAGS 0xF0000000 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci#define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr)>>22)&0x3F) 24762306a36Sopenharmony_ci#define DRXDAP_FASI_ADDR2BANK(addr) (((addr)>>16)&0x3F) 24862306a36Sopenharmony_ci#define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr)&0x7FFF) 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci#define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0) 25162306a36Sopenharmony_ci#define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0) 25262306a36Sopenharmony_ci#define DRXDAP_FASI_OFFSET_TOO_LARGE(addr) (((addr) & 0x00008000) != 0) 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci#endif /* __DRX_DAP_FASI_H__ */ 255