diff mbox series

[03/10] sim7100: query device model during enable

Message ID 20240430115234.180185-3-martin@geanix.com (mailing list archive)
State Accepted
Headers show
Series [01/10] sim7100: simplify serial device opening | expand

Commit Message

Martin Hundebøll April 30, 2024, 11:52 a.m. UTC
Adding support for more simcom modems in the sim7100 driver requires
certain variants handlings based on the present modem model.

Default to an "unknown" variant to keep the existing behaviour, and
introduce the A76XX model to use when later adding support for the A7672
vartiant.
---
 plugins/sim7100.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

Comments

Denis Kenzior May 2, 2024, 2:04 p.m. UTC | #1
Hi Martin,

On 4/30/24 6:52 AM, Martin Hundebøll wrote:
> Adding support for more simcom modems in the sim7100 driver requires
> certain variants handlings based on the present modem model.
> 
> Default to an "unknown" variant to keep the existing behaviour, and
> introduce the A76XX model to use when later adding support for the A7672
> vartiant.
> ---
>   plugins/sim7100.c | 43 ++++++++++++++++++++++++++++++++++++++++---
>   1 file changed, 40 insertions(+), 3 deletions(-)
> 

Nice series!  Thanks you.  This patch was applied as well:

> +
> +	if (!ok) {
> +		ofono_error("%s: failed to query model", ofono_modem_get_path(modem));

I amended here to avoid > 80 char line.

> +		ofono_modem_set_powered(modem, FALSE);
> +		return;
> +	}

Regards,
-Denis
diff mbox series

Patch

diff --git a/plugins/sim7100.c b/plugins/sim7100.c
index b5e65891..1c80f4ba 100644
--- a/plugins/sim7100.c
+++ b/plugins/sim7100.c
@@ -59,9 +59,15 @@ 
 #include <drivers/atmodem/vendor.h>
 #include <drivers/atmodem/atutil.h>
 
+enum sim7x00_model {
+	SIMCOM_UNKNOWN = 0,
+	SIMCOM_A76XX,
+};
+
 struct sim7100_data {
 	GAtChat *at;
 	GAtChat *ppp;
+	enum sim7x00_model model;
 };
 
 static void sim7100_debug(const char *str, void *user_data)
@@ -116,6 +122,38 @@  static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		ofono_modem_set_powered(modem, TRUE);
 }
 
+static void cgmm_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct sim7100_data *data = ofono_modem_get_data(modem);
+	GAtResultIter iter;
+	const char *model;
+
+	if (!ok) {
+		ofono_error("%s: failed to query model", ofono_modem_get_path(modem));
+		ofono_modem_set_powered(modem, FALSE);
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	while (g_at_result_iter_next(&iter, NULL)) {
+		if (!g_at_result_iter_next_unquoted_string(&iter, &model))
+			continue;
+
+		DBG("modem model: %s", model);
+
+		if (g_str_has_prefix(model, "A7672"))
+			data->model = SIMCOM_A76XX;
+
+		break;
+	}
+
+	/* power up modem */
+	g_at_chat_send(data->at, "AT+CFUN=1", NULL, cfun_set_on_cb, modem,
+									NULL);
+}
+
 static int open_device(struct ofono_modem *modem, char *devkey, GAtChat **chat)
 {
 	DBG("devkey=%s", devkey);
@@ -145,9 +183,8 @@  static int sim7100_enable(struct ofono_modem *modem)
 	/* ensure modem is in a known state; verbose on, echo/quiet off */
 	g_at_chat_send(data->at, "ATE0Q0V1", NULL, NULL, NULL, NULL);
 
-	/* power up modem */
-	g_at_chat_send(data->at, "AT+CFUN=1", NULL, cfun_set_on_cb,
-								modem, NULL);
+	/* query modem model string */
+	g_at_chat_send(data->at, "AT+CGMM", NULL, cgmm_cb, modem, NULL);
 
 	return -EINPROGRESS;
 }