Home | History | Annotate | Line # | Download | only in i2c
twl4030.c revision 1.2
      1  1.2  jmcneill /* $NetBSD: twl4030.c,v 1.2 2019/11/01 09:49:55 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2019 Jared McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill #include <sys/cdefs.h>
     30  1.2  jmcneill __KERNEL_RCSID(0, "$NetBSD: twl4030.c,v 1.2 2019/11/01 09:49:55 jmcneill Exp $");
     31  1.1  jmcneill 
     32  1.1  jmcneill #include <sys/param.h>
     33  1.1  jmcneill #include <sys/systm.h>
     34  1.1  jmcneill #include <sys/kernel.h>
     35  1.1  jmcneill #include <sys/device.h>
     36  1.1  jmcneill #include <sys/conf.h>
     37  1.1  jmcneill #include <sys/bus.h>
     38  1.1  jmcneill #include <sys/kmem.h>
     39  1.1  jmcneill #include <sys/gpio.h>
     40  1.1  jmcneill 
     41  1.1  jmcneill #include <dev/i2c/i2cvar.h>
     42  1.1  jmcneill 
     43  1.1  jmcneill #include <dev/fdt/fdtvar.h>
     44  1.1  jmcneill 
     45  1.1  jmcneill #define	TWL_PIN_COUNT	16
     46  1.1  jmcneill 
     47  1.1  jmcneill /* TWL4030 is a multi-function IC. Each module is at a separate I2C address */
     48  1.1  jmcneill #define	ADDR_USB	0x00
     49  1.1  jmcneill #define	ADDR_INT	0x01
     50  1.1  jmcneill #define	ADDR_AUX	0x02
     51  1.1  jmcneill #define	ADDR_POWER	0x03
     52  1.1  jmcneill 
     53  1.2  jmcneill /* INTBR registers */
     54  1.2  jmcneill #define	IDCODE_7_0	0x85
     55  1.2  jmcneill #define	IDCODE_15_8	0x86
     56  1.2  jmcneill #define	IDCODE_23_16	0x87
     57  1.2  jmcneill #define	IDCODE_31_24	0x88
     58  1.2  jmcneill 
     59  1.1  jmcneill /* GPIO registers */
     60  1.1  jmcneill #define	GPIOBASE		0x98
     61  1.1  jmcneill #define	GPIODATAIN(pin)		(GPIOBASE + 0x00 + (pin) / 8)
     62  1.1  jmcneill #define	GPIODATADIR(pin)	(GPIOBASE + 0x03 + (pin) / 8)
     63  1.1  jmcneill #define	CLEARGPIODATAOUT(pin)	(GPIOBASE + 0x09 + (pin) / 8)
     64  1.1  jmcneill #define	SETGPIODATAOUT(pin)	(GPIOBASE + 0x0c + (pin) / 8)
     65  1.1  jmcneill #define	 PIN_BIT(pin)		__BIT((pin) % 8)
     66  1.1  jmcneill #define	GPIOPUPDCTR(pin)	(GPIOBASE + 0x13 + (n) / 4)
     67  1.1  jmcneill #define	 PUPD_BITS(pin)		__BITS((pin) % 4 + 1, (pin) % 4)
     68  1.1  jmcneill 
     69  1.2  jmcneill /* POWER registers */
     70  1.2  jmcneill #define	SECONDS_REG		0x1c
     71  1.2  jmcneill #define	MINUTES_REG		0x1d
     72  1.2  jmcneill #define	HOURS_REG		0x1e
     73  1.2  jmcneill #define	DAYS_REG		0x1f
     74  1.2  jmcneill #define	MONTHS_REG		0x20
     75  1.2  jmcneill #define	YEARS_REG		0x21
     76  1.2  jmcneill #define	WEEKS_REG		0x22
     77  1.2  jmcneill #define	RTC_CTRL_REG		0x29
     78  1.2  jmcneill #define	 GET_TIME		__BIT(6)
     79  1.2  jmcneill #define	 STOP_RTC		__BIT(0)
     80  1.2  jmcneill 
     81  1.1  jmcneill struct twl_softc {
     82  1.1  jmcneill 	device_t	sc_dev;
     83  1.1  jmcneill 	i2c_tag_t	sc_i2c;
     84  1.1  jmcneill 	i2c_addr_t	sc_addr;
     85  1.1  jmcneill 	int		sc_phandle;
     86  1.1  jmcneill 
     87  1.1  jmcneill 	int		sc_npins;
     88  1.2  jmcneill 
     89  1.2  jmcneill 	struct todr_chip_handle sc_todr;
     90  1.1  jmcneill };
     91  1.1  jmcneill 
     92  1.1  jmcneill struct twl_pin {
     93  1.1  jmcneill 	struct twl_softc	*pin_sc;
     94  1.1  jmcneill 	int			pin_num;
     95  1.1  jmcneill 	int			pin_flags;
     96  1.1  jmcneill 	bool			pin_actlo;
     97  1.1  jmcneill };
     98  1.1  jmcneill 
     99  1.1  jmcneill static const struct device_compatible_entry compat_data[] = {
    100  1.1  jmcneill 	{ "ti,twl4030",			0 },
    101  1.1  jmcneill 	{ NULL,				0 }
    102  1.1  jmcneill };
    103  1.1  jmcneill 
    104  1.2  jmcneill static const char * const rtc_compatible[] = { "ti,twl4030-rtc", NULL };
    105  1.1  jmcneill static const char * const gpio_compatible[] = { "ti,twl4030-gpio", NULL };
    106  1.1  jmcneill 
    107  1.1  jmcneill static uint8_t
    108  1.1  jmcneill twl_read(struct twl_softc *sc, uint8_t mod, uint8_t reg, int flags)
    109  1.1  jmcneill {
    110  1.1  jmcneill 	uint8_t val = 0;
    111  1.1  jmcneill 	int error;
    112  1.1  jmcneill 
    113  1.1  jmcneill 	error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr + mod,
    114  1.1  jmcneill 	    &reg, 1, &val, 1, flags);
    115  1.1  jmcneill 	if (error != 0)
    116  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "error reading reg %#x: %d\n", reg, error);
    117  1.1  jmcneill 
    118  1.1  jmcneill 	return val;
    119  1.1  jmcneill }
    120  1.1  jmcneill 
    121  1.1  jmcneill static void
    122  1.1  jmcneill twl_write(struct twl_softc *sc, uint8_t mod, uint8_t reg, uint8_t val, int flags)
    123  1.1  jmcneill {
    124  1.1  jmcneill 	uint8_t buf[2];
    125  1.1  jmcneill 	int error;
    126  1.1  jmcneill 
    127  1.1  jmcneill 	buf[0] = reg;
    128  1.1  jmcneill 	buf[1] = val;
    129  1.1  jmcneill 
    130  1.1  jmcneill 	error = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr + mod,
    131  1.1  jmcneill 	    NULL, 0, buf, 2, flags);
    132  1.1  jmcneill 	if (error != 0)
    133  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "error writing reg %#x: %d\n", reg, error);
    134  1.1  jmcneill }
    135  1.1  jmcneill 
    136  1.1  jmcneill #define	I2C_LOCK(sc)		iic_acquire_bus((sc)->sc_i2c, I2C_F_POLL)
    137  1.1  jmcneill #define	I2C_UNLOCK(sc)		iic_release_bus((sc)->sc_i2c, I2C_F_POLL)
    138  1.1  jmcneill 
    139  1.1  jmcneill #define	INT_READ(sc, reg)	twl_read((sc), ADDR_INT, (reg), I2C_F_POLL)
    140  1.1  jmcneill #define	INT_WRITE(sc, reg, val)	twl_write((sc), ADDR_INT, (reg), (val), I2C_F_POLL)
    141  1.1  jmcneill 
    142  1.2  jmcneill #define	POWER_READ(sc, reg)	twl_read((sc), ADDR_POWER, (reg), I2C_F_POLL)
    143  1.2  jmcneill #define	POWER_WRITE(sc, reg, val) twl_write((sc), ADDR_POWER, (reg), (val), I2C_F_POLL)
    144  1.2  jmcneill 
    145  1.2  jmcneill static void
    146  1.2  jmcneill twl_rtc_enable(struct twl_softc *sc, bool onoff)
    147  1.2  jmcneill {
    148  1.2  jmcneill 	uint8_t rtc_ctrl;
    149  1.2  jmcneill 
    150  1.2  jmcneill 	rtc_ctrl = POWER_READ(sc, RTC_CTRL_REG);
    151  1.2  jmcneill 	if (onoff)
    152  1.2  jmcneill 		rtc_ctrl |= STOP_RTC;	/* 1: RTC is running */
    153  1.2  jmcneill 	else
    154  1.2  jmcneill 		rtc_ctrl &= ~STOP_RTC;	/* 0: RTC is frozen */
    155  1.2  jmcneill 	POWER_WRITE(sc, RTC_CTRL_REG, rtc_ctrl);
    156  1.2  jmcneill }
    157  1.2  jmcneill 
    158  1.2  jmcneill static int
    159  1.2  jmcneill twl_rtc_gettime(todr_chip_handle_t tch, struct clock_ymdhms *dt)
    160  1.2  jmcneill {
    161  1.2  jmcneill 	struct twl_softc *sc = tch->cookie;
    162  1.2  jmcneill 	uint8_t seconds_reg, minutes_reg, hours_reg,
    163  1.2  jmcneill 	    days_reg, months_reg, years_reg, weeks_reg;
    164  1.2  jmcneill 
    165  1.2  jmcneill 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    166  1.2  jmcneill 	seconds_reg = POWER_READ(sc, SECONDS_REG);
    167  1.2  jmcneill 	minutes_reg = POWER_READ(sc, MINUTES_REG);
    168  1.2  jmcneill 	hours_reg = POWER_READ(sc, HOURS_REG);
    169  1.2  jmcneill 	days_reg = POWER_READ(sc, DAYS_REG);
    170  1.2  jmcneill 	months_reg = POWER_READ(sc, MONTHS_REG);
    171  1.2  jmcneill 	years_reg = POWER_READ(sc, YEARS_REG);
    172  1.2  jmcneill 	weeks_reg = POWER_READ(sc, WEEKS_REG);
    173  1.2  jmcneill 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    174  1.2  jmcneill 
    175  1.2  jmcneill 	dt->dt_sec = bcdtobin(seconds_reg);
    176  1.2  jmcneill 	dt->dt_min = bcdtobin(minutes_reg);
    177  1.2  jmcneill 	dt->dt_hour = bcdtobin(hours_reg);
    178  1.2  jmcneill 	dt->dt_day = bcdtobin(days_reg);
    179  1.2  jmcneill 	dt->dt_mon = bcdtobin(months_reg);
    180  1.2  jmcneill 	dt->dt_year = bcdtobin(years_reg) + 2000;
    181  1.2  jmcneill 	dt->dt_wday = bcdtobin(weeks_reg);
    182  1.2  jmcneill 
    183  1.2  jmcneill 	return 0;
    184  1.2  jmcneill }
    185  1.2  jmcneill 
    186  1.2  jmcneill static int
    187  1.2  jmcneill twl_rtc_settime(todr_chip_handle_t tch, struct clock_ymdhms *dt)
    188  1.2  jmcneill {
    189  1.2  jmcneill 	struct twl_softc *sc = tch->cookie;
    190  1.2  jmcneill 
    191  1.2  jmcneill 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    192  1.2  jmcneill 	twl_rtc_enable(sc, false);
    193  1.2  jmcneill         POWER_WRITE(sc, SECONDS_REG, bintobcd(dt->dt_sec));
    194  1.2  jmcneill         POWER_WRITE(sc, MINUTES_REG, bintobcd(dt->dt_min));
    195  1.2  jmcneill         POWER_WRITE(sc, HOURS_REG, bintobcd(dt->dt_hour));
    196  1.2  jmcneill         POWER_WRITE(sc, DAYS_REG, bintobcd(dt->dt_day));
    197  1.2  jmcneill         POWER_WRITE(sc, MONTHS_REG, bintobcd(dt->dt_mon));
    198  1.2  jmcneill         POWER_WRITE(sc, YEARS_REG, bintobcd(dt->dt_year % 100));
    199  1.2  jmcneill         POWER_WRITE(sc, WEEKS_REG, bintobcd(dt->dt_wday));
    200  1.2  jmcneill 	twl_rtc_enable(sc, true);
    201  1.2  jmcneill 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    202  1.2  jmcneill 
    203  1.2  jmcneill 	return 0;
    204  1.2  jmcneill }
    205  1.2  jmcneill 
    206  1.1  jmcneill static int
    207  1.1  jmcneill twl_gpio_config(struct twl_softc *sc, int pin, int flags)
    208  1.1  jmcneill {
    209  1.1  jmcneill 	uint8_t dir;
    210  1.1  jmcneill 
    211  1.1  jmcneill 	KASSERT(pin >= 0 && pin < sc->sc_npins);
    212  1.1  jmcneill 
    213  1.1  jmcneill 	dir = INT_READ(sc, GPIODATADIR(pin));
    214  1.1  jmcneill 
    215  1.1  jmcneill 	switch (flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) {
    216  1.1  jmcneill 	case GPIO_PIN_INPUT:
    217  1.1  jmcneill 		dir &= ~PIN_BIT(pin);
    218  1.1  jmcneill 		break;
    219  1.1  jmcneill 	case GPIO_PIN_OUTPUT:
    220  1.1  jmcneill 		dir |= PIN_BIT(pin);
    221  1.1  jmcneill 		break;
    222  1.1  jmcneill 	default:
    223  1.1  jmcneill 		return EINVAL;
    224  1.1  jmcneill 	}
    225  1.1  jmcneill 
    226  1.1  jmcneill 	INT_WRITE(sc, GPIODATADIR(pin), dir);
    227  1.1  jmcneill 
    228  1.1  jmcneill 	return 0;
    229  1.1  jmcneill }
    230  1.1  jmcneill 
    231  1.1  jmcneill static void *
    232  1.1  jmcneill twl_gpio_acquire(device_t dev, const void *data, size_t len, int flags)
    233  1.1  jmcneill {
    234  1.1  jmcneill 	struct twl_softc * const sc = device_private(dev);
    235  1.1  jmcneill 	struct twl_pin *gpin;
    236  1.1  jmcneill 	const u_int *gpio = data;
    237  1.1  jmcneill 	int error;
    238  1.1  jmcneill 
    239  1.1  jmcneill 	if (len != 12)
    240  1.1  jmcneill 		return NULL;
    241  1.1  jmcneill 
    242  1.1  jmcneill 	const uint8_t pin = be32toh(gpio[1]) & 0xff;
    243  1.1  jmcneill 	const bool actlo = (be32toh(gpio[2]) & __BIT(0)) != 0;
    244  1.1  jmcneill 
    245  1.1  jmcneill 	if (pin >= sc->sc_npins)
    246  1.1  jmcneill 		return NULL;
    247  1.1  jmcneill 
    248  1.1  jmcneill 	I2C_LOCK(sc);
    249  1.1  jmcneill 	error = twl_gpio_config(sc, pin, flags);
    250  1.1  jmcneill 	I2C_UNLOCK(sc);
    251  1.1  jmcneill 
    252  1.1  jmcneill 	if (error != 0) {
    253  1.1  jmcneill 		device_printf(dev, "bad pin %d config %#x\n", pin, flags);
    254  1.1  jmcneill 		return NULL;
    255  1.1  jmcneill 	}
    256  1.1  jmcneill 
    257  1.1  jmcneill 	gpin = kmem_zalloc(sizeof(*gpin), KM_SLEEP);
    258  1.1  jmcneill 	gpin->pin_sc = sc;
    259  1.1  jmcneill 	gpin->pin_num = pin;
    260  1.1  jmcneill 	gpin->pin_flags = flags;
    261  1.1  jmcneill 	gpin->pin_actlo = actlo;
    262  1.1  jmcneill 
    263  1.1  jmcneill 	return gpin;
    264  1.1  jmcneill }
    265  1.1  jmcneill 
    266  1.1  jmcneill static void
    267  1.1  jmcneill twl_gpio_release(device_t dev, void *priv)
    268  1.1  jmcneill {
    269  1.1  jmcneill 	struct twl_softc * const sc = device_private(dev);
    270  1.1  jmcneill 	struct twl_pin *gpin = priv;
    271  1.1  jmcneill 
    272  1.1  jmcneill 	I2C_LOCK(sc);
    273  1.1  jmcneill 	twl_gpio_config(sc, gpin->pin_num, GPIO_PIN_INPUT);
    274  1.1  jmcneill 	I2C_UNLOCK(sc);
    275  1.1  jmcneill 
    276  1.1  jmcneill 	kmem_free(gpin, sizeof(*gpin));
    277  1.1  jmcneill }
    278  1.1  jmcneill 
    279  1.1  jmcneill static int
    280  1.1  jmcneill twl_gpio_read(device_t dev, void *priv, bool raw)
    281  1.1  jmcneill {
    282  1.1  jmcneill 	struct twl_softc * const sc = device_private(dev);
    283  1.1  jmcneill 	struct twl_pin *gpin = priv;
    284  1.1  jmcneill 	uint8_t gpio;
    285  1.1  jmcneill 	int val;
    286  1.1  jmcneill 
    287  1.1  jmcneill 	I2C_LOCK(sc);
    288  1.1  jmcneill 	gpio = INT_READ(sc, GPIODATAIN(gpin->pin_num));
    289  1.1  jmcneill 	I2C_UNLOCK(sc);
    290  1.1  jmcneill 
    291  1.1  jmcneill 	val = __SHIFTOUT(gpio, PIN_BIT(gpin->pin_num));
    292  1.1  jmcneill 	if (!raw && gpin->pin_actlo)
    293  1.1  jmcneill 		val = !val;
    294  1.1  jmcneill 
    295  1.1  jmcneill 	return val;
    296  1.1  jmcneill }
    297  1.1  jmcneill 
    298  1.1  jmcneill static void
    299  1.1  jmcneill twl_gpio_write(device_t dev, void *priv, int val, bool raw)
    300  1.1  jmcneill {
    301  1.1  jmcneill 	struct twl_softc * const sc = device_private(dev);
    302  1.1  jmcneill 	struct twl_pin *gpin = priv;
    303  1.1  jmcneill 
    304  1.1  jmcneill 	if (!raw && gpin->pin_actlo)
    305  1.1  jmcneill 		val = !val;
    306  1.1  jmcneill 
    307  1.1  jmcneill 	I2C_LOCK(sc);
    308  1.1  jmcneill 	if (val)
    309  1.1  jmcneill 		INT_WRITE(sc, SETGPIODATAOUT(gpin->pin_num), PIN_BIT(gpin->pin_num));
    310  1.1  jmcneill 	else
    311  1.1  jmcneill 		INT_WRITE(sc, CLEARGPIODATAOUT(gpin->pin_num), PIN_BIT(gpin->pin_num));
    312  1.1  jmcneill 	I2C_UNLOCK(sc);
    313  1.1  jmcneill }
    314  1.1  jmcneill 
    315  1.1  jmcneill static struct fdtbus_gpio_controller_func twl_gpio_funcs = {
    316  1.1  jmcneill 	.acquire = twl_gpio_acquire,
    317  1.1  jmcneill 	.release = twl_gpio_release,
    318  1.1  jmcneill 	.read = twl_gpio_read,
    319  1.1  jmcneill 	.write = twl_gpio_write,
    320  1.1  jmcneill };
    321  1.1  jmcneill 
    322  1.1  jmcneill static void
    323  1.2  jmcneill twl_rtc_attach(struct twl_softc *sc, const int phandle)
    324  1.2  jmcneill {
    325  1.2  jmcneill 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    326  1.2  jmcneill 	twl_rtc_enable(sc, true);
    327  1.2  jmcneill 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    328  1.2  jmcneill 
    329  1.2  jmcneill 	sc->sc_todr.todr_gettime_ymdhms = twl_rtc_gettime;
    330  1.2  jmcneill 	sc->sc_todr.todr_settime_ymdhms = twl_rtc_settime;
    331  1.2  jmcneill 	sc->sc_todr.cookie = sc;
    332  1.2  jmcneill 	fdtbus_todr_attach(sc->sc_dev, phandle, &sc->sc_todr);
    333  1.2  jmcneill }
    334  1.2  jmcneill 
    335  1.2  jmcneill static void
    336  1.1  jmcneill twl_gpio_attach(struct twl_softc *sc, const int phandle)
    337  1.1  jmcneill {
    338  1.1  jmcneill 	fdtbus_register_gpio_controller(sc->sc_dev, phandle, &twl_gpio_funcs);
    339  1.1  jmcneill }
    340  1.1  jmcneill 
    341  1.1  jmcneill static int
    342  1.1  jmcneill twl_match(device_t parent, cfdata_t match, void *aux)
    343  1.1  jmcneill {
    344  1.1  jmcneill 	struct i2c_attach_args *ia = aux;
    345  1.1  jmcneill 	int match_result;
    346  1.1  jmcneill 
    347  1.1  jmcneill 	if (iic_use_direct_match(ia, match, compat_data, &match_result))
    348  1.1  jmcneill 		return match_result;
    349  1.1  jmcneill 
    350  1.1  jmcneill 	return 0;
    351  1.1  jmcneill }
    352  1.1  jmcneill 
    353  1.1  jmcneill static void
    354  1.1  jmcneill twl_attach(device_t parent, device_t self, void *aux)
    355  1.1  jmcneill {
    356  1.1  jmcneill 	struct twl_softc * const sc = device_private(self);
    357  1.1  jmcneill 	struct i2c_attach_args *ia = aux;
    358  1.2  jmcneill 	uint32_t idcode;
    359  1.1  jmcneill 	int child;
    360  1.1  jmcneill 
    361  1.1  jmcneill 	sc->sc_dev = self;
    362  1.1  jmcneill 	sc->sc_i2c = ia->ia_tag;
    363  1.1  jmcneill 	sc->sc_addr = ia->ia_addr;
    364  1.1  jmcneill 	sc->sc_phandle = ia->ia_cookie;
    365  1.1  jmcneill 	sc->sc_npins = TWL_PIN_COUNT;
    366  1.1  jmcneill 
    367  1.1  jmcneill 	aprint_naive("\n");
    368  1.1  jmcneill 	aprint_normal(": TWL4030");
    369  1.1  jmcneill 
    370  1.1  jmcneill 	for (child = OF_child(sc->sc_phandle); child; child = OF_peer(child)) {
    371  1.1  jmcneill 		if (of_match_compatible(child, gpio_compatible)) {
    372  1.1  jmcneill 			aprint_normal(", GPIO");
    373  1.1  jmcneill 			twl_gpio_attach(sc, child);
    374  1.2  jmcneill 		} else if (of_match_compatible(child, rtc_compatible)) {
    375  1.2  jmcneill 			aprint_normal(", RTC");
    376  1.2  jmcneill 			twl_rtc_attach(sc, child);
    377  1.1  jmcneill 		}
    378  1.1  jmcneill 	}
    379  1.2  jmcneill 
    380  1.2  jmcneill 	I2C_LOCK(sc);
    381  1.2  jmcneill 	idcode = INT_READ(sc, IDCODE_7_0);
    382  1.2  jmcneill 	idcode |= (uint32_t)INT_READ(sc, IDCODE_15_8) << 8;
    383  1.2  jmcneill 	idcode |= (uint32_t)INT_READ(sc, IDCODE_23_16) << 16;
    384  1.2  jmcneill 	idcode |= (uint32_t)INT_READ(sc, IDCODE_31_24) << 24;
    385  1.2  jmcneill 	I2C_UNLOCK(sc);
    386  1.2  jmcneill 
    387  1.2  jmcneill 	aprint_normal(", IDCODE 0x%08x\n", idcode);
    388  1.1  jmcneill }
    389  1.1  jmcneill 
    390  1.1  jmcneill CFATTACH_DECL_NEW(twl, sizeof(struct twl_softc),
    391  1.1  jmcneill     twl_match, twl_attach, NULL, NULL);
    392