Home | History | Annotate | Line # | Download | only in i2c
axppmic.c revision 1.9.2.3
      1  1.9.2.3  pgoyette /* $NetBSD: axppmic.c,v 1.9.2.3 2018/06/25 07:25:50 pgoyette Exp $ */
      2  1.9.2.2  pgoyette 
      3  1.9.2.2  pgoyette /*-
      4  1.9.2.2  pgoyette  * Copyright (c) 2014-2018 Jared McNeill <jmcneill (at) invisible.ca>
      5  1.9.2.2  pgoyette  * All rights reserved.
      6  1.9.2.2  pgoyette  *
      7  1.9.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      8  1.9.2.2  pgoyette  * modification, are permitted provided that the following conditions
      9  1.9.2.2  pgoyette  * are met:
     10  1.9.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     11  1.9.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     12  1.9.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.9.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     14  1.9.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     15  1.9.2.2  pgoyette  *
     16  1.9.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.9.2.2  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.9.2.2  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.9.2.2  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.9.2.2  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.9.2.2  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.9.2.2  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.9.2.2  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.9.2.2  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.9.2.2  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.9.2.2  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     27  1.9.2.2  pgoyette  */
     28  1.9.2.2  pgoyette 
     29  1.9.2.2  pgoyette #include <sys/cdefs.h>
     30  1.9.2.3  pgoyette __KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.9.2.3 2018/06/25 07:25:50 pgoyette Exp $");
     31  1.9.2.2  pgoyette 
     32  1.9.2.2  pgoyette #include <sys/param.h>
     33  1.9.2.2  pgoyette #include <sys/systm.h>
     34  1.9.2.2  pgoyette #include <sys/kernel.h>
     35  1.9.2.2  pgoyette #include <sys/device.h>
     36  1.9.2.2  pgoyette #include <sys/conf.h>
     37  1.9.2.2  pgoyette #include <sys/bus.h>
     38  1.9.2.2  pgoyette #include <sys/kmem.h>
     39  1.9.2.2  pgoyette 
     40  1.9.2.2  pgoyette #include <dev/i2c/i2cvar.h>
     41  1.9.2.2  pgoyette 
     42  1.9.2.2  pgoyette #include <dev/sysmon/sysmonvar.h>
     43  1.9.2.2  pgoyette #include <dev/sysmon/sysmon_taskq.h>
     44  1.9.2.2  pgoyette 
     45  1.9.2.2  pgoyette #include <dev/fdt/fdtvar.h>
     46  1.9.2.2  pgoyette 
     47  1.9.2.2  pgoyette #define	AXP_POWER_SOURCE_REG	0x00
     48  1.9.2.2  pgoyette #define	 AXP_POWER_SOURCE_ACIN_PRESENT	__BIT(7)
     49  1.9.2.2  pgoyette #define	 AXP_POWER_SOURCE_VBUS_PRESENT	__BIT(5)
     50  1.9.2.3  pgoyette #define	 AXP_POWER_SOURCE_CHARGE_DIRECTION __BIT(2)
     51  1.9.2.2  pgoyette 
     52  1.9.2.2  pgoyette #define	AXP_POWER_MODE_REG	0x01
     53  1.9.2.2  pgoyette #define	 AXP_POWER_MODE_BATT_VALID	__BIT(4)
     54  1.9.2.2  pgoyette #define	 AXP_POWER_MODE_BATT_PRESENT	__BIT(5)
     55  1.9.2.2  pgoyette #define	 AXP_POWER_MODE_BATT_CHARGING	__BIT(6)
     56  1.9.2.2  pgoyette 
     57  1.9.2.2  pgoyette #define AXP_POWER_DISABLE_REG	0x32
     58  1.9.2.2  pgoyette #define	 AXP_POWER_DISABLE_CTRL	__BIT(7)
     59  1.9.2.2  pgoyette 
     60  1.9.2.2  pgoyette #define AXP_IRQ_ENABLE_REG(n)	(0x40 + (n) - 1)
     61  1.9.2.2  pgoyette #define	 AXP_IRQ1_ACIN_RAISE	__BIT(6)
     62  1.9.2.2  pgoyette #define	 AXP_IRQ1_ACIN_LOWER	__BIT(5)
     63  1.9.2.2  pgoyette #define	 AXP_IRQ1_VBUS_RAISE	__BIT(3)
     64  1.9.2.2  pgoyette #define	 AXP_IRQ1_VBUS_LOWER	__BIT(2)
     65  1.9.2.2  pgoyette #define AXP_IRQ_STATUS_REG(n)	(0x48 + (n) - 1)
     66  1.9.2.2  pgoyette 
     67  1.9.2.3  pgoyette #define	AXP_BATSENSE_HI_REG	0x78
     68  1.9.2.3  pgoyette #define	AXP_BATSENSE_LO_REG	0x79
     69  1.9.2.3  pgoyette 
     70  1.9.2.3  pgoyette #define	AXP_BATTCHG_HI_REG	0x7a
     71  1.9.2.3  pgoyette #define	AXP_BATTCHG_LO_REG	0x7b
     72  1.9.2.3  pgoyette 
     73  1.9.2.3  pgoyette #define	AXP_BATTDISCHG_HI_REG	0x7c
     74  1.9.2.3  pgoyette #define	AXP_BATTDISCHG_LO_REG	0x7d
     75  1.9.2.3  pgoyette 
     76  1.9.2.3  pgoyette #define	AXP_ADC_RAW(_hi, _lo)	\
     77  1.9.2.3  pgoyette 	(((u_int)(_hi) << 4) | ((lo) & 0xf))
     78  1.9.2.3  pgoyette 
     79  1.9.2.2  pgoyette #define	AXP_FUEL_GAUGE_CTRL_REG	0xb8
     80  1.9.2.2  pgoyette #define	 AXP_FUEL_GAUGE_CTRL_EN	__BIT(7)
     81  1.9.2.3  pgoyette 
     82  1.9.2.2  pgoyette #define	AXP_BATT_CAP_REG	0xb9
     83  1.9.2.2  pgoyette #define	 AXP_BATT_CAP_VALID	__BIT(7)
     84  1.9.2.2  pgoyette #define	 AXP_BATT_CAP_PERCENT	__BITS(6,0)
     85  1.9.2.2  pgoyette 
     86  1.9.2.2  pgoyette #define	AXP_BATT_CAP_WARN_REG	0xe6
     87  1.9.2.2  pgoyette #define	 AXP_BATT_CAP_WARN_LV1	__BITS(7,4)
     88  1.9.2.2  pgoyette #define	 AXP_BATT_CAP_WARN_LV2	__BITS(3,0)
     89  1.9.2.2  pgoyette 
     90  1.9.2.2  pgoyette struct axppmic_ctrl {
     91  1.9.2.2  pgoyette 	device_t	c_dev;
     92  1.9.2.2  pgoyette 
     93  1.9.2.2  pgoyette 	const char *	c_name;
     94  1.9.2.2  pgoyette 	u_int		c_min;
     95  1.9.2.2  pgoyette 	u_int		c_max;
     96  1.9.2.2  pgoyette 	u_int		c_step1;
     97  1.9.2.2  pgoyette 	u_int		c_step1cnt;
     98  1.9.2.2  pgoyette 	u_int		c_step2;
     99  1.9.2.2  pgoyette 	u_int		c_step2cnt;
    100  1.9.2.2  pgoyette 
    101  1.9.2.2  pgoyette 	uint8_t		c_enable_reg;
    102  1.9.2.2  pgoyette 	uint8_t		c_enable_mask;
    103  1.9.2.2  pgoyette 
    104  1.9.2.2  pgoyette 	uint8_t		c_voltage_reg;
    105  1.9.2.2  pgoyette 	uint8_t		c_voltage_mask;
    106  1.9.2.2  pgoyette };
    107  1.9.2.2  pgoyette 
    108  1.9.2.2  pgoyette #define AXP_CTRL(name, min, max, step, ereg, emask, vreg, vmask)	\
    109  1.9.2.2  pgoyette 	{ .c_name = (name), .c_min = (min), .c_max = (max),		\
    110  1.9.2.2  pgoyette 	  .c_step1 = (step), .c_step1cnt = (((max) - (min)) / (step)) + 1, \
    111  1.9.2.2  pgoyette 	  .c_step2 = 0, .c_step2cnt = 0,				\
    112  1.9.2.2  pgoyette 	  .c_enable_reg = (ereg), .c_enable_mask = (emask),		\
    113  1.9.2.2  pgoyette 	  .c_voltage_reg = (vreg), .c_voltage_mask = (vmask) }
    114  1.9.2.2  pgoyette 
    115  1.9.2.2  pgoyette #define AXP_CTRL2(name, min, max, step1, step1cnt, step2, step2cnt, ereg, emask, vreg, vmask) \
    116  1.9.2.2  pgoyette 	{ .c_name = (name), .c_min = (min), .c_max = (max),		\
    117  1.9.2.2  pgoyette 	  .c_step1 = (step1), .c_step1cnt = (step1cnt),			\
    118  1.9.2.2  pgoyette 	  .c_step2 = (step2), .c_step2cnt = (step2cnt),			\
    119  1.9.2.2  pgoyette 	  .c_enable_reg = (ereg), .c_enable_mask = (emask),		\
    120  1.9.2.2  pgoyette 	  .c_voltage_reg = (vreg), .c_voltage_mask = (vmask) }
    121  1.9.2.2  pgoyette 
    122  1.9.2.2  pgoyette static const struct axppmic_ctrl axp803_ctrls[] = {
    123  1.9.2.2  pgoyette 	AXP_CTRL("dldo1", 700, 3300, 100,
    124  1.9.2.2  pgoyette 		0x12, __BIT(3), 0x15, __BITS(4,0)),
    125  1.9.2.2  pgoyette 	AXP_CTRL2("dldo2", 700, 4200, 100, 28, 200, 4,
    126  1.9.2.2  pgoyette 		0x12, __BIT(4), 0x16, __BITS(4,0)),
    127  1.9.2.2  pgoyette 	AXP_CTRL("dldo3", 700, 3300, 100,
    128  1.9.2.2  pgoyette 	 	0x12, __BIT(5), 0x17, __BITS(4,0)),
    129  1.9.2.2  pgoyette 	AXP_CTRL("dldo4", 700, 3300, 100,
    130  1.9.2.2  pgoyette 		0x12, __BIT(6), 0x18, __BITS(4,0)),
    131  1.9.2.2  pgoyette 	AXP_CTRL("eldo1", 700, 1900, 50,
    132  1.9.2.2  pgoyette 		0x12, __BIT(0), 0x19, __BITS(4,0)),
    133  1.9.2.2  pgoyette 	AXP_CTRL("eldo2", 700, 1900, 50,
    134  1.9.2.2  pgoyette 		0x12, __BIT(1), 0x1a, __BITS(4,0)),
    135  1.9.2.2  pgoyette 	AXP_CTRL("eldo3", 700, 1900, 50,
    136  1.9.2.2  pgoyette 		0x12, __BIT(2), 0x1b, __BITS(4,0)),
    137  1.9.2.2  pgoyette 	AXP_CTRL("fldo1", 700, 1450, 50,
    138  1.9.2.2  pgoyette 		0x13, __BIT(2), 0x1c, __BITS(3,0)),
    139  1.9.2.2  pgoyette 	AXP_CTRL("fldo2", 700, 1450, 50,
    140  1.9.2.2  pgoyette 		0x13, __BIT(3), 0x1d, __BITS(3,0)),
    141  1.9.2.2  pgoyette 	AXP_CTRL("dcdc1", 1600, 3400, 100,
    142  1.9.2.2  pgoyette 		0x10, __BIT(0), 0x20, __BITS(4,0)),
    143  1.9.2.2  pgoyette 	AXP_CTRL2("dcdc2", 500, 1300, 10, 70, 20, 5,
    144  1.9.2.2  pgoyette 		0x10, __BIT(1), 0x21, __BITS(6,0)),
    145  1.9.2.2  pgoyette 	AXP_CTRL2("dcdc3", 500, 1300, 10, 70, 20, 5,
    146  1.9.2.2  pgoyette 		0x10, __BIT(2), 0x22, __BITS(6,0)),
    147  1.9.2.2  pgoyette 	AXP_CTRL2("dcdc4", 500, 1300, 10, 70, 20, 5,
    148  1.9.2.2  pgoyette 		0x10, __BIT(3), 0x23, __BITS(6,0)),
    149  1.9.2.2  pgoyette 	AXP_CTRL2("dcdc5", 800, 1840, 10, 33, 20, 36,
    150  1.9.2.2  pgoyette 		0x10, __BIT(4), 0x24, __BITS(6,0)),
    151  1.9.2.2  pgoyette 	AXP_CTRL2("dcdc6", 600, 1520, 10, 51, 20, 21,
    152  1.9.2.2  pgoyette 		0x10, __BIT(5), 0x25, __BITS(6,0)),
    153  1.9.2.2  pgoyette 	AXP_CTRL("aldo1", 700, 3300, 100,
    154  1.9.2.2  pgoyette 		0x13, __BIT(5), 0x28, __BITS(4,0)),
    155  1.9.2.2  pgoyette 	AXP_CTRL("aldo2", 700, 3300, 100,
    156  1.9.2.2  pgoyette 		0x13, __BIT(6), 0x29, __BITS(4,0)),
    157  1.9.2.2  pgoyette 	AXP_CTRL("aldo3", 700, 3300, 100,
    158  1.9.2.2  pgoyette 		0x13, __BIT(7), 0x2a, __BITS(4,0)),
    159  1.9.2.2  pgoyette };
    160  1.9.2.2  pgoyette 
    161  1.9.2.2  pgoyette static const struct axppmic_ctrl axp805_ctrls[] = {
    162  1.9.2.2  pgoyette 	AXP_CTRL2("dcdca", 600, 1520, 10, 51, 20, 21,
    163  1.9.2.2  pgoyette 		0x10, __BIT(0), 0x12, __BITS(6,0)),
    164  1.9.2.2  pgoyette 	AXP_CTRL("dcdcb", 1000, 2550, 50,
    165  1.9.2.2  pgoyette 		0x10, __BIT(1), 0x13, __BITS(4,0)),
    166  1.9.2.2  pgoyette 	AXP_CTRL2("dcdcc", 600, 1520, 10, 51, 20, 21,
    167  1.9.2.2  pgoyette 		0x10, __BIT(2), 0x14, __BITS(6,0)),
    168  1.9.2.2  pgoyette 	AXP_CTRL2("dcdcd", 600, 3300, 20, 46, 100, 18,
    169  1.9.2.2  pgoyette 		0x10, __BIT(3), 0x15, __BITS(5,0)),
    170  1.9.2.2  pgoyette 	AXP_CTRL("dcdce", 1100, 3400, 100,
    171  1.9.2.2  pgoyette 		0x10, __BIT(4), 0x16, __BITS(4,0)),
    172  1.9.2.2  pgoyette 	AXP_CTRL("aldo1", 700, 3300, 100,
    173  1.9.2.2  pgoyette 		0x10, __BIT(5), 0x17, __BITS(4,0)),
    174  1.9.2.2  pgoyette 	AXP_CTRL("aldo2", 700, 3400, 100,
    175  1.9.2.2  pgoyette 		0x10, __BIT(6), 0x18, __BITS(4,0)),
    176  1.9.2.2  pgoyette 	AXP_CTRL("aldo3", 700, 3300, 100,
    177  1.9.2.2  pgoyette 		0x10, __BIT(7), 0x19, __BITS(4,0)),
    178  1.9.2.2  pgoyette 	AXP_CTRL("bldo1", 700, 1900, 100,
    179  1.9.2.2  pgoyette 		0x11, __BIT(0), 0x20, __BITS(3,0)),
    180  1.9.2.2  pgoyette 	AXP_CTRL("bldo2", 700, 1900, 100,
    181  1.9.2.2  pgoyette 		0x11, __BIT(1), 0x21, __BITS(3,0)),
    182  1.9.2.2  pgoyette 	AXP_CTRL("bldo3", 700, 1900, 100,
    183  1.9.2.2  pgoyette 		0x11, __BIT(2), 0x22, __BITS(3,0)),
    184  1.9.2.2  pgoyette 	AXP_CTRL("bldo4", 700, 1900, 100,
    185  1.9.2.2  pgoyette 		0x11, __BIT(3), 0x23, __BITS(3,0)),
    186  1.9.2.2  pgoyette 	AXP_CTRL("cldo1", 700, 3300, 100,
    187  1.9.2.2  pgoyette 		0x11, __BIT(4), 0x24, __BITS(4,0)),
    188  1.9.2.2  pgoyette 	AXP_CTRL2("cldo2", 700, 4200, 100, 28, 200, 4,
    189  1.9.2.2  pgoyette 		0x11, __BIT(5), 0x25, __BITS(4,0)),
    190  1.9.2.2  pgoyette 	AXP_CTRL("cldo3", 700, 3300, 100,
    191  1.9.2.2  pgoyette 		0x11, __BIT(6), 0x26, __BITS(4,0)),
    192  1.9.2.2  pgoyette };
    193  1.9.2.2  pgoyette 
    194  1.9.2.2  pgoyette struct axppmic_irq {
    195  1.9.2.2  pgoyette 	u_int reg;
    196  1.9.2.2  pgoyette 	uint8_t mask;
    197  1.9.2.2  pgoyette };
    198  1.9.2.2  pgoyette 
    199  1.9.2.2  pgoyette #define	AXPPMIC_IRQ(_reg, _mask)	\
    200  1.9.2.2  pgoyette 	{ .reg = (_reg), .mask = (_mask) }
    201  1.9.2.2  pgoyette 
    202  1.9.2.2  pgoyette struct axppmic_config {
    203  1.9.2.2  pgoyette 	const char *name;
    204  1.9.2.2  pgoyette 	const struct axppmic_ctrl *controls;
    205  1.9.2.2  pgoyette 	u_int ncontrols;
    206  1.9.2.2  pgoyette 	u_int irq_regs;
    207  1.9.2.2  pgoyette 	bool has_battery;
    208  1.9.2.2  pgoyette 	bool has_fuel_gauge;
    209  1.9.2.2  pgoyette 	struct axppmic_irq poklirq;
    210  1.9.2.2  pgoyette 	struct axppmic_irq acinirq;
    211  1.9.2.2  pgoyette 	struct axppmic_irq vbusirq;
    212  1.9.2.2  pgoyette 	struct axppmic_irq battirq;
    213  1.9.2.2  pgoyette 	struct axppmic_irq chargeirq;
    214  1.9.2.2  pgoyette 	struct axppmic_irq chargestirq;
    215  1.9.2.3  pgoyette 	u_int batsense_step;	/* uV */
    216  1.9.2.3  pgoyette 	u_int charge_step;	/* uA */
    217  1.9.2.3  pgoyette 	u_int discharge_step;	/* uA */
    218  1.9.2.3  pgoyette 	u_int maxcap_step;	/* uAh */
    219  1.9.2.3  pgoyette 	u_int coulomb_step;	/* uAh */
    220  1.9.2.2  pgoyette };
    221  1.9.2.2  pgoyette 
    222  1.9.2.2  pgoyette enum axppmic_sensor {
    223  1.9.2.2  pgoyette 	AXP_SENSOR_ACIN_PRESENT,
    224  1.9.2.2  pgoyette 	AXP_SENSOR_VBUS_PRESENT,
    225  1.9.2.2  pgoyette 	AXP_SENSOR_BATT_PRESENT,
    226  1.9.2.2  pgoyette 	AXP_SENSOR_BATT_CHARGING,
    227  1.9.2.2  pgoyette 	AXP_SENSOR_BATT_CHARGE_STATE,
    228  1.9.2.3  pgoyette 	AXP_SENSOR_BATT_VOLTAGE,
    229  1.9.2.3  pgoyette 	AXP_SENSOR_BATT_CHARGE_CURRENT,
    230  1.9.2.3  pgoyette 	AXP_SENSOR_BATT_DISCHARGE_CURRENT,
    231  1.9.2.3  pgoyette 	AXP_SENSOR_BATT_CAPACITY_PERCENT,
    232  1.9.2.2  pgoyette 	AXP_NSENSORS
    233  1.9.2.2  pgoyette };
    234  1.9.2.2  pgoyette 
    235  1.9.2.2  pgoyette struct axppmic_softc {
    236  1.9.2.2  pgoyette 	device_t	sc_dev;
    237  1.9.2.2  pgoyette 	i2c_tag_t	sc_i2c;
    238  1.9.2.2  pgoyette 	i2c_addr_t	sc_addr;
    239  1.9.2.2  pgoyette 	int		sc_phandle;
    240  1.9.2.2  pgoyette 
    241  1.9.2.2  pgoyette 	const struct axppmic_config *sc_conf;
    242  1.9.2.2  pgoyette 
    243  1.9.2.2  pgoyette 	struct sysmon_pswitch sc_smpsw;
    244  1.9.2.2  pgoyette 
    245  1.9.2.2  pgoyette 	struct sysmon_envsys *sc_sme;
    246  1.9.2.2  pgoyette 
    247  1.9.2.2  pgoyette 	envsys_data_t	sc_sensor[AXP_NSENSORS];
    248  1.9.2.2  pgoyette 
    249  1.9.2.2  pgoyette 	u_int		sc_warn_thres;
    250  1.9.2.2  pgoyette 	u_int		sc_shut_thres;
    251  1.9.2.2  pgoyette };
    252  1.9.2.2  pgoyette 
    253  1.9.2.2  pgoyette struct axpreg_softc {
    254  1.9.2.2  pgoyette 	device_t	sc_dev;
    255  1.9.2.2  pgoyette 	i2c_tag_t	sc_i2c;
    256  1.9.2.2  pgoyette 	i2c_addr_t	sc_addr;
    257  1.9.2.2  pgoyette 	const struct axppmic_ctrl *sc_ctrl;
    258  1.9.2.2  pgoyette };
    259  1.9.2.2  pgoyette 
    260  1.9.2.2  pgoyette struct axpreg_attach_args {
    261  1.9.2.2  pgoyette 	const struct axppmic_ctrl *reg_ctrl;
    262  1.9.2.2  pgoyette 	int		reg_phandle;
    263  1.9.2.2  pgoyette 	i2c_tag_t	reg_i2c;
    264  1.9.2.2  pgoyette 	i2c_addr_t	reg_addr;
    265  1.9.2.2  pgoyette };
    266  1.9.2.2  pgoyette 
    267  1.9.2.3  pgoyette static const char *axp803_compatstrings[] = { "x-powers,axp803", NULL };
    268  1.9.2.2  pgoyette static const struct axppmic_config axp803_config = {
    269  1.9.2.2  pgoyette 	.name = "AXP803",
    270  1.9.2.2  pgoyette 	.controls = axp803_ctrls,
    271  1.9.2.2  pgoyette 	.ncontrols = __arraycount(axp803_ctrls),
    272  1.9.2.2  pgoyette 	.irq_regs = 6,
    273  1.9.2.2  pgoyette 	.has_battery = true,
    274  1.9.2.2  pgoyette 	.has_fuel_gauge = true,
    275  1.9.2.3  pgoyette 	.batsense_step = 1100,
    276  1.9.2.3  pgoyette 	.charge_step = 1000,
    277  1.9.2.3  pgoyette 	.discharge_step = 1000,
    278  1.9.2.2  pgoyette 	.poklirq = AXPPMIC_IRQ(5, __BIT(3)),
    279  1.9.2.2  pgoyette 	.acinirq = AXPPMIC_IRQ(1, __BITS(6,5)),
    280  1.9.2.2  pgoyette 	.vbusirq = AXPPMIC_IRQ(1, __BITS(3,2)),
    281  1.9.2.2  pgoyette 	.battirq = AXPPMIC_IRQ(2, __BITS(7,6)),
    282  1.9.2.2  pgoyette 	.chargeirq = AXPPMIC_IRQ(2, __BITS(3,2)),
    283  1.9.2.2  pgoyette 	.chargestirq = AXPPMIC_IRQ(4, __BITS(1,0)),
    284  1.9.2.2  pgoyette };
    285  1.9.2.2  pgoyette 
    286  1.9.2.3  pgoyette static const char *axp805_compatstrings[] = { "x-powers,axp805",
    287  1.9.2.3  pgoyette 					      "x-powers,axp806", NULL };
    288  1.9.2.2  pgoyette static const struct axppmic_config axp805_config = {
    289  1.9.2.2  pgoyette 	.name = "AXP805/806",
    290  1.9.2.2  pgoyette 	.controls = axp805_ctrls,
    291  1.9.2.2  pgoyette 	.ncontrols = __arraycount(axp805_ctrls),
    292  1.9.2.2  pgoyette 	.irq_regs = 2,
    293  1.9.2.2  pgoyette 	.poklirq = AXPPMIC_IRQ(2, __BIT(0)),
    294  1.9.2.2  pgoyette };
    295  1.9.2.2  pgoyette 
    296  1.9.2.3  pgoyette static const struct device_compatible_entry axppmic_compat_data[] = {
    297  1.9.2.3  pgoyette 	DEVICE_COMPAT_ENTRY_WITH_DATA(axp803_compatstrings, &axp803_config),
    298  1.9.2.3  pgoyette 	DEVICE_COMPAT_ENTRY_WITH_DATA(axp805_compatstrings, &axp805_config),
    299  1.9.2.3  pgoyette 	DEVICE_COMPAT_TERMINATOR
    300  1.9.2.2  pgoyette };
    301  1.9.2.2  pgoyette 
    302  1.9.2.2  pgoyette static int
    303  1.9.2.2  pgoyette axppmic_read(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t *val, int flags)
    304  1.9.2.2  pgoyette {
    305  1.9.2.2  pgoyette 	return iic_smbus_read_byte(tag, addr, reg, val, flags);
    306  1.9.2.2  pgoyette }
    307  1.9.2.2  pgoyette 
    308  1.9.2.2  pgoyette static int
    309  1.9.2.2  pgoyette axppmic_write(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t val, int flags)
    310  1.9.2.2  pgoyette {
    311  1.9.2.2  pgoyette 	return iic_smbus_write_byte(tag, addr, reg, val, flags);
    312  1.9.2.2  pgoyette }
    313  1.9.2.2  pgoyette 
    314  1.9.2.2  pgoyette static int
    315  1.9.2.2  pgoyette axppmic_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int min, u_int max)
    316  1.9.2.2  pgoyette {
    317  1.9.2.2  pgoyette 	const int flags = (cold ? I2C_F_POLL : 0);
    318  1.9.2.2  pgoyette 	u_int vol, reg_val;
    319  1.9.2.2  pgoyette 	int nstep, error;
    320  1.9.2.2  pgoyette 	uint8_t val;
    321  1.9.2.2  pgoyette 
    322  1.9.2.2  pgoyette 	if (!c->c_voltage_mask)
    323  1.9.2.2  pgoyette 		return EINVAL;
    324  1.9.2.2  pgoyette 
    325  1.9.2.2  pgoyette 	if (min < c->c_min || min > c->c_max)
    326  1.9.2.2  pgoyette 		return EINVAL;
    327  1.9.2.2  pgoyette 
    328  1.9.2.2  pgoyette 	reg_val = 0;
    329  1.9.2.2  pgoyette 	nstep = 1;
    330  1.9.2.2  pgoyette 	vol = c->c_min;
    331  1.9.2.2  pgoyette 
    332  1.9.2.2  pgoyette 	for (nstep = 0; nstep < c->c_step1cnt && vol < min; nstep++) {
    333  1.9.2.2  pgoyette 		++reg_val;
    334  1.9.2.2  pgoyette 		vol += c->c_step1;
    335  1.9.2.2  pgoyette 	}
    336  1.9.2.2  pgoyette 	for (nstep = 0; nstep < c->c_step2cnt && vol < min; nstep++) {
    337  1.9.2.2  pgoyette 		++reg_val;
    338  1.9.2.2  pgoyette 		vol += c->c_step2;
    339  1.9.2.2  pgoyette 	}
    340  1.9.2.2  pgoyette 
    341  1.9.2.2  pgoyette 	if (vol > max)
    342  1.9.2.2  pgoyette 		return EINVAL;
    343  1.9.2.2  pgoyette 
    344  1.9.2.2  pgoyette 	iic_acquire_bus(tag, flags);
    345  1.9.2.2  pgoyette 	if ((error = axppmic_read(tag, addr, c->c_voltage_reg, &val, flags)) == 0) {
    346  1.9.2.2  pgoyette 		val &= ~c->c_voltage_mask;
    347  1.9.2.2  pgoyette 		val |= __SHIFTIN(reg_val, c->c_voltage_mask);
    348  1.9.2.2  pgoyette 		error = axppmic_write(tag, addr, c->c_voltage_reg, val, flags);
    349  1.9.2.2  pgoyette 	}
    350  1.9.2.2  pgoyette 	iic_release_bus(tag, flags);
    351  1.9.2.2  pgoyette 
    352  1.9.2.2  pgoyette 	return error;
    353  1.9.2.2  pgoyette }
    354  1.9.2.2  pgoyette 
    355  1.9.2.2  pgoyette static int
    356  1.9.2.2  pgoyette axppmic_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int *pvol)
    357  1.9.2.2  pgoyette {
    358  1.9.2.2  pgoyette 	const int flags = (cold ? I2C_F_POLL : 0);
    359  1.9.2.2  pgoyette 	int reg_val, error;
    360  1.9.2.2  pgoyette 	uint8_t val;
    361  1.9.2.2  pgoyette 
    362  1.9.2.2  pgoyette 	if (!c->c_voltage_mask)
    363  1.9.2.2  pgoyette 		return EINVAL;
    364  1.9.2.2  pgoyette 
    365  1.9.2.2  pgoyette 	iic_acquire_bus(tag, flags);
    366  1.9.2.2  pgoyette 	error = axppmic_read(tag, addr, c->c_voltage_reg, &val, flags);
    367  1.9.2.2  pgoyette 	iic_release_bus(tag, flags);
    368  1.9.2.2  pgoyette 	if (error)
    369  1.9.2.2  pgoyette 		return error;
    370  1.9.2.2  pgoyette 
    371  1.9.2.2  pgoyette 	reg_val = __SHIFTOUT(val, c->c_voltage_mask);
    372  1.9.2.2  pgoyette 	if (reg_val < c->c_step1cnt) {
    373  1.9.2.2  pgoyette 		*pvol = c->c_min + reg_val * c->c_step1;
    374  1.9.2.2  pgoyette 	} else {
    375  1.9.2.2  pgoyette 		*pvol = c->c_min + (c->c_step1cnt * c->c_step1) +
    376  1.9.2.2  pgoyette 		    ((reg_val - c->c_step1cnt) * c->c_step2);
    377  1.9.2.2  pgoyette 	}
    378  1.9.2.2  pgoyette 
    379  1.9.2.2  pgoyette 	return 0;
    380  1.9.2.2  pgoyette }
    381  1.9.2.2  pgoyette 
    382  1.9.2.2  pgoyette static void
    383  1.9.2.2  pgoyette axppmic_power_poweroff(device_t dev)
    384  1.9.2.2  pgoyette {
    385  1.9.2.2  pgoyette 	struct axppmic_softc *sc = device_private(dev);
    386  1.9.2.2  pgoyette 
    387  1.9.2.2  pgoyette 	delay(1000000);
    388  1.9.2.2  pgoyette 
    389  1.9.2.2  pgoyette 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    390  1.9.2.2  pgoyette 	axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL);
    391  1.9.2.2  pgoyette 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    392  1.9.2.2  pgoyette }
    393  1.9.2.2  pgoyette 
    394  1.9.2.2  pgoyette static struct fdtbus_power_controller_func axppmic_power_funcs = {
    395  1.9.2.2  pgoyette 	.poweroff = axppmic_power_poweroff,
    396  1.9.2.2  pgoyette };
    397  1.9.2.2  pgoyette 
    398  1.9.2.2  pgoyette static void
    399  1.9.2.2  pgoyette axppmic_task_shut(void *priv)
    400  1.9.2.2  pgoyette {
    401  1.9.2.2  pgoyette 	struct axppmic_softc *sc = priv;
    402  1.9.2.2  pgoyette 
    403  1.9.2.2  pgoyette 	sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);
    404  1.9.2.2  pgoyette }
    405  1.9.2.2  pgoyette 
    406  1.9.2.2  pgoyette static void
    407  1.9.2.2  pgoyette axppmic_sensor_update(struct sysmon_envsys *sme, envsys_data_t *e)
    408  1.9.2.2  pgoyette {
    409  1.9.2.2  pgoyette 	struct axppmic_softc *sc = sme->sme_cookie;
    410  1.9.2.3  pgoyette 	const struct axppmic_config *c = sc->sc_conf;
    411  1.9.2.2  pgoyette 	const int flags = I2C_F_POLL;
    412  1.9.2.3  pgoyette 	uint8_t val, lo, hi;
    413  1.9.2.2  pgoyette 
    414  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    415  1.9.2.2  pgoyette 
    416  1.9.2.3  pgoyette 	const bool battery_present =
    417  1.9.2.3  pgoyette 	    sc->sc_sensor[AXP_SENSOR_BATT_PRESENT].state == ENVSYS_SVALID &&
    418  1.9.2.3  pgoyette 	    sc->sc_sensor[AXP_SENSOR_BATT_PRESENT].value_cur == 1;
    419  1.9.2.3  pgoyette 
    420  1.9.2.2  pgoyette 	switch (e->private) {
    421  1.9.2.2  pgoyette 	case AXP_SENSOR_ACIN_PRESENT:
    422  1.9.2.2  pgoyette 		if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, &val, flags) == 0) {
    423  1.9.2.2  pgoyette 			e->state = ENVSYS_SVALID;
    424  1.9.2.2  pgoyette 			e->value_cur = !!(val & AXP_POWER_SOURCE_ACIN_PRESENT);
    425  1.9.2.2  pgoyette 		}
    426  1.9.2.2  pgoyette 		break;
    427  1.9.2.2  pgoyette 	case AXP_SENSOR_VBUS_PRESENT:
    428  1.9.2.2  pgoyette 		if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, &val, flags) == 0) {
    429  1.9.2.2  pgoyette 			e->state = ENVSYS_SVALID;
    430  1.9.2.2  pgoyette 			e->value_cur = !!(val & AXP_POWER_SOURCE_VBUS_PRESENT);
    431  1.9.2.2  pgoyette 		}
    432  1.9.2.2  pgoyette 		break;
    433  1.9.2.2  pgoyette 	case AXP_SENSOR_BATT_PRESENT:
    434  1.9.2.2  pgoyette 		if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, &val, flags) == 0) {
    435  1.9.2.2  pgoyette 			if (val & AXP_POWER_MODE_BATT_VALID) {
    436  1.9.2.2  pgoyette 				e->state = ENVSYS_SVALID;
    437  1.9.2.2  pgoyette 				e->value_cur = !!(val & AXP_POWER_MODE_BATT_PRESENT);
    438  1.9.2.2  pgoyette 			}
    439  1.9.2.2  pgoyette 		}
    440  1.9.2.2  pgoyette 		break;
    441  1.9.2.2  pgoyette 	case AXP_SENSOR_BATT_CHARGING:
    442  1.9.2.2  pgoyette 		if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_MODE_REG, &val, flags) == 0) {
    443  1.9.2.2  pgoyette 			e->state = ENVSYS_SVALID;
    444  1.9.2.2  pgoyette 			e->value_cur = !!(val & AXP_POWER_MODE_BATT_CHARGING);
    445  1.9.2.2  pgoyette 		}
    446  1.9.2.2  pgoyette 		break;
    447  1.9.2.2  pgoyette 	case AXP_SENSOR_BATT_CHARGE_STATE:
    448  1.9.2.3  pgoyette 		if (battery_present &&
    449  1.9.2.2  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_REG, &val, flags) == 0 &&
    450  1.9.2.2  pgoyette 		    (val & AXP_BATT_CAP_VALID) != 0) {
    451  1.9.2.2  pgoyette 			const u_int batt_val = __SHIFTOUT(val, AXP_BATT_CAP_PERCENT);
    452  1.9.2.2  pgoyette 			if (batt_val <= sc->sc_shut_thres) {
    453  1.9.2.2  pgoyette 				e->state = ENVSYS_SCRITICAL;
    454  1.9.2.2  pgoyette 				e->value_cur = ENVSYS_BATTERY_CAPACITY_CRITICAL;
    455  1.9.2.2  pgoyette 			} else if (batt_val <= sc->sc_warn_thres) {
    456  1.9.2.2  pgoyette 				e->state = ENVSYS_SWARNUNDER;
    457  1.9.2.2  pgoyette 				e->value_cur = ENVSYS_BATTERY_CAPACITY_WARNING;
    458  1.9.2.2  pgoyette 			} else {
    459  1.9.2.2  pgoyette 				e->state = ENVSYS_SVALID;
    460  1.9.2.2  pgoyette 				e->value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL;
    461  1.9.2.2  pgoyette 			}
    462  1.9.2.2  pgoyette 		}
    463  1.9.2.2  pgoyette 		break;
    464  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_CAPACITY_PERCENT:
    465  1.9.2.3  pgoyette 		if (battery_present &&
    466  1.9.2.2  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_REG, &val, flags) == 0 &&
    467  1.9.2.2  pgoyette 		    (val & AXP_BATT_CAP_VALID) != 0) {
    468  1.9.2.2  pgoyette 			e->state = ENVSYS_SVALID;
    469  1.9.2.2  pgoyette 			e->value_cur = __SHIFTOUT(val, AXP_BATT_CAP_PERCENT);
    470  1.9.2.2  pgoyette 		}
    471  1.9.2.2  pgoyette 		break;
    472  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_VOLTAGE:
    473  1.9.2.3  pgoyette 		if (battery_present &&
    474  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATSENSE_HI_REG, &hi, flags) == 0 &&
    475  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATSENSE_LO_REG, &lo, flags) == 0) {
    476  1.9.2.3  pgoyette 			e->state = ENVSYS_SVALID;
    477  1.9.2.3  pgoyette 			e->value_cur = AXP_ADC_RAW(hi, lo) * c->batsense_step;
    478  1.9.2.3  pgoyette 		}
    479  1.9.2.3  pgoyette 		break;
    480  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_CHARGE_CURRENT:
    481  1.9.2.3  pgoyette 		if (battery_present &&
    482  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, &val, flags) == 0 &&
    483  1.9.2.3  pgoyette 		    (val & AXP_POWER_SOURCE_CHARGE_DIRECTION) != 0 &&
    484  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATTCHG_HI_REG, &hi, flags) == 0 &&
    485  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATTCHG_LO_REG, &lo, flags) == 0) {
    486  1.9.2.3  pgoyette 			e->state = ENVSYS_SVALID;
    487  1.9.2.3  pgoyette 			e->value_cur = AXP_ADC_RAW(hi, lo) * c->charge_step;
    488  1.9.2.3  pgoyette 		}
    489  1.9.2.3  pgoyette 		break;
    490  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_DISCHARGE_CURRENT:
    491  1.9.2.3  pgoyette 		if (battery_present &&
    492  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_POWER_SOURCE_REG, &val, flags) == 0 &&
    493  1.9.2.3  pgoyette 		    (val & AXP_POWER_SOURCE_CHARGE_DIRECTION) == 0 &&
    494  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATTDISCHG_HI_REG, &hi, flags) == 0 &&
    495  1.9.2.3  pgoyette 		    axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATTDISCHG_LO_REG, &lo, flags) == 0) {
    496  1.9.2.3  pgoyette 			e->state = ENVSYS_SVALID;
    497  1.9.2.3  pgoyette 			e->value_cur = AXP_ADC_RAW(hi, lo) * c->discharge_step;
    498  1.9.2.3  pgoyette 		}
    499  1.9.2.3  pgoyette 		break;
    500  1.9.2.2  pgoyette 	}
    501  1.9.2.2  pgoyette }
    502  1.9.2.2  pgoyette 
    503  1.9.2.2  pgoyette static void
    504  1.9.2.2  pgoyette axppmic_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *e)
    505  1.9.2.2  pgoyette {
    506  1.9.2.2  pgoyette 	struct axppmic_softc *sc = sme->sme_cookie;
    507  1.9.2.2  pgoyette 	const int flags = I2C_F_POLL;
    508  1.9.2.2  pgoyette 
    509  1.9.2.2  pgoyette 	switch (e->private) {
    510  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_CAPACITY_PERCENT:
    511  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_VOLTAGE:
    512  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_CHARGE_CURRENT:
    513  1.9.2.3  pgoyette 	case AXP_SENSOR_BATT_DISCHARGE_CURRENT:
    514  1.9.2.3  pgoyette 		/* Always update battery capacity and ADCs */
    515  1.9.2.2  pgoyette 		iic_acquire_bus(sc->sc_i2c, flags);
    516  1.9.2.2  pgoyette 		axppmic_sensor_update(sme, e);
    517  1.9.2.2  pgoyette 		iic_release_bus(sc->sc_i2c, flags);
    518  1.9.2.2  pgoyette 		break;
    519  1.9.2.2  pgoyette 	default:
    520  1.9.2.2  pgoyette 		/* Refresh if the sensor is not in valid state */
    521  1.9.2.2  pgoyette 		if (e->state != ENVSYS_SVALID) {
    522  1.9.2.2  pgoyette 			iic_acquire_bus(sc->sc_i2c, flags);
    523  1.9.2.2  pgoyette 			axppmic_sensor_update(sme, e);
    524  1.9.2.2  pgoyette 			iic_release_bus(sc->sc_i2c, flags);
    525  1.9.2.2  pgoyette 		}
    526  1.9.2.2  pgoyette 		break;
    527  1.9.2.2  pgoyette 	}
    528  1.9.2.2  pgoyette }
    529  1.9.2.2  pgoyette 
    530  1.9.2.2  pgoyette static int
    531  1.9.2.2  pgoyette axppmic_intr(void *priv)
    532  1.9.2.2  pgoyette {
    533  1.9.2.2  pgoyette 	struct axppmic_softc *sc = priv;
    534  1.9.2.2  pgoyette 	const struct axppmic_config *c = sc->sc_conf;
    535  1.9.2.2  pgoyette 	const int flags = I2C_F_POLL;
    536  1.9.2.2  pgoyette 	uint8_t stat;
    537  1.9.2.2  pgoyette 	u_int n;
    538  1.9.2.2  pgoyette 
    539  1.9.2.2  pgoyette 	iic_acquire_bus(sc->sc_i2c, flags);
    540  1.9.2.2  pgoyette 	for (n = 1; n <= c->irq_regs; n++) {
    541  1.9.2.2  pgoyette 		if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(n), &stat, flags) == 0) {
    542  1.9.2.2  pgoyette 			if (n == c->poklirq.reg && (stat & c->poklirq.mask) != 0)
    543  1.9.2.2  pgoyette 				sysmon_task_queue_sched(0, axppmic_task_shut, sc);
    544  1.9.2.2  pgoyette 			if (n == c->acinirq.reg && (stat & c->acinirq.mask) != 0)
    545  1.9.2.2  pgoyette 				axppmic_sensor_update(sc->sc_sme, &sc->sc_sensor[AXP_SENSOR_ACIN_PRESENT]);
    546  1.9.2.2  pgoyette 			if (n == c->vbusirq.reg && (stat & c->vbusirq.mask) != 0)
    547  1.9.2.2  pgoyette 				axppmic_sensor_update(sc->sc_sme, &sc->sc_sensor[AXP_SENSOR_VBUS_PRESENT]);
    548  1.9.2.2  pgoyette 			if (n == c->battirq.reg && (stat & c->battirq.mask) != 0)
    549  1.9.2.2  pgoyette 				axppmic_sensor_update(sc->sc_sme, &sc->sc_sensor[AXP_SENSOR_BATT_PRESENT]);
    550  1.9.2.2  pgoyette 			if (n == c->chargeirq.reg && (stat & c->chargeirq.mask) != 0)
    551  1.9.2.2  pgoyette 				axppmic_sensor_update(sc->sc_sme, &sc->sc_sensor[AXP_SENSOR_BATT_CHARGING]);
    552  1.9.2.2  pgoyette 			if (n == c->chargestirq.reg && (stat & c->chargestirq.mask) != 0)
    553  1.9.2.2  pgoyette 				axppmic_sensor_update(sc->sc_sme, &sc->sc_sensor[AXP_SENSOR_BATT_CHARGE_STATE]);
    554  1.9.2.2  pgoyette 
    555  1.9.2.2  pgoyette 			if (stat != 0)
    556  1.9.2.2  pgoyette 				axppmic_write(sc->sc_i2c, sc->sc_addr,
    557  1.9.2.2  pgoyette 				    AXP_IRQ_STATUS_REG(n), stat, flags);
    558  1.9.2.2  pgoyette 		}
    559  1.9.2.2  pgoyette 	}
    560  1.9.2.2  pgoyette 	iic_release_bus(sc->sc_i2c, flags);
    561  1.9.2.2  pgoyette 
    562  1.9.2.2  pgoyette 	return 1;
    563  1.9.2.2  pgoyette }
    564  1.9.2.2  pgoyette 
    565  1.9.2.2  pgoyette static void
    566  1.9.2.2  pgoyette axppmic_attach_acadapter(struct axppmic_softc *sc)
    567  1.9.2.2  pgoyette {
    568  1.9.2.2  pgoyette 	envsys_data_t *e;
    569  1.9.2.2  pgoyette 
    570  1.9.2.2  pgoyette 	e = &sc->sc_sensor[AXP_SENSOR_ACIN_PRESENT];
    571  1.9.2.2  pgoyette 	e->private = AXP_SENSOR_ACIN_PRESENT;
    572  1.9.2.2  pgoyette 	e->units = ENVSYS_INDICATOR;
    573  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    574  1.9.2.2  pgoyette 	strlcpy(e->desc, "ACIN present", sizeof(e->desc));
    575  1.9.2.2  pgoyette 	sysmon_envsys_sensor_attach(sc->sc_sme, e);
    576  1.9.2.2  pgoyette 
    577  1.9.2.2  pgoyette 	e = &sc->sc_sensor[AXP_SENSOR_VBUS_PRESENT];
    578  1.9.2.2  pgoyette 	e->private = AXP_SENSOR_VBUS_PRESENT;
    579  1.9.2.2  pgoyette 	e->units = ENVSYS_INDICATOR;
    580  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    581  1.9.2.2  pgoyette 	strlcpy(e->desc, "VBUS present", sizeof(e->desc));
    582  1.9.2.2  pgoyette 	sysmon_envsys_sensor_attach(sc->sc_sme, e);
    583  1.9.2.2  pgoyette }
    584  1.9.2.2  pgoyette 
    585  1.9.2.2  pgoyette static void
    586  1.9.2.2  pgoyette axppmic_attach_battery(struct axppmic_softc *sc)
    587  1.9.2.2  pgoyette {
    588  1.9.2.3  pgoyette 	const struct axppmic_config *c = sc->sc_conf;
    589  1.9.2.2  pgoyette 	envsys_data_t *e;
    590  1.9.2.2  pgoyette 	uint8_t val;
    591  1.9.2.2  pgoyette 
    592  1.9.2.2  pgoyette 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    593  1.9.2.2  pgoyette 	if (axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_BATT_CAP_WARN_REG, &val, I2C_F_POLL) == 0) {
    594  1.9.2.2  pgoyette 		sc->sc_warn_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV1) + 5;
    595  1.9.2.2  pgoyette 		sc->sc_shut_thres = __SHIFTOUT(val, AXP_BATT_CAP_WARN_LV2);
    596  1.9.2.2  pgoyette 	}
    597  1.9.2.2  pgoyette 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    598  1.9.2.2  pgoyette 
    599  1.9.2.2  pgoyette 	e = &sc->sc_sensor[AXP_SENSOR_BATT_PRESENT];
    600  1.9.2.2  pgoyette 	e->private = AXP_SENSOR_BATT_PRESENT;
    601  1.9.2.2  pgoyette 	e->units = ENVSYS_INDICATOR;
    602  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    603  1.9.2.2  pgoyette 	strlcpy(e->desc, "battery present", sizeof(e->desc));
    604  1.9.2.2  pgoyette 	sysmon_envsys_sensor_attach(sc->sc_sme, e);
    605  1.9.2.2  pgoyette 
    606  1.9.2.2  pgoyette 	e = &sc->sc_sensor[AXP_SENSOR_BATT_CHARGING];
    607  1.9.2.2  pgoyette 	e->private = AXP_SENSOR_BATT_CHARGING;
    608  1.9.2.2  pgoyette 	e->units = ENVSYS_BATTERY_CHARGE;
    609  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    610  1.9.2.2  pgoyette 	strlcpy(e->desc, "charging", sizeof(e->desc));
    611  1.9.2.2  pgoyette 	sysmon_envsys_sensor_attach(sc->sc_sme, e);
    612  1.9.2.2  pgoyette 
    613  1.9.2.2  pgoyette 	e = &sc->sc_sensor[AXP_SENSOR_BATT_CHARGE_STATE];
    614  1.9.2.2  pgoyette 	e->private = AXP_SENSOR_BATT_CHARGE_STATE;
    615  1.9.2.2  pgoyette 	e->units = ENVSYS_BATTERY_CAPACITY;
    616  1.9.2.2  pgoyette 	e->flags = ENVSYS_FMONSTCHANGED;
    617  1.9.2.2  pgoyette 	e->state = ENVSYS_SINVALID;
    618  1.9.2.2  pgoyette 	e->value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL;
    619  1.9.2.2  pgoyette 	strlcpy(e->desc, "charge state", sizeof(e->desc));
    620  1.9.2.2  pgoyette 	sysmon_envsys_sensor_attach(sc->sc_sme, e);
    621  1.9.2.2  pgoyette 
    622  1.9.2.3  pgoyette 	if (c->batsense_step) {
    623  1.9.2.3  pgoyette 		e = &sc->sc_sensor[AXP_SENSOR_BATT_VOLTAGE];
    624  1.9.2.3  pgoyette 		e->private = AXP_SENSOR_BATT_VOLTAGE;
    625  1.9.2.3  pgoyette 		e->units = ENVSYS_SVOLTS_DC;
    626  1.9.2.3  pgoyette 		e->state = ENVSYS_SINVALID;
    627  1.9.2.3  pgoyette 		strlcpy(e->desc, "battery voltage", sizeof(e->desc));
    628  1.9.2.3  pgoyette 		sysmon_envsys_sensor_attach(sc->sc_sme, e);
    629  1.9.2.3  pgoyette 	}
    630  1.9.2.3  pgoyette 
    631  1.9.2.3  pgoyette 	if (c->charge_step) {
    632  1.9.2.3  pgoyette 		e = &sc->sc_sensor[AXP_SENSOR_BATT_CHARGE_CURRENT];
    633  1.9.2.3  pgoyette 		e->private = AXP_SENSOR_BATT_CHARGE_CURRENT;
    634  1.9.2.3  pgoyette 		e->units = ENVSYS_SAMPS;
    635  1.9.2.3  pgoyette 		e->state = ENVSYS_SINVALID;
    636  1.9.2.3  pgoyette 		strlcpy(e->desc, "battery charge current", sizeof(e->desc));
    637  1.9.2.3  pgoyette 		sysmon_envsys_sensor_attach(sc->sc_sme, e);
    638  1.9.2.3  pgoyette 	}
    639  1.9.2.3  pgoyette 
    640  1.9.2.3  pgoyette 	if (c->discharge_step) {
    641  1.9.2.3  pgoyette 		e = &sc->sc_sensor[AXP_SENSOR_BATT_DISCHARGE_CURRENT];
    642  1.9.2.3  pgoyette 		e->private = AXP_SENSOR_BATT_DISCHARGE_CURRENT;
    643  1.9.2.3  pgoyette 		e->units = ENVSYS_SAMPS;
    644  1.9.2.3  pgoyette 		e->state = ENVSYS_SINVALID;
    645  1.9.2.3  pgoyette 		strlcpy(e->desc, "battery discharge current", sizeof(e->desc));
    646  1.9.2.3  pgoyette 		sysmon_envsys_sensor_attach(sc->sc_sme, e);
    647  1.9.2.3  pgoyette 	}
    648  1.9.2.3  pgoyette 
    649  1.9.2.3  pgoyette 	if (c->has_fuel_gauge) {
    650  1.9.2.3  pgoyette 		e = &sc->sc_sensor[AXP_SENSOR_BATT_CAPACITY_PERCENT];
    651  1.9.2.3  pgoyette 		e->private = AXP_SENSOR_BATT_CAPACITY_PERCENT;
    652  1.9.2.2  pgoyette 		e->units = ENVSYS_INTEGER;
    653  1.9.2.2  pgoyette 		e->state = ENVSYS_SINVALID;
    654  1.9.2.2  pgoyette 		e->flags = ENVSYS_FPERCENT;
    655  1.9.2.2  pgoyette 		strlcpy(e->desc, "battery percent", sizeof(e->desc));
    656  1.9.2.2  pgoyette 		sysmon_envsys_sensor_attach(sc->sc_sme, e);
    657  1.9.2.2  pgoyette 	}
    658  1.9.2.2  pgoyette }
    659  1.9.2.2  pgoyette 
    660  1.9.2.2  pgoyette static void
    661  1.9.2.2  pgoyette axppmic_attach_sensors(struct axppmic_softc *sc)
    662  1.9.2.2  pgoyette {
    663  1.9.2.2  pgoyette 	if (sc->sc_conf->has_battery) {
    664  1.9.2.2  pgoyette 		sc->sc_sme = sysmon_envsys_create();
    665  1.9.2.2  pgoyette 		sc->sc_sme->sme_name = device_xname(sc->sc_dev);
    666  1.9.2.2  pgoyette 		sc->sc_sme->sme_cookie = sc;
    667  1.9.2.2  pgoyette 		sc->sc_sme->sme_refresh = axppmic_sensor_refresh;
    668  1.9.2.2  pgoyette 		sc->sc_sme->sme_class = SME_CLASS_BATTERY;
    669  1.9.2.2  pgoyette 		sc->sc_sme->sme_flags = SME_INIT_REFRESH;
    670  1.9.2.2  pgoyette 
    671  1.9.2.2  pgoyette 		axppmic_attach_acadapter(sc);
    672  1.9.2.2  pgoyette 		axppmic_attach_battery(sc);
    673  1.9.2.2  pgoyette 
    674  1.9.2.2  pgoyette 		sysmon_envsys_register(sc->sc_sme);
    675  1.9.2.2  pgoyette 	}
    676  1.9.2.2  pgoyette }
    677  1.9.2.2  pgoyette 
    678  1.9.2.2  pgoyette 
    679  1.9.2.2  pgoyette static int
    680  1.9.2.2  pgoyette axppmic_match(device_t parent, cfdata_t match, void *aux)
    681  1.9.2.2  pgoyette {
    682  1.9.2.2  pgoyette 	struct i2c_attach_args *ia = aux;
    683  1.9.2.3  pgoyette 	int match_result;
    684  1.9.2.2  pgoyette 
    685  1.9.2.3  pgoyette 	if (iic_use_direct_match(ia, match, axppmic_compat_data, &match_result))
    686  1.9.2.3  pgoyette 		return match_result;
    687  1.9.2.2  pgoyette 
    688  1.9.2.3  pgoyette 	/* This device is direct-config only. */
    689  1.9.2.3  pgoyette 
    690  1.9.2.3  pgoyette 	return 0;
    691  1.9.2.2  pgoyette }
    692  1.9.2.2  pgoyette 
    693  1.9.2.2  pgoyette static void
    694  1.9.2.2  pgoyette axppmic_attach(device_t parent, device_t self, void *aux)
    695  1.9.2.2  pgoyette {
    696  1.9.2.2  pgoyette 	struct axppmic_softc *sc = device_private(self);
    697  1.9.2.3  pgoyette 	const struct device_compatible_entry *dce;
    698  1.9.2.2  pgoyette 	const struct axppmic_config *c;
    699  1.9.2.2  pgoyette 	struct axpreg_attach_args aaa;
    700  1.9.2.2  pgoyette 	struct i2c_attach_args *ia = aux;
    701  1.9.2.2  pgoyette 	int phandle, child, i;
    702  1.9.2.2  pgoyette 	uint32_t irq_mask;
    703  1.9.2.2  pgoyette 	void *ih;
    704  1.9.2.2  pgoyette 
    705  1.9.2.3  pgoyette 	dce = iic_compatible_match(ia, axppmic_compat_data, NULL);
    706  1.9.2.3  pgoyette 	KASSERT(dce != NULL);
    707  1.9.2.3  pgoyette 	c = DEVICE_COMPAT_ENTRY_GET_PTR(dce);
    708  1.9.2.2  pgoyette 
    709  1.9.2.2  pgoyette 	sc->sc_dev = self;
    710  1.9.2.2  pgoyette 	sc->sc_i2c = ia->ia_tag;
    711  1.9.2.2  pgoyette 	sc->sc_addr = ia->ia_addr;
    712  1.9.2.2  pgoyette 	sc->sc_phandle = ia->ia_cookie;
    713  1.9.2.2  pgoyette 	sc->sc_conf = c;
    714  1.9.2.2  pgoyette 
    715  1.9.2.2  pgoyette 	aprint_naive("\n");
    716  1.9.2.2  pgoyette 	aprint_normal(": %s\n", c->name);
    717  1.9.2.2  pgoyette 
    718  1.9.2.2  pgoyette 	sc->sc_smpsw.smpsw_name = device_xname(self);
    719  1.9.2.2  pgoyette 	sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER;
    720  1.9.2.2  pgoyette 	sysmon_pswitch_register(&sc->sc_smpsw);
    721  1.9.2.2  pgoyette 
    722  1.9.2.2  pgoyette 	iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
    723  1.9.2.2  pgoyette 	for (i = 1; i <= c->irq_regs; i++) {
    724  1.9.2.2  pgoyette 		irq_mask = 0;
    725  1.9.2.2  pgoyette 		if (i == c->poklirq.reg)
    726  1.9.2.2  pgoyette 			irq_mask |= c->poklirq.mask;
    727  1.9.2.2  pgoyette 		if (i == c->acinirq.reg)
    728  1.9.2.2  pgoyette 			irq_mask |= c->acinirq.mask;
    729  1.9.2.2  pgoyette 		if (i == c->vbusirq.reg)
    730  1.9.2.2  pgoyette 			irq_mask |= c->vbusirq.mask;
    731  1.9.2.2  pgoyette 		if (i == c->battirq.reg)
    732  1.9.2.2  pgoyette 			irq_mask |= c->battirq.mask;
    733  1.9.2.2  pgoyette 		if (i == c->chargeirq.reg)
    734  1.9.2.2  pgoyette 			irq_mask |= c->chargeirq.mask;
    735  1.9.2.2  pgoyette 		if (i == c->chargestirq.reg)
    736  1.9.2.2  pgoyette 			irq_mask |= c->chargestirq.mask;
    737  1.9.2.2  pgoyette 		axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, I2C_F_POLL);
    738  1.9.2.2  pgoyette 	}
    739  1.9.2.2  pgoyette 	iic_release_bus(sc->sc_i2c, I2C_F_POLL);
    740  1.9.2.2  pgoyette 
    741  1.9.2.2  pgoyette 	ih = fdtbus_intr_establish(sc->sc_phandle, 0, IPL_VM, FDT_INTR_MPSAFE,
    742  1.9.2.2  pgoyette 	    axppmic_intr, sc);
    743  1.9.2.2  pgoyette 	if (ih == NULL) {
    744  1.9.2.2  pgoyette 		aprint_error_dev(self, "WARNING: couldn't establish interrupt handler\n");
    745  1.9.2.2  pgoyette 	}
    746  1.9.2.2  pgoyette 
    747  1.9.2.2  pgoyette 	fdtbus_register_power_controller(sc->sc_dev, sc->sc_phandle,
    748  1.9.2.2  pgoyette 	    &axppmic_power_funcs);
    749  1.9.2.2  pgoyette 
    750  1.9.2.2  pgoyette 	phandle = of_find_firstchild_byname(sc->sc_phandle, "regulators");
    751  1.9.2.2  pgoyette 	if (phandle > 0) {
    752  1.9.2.2  pgoyette 		aaa.reg_i2c = sc->sc_i2c;
    753  1.9.2.2  pgoyette 		aaa.reg_addr = sc->sc_addr;
    754  1.9.2.2  pgoyette 		for (i = 0; i < c->ncontrols; i++) {
    755  1.9.2.2  pgoyette 			const struct axppmic_ctrl *ctrl = &c->controls[i];
    756  1.9.2.2  pgoyette 			child = of_find_firstchild_byname(phandle, ctrl->c_name);
    757  1.9.2.2  pgoyette 			if (child <= 0)
    758  1.9.2.2  pgoyette 				continue;
    759  1.9.2.2  pgoyette 			aaa.reg_ctrl = ctrl;
    760  1.9.2.2  pgoyette 			aaa.reg_phandle = child;
    761  1.9.2.2  pgoyette 			config_found(sc->sc_dev, &aaa, NULL);
    762  1.9.2.2  pgoyette 		}
    763  1.9.2.2  pgoyette 	}
    764  1.9.2.2  pgoyette 
    765  1.9.2.2  pgoyette 	if (c->has_battery)
    766  1.9.2.2  pgoyette 		axppmic_attach_sensors(sc);
    767  1.9.2.2  pgoyette }
    768  1.9.2.2  pgoyette 
    769  1.9.2.2  pgoyette static int
    770  1.9.2.2  pgoyette axpreg_acquire(device_t dev)
    771  1.9.2.2  pgoyette {
    772  1.9.2.2  pgoyette 	return 0;
    773  1.9.2.2  pgoyette }
    774  1.9.2.2  pgoyette 
    775  1.9.2.2  pgoyette static void
    776  1.9.2.2  pgoyette axpreg_release(device_t dev)
    777  1.9.2.2  pgoyette {
    778  1.9.2.2  pgoyette }
    779  1.9.2.2  pgoyette 
    780  1.9.2.2  pgoyette static int
    781  1.9.2.2  pgoyette axpreg_enable(device_t dev, bool enable)
    782  1.9.2.2  pgoyette {
    783  1.9.2.2  pgoyette 	struct axpreg_softc *sc = device_private(dev);
    784  1.9.2.2  pgoyette 	const struct axppmic_ctrl *c = sc->sc_ctrl;
    785  1.9.2.2  pgoyette 	const int flags = (cold ? I2C_F_POLL : 0);
    786  1.9.2.2  pgoyette 	uint8_t val;
    787  1.9.2.2  pgoyette 	int error;
    788  1.9.2.2  pgoyette 
    789  1.9.2.2  pgoyette 	if (!c->c_enable_mask)
    790  1.9.2.2  pgoyette 		return EINVAL;
    791  1.9.2.2  pgoyette 
    792  1.9.2.2  pgoyette 	iic_acquire_bus(sc->sc_i2c, flags);
    793  1.9.2.2  pgoyette 	if ((error = axppmic_read(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, &val, flags)) == 0) {
    794  1.9.2.2  pgoyette 		if (enable)
    795  1.9.2.2  pgoyette 			val |= c->c_enable_mask;
    796  1.9.2.2  pgoyette 		else
    797  1.9.2.2  pgoyette 			val &= ~c->c_enable_mask;
    798  1.9.2.2  pgoyette 		error = axppmic_write(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, val, flags);
    799  1.9.2.2  pgoyette 	}
    800  1.9.2.2  pgoyette 	iic_release_bus(sc->sc_i2c, flags);
    801  1.9.2.2  pgoyette 
    802  1.9.2.2  pgoyette 	return error;
    803  1.9.2.2  pgoyette }
    804  1.9.2.2  pgoyette 
    805  1.9.2.2  pgoyette static int
    806  1.9.2.2  pgoyette axpreg_set_voltage(device_t dev, u_int min_uvol, u_int max_uvol)
    807  1.9.2.2  pgoyette {
    808  1.9.2.2  pgoyette 	struct axpreg_softc *sc = device_private(dev);
    809  1.9.2.2  pgoyette 	const struct axppmic_ctrl *c = sc->sc_ctrl;
    810  1.9.2.2  pgoyette 
    811  1.9.2.2  pgoyette 	return axppmic_set_voltage(sc->sc_i2c, sc->sc_addr, c,
    812  1.9.2.2  pgoyette 	    min_uvol / 1000, max_uvol / 1000);
    813  1.9.2.2  pgoyette }
    814  1.9.2.2  pgoyette 
    815  1.9.2.2  pgoyette static int
    816  1.9.2.2  pgoyette axpreg_get_voltage(device_t dev, u_int *puvol)
    817  1.9.2.2  pgoyette {
    818  1.9.2.2  pgoyette 	struct axpreg_softc *sc = device_private(dev);
    819  1.9.2.2  pgoyette 	const struct axppmic_ctrl *c = sc->sc_ctrl;
    820  1.9.2.2  pgoyette 	int error;
    821  1.9.2.2  pgoyette 	u_int vol;
    822  1.9.2.2  pgoyette 
    823  1.9.2.2  pgoyette 	error = axppmic_get_voltage(sc->sc_i2c, sc->sc_addr, c, &vol);
    824  1.9.2.2  pgoyette 	if (error)
    825  1.9.2.2  pgoyette 		return error;
    826  1.9.2.2  pgoyette 
    827  1.9.2.2  pgoyette 	*puvol = vol * 1000;
    828  1.9.2.2  pgoyette 	return 0;
    829  1.9.2.2  pgoyette }
    830  1.9.2.2  pgoyette 
    831  1.9.2.2  pgoyette static struct fdtbus_regulator_controller_func axpreg_funcs = {
    832  1.9.2.2  pgoyette 	.acquire = axpreg_acquire,
    833  1.9.2.2  pgoyette 	.release = axpreg_release,
    834  1.9.2.2  pgoyette 	.enable = axpreg_enable,
    835  1.9.2.2  pgoyette 	.set_voltage = axpreg_set_voltage,
    836  1.9.2.2  pgoyette 	.get_voltage = axpreg_get_voltage,
    837  1.9.2.2  pgoyette };
    838  1.9.2.2  pgoyette 
    839  1.9.2.2  pgoyette static int
    840  1.9.2.2  pgoyette axpreg_match(device_t parent, cfdata_t match, void *aux)
    841  1.9.2.2  pgoyette {
    842  1.9.2.2  pgoyette 	return 1;
    843  1.9.2.2  pgoyette }
    844  1.9.2.2  pgoyette 
    845  1.9.2.2  pgoyette static void
    846  1.9.2.2  pgoyette axpreg_attach(device_t parent, device_t self, void *aux)
    847  1.9.2.2  pgoyette {
    848  1.9.2.2  pgoyette 	struct axpreg_softc *sc = device_private(self);
    849  1.9.2.2  pgoyette 	struct axpreg_attach_args *aaa = aux;
    850  1.9.2.2  pgoyette 	const int phandle = aaa->reg_phandle;
    851  1.9.2.2  pgoyette 	const char *name;
    852  1.9.2.2  pgoyette 
    853  1.9.2.2  pgoyette 	sc->sc_dev = self;
    854  1.9.2.2  pgoyette 	sc->sc_i2c = aaa->reg_i2c;
    855  1.9.2.2  pgoyette 	sc->sc_addr = aaa->reg_addr;
    856  1.9.2.2  pgoyette 	sc->sc_ctrl = aaa->reg_ctrl;
    857  1.9.2.2  pgoyette 
    858  1.9.2.2  pgoyette 	fdtbus_register_regulator_controller(self, phandle,
    859  1.9.2.2  pgoyette 	    &axpreg_funcs);
    860  1.9.2.2  pgoyette 
    861  1.9.2.2  pgoyette 	aprint_naive("\n");
    862  1.9.2.2  pgoyette 	name = fdtbus_get_string(phandle, "regulator-name");
    863  1.9.2.2  pgoyette 	if (name)
    864  1.9.2.2  pgoyette 		aprint_normal(": %s\n", name);
    865  1.9.2.2  pgoyette 	else
    866  1.9.2.2  pgoyette 		aprint_normal("\n");
    867  1.9.2.2  pgoyette }
    868  1.9.2.2  pgoyette 
    869  1.9.2.2  pgoyette CFATTACH_DECL_NEW(axppmic, sizeof(struct axppmic_softc),
    870  1.9.2.2  pgoyette     axppmic_match, axppmic_attach, NULL, NULL);
    871  1.9.2.2  pgoyette 
    872  1.9.2.2  pgoyette CFATTACH_DECL_NEW(axpreg, sizeof(struct axpreg_softc),
    873  1.9.2.2  pgoyette     axpreg_match, axpreg_attach, NULL, NULL);
    874