18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
38c2ecf20Sopenharmony_ci/* i2c-iop3xx.h algorithm driver definitions private to i2c-iop3xx.c         */
48c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
58c2ecf20Sopenharmony_ci/*   Copyright (C) 2003 Peter Milne, D-TACQ Solutions Ltd
68c2ecf20Sopenharmony_ci *                      <Peter dot Milne at D hyphen TACQ dot com>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef I2C_IOP3XX_H
138c2ecf20Sopenharmony_ci#define I2C_IOP3XX_H 1
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * iop321 hardware bit definitions
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#define IOP3XX_ICR_FAST_MODE	0x8000	/* 1=400kBps, 0=100kBps */
198c2ecf20Sopenharmony_ci#define IOP3XX_ICR_UNIT_RESET	0x4000	/* 1=RESET */
208c2ecf20Sopenharmony_ci#define IOP3XX_ICR_SAD_IE	0x2000	/* 1=Slave Detect Interrupt Enable */
218c2ecf20Sopenharmony_ci#define IOP3XX_ICR_ALD_IE	0x1000	/* 1=Arb Loss Detect Interrupt Enable */
228c2ecf20Sopenharmony_ci#define IOP3XX_ICR_SSD_IE	0x0800	/* 1=Slave STOP Detect Interrupt Enable */
238c2ecf20Sopenharmony_ci#define IOP3XX_ICR_BERR_IE	0x0400	/* 1=Bus Error Interrupt Enable */
248c2ecf20Sopenharmony_ci#define IOP3XX_ICR_RXFULL_IE	0x0200	/* 1=Receive Full Interrupt Enable */
258c2ecf20Sopenharmony_ci#define IOP3XX_ICR_TXEMPTY_IE	0x0100	/* 1=Transmit Empty Interrupt Enable */
268c2ecf20Sopenharmony_ci#define IOP3XX_ICR_GCD		0x0080	/* 1=General Call Disable */
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * IOP3XX_ICR_GCD: 1 disables response as slave. "This bit must be set
298c2ecf20Sopenharmony_ci * when sending a master mode general call message from the I2C unit"
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci#define IOP3XX_ICR_UE		0x0040	/* 1=Unit Enable */
328c2ecf20Sopenharmony_ci/*
338c2ecf20Sopenharmony_ci * "NOTE: To avoid I2C bus integrity problems,
348c2ecf20Sopenharmony_ci * the user needs to ensure that the GPIO Output Data Register -
358c2ecf20Sopenharmony_ci * GPOD bits associated with an I2C port are cleared prior to setting
368c2ecf20Sopenharmony_ci * the enable bit for that I2C serial port.
378c2ecf20Sopenharmony_ci * The user prepares to enable I2C port 0 and
388c2ecf20Sopenharmony_ci * I2C port 1 by clearing GPOD bits 7:6 and GPOD bits 5:4, respectively.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define IOP3XX_ICR_SCLEN	0x0020	/* 1=SCL enable for master mode */
418c2ecf20Sopenharmony_ci#define IOP3XX_ICR_MABORT	0x0010	/* 1=Send a STOP with no data
428c2ecf20Sopenharmony_ci					 * NB TBYTE must be clear */
438c2ecf20Sopenharmony_ci#define IOP3XX_ICR_TBYTE	0x0008	/* 1=Send/Receive a byte. i2c clears */
448c2ecf20Sopenharmony_ci#define IOP3XX_ICR_NACK		0x0004	/* 1=reply with NACK */
458c2ecf20Sopenharmony_ci#define IOP3XX_ICR_MSTOP	0x0002	/* 1=send a STOP after next data byte */
468c2ecf20Sopenharmony_ci#define IOP3XX_ICR_MSTART	0x0001	/* 1=initiate a START */
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define IOP3XX_ISR_BERRD	0x0400	/* 1=BUS ERROR Detected */
508c2ecf20Sopenharmony_ci#define IOP3XX_ISR_SAD		0x0200	/* 1=Slave ADdress Detected */
518c2ecf20Sopenharmony_ci#define IOP3XX_ISR_GCAD		0x0100	/* 1=General Call Address Detected */
528c2ecf20Sopenharmony_ci#define IOP3XX_ISR_RXFULL	0x0080	/* 1=Receive Full */
538c2ecf20Sopenharmony_ci#define IOP3XX_ISR_TXEMPTY	0x0040	/* 1=Transmit Empty */
548c2ecf20Sopenharmony_ci#define IOP3XX_ISR_ALD		0x0020	/* 1=Arbitration Loss Detected */
558c2ecf20Sopenharmony_ci#define IOP3XX_ISR_SSD		0x0010	/* 1=Slave STOP Detected */
568c2ecf20Sopenharmony_ci#define IOP3XX_ISR_BBUSY	0x0008	/* 1=Bus BUSY */
578c2ecf20Sopenharmony_ci#define IOP3XX_ISR_UNITBUSY	0x0004	/* 1=Unit Busy */
588c2ecf20Sopenharmony_ci#define IOP3XX_ISR_NACK		0x0002	/* 1=Unit Rx or Tx a NACK */
598c2ecf20Sopenharmony_ci#define IOP3XX_ISR_RXREAD	0x0001	/* 1=READ 0=WRITE (R/W bit of slave addr */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define IOP3XX_ISR_CLEARBITS	0x07f0
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define IOP3XX_ISAR_SAMASK	0x007f
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define IOP3XX_IDBR_MASK	0x00ff
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define IOP3XX_IBMR_SCL		0x0002
688c2ecf20Sopenharmony_ci#define IOP3XX_IBMR_SDA		0x0001
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define IOP3XX_GPOD_I2C0	0x00c0	/* clear these bits to enable ch0 */
718c2ecf20Sopenharmony_ci#define IOP3XX_GPOD_I2C1	0x0030	/* clear these bits to enable ch1 */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define MYSAR			0	/* default slave address */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define I2C_ERR			321
768c2ecf20Sopenharmony_ci#define I2C_ERR_BERR		(I2C_ERR+0)
778c2ecf20Sopenharmony_ci#define I2C_ERR_ALD		(I2C_ERR+1)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define	CR_OFFSET		0
818c2ecf20Sopenharmony_ci#define	SR_OFFSET		0x4
828c2ecf20Sopenharmony_ci#define	SAR_OFFSET		0x8
838c2ecf20Sopenharmony_ci#define	DBR_OFFSET		0xc
848c2ecf20Sopenharmony_ci#define	CCR_OFFSET		0x10
858c2ecf20Sopenharmony_ci#define	BMR_OFFSET		0x14
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define	IOP3XX_I2C_IO_SIZE	0x18
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistruct i2c_algo_iop3xx_data {
908c2ecf20Sopenharmony_ci	void __iomem *ioaddr;
918c2ecf20Sopenharmony_ci	wait_queue_head_t waitq;
928c2ecf20Sopenharmony_ci	spinlock_t lock;
938c2ecf20Sopenharmony_ci	u32 SR_enabled, SR_received;
948c2ecf20Sopenharmony_ci	int id;
958c2ecf20Sopenharmony_ci	struct gpio_desc *gpio_scl;
968c2ecf20Sopenharmony_ci	struct gpio_desc *gpio_sda;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#endif /* I2C_IOP3XX_H */
100