From 74ec7598b51fb347a1273f8deea42883ae725e6e Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 22 Jun 2016 11:42:05 +0200 Subject: [PATCH] greybus: es2: add support for greybus cport flags Add support for Greybus CPort flags that are sent to the bridge through a new USB vendor request when enabling a CPort as part of connection establishment. Currently the Greybus control and high-priority connection flags are recognised and forwarded to APBA. Reviewed-by: Alex Elder Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/es2.c | 42 +++++++++++++++++++++ drivers/staging/greybus/greybus_protocols.h | 10 +++++ 2 files changed, 52 insertions(+) diff --git a/drivers/staging/greybus/es2.c b/drivers/staging/greybus/es2.c index 89fe7641cd24..22174450a8b3 100644 --- a/drivers/staging/greybus/es2.c +++ b/drivers/staging/greybus/es2.c @@ -607,6 +607,47 @@ static void es2_cport_release(struct gb_host_device *hd, u16 cport_id) ida_simple_remove(&hd->cport_id_map, cport_id); } +static int cport_enable(struct gb_host_device *hd, u16 cport_id, + unsigned long flags) +{ + struct es2_ap_dev *es2 = hd_to_es2(hd); + struct usb_device *udev = es2->usb_dev; + struct gb_apb_request_cport_flags *req; + int ret; + + req = kzalloc(sizeof(*req), GFP_KERNEL); + if (!req) + return -ENOMEM; + + if (flags & GB_CONNECTION_FLAG_CONTROL) + req->flags |= GB_APB_CPORT_FLAG_CONTROL; + if (flags & GB_CONNECTION_FLAG_HIGH_PRIO) + req->flags |= GB_APB_CPORT_FLAG_HIGH_PRIO; + + dev_dbg(&hd->dev, "%s - cport = %u, flags = %02x\n", __func__, + cport_id, req->flags); + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + GB_APB_REQUEST_CPORT_FLAGS, + USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_INTERFACE, cport_id, 0, + req, sizeof(*req), ES2_TIMEOUT); + if (ret != sizeof(*req)) { + dev_err(&udev->dev, "failed to set cport flags for port %d\n", + cport_id); + if (ret >= 0) + ret = -EIO; + + goto out; + } + + ret = 0; +out: + kfree(req); + + return ret; +} + static int cport_disable(struct gb_host_device *hd, u16 cport_id) { int retval; @@ -799,6 +840,7 @@ static struct gb_hd_driver es2_driver = { .message_cancel = message_cancel, .cport_allocate = es2_cport_allocate, .cport_release = es2_cport_release, + .cport_enable = cport_enable, .cport_disable = cport_disable, .latency_tag_enable = latency_tag_enable, .latency_tag_disable = latency_tag_disable, diff --git a/drivers/staging/greybus/greybus_protocols.h b/drivers/staging/greybus/greybus_protocols.h index 203bc46151e7..327d01f3679a 100644 --- a/drivers/staging/greybus/greybus_protocols.h +++ b/drivers/staging/greybus/greybus_protocols.h @@ -225,6 +225,16 @@ struct gb_control_timesync_get_last_event_response { #define REQUEST_TIMESYNC_AUTHORITATIVE 0x0f #define REQUEST_TIMESYNC_GET_LAST_EVENT 0x10 +/* requests to set Greybus CPort flags */ +#define GB_APB_REQUEST_CPORT_FLAGS 0x11 + +struct gb_apb_request_cport_flags { + u32 flags; +#define GB_APB_CPORT_FLAG_CONTROL 0x01 +#define GB_APB_CPORT_FLAG_HIGH_PRIO 0x02 +} __packed; + + /* Firmware Download Protocol */ /* Request Types */