Add "cookietype" to i2c attach args, so the consumer knows if ia_cookie

is either an OF phandle or an ACPI_HANDLE. Add NXP0002 compatible mapping
while here.
This commit is contained in:
jmcneill 2021-01-25 12:15:32 +00:00
parent 10d66639d3
commit 02b41e14ea
3 changed files with 24 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: acpi_i2c.c,v 1.8 2020/08/24 05:37:41 msaitoh Exp $ */
/* $NetBSD: acpi_i2c.c,v 1.9 2021/01/25 12:15:32 jmcneill Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -30,11 +30,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.8 2020/08/24 05:37:41 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.9 2021/01/25 12:15:32 jmcneill Exp $");
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
#include <dev/acpi/acpi_i2c.h>
#include <dev/i2c/i2cvar.h>
#define _COMPONENT ACPI_BUS_COMPONENT
ACPI_MODULE_NAME ("acpi_i2c")
@ -111,6 +112,12 @@ static const struct acpi_i2c_id acpi_i2c_ids[] = {
.compatlen = 13,
.parse = acpi_enter_i2c_hid
},
{
.id = "NXP0002",
.compat = "nxp,pca9547",
.compatlen = 12,
.parse = NULL
},
{
.id = NULL,
.compat = NULL,
@ -192,6 +199,7 @@ acpi_enter_i2c_device(struct acpi_devnode *ad, prop_array_t array)
prop_dictionary_set_string(dev, "name", name);
prop_dictionary_set_uint32(dev, "addr", i2cc.i2c_addr);
prop_dictionary_set_uint64(dev, "cookie", (uintptr_t)ad->ad_handle);
prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_ACPI);
/* first search by name, then by CID */
i2c_id = acpi_i2c_search(name);
idlist = &ad->ad_devinfo->CompatibleIdList;

View File

@ -1,4 +1,4 @@
/* $NetBSD: i2cvar.h,v 1.22 2021/01/18 15:28:21 thorpej Exp $ */
/* $NetBSD: i2cvar.h,v 1.23 2021/01/25 12:15:32 jmcneill Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@ -134,6 +134,13 @@ struct i2cbus_attach_args {
prop_array_t iba_child_devices; /* child devices (direct config) */
};
/* Type of value stored in "ia_cookie" */
enum i2c_cookie_type {
I2C_COOKIE_NONE, /* Cookie is not valid */
I2C_COOKIE_OF, /* Cookie is an OF node phandle */
I2C_COOKIE_ACPI, /* Cookie is an ACPI handle */
};
/* Used to attach devices on the i2c bus. */
struct i2c_attach_args {
i2c_tag_t ia_tag; /* our controller */
@ -158,6 +165,7 @@ struct i2c_attach_args {
* On ACPI platforms this is the ACPI_HANDLE of the device.
*/
uintptr_t ia_cookie; /* OF node in openfirmware machines */
enum i2c_cookie_type ia_cookietype; /* Value type of cookie */
};
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ofw_subr.c,v 1.48 2021/01/24 21:48:38 thorpej Exp $ */
/* $NetBSD: ofw_subr.c,v 1.49 2021/01/25 12:15:33 jmcneill Exp $ */
/*
* Copyright 1998
@ -34,13 +34,14 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.48 2021/01/24 21:48:38 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.49 2021/01/25 12:15:33 jmcneill Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <dev/ofw/openfirm.h>
#include <dev/i2c/i2cvar.h>
#define OFW_MAX_STACK_BUF_SIZE 256
#define OFW_PATH_BUF_SIZE 512
@ -508,6 +509,7 @@ of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size,
prop_dictionary_set_string(dev, "name", name);
prop_dictionary_set_uint32(dev, "addr", addr);
prop_dictionary_set_uint64(dev, "cookie", node);
prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_OF);
of_to_dataprop(dev, node, "compatible", "compatible");
prop_array_add(array, dev);
prop_object_release(dev);