aboutsummaryrefslogtreecommitdiff
path: root/drivers/i2c/i2c-cortina.h
blob: 7e406b580ea300bf623258cd38cb3a733a78b979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * (C) Copyright 2019
 * Cortina Access, <www.cortina-access.com>
 */

#ifndef __CA_I2C_H_
#define __CA_I2C_H_

#include <linux/bitops.h>
#include <linux/delay.h>

#if !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
struct i2c_regs {
	u32 i2c_cfg;
	u32 i2c_ctrl;
	u32 i2c_txr;
	u32 i2c_rxr;
	u32 i2c_ack;
	u32 i2c_ie0;
	u32 i2c_int0;
	u32 i2c_ie1;
	u32 i2c_int1;
	u32 i2c_stat;
};

union ca_biw_cfg {
	struct biw_cfg {
		u32 core_en		: 1;
		u32 biw_soft_reset	: 1;
		u32 busywait_en		: 1;
		u32 stretch_en		: 1;
		u32 arb_en		: 1;
		u32 clksync_en		: 1;
		u32 rsrvd1		: 2;
		u32 spike_cnt		: 4;
		u32 rsrvd2		: 4;
		u32 prer		: 16;
	} bf;
	unsigned int wrd;
};

union ca_biw_ctrl {
	struct biw_ctrl {
		u32 biwdone	: 1;
		u32 rsrvd1	: 2;
		u32 ack_in	: 1;
		u32 write	: 1;
		u32 read	: 1;
		u32 stop	: 1;
		u32 start	: 1;
		u32 rsrvd2	: 24;
	} bf;
	unsigned int wrd;
};

union ca_biw_ack {
	struct biw_ack {
		u32 al		:1;
		u32 biw_busy	:1;
		u32 ack_out	:1;
		u32 rsrvd1	:29;
	} bf;
	unsigned int wrd;
};
#endif /* !__ASSEMBLER__*/

struct ca_i2c {
	struct i2c_regs *regs;
	unsigned int speed;
};

#define I2C_CMD_WT			0
#define I2C_CMD_RD			1

#define BIW_CTRL_DONE		BIT(0)
#define BIW_CTRL_ACK_IN		BIT(3)
#define BIW_CTRL_WRITE		BIT(4)
#define BIW_CTRL_READ		BIT(5)
#define BIW_CTRL_STOP		BIT(6)
#define BIW_CTRL_START		BIT(7)

#define I2C_BYTE_TO		(CONFIG_SYS_HZ / 500)
#define I2C_STOPDET_TO		(CONFIG_SYS_HZ / 500)
#define I2C_BYTE_TO_BB		(10)

#endif							/* __CA_I2C_H_ */