18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc. 38c2ecf20Sopenharmony_ci All rights reserved. 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci Redistribution and use in source and binary forms, with or without 68c2ecf20Sopenharmony_ci modification, are permitted provided that the following conditions are met: 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci * Redistributions of source code must retain the above copyright notice, 98c2ecf20Sopenharmony_ci this list of conditions and the following disclaimer. 108c2ecf20Sopenharmony_ci * Redistributions in binary form must reproduce the above copyright notice, 118c2ecf20Sopenharmony_ci this list of conditions and the following disclaimer in the documentation 128c2ecf20Sopenharmony_ci and/or other materials provided with the distribution. 138c2ecf20Sopenharmony_ci * Neither the name of Trident Microsystems nor Hauppauge Computer Works 148c2ecf20Sopenharmony_ci nor the names of its contributors may be used to endorse or promote 158c2ecf20Sopenharmony_ci products derived from this software without specific prior written 168c2ecf20Sopenharmony_ci permission. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 198c2ecf20Sopenharmony_ci AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 208c2ecf20Sopenharmony_ci IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 218c2ecf20Sopenharmony_ci ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 228c2ecf20Sopenharmony_ci LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 238c2ecf20Sopenharmony_ci CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 248c2ecf20Sopenharmony_ci SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 258c2ecf20Sopenharmony_ci INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 268c2ecf20Sopenharmony_ci CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 278c2ecf20Sopenharmony_ci ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 288c2ecf20Sopenharmony_ci POSSIBILITY OF SUCH DAMAGE. 298c2ecf20Sopenharmony_ci*/ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/******************************************************************************* 328c2ecf20Sopenharmony_ci* FILENAME: $Id: drx_dap_fasi.h,v 1.5 2009/07/07 14:21:40 justin Exp $ 338c2ecf20Sopenharmony_ci* 348c2ecf20Sopenharmony_ci* DESCRIPTION: 358c2ecf20Sopenharmony_ci* Part of DRX driver. 368c2ecf20Sopenharmony_ci* Data access protocol: Fast Access Sequential Interface (fasi) 378c2ecf20Sopenharmony_ci* Fast access, because of short addressing format (16 instead of 32 bits addr) 388c2ecf20Sopenharmony_ci* Sequential, because of I2C. 398c2ecf20Sopenharmony_ci* 408c2ecf20Sopenharmony_ci* USAGE: 418c2ecf20Sopenharmony_ci* Include. 428c2ecf20Sopenharmony_ci* 438c2ecf20Sopenharmony_ci* NOTES: 448c2ecf20Sopenharmony_ci* 458c2ecf20Sopenharmony_ci* 468c2ecf20Sopenharmony_ci*******************************************************************************/ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/*-------- compilation control switches --------------------------------------*/ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#ifndef __DRX_DAP_FASI_H__ 518c2ecf20Sopenharmony_ci#define __DRX_DAP_FASI_H__ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/*-------- Required includes -------------------------------------------------*/ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#include "drx_driver.h" 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/*-------- Defines, configuring the API --------------------------------------*/ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/******************************************** 608c2ecf20Sopenharmony_ci* Allowed address formats 618c2ecf20Sopenharmony_ci********************************************/ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* 648c2ecf20Sopenharmony_ci* Comments about short/long addressing format: 658c2ecf20Sopenharmony_ci* 668c2ecf20Sopenharmony_ci* The DAP FASI offers long address format (4 bytes) and short address format 678c2ecf20Sopenharmony_ci* (2 bytes). The DAP can operate in 3 modes: 688c2ecf20Sopenharmony_ci* (1) only short 698c2ecf20Sopenharmony_ci* (2) only long 708c2ecf20Sopenharmony_ci* (3) both long and short but short preferred and long only when necessary 718c2ecf20Sopenharmony_ci* 728c2ecf20Sopenharmony_ci* These modes must be selected compile time via compile switches. 738c2ecf20Sopenharmony_ci* Compile switch settings for the different modes: 748c2ecf20Sopenharmony_ci* (1) DRXDAPFASI_LONG_ADDR_ALLOWED=0, DRXDAPFASI_SHORT_ADDR_ALLOWED=1 758c2ecf20Sopenharmony_ci* (2) DRXDAPFASI_LONG_ADDR_ALLOWED=1, DRXDAPFASI_SHORT_ADDR_ALLOWED=0 768c2ecf20Sopenharmony_ci* (3) DRXDAPFASI_LONG_ADDR_ALLOWED=1, DRXDAPFASI_SHORT_ADDR_ALLOWED=1 778c2ecf20Sopenharmony_ci* 788c2ecf20Sopenharmony_ci* The default setting will be (3) both long and short. 798c2ecf20Sopenharmony_ci* The default setting will need no compile switches. 808c2ecf20Sopenharmony_ci* The default setting must be overridden if compile switches are already 818c2ecf20Sopenharmony_ci* defined. 828c2ecf20Sopenharmony_ci* 838c2ecf20Sopenharmony_ci*/ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* set default */ 868c2ecf20Sopenharmony_ci#if !defined(DRXDAPFASI_LONG_ADDR_ALLOWED) 878c2ecf20Sopenharmony_ci#define DRXDAPFASI_LONG_ADDR_ALLOWED 1 888c2ecf20Sopenharmony_ci#endif 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* set default */ 918c2ecf20Sopenharmony_ci#if !defined(DRXDAPFASI_SHORT_ADDR_ALLOWED) 928c2ecf20Sopenharmony_ci#define DRXDAPFASI_SHORT_ADDR_ALLOWED 1 938c2ecf20Sopenharmony_ci#endif 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* check */ 968c2ecf20Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && \ 978c2ecf20Sopenharmony_ci (DRXDAPFASI_SHORT_ADDR_ALLOWED == 0)) 988c2ecf20Sopenharmony_ci#error At least one of short- or long-addressing format must be allowed. 998c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 1008c2ecf20Sopenharmony_ci#endif 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/******************************************** 1038c2ecf20Sopenharmony_ci* Single/master multi master setting 1048c2ecf20Sopenharmony_ci********************************************/ 1058c2ecf20Sopenharmony_ci/* 1068c2ecf20Sopenharmony_ci* Comments about SINGLE MASTER/MULTI MASTER modes: 1078c2ecf20Sopenharmony_ci* 1088c2ecf20Sopenharmony_ci* Consider the two sides:1) the master and 2)the slave. 1098c2ecf20Sopenharmony_ci* 1108c2ecf20Sopenharmony_ci* Master: 1118c2ecf20Sopenharmony_ci* Single/multimaster operation set via DRXDAP_SINGLE_MASTER compile switch 1128c2ecf20Sopenharmony_ci* + single master mode means no use of repeated starts 1138c2ecf20Sopenharmony_ci* + multi master mode means use of repeated starts 1148c2ecf20Sopenharmony_ci* Default is single master. 1158c2ecf20Sopenharmony_ci* Default can be overridden by setting the compile switch DRXDAP_SINGLE_MASTER. 1168c2ecf20Sopenharmony_ci* 1178c2ecf20Sopenharmony_ci* Slave: 1188c2ecf20Sopenharmony_ci* Single/multi master selected via the flags in the FASI protocol. 1198c2ecf20Sopenharmony_ci* + single master means remember memory address between i2c packets 1208c2ecf20Sopenharmony_ci* + multimaster means flush memory address between i2c packets 1218c2ecf20Sopenharmony_ci* Default is single master, DAP FASI changes multi-master setting silently 1228c2ecf20Sopenharmony_ci* into single master setting. This cannot be overridden. 1238c2ecf20Sopenharmony_ci* 1248c2ecf20Sopenharmony_ci*/ 1258c2ecf20Sopenharmony_ci/* set default */ 1268c2ecf20Sopenharmony_ci#ifndef DRXDAP_SINGLE_MASTER 1278c2ecf20Sopenharmony_ci#define DRXDAP_SINGLE_MASTER 0 1288c2ecf20Sopenharmony_ci#endif 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/******************************************** 1318c2ecf20Sopenharmony_ci* Chunk/mode checking 1328c2ecf20Sopenharmony_ci********************************************/ 1338c2ecf20Sopenharmony_ci/* 1348c2ecf20Sopenharmony_ci* Comments about DRXDAP_MAX_WCHUNKSIZE in single or multi master mode and 1358c2ecf20Sopenharmony_ci* in combination with short and long addressing format. All text below 1368c2ecf20Sopenharmony_ci* assumes long addressing format. The table also includes information 1378c2ecf20Sopenharmony_ci* for short ADDRessing format. 1388c2ecf20Sopenharmony_ci* 1398c2ecf20Sopenharmony_ci* In single master mode, data can be written by sending the register address 1408c2ecf20Sopenharmony_ci* first, then two or four bytes of data in the next packet. 1418c2ecf20Sopenharmony_ci* Because the device address plus a register address equals five bytes, 1428c2ecf20Sopenharmony_ci* the minimum chunk size must be five. 1438c2ecf20Sopenharmony_ci* If ten-bit I2C device addresses are used, the minimum chunk size must be six, 1448c2ecf20Sopenharmony_ci* because the I2C device address will then occupy two bytes when writing. 1458c2ecf20Sopenharmony_ci* 1468c2ecf20Sopenharmony_ci* Data in single master mode is transferred as follows: 1478c2ecf20Sopenharmony_ci* <S> <devW> a0 a1 a2 a3 <P> 1488c2ecf20Sopenharmony_ci* <S> <devW> d0 d1 [d2 d3] <P> 1498c2ecf20Sopenharmony_ci* .. 1508c2ecf20Sopenharmony_ci* or 1518c2ecf20Sopenharmony_ci* .. 1528c2ecf20Sopenharmony_ci* <S> <devW> a0 a1 a2 a3 <P> 1538c2ecf20Sopenharmony_ci* <S> <devR> --- <P> 1548c2ecf20Sopenharmony_ci* 1558c2ecf20Sopenharmony_ci* In multi-master mode, the data must immediately follow the address (an I2C 1568c2ecf20Sopenharmony_ci* stop resets the internal address), and hence the minimum chunk size is 1578c2ecf20Sopenharmony_ci* 1 <I2C address> + 4 (register address) + 2 (data to send) = 7 bytes (8 if 1588c2ecf20Sopenharmony_ci* 10-bit I2C device addresses are used). 1598c2ecf20Sopenharmony_ci* 1608c2ecf20Sopenharmony_ci* The 7-bit or 10-bit i2c address parameters is a runtime parameter. 1618c2ecf20Sopenharmony_ci* The other parameters can be limited via compile time switches. 1628c2ecf20Sopenharmony_ci* 1638c2ecf20Sopenharmony_ci*------------------------------------------------------------------------------- 1648c2ecf20Sopenharmony_ci* 1658c2ecf20Sopenharmony_ci* Minimum chunk size table (in bytes): 1668c2ecf20Sopenharmony_ci* 1678c2ecf20Sopenharmony_ci* +----------------+----------------+ 1688c2ecf20Sopenharmony_ci* | 7b i2c addr | 10b i2c addr | 1698c2ecf20Sopenharmony_ci* +----------------+----------------+ 1708c2ecf20Sopenharmony_ci* | single | multi | single | multi | 1718c2ecf20Sopenharmony_ci* ------+--------+-------+--------+-------+ 1728c2ecf20Sopenharmony_ci* short | 3 | 5 | 4 | 6 | 1738c2ecf20Sopenharmony_ci* long | 5 | 7 | 6 | 8 | 1748c2ecf20Sopenharmony_ci* ------+--------+-------+--------+-------+ 1758c2ecf20Sopenharmony_ci* 1768c2ecf20Sopenharmony_ci*/ 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/* set default */ 1798c2ecf20Sopenharmony_ci#if !defined(DRXDAP_MAX_WCHUNKSIZE) 1808c2ecf20Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE 254 1818c2ecf20Sopenharmony_ci#endif 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/* check */ 1848c2ecf20Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) 1858c2ecf20Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 1868c2ecf20Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 3 1878c2ecf20Sopenharmony_ci#else 1888c2ecf20Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 5 1898c2ecf20Sopenharmony_ci#endif 1908c2ecf20Sopenharmony_ci#else 1918c2ecf20Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 1928c2ecf20Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 5 1938c2ecf20Sopenharmony_ci#else 1948c2ecf20Sopenharmony_ci#define DRXDAP_MAX_WCHUNKSIZE_MIN 7 1958c2ecf20Sopenharmony_ci#endif 1968c2ecf20Sopenharmony_ci#endif 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#if DRXDAP_MAX_WCHUNKSIZE < DRXDAP_MAX_WCHUNKSIZE_MIN 1998c2ecf20Sopenharmony_ci#if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 0) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)) 2008c2ecf20Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 2018c2ecf20Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 3 in single master mode 2028c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2038c2ecf20Sopenharmony_ci#else 2048c2ecf20Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 5 in multi master mode 2058c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2068c2ecf20Sopenharmony_ci#endif 2078c2ecf20Sopenharmony_ci#else 2088c2ecf20Sopenharmony_ci#if DRXDAP_SINGLE_MASTER 2098c2ecf20Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 5 in single master mode 2108c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2118c2ecf20Sopenharmony_ci#else 2128c2ecf20Sopenharmony_ci#error DRXDAP_MAX_WCHUNKSIZE must be at least 7 in multi master mode 2138c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2148c2ecf20Sopenharmony_ci#endif 2158c2ecf20Sopenharmony_ci#endif 2168c2ecf20Sopenharmony_ci#endif 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci/* set default */ 2198c2ecf20Sopenharmony_ci#if !defined(DRXDAP_MAX_RCHUNKSIZE) 2208c2ecf20Sopenharmony_ci#define DRXDAP_MAX_RCHUNKSIZE 254 2218c2ecf20Sopenharmony_ci#endif 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* check */ 2248c2ecf20Sopenharmony_ci#if DRXDAP_MAX_RCHUNKSIZE < 2 2258c2ecf20Sopenharmony_ci#error DRXDAP_MAX_RCHUNKSIZE must be at least 2 2268c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2278c2ecf20Sopenharmony_ci#endif 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci/* check */ 2308c2ecf20Sopenharmony_ci#if DRXDAP_MAX_RCHUNKSIZE & 1 2318c2ecf20Sopenharmony_ci#error DRXDAP_MAX_RCHUNKSIZE must be even 2328c2ecf20Sopenharmony_ci*; /* illegal statement to force compiler error */ 2338c2ecf20Sopenharmony_ci#endif 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci/*-------- Public API functions ----------------------------------------------*/ 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ciextern struct drx_access_func drx_dap_fasi_funct_g; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci#define DRXDAP_FASI_RMW 0x10000000 2408c2ecf20Sopenharmony_ci#define DRXDAP_FASI_BROADCAST 0x20000000 2418c2ecf20Sopenharmony_ci#define DRXDAP_FASI_CLEARCRC 0x80000000 2428c2ecf20Sopenharmony_ci#define DRXDAP_FASI_SINGLE_MASTER 0xC0000000 2438c2ecf20Sopenharmony_ci#define DRXDAP_FASI_MULTI_MASTER 0x40000000 2448c2ecf20Sopenharmony_ci#define DRXDAP_FASI_SMM_SWITCH 0x40000000 /* single/multi master switch */ 2458c2ecf20Sopenharmony_ci#define DRXDAP_FASI_MODEFLAGS 0xC0000000 2468c2ecf20Sopenharmony_ci#define DRXDAP_FASI_FLAGS 0xF0000000 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#define DRXDAP_FASI_ADDR2BLOCK(addr) (((addr)>>22)&0x3F) 2498c2ecf20Sopenharmony_ci#define DRXDAP_FASI_ADDR2BANK(addr) (((addr)>>16)&0x3F) 2508c2ecf20Sopenharmony_ci#define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr)&0x7FFF) 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci#define DRXDAP_FASI_SHORT_FORMAT(addr) (((addr) & 0xFC30FF80) == 0) 2538c2ecf20Sopenharmony_ci#define DRXDAP_FASI_LONG_FORMAT(addr) (((addr) & 0xFC30FF80) != 0) 2548c2ecf20Sopenharmony_ci#define DRXDAP_FASI_OFFSET_TOO_LARGE(addr) (((addr) & 0x00008000) != 0) 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci#endif /* __DRX_DAP_FASI_H__ */ 257