usb-musb: make qdev-aware
cover usb-musb: make qdev-aware
This patchset has some minor cleanups to usb-musb that we can make now that the only user (tusb6010) is a qdev device.
I've thrown in a minor piece of renaming to avoid a C-standard reserved namespace.
These patches depend only on the just-committed bdc76462a so they should be fine to go in through the usb queue.
Juha Riihimäki (1):
usb-musb: Add reset function
Peter Maydell (2):
usb: Remove leading underscores from __musb_irq_max
usb-musb: Take a DeviceState* in init function
hw/tusb6010.c | 11 +++-------- hw/usb-musb.c | 26 ++++++++++++++++++++------ hw/usb.h | 6 ++++-- 3 files changed, 27 insertions(+), 16 deletions(-)
PATCH 1/3 usb: Remove leading underscores from __musb_irq_max
Identifiers with double leading underscore are reserved, so rename __musb_irq_max so we don't encroach on reserved namespace.
--- hw/tusb6010.c | 6 +++--- hw/usb.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
hw/tusb6010.c +3 -3
@@ -785,9 +785,9 @@ static int tusb6010_init(SysBusDevice *dev)sysbus_init_mmio_region (dev, &s->iomem[0 ]);sysbus_init_mmio_region (dev, &s->iomem[1 ]);sysbus_init_irq (dev, &s->irq); -qdev_init_gpio_in (&dev->qdev, tusb6010_irq, __musb_irq_max +1 ); - musb_irqs =g_new0 (qemu_irq, __musb_irq_max); -for (i =0 ; i < __musb_irq_max; i++) { +qdev_init_gpio_in (&dev->qdev, tusb6010_irq, musb_irq_max +1 ); + musb_irqs =g_new0 (qemu_irq, musb_irq_max); +for (i =0 ; i < musb_irq_max; i++) { musb_irqs[i] =qdev_get_gpio_in (&dev->qdev, i +1 ); } s->musb =musb_init (musb_irqs);
hw/usb.h +2 -1
@@ -337,7 +337,8 @@ enum musb_irq_source_e { musb_irq_tx, musb_set_vbus, musb_set_session, - __musb_irq_max, +/* Add new interrupts here */ + musb_irq_max, /* total number of interrupts defined */ };typedef struct MUSBState MUSBState ;
Signature · 1 line
1.7.1
PATCH 2/3 usb-musb: Take a DeviceState* in init function
In reply to Peter MaydellInitialise usb-musb by passing it a DeviceState* and the offset of the IRQs in its gpio array, rather than a plain pointer to an irq array. This is simpler for callers and also allows us to pass in a valid parent to usb_bus_new(), so the USB bus actually appears in the qdev tree.
--- hw/tusb6010.c | 8 +------- hw/usb-musb.c | 10 ++++++---- hw/usb.h | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-)
hw/tusb6010.c +1 -7
@@ -776,8 +776,6 @@ static void tusb6010_reset(DeviceState *dev)static int tusb6010_init (SysBusDevice *dev) {TUSBState *s =FROM_SYSBUS (TUSBState, dev); -qemu_irq *musb_irqs; -int i; s->otg_timer =qemu_new_timer_ns (vm_clock, tusb_otg_tick, s); s->pwr_timer =qemu_new_timer_ns (vm_clock, tusb_power_tick, s); memory_region_init_io(&s->iomem[1], &tusb_async_ops, s, "tusb-async",
@@ -786,11 +784,7 @@ static int tusb6010_init(SysBusDevice *dev)sysbus_init_mmio_region (dev, &s->iomem[1 ]);sysbus_init_irq (dev, &s->irq);qdev_init_gpio_in (&dev->qdev, tusb6010_irq, musb_irq_max +1 ); - musb_irqs =g_new0 (qemu_irq, musb_irq_max); -for (i =0 ; i < musb_irq_max; i++) { - musb_irqs[i] =qdev_get_gpio_in (&dev->qdev, i +1 ); - } - s->musb =musb_init (musb_irqs); + s->musb =musb_init (&dev->qdev,1 );return 0 ; }
hw/usb-musb.c +6 -4
@@ -314,7 +314,7 @@ struct MUSBEndPoint { };struct MUSBState { -qemu_irq *irqs; +qemu_irq irqs[musb_irq_max];USBBus bus;USBPort port;
@@ -340,12 +340,14 @@ struct MUSBState {MUSBEndPoint ep[16 ]; }; -struct MUSBState *musb_init (qemu_irq *irqs) +struct MUSBState *musb_init (DeviceState *parent_device,int gpio_base) {MUSBState *s =g_malloc0 (sizeof (*s));int i; - s->irqs = irqs; +for (i =0 ; i < musb_irq_max; i++) { + s->irqs[i] =qdev_get_gpio_in (parent_device, gpio_base + i); + } s->faddr =0x00 ; s->power =MGC_M_POWER_HSENAB ;
@@ -369,7 +371,7 @@ struct MUSBState *musb_init(qemu_irq *irqs)usb_packet_init (&s->ep[i].packey[1 ].p); } -usb_bus_new (&s->bus, &musb_bus_ops,NULL /* FIXME */ ); +usb_bus_new (&s->bus, &musb_bus_ops, parent_device);usb_register_port (&s->bus, &s->port, s,0 , &musb_port_ops,USB_SPEED_MASK_LOW |USB_SPEED_MASK_FULL );
hw/usb.h +1 -1
@@ -342,7 +342,7 @@ enum musb_irq_source_e { };typedef struct MUSBState MUSBState ; -MUSBState *musb_init (qemu_irq *irqs); +MUSBState *musb_init (DeviceState *parent_device,int gpio_base);uint32_t musb_core_intr_get (MUSBState *s);void musb_core_intr_clear (MUSBState *s,uint32_t mask);void musb_set_size (MUSBState *s,int epnum,int size,int is_tx);
Signature · 1 line
1.7.1
PATCH 3/3 usb-musb: Add reset function
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Add a separate reset function musb_reset() to the usb-musb interface, so that users who implement a reset function can also reset usb-musb. Use this in tusb6010.
--- hw/tusb6010.c | 1 + hw/usb-musb.c | 24 ++++++++++++++++++------ hw/usb.h | 1 + 3 files changed, 20 insertions(+), 6 deletions(-)
hw/tusb6010.c +1 -0
@@ -771,6 +771,7 @@ static void tusb6010_reset(DeviceState *dev)for (i =0 ; i <15 ; i++) { s->rx_config[i] = s->tx_config[i] =0 ; } +musb_reset (s->musb); }static int tusb6010_init (SysBusDevice *dev)
hw/usb-musb.c +18 -6
@@ -340,16 +340,12 @@ struct MUSBState {MUSBEndPoint ep[16 ]; }; -struct MUSBState *musb_init (DeviceState *parent_device,int gpio_base) +void musb_reset (MUSBState *s) { -MUSBState *s =g_malloc0 (sizeof (*s));int i; -for (i =0 ; i < musb_irq_max; i++) { - s->irqs[i] =qdev_get_gpio_in (parent_device, gpio_base + i); - } - s->faddr =0x00 ; + s->devctl =0 ; s->power =MGC_M_POWER_HSENAB ; s->tx_intr =0x0000 ; s->rx_intr =0x0000 ;
@@ -359,6 +355,10 @@ struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base) s->mask =0x06 ; s->idx =0 ; + s->setup_len =0 ; + s->session =0 ; +memset (s->buf,0 ,sizeof (s->buf)); +/* TODO: _DW */ s->ep[0 ].config =MGC_M_CONFIGDATA_SOFTCONE |MGC_M_CONFIGDATA_DYNFIFO ;for (i =0 ; i <16 ; i ++) {
@@ -370,6 +370,18 @@ struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)usb_packet_init (&s->ep[i].packey[0 ].p);usb_packet_init (&s->ep[i].packey[1 ].p); } +} + +struct MUSBState *musb_init (DeviceState *parent_device,int gpio_base) +{ +MUSBState *s =g_malloc0 (sizeof (*s)); +int i; + +for (i =0 ; i < musb_irq_max; i++) { + s->irqs[i] =qdev_get_gpio_in (parent_device, gpio_base + i); + } + +musb_reset (s);usb_bus_new (&s->bus, &musb_bus_ops, parent_device); usb_register_port(&s->bus, &s->port, s, 0, &musb_port_ops,
hw/usb.h +1 -0
@@ -343,6 +343,7 @@ enum musb_irq_source_e {typedef struct MUSBState MUSBState ;MUSBState *musb_init (DeviceState *parent_device,int gpio_base); +void musb_reset (MUSBState *s);uint32_t musb_core_intr_get (MUSBState *s);void musb_core_intr_clear (MUSBState *s,uint32_t mask);void musb_set_size (MUSBState *s,int epnum,int size,int is_tx);
Signature · 1 line
1.7.1
Quoted 8 lines · Peter Maydell
This patchset has some minor cleanups to usb-musb that we can make now that the only user (tusb6010) is a qdev device.
I've thrown in a minor piece of renaming to avoid a C-standard reserved namespace.
These patches depend only on the just-committed
bdc76462aso they should be fine to go in through the usb queue.
Added to the queue, thanks.
How to you test musb?
cheers,
Gerd
Quoted 1 line · Gerd Hoffmann
How to you test musb?
Unfortunately I don't have any test cases which actively use the musb, so I settle for testing an n810 image (and a beagle image in my omap3 tree) and confirming that the init part of things still works ok. (I'm not entirely happy with this but init is really all we're changing with these patches so we should be ok...)
Riku/Juha -- do you have any musb test images/command lines?
-- PMM
Quoted 9 lines
Quoted 1 line
How to you test musb?
Unfortunately I don't have any test cases which actively use the musb, so I settle for testing an n810 image (and a beagle image in my omap3 tree) and confirming that the init part of things still works ok. (I'm not entirely happy with this but init is really all we're changing with these patches so we should be ok...)
Riku/Juha -- do you have any musb test images/command lines?
With an existing n810 image I guess you can test USB networking by adding "-usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir tcp:2022::22" to qemu command line parameters. In the guest, launch X terminal and command "sudo gainroot" followed by "udhcpc". You should now be able to ssh to the guest from the host with "ssh -p 2022 root@localhost". Would this be sufficient for your needs?
Cheers,
Juha
Quoted 8 lines · On 09/02/11 09:03, [email protected] wrote:
Quoted 8 lines
Quoted 1 line
How to you test musb?
Unfortunately I don't have any test cases which actively use the musb, so I settle for testing an n810 image (and a beagle image in my omap3 tree) and confirming that the init part of things still works ok. (I'm not entirely happy with this but init is really all we're changing with these patches so we should be ok...)
Quoted 8 lines
Quoted 1 line
Riku/Juha -- do you have any musb test images/command lines?
With an existing n810 image I guess you can test USB networking by adding "-usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir tcp:2022::22" to qemu command line parameters. In the guest, launch X terminal and command "sudo gainroot" followed by "udhcpc". You should now be able to ssh to the guest from the host with "ssh -p 2022 root@localhost". Would this be sufficient for your needs?
For starters just "qemu-system-arm -M n810" is better than nothing, this does at least make sure it doesn't blow up somewhere when creating the device tree.
Booting an image and operating some usb device is even better. Are n810 images are freely available for download somewhere? Failing that, is it possible to just install some linux distro (say debian) on the virtual n810 or another arm device which has a musb controller?
thanks,
Gerd
Quoted 18 lines · Gerd Hoffmann
Quoted 8 lines · On 09/02/11 09:03, [email protected] wrote:
Quoted 8 lines
Quoted 1 line
How to you test musb?
Unfortunately I don't have any test cases which actively use the musb, so I settle for testing an n810 image (and a beagle image in my omap3 tree) and confirming that the init part of things still works ok. (I'm not entirely happy with this but init is really all we're changing with these patches so we should be ok...)
Quoted 8 lines
Quoted 1 line
Riku/Juha -- do you have any musb test images/command lines?
With an existing n810 image I guess you can test USB networking by adding "-usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir tcp:2022::22" to qemu command line parameters. In the guest, launch X terminal and command "sudo gainroot" followed by "udhcpc". You should now be able to ssh to the guest from the host with "ssh -p 2022 root@localhost". Would this be sufficient for your needs?
Quoted 8 lines
For starters just "qemu-system-arm -M n810" is better than nothing, this does at least make sure it doesn't blow up somewhere when creating the device tree.
Booting an image and operating some usb device is even better. Are n810 images are freely available for download somewhere? Failing that, is it possible to just install some linux distro (say debian) on the virtual n810 or another arm device which has a musb controller?
n800/n810 qemu images based on official are not redistributable, as they carry propiertary software. Instructions howto convert a firmare to qemu image exist, but to get your hands on a firmware you need to know a n800/n810 serial number:
http://marcin.juszkiewicz.com.pl/2008/04/11/nokia-n800-emulation/
http://www.rkeene.org/projects/info/wiki/106
Marcin might have a poky image still somehere thou?
Riku
W dniu 02.09.2011 10:00, Riku Voipio pisze:
Quoted 9 lines
n800/n810 qemu images based on official are not redistributable, as they carry propiertary software. Instructions howto convert a firmare to qemu image exist, but to get your hands on a firmware you need to know a n800/n810 serial number:
http://marcin.juszkiewicz.com.pl/2008/04/11/nokia-n800-emulation/
http://www.rkeene.org/projects/info/wiki/106Marcin might have a poky image still somehere thou?
http://narcissus.angstrom-distribution.org/ can generate jffs2/ubifs images for n8x0 (select nokia800 from machine selector). You will need a copy of config mtd partition from working n8x0 (at least it was needed when I was playing with it) with “no-lifeguard-reset” flag set.
http://marcin.juszkiewicz.com.pl/2008/08/01/nokia-n8x0-emulation-part-ii/ is second part of my story with running Maemo on n8x0.
I remember fun during Berlin Maemo Summit where I presented this working but was not allowed (by Intel) to show working BT emulation cause it was not yet cleaned by 'legal' who will have copyright for this code.
Hi,
Quoted 4 lines
http://narcissus.angstrom-distribution.org/ can generate jffs2/ubifs images for n8x0 (select nokia800 from machine selector). You will need a copy of config mtd partition from working n8x0 (at least it was needed when I was playing with it) with “no-lifeguard-reset” flag set.
Got a tarball. Passing the zImage in there to qemu via -kernel works. I see it boot @ sdl, with the boot messages flying by quickly. Redirecting the console to a terminal seems not to work, at least not via '-nographic -append "console=ttyS0"'
When passing in something via -mtdblock I can see lots of error messages about bad eraseblocks. I guess this is where the config mtd partition will be needed?
thanks,
Gerd
Quoted 3 lines · Gerd Hoffmann
For starters just "qemu-system-arm -M n810" is better than nothing, this does at least make sure it doesn't blow up somewhere when creating the device tree.
NB that the n810 machine doesn't create the usb device unless you pass "-usb" on the command line so you need tat to be able to test the init code.
-- PMM
Quoted 1 line · Gerd Hoffmann
Booting an image and operating some usb device is even better.
Incidentally, if anybody has both (1) an image/config that connects a keyboard via usb-musb and (2) a copy of the MUSB hardware spec they will be able to test and fix the bug that musb_port_ops doesn't implement the wakeup callback. Sadly I have neither :-(
-- PMM