Commit graph

104 commits

Author SHA1 Message Date
Aidan MacDonald
6e61e6f0c8 usb_core: don't buffer control request unnecessarily
Due to how the old control request API worked, the request
pointer (and the pointed-to contents) passed by the driver
must remain valid for the lifetime of the request.

The buffered copy wasn't used consistently anyway, so it
should be safe to just get rid of it.

(This only affects the old API compatibility layer.)

Change-Id: I00294c718a7515a91b84f7c7cae5220c73aa5960
2021-11-14 17:58:39 +00:00
Aidan MacDonald
f8810be6de usb_core: More legacy control API fixes
In the old API, usb_core_transfer_complete() would ignore
any completions on EP0. The legacy control API will also
ignore most completions on EP0, but it only did so after
filling in the completion event.

If the driver submits a spurious completion on EP0, then
this could clobber a previously queued completion event.

Fix this by deciding whether to ignore the completion
*before* modifying the event data.

Change-Id: I68526898a96efa594ada4e94bb6851aaaf12e92a
2021-11-13 18:37:33 +00:00
Aidan MacDonald
7af98ce6bb usb: Fix possible SET ADDRESS data corruption
The address from the packet needs to be saved before sending
the response -- after the response the request being pointed
to could get overwritten. This used to be done correctly but
I unintentionally broke it when updating the handler to the
new control request API.

Change-Id: I9b11548baf20dce44a82301731405dc8e8f1cef3
2021-11-09 14:45:07 +00:00
Aidan MacDonald
8c954c68e5 usb: Attempt to fix race condition in compatibility layer
Because usb_core_legacy_control_request() is called by an
interrupt handler the global variables used to track the
current control request at the very least need to be volatile.

It might also be necessary to disable IRQs but I'm not sure
of that.

Change-Id: I0f0bb86d0ad63734e8d3c73cb1c52fedf5a98120
2021-11-08 21:46:36 +00:00
Aidan MacDonald
77731c3579 usb: port usb_core control request handling to new API
Change-Id: I3850c9cfcb87831e56884c83e31f728590b76f83
2021-10-16 21:14:42 +01:00
Aidan MacDonald
82efb1150e usb: implement new API with legacy emulation layer
All existing USB drivers now define USB_LEGACY_CONTROL_API to
enable the emulation layer.

Control request handlers will be ported in follow-up commits.

Change-Id: I4be1ce7c372f2f6fee5978a4858c841b72e77405
2021-10-16 21:14:42 +01:00
Aidan MacDonald
dff8320a5d usb: add request data argument to all control request handlers
Change-Id: I237143fa0d95c914b8e25ed22f8acde96ec00551
2021-10-16 21:14:42 +01:00
Aidan MacDonald
b69d43c247 usb: give USB transfer completion events two data pointers
Change-Id: I036cc7f02c2f86a364d2dba59493a6aa893f2c16
2021-10-16 21:14:42 +01:00
Aidan MacDonald
ec164c389c usb: introduce new control request API
Change-Id: I6545d8985ab683c026f28f6a7c0e23b40d0a6506
2021-10-16 15:58:43 -04:00
James Buren
c0a59b9a6a usbstack: Revise usb string descriptor table to use enum values for indices
This makes it possible for macros of conditionally included string
descriptors to get a correct index no matter what other usb drivers
are enabled or disabled due to the nature behavior of enums.

Change-Id: I8ccebbd316605bed0f5d90b6b73fab4a333c02fa
2021-10-06 17:59:17 -04:00
Aidan MacDonald
3a89fdee96 x1000: fix hang that may occur in USB mode
Upon getting a USB reset, the USB core will update charging
current by calling usb_charging_maxcurrent_change(). On all
current X1000 targets this may cause a hang, since changing
the charge current involves a blocking I2C transaction.

Eg. if the host issues a reset when we're already configured
as part of error recovery, the change from 500 mA -> 100 mA
will cause a hang.

Change-Id: I5b45272c01fa16b179ae3d16bbc50c7fab9a416b
2021-10-02 15:09:46 +01:00
Aidan MacDonald
672bbe434b usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()
IMHO the current name is somewhat misleading:

- usb_drv_send() is blocking and we have usb_drv_send_nonblocking()
  for the non-blocking case. This inconsistent naming can only
  promote confusion. (And what would we call a blocking receive?)

