Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Apr 2026 16:26:52 +0000
From:      Enji Cooper <ngie@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 464afc5d0e85 - stable/14 - asmc: introduce the concept of generic models
Message-ID:  <69eceb4c.442dc.29159d19@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by ngie:

URL: https://cgit.FreeBSD.org/src/commit/?id=464afc5d0e855b478f7e8260a0ce8a1f7884806d

commit 464afc5d0e855b478f7e8260a0ce8a1f7884806d
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-02-20 06:37:05 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-04-25 16:25:42 +0000

    asmc: introduce the concept of generic models
    
    Having to enter in each of the models for Apple hardware, recompiling,
    etc, is tedious. Provide generic models so end-users can leverage some
    of the capabilities provided by the driver, i.e., common features like
    minimal fans and lights (if present on the generic model) support.
    
    The generic models are as follows:
    - Macmini
    - MacBookAir
    - MacBookPro
    - MacPro
    
    This sort of follows the pattern established by the `applesmc` driver in
    Linux.
    
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D55395
    
    (cherry picked from commit 3023bb49e115b4149f9fc0683dabde172ecb1336)
---
 sys/dev/asmc/asmc.c | 80 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 67 insertions(+), 13 deletions(-)

diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c
index b6b98b1c8953..56518269be07 100644
--- a/sys/dev/asmc/asmc.c
+++ b/sys/dev/asmc/asmc.c
@@ -160,6 +160,11 @@ static const struct asmc_model *asmc_match(device_t dev);
 
 #define ASMC_LIGHT_FUNCS_DISABLED NULL, NULL, NULL
 
+#define	ASMC_TEMPS_FUNCS_DISABLED \
+			  .smc_temps = {},		\
+			  .smc_tempnames = {},		\
+			  .smc_tempdescs = {}		\
+
 static const struct asmc_model asmc_models[] = {
 	{
 	  "MacBook1,1", "Apple SMC MacBook Core Duo",
@@ -492,8 +497,42 @@ static const struct asmc_model asmc_models[] = {
 	  ASMC_FAN_FUNCS2,
 	  ASMC_LIGHT_FUNCS,
 	  ASMC_MBA7_TEMPS, ASMC_MBA7_TEMPNAMES, ASMC_MBA7_TEMPDESCS
+	}
+};
+
+static const struct asmc_model asmc_generic_models[] = {
+	{
+	  .smc_model = "MacBookAir",
+	  .smc_desc = NULL,
+	  ASMC_SMS_FUNCS_DISABLED,
+	  ASMC_FAN_FUNCS2,
+	  ASMC_LIGHT_FUNCS,
+	  ASMC_TEMPS_FUNCS_DISABLED
+	},
+	{
+	  .smc_model = "MacBookPro",
+	  .smc_desc = NULL,
+	  ASMC_SMS_FUNCS_DISABLED,
+	  ASMC_FAN_FUNCS2,
+	  ASMC_LIGHT_FUNCS,
+	  ASMC_TEMPS_FUNCS_DISABLED
+	},
+	{
+	  .smc_model = "MacPro",
+	  .smc_desc = NULL,
+	  ASMC_SMS_FUNCS_DISABLED,
+	  ASMC_FAN_FUNCS2,
+	  ASMC_LIGHT_FUNCS_DISABLED,
+	  ASMC_TEMPS_FUNCS_DISABLED
 	},
-	{ NULL, NULL }
+	{
+	  .smc_model = "Macmini",
+	  .smc_desc = NULL,
+	  ASMC_SMS_FUNCS_DISABLED,
+	  ASMC_FAN_FUNCS2,
+	  ASMC_LIGHT_FUNCS_DISABLED,
+	  ASMC_TEMPS_FUNCS_DISABLED
+	}
 };
 
 #undef ASMC_SMS_FUNCS
@@ -541,28 +580,41 @@ MODULE_DEPEND(asmc, acpi, 1, 1, 1);
 static const struct asmc_model *
 asmc_match(device_t dev)
 {
+	const struct asmc_model *model;
+	char *model_name;
 	int i;
-	char *model;
 
-	model = kern_getenv("smbios.system.product");
-	if (model == NULL)
-		return (NULL);
+	model = NULL;
+
+	model_name = kern_getenv("smbios.system.product");
+	if (model_name == NULL)
+		goto out;
 
-	for (i = 0; asmc_models[i].smc_model; i++) {
-		if (!strncmp(model, asmc_models[i].smc_model, strlen(model))) {
-			freeenv(model);
-			return (&asmc_models[i]);
+	for (i = 0; i < nitems(asmc_models); i++) {
+		if (strncmp(model_name, asmc_models[i].smc_model,
+		    strlen(model_name)) == 0) {
+			model = &asmc_models[i];
+			goto out;
+		}
+	}
+	for (i = 0; i < nitems(asmc_generic_models); i++) {
+		if (strncmp(model_name, asmc_generic_models[i].smc_model,
+		    strlen(asmc_generic_models[i].smc_model)) == 0) {
+			model = &asmc_generic_models[i];
+			goto out;
 		}
 	}
-	freeenv(model);
 
-	return (NULL);
+out:
+	freeenv(model_name);
+	return (model);
 }
 
 static int
 asmc_probe(device_t dev)
 {
 	const struct asmc_model *model;
+	const char *device_desc;
 	int rv;
 
 	if (resource_disabled("asmc", 0))
@@ -572,11 +624,13 @@ asmc_probe(device_t dev)
 		return (rv);
 
 	model = asmc_match(dev);
-	if (!model) {
+	if (model == NULL) {
 		device_printf(dev, "model not recognized\n");
 		return (ENXIO);
 	}
-	device_set_desc(dev, model->smc_desc);
+	device_desc = model->smc_desc == NULL ?
+	    model->smc_model : model->smc_desc;
+	device_set_desc(dev, device_desc);
 
 	return (rv);
 }


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69eceb4c.442dc.29159d19>