Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-i2c-spi-conf]: src/sys/arch/sparc64 - Move all of the stuff-miss...
details: https://anonhg.NetBSD.org/src/rev/fb6b46521aa3
branches: thorpej-i2c-spi-conf
changeset: 378780:fb6b46521aa3
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat May 15 03:22:17 2021 +0000
description:
- Move all of the stuff-missing-from-OFW-device-tree stuff into a
new function sparc64_device_tree_fixup(), and call it from
device_register().
- sparc64_device_tree_fixup() is table-driven, selecting the table
based on the machine_model. It can appy "dtnode" fixups (by matching
the device's OFW path) and "special" fixups, which are especially
useful when a property needs to be added to another device that happens
to not be in the OFW device tree.
- Implement enumeration of missing-from-OFW-device-tree i2c devices
by "sub-classing" the controller's device handle, intercepting the
"i2c-enumerate-devices" device call. We let the "super" first
enumerate any i2c devices that are in the OFW device tree, and then
enumerate our own additions after that is done. i2c additions are
provided by the machine_model fixup tables.
diffstat:
sys/arch/sparc64/dev/pcf8591_envctrl.c | 8 +-
sys/arch/sparc64/sparc64/autoconf.c | 94 +--
sys/arch/sparc64/sparc64/ofw_patch.c | 1015 +++++++++++++++++++++++--------
sys/arch/sparc64/sparc64/ofw_patch.h | 12 +-
4 files changed, 769 insertions(+), 360 deletions(-)
diffs (truncated from 1325 to 300 lines):
diff -r 011d21ff9b84 -r fb6b46521aa3 sys/arch/sparc64/dev/pcf8591_envctrl.c
--- a/sys/arch/sparc64/dev/pcf8591_envctrl.c Sat May 15 00:32:40 2021 +0000
+++ b/sys/arch/sparc64/dev/pcf8591_envctrl.c Sat May 15 03:22:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcf8591_envctrl.c,v 1.19 2021/01/27 02:20:03 thorpej Exp $ */
+/* $NetBSD: pcf8591_envctrl.c,v 1.19.4.1 2021/05/15 03:22:17 thorpej Exp $ */
/* $OpenBSD: pcf8591_envctrl.c,v 1.6 2007/10/25 21:17:20 kettenis Exp $ */
/*
@@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.19 2021/01/27 02:20:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.19.4.1 2021/05/15 03:22:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -125,9 +125,11 @@ ecadc_attach(device_t parent, device_t s
int64_t minv, warnv, crit, num, den;
u_int8_t junk[PCF8591_CHANNELS + 1];
envsys_data_t *sensor;
- int len, error, addr, chan, node = (int)ia->ia_cookie;
+ int len, error, addr, chan, node;
u_int i;
+ node = devhandle_to_of(device_handle(self));
+
sc->sc_dev = self;
sc->sc_nchan = 0;
sc->sc_hastimer = 0;
diff -r 011d21ff9b84 -r fb6b46521aa3 sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c Sat May 15 00:32:40 2021 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c Sat May 15 03:22:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.228.2.1 2021/05/13 00:47:28 thorpej Exp $ */
+/* $NetBSD: autoconf.c,v 1.228.2.2 2021/05/15 03:22:17 thorpej Exp $ */
/*
* Copyright (c) 1996
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.228.2.1 2021/05/13 00:47:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.228.2.2 2021/05/15 03:22:17 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -1005,6 +1005,9 @@ device_register(device_t dev, void *aux)
devhandle_t devhandle;
int ofnode = 0;
+ /* Fixup devices that have missing device tree information. */
+ sparc64_device_tree_fixup(dev, aux);
+
/*
* If the device has a valid OpenFirmware node association,
* grab it now.
@@ -1025,24 +1028,6 @@ device_register(device_t dev, void *aux)
* Ignore mainbus0 itself, it certainly is not a boot
* device.
*/
- } else if (device_is_a(busdev, "iic")) {
- struct i2c_attach_args *ia = aux;
-
- if (ia->ia_name == NULL) /* indirect config */
- return;
-
- ofnode = (int)ia->ia_cookie;
- if (device_is_a(dev, "pcagpio")) {
- if (!strcmp(machine_model, "SUNW,Sun-Fire-V240") ||
- !strcmp(machine_model, "SUNW,Sun-Fire-V210")) {
- add_gpio_props_v210(dev, aux);
- }
- }
- if (device_is_a(dev, "pcf8574io")) {
- if (!strcmp(machine_model, "SUNW,Ultra-250")) {
- add_gpio_props_e250(dev, aux);
- }
- }
return;
} else if (device_is_a(dev, "sd") || device_is_a(dev, "cd")) {
struct scsipibus_attach_args *sa = aux;
@@ -1097,11 +1082,6 @@ device_register(device_t dev, void *aux)
dev_bi_unit_drive_match(dev, ofnode,
periph->periph_target + off, 0, periph->periph_lun);
}
-
- if (device_is_a(busdev, "scsibus")) {
- /* see if we're in a known SCA drivebay */
- add_drivebay_props(dev, ofnode, aux);
- }
return;
} else if (device_is_a(dev, "wd")) {
struct ata_device *adev = aux;
@@ -1125,9 +1105,6 @@ device_register(device_t dev, void *aux)
ofnode = devhandle_to_of(devhandle);
}
- if (busdev == NULL)
- return;
-
if (ofnode != 0) {
uint8_t eaddr[ETHER_ADDR_LEN];
char tmpstr[32];
@@ -1224,64 +1201,6 @@ noether:
}
}
- /*
- * Check for I2C busses and add data for their direct configuration.
- */
- if (device_is_a(dev, "iic")) {
- devhandle_t bushandle = device_handle(busdev);
- int busnode =
- devhandle_type(bushandle) == DEVHANDLE_TYPE_OF ?
- devhandle_to_of(bushandle) : 0;
-
- if (busnode) {
- prop_dictionary_t props = device_properties(busdev);
- prop_object_t cfg = prop_dictionary_get(props,
- "i2c-child-devices");
- if (!cfg) {
- int node;
- const char *name;
-
- /*
- * pmu's i2c devices are under the "i2c" node,
- * so find it out.
- */
- name = prom_getpropstring(busnode, "name");
- if (strcmp(name, "pmu") == 0) {
- for (node = OF_child(busnode);
- node != 0; node = OF_peer(node)) {
- name = prom_getpropstring(node,
- "name");
- if (strcmp(name, "i2c") == 0) {
- busnode = node;
- break;
- }
- }
- }
-
- of_enter_i2c_devs(props, busnode,
- sizeof(cell_t), 1);
- }
- }
-
- if (!strcmp(machine_model, "TAD,SPARCLE"))
- add_spdmem_props_sparcle(busdev);
-
- if (device_is_a(busdev, "pcfiic") &&
- (!strcmp(machine_model, "SUNW,Sun-Fire-V240") ||
- !strcmp(machine_model, "SUNW,Sun-Fire-V210")))
- add_env_sensors_v210(busdev);
-
- /* E450 SUNW,envctrl */
- if (device_is_a(busdev, "pcfiic") &&
- (!strcmp(machine_model, "SUNW,Ultra-4")))
- add_i2c_props_e450(busdev, busnode);
-
- /* E250 SUNW,envctrltwo */
- if (device_is_a(busdev, "pcfiic") &&
- (!strcmp(machine_model, "SUNW,Ultra-250")))
- add_i2c_props_e250(busdev, busnode);
- }
-
/* set properties for PCI framebuffers */
if (device_is_a(busdev, "pci")) {
/* see if this is going to be console */
@@ -1344,10 +1263,7 @@ noether:
}
}
#endif
- set_static_edid(dict);
}
-
- set_hw_props(dev);
}
/*
diff -r 011d21ff9b84 -r fb6b46521aa3 sys/arch/sparc64/sparc64/ofw_patch.c
--- a/sys/arch/sparc64/sparc64/ofw_patch.c Sat May 15 00:32:40 2021 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_patch.c Sat May 15 03:22:17 2021 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: ofw_patch.c,v 1.7 2020/12/23 07:01:14 jdc Exp $ */
+/* $NetBSD: ofw_patch.c,v 1.7.4.1 2021/05/15 03:22:17 thorpej Exp $ */
/*-
- * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 2020, 2021 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
- * by Julian Coleman.
+ * by Julian Coleman and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,9 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7 2020/12/23 07:01:14 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.4.1 2021/05/15 03:22:17 thorpej Exp $");
#include <sys/param.h>
+#include <sys/kmem.h>
#include <dev/i2c/i2cvar.h>
#include <dev/scsipi/scsipiconf.h>
@@ -41,6 +42,10 @@
#include <sparc64/sparc64/ofw_patch.h>
#include <sparc64/sparc64/static_edid.h>
+/*****************************************************************************
+ * GPIO fixup support
+ *****************************************************************************/
+
static void
add_gpio_pin(prop_array_t pins, const char *name, int num, int act, int def)
{
@@ -54,328 +59,822 @@ add_gpio_pin(prop_array_t pins, const ch
prop_object_release(pin);
}
-static prop_array_t
-create_i2c_dict(device_t busdev)
+struct gpio_pin_fixup {
+ const char *name;
+ int num;
+ int act;
+ int def;
+};
+
+static void
+add_gpio_pins(device_t dev, const struct gpio_pin_fixup *addpins, int npins)
{
- prop_dictionary_t props = device_properties(busdev);
- prop_array_t cfg = NULL;
+ prop_dictionary_t dict = device_properties(dev);
+ prop_array_t pins = prop_array_create();
+ int i;
+
+ for (i = 0; i < npins; i++) {
+ add_gpio_pin(pins, addpins[i].name, addpins[i].num,
+ addpins[i].act, addpins[i].def);
+ }
+
+ prop_dictionary_set(dict, "pins", pins);
+ prop_object_release(pins);
+}
+
+/*****************************************************************************
+ * I2C device fixup support
+ *****************************************************************************/
+
+/*
+ * On some systems, there are lots of i2c devices missing from the
+ * device tree.
+ *
+ * The way we deal with this is by defining a devhandle_impl subclass
+ * of the i2c controller's devhandle, create a new OF-type devhandle
+ * with the new devhandle_impl, and stuff that into the controller
+ * device's handle, which will then pass that handle on down to the iic bus
+ * instance. This devhandle_impl will implement "i2c-enumerate-devices",
+ * and pass everything else along to the super.
+ *
+ * This devhandle_impl will be wrapped inside of a container structure
+ * that will point to the extra devices that need to be added as children
+ * of that node. The "i2c-enumerate-devices" call will first enumerate
+ * devices that are present in the device tree, and then enumerate the
+ * additions.
+ */
+
+struct i2c_addition {
+ const char *name;
+ const char *compat;
+ i2c_addr_t addr;
+};
+
+struct i2c_fixup_container {
+ struct devhandle_impl i2c_devhandle_impl;
+ devhandle_t i2c_super_handle;
+ const struct i2c_addition *i2c_additions;
+ int i2c_nadditions;
+ int i2c_phandle;
+};
- cfg = prop_dictionary_get(props, "i2c-child-devices");
- if (!cfg) {
- DPRINTF(ACDB_PROBE, ("\nCreating new i2c-child-devices\n"));
- cfg = prop_array_create();
- prop_dictionary_set(props, "i2c-child-devices", cfg);
- prop_dictionary_set_bool(props, "i2c-indirect-config", false);
+static int
+i2c_fixup_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
+{
+ struct i2c_enumerate_devices_args *args = v;
Home |
Main Index |
Thread Index |
Old Index