- Other hardware abstraction APIs in Rockbox are usually blocking:
  storage, LCD, backlight, audio... in other words, blocking is the
  default expected behavior, with non-blocking calls being a rarity.

Change-Id: I05b41088d09eab582697674f4f06fdca0c8950af
2021-09-20 22:41:29 +01:00
Tomasz Moń
b4ecd612f7
Sansa Connect: Use deviceid in USB Serial Number
Atmel AT88SC6416C CryptoMemory is almost I2C compatible. The device
is connected to bitbanged I2C bus shared with compliant I2C devices.

Change-Id: Iec54702db1bdfb93c01291eef18ec60391c63b16
2021-07-10 08:56:32 +02:00
James Buren
018372bf39 usb: implement macro for initializing USB strings
This uses the new unicode string literal feature that is available
now to greatly simplify the initialization of these special string
types. This makes them much more readable at a quick glance.

Change-Id: Iad8b49aa763486608e3bb7e83fb8abfb48ce0a7b
2021-03-25 13:26:03 -05:00
Marcin Bukat
c1609b0889 Coding style fix for bde5394
Change-Id: I6e9ba6a2570915191cf5b66f58ed9ddb1959b6cc
2014-02-10 07:46:13 +01:00
Frank Gevaerts
bde5394f5a Return a valid USB string descriptor for index 0xEE.
Windows will try to retrieve such a descriptor on first connect.
If the device returns STALL or a regular string descriptor (i.e.
not one that follows the Microsoft OS Descriptor spec), things
will continue normally.

Unfortunately some of our low-level USB drivers have issues with
STALL so any other valid descriptor is the next best solution.

Change-Id: I59eb09eea157e4e14bec0197a898be378a5559f2
Reviewed-on: http://gerrit.rockbox.org/680
Reviewed-by: Frank Gevaerts <frank@gevaerts.be>
Tested: Frank Gevaerts <frank@gevaerts.be>
2014-02-09 20:39:18 +01:00
Frank Gevaerts
204668db89 Make sure usb class driver disconnect() functions are called properly.
disconnect() needs to be called exactly once per call to init_connection().
In case of bus resets, disconnect() was not called, which led to leaking
alloc_maximum() allocated buflib handles, which led to buflib running out
of memory to allocate.

Change-Id: I03025da578dc54e48b6de6bd3e3f40feae7220a6
2014-01-05 22:57:04 +01:00
Marcin Bukat
49bcf35309 usb stack: add more verbose debug logf()s
Change-Id: I087aefd2854978813c7e4ed7ef7da400f3692e39
2013-07-24 23:17:13 +02:00
Amaury Pouly
21c5ffe09a usb_core: rework handling of clear feature
Change-Id: Icb1e973aa5fd8520eff0796aa8164e0a988d9107
2013-07-24 23:16:38 +02:00
Amaury Pouly
d938ae692c imx233: fix ocotop/debug and usb-core for stmp3600
Currently we don't know where the serial number is stored on the
stmp3600. It is probably using the laser fuses but this needs to
be investigated

Change-Id: I1ac25e38b8f65635abb68788ceb65df0a740dabd
2013-06-24 13:17:17 +02:00
Amaury Pouly
6f0eaf4827 imx233: rewrite ocotp using new register headers
Change-Id: I3c622119a1e296ec6b3f35f27e81b5118ab7f6cc
2013-06-16 16:58:00 +02:00
Amaury Pouly
775ab07d5e usb: add support for hardware handled SET ADDR/CONFIG
Some USB controllers like the one of the Rockchip 27xx handle some
requests in pure hardware. This is especially a problem for two
of them:
- SET ADDR which is used by our core to track the DEFAULT/ADDRESS
  state and is required for the drivers to work properly
- SET CONFIG which is used by our core to initialise the drivers
  by calling init_connection()
In these cases we need a way to notify the core that such requests
happened.
We do this by exporting two functions which directly notify the
core about these requests and perform the necessary init steps
required without doing the actual USB transfers. Special care is
needed because these functions could be called from an interrupt
handler. For this reason we still use the usb_queue and introduce
new IDs so that they are processed in order and safely.

No functional change is intended, both in the usbstack and on
targets without such quirks.

