gnss: motmdm: Add support for Motorola Mapphone MDM6600 modem
Subsystems (6)
PATCH 1/1 gnss: motmdm: Add support for Motorola Mapphone MDM6600 modem
Motorola is using a custom TS 27.010 based serial port line discipline for various devices on the modem. These devices can be accessed on dedicated channels using Linux kernel serdev-ngsm driver.
For the GNSS on these devices, we need to kick the GNSS device at a desired rate. Otherwise the GNSS device stops sending data after a few minutes. The rate we poll data defaults to 1000 ms, and can be specified with a module option rate_ms between 1 to 16 seconds.
[Tony Lindgren did most of the work here, I just converted it to be normal serdev.]
drivers/gnss/Kconfig +8 -0
@@ -13,6 +13,14 @@ menuconfig GNSS if GNSS +config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSM + help + Say Y here if you have a Motorola modem using TS 27.010 line + discipline for GNSS such as a Motorola Mapphone series device + like Droid 4. + config GNSS_SERIAL tristate
drivers/gnss/Makefile +3 -0
@@ -6,6 +6,9 @@ obj-$(CONFIG_GNSS) += gnss.o gnss-y := core.o +obj-$(CONFIG_GNSS_MOTMDM) += gnss-motmdm.o +gnss-motmdm-y := motmdm.o + obj-$(CONFIG_GNSS_SERIAL) += gnss-serial.o gnss-serial-y := serial.o
drivers/gnss/motmdm.c new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Hi!
Quoted 9 lines
Motorola is using a custom TS 27.010 based serial port line discipline for various devices on the modem. These devices can be accessed on dedicated channels using Linux kernel serdev-ngsm driver.
For the GNSS on these devices, we need to kick the GNSS device at a desired rate. Otherwise the GNSS device stops sending data after a few minutes. The rate we poll data defaults to 1000 ms, and can be specified with a module option
rate_msbetween 1 to 16 seconds.
Quoted 4 lines
[Tony Lindgren did most of the work here, I just converted it to be normal serdev.]
Signed-off-by Pavel Machek <[email protected]>
20 days... ping...?
Pavel
Quoted 452 lines
drivers/gnss/Kconfig +8
-0@@ -13,6 +13,14 @@ menuconfig GNSS if GNSS +config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSM + help + Say Y here if you have a Motorola modem using TS 27.010 line + discipline for GNSS such as a Motorola Mapphone series device + like Droid 4. + config GNSS_SERIAL tristatedrivers/gnss/Makefile +3
-0@@ -6,6 +6,9 @@ obj-$(CONFIG_GNSS) += gnss.o gnss-y := core.o +obj-$(CONFIG_GNSS_MOTMDM) += gnss-motmdm.o +gnss-motmdm-y := motmdm.o + obj-$(CONFIG_GNSS_SERIAL) += gnss-serial.o gnss-serial-y := serial.odrivers/gnss/motmdm.c new file +409
-0@@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Motorola Modem TS 27.010 serdev GNSS driver +* +* Copyright (C) 2018 - 2020 Tony Lindgren <[email protected]> +* Copyright (C) 2020 - 2021 Pavel Machek <[email protected]> +* +* Based on drivers/gnss/sirf.c driver example: +* Copyright (C) 2018 Johan Hovold <[email protected]> +*/ + +#include <linux/errno.h> +#include <linux/gnss.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/serdev-gsm.h> +#include <linux/slab.h> + +#define MOTMDM_GNSS_TIMEOUT 1000 +#define MOTMDM_GNSS_RATE 1000 + +/* +* Motorola MDM GNSS device communicates over a dedicated TS 27.010 channel +* using custom data packets. The packets look like AT commands embedded into +* a Motorola invented packet using format like "U1234AT+MPDSTART=0,1,100,0". +* But it's not an AT compatible serial interface, it's a packet interface +* using AT like commands. +*/ +#define MOTMDM_GNSS_HEADER_LEN 5/* U1234 */ +#define MOTMDM_GNSS_RESP_LEN (MOTMDM_GNSS_HEADER_LEN + 4)/* U1234+MPD */ +#define MOTMDM_GNSS_DATA_LEN (MOTMDM_GNSS_RESP_LEN + 1)/* U1234~+MPD */ +#define MOTMDM_GNSS_STATUS_LEN (MOTMDM_GNSS_DATA_LEN + 7)/* STATUS= */ +#define MOTMDM_GNSS_NMEA_LEN (MOTMDM_GNSS_DATA_LEN + 8)/* NMEA=NN, */ + +enum motmdm_gnss_status { +MOTMDM_GNSS_UNKNOWN , +MOTMDM_GNSS_INITIALIZED , +MOTMDM_GNSS_DATA_OR_TIMEOUT , +MOTMDM_GNSS_STARTED , +MOTMDM_GNSS_STOPPED , +}; + +struct motmdm_gnss_data { +struct gnss_device *gdev; +struct device *modem; +struct serdev_device *serdev; +struct delayed_work restart_work; +struct mutex mutex;/* For modem commands */ +ktime_t last_update; +int status; +unsigned char *buf; +size_t len; +wait_queue_head_t read_queue; +unsigned int parsed:1 ; +}; + +static unsigned int rate_ms =MOTMDM_GNSS_RATE ; +module_param (rate_ms, uint,0644 ); +MODULE_PARM_DESC (rate_ms,"GNSS refresh rate between 1000 and 16000 ms (default 1000 ms)" ); + +/* +* Note that multiple commands can be sent in series with responses coming +* out-of-order. For GNSS, we don't need to care about the out-of-order +* responses, and can assume we have at most one command active at a time. +* For the commands, can use just a jiffies base packet ID and let the modem +* sort out the ID conflicts with the modem's unsolicited message ID +* numbering. +*/ +int motmdm_gnss_send_command (struct motmdm_gnss_data *ddata, +const u8 *buf,int len) +{ +struct gnss_device *gdev = ddata->gdev; +const int timeout_ms =1000 ; +unsigned char cmd[128 ]; +int ret, cmdlen; + + cmdlen = len +MOTMDM_GNSS_HEADER_LEN +1 ; +if (cmdlen >128 ) +return -EINVAL ; + +mutex_lock (&ddata->mutex); +memset (ddata->buf,0 , ddata->len); + ddata->parsed = false; +snprintf (cmd, cmdlen,"U%04li%s" , jiffies %10000 , buf); + + ret =serdev_device_write (ddata->serdev, cmd, cmdlen,MAX_SCHEDULE_TIMEOUT ); +if (ret <0 ) + goto out_unlock; + +serdev_device_wait_until_sent (ddata->serdev,0 ); + + ret =wait_event_timeout (ddata->read_queue, ddata->parsed, +msecs_to_jiffies (timeout_ms)); +if (ret ==0 ) { + ret = -ETIMEDOUT ; + goto out_unlock; + }else if (ret <0 ) { + goto out_unlock; + } + +if (!strstr (ddata->buf,":OK" )) { +dev_err (&gdev->dev,"command %s error %s\n" , + cmd, ddata->buf); + ret = -EPIPE ; + } + + ret = len; + +out_unlock: +mutex_unlock (&ddata->mutex); + +return ret; +} + +/* +* Android uses AT+MPDSTART=0,1,100,0 which starts GNSS for a while, +* and then GNSS needs to be kicked with an AT command based on a +* status message. +*/ +static void motmdm_gnss_restart (struct work_struct *work) +{ +struct motmdm_gnss_data *ddata = + container_of(work, struct motmdm_gnss_data, + restart_work.work); +struct gnss_device *gdev = ddata->gdev; +const unsigned char *cmd ="AT+MPDSTART=0,1,100,0" ; +int error; + + ddata->last_update =ktime_get (); + + error =motmdm_gnss_send_command (ddata, cmd,strlen (cmd)); +if (error <0 ) { +/* Timeouts can happen, don't warn and try again */ +if (error != -ETIMEDOUT ) +dev_warn (&gdev->dev,"%s: could not start: %i\n" , + __func__, error); + +schedule_delayed_work (&ddata->restart_work, +msecs_to_jiffies (MOTMDM_GNSS_RATE )); + } +} + +static void motmdm_gnss_start (struct gnss_device *gdev,int delay_ms) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +ktime_t now, next, delta; +int next_ms; + + now =ktime_get (); + next =ktime_add_ms (ddata->last_update, delay_ms); + delta =ktime_sub (next, now); + next_ms =ktime_to_ms (delta); + +if (next_ms <0 ) + next_ms =0 ; +if (next_ms > delay_ms) + next_ms = delay_ms; + +schedule_delayed_work (&ddata->restart_work,msecs_to_jiffies (next_ms)); +} + +static int motmdm_gnss_stop (struct gnss_device *gdev) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +const unsigned char *cmd ="AT+MPDSTOP" ; + +cancel_delayed_work_sync (&ddata->restart_work); + +return motmdm_gnss_send_command (ddata, cmd,strlen (cmd)); +} + +static int motmdm_gnss_init (struct gnss_device *gdev) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +const unsigned char *cmd ="AT+MPDINIT=1" ; +int error; + + error =motmdm_gnss_send_command (ddata, cmd,strlen (cmd)); +if (error <0 ) +return error; + +motmdm_gnss_start (gdev,0 ); + +return 0 ; +} + +static int motmdm_gnss_finish (struct gnss_device *gdev) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +const unsigned char *cmd ="AT+MPDINIT=0" ; +int error; + + error =motmdm_gnss_stop (gdev); +if (error <0 ) +return error; + +return motmdm_gnss_send_command (ddata, cmd,strlen (cmd)); +} + +static int motmdm_gnss_receive_data (struct serdev_device *serdev, +const unsigned char *buf,size_t len) +{ +struct motmdm_gnss_data *ddata =serdev_device_get_drvdata (serdev); +struct gnss_device *gdev = ddata->gdev; +const unsigned char *msg; +size_t msglen; +int error =0 ; + +if (len <=MOTMDM_GNSS_RESP_LEN ) +return 0 ; + +/* Handle U1234+MPD style command response */ +if (buf[MOTMDM_GNSS_HEADER_LEN ] !='~' ) { + msg = buf +MOTMDM_GNSS_RESP_LEN ; +strncpy (ddata->buf, msg, len -MOTMDM_GNSS_RESP_LEN ); + ddata->parsed = true; +wake_up (&ddata->read_queue); + +return len; + } + +if (len <=MOTMDM_GNSS_DATA_LEN ) +return 0 ; + +/* Handle U1234~+MPD style unsolicted message */ +switch (buf[MOTMDM_GNSS_DATA_LEN ]) { +case 'N' :/* UNNNN~+MPDNMEA=NN, */ + msg = buf +MOTMDM_GNSS_NMEA_LEN ; + msglen = len -MOTMDM_GNSS_NMEA_LEN ; + +/* +* Firmware bug: Strip out extra duplicate line break always +* in the data +*/ + msglen--; + +/* +* Firmware bug: Strip out extra data based on an +* earlier line break in the data +*/ +if (msg[msglen -5 -1 ] ==0x0a ) + msglen -=5 ; + + error =gnss_insert_raw (gdev, msg, msglen); +WARN_ON (error); +break ; +case 'S' :/* UNNNN~+MPDSTATUS=N,NN */ + msg = buf +MOTMDM_GNSS_STATUS_LEN ; + msglen = len -MOTMDM_GNSS_STATUS_LEN ; + +switch (msg[0 ]) { +case '1' : + ddata->status =MOTMDM_GNSS_INITIALIZED ; +break ; +case '2' : + ddata->status =MOTMDM_GNSS_DATA_OR_TIMEOUT ; +if (rate_ms <MOTMDM_GNSS_RATE ) + rate_ms =MOTMDM_GNSS_RATE ; +if (rate_ms >16 *MOTMDM_GNSS_RATE ) + rate_ms =16 *MOTMDM_GNSS_RATE ; +motmdm_gnss_start (gdev, rate_ms); +break ; +case '3' : + ddata->status =MOTMDM_GNSS_STARTED ; +break ; +case '4' : + ddata->status =MOTMDM_GNSS_STOPPED ; +break ; +default : + ddata->status =MOTMDM_GNSS_UNKNOWN ; +break ; + } +break ; +case 'X' :/* UNNNN~+MPDXREQ=N for updated xtra2.bin needed */ +default : +break ; + } + +return len; +} + +static const struct serdev_device_ops gnss_serdev_ops = { + .receive_buf = motmdm_gnss_receive_data, + .write_wakeup = serdev_device_write_wakeup, +}; + +static int motmdm_gnss_open (struct gnss_device *gdev) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +int error; + +serdev_device_set_client_ops (ddata->serdev, &gnss_serdev_ops); + + error =serdev_device_open (ddata->serdev); +if (error) { +return error; + } + + error =motmdm_gnss_init (gdev); +if (error) { +return error; + } + +return 0 ; +} + +static void motmdm_gnss_close (struct gnss_device *gdev) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); +int error; + + error =motmdm_gnss_finish (gdev); +if (error <0 ) +dev_warn (&gdev->dev,"%s: close failed: %i\n" , + __func__, error); + +serdev_device_close (ddata->serdev); +} + +static int motmdm_gnss_write_raw (struct gnss_device *gdev, +const unsigned char *buf, +size_t count) +{ +struct motmdm_gnss_data *ddata =gnss_get_drvdata (gdev); + +return serdev_device_write (ddata->serdev, buf, count,MAX_SCHEDULE_TIMEOUT ); +serdev_device_wait_until_sent (ddata->serdev,0 ); + +return count; +} + +static const struct gnss_operations motmdm_gnss_ops = { + .open = motmdm_gnss_open, + .close = motmdm_gnss_close, + .write_raw = motmdm_gnss_write_raw, +}; + +static int motmdm_gnss_probe (struct serdev_device *serdev) +{ +struct device *dev = &serdev->dev; +struct motmdm_gnss_data *ddata; +struct gnss_device *gdev; +int ret; + + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + + ddata->serdev = serdev; + ddata->modem = dev->parent; + ddata->len =PAGE_SIZE ; +mutex_init (&ddata->mutex); +INIT_DELAYED_WORK (&ddata->restart_work, motmdm_gnss_restart); +init_waitqueue_head (&ddata->read_queue); + + ddata->buf =devm_kzalloc (dev, ddata->len,GFP_KERNEL ); +if (!ddata->buf) +return -ENOMEM ; + +serdev_device_set_drvdata (serdev, ddata); + + gdev =gnss_allocate_device (dev); +if (!gdev) +return -ENOMEM ; + + gdev->type =GNSS_TYPE_NMEA ; + gdev->ops = &motmdm_gnss_ops; +gnss_set_drvdata (gdev, ddata); + ddata->gdev = gdev; + + ret =gnss_register_device (gdev); +if (ret) +gnss_put_device (ddata->gdev); + +return ret; +} + +static void motmdm_gnss_remove (struct serdev_device *serdev) +{ +struct motmdm_gnss_data *data =serdev_device_get_drvdata (serdev); + +gnss_deregister_device (data->gdev); +gnss_put_device (data->gdev); +}; + +#ifdef CONFIG_OF +static const struct of_device_id motmdm_gnss_of_match[] = { + { .compatible ="motorola,mapphone-mdm6600-gnss" }, + {}, +}; +MODULE_DEVICE_TABLE (of, motmdm_gnss_of_match); +#endif + +static struct serdev_device_driver motmdm_gnss_driver = { + .driver = { + .name ="gnss-mot-mdm6600" , + .of_match_table =of_match_ptr (motmdm_gnss_of_match), + }, + .probe = motmdm_gnss_probe, + .remove = motmdm_gnss_remove, +}; +module_serdev_device_driver (motmdm_gnss_driver); + +MODULE_AUTHOR ("Tony Lindgren <[email protected]>" ); +MODULE_DESCRIPTION ("Motorola Mapphone MDM6600 GNSS receiver driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 2 lines
-- http://www.livejournal.com/~pavelmachek
Signature · 1 line
http://www.livejournal.com/~pavelmachek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 21 lines
Quoted 1 line
Motorola is using a custom TS 27.010 based serial port line discipline
s/serial port line discipline/multiplexer protocol/
drivers/gnss/Kconfig menuconfig GNSS · line 18
Quoted 11 lines
drivers/gnss/Kconfig +3
-0@@ -13,6 +13,14 @@ menuconfig GNSS if GNSS +config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSMYou need to post this driver together with the serdev-ngsm driver. This one cannot currently even be built without it, but we also need to see the greater picture here.
Quoted 1 line
Does this even still need to be a build-time dependency?
Not any more, it is now normal serdev driver, that's why I posted it separately.
Quoted 3 lines
drivers/gnss/Kconfig menuconfig GNSS · line 20
Quoted 1 line
drivers/gnss/Kconfig +1
-0+ Say Y here if you have a Motorola modem using TS 27.010 lines/line discipline/multiplexer protocol/
Ok.
Quoted 8 lines
drivers/gnss/Kconfig menuconfig GNSS · line 24
Quoted 5 lines
drivers/gnss/Kconfig +5
-0+#define MOTMDM_GNSS_HEADER_LEN 5 /* U1234 */ +#define MOTMDM_GNSS_RESP_LEN (MOTMDM_GNSS_HEADER_LEN + 4) /* U1234+MPD */ +#define MOTMDM_GNSS_DATA_LEN (MOTMDM_GNSS_RESP_LEN + 1) /* U1234~+MPD */ +#define MOTMDM_GNSS_STATUS_LEN (MOTMDM_GNSS_DATA_LEN + 7) /* STATUS= */ +#define MOTMDM_GNSS_NMEA_LEN (MOTMDM_GNSS_DATA_LEN + 8) /* NMEA=NN, */The comments are inconsistent; does the latter two have a "U1234" prefix?
It is U1234~+MPDSTATUS= and U1234~+MPDNMEA=NN, -- will fix. Hopefully 85 columns is okay with you here.
Quoted 12 lines
drivers/gnss/Kconfig menuconfig GNSS
Quoted 9 lines
drivers/gnss/Kconfig +9
-0+ /* + * Firmware bug: Strip out extra data based on an + * earlier line break in the data + */ + if (msg[msglen - 5 - 1] == 0x0a) + msglen -= 5; + + error = gnss_insert_raw(gdev, msg, msglen); + WARN_ON(error);The return value is not an "error" but the number of queued bytes.
Quoted 1 line
So that
WARN_ON(error)makes it look like you never even tested this?
Well, I did test it and it works. Unfortunately Droid 4 produces lot of output during normal operation, including periodic WARNs, so I missed that. Sorry about that.
Quoted 6 lines
drivers/gnss/Kconfig
Quoted 4 lines
drivers/gnss/Kconfig +4
-0+ error = serdev_device_open(ddata->serdev); + if (error) { + return error; + }Nit: drop the brackets.
Ok.
Quoted 4 lines
drivers/gnss/Kconfig
Quoted 2 lines
drivers/gnss/Kconfig +2
-0+ error = motmdm_gnss_init(gdev); + if (error) {You must close the port before returning.
Ok.
Quoted 10 lines
drivers/gnss/Kconfig
Quoted 8 lines
drivers/gnss/Kconfig +8
-0+static int motmdm_gnss_write_raw(struct gnss_device *gdev, + const unsigned char *buf, + size_t count) +{ + struct motmdm_gnss_data *ddata = gnss_get_drvdata(gdev); + + return serdev_device_write(ddata->serdev, buf, count, MAX_SCHEDULE_TIMEOUT); + serdev_device_wait_until_sent(ddata->serdev, 0);This code is never reached.
Fixed.
I'll get new version out. I'll also get serdev/ngsm patch out for context, but that one needs more work.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC/context] add serdev interfaces to n_gsm
Hi!
Quoted 8 lines
Quoted 7 lines
drivers/gnss/Kconfig menuconfig GNSS · line 18
Quoted 3 lines
drivers/gnss/Kconfig +3
-0+config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSMYou need to post this driver together with the serdev-ngsm driver. This one cannot currently even be built without it, but we also need to see the greater picture here.
Quoted 4 lines
Well, here it is, for greater picture. But it is not ready. Current problem I have is
gsm_serdev_register_tty_port(). The way I do platform device registration causes oops on module unload. Help with that would be welcome
I would not mind comments on parent patch and some help here.
Basically I tried to work around limitation in
int serdev_device_add(struct serdev_device *serdev) {
...
/* Only a single slave device is currently supported. */
if (ctrl->serdev) {
...
return -EBUSY;Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Johan Hovold
maintainerRe: [RFC/context] add serdev interfaces to n_gsm
Quoted 17 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
drivers/gnss/Kconfig menuconfig GNSS · line 18
Quoted 3 lines
drivers/gnss/Kconfig +3
-0+config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSMYou need to post this driver together with the serdev-ngsm driver. This one cannot currently even be built without it, but we also need to see the greater picture here.
Quoted 4 lines
Well, here it is, for greater picture. But it is not ready. Current problem I have is
gsm_serdev_register_tty_port(). The way I do platform device registration causes oops on module unload. Help with that would be welcomeI would not mind comments on parent patch and some help here.
Quoted 8 lines
Basically I tried to work around limitation in
int
serdev_device_add(struct serdev_device *serdev){
.../* Only a single slave device is currently supported. */ if (ctrl->serdev) {...
I haven't really had time to look at the code yet, but trying to work around the single-client (slave) assumption seems wrong. You still have only one client per port even if the mux driver provides multiple (virtual) ports.
But judging from a quick look it appears that you are indeed registering one tty device per mux channel in gsm_serdev_register_tty_port() (as you should) so perhaps that's not the issue here.
Do you have a stack trace from the oops? Are the client drivers holding the ports open while you unload the parent driver? That sounds like something which could go boom unless you pin the parent for example (serdev doesn't support hangups).
Also, did you forget to post the gsm_tty_driver implementation? I don't see a definition of that symbol in the patch.
Johan
Re: [RFC/context] add serdev interfaces to n_gsm
Hi!
Quoted 24 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
drivers/gnss/Kconfig menuconfig GNSS · line 18
Quoted 3 lines
drivers/gnss/Kconfig +3
-0+config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_N_GSMYou need to post this driver together with the serdev-ngsm driver. This one cannot currently even be built without it, but we also need to see the greater picture here.
Quoted 4 lines
Well, here it is, for greater picture. But it is not ready. Current problem I have is
gsm_serdev_register_tty_port(). The way I do platform device registration causes oops on module unload. Help with that would be welcomeI would not mind comments on parent patch and some help here.
Quoted 8 lines
Basically I tried to work around limitation in
int
serdev_device_add(struct serdev_device *serdev){
.../* Only a single slave device is currently supported. */ if (ctrl->serdev) {...
Quoted 4 lines
I haven't really had time to look at the code yet, but trying to work around the single-client (slave) assumption seems wrong. You still have only one client per port even if the mux driver provides multiple (virtual) ports.
Correct.
But this limitation prevents me to registering multiple slave ports with master serdev as their parent.
a) There's a physical line
b) Then there's serdev connected to it
c) Mux splits it to many virtual ports, but I still need something to specify as their parent. serdev b) would be most suitable, but this check prevents that.
Quoted 11 lines
But judging from a quick look it appears that you are indeed registering one tty device per mux channel in
gsm_serdev_register_tty_port()(as you should) so perhaps that's not the issue here.Do you have a stack trace from the oops? Are the client drivers holding the ports open while you unload the parent driver? That sounds like something which could go boom unless you pin the parent for example (serdev doesn't support hangups).
Also, did you forget to post the
gsm_tty_driverimplementation? I don't see a definition of that symbol in the patch.
I'll gather the data in next debugging session.
But .... this way I have to provide fake platform device parent for gsmtty1 and friends, and that just feels wrong.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
PATCH v2 1/1 gnss: motmdm: Add support for Motorola Mapphone MDM6600 modem
In reply to Pavel MachekMotorola is using a custom TS 27.010 based multiplexer protocol for various devices on the modem. These devices can be accessed on dedicated channels using Linux kernel serdev-ngsm driver.
For the GNSS on these devices, we need to kick the GNSS device at a desired rate. Otherwise the GNSS device stops sending data after a few minutes. The rate we poll data defaults to 1000 ms, and can be specified with a module option rate_ms between 1 to 16 seconds.
[Tony Lindgren did most of the work here, I just converted it to be normal serdev.]
drivers/gnss/Kconfig +8 -0
@@ -13,6 +13,14 @@ menuconfig GNSS if GNSS +config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_BUS + help + Say Y here if you have a Motorola modem using TS 27.010 + multiplexer protocol for GNSS such as a Motorola Mapphone + series device like Droid 4. + config GNSS_SERIAL tristate
drivers/gnss/Makefile +3 -0
@@ -6,6 +6,9 @@ obj-$(CONFIG_GNSS) += gnss.o gnss-y := core.o +obj-$(CONFIG_GNSS_MOTMDM) += gnss-motmdm.o +gnss-motmdm-y := motmdm.o + obj-$(CONFIG_GNSS_SERIAL) += gnss-serial.o gnss-serial-y := serial.o
drivers/gnss/motmdm.c new file +406 -0
406 lines not on this page · raw message
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Hi!
Quoted 11 lines
Motorola is using a custom TS 27.010 based multiplexer protocol for various devices on the modem. These devices can be accessed on dedicated channels using Linux kernel serdev-ngsm driver.
For the GNSS on these devices, we need to kick the GNSS device at a desired rate. Otherwise the GNSS device stops sending data after a few minutes. The rate we poll data defaults to 1000 ms, and can be specified with a module option
rate_msbetween 1 to 16 seconds.[Tony Lindgren did most of the work here, I just converted it to be normal serdev.]
Could I get some comments on the gnss patch? It is fairly simple, and I believe it is ready for merge.
Here's new version of the serdev multiplexing patch for reference. And yes, I'd like you to review the design here, too. Yes, gsm_serdev_register_tty_port() needs to be cleaned up, but with ifdefs you can see alternative approach I tried to work around "controller busy" problem.
Best regards,
Pavel
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +73 -0
@@ -0,0 +1,73 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/serdev/serdev-ngsm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic serdev-ngsm TS 27.010 driver + +maintainers: + - Tony Lindgren <[email protected]> + +properties: + compatible: + enum: + - etsi,3gpp-ts27010-adaption1 + - motorola,mapphone-mdm6600-serial + + ttymask: + $ref: /schemas/types.yaml#/definitions/uint64 + description: Mask of the TS 27.010 channel TTY interfaces to start (64 bit) + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +allOf: + - if: + properties: + compatible: + contains: + const: motorola,mapphone-mdm6600-serial + then: + properties: + phys: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: USB PHY needed for shared GPIO PM wake-up pins + maxItems: 1 + + phy-names: + description: Name of the USB PHY + const: usb + + compatible: + description: GNSS receiver + const: motorola,mapphone-mdm6600-gnss + + required: + - phys + - phy-names + +required: + - compatible + - ttymask + - "#address-cells" + - "#size-cells" + +examples: + - | + modem { + compatible = "motorola,mapphone-mdm6600-serial"; + ttymask = <0 0x00001fee>; + phys = <&fsusb1_phy>; + phy-names = "usb"; + #address-cells = <1>; + #size-cells = <0>; + + gnss@4 { + compatible = "motorola,mapphone-mdm6600-gnss"; + reg = <4>; + }; + };
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -341,6 +341,8 @@ patternProperties: description: Espressif Systems Co. Ltd. "^est,.*": description: ESTeem Wireless Modems + "^etsi,.*": + description: ETSI "^ettus,.*": description: NI Ettus Research "^eukrea,.*":
drivers/gnss/Kconfig +8 -0
@@ -13,6 +13,14 @@ menuconfig GNSS if GNSS +config GNSS_MOTMDM + tristate "Motorola Modem TS 27.010 serdev GNSS receiver support" + depends on SERIAL_DEV_BUS + help + Say Y here if you have a Motorola modem using TS 27.010 + multiplexer protocol for GNSS such as a Motorola Mapphone + series device like Droid 4. + config GNSS_SERIAL tristate
drivers/gnss/Makefile +3 -0
@@ -6,6 +6,9 @@ obj-$(CONFIG_GNSS) += gnss.o gnss-y := core.o +obj-$(CONFIG_GNSS_MOTMDM) += gnss-motmdm.o +gnss-motmdm-y := motmdm.o + obj-$(CONFIG_GNSS_SERIAL) += gnss-serial.o gnss-serial-y := serial.o
drivers/tty/n_gsm.c +424 -7
490 lines not on this page · raw message
drivers/tty/serdev/Kconfig +10 -0
@@ -22,4 +22,14 @@ config SERIAL_DEV_CTRL_TTYPORT depends on SERIAL_DEV_BUS != m default y +config SERIAL_DEV_N_GSM + tristate "Serial device TS 27.010 support" + depends on N_GSM + depends on SERIAL_DEV_CTRL_TTYPORT + help + Select this if you want to use the TS 27.010 with a serial port with + devices such as modems and GNSS devices. + + If unsure, say N. + endif
drivers/tty/serdev/Makefile +1 -0
@@ -4,3 +4,4 @@ serdev-objs := core.o obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o obj-$(CONFIG_SERIAL_DEV_CTRL_TTYPORT) += serdev-ttyport.o +obj-$(CONFIG_SERIAL_DEV_N_GSM) += serdev-ngsm.o
drivers/tty/serdev/serdev-ngsm.c new file +419 -0
419 lines not on this page · raw message
include/linux/printk.h +7 -15
@@ -572,6 +572,13 @@ extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,extern void print_hex_dump (const char *level,const char *prefix_str,int prefix_type,int rowsize,int groupsize,const void *buf,size_t len,bool ascii); +#if defined(CONFIG_DYNAMIC_DEBUG ) +#define print_hex_dump_bytes (prefix_str, prefix_type, buf, len) \ + dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) +#else +extern void print_hex_dump_bytes (const char *prefix_str,int prefix_type, +const void *buf,size_t len); +#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ #else static inline void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize,
@@ -604,19 +611,4 @@ static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, }#endif -/** -* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params -* @prefix_str: string to prefix each line with; -* caller supplies trailing spaces for alignment if desired -* @prefix_type: controls whether prefix of an offset, address, or none -* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) -* @buf: data blob to dump -* @len: number of bytes in the @buf -* -* Calls print_hex_dump(), with log level of KERN_DEBUG, -* rowsize of 16, groupsize of 1, and ASCII output included. -*/ -#define print_hex_dump_bytes (prefix_str, prefix_type, buf, len) \ - print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true) -#endif
include/linux/serdev-gsm.h new file +175 -0
175 lines not on this page · raw message
lib/hexdump.c +21 -0
@@ -270,4 +270,25 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, }EXPORT_SYMBOL (print_hex_dump); +#if !defined(CONFIG_DYNAMIC_DEBUG ) +/** +* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params +* @prefix_str: string to prefix each line with; +* caller supplies trailing spaces for alignment if desired +* @prefix_type: controls whether prefix of an offset, address, or none +* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) +* @buf: data blob to dump +* @len: number of bytes in the @buf +* +* Calls print_hex_dump(), with log level of KERN_DEBUG, +* rowsize of 16, groupsize of 1, and ASCII output included. +*/ +void print_hex_dump_bytes (const char *prefix_str,int prefix_type, +const void *buf,size_t len) +{ +print_hex_dump (KERN_DEBUG , prefix_str, prefix_type,16 ,1 , + buf, len, true); +} +EXPORT_SYMBOL (print_hex_dump_bytes); +#endif /* !defined(CONFIG_DYNAMIC_DEBUG) */ #endif /* defined(CONFIG_PRINTK) */
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Johan Hovold
maintainerQuoted 11 lines · Pavel Machek
Hi!
Quoted 9 lines
Motorola is using a custom TS 27.010 based multiplexer protocol for various devices on the modem. These devices can be accessed on dedicated channels using Linux kernel serdev-ngsm driver.
For the GNSS on these devices, we need to kick the GNSS device at a desired rate. Otherwise the GNSS device stops sending data after a few minutes. The rate we poll data defaults to 1000 ms, and can be specified with a module option
rate_msbetween 1 to 16 seconds.
Quoted 5 lines
Quoted 2 lines
[Tony Lindgren did most of the work here, I just converted it to be normal serdev.]
Could I get some comments on the gnss patch? It is fairly simple, and I believe it is ready for merge.
Let's get the mux driver in shape first.
Quoted 5 lines
Here's new version of the serdev multiplexing patch for reference. And yes, I'd like you to review the design here, too. Yes,
gsm_serdev_register_tty_port()needs to be cleaned up, but with ifdefs you can see alternative approach I tried to work around "controller busy" problem.
As I said before, if you're trying to work around the one client-per-port assumption of serdev, you're doing it wrong. You still have one client per *virtual* port.
Quoted 10 lines
Signed-off-by Pavel Machek <[email protected]>Best regards,
PavelDocumentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +0
-0
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml line 20
Quoted 4 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +3
-0+ ttymask: + $ref: /schemas/types.yaml#/definitions/uint64 + description: Mask of the TS 27.010 channel TTY interfaces to start (64 bit)
How is this intended to be used? Looks too Linux-specific for a binding.
Quoted 5 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +5
-0+examples: + - | + modem { + compatible = "motorola,mapphone-mdm6600-serial"; + ttymask = <0 0x00001fee>;
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml line 73
Quoted 10 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +10
-0+ phys = <&fsusb1_phy>; + phy-names = "usb"; + #address-cells = <1>; + #size-cells = <0>; + + gnss@4 { + compatible = "motorola,mapphone-mdm6600-gnss"; + reg = <4>; + }; + };
So is this is probably the issue: you're skipping one level of the topology and do not describe the virtual ports.
This should instead be something like below; I'm including one level above for the full picture:
serial@nnn {
compatible = "ns16550a";
reg = <nnn>;
modem {
compatible = "ts27010-mux, motorola,mapphone-mdm6600-serial";
serial@4 {
reg = <4>
gnss {
compatible = "motorola,mapphone-mdm6600-gnss";
};
};
};
};Here serial@nnn is a normal serial port, modem is the modem (TS 27.010 mux) connected to the serial port, serial@4 is virtual port number four of the mux, and gnss is the gnss device connected to the virtual port.
You should probably just replace the ttymask property with explicit nodes for the virtual ports to enable. With no client devices described in devicetree, these will then show up as regular tty devices under Linux.
If you add a compatible property for the virtual ports (e.g. "ts27010-port") you might be able to just use of_platform_populate() instead of walking the child nodes in gsm_serdev_register_tty_port().
Quoted 74 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +74
-0+int gsm_serdev_register_tty_port(struct gsm_serdev *gsd, int line) +{ + struct gsm_serdev_dlci_operations *ops; + unsigned int base; + int error; + struct device *dev; + struct device_node *node; + struct device *dev2 = NULL; + struct device *ndev; + + if (line < 1) + return -EINVAL; + + ops = kzalloc(sizeof(*ops), GFP_KERNEL); + if (!ops) + return -ENOMEM; + + ops->line = line; + ops->receive_buf = gsd_dlci_receive_buf; + + error = gsm_serdev_register_dlci(gsd, ops); + if (error) + goto error; + + base = mux_num_to_base(gsd->gsm); + printk("register_tty_port: have port: %p, %d+%d\n", &gsd->gsm->dlci[line]->port, base, ops->line); + dev = &gsd->serdev->dev; + + for_each_available_child_of_node(dev->of_node, node) { + struct platform_device_info devinfo = {}; + static int idx; + struct platform_device *pdev; + const char *c = of_get_property(node, "compatible", NULL); + int reg; + + dev_info(dev, "register_tty: child -- %pOF -- compatible %s\n", node, c); + + if (!c) + continue; +#ifdef OLD + if (strcmp(c, "gsmmux,port")) + continue; +#endif + if (of_property_read_u32(node, "reg", ®)) { + printk("no reg property\n"); + continue; + } + + if (reg != line) + continue; + + printk("n_gsm: line %d reg is %d, compatible %s\n", line, reg, c); + /* Hmm, gnss does not work now? */ + /* Should we pass the "master" serdev here? */ +#ifndef OLD + /* does not work, controller is "BUSY". We already have that in variable "dev" */ + dev2 = dev; +#else + devinfo.name = kasprintf(GFP_KERNEL, "gsm-mux-%d", idx++); + devinfo.parent = dev; + + /* Thanks to core.c: serdev_device_add */ + pdev = platform_device_register_full(&devinfo); + pdev->dev.of_node = node; + + dev2 = &pdev->dev; + printk("device name is %s / %s\n", dev2->init_name, dev2->kobj.name); +#endif + break; + } + + printk("n_gsm: Registering device at line %d, device is %p\n", line, dev2); + ndev = tty_port_register_device_serdev(&gsd->gsm->dlci[line]->port, + gsm_tty_driver, base + ops->line, dev2);
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml
Quoted 10 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +10
-0+ if (dev2) + printk("device name is now %s / %s\n", dev2->init_name, dev2->kobj.name); + + printk("register_tty_port: got %p\n", ndev); + return 0; +error: + kfree(ops); + return error; +} +EXPORT_SYMBOL_GPL(gsm_serdev_register_tty_port);
Johan
Hi!
Quoted 4 lines
Quoted 2 lines
Could I get some comments on the gnss patch? It is fairly simple, and I believe it is ready for merge.
Let's get the mux driver in shape first.
Well, gnss driver is now completely independent of that in the new versions.
Quoted 9 lines
Quoted 5 lines
Here's new version of the serdev multiplexing patch for reference. And yes, I'd like you to review the design here, too. Yes,
gsm_serdev_register_tty_port()needs to be cleaned up, but with ifdefs you can see alternative approach I tried to work around "controller busy" problem.As I said before, if you're trying to work around the one client-per-port assumption of serdev, you're doing it wrong. You still have one client per *virtual* port.
Yes, I have one client per virtual port. But those virtual ports need their parents.
We can have
serial@ -- motorola,mapphone-mdm6600-serial
(serdev here)
modem -- ts27010-mux
(here is the problem!)
serial@4 -- serial@1 -- (serdev here) (serdev here) gnss -- motorola,mapphone-mdm6600-gnss modem voice -- something
and I believe we agree on that. But serial@1 and serial@4 still need some kind of parent, and that's where I'm getting the controller busy problem.
Quoted 7 lines
Documentation/devicetree/bindings/serdev/serdev-ngsm.yaml line 20
Quoted 5 lines
+++
b/Documentation/devicetree/bindings/serdev/serdev-ngsm.yamlDocumentation/devicetree/bindings/serdev/serdev-ngsm.yaml new file +3
-0+ ttymask: + $ref: /schemas/types.yaml#/definitions/uint64 + description: Mask of the TS 27.010 channel TTY interfaces to start (64 bit)How is this intended to be used? Looks too Linux-specific for a binding.
The mask says which virtual ports contain "something". We have kernel clients for some, and we want to expose the rest of the used ones to the userspace.
Quoted 2 lines
So is this is probably the issue: you're skipping one level of the topology and do not describe the virtual ports.
Well, docs need to be updated.
Quoted 4 lines
You should probably just replace the ttymask property with explicit nodes for the virtual ports to enable. With no client devices described in devicetree, these will then show up as regular tty devices under Linux.
Yes, that can be done.
Quoted 3 lines
If you add a compatible property for the virtual ports (e.g. "ts27010-port") you might be able to just use
of_platform_populate()instead of walking the child nodes ingsm_serdev_register_tty_port().
I have "gsmmux,port" for that. And yes, I can take a look at of_platform_populate.
But as I explained above, there's still problem with the parent devices.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek