/* 2012-09-16: File added by Sony Corporation */
/*
 * icx_spi.h
 *
 * Copyright 2011 Sony Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef __ICX_SPI_H__
#define __ICX_SPI_H__


/************/
/*@ defines */
/************/

/* spi_config_t.dev */
#define SPI_DEV_SP0         0
#define SPI_DEV_SP1         1
#define SPI_DEV_SP2         2
#define SPI_DEV_SP3         3

/* spi_config_t.cs_sel */
#define SPI_CS_SEL_CS0      (0 << 4)
#define SPI_CS_SEL_CS1      (1 << 4)
#define SPI_CS_SEL_CS2      (2 << 4)

/* spi_config_t.pol */
#define SPI_CK_DLY_OFF      (0 << 2)
#define SPI_CK_DLY_ON       (1 << 2)
#define SPI_CK_POL_POS      (0 << 1)
#define SPI_CK_POL_NEG      (1 << 1)
#define SPI_CS_POL_POS      (0 << 0)
#define SPI_CS_POL_NEG      (1 << 0)
#define SPI_CS_POL_MASK     (1 << 0)

/* spi_config.clk */
#define SPI_CLK_1500KHZ     0
#define SPI_CLK_3MHZ        1
#define SPI_CLK_6MHZ        2
#define SPI_CLK_12MHZ       3
#define SPI_CLK_24MHZ       4
#define SPI_CLK_48MHZ       5
#define SPI_CLK_1MHZ        6

/* spi_config.nb */
#define SPI_NB_8BIT         8
#define SPI_NB_9BIT         9
#define SPI_NB_16BIT        16
#define SPI_NB_24BIT        24
#define SPI_NB_32BIT        32

/* read mode */
#define SPI_READ_1CYCLE     1
#define SPI_READ_2CYCLE     2

/* tiecs */
#define SPI_TIECS_NORMAL    (0)
#define SPI_TIECS_FIXED     (1)


/**************/
/*@ structure */
/**************/

/* SPI config */
typedef struct {
	u_char  dev;        /* device   : SPI_DEV_SP0/1/3           */
	u_int   clk;        /* clock                                */
	u_char  cs;         /* cs select: SPI_CS_SEL_CS0/1          */
	u_int   pol;        /* polarity : CSW/CK_DLY/CK_POL/CS_POL  */
	u_int   nbw;        /* the number of bit to write           */
	u_int   nbr;        /* the number of bit to read            */
} spi_config_t;


/**************/
/*@ prototype */
/**************/

void spi_init(void);
int  spi_probe(spi_config_t *);
int  spi_remove(spi_config_t *);
int  spi_write(spi_config_t *, u_int *, u_int);
int  spi_read(spi_config_t *config, u_int *cmd, u_int *buf, u_int flag);

int  spi_write_tiecs(spi_config_t *, u_int *, u_int);
int  spi_read_tiecs(spi_config_t *, u_int *, u_int *, u_int);


#endif /* __ICX_SPI_H__ */
