n_gsm serdev support and mfd driver for droid4 modem
v3 cover n_gsm serdev support and mfd driver for droid4 modem
Hi all,
Here's v3 set of n_gsm serdev support patches, and the related MFD driver for the modem found on Motorola Mapphone phones and tablets like droid4.
This series only adds basic character device support for the MFD driver. Other serdev consumer drivers for specific devices will be posted separately.
The patches are against v5.6-rc1.
Regards,
Tony
Changes since v2:
- Drop useless send_command indirection, use static motmdm_send_command
Changes since v1:
- Simplified usage and got rid of few pointless inline functions
- Added consumer MFD driver, devicetree binding, and dts changes
Tony Lindgren (4):
tty: n_gsm: Add support for serdev drivers
mfd: motmdm: Add Motorola TS 27.010 serdev modem driver for droid4
dt-bindings: mfd: motmdm: Add binding for motorola-mdm
ARM: dts: omap4-droid4: Enable basic modem support
.../mfd/motorola,mapphone-mdm6600.yaml | 37 + .../boot/dts/motorola-mapphone-common.dtsi | 6 + drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 1 + drivers/mfd/motorola-mdm.c | 1198 +++++++++++++++++ drivers/tty/n_gsm.c | 372 +++++ include/linux/serdev-gsm.h | 168 +++ 7 files changed, 1791 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/motorola,mapphone-mdm6600.yaml create mode 100644 drivers/mfd/motorola-mdm.c create mode 100644 include/linux/serdev-gsm.h
Signature · 1 line
2.25.1
PATCH v3 1/4 tty: n_gsm: Add support for serdev drivers
We can make use of serdev drivers to do simple device drivers for TS 27.010 chanels, and we can handle vendor specific protocols on top of TS 27.010 with serdev drivers.
So far this has been tested with Motorola droid4 where there is a custom packet numbering protocol on top of TS 27.010 for the MDM6600 modem.
I initially though about adding the serdev support into a separate file, but that will take some refactoring of n_gsm.c. And I'd like to have things working first. Then later on we might want to consider splitting n_gsm.c into three pieces for core, tty and serdev parts.
--- drivers/tty/n_gsm.c | 372 +++++++++++++++++++++++++++++++++++++ include/linux/serdev-gsm.h | 168 +++++++++++++++++ 2 files changed, 540 insertions(+) create mode 100644 include/linux/serdev-gsm.h
drivers/tty/n_gsm.c +372 -0
@@ -39,6 +39,7 @@#include <linux/file.h> #include <linux/uaccess.h> #include <linux/module.h> +#include <linux/serdev.h> #include <linux/timer.h> #include <linux/tty_flip.h> #include <linux/tty_driver.h>
@@ -50,6 +51,7 @@#include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/gsmmux.h> +#include <linux/serdev-gsm.h> static int debug;module_param (debug, int,0600 );
@@ -145,6 +147,7 @@ struct gsm_dlci {/* Data handling callback */ void (*data)(struct gsm_dlci *dlci,const u8 *data,int len);void (*prev_data)(struct gsm_dlci *dlci,const u8 *data,int len); +struct gsm_serdev_dlci *ops;/* serdev dlci ops, if used */ struct net_device *net;/* network interface, if created */ };
@@ -179,6 +182,7 @@ struct gsm_control {*/ struct gsm_mux { +struct gsm_serdev *gsd;/* Serial device bus data */ struct tty_struct *tty;/* The tty our ldisc is bound to */ spinlock_t lock;struct mutex mutex;
@@ -2326,6 +2330,374 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)return 0 ; } +#ifdef CONFIG_SERIAL_DEV_BUS + +/** +* gsm_serdev_get_config - read ts 27.010 config +* @gsd: serdev-gsm instance +* @c: ts 27.010 config data +* +* See gsm_copy_config_values() for more information. +*/ +int gsm_serdev_get_config (struct gsm_serdev *gsd,struct gsm_config *c) +{ +struct gsm_mux *gsm; + +if (!gsd || !gsd->gsm) +return -ENODEV ; + + gsm = gsd->gsm; + +if (!c) +return -EINVAL ; + +gsm_copy_config_values (gsm, c); + +return 0 ; +} +EXPORT_SYMBOL_GPL (gsm_serdev_get_config); + +/** +* gsm_serdev_set_config - set ts 27.010 config +* @gsd: serdev-gsm instance +* @c: ts 27.010 config data +* +* See gsm_config() for more information. +*/ +int gsm_serdev_set_config (struct gsm_serdev *gsd,struct gsm_config *c) +{ +struct gsm_mux *gsm; + +if (!gsd || !gsd->serdev || !gsd->gsm) +return -ENODEV ; + + gsm = gsd->gsm; + +if (!c) +return -EINVAL ; + +return gsm_config (gsm, c); +} +EXPORT_SYMBOL_GPL (gsm_serdev_set_config); + +static struct gsm_dlci *gsd_dlci_get (struct gsm_serdev *gsd,int line, +bool allocate) +{ +struct gsm_mux *gsm; +struct gsm_dlci *dlci; + +if (!gsd || !gsd->gsm) +return ERR_PTR (-ENODEV ); + + gsm = gsd->gsm; + +if (line <1 || line >=63 ) +return ERR_PTR (-EINVAL ); + +mutex_lock (&gsm->mutex); + +if (gsm->dlci[line]) { + dlci = gsm->dlci[line]; + goto unlock; + }else if (!allocate) { + dlci =ERR_PTR (-ENODEV ); + goto unlock; + } + + dlci =gsm_dlci_alloc (gsm, line); +if (!dlci) { + gsm =ERR_PTR (-ENOMEM ); + goto unlock; + } + + gsm->dlci[line] = dlci; + +unlock: +mutex_unlock (&gsm->mutex); + +return dlci; +} + +static void gsd_dlci_data (struct gsm_dlci *dlci,const u8 *buf,int len) +{ +struct gsm_mux *gsm = dlci->gsm; +struct gsm_serdev *gsd = gsm->gsd; + +if (!gsd || !dlci->ops) +return ; + +switch (dlci->adaption) { +case 0 : +case 1 : +if (dlci->ops->receive_buf) + dlci->ops->receive_buf (dlci->ops, buf, len); +break ; +default : +pr_warn ("dlci%i adaption %i not yet implemented\n" , + dlci->addr, dlci->adaption); +break ; + } +} + +/** +* gsm_serdev_write - write data to a ts 27.010 channel +* @gsd: serdev-gsm instance +* @ops: channel ops +* @buf: write buffer +* @len: buffer length +*/ +int gsm_serdev_write (struct gsm_serdev *gsd,struct gsm_serdev_dlci *ops, +const u8 *buf,int len) +{ +struct gsm_mux *gsm; +struct gsm_dlci *dlci; +struct gsm_msg *msg; +int h, size, total_size =0 ; +u8 *dp; + +if (!gsd || !gsd->gsm) +return -ENODEV ; + + gsm = gsd->gsm; + + dlci =gsd_dlci_get (gsd, ops->line, false); +if (IS_ERR (dlci)) +return PTR_ERR (dlci); + + h = dlci->adaption -1 ; + +if (len > gsm->mtu) + len = gsm->mtu; + + size = len + h; + + msg =gsm_data_alloc (gsm, dlci->addr, size, gsm->ftype); +if (!msg) +return -ENOMEM ; + + dp = msg->data; +switch (dlci->adaption) { +case 1 : +break ; +case 2 : + *dp++ =gsm_encode_modem (dlci); +break ; + } +memcpy (dp, buf, len); +gsm_data_queue (dlci, msg); + total_size += size; + +return total_size; +} +EXPORT_SYMBOL_GPL (gsm_serdev_write); + +/** +* gsm_serdev_data_kick - indicate more data can be transmitted +* @gsd: serdev-gsm instance +* +* See gsm_data_kick() for more information. +*/ +void gsm_serdev_data_kick (struct gsm_serdev *gsd) +{ +struct gsm_mux *gsm; +unsigned long flags; + +if (!gsd || !gsd->gsm) +return ; + + gsm = gsd->gsm; + +spin_lock_irqsave (&gsm->tx_lock, flags); +gsm_data_kick (gsm); +spin_unlock_irqrestore (&gsm->tx_lock, flags); +} +EXPORT_SYMBOL_GPL (gsm_serdev_data_kick); + +/** +* gsm_serdev_register_dlci - register a ts 27.010 channel +* @gsd: serdev-gsm instance +* @ops: channel ops +*/ +int gsm_serdev_register_dlci (struct gsm_serdev *gsd, +struct gsm_serdev_dlci *ops) +{ +struct gsm_dlci *dlci; +struct gsm_mux *gsm; +int retries; + +if (!gsd || !gsd->gsm || !gsd->serdev) +return -ENODEV ; + + gsm = gsd->gsm; + +if (!ops || !ops->line || !ops->receive_buf) +return -EINVAL ; + + dlci =gsd_dlci_get (gsd, ops->line, true); +if (IS_ERR (dlci)) +return PTR_ERR (dlci); + +if (dlci->state ==DLCI_OPENING || dlci->state ==DLCI_OPEN || + dlci->state ==DLCI_CLOSING ) +return -EBUSY ; + +mutex_lock (&dlci->mutex); + dlci->ops = ops; + dlci->modem_rx =0 ; + dlci->prev_data = dlci->data; + dlci->data = gsd_dlci_data; +mutex_unlock (&dlci->mutex); + +gsm_dlci_begin_open (dlci); + +/* +* Allow some time for dlci to move to DLCI_OPEN state. Otherwise +* the serdev consumer driver can start sending data too early during +* the setup, and the response will be missed by gms_queue() if we +* still have DLCI_CLOSED state. +*/ +for (retries =10 ; retries >0 ; retries--) { +if (dlci->state ==DLCI_OPEN ) +break ; +msleep (100 ); + } + +if (!retries) +dev_dbg (&gsd->serdev->dev,"dlci%i not currently active\n" , + dlci->addr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (gsm_serdev_register_dlci); + +/** +* gsm_serdev_unregister_dlci - unregister a ts 27.010 channel +* @gsd: serdev-gsm instance +* @ops: channel ops +*/ +void gsm_serdev_unregister_dlci (struct gsm_serdev *gsd, +struct gsm_serdev_dlci *ops) +{ +struct gsm_mux *gsm; +struct gsm_dlci *dlci; + +if (!gsd || !gsd->gsm || !gsd->serdev) +return ; + + gsm = gsd->gsm; + +if (!ops || !ops->line) +return ; + + dlci =gsd_dlci_get (gsd, ops->line, false); +if (IS_ERR (dlci)) +return ; + +mutex_lock (&dlci->mutex); +gsm_destroy_network (dlci); + dlci->data = dlci->prev_data; + dlci->ops =NULL ; +mutex_unlock (&dlci->mutex); + +gsm_dlci_begin_close (dlci); +} +EXPORT_SYMBOL_GPL (gsm_serdev_unregister_dlci); + +static int gsm_serdev_output (struct gsm_mux *gsm,u8 *data,int len) +{ +struct gsm_serdev *gsd = gsm->gsd; +struct serdev_device *serdev = gsm->gsd->serdev; +bool asleep; + + asleep =atomic_read (&gsd->asleep); +if (asleep) +return -ENOSPC ; + +if (gsm->gsd->output) +return gsm->gsd->output (gsm->gsd, data, len); +else +return serdev_device_write_buf (serdev, data, len); +} + +static int gsd_receive_buf (struct serdev_device *serdev,const u8 *data, +size_t count) +{ +struct gsm_serdev *gsd =serdev_device_get_drvdata (serdev); +struct gsm_mux *gsm; +const unsigned char *dp; +int i; + +if (WARN_ON (!gsd)) +return 0 ; + + gsm = gsd->gsm; + +if (debug &4 ) +print_hex_dump_bytes ("gsd_receive_buf: " , +DUMP_PREFIX_OFFSET , + data, count); + +for (i = count, dp = data; i; i--, dp++) + gsm->receive (gsm, *dp); + +return count; +} + +static void gsd_write_wakeup (struct serdev_device *serdev) +{ +serdev_device_write_wakeup (serdev); +} + +static struct serdev_device_ops gsd_client_ops = { + .receive_buf = gsd_receive_buf, + .write_wakeup = gsd_write_wakeup, +}; + +int gsm_serdev_register_device (struct gsm_serdev *gsd) +{ +struct gsm_mux *gsm; +int error; + +if (WARN (!gsd || !gsd->serdev || !gsd->output, +"serdev and output must be initialized\n" )) +return -EINVAL ; + +serdev_device_set_client_ops (gsd->serdev, &gsd_client_ops); + + gsm =gsm_alloc_mux (); +if (!gsm) +return -ENOMEM ; + + gsm->encoding =1 ; + gsm->tty =NULL ; + gsm->gsd = gsd; + gsm->output = gsm_serdev_output; +atomic_set (&gsd->asleep,0 ); + gsd->gsm = gsm; +mux_get (gsd->gsm); + + error =gsm_activate_mux (gsd->gsm); +if (error) { +gsm_cleanup_mux (gsd->gsm); +mux_put (gsd->gsm); + +return error; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (gsm_serdev_register_device); + +void gsm_serdev_unregister_device (struct gsm_serdev *gsd) +{ +gsm_cleanup_mux (gsd->gsm); +mux_put (gsd->gsm); + gsd->gsm =NULL ; +} +EXPORT_SYMBOL_GPL (gsm_serdev_unregister_device); + +#endif /* CONFIG_SERIAL_DEV_BUS */ +/** * gsmld_output - write to link * @gsm: our mux
include/linux/serdev-gsm.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 3/4 dt-bindings: mfd: motmdm: Add binding for motorola-mdm
In reply to Tony LindgrenAdd a binding document for Motorola modems controllable by TS 27.010 UART line discipline using serdev drivers.
--- .../mfd/motorola,mapphone-mdm6600.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/motorola,mapphone-mdm6600.yaml
Documentation/devicetree/bindings/mfd/motorola,mapphone-mdm6600.yaml new file +37 -0
@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/motorola,mapphone-mdm6600.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Motorola Mapphone MDM6600 Modem + +maintainers: + - Tony Lindgren <[email protected]> + +allOf: + - $ref: "motorola,mapphone-mdm6600.yaml#" + +properties: + compatible: + items: + - const: motorola,mapphone-mdm6600-serial + + phys: + maxItems: 1 + + phy-names: + const: usb + +required: + - compatible + - phys + - phy-names + +examples: + - | + modem { + compatible = "motorola,mapphone-mdm6600-serial"; + phys = <&fsusb1_phy>; + phy-names = "usb"; + };
Signature · 1 line
2.25.1
PATCH v3 2/4 mfd: motmdm: Add Motorola TS 27.010 serdev modem driver for droid4
In reply to Tony LindgrenMany Motorola phones are controlling the modem using a custom variant of TS 27.010 serial line discipline. Devices on these modems have a dedicated TS 27.010 channel for features like audio mixer, GNSS, voice modem, SIM card reader and so on.
This driver allows using various devices on the modem. In order to do that, we need to take care of the following three things:
1. Provide /dev/motmdm* character devices for apps to use for talking to the various devices on the modem
2. Handle Motorola custom protocol over TS 27.010 to make the channels usable for userspace
3. Coordinate PM runtime with the USB PHY because of shared GPIO pins with the USB PHY
With this patch, folks with droid4 can place a voice call with just:
$ printf "ATD%s,0\r" "${phone_number}" > /dev/motmdm1
D:OK
~+CIEV=1,1,0
...
$ printf "ATH\r" > /dev/motmdm1
H:OKAlso SMS can be sent with this patch using /dev/motmdm3 for sending, and /dev/motmdm9 for receiving messages.
Note that the audio mixer needs additional patches though. I will be sending those as a separate series of patches.
--- drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 1 + drivers/mfd/motorola-mdm.c | 1198 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1208 insertions(+) create mode 100644 drivers/mfd/motorola-mdm.c
drivers/mfd/Kconfig +9 -0
@@ -2025,6 +2025,15 @@ config MFD_VEXPRESS_SYSREG System Registers are the platform configuration block on the ARM Ltd. Versatile Express board. +config MFD_MOTMDM + tristate "Motorola Modem TS 27.010 Serdev Driver" + depends on N_GSM && SERIAL_DEV_BUS && PHY_MAPPHONE_MDM6600 + select MFD_CORE + help + Select this for Motorola modems using TS 27.010 serial line + discipline such as MDM6600 modem found on Motorola Mapphone + series of devices such as Droid 4. + config RAVE_SP_CORE tristate "RAVE SP MCU core driver" depends on SERIAL_DEV_BUS
drivers/mfd/Makefile +1 -0
@@ -251,6 +251,7 @@ obj-$(CONFIG_MFD_STM32_LPTIMER) += stm32-lptimer.o obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o obj-$(CONFIG_MFD_MXS_LRADC) += mxs-lradc.o obj-$(CONFIG_MFD_SC27XX_PMIC) += sprd-sc27xx-spi.o +obj-$(CONFIG_MFD_MOTMDM) += motorola-mdm.o obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o obj-$(CONFIG_MFD_ROHM_BD70528) += rohm-bd70528.o obj-$(CONFIG_MFD_ROHM_BD71828) += rohm-bd71828.o
drivers/mfd/motorola-mdm.c new file +1198 -0
1,198 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 4/4 ARM: dts: omap4-droid4: Enable basic modem support
In reply to Tony LindgrenThis allows apps to use /dev/motmdm1 for voice call AT commands, /dev/motmdm3 for sending SMS, and /dev/motmdm9 for reading SMS.
Voice call audio mixer and GNSS are not yet supported.
--- arch/arm/boot/dts/motorola-mapphone-common.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/boot/dts/motorola-mapphone-common.dtsi +6 -0
@@ -689,6 +689,12 @@ &uart1 { pinctrl-0 = <&uart1_pins>; interrupts-extended = <&wakeupgen GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH &omap4_pmx_core 0xfc>; + + modem { + compatible = "motorola,mapphone-mdm6600-serial"; + phys = <&fsusb1_phy>; + phy-names = "usb"; + }; }; &uart3 {
Signature · 1 line
2.25.1
Re: [PATCH 3/4] dt-bindings: mfd: motmdm: Add binding for motorola-mdm
In reply to Tony LindgrenQuoted 2 lines · Tony Lindgren
Add a binding document for Motorola modems controllable by TS 27.010 UART line discipline using serdev drivers.
FYI, this patch needs updating for the license and to drop the pointless "allOf" from the binding based on Rob's comments from yesterday for v2 of this series.
Regards,
Tony
Re: [PATCH 2/4] mfd: motmdm: Add Motorola TS 27.010 serdev modem driver for droid4
In reply to Tony LindgrenQuoted 25 lines · Tony Lindgren
drivers/mfd/motorola-mdm.c new file +25
-0+static int motmdm_register_dlci (struct device *dev, +struct motmdm_dlci *mot_dlci) +{ +struct motmdm *ddata; +struct gsm_serdev *gsd; +struct gsm_serdev_dlci *gsm_dlci; +int err; + +if (!dev || !mot_dlci || !mot_dlci->line) +return -EINVAL ; + + err =pm_runtime_get_sync (dev); +if ((err != -EINPROGRESS ) && err <0 ) { +pm_runtime_put_noidle (dev); + +return err; + } + + ddata =gsm_serdev_get_drvdata (dev); + gsd = &ddata->gsd; + gsm_dlci = &mot_dlci->gsm_dlci; +INIT_LIST_HEAD (&mot_dlci->list); +init_waitqueue_head (&mot_dlci->read_queue); + gsm_dlci->line = mot_dlci->line; + gsm_dlci->receive_buf = motmdm_dlci_receive_buf;
drivers/mfd/motorola-mdm.c line 514
Quoted 10 lines
drivers/mfd/motorola-mdm.c new file +10
-0+ + err =gsm_serdev_register_dlci (gsd, gsm_dlci); +if (err) { +dev_warn (dev,"error registering dlci%i: %i\n" , + mot_dlci->line, err); +kfifo_free (&mot_dlci->read_fifo); +memset (gsm_dlci,0 ,sizeof (*gsm_dlci)); + }else { + mot_dlci->privdata = ddata; + }
Here we want mot_dlci->privdata initialized before gsm_serdev_register_dlci, otherwise we may get an interrupt between gsm_serdev_register_dlci and setting mot_dlci->privdata.
So I'll be sending out v4 series.
Regards,
Tony