ki2cvar.h revision 1.7 1 1.7 macallan /* $NetBSD: ki2cvar.h,v 1.7 2025/07/05 15:16:08 macallan Exp $ */
2 1.1 macallan /* Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp */
3 1.1 macallan
4 1.1 macallan /*-
5 1.1 macallan * Copyright (c) 2001 Tsubai Masanari. All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan * 3. The name of the author may not be used to endorse or promote products
16 1.1 macallan * derived from this software without specific prior written permission.
17 1.1 macallan *
18 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 1.1 macallan * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 macallan */
29 1.1 macallan
30 1.1 macallan #ifndef KI2CVAR_H
31 1.1 macallan #define KI2CVAR_H
32 1.1 macallan
33 1.1 macallan #include <sys/param.h>
34 1.1 macallan #include <sys/device.h>
35 1.1 macallan #include <sys/systm.h>
36 1.5 macallan #include <machine/autoconf.h>
37 1.1 macallan
38 1.1 macallan #include <dev/i2c/i2cvar.h>
39 1.1 macallan
40 1.1 macallan /* Keywest I2C Register offsets */
41 1.1 macallan #define MODE 0
42 1.1 macallan #define CONTROL 1
43 1.1 macallan #define STATUS 2
44 1.1 macallan #define ISR 3
45 1.1 macallan #define IER 4
46 1.1 macallan #define ADDR 5
47 1.1 macallan #define SUBADDR 6
48 1.1 macallan #define DATA 7
49 1.1 macallan
50 1.1 macallan /* MODE */
51 1.1 macallan #define I2C_SPEED 0x03 /* Speed mask */
52 1.1 macallan #define I2C_100kHz 0x00
53 1.1 macallan #define I2C_50kHz 0x01
54 1.1 macallan #define I2C_25kHz 0x02
55 1.1 macallan #define I2C_MODE 0x0c /* Mode mask */
56 1.1 macallan #define I2C_DUMBMODE 0x00 /* Dumb mode */
57 1.1 macallan #define I2C_STDMODE 0x04 /* Standard mode */
58 1.1 macallan #define I2C_STDSUBMODE 0x08 /* Standard mode + sub address */
59 1.1 macallan #define I2C_COMBMODE 0x0c /* Combined mode */
60 1.1 macallan #define I2C_PORT 0xf0 /* Port mask */
61 1.1 macallan
62 1.1 macallan /* CONTROL */
63 1.1 macallan #define I2C_CT_AAK 0x01 /* Send AAK */
64 1.1 macallan #define I2C_CT_ADDR 0x02 /* Send address(es) */
65 1.1 macallan #define I2C_CT_STOP 0x04 /* Send STOP */
66 1.1 macallan #define I2C_CT_START 0x08 /* Send START */
67 1.1 macallan
68 1.1 macallan /* STATUS */
69 1.1 macallan #define I2C_ST_BUSY 0x01 /* Busy */
70 1.1 macallan #define I2C_ST_LASTAAK 0x02 /* Last AAK */
71 1.1 macallan #define I2C_ST_LASTRW 0x04 /* Last R/W */
72 1.1 macallan #define I2C_ST_SDA 0x08 /* SDA */
73 1.1 macallan #define I2C_ST_SCL 0x10 /* SCL */
74 1.1 macallan
75 1.1 macallan /* ISR/IER */
76 1.1 macallan #define I2C_INT_DATA 0x01 /* Data byte sent/received */
77 1.1 macallan #define I2C_INT_ADDR 0x02 /* Address sent */
78 1.1 macallan #define I2C_INT_STOP 0x04 /* STOP condition sent */
79 1.1 macallan #define I2C_INT_START 0x08 /* START condition sent */
80 1.6 macallan #define I2C_INT_ALL 0x0f
81 1.1 macallan
82 1.1 macallan /* I2C flags */
83 1.1 macallan #define I2C_BUSY 0x01
84 1.1 macallan #define I2C_READING 0x02
85 1.1 macallan #define I2C_ERROR 0x04
86 1.1 macallan
87 1.1 macallan struct ki2c_softc {
88 1.4 macallan device_t sc_dev;
89 1.5 macallan bus_space_tag_t sc_tag;
90 1.5 macallan bus_space_handle_t sc_bh;
91 1.1 macallan int sc_regstep;
92 1.1 macallan
93 1.1 macallan struct i2c_controller sc_i2c;
94 1.1 macallan
95 1.6 macallan kcondvar_t sc_todev;
96 1.6 macallan kmutex_t sc_todevmtx;
97 1.1 macallan int sc_flags;
98 1.1 macallan u_char *sc_data;
99 1.1 macallan int sc_resid;
100 1.7 macallan int sc_poll;
101 1.1 macallan };
102 1.1 macallan
103 1.1 macallan struct ki2c_confargs {
104 1.1 macallan char *ka_name; /* device name */
105 1.1 macallan int ka_node;
106 1.1 macallan i2c_tag_t ka_tag; /* our controller */
107 1.1 macallan i2c_addr_t ka_addr; /* address of device */
108 1.1 macallan };
109 1.1 macallan
110 1.1 macallan #endif
111