aw_sid: rewrite compat-string configuration to be more flexible

This will allow easiser support in the future for boards that have thermal
data and different offsets for root key/efuse data.
This commit is contained in:
Kyle Evans 2017-12-31 06:44:15 +00:00
parent 5261ac0eda
commit 1ccce047f5

View File

@ -52,28 +52,36 @@ __FBSDID("$FreeBSD$");
#define SID_THERMAL_CALIB0 (SID_SRAM + 0x34) #define SID_THERMAL_CALIB0 (SID_SRAM + 0x34)
#define SID_THERMAL_CALIB1 (SID_SRAM + 0x38) #define SID_THERMAL_CALIB1 (SID_SRAM + 0x38)
#define A10_ROOT_KEY_OFF 0x0
#define A83T_ROOT_KEY_OFF SID_SRAM
#define ROOT_KEY_SIZE 4 #define ROOT_KEY_SIZE 4
enum sid_type { struct aw_sid_conf {
A10_SID = 1, bus_size_t rootkey_offset;
A20_SID, bool has_thermal;
A83T_SID, };
static const struct aw_sid_conf a10_conf = {
.rootkey_offset = 0,
};
static const struct aw_sid_conf a20_conf = {
.rootkey_offset = 0,
};
static const struct aw_sid_conf a83t_conf = {
.rootkey_offset = SID_SRAM,
.has_thermal = true,
}; };
static struct ofw_compat_data compat_data[] = { static struct ofw_compat_data compat_data[] = {
{ "allwinner,sun4i-a10-sid", A10_SID}, { "allwinner,sun4i-a10-sid", (uintptr_t)&a10_conf},
{ "allwinner,sun7i-a20-sid", A20_SID}, { "allwinner,sun7i-a20-sid", (uintptr_t)&a20_conf},
{ "allwinner,sun8i-a83t-sid", A83T_SID}, { "allwinner,sun8i-a83t-sid", (uintptr_t)&a83t_conf},
{ NULL, 0 } { NULL, 0 }
}; };
struct aw_sid_softc { struct aw_sid_softc {
struct resource *res; struct resource *res;
int type; struct aw_sid_conf *sid_conf;
bus_size_t root_key_off;
}; };
static struct aw_sid_softc *aw_sid_sc; static struct aw_sid_softc *aw_sid_sc;
@ -118,16 +126,7 @@ aw_sid_attach(device_t dev)
} }
aw_sid_sc = sc; aw_sid_sc = sc;
sc->sid_conf = (struct aw_sid_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data;
sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
switch (sc->type) {
case A83T_SID:
sc->root_key_off = A83T_ROOT_KEY_OFF;
break;
default:
sc->root_key_off = A10_ROOT_KEY_OFF;
break;
}
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
@ -146,7 +145,7 @@ aw_sid_read_tscalib(uint32_t *calib0, uint32_t *calib1)
sc = aw_sid_sc; sc = aw_sid_sc;
if (sc == NULL) if (sc == NULL)
return (ENXIO); return (ENXIO);
if (sc->type != A83T_SID) if (!sc->sid_conf->has_thermal)
return (ENXIO); return (ENXIO);
*calib0 = RD4(sc, SID_THERMAL_CALIB0); *calib0 = RD4(sc, SID_THERMAL_CALIB0);
@ -160,14 +159,15 @@ aw_sid_get_rootkey(u_char *out)
{ {
struct aw_sid_softc *sc; struct aw_sid_softc *sc;
int i; int i;
bus_size_t root_key_off;
u_int tmp; u_int tmp;
sc = aw_sid_sc; sc = aw_sid_sc;
if (sc == NULL) if (sc == NULL)
return (ENXIO); return (ENXIO);
root_key_off = aw_sid_sc->sid_conf->rootkey_offset;
for (i = 0; i < ROOT_KEY_SIZE ; i++) { for (i = 0; i < ROOT_KEY_SIZE ; i++) {
tmp = RD4(aw_sid_sc, aw_sid_sc->root_key_off + (i * 4)); tmp = RD4(aw_sid_sc, root_key_off + (i * 4));
be32enc(&out[i * 4], tmp); be32enc(&out[i * 4], tmp);
} }