1 /* $NetBSD: dbcool_ki2c.c,v 1.5 2009/11/02 21:38:07 christos Exp $ */
4 * Copyright (C) 2005 Michael Lorenz
5 * Copyright (C) 2008 Paul Goyette
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * a driver for the dbCool family of environmental controllers found in the
30 * iBook G4 and probably other Apple machines
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: dbcool_ki2c.c,v 1.5 2009/11/02 21:38:07 christos Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/device.h>
40 #include <sys/malloc.h>
41 #include <sys/sysctl.h>
43 #include <uvm/uvm_extern.h>
45 #include <dev/ofw/openfirm.h>
46 #include <macppc/dev/ki2cvar.h>
48 #include <dev/i2c/dbcool_var.h>
49 #include <dev/i2c/dbcool_reg.h>
51 static void dbcool_ki2c_attach(device_t
, device_t
, void *);
52 static int dbcool_ki2c_match(device_t
, cfdata_t
, void *);
53 static uint8_t dbcool_ki2c_readreg(struct dbcool_chipset
*, uint8_t);
54 static void dbcool_ki2c_writereg(struct dbcool_chipset
*, uint8_t, uint8_t);
56 CFATTACH_DECL_NEW(dbcool_ki2c
, sizeof(struct dbcool_softc
),
57 dbcool_ki2c_match
, dbcool_ki2c_attach
, NULL
, NULL
);
60 dbcool_ki2c_match(device_t parent
, cfdata_t cf
, void *aux
)
62 struct ki2c_confargs
*ka
= aux
;
65 if (strcmp(ka
->ka_name
, "fan") != 0)
68 memset(compat
, 0, sizeof(compat
));
69 OF_getprop(ka
->ka_node
, "compatible", compat
, sizeof(compat
));
70 if (strcmp(compat
, "adt7467") != 0 && strcmp(compat
, "adt7460") != 0)
77 dbcool_ki2c_attach(device_t parent
, device_t self
, void *aux
)
79 struct dbcool_softc
*sc
= device_private(self
);
80 struct ki2c_confargs
*ka
= aux
;
86 sc
->sc_dc
.dc_tag
= ka
->ka_tag
;
87 sc
->sc_dc
.dc_addr
= ka
->ka_addr
& 0xfe;
88 sc
->sc_dc
.dc_readreg
= dbcool_ki2c_readreg
;
89 sc
->sc_dc
.dc_writereg
= dbcool_ki2c_writereg
;
91 if (dbcool_chip_ident(&sc
->sc_dc
) < 0) {
92 aprint_error_dev(self
, "Unrecognized dbCool chip - "
97 ver
= sc
->sc_dc
.dc_readreg(&sc
->sc_dc
, DBCOOL_REVISION_REG
);
99 if (sc
->sc_dc
.dc_chip
->flags
& DBCFLAG_4BIT_VER
)
100 aprint_normal_dev(self
, "%s dBCool(tm) Controller "
101 "(rev 0x%02x, stepping 0x%02x)\n", sc
->sc_dc
.dc_chip
->name
,
102 ver
>> 4, ver
& 0x0f);
104 aprint_normal_dev(self
, "%s dBCool(tm) Controller "
105 "(rev 0x%04x)\n", sc
->sc_dc
.dc_chip
->name
, ver
);
109 if (!pmf_device_register(self
, dbcool_pmf_suspend
, dbcool_pmf_resume
))
110 aprint_error_dev(self
, "couldn't establish power handler\n");
114 dbcool_ki2c_readreg(struct dbcool_chipset
*dc
, uint8_t reg
)
118 iic_acquire_bus(dc
->dc_tag
, 0);
119 iic_exec(dc
->dc_tag
, I2C_OP_READ
, dc
->dc_addr
, ®
, 1, &data
, 1, 0);
120 iic_release_bus(dc
->dc_tag
, 0);
125 dbcool_ki2c_writereg(struct dbcool_chipset
*dc
, uint8_t reg
, uint8_t data
)
127 uint8_t mdata
[2] = {reg
, data
};
129 iic_acquire_bus(dc
->dc_tag
, 0);
130 iic_exec(dc
->dc_tag
, I2C_OP_WRITE
, dc
->dc_addr
, &mdata
, 2, NULL
, 0, 0);
131 iic_release_bus(dc
->dc_tag
, 0);