Change-Id: Ie42feffd4584e88bf37cff018b627f333dca1140
2012-12-07 13:37:26 +01:00
Amaury Pouly
9bae382e95 Fill USB serial number descriptor on imx233 targets.
Compute a serial number using the ocotp OPS bits like the OF.
Also add a comment about the first character of serial number
being a indicator of the enabled interfaces.

Change-Id: I9b90aed4e3b803f12fec003c9bc8ee8a046f4e42
2012-05-31 13:57:25 +02:00
Rafaël Carré
c4a51d2d88 missing const 2012-05-07 01:35:57 -04:00
Frank Gevaerts
4fcffcbdf3 Reorganise USB initialisation to not depend on a specific enumeration sequence, by Bartosz Fabianowski, with minor tweaks by Michael Sevakis (FS#12497)
FreeBSD apparently sends a SET_ADDRESS first, which confused our code.
This patch fixes that, and also simplifies the connection handling a bit.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31582 a1c6a512-1295-4272-9138-f99709370657
2012-01-04 21:55:09 +00:00
Michael Sparmann
a9b5c2af93 usb_core: Fix typo in comment
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31482 a1c6a512-1295-4272-9138-f99709370657
2011-12-31 16:53:41 +00:00
Bertrik Sikken
9c33dca647 Fix tabs in .c and .h files in firmware/
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29832 a1c6a512-1295-4272-9138-f99709370657
2011-05-08 11:37:18 +00:00
Michael Sevakis
05f6f3419a Add a higher level USB detection that prevents fraudulent bus resets from causing USB mode to be entered. Enable for SA9200 only at this time. Also, for SA9200, use the bus power GPIO rather than the 'connector inserted' GPIO to detect the cable.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29068 a1c6a512-1295-4272-9138-f99709370657
2011-01-17 12:24:41 +00:00
Amaury Pouly
7baa522364 usb: remove unused variable and correctly stall on unhandled control requests
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28121 a1c6a512-1295-4272-9138-f99709370657
2010-09-20 14:18:14 +00:00
Rafaël Carré
336cec2e1f Fix set_serial_descriptor() for targets with as3543
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28013 a1c6a512-1295-4272-9138-f99709370657
2010-09-06 18:26:17 +00:00
Torne Wuff
2eb0142587 New USB charging system, part 2 - "Force" charging mode
Enable support for the "force" mode of USB charging. This should work on Gigabeat S and Nano2g (and any other future target which has a RB usb stack and supports charging) - if a host connection is not detected within 10 seconds of USB insertion, assume that the connected device is an AC charger and charge anyway, if the user has specified "force" as the mode.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26594 a1c6a512-1295-4272-9138-f99709370657
2010-06-05 20:43:30 +00:00
Torne Wuff
991e92fd3d New USB charging system, part 1 - API rework and user-visible setting update
1) "Charge during USB connection" option is now tristate: off/on/force. Currently "force" behaves just like "on", but in future it will allow charging even when it was not possible to positively identify a charger.

2) The H300 code has been adjusted to use the new system but there should be no functional differences, it already had the USB charging option and its USB/charging support is hardware controlled.

3) The Gigabeat S code has been adjusted to use the new system: the player now has the USB charging option, which wasn't previously available. The player will only charge at full speed when allowed to do so by a working USB host, so USB AC adapters won't work very well; however, they didn't work before either, so this is not a change in functionality.

4) The iPod Nano 2G code has been adjusted to use the new system: it already had the USB charging option. Using a USB AC adapter won't charge at full speed any more (it did before) - the old implementation was equivalent to the not-yet-implemented "force" option in the new system.

