1*c7fb772bSthorpej /* $NetBSD: sbsmbus.c,v 1.19 2021/08/07 16:18:59 thorpej Exp $ */
2f4e42e7eSsimonb
3f4e42e7eSsimonb /*
4f4e42e7eSsimonb * Copyright 2002 Wasabi Systems, Inc.
5f4e42e7eSsimonb * All rights reserved.
6f4e42e7eSsimonb *
7f4e42e7eSsimonb * Written by Simon Burge for Wasabi Systems, Inc.
8f4e42e7eSsimonb *
9f4e42e7eSsimonb * Redistribution and use in source and binary forms, with or without
10f4e42e7eSsimonb * modification, are permitted provided that the following conditions
11f4e42e7eSsimonb * are met:
12f4e42e7eSsimonb * 1. Redistributions of source code must retain the above copyright
13f4e42e7eSsimonb * notice, this list of conditions and the following disclaimer.
14f4e42e7eSsimonb * 2. Redistributions in binary form must reproduce the above copyright
15f4e42e7eSsimonb * notice, this list of conditions and the following disclaimer in the
16f4e42e7eSsimonb * documentation and/or other materials provided with the distribution.
17f4e42e7eSsimonb * 3. All advertising materials mentioning features or use of this software
18f4e42e7eSsimonb * must display the following acknowledgement:
19f4e42e7eSsimonb * This product includes software developed for the NetBSD Project by
20f4e42e7eSsimonb * Wasabi Systems, Inc.
21f4e42e7eSsimonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22f4e42e7eSsimonb * or promote products derived from this software without specific prior
23f4e42e7eSsimonb * written permission.
24f4e42e7eSsimonb *
25f4e42e7eSsimonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26f4e42e7eSsimonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27f4e42e7eSsimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28f4e42e7eSsimonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29f4e42e7eSsimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30f4e42e7eSsimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31f4e42e7eSsimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32f4e42e7eSsimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33f4e42e7eSsimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34f4e42e7eSsimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35f4e42e7eSsimonb * POSSIBILITY OF SUCH DAMAGE.
36f4e42e7eSsimonb */
37f4e42e7eSsimonb
384b2744bfSlukem #include <sys/cdefs.h>
39*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: sbsmbus.c,v 1.19 2021/08/07 16:18:59 thorpej Exp $");
404b2744bfSlukem
41f4e42e7eSsimonb #include <sys/param.h>
42f4e42e7eSsimonb #include <sys/device.h>
43f4e42e7eSsimonb #include <sys/systm.h>
44f4e42e7eSsimonb
457ed56e8cSmrg #include <evbmips/sbmips/swarm.h>
46f4e42e7eSsimonb #include <mips/sibyte/dev/sbsmbusvar.h>
47f4e42e7eSsimonb
4896c9d84cSsimonb #include <dev/smbus/x1241reg.h>
4996c9d84cSsimonb #include <dev/smbus/m41t81reg.h>
5096c9d84cSsimonb
51f4e42e7eSsimonb #include "locators.h"
52f4e42e7eSsimonb
53916ee5b6Smatt static int smbus_match(device_t, cfdata_t, void *);
54916ee5b6Smatt static void smbus_attach(device_t, device_t, void *);
55f4e42e7eSsimonb static int smbus_print(void *, const char *);
56f4e42e7eSsimonb
57916ee5b6Smatt CFATTACH_DECL_NEW(smbus, 0,
5889bf5a8fSthorpej smbus_match, smbus_attach, NULL, NULL);
59f4e42e7eSsimonb
60f4e42e7eSsimonb /* autoconfiguration match information for zbbus children */
61f4e42e7eSsimonb struct smbus_attach_locs {
62f4e42e7eSsimonb int sa_interface;
63f4e42e7eSsimonb int sa_device;
64f4e42e7eSsimonb };
65f4e42e7eSsimonb
66f4e42e7eSsimonb /* XXX XXX this table should be imported from machine-specific code XXX XXX */
67f4e42e7eSsimonb static const struct smbus_attach_locs smbus_devs[] = {
6896c9d84cSsimonb { X1241_SMBUS_CHAN, X1241_RTC_SLAVEADDR },
6996c9d84cSsimonb { M41T81_SMBUS_CHAN, M41T81_SLAVEADDR },
70f4e42e7eSsimonb };
71f4e42e7eSsimonb
72f4e42e7eSsimonb static int found = 0;
73f4e42e7eSsimonb
74f4e42e7eSsimonb static int
smbus_match(device_t parent,cfdata_t match,void * aux)75916ee5b6Smatt smbus_match(device_t parent, cfdata_t match, void *aux)
76f4e42e7eSsimonb {
77f4e42e7eSsimonb
78f4e42e7eSsimonb /* 2 SMBus's on the BCM112x and BCM1250 */
79f4e42e7eSsimonb return (found < 2);
80f4e42e7eSsimonb }
81f4e42e7eSsimonb
82f4e42e7eSsimonb static void
smbus_attach(device_t parent,device_t self,void * aux)83916ee5b6Smatt smbus_attach(device_t parent, device_t self, void *aux)
84f4e42e7eSsimonb {
85f4e42e7eSsimonb struct smbus_attach_args sa;
86f4e42e7eSsimonb int i;
87fa3cb84dSdrochner int locs[SMBUSCF_NLOCS];
88f4e42e7eSsimonb
89f4e42e7eSsimonb found++;
9082bf97dcSmatt aprint_normal("\n");
91f4e42e7eSsimonb
9282bf97dcSmatt for (i = 0; i < __arraycount(smbus_devs); i++) {
9339cd836eSthorpej if (device_unit(self) != smbus_devs[i].sa_interface)
94f4e42e7eSsimonb continue;
95f4e42e7eSsimonb
96f4e42e7eSsimonb memset(&sa, 0, sizeof sa);
97f4e42e7eSsimonb sa.sa_interface = smbus_devs[i].sa_interface;
98f4e42e7eSsimonb sa.sa_device = smbus_devs[i].sa_device;
99a02e2488Sdrochner
100fa3cb84dSdrochner locs[SMBUSCF_CHAN] = 0; /* XXX */
101fa3cb84dSdrochner locs[SMBUSCF_DEV] = smbus_devs[i].sa_device;
102a02e2488Sdrochner
1032685996bSthorpej config_found(self, &sa, smbus_print,
104*c7fb772bSthorpej CFARGS(.submatch = config_stdsubmatch,
105*c7fb772bSthorpej .locators = locs));
106f4e42e7eSsimonb }
107f4e42e7eSsimonb }
108f4e42e7eSsimonb
109f4e42e7eSsimonb
110f4e42e7eSsimonb static int
smbus_print(void * aux,const char * pnp)111f4e42e7eSsimonb smbus_print(void *aux, const char *pnp)
112f4e42e7eSsimonb {
113f4e42e7eSsimonb struct smbus_attach_args *sa = aux;
114f4e42e7eSsimonb
115f4e42e7eSsimonb if (pnp)
116dbb0f0ebSthorpej aprint_normal("rtc0 at %s", pnp); /* XXX! */
117dbb0f0ebSthorpej aprint_normal(" device 0x%x", sa->sa_device);
118f4e42e7eSsimonb
119f4e42e7eSsimonb return (UNCONF);
120f4e42e7eSsimonb }
121