Module Name: src Committed By: jdc Date: Thu Jul 23 16:08:03 UTC 2020
Modified Files: src/sys/arch/sparc64/sparc64: autoconf.c Log Message: Move machine-specific fixes into separate functions to improve readability. To generate a diff of this commit: cvs rdiff -u -r1.221 -r1.222 src/sys/arch/sparc64/sparc64/autoconf.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/arch/sparc64/sparc64/autoconf.c diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.221 src/sys/arch/sparc64/sparc64/autoconf.c:1.222 --- src/sys/arch/sparc64/sparc64/autoconf.c:1.221 Sun Jul 5 09:56:06 2020 +++ src/sys/arch/sparc64/sparc64/autoconf.c Thu Jul 23 16:08:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.221 2020/07/05 09:56:06 martin Exp $ */ +/* $NetBSD: autoconf.c,v 1.222 2020/07/23 16:08:02 jdc Exp $ */ /* * Copyright (c) 1996 @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.221 2020/07/05 09:56:06 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.222 2020/07/23 16:08:02 jdc Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -1111,6 +1111,101 @@ add_drivebay_props_v210(device_t dev, in } /* + * Add SPARCle spdmem devices (0x50 and 0x51) that are not in the OFW tree + */ +static void +add_spdmem_props_sparcle(device_t busdev) +{ + prop_dictionary_t props = device_properties(busdev); + prop_array_t cfg = prop_array_create(); + int i; + + DPRINTF(ACDB_PROBE, ("\nAdding spdmem for SPARCle ")); + for (i = 0x50; i <= 0x51; i++) { + prop_dictionary_t spd = prop_dictionary_create(); + prop_dictionary_set_string(spd, "name", "dimm-spd"); + prop_dictionary_set_uint32(spd, "addr", i); + prop_dictionary_set_uint64(spd, "cookie", 0); + prop_array_add(cfg, spd); + prop_object_release(spd); + } + prop_dictionary_set(props, "i2c-child-devices", cfg); + prop_object_release(cfg); +} + +/* + * Add V210/V240 environmental sensors that are not in the OFW tree. + */ +static void +add_env_sensors_v210(device_t busdev) +{ + prop_dictionary_t props = device_properties(busdev); + prop_array_t cfg = NULL; + prop_dictionary_t sens; + prop_data_t data; + const char name_lm[] = "i2c-lm75"; + const char name_adm[] = "i2c-adm1026"; + + DPRINTF(ACDB_PROBE, ("\nAdding sensors for %s ", machine_model)); + cfg = prop_dictionary_get(props, "i2c-child-devices"); + if (!cfg) { + cfg = prop_array_create(); + prop_dictionary_set(props, "i2c-child-devices", cfg); + prop_dictionary_set_bool(props, "i2c-indirect-config", false); + } + + /* ADM1026 at 0x2e */ + sens = prop_dictionary_create(); + prop_dictionary_set_uint32(sens, "addr", 0x2e); + prop_dictionary_set_uint64(sens, "cookie", 0); + prop_dictionary_set_string(sens, "name", "hardware-monitor"); + data = prop_data_create_copy(&name_adm[0], sizeof(name_adm)); + prop_dictionary_set(sens, "compatible", data); + prop_object_release(data); + prop_array_add(cfg, sens); + prop_object_release(sens); + + /* LM75 at 0x4e */ + sens = prop_dictionary_create(); + prop_dictionary_set_uint32(sens, "addr", 0x4e); + prop_dictionary_set_uint64(sens, "cookie", 0); + prop_dictionary_set_string(sens, "name", "temperature-sensor"); + data = prop_data_create_copy(&name_lm[0], sizeof(name_lm)); + prop_dictionary_set(sens, "compatible", data); + prop_object_release(data); + prop_array_add(cfg, sens); + prop_object_release(sens); +} + +/* Hardware specific device properties */ +static void +set_hw_props(device_t dev) +{ + device_t busdev = device_parent(dev); + + if ((!strcmp(machine_model, "SUNW,Sun-Fire-V240") || + !strcmp(machine_model, "SUNW,Sun-Fire-V210"))) { + device_t busparent = device_parent(busdev); + prop_dictionary_t props = device_properties(dev); + + if (busparent != NULL && device_is_a(busparent, "pcfiic") && + device_is_a(dev, "adm1026hm") && props != NULL) { + prop_dictionary_set_uint8(props, "fan_div2", 0x55); + prop_dictionary_set_bool(props, "multi_read", true); + } + } + + if (!strcmp(machine_model, "SUNW,Sun-Fire-V440")) { + device_t busparent = device_parent(busdev); + prop_dictionary_t props = device_properties(dev); + if (busparent != NULL && device_is_a(busparent, "pcfiic") && + device_is_a(dev, "adm1026hm") && props != NULL) { + prop_dictionary_set_bool(props, "multi_read", true); + } + } +} + +/* * Called back during autoconfiguration for each device found */ void @@ -1155,7 +1250,8 @@ device_register(device_t dev, void *aux) ofnode = (int)ia->ia_cookie; if (device_is_a(dev, "pcagpio")) { - if (strcmp(machine_model, "SUNW,Sun-Fire-V210") == 0) { + if (!strcmp(machine_model, "SUNW,Sun-Fire-V240") || + !strcmp(machine_model, "SUNW,Sun-Fire-V210")) { add_gpio_props_v210(dev, aux); } } @@ -1344,82 +1440,13 @@ noether: } } - /* - * Add SPARCle spdmem devices (0x50 and 0x51) that the - * firmware does not know about. - */ - if (!strcmp(machine_model, "TAD,SPARCLE")) { - prop_dictionary_t props = device_properties(busdev); - prop_array_t cfg = prop_array_create(); - int i; - - DPRINTF(ACDB_PROBE, ("\nAdding spdmem for SPARCle ")); - for (i = 0x50; i <= 0x51; i++) { - prop_dictionary_t spd = - prop_dictionary_create(); - prop_dictionary_set_string(spd, "name", - "dimm-spd"); - prop_dictionary_set_uint32(spd, "addr", i); - prop_dictionary_set_uint64(spd, "cookie", 0); - prop_array_add(cfg, spd); - prop_object_release(spd); - } - prop_dictionary_set(props, "i2c-child-devices", cfg); - prop_object_release(cfg); - - } + if (!strcmp(machine_model, "TAD,SPARCLE")) + add_spdmem_props_sparcle(busdev); - /* - * Add V210/V240 environmental sensors that are not in - * the OFW tree. - */ if (device_is_a(busdev, "pcfiic") && (!strcmp(machine_model, "SUNW,Sun-Fire-V240") || - !strcmp(machine_model, "SUNW,Sun-Fire-V210"))) { - prop_dictionary_t props = device_properties(busdev); - prop_array_t cfg = NULL; - prop_dictionary_t sens; - prop_data_t data; - const char name_lm[] = "i2c-lm75"; - const char name_adm[] = "i2c-adm1026"; - - DPRINTF(ACDB_PROBE, ("\nAdding sensors for %s ", - machine_model)); - cfg = prop_dictionary_get(props, "i2c-child-devices"); - if (!cfg) { - cfg = prop_array_create(); - prop_dictionary_set(props, "i2c-child-devices", - cfg); - prop_dictionary_set_bool(props, - "i2c-no-indirect-config", true); - } - - /* ADM1026 at 0x2e */ - sens = prop_dictionary_create(); - prop_dictionary_set_uint32(sens, "addr", 0x2e); - prop_dictionary_set_uint64(sens, "cookie", 0); - prop_dictionary_set_string(sens, "name", - "hardware-monitor"); - data = prop_data_create_copy(&name_adm[0], - sizeof(name_adm)); - prop_dictionary_set(sens, "compatible", data); - prop_object_release(data); - prop_array_add(cfg, sens); - prop_object_release(sens); - - /* LM75 at 0x4e */ - sens = prop_dictionary_create(); - prop_dictionary_set_uint32(sens, "addr", 0x4e); - prop_dictionary_set_uint64(sens, "cookie", 0); - prop_dictionary_set_string(sens, "name", - "temperature-sensor"); - data = prop_data_create_copy(&name_lm[0], - sizeof(name_lm)); - prop_dictionary_set(sens, "compatible", data); - prop_object_release(data); - prop_array_add(cfg, sens); - prop_object_release(sens); - } + !strcmp(machine_model, "SUNW,Sun-Fire-V210"))) + add_env_sensors_v210(busdev); } /* set properties for PCI framebuffers */ @@ -1484,26 +1511,7 @@ noether: #endif } - /* Hardware specific device properties */ - if ((!strcmp(machine_model, "SUNW,Sun-Fire-V240") || - !strcmp(machine_model, "SUNW,Sun-Fire-V210"))) { - device_t busparent = device_parent(busdev); - prop_dictionary_t props = device_properties(dev); - - if (busparent != NULL && device_is_a(busparent, "pcfiic") && - device_is_a(dev, "adm1026hm") && props != NULL) { - prop_dictionary_set_uint8(props, "fan_div2", 0x55); - prop_dictionary_set_bool(props, "multi_read", true); - } - } - if (!strcmp(machine_model, "SUNW,Sun-Fire-V440")) { - device_t busparent = device_parent(busdev); - prop_dictionary_t props = device_properties(dev); - if (busparent != NULL && device_is_a(busparent, "pcfiic") && - device_is_a(dev, "adm1026hm") && props != NULL) { - prop_dictionary_set_bool(props, "multi_read", true); - } - } + set_hw_props(dev); } /*