No other target should be affected. Support for the "force" mode and support for at least some other iPod models will come in a future commit :)


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26570 a1c6a512-1295-4272-9138-f99709370657
2010-06-05 10:05:27 +00:00
Amaury Pouly
0104539a5f Enforce the 80-char limit to make everyone happy.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25619 a1c6a512-1295-4272-9138-f99709370657
2010-04-13 10:07:02 +00:00
Amaury Pouly
8a8568088f - Forget a cosmetic change.
- Interface number is in lower half of wIndex for interface control requests. Upper half is reserved and used in other protocols.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25618 a1c6a512-1295-4272-9138-f99709370657
2010-04-13 08:40:27 +00:00
Amaury Pouly
d372e3c8e6 Attempt to have a consistent coding convention in usb_core.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25617 a1c6a512-1295-4272-9138-f99709370657
2010-04-13 08:40:21 +00:00
Frank Gevaerts
c689496e04 Remove unnecessary (and incorrect) acks after stalling the control endpoint
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25359 a1c6a512-1295-4272-9138-f99709370657
2010-03-27 19:41:37 +00:00
Amaury Pouly
ae208af9cc - Fix the control_handler selection in usb_core when a request in sent to an endpoint (use endpoint dir and not EP_CONTROL !)
- Only interpret standard endpoint requests (previous code didn't check the request type) and pass all others to usb drivers.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25069 a1c6a512-1295-4272-9138-f99709370657
2010-03-08 13:00:24 +00:00
Frank Gevaerts
c12502f249 use the EP_DIR() macro to go from USB_DIR_* to a 0 or 1 value
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23640 a1c6a512-1295-4272-9138-f99709370657
2009-11-15 22:17:45 +00:00
Frank Gevaerts
724e4fe5e4 Don't use the same completion_event for both directions. This could cause problems on USB controllers that have IN and OUT endpoints with the same endpoint number (such as the arc controller)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23639 a1c6a512-1295-4272-9138-f99709370657
2009-11-15 21:58:25 +00:00
Jeffrey Goode
9d842683eb Comment out LOGF_ENABLE defines everywhere, replace evil comments
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23497 a1c6a512-1295-4272-9138-f99709370657
2009-11-03 16:25:03 +00:00
Frank Gevaerts
bad510ad10 Change control handling to start expecting host packets before sending data to the host. This makes the handling less timing sensitive on some controllers
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23263 a1c6a512-1295-4272-9138-f99709370657
2009-10-19 16:21:50 +00:00
Tomer Shalev
31c18116de USB: Use explicit casting when setting wTotalLength field in descriptor
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23157 a1c6a512-1295-4272-9138-f99709370657
2009-10-13 19:50:23 +00:00
Tomer Shalev
8c5141b32e Commit "FS#10468 - USB HID: Show keypad mode on screen"
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22852 a1c6a512-1295-4272-9138-f99709370657
2009-09-30 10:06:04 +00:00
Maurus Cuelenaere
f060b9764d Remove USB storage defines from USB core
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22018 a1c6a512-1295-4272-9138-f99709370657
2009-07-23 23:05:26 +00:00
Frank Gevaerts
4f2dfcc01b always call the class driver init function. This is needed because they are called before the usb_core_enable_driver() calls, so depending on enabled status breaks things
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21069 a1c6a512-1295-4272-9138-f99709370657
2009-05-24 20:46:57 +00:00
Frank Gevaerts
c61a75173b Reorganise USB stack defines. Now config.h decides which class drivers get enabled instead of usb_core.h
Also enable HID, and use that as the dummy class instead of charging-only for controllers that have working interrupt transfers.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21053 a1c6a512-1295-4272-9138-f99709370657
2009-05-23 14:30:20 +00:00
Frank Gevaerts
bca3d3dca4 Fix #ifdef nesting to allow USB_HID to be built without USB_CHARGING_ONLY (FS#10236 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21052 a1c6a512-1295-4272-9138-f99709370657
2009-05-23 12:41:46 +00:00
Frank Gevaerts
69a4117c1d Add working USB HID driver, by Tomer Shalev (part of his GSoC work).
This needs support for usb interrupt transfers, so there are some changes in various USB drivers as well (only usb-drv-arc supports it at this point, others won't have working HID yet).

HID is disabled for now, as the apps/ part is not included yet.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20962 a1c6a512-1295-4272-9138-f99709370657
2009-05-16 15:30:09 +00:00
Maurus Cuelenaere
1ab19d0b9b Disable usage of USB serial descriptor when no unique one is available
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20761 a1c6a512-1295-4272-9138-f99709370657
2009-04-20 20:24:23 +00:00
Frank Gevaerts
2a085f4477 Add preliminary HID driver. It doesn't do anything yet, but that should change soon (FS#10116 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20750 a1c6a512-1295-4272-9138-f99709370657
2009-04-19 21:17:18 +00:00