Module Name: src
Committed By: jmcneill
Date: Wed Aug 29 11:08:30 UTC 2018
Modified Files:
src/sys/dev/i2c: fan53555.c
Log Message:
Initialize transition slew rate if specified in the DT
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/fan53555.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/i2c/fan53555.c
diff -u src/sys/dev/i2c/fan53555.c:1.1 src/sys/dev/i2c/fan53555.c:1.2
--- src/sys/dev/i2c/fan53555.c:1.1 Wed Aug 29 01:57:38 2018
+++ src/sys/dev/i2c/fan53555.c Wed Aug 29 11:08:30 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $ */
+/* $NetBSD: fan53555.c,v 1.2 2018/08/29 11:08:30 jmcneill Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.1 2018/08/29 01:57:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fan53555.c,v 1.2 2018/08/29 11:08:30 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -80,6 +80,14 @@ enum fan53555_vendor {
FAN_VENDOR_SILERGY,
};
+/*
+ * Transition slew rates.
+ * Array index is reg value, value is slew rate in uV / us
+ */
+static const int fan53555_slew_rates[] = {
+ 64000, 32000, 16000, 8000, 4000, 2000, 1000, 500
+};
+
static const struct device_compatible_entry compat_data[] = {
{ "silergy,syr827", FAN_VENDOR_SILERGY },
{ "silergy,syr828", FAN_VENDOR_SILERGY },
@@ -205,7 +213,8 @@ static struct fdtbus_regulator_controlle
static int
fan53555_init(struct fan53555_softc *sc, enum fan53555_vendor vendor)
{
- uint8_t id1;
+ uint8_t id1, control;
+ int n;
I2C_LOCK(sc);
id1 = I2C_READ(sc, ID1_REG);
@@ -232,6 +241,8 @@ fan53555_init(struct fan53555_softc *sc,
return ENXIO;
}
+ of_getprop_uint32(sc->sc_phandle, "suspend_voltage_selector",
+ &sc->sc_suspend_voltage_selector);
switch (sc->sc_suspend_voltage_selector) {
case 0:
sc->sc_suspend_reg = VSEL0_REG;
@@ -242,10 +253,28 @@ fan53555_init(struct fan53555_softc *sc,
sc->sc_runtime_reg = VSEL0_REG;
break;
default:
- aprint_error(": Unsupported 'fcs,suspend-voltage-selector' value %u\n", sc->sc_suspend_voltage_selector);
+ aprint_error_dev(sc->sc_dev, "unsupported 'fcs,suspend-voltage-selector' value %u\n", sc->sc_suspend_voltage_selector);
return EINVAL;
}
+ of_getprop_uint32(sc->sc_phandle, "regulator-ramp-delay",
+ &sc->sc_ramp_delay);
+ if (sc->sc_ramp_delay) {
+ for (n = 0; n < __arraycount(fan53555_slew_rates); n++)
+ if (sc->sc_ramp_delay > fan53555_slew_rates[n])
+ break;
+ if (n == __arraycount(fan53555_slew_rates)) {
+ aprint_error_dev(sc->sc_dev, "unsupported 'regulator-ramp-delay' value %u\n", sc->sc_ramp_delay);
+ return EINVAL;
+ }
+ I2C_LOCK(sc);
+ control = I2C_READ(sc, CONTROL_REG);
+ control &= ~CONTROL_SLEW;
+ control |= __SHIFTIN(fan53555_slew_rates[n], CONTROL_SLEW);
+ I2C_WRITE(sc, CONTROL_REG, control);
+ I2C_UNLOCK(sc);
+ }
+
return 0;
}
@@ -267,7 +296,6 @@ fan53555_attach(device_t parent, device_
struct fan53555_softc * const sc = device_private(self);
const struct device_compatible_entry *compat;
struct i2c_attach_args *ia = aux;
- enum fan53555_vendor vendor;
sc->sc_dev = self;
sc->sc_i2c = ia->ia_tag;
@@ -275,14 +303,8 @@ fan53555_attach(device_t parent, device_
sc->sc_phandle = ia->ia_cookie;
iic_compatible_match(ia, compat_data, &compat);
- vendor = compat->data;
-
- of_getprop_uint32(sc->sc_phandle, "regulator-ramp-delay",
- &sc->sc_ramp_delay);
- of_getprop_uint32(sc->sc_phandle, "suspend_voltage_selector",
- &sc->sc_suspend_voltage_selector);
- if (fan53555_init(sc, vendor) != 0)
+ if (fan53555_init(sc, compat->data) != 0)
return;
fdtbus_register_regulator_controller(self, sc->sc_phandle,