greybus: add pwm protocol driver

Add a PWM driver that implements the Greybus PWM protocol.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: don't assume PAGE_SIZE for URB size

The buffers allocated for CPort URBS are ES1_GBUF_MSG_SIZE bytes.
But usb_fill_bulk_urb() passes PAGE_SIZE as its size.  They happen
to be the same, but the code is wrong, so fix it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greybus: fix request timeout bug

This commit changed the timeout behavior for operations:
    6a8732e operation: make the timeout a per-operation thing...

It unfortunately left in place some code that was only
appropriate for per-connection timeouts.  In particular,
the timer for an operation is currently getting started
only if no existing operations are in flight.

Fix that oversight, and schedule an operation's timer
unconditionally.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greybus: move timeout out of gb_operation_insert()

Currently, gb_operation_insert() arranges to time out a request if
it takes too long.  Move this out of that function and into
gb_operation_request_send(), so we know it's getting set up after
the request has actually be sent.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greybus: simplify pending operations tracking

Greg raised the alarm when I first put in the red-black tree for
tracking pending operations.  The reality as that we're not likely
to have that many operations in flight at any one time, so the
complexity of the red-black tree is most likely unwarranted.  I
already

This pulls out the red-black tree and uses a simple list instead.  A
connection maintains two lists of operations.  An operation starts
on its connection's operations list.  It is moved to the pending
list when its request message is sent.  And it is moved back to
the operations list when the response message arrives.  It is
removed from whatever list it's in when the operation is destroyed.
We reuse the single operation->links field for both lists.

Only outgoing requests are ever "pending."  Incoming requests are
transient--we receive them, process them, send the response, and
then we're done.

Change a few function names so it's clear we're working with the
pending list.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greybus: op_cycle doesn't need to be atomic

We can update a connection's operation id counter under spinlock,
and thereby avoid the need to maintain it in an atomic variable.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greybus: pass operation type on request receive

When an incoming request is received, the operation type is encoded
in the header and is not available in the payload.  Add the
operation type as a parameter to the request_recv method so the
request handler knows what to do.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>