Re: device registration callback for usb-serial

2017-08-12 Thread Okash Khawaja
On Fri, Aug 11, 2017 at 11:47:35PM +0200, Samuel Thibault wrote:
> Okash Khawaja, on ven. 11 ao??t 2017 22:38:14 +0100, wrote:
> > On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> > > Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > > > You cannot make assumptions about driver load. Your driver was loaded.
> > > > End of story. Register it with the proper subsystem.
> > > 
> > > The subsystem in question is a line discipline. Registering a line
> > > discipline will not trigger applying it to the serial port, so it's not
> > > enough.
> > > 
> > > Samuel
> > 
> > Okay, it looks like port_probe callback inside usb_serial_driver does
> > this. It gets passed in usb_serial_port which is enough.
> 
> Mmm, but that is called before tty_register_device, is that not a
> problem?
Ah yes. Okay so that won't work.

May be what is needed is something similar to following. It is untested
and intended only to illustrate what is required.

Thanks,
Okash


--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -69,6 +69,9 @@ static int usb_serial_device_probe(struc
goto err_port_remove;
}

+   if (driver->tty_registered)
+   driver->tty_registered(port);
+
usb_autopm_put_interface(port->serial->interface);

dev_info(>serial->dev->dev,
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -225,6 +225,9 @@ struct usb_serial_endpoints {
  * called when the device is unplugged or unbound from the driver.
  * @release: pointer to the driver's release function.  This will be called
  * when the usb_serial data structure is about to be destroyed.
+ * @tty_registered: pointer to the driver's tty_registered callback.
+ * This will be called when the usb serial port has been successfully
+ * registered as a tty device.
  * @usb_driver: pointer to the struct usb_driver that controls this
  * device.  This is necessary to allow dynamic ids to be added to
  * the driver from sysfs.
@@ -268,6 +271,7 @@ struct usb_serial_driver {
void (*release)(struct usb_serial *serial);

int (*port_probe)(struct usb_serial_port *port);
+   void (*tty_registered)(struct usb_serial_port *port);
int (*port_remove)(struct usb_serial_port *port);

int (*suspend)(struct usb_serial *serial, pm_message_t message);
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-11 Thread Samuel Thibault
Okash Khawaja, on ven. 11 août 2017 22:38:14 +0100, wrote:
> On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> > Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > > You cannot make assumptions about driver load. Your driver was loaded.
> > > End of story. Register it with the proper subsystem.
> > 
> > The subsystem in question is a line discipline. Registering a line
> > discipline will not trigger applying it to the serial port, so it's not
> > enough.
> > 
> > Samuel
> 
> Okay, it looks like port_probe callback inside usb_serial_driver does
> this. It gets passed in usb_serial_port which is enough.

Mmm, but that is called before tty_register_device, is that not a
problem?

Samuel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-11 Thread Okash Khawaja
On Thu, Aug 10, 2017 at 10:27:31AM +0200, Samuel Thibault wrote:
> Oliver Neukum, on jeu. 10 ao??t 2017 10:03:51 +0200, wrote:
> > You cannot make assumptions about driver load. Your driver was loaded.
> > End of story. Register it with the proper subsystem.
> 
> The subsystem in question is a line discipline. Registering a line
> discipline will not trigger applying it to the serial port, so it's not
> enough.
> 
> Samuel

Okay, it looks like port_probe callback inside usb_serial_driver does
this. It gets passed in usb_serial_port which is enough.

Thanks,
Okash
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-10 Thread Samuel Thibault
Oliver Neukum, on jeu. 10 août 2017 10:03:51 +0200, wrote:
> You cannot make assumptions about driver load. Your driver was loaded.
> End of story. Register it with the proper subsystem.

The subsystem in question is a line discipline. Registering a line
discipline will not trigger applying it to the serial port, so it's not
enough.

Samuel
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: device registration callback for usb-serial

2017-08-10 Thread Oliver Neukum
Am Donnerstag, den 10.08.2017, 07:56 +0100 schrieb Okash Khawaja:
> Hi,
> 
> struct usb_serial_device has probe and attach callbacks. After attach
> is invoked, device minor numbers are allocated and then registered with
> driver core. So attach callback doesn't know minor number.
> 
> Can a usb-serial driver know about device minor number as soon as it is
> registered with driver core?

Merely registering a driver does not allocate a minor. And is the order
of device enumeration is unknown at that time, it cannot know a minor
number.

You cannot make assumptions about driver load. Your driver was loaded.
End of story. Register it with the proper subsystem.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


device registration callback for usb-serial

2017-08-10 Thread Okash Khawaja
Hi,

struct usb_serial_device has probe and attach callbacks. After attach
is invoked, device minor numbers are allocated and then registered with
driver core. So attach callback doesn't know minor number.

Can a usb-serial driver know about device minor number as soon as it is
registered with driver core?

This is what I'm trying to do. As soon as user plugs in usb-serial
device with particular vendor id and product id, my usb-serial driver
is loaded which then gets notified of minor device number when the
device is registered. At that time, this usb-serial driver will pass
that information to another kernel module (speakup) which knows
everything else needed to deal with that device.

The end goal is to automatically load speakup with correct params, i.e.
major and minor device numbers, as soon as a supported usb device is
plugged in. We want to do this all inside kernel and without having
the user to set up things in user space.

Also, apart from above method, if there is some other way to achieve
this then please suggest.

Thanks,
Okash
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html