Re: modeling hotplug usb host controller driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 7 Dec 2010, Richard Retanubun wrote:

> Here is the more detailed question:
> 
> - My linux baseline is 2.6.32-5
> 
> - I've ported the isp1763-hcd driver from isp1760-hcd driver
>    (and trying to mainline a unified one on a separate thread of work).
> 
> - The platform I am working on (MPC8360E CPU) will have isp1763 chips on both the main board
>    and some hotswap modules.
> 
> - For the mainboard one, things are simple, declare stuff in dtb and up it goes.
> 
> - For the hcd on the hostswap modules, some help from external program is needed to
>    realize a new module is plugged in and trigger calling usb_create_hcd and usb_add_hcd
>    for the driver (using generic netlink), modprobe with arguments may also work, but
>    generic netlink feels like a more structured approach.

Once the kernel knows a new module has been plugged in, the module's 
driver should be responsible for registering all the devices contained 
in the module.

> - I am mostly wondering about the use of struct device *dev; In the examples I have looked at
>    most of these comes wrapped as a member of a larger struct (struct of_device, struct pci_dev,
>    struct usb_dev, struct platform_device) I don't know if it is legal to do something like this:

It is legal but it is rarely useful.

> static int isp1763_genl_lmb_dev_add(struct sk_buff *skbuff, struct genl_info *info)
> {
> 	struct device dev; /* local device structure, initialize somehow */
> 	struct usb_hcd *hcd;
> 
> 	/* Get mem resource and irq resource from genl_info fill it into hcd struct members */
> 	
> 	hcd = usb_create_hcd(&isp1763_hc_driver, &dev, dev_name(&dev));
>          -----------------------------------------^^^^^^^^^^^^^^^^^^^^
>          /* Is passing a local (non-wrapped) device stucture here legal? is it a good practice?
>           * or is it better to use a static platform_device per driver instance?
>           */
> }

This is definitely wrong, for several reasons.  For one thing, the hcd
structure will contain a pointer to the struct device on the stack.  
When this function returns, it will immediately become a stale pointer.

> I can also create a local platform_device structure in the function above (or is it better that this be a static filescope structure?)
> and use the struct device *dev that is included inside the struct platform_device but that feels awkward, and yet I haven't found another
> way to cleanly remove the device later like this:
> 
> /* static filescope platform_device, filled in during isp1763_genl_lmb_dev_add */
> static struct platform_device pdev;
> 
> static int isp1763_genl_lmb_dev_remove(struct sk_buff *skbuff, struct genl_info *info)
> {
> 	/* Get mem resource and irq resource from genl_info fill it into hcd struct members */
> 
> 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
> 
> 	usb_remove_hcd(hcd);
> 	/* Free memory and irq resources */
> 	usb_put_hcd(hcd);
> 	return 0;
> }
> 
> The only driver I've found that does something similar (having a static struct platform_device) is /usb/host/sl811_cs.c
> but I am not sure if there are some special pcmcia concepts I am missing,

What does pcmcia have to do with any of this?

> for example it calls platform_device_register and platform_device_unregister.
> 
> Any comments is much appreciated.

Look at drivers/usb/gadget/dummy_hcd.c for an example much like what 
you are doing.

Alan Stern

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


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux