xref: /freebsd/sys/dev/chromebook_platform/chromebook_platform.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * Copyright (c) 2016 The FreeBSD Project.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/errno.h>
35 #include <sys/bus.h>
36 
37 #include <dev/pci/pcivar.h>
38 #include <dev/pci/pcireg.h>
39 #include <dev/iicbus/iicbus.h>
40 #include <dev/iicbus/iiconf.h>
41 
42 /*
43  * Driver that attaches I2C devices.
44  */
45 static struct {
46 	uint32_t	pci_id;
47 	const char	*name;
48 	uint8_t		addr;
49 } slaves[] = {
50 	{ 0x9c628086,	"isl",		0x88 },
51 	{ 0x9c618086,	"cyapa",	0xce },
52 };
53 
54 static void
55 chromebook_i2c_identify(driver_t *driver, device_t bus)
56 {
57 	device_t controller;
58 	device_t child;
59 	int i;
60 
61 	/*
62 	 * A stopgap approach to preserve the status quo.
63 	 * A more intelligent approach is required to correctly
64 	 * identify a machine model and hardware available on it.
65 	 * For instance, DMI could be used.
66 	 * See http://lxr.free-electrons.com/source/drivers/platform/chrome/chromeos_laptop.c
67 	 */
68 	controller = device_get_parent(bus);
69 	if (strcmp(device_get_name(controller), "ig4iic") != 0)
70 		return;
71 
72 	for (i = 0; i < nitems(slaves); i++) {
73 		if (device_find_child(bus, slaves[i].name, -1) != NULL)
74 			continue;
75 		if (slaves[i].pci_id != pci_get_devid(controller))
76 			continue;
77 		child = BUS_ADD_CHILD(bus, 0, slaves[i].name, -1);
78 		if (child != NULL)
79 			iicbus_set_addr(child, slaves[i].addr);
80 	}
81 }
82 
83 static device_method_t chromebook_i2c_methods[] = {
84 	DEVMETHOD(device_identify,	chromebook_i2c_identify),
85 	{ 0, 0 }
86 };
87 
88 static driver_t chromebook_i2c_driver = {
89 	"chromebook_i2c",
90 	chromebook_i2c_methods,
91 	0	/* no softc */
92 };
93 
94 DRIVER_MODULE(chromebook_i2c, iicbus, chromebook_i2c_driver, 0, 0);
95 MODULE_VERSION(chromebook_i2c, 1);
96 
97