35#include <sys/kernel.h>
36#include <sys/module.h>
39#include <machine/bus.h>
44#include <dev/ofw/ofw_bus.h>
45#include <dev/ofw/ofw_bus_subr.h>
47#include <dev/extres/regulator/regulator.h>
52#define FAN53555_VSEL0 0x00
53#define FAN53555_VSEL1 0x01
54#define FAN53555_VSEL_ENA (1 << 7)
55#define FAN53555_VSEL_MODE (1 << 6)
56#define FAN53555_VSEL_MASK 0x3f
57#define FAN53555_CTRL 0x02
58#define FAN53555_ID1 0x03
59#define FAN53555_ID1_DIE_ID(x) (((x) >> 4) & 0x0F)
60#define FAN53555_ID2 0x04
61#define FAN53555_ID2_DIE_REV(x) (((x) >> 4) & 0x0F)
62#define FAN53555_MON 0x05
66#define dprintf(sc, format, arg...) \
67 device_printf(sc->base_dev, "%s: " format, __func__, arg)
69#define dprintf(sc, format, arg...)
80 {
"silergy,syr827",
SYR827},
81 {
"silergy,syr828",
SYR828},
92 struct regnode_std_param *
param;
102 REG_RANGE_INIT( 0, 0x3F, 712500, 12500);
105 REG_RANGE_INIT( 0, 0x3F, 600000, 10000);
107 REG_RANGE_INIT( 0, 0x3F, 800000, 10000);
109 REG_RANGE_INIT( 0, 0x3F, 600000, 10000);
111 REG_RANGE_INIT( 0, 0x3F, 603000, 12826);
130 device_printf(
dev,
"Error when reading reg 0x%02X, rv: %d\n",
155 "Error when writing reg 0x%02X, rv: %d\n", reg, rv);
182 reg &= ~FAN53555_VSEL_MASK;
203 sc = regnode_get_softc(
regnode);
205 dprintf(sc,
"%sabling regulator %s\n", enable ?
"En" :
"Dis",
211 val &= ~FAN53555_VSEL_ENA;
214 *udelay = sc->
param->enable_delay;
221 int max_uvolt,
int *udelay)
227 sc = regnode_get_softc(
regnode);
229 dprintf(sc,
"Setting %s to %d<->%d uvolts\n", sc->
name, min_uvolt,
231 rv = regulator_range_volt_to_sel8(sc->
range, 1, min_uvolt, max_uvolt,
235 *udelay = sc->
param->ramp_delay;
237 dprintf(sc,
"Regulator %s writing sel: 0x%02X\n", sc->
name, sel);
240 regulator_range_sel8_to_volt(sc->
range, 1, sel, &uvolt);
241 dprintf(sc,
"Regulator %s set to %d uvolt (sel: 0x%02X)\n", sc->
name,
254 sc = regnode_get_softc(
regnode);
259 rv = regulator_range_sel8_to_volt(sc->
range, 1, sel, uvolt);
260 dprintf(sc,
"Regulator %s is at %d uvolt ((sel: 0x%02X)\n", sc->
name,
277static struct regulator_range *
318 struct regnode_init_def initdef;
319 struct regnode *regnode;
320 static struct regulator_range *range;
323 memset(&initdef, 0,
sizeof(initdef));
324 if (regulator_parse_ofw_stdparam(sc->
dev, node, &initdef) != 0) {
325 device_printf(sc->
dev,
"cannot parse regulator FDT data\n");
330 device_printf(sc->
dev,
"cannot read ID1\n");
335 device_printf(sc->
dev,
"cannot read ID2\n");
338 dprintf(sc,
"Device ID1: 0x%02X, ID2: 0x%02X\n", id1, id2);
343 device_printf(sc->
dev,
344 "cannot determine chip type (ID1: 0x%02X, ID2: 0x%02X)\n",
350 initdef.ofw_node = node;
352 regnode = regnode_create(sc->
dev, &fan53555_regnode_class, &initdef);
353 if (regnode == NULL) {
354 device_printf(sc->
dev,
"cannot create regulator\n");
358 reg_sc = regnode_get_softc(regnode);
359 reg_sc->
name =
"fan53555";
362 reg_sc->
param = regnode_get_stdparam(regnode);
363 reg_sc->
range = range;
370 regnode_register(regnode);
374 regnode_topo_slock();
375 rv = regnode_get_voltage(regnode, &volt);
377 device_printf(sc->
dev,
378 " Regulator %s: parent doesn't exist yet.\n",
379 regnode_get_name(regnode));
380 }
else if (rv != 0) {
381 device_printf(sc->
dev,
382 " Regulator %s: voltage: INVALID!!!\n",
383 regnode_get_name(regnode));
385 device_printf(sc->
dev,
386 " Regulator %s: voltage: %d uV\n",
387 regnode_get_name(regnode), volt);
389 regnode_topo_unlock();
400 if (!ofw_bus_status_okay(
dev))
406 device_set_desc(
dev,
"FAN53555 PMIC");
409 device_set_desc(
dev,
"SYR827 PMIC");
412 device_set_desc(
dev,
"SYR828 PMIC");
418 return (BUS_PROBE_DEFAULT);
426 int type, susp_sel, rv;
428 sc = device_get_softc(
dev);
430 node = ofw_bus_get_node(
dev);
433 rv = OF_getencprop(node,
"fcs,suspend-voltage-selector", &susp_sel,
445 device_printf(
dev,
"cannot attach regulator.\n");
464 DEVMETHOD(regdev_map, regdev_default_ofw_map),
static int fan53555_detach(device_t dev)
static int fan53555_probe(device_t dev)
#define FAN53555_VSEL_ENA
static struct regulator_range syr_8_range
static devclass_t fan53555_devclass
static int fan53555_write_sel(struct fan53555_reg_sc *sc, uint8_t sel)
static struct regulator_range fan_1_range
#define dprintf(sc, format, arg...)
MODULE_VERSION(fan53555, 1)
DEFINE_CLASS_1(fan53555_regnode, fan53555_regnode_class, fan53555_regnode_methods, sizeof(struct fan53555_reg_sc), regnode_class)
static int fan53555_regnode_enable(struct regnode *regnode, bool enable, int *udelay)
static DEFINE_CLASS_0(fan53555_pmic, fan53555_driver, fan53555_methods, sizeof(struct fan53555_softc))
static struct regulator_range * fan53555_get_range(struct fan53555_softc *sc, int type, uint8_t id, uint8_t rev)
static struct regulator_range fan_0_13_range
static int fan53555_write(device_t dev, uint8_t reg, uint8_t val)
#define FAN53555_VSEL_MASK
EARLY_DRIVER_MODULE(fan53555, iicbus, fan53555_driver, fan53555_devclass, 0, 0, BUS_PASS_RESOURCE)
static device_method_t fan53555_methods[]
MODULE_DEPEND(fan53555, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
static int fan53555_regnode_init(struct regnode *regnode)
#define FAN53555_ID2_DIE_REV(x)
static int fan53555_regnode_get_voltage(struct regnode *regnode, int *uvolt)
static regnode_method_t fan53555_regnode_methods[]
IICBUS_FDT_PNP_INFO(compat_data)
static struct ofw_compat_data compat_data[]
static int fan53555_read(device_t dev, uint8_t reg, uint8_t *val)
static int fan53555_regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt, int *udelay)
#define FAN53555_ID1_DIE_ID(x)
static int fan53555_attach(device_t dev)
static struct regulator_range fan_0_0_range
static struct regulator_range fan_4_range
static int fan53555_read_sel(struct fan53555_reg_sc *sc, uint8_t *sel)
static struct fan53555_reg_sc * fan53555_reg_attach(struct fan53555_softc *sc, phandle_t node, int type)
int iicbus_transfer_excl(device_t dev, struct iic_msg *msgs, uint32_t nmsgs, int how)
struct regulator_range * range
struct regnode_std_param * param