1*601e1783Sthorpej /* $NetBSD: i80312_i2c.c,v 1.7 2019/12/22 23:23:30 thorpej Exp $ */
2d322684fSthorpej
3d322684fSthorpej /*
4d322684fSthorpej * Copyright (c) 2003 Wasabi Systems, Inc.
5d322684fSthorpej * All rights reserved.
6d322684fSthorpej *
7d322684fSthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8d322684fSthorpej *
9d322684fSthorpej * Redistribution and use in source and binary forms, with or without
10d322684fSthorpej * modification, are permitted provided that the following conditions
11d322684fSthorpej * are met:
12d322684fSthorpej * 1. Redistributions of source code must retain the above copyright
13d322684fSthorpej * notice, this list of conditions and the following disclaimer.
14d322684fSthorpej * 2. Redistributions in binary form must reproduce the above copyright
15d322684fSthorpej * notice, this list of conditions and the following disclaimer in the
16d322684fSthorpej * documentation and/or other materials provided with the distribution.
17d322684fSthorpej * 3. All advertising materials mentioning features or use of this software
18d322684fSthorpej * must display the following acknowledgement:
19d322684fSthorpej * This product includes software developed for the NetBSD Project by
20d322684fSthorpej * Wasabi Systems, Inc.
21d322684fSthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22d322684fSthorpej * or promote products derived from this software without specific prior
23d322684fSthorpej * written permission.
24d322684fSthorpej *
25d322684fSthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26d322684fSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27d322684fSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28d322684fSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29d322684fSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30d322684fSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31d322684fSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32d322684fSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33d322684fSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34d322684fSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35d322684fSthorpej * POSSIBILITY OF SUCH DAMAGE.
36d322684fSthorpej */
37d322684fSthorpej
38d322684fSthorpej /*
39d322684fSthorpej * Intel i80321 I/O Processor I2C Controller Unit support.
40d322684fSthorpej */
41d322684fSthorpej
42d322684fSthorpej #include <sys/cdefs.h>
43*601e1783Sthorpej __KERNEL_RCSID(0, "$NetBSD: i80312_i2c.c,v 1.7 2019/12/22 23:23:30 thorpej Exp $");
44d322684fSthorpej
45d322684fSthorpej #include <sys/param.h>
46065b6ba2Sad #include <sys/mutex.h>
47d322684fSthorpej #include <sys/systm.h>
48d322684fSthorpej #include <sys/device.h>
49d322684fSthorpej #include <sys/kernel.h>
50d322684fSthorpej
51ed9977b1Sdyoung #include <sys/bus.h>
52d322684fSthorpej #include <machine/intr.h>
53d322684fSthorpej
54d322684fSthorpej #include <arm/xscale/i80312var.h>
55d322684fSthorpej
56d322684fSthorpej #include <dev/i2c/i2cvar.h>
57d322684fSthorpej
58d322684fSthorpej #include <arm/xscale/iopi2cvar.h>
59d322684fSthorpej #include <arm/xscale/iopi2creg.h>
60d322684fSthorpej
61d322684fSthorpej static int
iic312_match(device_t parent,cfdata_t cf,void * aux)620c08541dSjakllsch iic312_match(device_t parent, cfdata_t cf, void *aux)
63d322684fSthorpej {
64d322684fSthorpej struct iopxs_attach_args *ia = aux;
65d322684fSthorpej
66d322684fSthorpej if (strcmp(cf->cf_name, ia->ia_name) == 0)
67d322684fSthorpej return (1);
68d322684fSthorpej
69d322684fSthorpej return (0);
70d322684fSthorpej }
71d322684fSthorpej
72d322684fSthorpej static void
iic312_attach(device_t parent,device_t self,void * aux)730c08541dSjakllsch iic312_attach(device_t parent, device_t self, void *aux)
74d322684fSthorpej {
750c08541dSjakllsch struct iopiic_softc *sc = device_private(self);
76d322684fSthorpej struct iopxs_attach_args *ia = aux;
77d322684fSthorpej int error;
78d322684fSthorpej
79d322684fSthorpej aprint_naive(": I2C controller\n");
80d322684fSthorpej aprint_normal(": I2C controller\n");
81d322684fSthorpej
820c08541dSjakllsch sc->sc_dev = self;
83d322684fSthorpej sc->sc_st = ia->ia_st;
84d322684fSthorpej if ((error = bus_space_subregion(sc->sc_st, ia->ia_sh,
85d322684fSthorpej ia->ia_offset, ia->ia_size,
86d322684fSthorpej &sc->sc_sh)) != 0) {
870c08541dSjakllsch aprint_error_dev(self,
880c08541dSjakllsch "unable to subregion registers, error = %d\n", error);
89d322684fSthorpej return;
90d322684fSthorpej }
91d322684fSthorpej
92d322684fSthorpej /* XXX Reset the I2C unit? */
93d322684fSthorpej
94d322684fSthorpej /* XXX We don't currently use interrupts. Fix this some day. */
95d322684fSthorpej #if 0
96d322684fSthorpej sc->sc_ih = i80321_intr_establish(ICU_INT_I2C, IPL_BIO,
97d322684fSthorpej iopiic_intr, sc);
98d322684fSthorpej if (sc->sc_ih == NULL) {
990c08541dSjakllsch aprint_error_dev(self,
1000c08541dSjakllsch "unable to establish interrupt handler\n");
101d322684fSthorpej return;
102d322684fSthorpej }
103d322684fSthorpej #endif
104d322684fSthorpej
105d322684fSthorpej /*
106a1f606d3Slukem * Enable the I2C unit as a master running at 100.0 kHz (ICCR=0x1f4
107d322684fSthorpej * per p.12-8 of the i80312 developer's manual).
108d322684fSthorpej * No, we do not support slave mode.
109d322684fSthorpej */
110d322684fSthorpej sc->sc_icr = IIC_ICR_GCD | IIC_ICR_UE | IIC_ICR_SCLE;
111d322684fSthorpej bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ICR, 0);
112d322684fSthorpej bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ICCR, 0x1f4);
113d322684fSthorpej bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ISAR, 0);
114d322684fSthorpej bus_space_write_4(sc->sc_st, sc->sc_sh, IIC_ICR, sc->sc_icr);
115d322684fSthorpej
116d322684fSthorpej iopiic_attach(sc);
117d322684fSthorpej }
118d322684fSthorpej
1190c08541dSjakllsch CFATTACH_DECL_NEW(iopiic, sizeof(struct iopiic_softc),
120d322684fSthorpej iic312_match, iic312_attach, NULL, NULL);
121