git: 6f9c622690fd - main - rx8803: Improve probing logic

From: Kornel Dulęba <kd_at_FreeBSD.org>
Date: Thu, 01 Dec 2022 09:15:33 UTC
The branch main has been updated by kd:

URL: https://cgit.FreeBSD.org/src/commit/?id=6f9c622690fd1faa6a6b8b1ead2760218e31328b

commit 6f9c622690fd1faa6a6b8b1ead2760218e31328b
Author:     Kornel Dulęba <kd@FreeBSD.org>
AuthorDate: 2022-12-01 05:41:41 +0000
Commit:     Kornel Dulęba <kd@FreeBSD.org>
CommitDate: 2022-12-01 09:14:58 +0000

    rx8803: Improve probing logic
    
    Add a PNP macro in order to load this driver automatically.
    While here check if the device is enabled in DT before probing it.
    
    Reviewed by:    wma
    Sponsored by:   Alstom
    Obtained from:  Semihalf
    Differential Revision: https://reviews.freebsd.org/D37579
---
 sys/dev/iicbus/rtc/rx8803.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/sys/dev/iicbus/rtc/rx8803.c b/sys/dev/iicbus/rtc/rx8803.c
index 7bd53537e755..9551b0976cd6 100644
--- a/sys/dev/iicbus/rtc/rx8803.c
+++ b/sys/dev/iicbus/rtc/rx8803.c
@@ -28,6 +28,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_platform.h"
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/bus.h>
@@ -69,6 +71,11 @@ struct rx8803_time {
 	uint8_t year;
 };
 
+static struct ofw_compat_data compat_data[] = {
+	{"epson,rx8803", 1},
+	{NULL,           0},
+};
+
 static int rx8803_probe(device_t dev);
 static int rx8803_attach(device_t dev);
 static int rx8803_detach(device_t dev);
@@ -191,7 +198,10 @@ static int
 rx8803_probe(device_t dev)
 {
 
-	if (!ofw_bus_is_compatible(dev, "epson,rx8803"))
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+
+	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
 		return (ENXIO);
 
 	device_set_desc(dev, "Epson RX8803 Real Time Clock");
@@ -238,4 +248,6 @@ static driver_t rx8803_driver = {
 };
 
 DRIVER_MODULE(rx8803, iicbus, rx8803_driver, NULL, NULL);
+MODULE_VERSION(rx8803, 1);
 MODULE_DEPEND(rx8803, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
+IICBUS_FDT_PNP_INFO(compat_data);