/*
 *  i2c-pnx0105.h: driver for PNX833X I2C (IP0105 Block)
 *    Copyright (C) 2006 Nikita Youshchenko <yoush@debian.org>
 *
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef _LINUX_I2C_PNX0105_H
#define _LINUX_I2C_PNX0105_H

#include <linux/i2c.h>
#include <linux/i2c-algo-pca.h>
#include <linux/wait.h>

typedef enum
{
    i2c_pnx0105_idle = 0u,
    i2c_pnx0105_master_transmitter,
    i2c_pnx0105_master_receiver,
    i2c_pnx0105_slave_transmitter,
    i2c_pnx0105_slave_receiver
} i2c_pnx0105_mode;

struct i2c_pnx0105_dev {
	unsigned long base;
	int irq;
	unsigned char clock;	/* value to write to freq bits of control reg */
	unsigned char bus_addr; /* bus address for slave mode; currently not supported */

	int timeout;		/* non-zero when timeout was detected */
	wait_queue_head_t wait;
	
	bool slave_enable;
	i2c_pnx0105_mode i2c_mode;
	unsigned char *slave_rd_buf;
	unsigned char *slave_wr_buf;
	int slave_bufsize;//for transimtter
	int slave_buflen;
	int slave_rd_bufindex;
	int slave_wr_bufindex;

	// Debug stuff
	int last_address;

	struct i2c_algo_pca_data algo_data;
	struct i2c_adapter adap;
};

/* Register area size */
#define I2C_PNX0105_IO_SIZE		0x1000

/* Register offsets */
#define I2C_PNX0105_CONTROL     0x0000
#define I2C_PNX0105_DAT         0x0004
#define I2C_PNX0105_STATUS		0x0008
#define I2C_PNX0105_ADDRESS		0x000C
#define I2C_PNX0105_STOP		0x0010
#define I2C_PNX0105_PD          0x0014
#define I2C_PNX0105_SET_PINS	0x0018
#define I2C_PNX0105_OBS_PINS	0x001C
#define I2C_PNX0105_INT_STATUS	0x0FE0
#define I2C_PNX0105_INT_ENABLE	0x0FE4
#define I2C_PNX0105_INT_CLEAR	0x0FE8
#define I2C_PNX0105_INT_SET		0x0FEC
#define I2C_PNX0105_POWER_DOWN	0x0FF4
#define I2C_PNX0105_MODULE_ID	0x0FFC

#endif
