summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/sandbox.c11
-rw-r--r--drivers/clk/clk-uclass.c16
-rw-r--r--drivers/clk/intel/clk_intel.c4
-rw-r--r--drivers/core/device.c9
-rw-r--r--drivers/core/of_extra.c21
-rw-r--r--drivers/dfu/dfu.c7
-rw-r--r--drivers/dfu/dfu_mmc.c39
-rw-r--r--drivers/dfu/dfu_mtd.c4
-rw-r--r--drivers/i2c/Makefile2
-rw-r--r--drivers/i2c/designware_i2c_pci.c2
-rw-r--r--drivers/misc/cros_ec.c200
-rw-r--r--drivers/misc/cros_ec_lpc.c7
-rw-r--r--drivers/misc/cros_ec_sandbox.c100
-rw-r--r--drivers/mmc/renesas-sdhi.c3
-rw-r--r--drivers/mmc/tmio-common.c3
-rw-r--r--drivers/mmc/tmio-common.h2
-rw-r--r--drivers/rtc/i2c_rtc_emul.c4
-rw-r--r--drivers/tpm/cr50_i2c.c42
-rw-r--r--drivers/usb/gadget/Kconfig9
-rw-r--r--drivers/usb/gadget/ci_udc.c5
-rw-r--r--drivers/usb/gadget/composite.c392
-rw-r--r--drivers/usb/gadget/core.c45
-rw-r--r--drivers/usb/gadget/ep0.c46
-rw-r--r--drivers/usb/gadget/epautoconf.c6
-rw-r--r--drivers/usb/gadget/f_fastboot.c85
-rw-r--r--drivers/usb/gadget/f_rockusb.c7
-rw-r--r--drivers/usb/gadget/f_thor.c11
-rw-r--r--drivers/usb/gadget/g_dnl.c1
-rw-r--r--drivers/usb/gadget/u_os_desc.h123
-rw-r--r--drivers/usb/gadget/usbstring.c74
30 files changed, 1062 insertions, 218 deletions
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 34c26cda47e..f57f690d3c0 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -92,6 +92,7 @@ int host_dev_bind(int devnum, char *filename)
{
struct host_block_dev *host_dev;
struct udevice *dev;
+ struct blk_desc *desc;
char dev_name[20], *str, *fname;
int ret, fd;
@@ -143,6 +144,12 @@ int host_dev_bind(int devnum, char *filename)
goto err_file;
}
+ desc = blk_get_devnum_by_type(IF_TYPE_HOST, devnum);
+ desc->removable = 1;
+ snprintf(desc->vendor, BLK_VEN_SIZE, "U-Boot");
+ snprintf(desc->product, BLK_PRD_SIZE, "hostfile");
+ snprintf(desc->revision, BLK_REV_SIZE, "1.0");
+
return 0;
err_file:
os_close(fd);
@@ -187,6 +194,10 @@ int host_dev_bind(int dev, char *filename)
blk_dev->block_write = host_block_write;
blk_dev->devnum = dev;
blk_dev->part_type = PART_TYPE_UNKNOWN;
+ blk_dev->removable = 1;
+ snprintf(blk_dev->vendor, BLK_VEN_SIZE, "U-Boot");
+ snprintf(blk_dev->product, BLK_PRD_SIZE, "hostfile");
+ snprintf(blk_dev->revision, BLK_REV_SIZE, "1.0");
part_init(blk_dev);
return 0;
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index b75056718bf..d5c4e3cbe51 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -83,7 +83,7 @@ static int clk_get_by_index_tail(int ret, ofnode node,
if (ret) {
debug("%s: uclass_get_device_by_of_offset failed: err=%d\n",
__func__, ret);
- return ret;
+ return log_msg_ret("get", ret);
}
clk->dev = dev_clk;
@@ -96,14 +96,15 @@ static int clk_get_by_index_tail(int ret, ofnode node,
ret = clk_of_xlate_default(clk, args);
if (ret) {
debug("of_xlate() failed: %d\n", ret);
- return ret;
+ return log_msg_ret("xlate", ret);
}
return clk_request(dev_clk, clk);
err:
debug("%s: Node '%s', property '%s', failed to request CLK index %d: %d\n",
__func__, ofnode_get_name(node), list_name, index, ret);
- return ret;
+
+ return log_msg_ret("prop", ret);
}
static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name,
@@ -122,7 +123,7 @@ static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name,
if (ret) {
debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n",
__func__, ret);
- return ret;
+ return log_ret(ret);
}
@@ -470,6 +471,7 @@ int clk_free(struct clk *clk)
ulong clk_get_rate(struct clk *clk)
{
const struct clk_ops *ops;
+ int ret;
debug("%s(clk=%p)\n", __func__, clk);
if (!clk_valid(clk))
@@ -479,7 +481,11 @@ ulong clk_get_rate(struct clk *clk)
if (!ops->get_rate)
return -ENOSYS;
- return ops->get_rate(clk);
+ ret = ops->get_rate(clk);
+ if (ret)
+ return log_ret(ret);
+
+ return 0;
}
struct clk *clk_get_parent(struct clk *clk)
diff --git a/drivers/clk/intel/clk_intel.c b/drivers/clk/intel/clk_intel.c
index b633934d90a..46ccbb1d834 100644
--- a/drivers/clk/intel/clk_intel.c
+++ b/drivers/clk/intel/clk_intel.c
@@ -29,8 +29,8 @@ static const struct udevice_id intel_clk_ids[] = {
{ }
};
-U_BOOT_DRIVER(clk_intel) = {
- .name = "clk_intel",
+U_BOOT_DRIVER(intel_apl_clk) = {
+ .name = "intel_apl_clk",
.id = UCLASS_CLK,
.of_match = intel_clk_ids,
.ops = &intel_clk_ops,
diff --git a/drivers/core/device.c b/drivers/core/device.c
index aeab3836ed7..8629df8defb 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -462,6 +462,15 @@ int device_probe(struct udevice *dev)
* continue regardless of the result of pinctrl. Don't process pinctrl
* settings for pinctrl devices since the device may not yet be
* probed.
+ *
+ * This call can produce some non-intuitive results. For example, on an
+ * x86 device where dev is the main PCI bus, the pinctrl device may be
+ * child or grandchild of that bus, meaning that the child will be
+ * probed here. If the child happens to be the P2SB and the pinctrl
+ * device is a child of that, then both the pinctrl and P2SB will be
+ * probed by this call. This works because the DM_FLAG_ACTIVATED flag
+ * is set just above. However, the PCI bus' probe() method and
+ * associated uclass methods have not yet been called.
*/
if (dev->parent && device_get_uclass_id(dev) != UCLASS_PINCTRL)
pinctrl_select_state(dev, "default");
diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c
index 6420e6ec448..653344529e6 100644
--- a/drivers/core/of_extra.c
+++ b/drivers/core/of_extra.c
@@ -14,16 +14,17 @@
int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry)
{
const char *prop;
+ ofnode subnode;
if (ofnode_read_u32(node, "image-pos", &entry->offset)) {
debug("Node '%s' has bad/missing 'image-pos' property\n",
ofnode_get_name(node));
- return log_ret(-ENOENT);
+ return log_msg_ret("image-pos", -ENOENT);
}
if (ofnode_read_u32(node, "size", &entry->length)) {
debug("Node '%s' has bad/missing 'size' property\n",
ofnode_get_name(node));
- return log_ret(-ENOENT);
+ return log_msg_ret("size", -ENOENT);
}
entry->used = ofnode_read_s32_default(node, "used", entry->length);
prop = ofnode_read_string(node, "compress");
@@ -31,18 +32,20 @@ int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry)
if (!strcmp(prop, "lz4"))
entry->compress_algo = FMAP_COMPRESS_LZ4;
else
- return log_msg_ret("Unknown compression algo",
- -EINVAL);
+ return log_msg_ret("compression algo", -EINVAL);
} else {
entry->compress_algo = FMAP_COMPRESS_NONE;
}
entry->unc_length = ofnode_read_s32_default(node, "uncomp-size",
entry->length);
- prop = ofnode_read_string(node, "hash");
- if (prop)
- entry->hash_size = strlen(prop);
- entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
- entry->hash = (uint8_t *)prop;
+ subnode = ofnode_find_subnode(node, "hash");
+ if (ofnode_valid(subnode)) {
+ prop = ofnode_read_prop(subnode, "value", &entry->hash_size);
+
+ /* Assume it is sha256 */
+ entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
+ entry->hash = (uint8_t *)prop;
+ }
return 0;
}
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index 501a60b3440..213a20e7bcb 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -26,6 +26,8 @@ static struct hash_algo *dfu_hash_algo;
static unsigned long dfu_timeout = 0;
#endif
+bool dfu_reinit_needed = false;
+
/*
* The purpose of the dfu_flush_callback() function is to
* provide callback for dfu user
@@ -139,6 +141,8 @@ int dfu_init_env_entities(char *interface, char *devstr)
char *env_bkp;
int ret = 0;
+ dfu_reinit_needed = false;
+
#ifdef CONFIG_SET_DFU_ALT_INFO
set_dfu_alt_info(interface, devstr);
#endif
@@ -614,7 +618,8 @@ const char *dfu_get_dev_type(enum dfu_device_type t)
const char *dfu_get_layout(enum dfu_layout l)
{
const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2",
- "EXT3", "EXT4", "RAM_ADDR" };
+ "EXT3", "EXT4", "RAM_ADDR", "SKIP",
+ "SCRIPT" };
return dfu_layout[l];
}
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 691d01c7ebd..e63fa84ce4f 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -16,6 +16,7 @@
#include <fat.h>
#include <mmc.h>
#include <part.h>
+#include <command.h>
static unsigned char *dfu_file_buf;
static u64 dfu_file_buf_len;
@@ -108,6 +109,8 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu,
case DFU_FS_EXT4:
fstype = FS_TYPE_EXT;
break;
+ case DFU_SKIP:
+ return 0;
default:
printf("%s: Layout (%s) not (yet) supported!\n", __func__,
dfu_get_layout(dfu->layout));
@@ -204,6 +207,12 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu,
case DFU_FS_EXT4:
ret = mmc_file_buf_write(dfu, offset, buf, len);
break;
+ case DFU_SCRIPT:
+ ret = run_command_list(buf, *len, 0);
+ break;
+ case DFU_SKIP:
+ ret = 0;
+ break;
default:
printf("%s: Layout (%s) not (yet) supported!\n", __func__,
dfu_get_layout(dfu->layout));
@@ -216,9 +225,21 @@ int dfu_flush_medium_mmc(struct dfu_entity *dfu)
{
int ret = 0;
- if (dfu->layout != DFU_RAW_ADDR) {
- /* Do stuff here. */
+ switch (dfu->layout) {
+ case DFU_FS_FAT:
+ case DFU_FS_EXT4:
ret = mmc_file_buf_write_finish(dfu);
+ break;
+ case DFU_SCRIPT:
+ /* script may have changed the dfu_alt_info */
+ dfu_reinit_needed = true;
+ break;
+ case DFU_RAW_ADDR:
+ case DFU_SKIP:
+ break;
+ default:
+ printf("%s: Layout (%s) not (yet) supported!\n", __func__,
+ dfu_get_layout(dfu->layout));
}
return ret;
@@ -238,6 +259,9 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size)
if (ret < 0)
return ret;
return 0;
+ case DFU_SCRIPT:
+ case DFU_SKIP:
+ return 0;
default:
printf("%s: Layout (%s) not (yet) supported!\n", __func__,
dfu_get_layout(dfu->layout));
@@ -316,7 +340,7 @@ void dfu_free_entity_mmc(struct dfu_entity *dfu)
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
{
const char *entity_type;
- size_t second_arg;
+ ssize_t second_arg;
size_t third_arg;
struct mmc *mmc;
@@ -339,7 +363,7 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
* Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8,
* with default 10.
*/
- second_arg = simple_strtoul(argv[1], NULL, 0);
+ second_arg = simple_strtol(argv[1], NULL, 0);
third_arg = simple_strtoul(argv[2], NULL, 0);
mmc = find_mmc_device(dfu->data.mmc.dev_num);
@@ -399,6 +423,10 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
dfu->layout = DFU_FS_FAT;
} else if (!strcmp(entity_type, "ext4")) {
dfu->layout = DFU_FS_EXT4;
+ } else if (!strcmp(entity_type, "skip")) {
+ dfu->layout = DFU_SKIP;
+ } else if (!strcmp(entity_type, "script")) {
+ dfu->layout = DFU_SCRIPT;
} else {
pr_err("Memory layout (%s) not supported!\n", entity_type);
return -ENODEV;
@@ -406,7 +434,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
/* if it's NOT a raw write */
if (strcmp(entity_type, "raw")) {
- dfu->data.mmc.dev = second_arg;
+ dfu->data.mmc.dev = (second_arg != -1) ? second_arg :
+ dfu->data.mmc.dev_num;
dfu->data.mmc.part = third_arg;
}
diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
index b34975dbb0d..ca67585a7e4 100644
--- a/drivers/dfu/dfu_mtd.c
+++ b/drivers/dfu/dfu_mtd.c
@@ -204,7 +204,7 @@ static int dfu_flush_medium_mtd(struct dfu_entity *dfu)
int ret;
/* in case of ubi partition, erase rest of the partition */
- if (dfu->data.nand.ubi) {
+ if (dfu->data.mtd.ubi) {
struct erase_info erase_op = {};
erase_op.mtd = dfu->data.mtd.info;
@@ -242,7 +242,7 @@ static unsigned int dfu_polltimeout_mtd(struct dfu_entity *dfu)
* ubi partition, as sectors which are not used need
* to be erased
*/
- if (dfu->data.nand.ubi)
+ if (dfu->data.mtd.ubi)
return DFU_MANIFEST_POLL_TIMEOUT;
return DFU_DEFAULT_POLL_TIMEOUT;
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 1aac5c481e2..29aab0f9e30 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -39,7 +39,9 @@ obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o
obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o
obj-$(CONFIG_SYS_I2C_ROCKCHIP) += rk_i2c.o
obj-$(CONFIG_SYS_I2C_S3C24X0) += s3c24x0_i2c.o exynos_hs_i2c.o
+ifndef CONFIG_SPL_BUILD
obj-$(CONFIG_SYS_I2C_SANDBOX) += sandbox_i2c.o i2c-emul-uclass.o
+endif
obj-$(CONFIG_SYS_I2C_SH) += sh_i2c.o
obj-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o
obj-$(CONFIG_SYS_I2C_STM32F7) += stm32f7_i2c.o
diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c
index ec0cdf62207..9e387737b6e 100644
--- a/drivers/i2c/designware_i2c_pci.c
+++ b/drivers/i2c/designware_i2c_pci.c
@@ -192,6 +192,8 @@ static const struct udevice_id designware_i2c_pci_ids[] = {
{ }
};
+DM_DRIVER_ALIAS(i2c_designware_pci, intel_apl_i2c)
+
U_BOOT_DRIVER(i2c_designware_pci) = {
.name = "i2c_designware_pci",
.id = UCLASS_I2C,
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index f03b7d55d64..ebfa7c41c25 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -44,6 +44,10 @@ enum {
CROS_EC_CMD_TIMEOUT_MS = 5000,
/* Timeout waiting for a synchronous hash to be recomputed */
CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
+
+ /* Wait 10 ms between attempts to check if EC's hash is ready */
+ CROS_EC_HASH_CHECK_DELAY_MS = 10,
+
};
#define INVALID_HCMD 0xFF
@@ -400,6 +404,8 @@ static int ec_command(struct udevice *dev, uint cmd, int cmd_version,
*/
if (din && in_buffer) {
assert(len <= din_len);
+ if (len > din_len)
+ return -ENOSPC;
memmove(din, in_buffer, len);
}
}
@@ -502,9 +508,10 @@ static int cros_ec_wait_on_hash_done(struct udevice *dev,
start = get_timer(0);
while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
- mdelay(50); /* Insert some reasonable delay */
+ mdelay(CROS_EC_HASH_CHECK_DELAY_MS);
p->cmd = EC_VBOOT_HASH_GET;
+
if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, p, sizeof(*p), hash,
sizeof(*hash)) < 0)
return -1;
@@ -591,6 +598,25 @@ static int cros_ec_invalidate_hash(struct udevice *dev)
return 0;
}
+int cros_ec_hello(struct udevice *dev, uint *handshakep)
+{
+ struct ec_params_hello req;
+ struct ec_response_hello *resp;
+
+ req.in_data = 0x12345678;
+ if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
+ (uint8_t **)&resp, sizeof(*resp)) < 0)
+ return -EIO;
+ if (resp->out_data != req.in_data + 0x01020304) {
+ printf("Received invalid handshake %x\n", resp->out_data);
+ if (handshakep)
+ *handshakep = req.in_data;
+ return -ENOTSYNC;
+ }
+
+ return 0;
+}
+
int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
{
struct ec_params_reboot_ec p;
@@ -603,18 +629,23 @@ int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
return -1;
if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
+ ulong start;
+
/*
* EC reboot will take place immediately so delay to allow it
* to complete. Note that some reboot types (EC_REBOOT_COLD)
* will reboot the AP as well, in which case we won't actually
* get to this point.
*/
- /*
- * TODO(rspangler@chromium.org): Would be nice if we had a
- * better way to determine when the reboot is complete. Could
- * we poll a memory-mapped LPC value?
- */
- udelay(50000);
+ mdelay(50);
+ start = get_timer(0);
+ while (cros_ec_hello(dev, NULL)) {
+ if (get_timer(start) > 3000) {
+ log_err("EC did not return from reboot\n");
+ return -ETIMEDOUT;
+ }
+ mdelay(5);
+ }
}
return 0;
@@ -738,7 +769,6 @@ static int cros_ec_check_version(struct udevice *dev)
{
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
struct ec_params_hello req;
- struct ec_response_hello *resp;
struct dm_cros_ec_ops *ops;
int ret;
@@ -767,14 +797,14 @@ static int cros_ec_check_version(struct udevice *dev)
/* Try sending a version 3 packet */
cdev->protocol_version = 3;
req.in_data = 0;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) > 0)
+ ret = cros_ec_hello(dev, NULL);
+ if (!ret || ret == -ENOTSYNC)
return 0;
/* Try sending a version 2 packet */
cdev->protocol_version = 2;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) > 0)
+ ret = cros_ec_hello(dev, NULL);
+ if (!ret || ret == -ENOTSYNC)
return 0;
/*
@@ -790,18 +820,16 @@ static int cros_ec_check_version(struct udevice *dev)
int cros_ec_test(struct udevice *dev)
{
- struct ec_params_hello req;
- struct ec_response_hello *resp;
+ uint out_data;
+ int ret;
- req.in_data = 0x12345678;
- if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
- (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
+ ret = cros_ec_hello(dev, &out_data);
+ if (ret == -ENOTSYNC) {
+ printf("Received invalid handshake %x\n", out_data);
+ return ret;
+ } else if (ret) {
printf("ec_command_inptr() returned error\n");
- return -1;
- }
- if (resp->out_data != req.in_data + 0x01020304) {
- printf("Received invalid handshake %x\n", resp->out_data);
- return -1;
+ return ret;
}
return 0;
@@ -1077,6 +1105,19 @@ int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
return 0;
}
+int cros_ec_get_sku_id(struct udevice *dev)
+{
+ struct ec_sku_id_info *r;
+ int ret;
+
+ ret = ec_command_inptr(dev, EC_CMD_GET_SKU_ID, 0, NULL, 0,
+ (uint8_t **)&r, sizeof(*r));
+ if (ret != sizeof(*r))
+ return -ret;
+
+ return r->sku_id;
+}
+
int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size)
{
struct ec_params_vbnvcontext p;
@@ -1303,19 +1344,33 @@ int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
return 0;
}
-int cros_ec_check_feature(struct udevice *dev, int feature)
+int cros_ec_get_features(struct udevice *dev, u64 *featuresp)
{
struct ec_response_get_features r;
int rv;
- rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, &r, sizeof(r), NULL, 0);
- if (rv)
- return rv;
+ rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r));
+ if (rv != sizeof(r))
+ return -EIO;
+ *featuresp = r.flags[0] | (u64)r.flags[1] << 32;
+
+ return 0;
+}
+
+int cros_ec_check_feature(struct udevice *dev, uint feature)
+{
+ struct ec_response_get_features r;
+ int rv;
+
+ rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r));
+ if (rv != sizeof(r))
+ return -EIO;
if (feature >= 8 * sizeof(r.flags))
- return -1;
+ return -EINVAL;
- return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature);
+ return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature) ? true :
+ false;
}
/*
@@ -1502,10 +1557,99 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
return 0;
}
+int cros_ec_vstore_supported(struct udevice *dev)
+{
+ return cros_ec_check_feature(dev, EC_FEATURE_VSTORE);
+}
+
+int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp)
+{
+ struct ec_response_vstore_info *resp;
+
+ if (ec_command_inptr(dev, EC_CMD_VSTORE_INFO, 0, NULL, 0,
+ (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+ return -EIO;
+
+ if (lockedp)
+ *lockedp = resp->slot_locked;
+
+ return resp->slot_count;
+}
+
+/*
+ * cros_ec_vstore_read - Read data from EC vstore slot
+ *
+ * @slot: vstore slot to read from
+ * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
+ */
+int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data)
+{
+ struct ec_params_vstore_read req;
+ struct ec_response_vstore_read *resp;
+
+ req.slot = slot;
+ if (ec_command_inptr(dev, EC_CMD_VSTORE_READ, 0, &req, sizeof(req),
+ (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+ return -EIO;
+
+ if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
+ return -EINVAL;
+
+ memcpy(data, resp->data, sizeof(resp->data));
+
+ return 0;
+}
+
+/*
+ * cros_ec_vstore_write - Save data into EC vstore slot
+ *
+ * @slot: vstore slot to write into
+ * @data: data to write
+ * @size: size of data in bytes
+ *
+ * Maximum size of data is EC_VSTORE_SLOT_SIZE. It is the callers
+ * responsibility to check the number of implemented slots by
+ * querying the vstore info.
+ */
+int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data,
+ size_t size)
+{
+ struct ec_params_vstore_write req;
+
+ if (slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
+ return -EINVAL;
+
+ req.slot = slot;
+ memcpy(req.data, data, size);
+
+ if (ec_command(dev, EC_CMD_VSTORE_WRITE, 0, &req, sizeof(req), NULL, 0))
+ return -EIO;
+
+ return 0;
+}
+
+int cros_ec_get_switches(struct udevice *dev)
+{
+ struct dm_cros_ec_ops *ops;
+ int ret;
+
+ ops = dm_cros_ec_get_ops(dev);
+ if (!ops->get_switches)
+ return -ENOSYS;
+
+ ret = ops->get_switches(dev);
+ if (ret < 0)
+ return log_msg_ret("get", ret);
+
+ return ret;
+}
+
UCLASS_DRIVER(cros_ec) = {
.id = UCLASS_CROS_EC,
.name = "cros-ec",
.per_device_auto = sizeof(struct cros_ec_dev),
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
.post_bind = dm_scan_fdt_dev,
+#endif
.flags = DM_UC_FLAG_ALLOC_PRIV_DMA,
};
diff --git a/drivers/misc/cros_ec_lpc.c b/drivers/misc/cros_ec_lpc.c
index e0002b9753f..f40375978dd 100644
--- a/drivers/misc/cros_ec_lpc.c
+++ b/drivers/misc/cros_ec_lpc.c
@@ -207,6 +207,12 @@ int cros_ec_lpc_init(struct cros_ec_dev *dev, const void *blob)
return 0;
}
+/* Return the byte of EC switch states */
+static int cros_ec_lpc_get_switches(struct udevice *dev)
+{
+ return inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
+}
+
/*
* Test if LPC command args are supported.
*
@@ -239,6 +245,7 @@ static struct dm_cros_ec_ops cros_ec_ops = {
.packet = cros_ec_lpc_packet,
.command = cros_ec_lpc_command,
.check_version = cros_ec_lpc_check_version,
+ .get_switches = cros_ec_lpc_get_switches,
};
static const struct udevice_id cros_ec_ids[] = {
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index 9fd6cc2086c..cb8adc4495a 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -18,6 +18,7 @@
#include <asm/malloc.h>
#include <asm/state.h>
#include <asm/sdl.h>
+#include <asm/test.h>
#include <linux/input.h>
/*
@@ -61,6 +62,15 @@ struct ec_keymatrix_entry {
int keycode; /* corresponding linux key code */
};
+enum {
+ VSTORE_SLOT_COUNT = 4,
+};
+
+struct vstore_slot {
+ bool locked;
+ u8 data[EC_VSTORE_SLOT_SIZE];
+};
+
/**
* struct ec_state - Information about the EC state
*
@@ -73,6 +83,8 @@ struct ec_keymatrix_entry {
* @matrix: Information about keyboard matrix
* @keyscan: Current keyscan information (bit set for each row/column pressed)
* @recovery_req: Keyboard recovery requested
+ * @test_flags: Flags that control behaviour for tests
+ * @slot_locked: Locked vstore slots (mask)
*/
struct ec_state {
u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -84,6 +96,8 @@ struct ec_state {
struct ec_keymatrix_entry *matrix; /* the key matrix info */
uint8_t keyscan[KEYBOARD_COLS];
bool recovery_req;
+ uint test_flags;
+ struct vstore_slot slot[VSTORE_SLOT_COUNT];
} s_state, *g_state;
/**
@@ -295,6 +309,8 @@ static int process_cmd(struct ec_state *ec,
struct ec_response_hello *resp = resp_data;
resp->out_data = req->in_data + 0x01020304;
+ if (ec->test_flags & CROSECT_BREAK_HELLO)
+ resp->out_data++;
len = sizeof(*resp);
break;
}
@@ -358,10 +374,20 @@ static int process_cmd(struct ec_state *ec,
resp->mask |= EC_HOST_EVENT_MASK(
EC_HOST_EVENT_KEYBOARD_RECOVERY);
}
-
+ if (ec->test_flags & CROSECT_LID_OPEN)
+ resp->mask |=
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN);
len = sizeof(*resp);
break;
}
+ case EC_CMD_HOST_EVENT_CLEAR_B: {
+ const struct ec_params_host_event_mask *req = req_data;
+
+ if (req->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN))
+ ec->test_flags &= ~CROSECT_LID_OPEN;
+ len = 0;
+ break;
+ }
case EC_CMD_VBOOT_HASH: {
const struct ec_params_vboot_hash *req = req_data;
struct ec_response_vboot_hash *resp = resp_data;
@@ -468,6 +494,62 @@ static int process_cmd(struct ec_state *ec,
len = sizeof(*resp);
break;
}
+ case EC_CMD_GET_SKU_ID: {
+ struct ec_sku_id_info *resp = resp_data;
+
+ resp->sku_id = 1234;
+ len = sizeof(*resp);
+ break;
+ }
+ case EC_CMD_GET_FEATURES: {
+ struct ec_response_get_features *resp = resp_data;
+
+ resp->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FLASH) |
+ EC_FEATURE_MASK_0(EC_FEATURE_I2C) |
+ EC_FEATURE_MASK_0(EC_FEATURE_VSTORE);
+ resp->flags[1] =
+ EC_FEATURE_MASK_1(EC_FEATURE_UNIFIED_WAKE_MASKS) |
+ EC_FEATURE_MASK_1(EC_FEATURE_ISH);
+ len = sizeof(*resp);
+ break;
+ }
+ case EC_CMD_VSTORE_INFO: {
+ struct ec_response_vstore_info *resp = resp_data;
+ int i;
+
+ resp->slot_count = VSTORE_SLOT_COUNT;
+ resp->slot_locked = 0;
+ for (i = 0; i < VSTORE_SLOT_COUNT; i++) {
+ if (ec->slot[i].locked)
+ resp->slot_locked |= 1 << i;
+ }
+ len = sizeof(*resp);
+ break;
+ };
+ case EC_CMD_VSTORE_WRITE: {
+ const struct ec_params_vstore_write *req = req_data;
+ struct vstore_slot *slot;
+
+ if (req->slot >= EC_VSTORE_SLOT_MAX)
+ return -EINVAL;
+ slot = &ec->slot[req->slot];
+ slot->locked = true;
+ memcpy(slot->data, req->data, EC_VSTORE_SLOT_SIZE);
+ len = 0;
+ break;
+ }
+ case EC_CMD_VSTORE_READ: {
+ const struct ec_params_vstore_read *req = req_data;
+ struct ec_response_vstore_read *resp = resp_data;
+ struct vstore_slot *slot;
+
+ if (req->slot >= EC_VSTORE_SLOT_MAX)
+ return -EINVAL;
+ slot = &ec->slot[req->slot];
+ memcpy(resp->data, slot->data, EC_VSTORE_SLOT_SIZE);
+ len = sizeof(*resp);
+ break;
+ }
default:
printf(" ** Unknown EC command %#02x\n", req_hdr->command);
return -1;
@@ -518,6 +600,21 @@ void cros_ec_check_keyboard(struct udevice *dev)
}
}
+/* Return the byte of EC switch states */
+static int cros_ec_sandbox_get_switches(struct udevice *dev)
+{
+ struct ec_state *ec = dev_get_priv(dev);
+
+ return ec->test_flags & CROSECT_LID_OPEN ? EC_SWITCH_LID_OPEN : 0;
+}
+
+void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
+{
+ struct ec_state *ec = dev_get_priv(dev);
+
+ ec->test_flags = flags;
+}
+
int cros_ec_probe(struct udevice *dev)
{
struct ec_state *ec = dev_get_priv(dev);
@@ -573,6 +670,7 @@ int cros_ec_probe(struct udevice *dev)
struct dm_cros_ec_ops cros_ec_ops = {
.packet = cros_ec_sandbox_packet,
+ .get_switches = cros_ec_sandbox_get_switches,
};
static const struct udevice_id cros_ec_ids[] = {
diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c
index 24130e620bf..2acb8c6efa0 100644
--- a/drivers/mmc/renesas-sdhi.c
+++ b/drivers/mmc/renesas-sdhi.c
@@ -862,6 +862,9 @@ static void renesas_sdhi_filter_caps(struct udevice *dev)
if (!(priv->caps & TMIO_SD_CAP_RCAR_GEN3))
return;
+ if (priv->caps & TMIO_SD_CAP_DMA_INTERNAL)
+ priv->idma_bus_width = TMIO_SD_DMA_MODE_BUS_WIDTH;
+
#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
diff --git a/drivers/mmc/tmio-common.c b/drivers/mmc/tmio-common.c
index 2c528689bd3..6c0c840bbb1 100644
--- a/drivers/mmc/tmio-common.c
+++ b/drivers/mmc/tmio-common.c
@@ -324,6 +324,8 @@ static int tmio_sd_dma_xfer(struct udevice *dev, struct mmc_data *data)
tmp = tmio_sd_readl(priv, TMIO_SD_DMA_MODE);
+ tmp |= priv->idma_bus_width;
+
if (data->flags & MMC_DATA_READ) {
buf = data->dest;
dir = DMA_FROM_DEVICE;
@@ -702,6 +704,7 @@ static void tmio_sd_host_init(struct tmio_sd_priv *priv)
if (priv->caps & TMIO_SD_CAP_DMA_INTERNAL) {
tmp = tmio_sd_readl(priv, TMIO_SD_DMA_MODE);
tmp |= TMIO_SD_DMA_MODE_ADDR_INC;
+ tmp |= priv->idma_bus_width;
tmio_sd_writel(priv, tmp, TMIO_SD_DMA_MODE);
}
}
diff --git a/drivers/mmc/tmio-common.h b/drivers/mmc/tmio-common.h
index 9062300c64f..59d5a0e22e9 100644
--- a/drivers/mmc/tmio-common.h
+++ b/drivers/mmc/tmio-common.h
@@ -90,6 +90,7 @@
#define TMIO_SD_VOLT_180 (2 << 0)/* 1.8V signal */
#define TMIO_SD_DMA_MODE 0x410
#define TMIO_SD_DMA_MODE_DIR_RD BIT(16) /* 1: from device, 0: to dev */
+#define TMIO_SD_DMA_MODE_BUS_WIDTH (BIT(5) | BIT(4)) /* RCar, 64bit */
#define TMIO_SD_DMA_MODE_ADDR_INC BIT(0) /* 1: address inc, 0: fixed */
#define TMIO_SD_DMA_CTL 0x414
#define TMIO_SD_DMA_CTL_START BIT(0) /* start DMA (auto cleared) */
@@ -121,6 +122,7 @@ struct tmio_sd_priv {
unsigned int version;
u32 caps;
u32 read_poll_flag;
+ u32 idma_bus_width;
#define TMIO_SD_CAP_NONREMOVABLE BIT(0) /* Nonremovable e.g. eMMC */
#define TMIO_SD_CAP_DMA_INTERNAL BIT(1) /* have internal DMA engine */
#define TMIO_SD_CAP_DIV1024 BIT(2) /* divisor 1024 is available */
diff --git a/drivers/rtc/i2c_rtc_emul.c b/drivers/rtc/i2c_rtc_emul.c
index 5a2a154e653..f25b976e54d 100644
--- a/drivers/rtc/i2c_rtc_emul.c
+++ b/drivers/rtc/i2c_rtc_emul.c
@@ -57,6 +57,7 @@ long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time,
plat->use_system_time = use_system_time;
if (offset != -1)
plat->offset = offset;
+ os_set_time_offset(plat->offset);
return old_offset;
}
@@ -80,7 +81,7 @@ static void reset_time(struct udevice *dev)
os_localtime(&now);
plat->base_time = rtc_mktime(&now);
- plat->offset = 0;
+ plat->offset = os_get_time_offset();
plat->use_system_time = true;
}
@@ -115,6 +116,7 @@ static int sandbox_i2c_rtc_set(struct udevice *dev, const struct rtc_time *time)
now = plat->base_time;
}
plat->offset = rtc_mktime(time) - now;
+ os_set_time_offset(plat->offset);
return 0;
}
diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index ce61b72d222..b103a6fdc39 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -183,23 +183,31 @@ static int cr50_i2c_write(struct udevice *dev, u8 addr, const u8 *buffer,
return cr50_i2c_wait_tpm_ready(dev);
}
-static inline u8 tpm_access(u8 locality)
+static inline u8 tpm_access(int locality)
{
+ if (locality == -1)
+ locality = 0;
return 0x0 | (locality << 4);
}
-static inline u8 tpm_sts(u8 locality)
+static inline u8 tpm_sts(int locality)
{
+ if (locality == -1)
+ locality = 0;
return 0x1 | (locality << 4);
}
-static inline u8 tpm_data_fifo(u8 locality)
+static inline u8 tpm_data_fifo(int locality)
{
+ if (locality == -1)
+ locality = 0;
return 0x5 | (locality << 4);
}
-static inline u8 tpm_did_vid(u8 locality)
+static inline u8 tpm_did_vid(int locality)
{
+ if (locality == -1)
+ locality = 0;
return 0x6 | (locality << 4);
}
@@ -372,7 +380,6 @@ out_err:
static int cr50_i2c_send(struct udevice *dev, const u8 *buf, size_t len)
{
struct cr50_priv *priv = dev_get_priv(dev);
-
int status;
size_t burstcnt, limit, sent = 0;
u8 tpm_go[4] = { TPM_STS_GO };
@@ -549,9 +556,23 @@ static int cr50_i2c_get_desc(struct udevice *dev, char *buf, int size)
{
struct dm_i2c_chip *chip = dev_get_parent_plat(dev);
struct cr50_priv *priv = dev_get_priv(dev);
+ int len;
+
+ len = snprintf(buf, size, "cr50 TPM 2.0 (i2c %02x id %x), ",
+ chip->chip_addr, priv->vendor >> 16);
+ if (priv->use_irq) {
+ len += snprintf(buf + len, size - len, "irq=%s/%ld",
+ priv->irq.dev->name, priv->irq.id);
+ } else if (dm_gpio_is_valid(&priv->ready_gpio)) {
+ len += snprintf(buf + len, size - len, "gpio=%s/%u",
+ priv->ready_gpio.dev->name,
+ priv->ready_gpio.offset);
+ } else {
+ len += snprintf(buf + len, size - len, "delay=%d",
+ TIMEOUT_NO_IRQ_US);
+ }
- return snprintf(buf, size, "cr50 TPM 2.0 (i2c %02x id %x) irq=%d",
- chip->chip_addr, priv->vendor >> 16, priv->use_irq);
+ return len;
}
static int cr50_i2c_open(struct udevice *dev)
@@ -694,11 +715,12 @@ static int cr50_i2c_probe(struct udevice *dev)
mdelay(10);
}
if (vendor != CR50_DID_VID) {
- log_debug("DID_VID %08x not recognised\n", vendor);
+ log_warning("DID_VID %08x not recognised\n", vendor);
return log_msg_ret("vendor-id", -EXDEV);
}
priv->vendor = vendor;
priv->locality = -1;
+ log_debug("Cr50 ready\n");
return 0;
}
@@ -720,8 +742,8 @@ static const struct udevice_id cr50_i2c_ids[] = {
{ }
};
-U_BOOT_DRIVER(cr50_i2c) = {
- .name = "cr50_i2c",
+U_BOOT_DRIVER(google_cr50) = {
+ .name = "google_cr50",
.id = UCLASS_TPM,
.of_match = cr50_i2c_ids,
.ops = &cr50_i2c_ops,
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 7c0df5c264d..4a3b22e6def 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -98,6 +98,15 @@ config USB_GADGET_DWC2_OTG_PHY_BUS_WIDTH_8
endif # USB_GADGET_DWC2_OTG
+config USB_GADGET_OS_DESCRIPTORS
+ bool "USB OS Feature Descriptors support"
+ help
+ This is a porting patch from linux kernel: 37a3a533429e
+ ("usb: gadget: OS Feature Descriptors support"), the original commit
+ log see below:
+ There is a custom (non-USB IF) extension to the USB standard:
+ http://msdn.microsoft.com/library/windows/hardware/gg463182
+
config CI_UDC
bool "ChipIdea device controller"
select USB_GADGET_DUALSPEED
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index cdb8f6fb3d0..226a9e6d671 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -145,6 +145,7 @@ static struct ci_drv controller = {
.name = "ci_udc",
.ops = &ci_udc_ops,
.is_dualspeed = 1,
+ .max_speed = USB_SPEED_HIGH,
},
};
@@ -335,6 +336,7 @@ static int ci_ep_enable(struct usb_ep *ep,
num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
in = (desc->bEndpointAddress & USB_DIR_IN) != 0;
ci_ep->desc = desc;
+ ep->desc = desc;
if (num) {
int max = get_unaligned_le16(&desc->wMaxPacketSize);
@@ -357,6 +359,7 @@ static int ci_ep_disable(struct usb_ep *ep)
struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep);
ci_ep->desc = NULL;
+ ep->desc = NULL;
return 0;
}
@@ -1015,8 +1018,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
return -EINVAL;
if (!driver->bind || !driver->setup || !driver->disconnect)
return -EINVAL;
- if (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH)
- return -EINVAL;
#if CONFIG_IS_ENABLED(DM_USB)
ret = usb_setup_ehci_gadget(&controller.ctrl);
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 91ed7fcec5a..2a309e624e1 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -12,6 +12,7 @@
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/usb/composite.h>
+#include "u_os_desc.h"
#define USB_BUFSIZ 4096
@@ -19,6 +20,10 @@
typedef struct { __le16 val; } __packed __le16_packed;
static struct usb_composite_driver *composite;
+static struct usb_configuration *os_desc_config;
+
+/* Microsoft OS String Descriptor */
+static char qw_sign_buf[OS_STRING_QW_SIGN_LEN / 2] = {'M', 'S', 'F', 'T', '1', '0', '0'};
static inline void le16_add_cpu_packed(__le16_packed *var, u16 val)
{
@@ -26,6 +31,22 @@ static inline void le16_add_cpu_packed(__le16_packed *var, u16 val)
}
/**
+ * struct usb_os_string - represents OS String to be reported by a gadget
+ * @bLength: total length of the entire descritor, always 0x12
+ * @bDescriptorType: USB_DT_STRING
+ * @qwSignature: the OS String proper
+ * @bMS_VendorCode: code used by the host for subsequent requests
+ * @bPad: not used, must be zero
+ */
+struct usb_os_string {
+ __u8 bLength;
+ __u8 bDescriptorType;
+ __u8 qwSignature[OS_STRING_QW_SIGN_LEN];
+ __u8 bMS_VendorCode;
+ __u8 bPad;
+} __packed;
+
+/**
* usb_add_function() - add a function to a configuration
* @config: the configuration
* @function: the function being added
@@ -67,6 +88,8 @@ int usb_add_function(struct usb_configuration *config,
config->fullspeed = 1;
if (!config->highspeed && function->hs_descriptors)
config->highspeed = 1;
+ if (!config->superspeed && function->ss_descriptors)
+ config->superspeed = 1;
done:
if (value)
@@ -202,7 +225,9 @@ static int config_buf(struct usb_configuration *config,
/* add each function's descriptors */
list_for_each_entry(f, &config->functions, list) {
- if (speed == USB_SPEED_HIGH)
+ if (speed == USB_SPEED_SUPER)
+ descriptors = f->ss_descriptors;
+ else if (speed == USB_SPEED_HIGH)
descriptors = f->hs_descriptors;
else
descriptors = f->descriptors;
@@ -228,8 +253,11 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
u8 type = w_value >> 8;
int hs = 0;
struct usb_configuration *c;
+ struct list_head *pos;
- if (gadget_is_dualspeed(gadget)) {
+ if (gadget_is_superspeed(gadget)) {
+ speed = gadget->speed;
+ } else if (gadget_is_dualspeed(gadget)) {
if (gadget->speed == USB_SPEED_HIGH)
hs = 1;
if (type == USB_DT_OTHER_SPEED_CONFIG)
@@ -239,8 +267,24 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
}
w_value &= 0xff;
- list_for_each_entry(c, &cdev->configs, list) {
- if (speed == USB_SPEED_HIGH) {
+
+ pos = &cdev->configs;
+ c = cdev->os_desc_config;
+ if (c)
+ goto check_config;
+
+ while ((pos = pos->next) != &cdev->configs) {
+ c = list_entry(pos, typeof(*c), list);
+
+ /* skip OS Descriptors config which is handled separately */
+ if (c == cdev->os_desc_config)
+ continue;
+
+check_config:
+ if (speed == USB_SPEED_SUPER) {
+ if (!c->superspeed)
+ continue;
+ } else if (speed == USB_SPEED_HIGH) {
if (!c->highspeed)
continue;
} else {
@@ -259,8 +303,12 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type)
struct usb_gadget *gadget = cdev->gadget;
unsigned count = 0;
int hs = 0;
+ int ss = 0;
struct usb_configuration *c;
+ if (gadget->speed == USB_SPEED_SUPER)
+ ss = 1;
+
if (gadget_is_dualspeed(gadget)) {
if (gadget->speed == USB_SPEED_HIGH)
hs = 1;
@@ -269,7 +317,10 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type)
}
list_for_each_entry(c, &cdev->configs, list) {
/* ignore configs that won't work at this speed */
- if (hs) {
+ if (ss) {
+ if (!c->superspeed)
+ continue;
+ } else if (hs) {
if (!c->highspeed)
continue;
} else {
@@ -353,6 +404,9 @@ static int set_config(struct usb_composite_dev *cdev,
case USB_SPEED_HIGH:
speed = "high";
break;
+ case USB_SPEED_SUPER:
+ speed = "super";
+ break;
default:
speed = "?";
break;
@@ -377,7 +431,9 @@ static int set_config(struct usb_composite_dev *cdev,
* function's setup callback instead of the current
* configuration's setup callback.
*/
- if (gadget->speed == USB_SPEED_HIGH)
+ if (gadget->speed == USB_SPEED_SUPER)
+ descriptors = f->ss_descriptors;
+ else if (gadget->speed == USB_SPEED_HIGH)
descriptors = f->hs_descriptors;
else
descriptors = f->descriptors;
@@ -457,8 +513,9 @@ int usb_add_config(struct usb_composite_dev *cdev,
list_del(&config->list);
config->cdev = NULL;
} else {
- debug("cfg %d/%p speeds:%s%s\n",
+ debug("cfg %d/%p speeds:%s%s%s\n",
config->bConfigurationValue, config,
+ config->superspeed ? " super" : "",
config->highspeed ? " high" : "",
config->fullspeed
? (gadget_is_dualspeed(cdev->gadget)
@@ -475,8 +532,24 @@ int usb_add_config(struct usb_composite_dev *cdev,
}
}
+ /*
+ * If one function of config is not super speed capable,
+ * force the gadget to be high speed so controller driver
+ * can init HW to be USB 2.0
+ */
+ if (gadget_is_superspeed(cdev->gadget)) {
+ list_for_each_entry(f, &config->functions, list) {
+ if (!f->ss_descriptors)
+ cdev->gadget->max_speed =
+ USB_SPEED_HIGH;
+ }
+ }
+
usb_ep_autoconfig_reset(cdev->gadget);
+ os_desc_config = config;
+ cdev->os_desc_config = os_desc_config;
+
done:
if (status)
debug("added config '%s'/%u --> %d\n", config->label,
@@ -577,6 +650,16 @@ static int get_string(struct usb_composite_dev *cdev,
return s->bLength;
}
+ if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) {
+ struct usb_os_string *b = buf;
+ b->bLength = sizeof(*b);
+ b->bDescriptorType = USB_DT_STRING;
+ memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature));
+ b->bMS_VendorCode = cdev->b_vendor_code;
+ b->bPad = 0;
+ return sizeof(*b);
+ }
+
/*
* Otherwise, look up and return a specified string. String IDs
* are device-scoped, so we look up each string table we're told
@@ -703,6 +786,7 @@ static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
static int bos_desc(struct usb_composite_dev *cdev)
{
struct usb_ext_cap_descriptor *usb_ext;
+ struct usb_dcd_config_params dcd_config_params;
struct usb_bos_descriptor *bos = cdev->req->buf;
bos->bLength = USB_DT_BOS_SIZE;
@@ -746,13 +830,173 @@ static int bos_desc(struct usb_composite_dev *cdev)
USB_HIGH_SPEED_OPERATION |
USB_5GBPS_OPERATION);
ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION;
- ss_cap->bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT;
- ss_cap->bU2DevExitLat =
- cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT);
+
+ /* Get Controller configuration */
+ if (cdev->gadget->ops->get_config_params) {
+ cdev->gadget->ops->get_config_params(
+ &dcd_config_params);
+ } else {
+ dcd_config_params.bU1devExitLat =
+ USB_DEFAULT_U1_DEV_EXIT_LAT;
+ dcd_config_params.bU2DevExitLat =
+ cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT);
+ }
+ ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat;
+ ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat;
}
return le16_to_cpu(bos->wTotalLength);
}
+static int count_ext_compat(struct usb_configuration *c)
+{
+ int i, res;
+
+ res = 0;
+ for (i = 0; i < c->next_interface_id; ++i) {
+ struct usb_function *f;
+ int j;
+
+ f = c->interface[i];
+ for (j = 0; j < f->os_desc_n; ++j) {
+ struct usb_os_desc *d;
+
+ if (i != f->os_desc_table[j].if_id)
+ continue;
+ d = f->os_desc_table[j].os_desc;
+ if (d && d->ext_compat_id)
+ ++res;
+ }
+ }
+ BUG_ON(res > 255);
+ return res;
+}
+
+static void fill_ext_compat(struct usb_configuration *c, u8 *buf)
+{
+ int i, count;
+
+ count = 16;
+ for (i = 0; i < c->next_interface_id; ++i) {
+ struct usb_function *f;
+ int j;
+
+ f = c->interface[i];
+ for (j = 0; j < f->os_desc_n; ++j) {
+ struct usb_os_desc *d;
+
+ if (i != f->os_desc_table[j].if_id)
+ continue;
+ d = f->os_desc_table[j].os_desc;
+ if (d && d->ext_compat_id) {
+ *buf++ = i;
+ *buf++ = 0x01;
+ memcpy(buf, d->ext_compat_id, 16);
+ buf += 22;
+ } else {
+ ++buf;
+ *buf = 0x01;
+ buf += 23;
+ }
+ count += 24;
+ if (count >= 4096)
+ return;
+ }
+ }
+}
+
+static int count_ext_prop(struct usb_configuration *c, int interface)
+{
+ struct usb_function *f;
+ int j;
+
+ f = c->interface[interface];
+ for (j = 0; j < f->os_desc_n; ++j) {
+ struct usb_os_desc *d;
+
+ if (interface != f->os_desc_table[j].if_id)
+ continue;
+ d = f->os_desc_table[j].os_desc;
+ if (d && d->ext_compat_id)
+ return d->ext_prop_count;
+ }
+ return 0;
+}
+
+static int len_ext_prop(struct usb_configuration *c, int interface)
+{
+ struct usb_function *f;
+ struct usb_os_desc *d;
+ int j, res;
+
+ res = 10; /* header length */
+ f = c->interface[interface];
+ for (j = 0; j < f->os_desc_n; ++j) {
+ if (interface != f->os_desc_table[j].if_id)
+ continue;
+ d = f->os_desc_table[j].os_desc;
+ if (d)
+ return min(res + d->ext_prop_len, 4096);
+ }
+ return res;
+}
+
+static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf)
+{
+ struct usb_function *f;
+ struct usb_os_desc *d;
+ struct usb_os_desc_ext_prop *ext_prop;
+ int j, count, n, ret;
+ u8 *start = buf;
+
+ f = c->interface[interface];
+ for (j = 0; j < f->os_desc_n; ++j) {
+ if (interface != f->os_desc_table[j].if_id)
+ continue;
+ d = f->os_desc_table[j].os_desc;
+ if (d)
+ list_for_each_entry(ext_prop, &d->ext_prop, entry) {
+ /* 4kB minus header length */
+ n = buf - start;
+ if (n >= 4086)
+ return 0;
+
+ count = ext_prop->data_len +
+ ext_prop->name_len + 14;
+ if (count > 4086 - n)
+ return -EINVAL;
+ usb_ext_prop_put_size(buf, count);
+ usb_ext_prop_put_type(buf, ext_prop->type);
+ ret = usb_ext_prop_put_name(buf, ext_prop->name,
+ ext_prop->name_len);
+ if (ret < 0)
+ return ret;
+ switch (ext_prop->type) {
+ case USB_EXT_PROP_UNICODE:
+ case USB_EXT_PROP_UNICODE_ENV:
+ case USB_EXT_PROP_UNICODE_LINK:
+ usb_ext_prop_put_unicode(buf, ret,
+ ext_prop->data,
+ ext_prop->data_len);
+ break;
+ case USB_EXT_PROP_BINARY:
+ usb_ext_prop_put_binary(buf, ret,
+ ext_prop->data,
+ ext_prop->data_len);
+ break;
+ case USB_EXT_PROP_LE32:
+ /* not implemented */
+ case USB_EXT_PROP_BE32:
+ /* not implemented */
+ default:
+ return -EINVAL;
+ }
+ buf += count;
+ }
+ }
+
+ return 0;
+}
+
/*
* The setup() callback implements all the ep0 functionality that's
* not handled lower down, in hardware or the hardware driver(like
@@ -801,32 +1045,28 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
cdev->desc.bNumConfigurations =
count_configs(cdev, USB_DT_DEVICE);
- /*
- * If the speed is Super speed, then the supported
- * max packet size is 512 and it should be sent as
- * exponent of 2. So, 9(2^9=512) should be filled in
- * bMaxPacketSize0. Also fill USB version as 3.0
- * if speed is Super speed.
- */
- if (cdev->gadget->speed == USB_SPEED_SUPER) {
+ cdev->desc.bMaxPacketSize0 =
+ cdev->gadget->ep0->maxpacket;
+ if (gadget->speed >= USB_SPEED_SUPER) {
+ cdev->desc.bcdUSB = cpu_to_le16(0x0310);
cdev->desc.bMaxPacketSize0 = 9;
- cdev->desc.bcdUSB = cpu_to_le16(0x0300);
} else {
- cdev->desc.bMaxPacketSize0 =
- cdev->gadget->ep0->maxpacket;
+ cdev->desc.bcdUSB = cpu_to_le16(0x0200);
}
value = min(w_length, (u16) sizeof cdev->desc);
memcpy(req->buf, &cdev->desc, value);
break;
case USB_DT_DEVICE_QUALIFIER:
- if (!gadget_is_dualspeed(gadget))
+ if (!gadget_is_dualspeed(gadget) ||
+ gadget->speed >= USB_SPEED_SUPER)
break;
device_qual(cdev);
value = min_t(int, w_length,
sizeof(struct usb_qualifier_descriptor));
break;
case USB_DT_OTHER_SPEED_CONFIG:
- if (!gadget_is_dualspeed(gadget))
+ if (!gadget_is_dualspeed(gadget) ||
+ gadget->speed >= USB_SPEED_SUPER)
break;
case USB_DT_CONFIG:
@@ -841,10 +1081,16 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
value = min(w_length, (u16) value);
break;
case USB_DT_BOS:
- if (gadget_is_superspeed(cdev->gadget))
+ /*
+ * Super speed connection should support BOS, and
+ * USB compliance test (USB 2.0 Command Verifier)
+ * also issues this request, return for now for
+ * USB 2.0 connection.
+ */
+ if (gadget->speed >= USB_SPEED_SUPER) {
value = bos_desc(cdev);
- if (value >= 0)
value = min(w_length, (u16)value);
+ }
break;
default:
goto unknown;
@@ -909,6 +1155,91 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
break;
default:
unknown:
+ /*
+ * OS descriptors handling
+ */
+ if (CONFIG_IS_ENABLED(USB_GADGET_OS_DESCRIPTORS) && cdev->use_os_string &&
+ cdev->os_desc_config && (ctrl->bRequestType & USB_TYPE_VENDOR) &&
+ ctrl->bRequest == cdev->b_vendor_code) {
+ struct usb_configuration *os_desc_cfg;
+ u8 *buf;
+ int interface;
+ int count = 0;
+
+ buf = req->buf;
+ os_desc_cfg = cdev->os_desc_config;
+ memset(buf, 0, w_length);
+ buf[5] = 0x01;
+ switch (ctrl->bRequestType & USB_RECIP_MASK) {
+ case USB_RECIP_DEVICE:
+ if (w_index != 0x4 || (w_value >> 8))
+ break;
+ buf[6] = w_index;
+ if (w_length == 0x10) {
+ /* Number of ext compat interfaces */
+ count = count_ext_compat(os_desc_cfg);
+ buf[8] = count;
+ count *= 24; /* 24 B/ext compat desc */
+ count += 16; /* header */
+ put_unaligned_le32(count, buf);
+ value = w_length;
+ } else {
+ /* "extended compatibility ID"s */
+ count = count_ext_compat(os_desc_cfg);
+ buf[8] = count;
+ count *= 24; /* 24 B/ext compat desc */
+ count += 16; /* header */
+ put_unaligned_le32(count, buf);
+ buf += 16;
+ fill_ext_compat(os_desc_cfg, buf);
+ value = w_length;
+ }
+ break;
+ case USB_RECIP_INTERFACE:
+ if (w_index != 0x5 || (w_value >> 8))
+ break;
+ interface = w_value & 0xFF;
+ buf[6] = w_index;
+ if (w_length == 0x0A) {
+ count = count_ext_prop(os_desc_cfg,
+ interface);
+ put_unaligned_le16(count, buf + 8);
+ count = len_ext_prop(os_desc_cfg,
+ interface);
+ put_unaligned_le32(count, buf);
+
+ value = w_length;
+ } else {
+ count = count_ext_prop(os_desc_cfg,
+ interface);
+ put_unaligned_le16(count, buf + 8);
+ count = len_ext_prop(os_desc_cfg,
+ interface);
+ put_unaligned_le32(count, buf);
+ buf += 10;
+ value = fill_ext_prop(os_desc_cfg,
+ interface, buf);
+ if (value < 0)
+ return value;
+
+ value = w_length;
+ }
+ break;
+ }
+
+ if (value >= 0) {
+ req->length = value;
+ req->zero = value < w_length;
+ value = usb_ep_queue(gadget->ep0, req, GFP_KERNEL);
+ if (value < 0) {
+ debug("ep_queue --> %d\n", value);
+ req->status = 0;
+ composite_setup_complete(gadget->ep0, req);
+ }
+ }
+ return value;
+ }
+
debug("non-core control req%02x.%02x v%04x i%04x l%d\n",
ctrl->bRequestType, ctrl->bRequest,
w_value, w_index, w_length);
@@ -1082,6 +1413,15 @@ static int composite_bind(struct usb_gadget *gadget)
sizeof(struct usb_device_descriptor));
cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
+ if (cdev->use_os_string) {
+ /* TODO: Do we want to pass this via platform? */
+ cdev->b_vendor_code = 0x40;
+
+ /* Microsoft OS String Descriptor */
+ utf8_to_utf16le(qw_sign_buf, (__le16 *)cdev->qw_sign,
+ OS_STRING_QW_SIGN_LEN / 2);
+ }
+
debug("%s: ready\n", composite->name);
return 0;
@@ -1129,7 +1469,7 @@ composite_resume(struct usb_gadget *gadget)
}
static struct usb_gadget_driver composite_driver = {
- .speed = USB_SPEED_HIGH,
+ .speed = USB_SPEED_SUPER,
.bind = composite_bind,
.unbind = composite_unbind,
diff --git a/drivers/usb/gadget/core.c b/drivers/usb/gadget/core.c
index 3781d25fd6d..888f0cfea66 100644
--- a/drivers/usb/gadget/core.c
+++ b/drivers/usb/gadget/core.c
@@ -36,7 +36,7 @@ extern struct usb_function_driver ep0_driver;
int registered_functions;
int registered_devices;
-char *usbd_device_events[] = {
+__maybe_unused static char *usbd_device_events[] = {
"DEVICE_UNKNOWN",
"DEVICE_INIT",
"DEVICE_CREATE",
@@ -56,52 +56,15 @@ char *usbd_device_events[] = {
"DEVICE_FUNCTION_PRIVATE",
};
-char *usbd_device_states[] = {
- "STATE_INIT",
- "STATE_CREATED",
- "STATE_ATTACHED",
- "STATE_POWERED",
- "STATE_DEFAULT",
- "STATE_ADDRESSED",
- "STATE_CONFIGURED",
- "STATE_UNKNOWN",
-};
-
-char *usbd_device_requests[] = {
- "GET STATUS", /* 0 */
- "CLEAR FEATURE", /* 1 */
- "RESERVED", /* 2 */
- "SET FEATURE", /* 3 */
- "RESERVED", /* 4 */
- "SET ADDRESS", /* 5 */
- "GET DESCRIPTOR", /* 6 */
- "SET DESCRIPTOR", /* 7 */
- "GET CONFIGURATION", /* 8 */
- "SET CONFIGURATION", /* 9 */
- "GET INTERFACE", /* 10 */
- "SET INTERFACE", /* 11 */
- "SYNC FRAME", /* 12 */
-};
-
-char *usbd_device_descriptors[] = {
- "UNKNOWN", /* 0 */
- "DEVICE", /* 1 */
- "CONFIG", /* 2 */
- "STRING", /* 3 */
- "INTERFACE", /* 4 */
- "ENDPOINT", /* 5 */
- "DEVICE QUALIFIER", /* 6 */
- "OTHER SPEED", /* 7 */
- "INTERFACE POWER", /* 8 */
-};
-
-char *usbd_device_status[] = {
+__maybe_unused static char *usbd_device_status[] = {
"USBD_OPENING",
"USBD_OK",
"USBD_SUSPENDED",
"USBD_CLOSING",
};
+#define USBD_DEVICE_STATUS(x) (((unsigned int)x <= USBD_CLOSING) ? usbd_device_status[x] : "UNKNOWN")
+
/* Descriptor support functions ************************************************************** */
diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
index 6fabee24ce9..457679f0a4c 100644
--- a/drivers/usb/gadget/ep0.c
+++ b/drivers/usb/gadget/ep0.c
@@ -46,6 +46,52 @@
#define dbg_ep0(lvl,fmt,args...)
#endif
+__maybe_unused static char *usbd_device_descriptors[] = {
+ "UNKNOWN", /* 0 */
+ "DEVICE", /* 1 */
+ "CONFIG", /* 2 */
+ "STRING", /* 3 */
+ "INTERFACE", /* 4 */
+ "ENDPOINT", /* 5 */
+ "DEVICE QUALIFIER", /* 6 */
+ "OTHER SPEED", /* 7 */
+ "INTERFACE POWER", /* 8 */
+};
+
+#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \
+ usbd_device_descriptors[x] : "UNKNOWN")
+
+__maybe_unused static char *usbd_device_states[] = {
+ "STATE_INIT",
+ "STATE_CREATED",
+ "STATE_ATTACHED",
+ "STATE_POWERED",
+ "STATE_DEFAULT",
+ "STATE_ADDRESSED",
+ "STATE_CONFIGURED",
+ "STATE_UNKNOWN",
+};
+
+#define USBD_DEVICE_STATE(x) (((unsigned int)x <= STATE_UNKNOWN) ? usbd_device_states[x] : "UNKNOWN")
+
+__maybe_unused static char *usbd_device_requests[] = {
+ "GET STATUS", /* 0 */
+ "CLEAR FEATURE", /* 1 */
+ "RESERVED", /* 2 */
+ "SET FEATURE", /* 3 */
+ "RESERVED", /* 4 */
+ "SET ADDRESS", /* 5 */
+ "GET DESCRIPTOR", /* 6 */
+ "SET DESCRIPTOR", /* 7 */
+ "GET CONFIGURATION", /* 8 */
+ "SET CONFIGURATION", /* 9 */
+ "GET INTERFACE", /* 10 */
+ "SET INTERFACE", /* 11 */
+ "SYNC FRAME", /* 12 */
+};
+
+#define USBD_DEVICE_REQUESTS(x) (((unsigned int)x <= USB_REQ_SYNCH_FRAME) ? usbd_device_requests[x] : "UNKNOWN")
+
/* EP0 Configuration Set ********************************************************************* */
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index e61fe5d1144..7da334f5d31 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -167,6 +167,10 @@ static int ep_matches(
size = 64;
put_unaligned(cpu_to_le16(size), &desc->wMaxPacketSize);
}
+
+ if (gadget->ops->ep_conf)
+ return gadget->ops->ep_conf(gadget, ep, desc);
+
return 1;
}
@@ -258,6 +262,7 @@ struct usb_ep *usb_ep_autoconfig(
ep = find_ep(gadget, "ep1-bulk");
if (ep && ep_matches(gadget, ep, desc))
return ep;
+#ifndef CONFIG_SPL_BUILD
} else if (gadget_is_dwc3(gadget)) {
const char *name = NULL;
/*
@@ -280,6 +285,7 @@ struct usb_ep *usb_ep_autoconfig(
ep = find_ep(gadget, name);
if (ep && ep_matches(gadget, ep, desc))
return ep;
+#endif
}
if (gadget->ops->match_ep)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index d1d087e12b2..950cc119495 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -46,6 +46,25 @@ struct f_fastboot {
struct usb_request *in_req, *out_req;
};
+static char fb_ext_prop_name[] = "DeviceInterfaceGUID";
+static char fb_ext_prop_data[] = "{4866319A-F4D6-4374-93B9-DC2DEB361BA9}";
+
+static struct usb_os_desc_ext_prop fb_ext_prop = {
+ .type = 1, /* NUL-terminated Unicode String (REG_SZ) */
+ .name = fb_ext_prop_name,
+ .data = fb_ext_prop_data,
+};
+
+/* 16 bytes of "Compatible ID" and "Subcompatible ID" */
+static char fb_cid[16] = {'W', 'I', 'N', 'U', 'S', 'B'};
+static struct usb_os_desc fb_os_desc = {
+ .ext_compat_id = fb_cid,
+};
+
+static struct usb_os_desc_table fb_os_desc_table = {
+ .os_desc = &fb_os_desc,
+};
+
static inline struct f_fastboot *func_to_fastboot(struct usb_function *f)
{
return container_of(f, struct f_fastboot, usb_function);
@@ -109,10 +128,45 @@ static struct usb_descriptor_header *fb_hs_function[] = {
NULL,
};
+/* Super speed */
+static struct usb_endpoint_descriptor ss_ep_in = {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = USB_DIR_IN,
+ .bmAttributes = USB_ENDPOINT_XFER_BULK,
+ .wMaxPacketSize = cpu_to_le16(1024),
+};
+
+static struct usb_endpoint_descriptor ss_ep_out = {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = USB_DIR_OUT,
+ .bmAttributes = USB_ENDPOINT_XFER_BULK,
+ .wMaxPacketSize = cpu_to_le16(1024),
+};
+
+static struct usb_ss_ep_comp_descriptor fb_ss_bulk_comp_desc = {
+ .bLength = sizeof(fb_ss_bulk_comp_desc),
+ .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
+};
+
+static struct usb_descriptor_header *fb_ss_function[] = {
+ (struct usb_descriptor_header *)&interface_desc,
+ (struct usb_descriptor_header *)&ss_ep_in,
+ (struct usb_descriptor_header *)&fb_ss_bulk_comp_desc,
+ (struct usb_descriptor_header *)&ss_ep_out,
+ (struct usb_descriptor_header *)&fb_ss_bulk_comp_desc,
+ NULL,
+};
+
static struct usb_endpoint_descriptor *
fb_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
- struct usb_endpoint_descriptor *hs)
+ struct usb_endpoint_descriptor *hs,
+ struct usb_endpoint_descriptor *ss)
{
+ if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER)
+ return ss;
+
if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
return hs;
return fs;
@@ -161,6 +215,19 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
return id;
interface_desc.bInterfaceNumber = id;
+ /* Enable OS and Extended Properties Feature Descriptor */
+ c->cdev->use_os_string = 1;
+ f->os_desc_table = &fb_os_desc_table;
+ f->os_desc_n = 1;
+ f->os_desc_table->if_id = id;
+ INIT_LIST_HEAD(&fb_os_desc.ext_prop);
+ fb_ext_prop.name_len = strlen(fb_ext_prop.name) * 2 + 2;
+ fb_os_desc.ext_prop_len = 10 + fb_ext_prop.name_len;
+ fb_os_desc.ext_prop_count = 1;
+ fb_ext_prop.data_len = strlen(fb_ext_prop.data) * 2 + 2;
+ fb_os_desc.ext_prop_len += fb_ext_prop.data_len + 4;
+ list_add_tail(&fb_ext_prop.entry, &fb_os_desc.ext_prop);
+
id = usb_string_id(c->cdev);
if (id < 0)
return id;
@@ -187,6 +254,12 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
f->hs_descriptors = fb_hs_function;
}
+ if (gadget_is_superspeed(gadget)) {
+ ss_ep_in.bEndpointAddress = fs_ep_in.bEndpointAddress;
+ ss_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress;
+ f->ss_descriptors = fb_ss_function;
+ }
+
s = env_get("serial#");
if (s)
g_dnl_set_serialnumber((char *)s);
@@ -196,6 +269,8 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
static void fastboot_unbind(struct usb_configuration *c, struct usb_function *f)
{
+ f->os_desc_table = NULL;
+ list_del(&fb_os_desc.ext_prop);
memset(fastboot_func, 0, sizeof(*fastboot_func));
}
@@ -249,7 +324,7 @@ static int fastboot_set_alt(struct usb_function *f,
debug("%s: func: %s intf: %d alt: %d\n",
__func__, f->name, interface, alt);
- d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out);
+ d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out, &ss_ep_out);
ret = usb_ep_enable(f_fb->out_ep, d);
if (ret) {
puts("failed to enable out ep\n");
@@ -264,7 +339,7 @@ static int fastboot_set_alt(struct usb_function *f,
}
f_fb->out_req->complete = rx_handler_command;
- d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in);
+ d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in, &ss_ep_in);
ret = usb_ep_enable(f_fb->in_ep, d);
if (ret) {
puts("failed to enable in ep\n");
@@ -315,7 +390,7 @@ static int fastboot_add(struct usb_configuration *c)
status = usb_add_function(c, &f_fb->usb_function);
if (status) {
free(f_fb);
- fastboot_func = f_fb;
+ fastboot_func = NULL;
}
return status;
@@ -352,7 +427,7 @@ static unsigned int rx_bytes_expected(struct usb_ep *ep)
{
int rx_remain = fastboot_data_remaining();
unsigned int rem;
- unsigned int maxpacket = ep->maxpacket;
+ unsigned int maxpacket = usb_endpoint_maxp(ep->desc);
if (rx_remain <= 0)
return 0;
diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c
index 9ae02ae78c1..bd846ce9a77 100644
--- a/drivers/usb/gadget/f_rockusb.c
+++ b/drivers/usb/gadget/f_rockusb.c
@@ -110,7 +110,7 @@ struct f_rockusb *get_rkusb(void)
if (!f_rkusb) {
f_rkusb = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_rkusb));
if (!f_rkusb)
- return 0;
+ return NULL;
rockusb_func = f_rkusb;
memset(f_rkusb, 0, sizeof(*f_rkusb));
@@ -120,7 +120,7 @@ struct f_rockusb *get_rkusb(void)
f_rkusb->buf_head = memalign(CONFIG_SYS_CACHELINE_SIZE,
RKUSB_BUF_SIZE);
if (!f_rkusb->buf_head)
- return 0;
+ return NULL;
f_rkusb->buf = f_rkusb->buf_head;
memset(f_rkusb->buf_head, 0, RKUSB_BUF_SIZE);
@@ -309,8 +309,9 @@ static int rockusb_add(struct usb_configuration *c)
status = usb_add_function(c, &f_rkusb->usb_function);
if (status) {
+ free(f_rkusb->buf_head);
free(f_rkusb);
- rockusb_func = f_rkusb;
+ rockusb_func = NULL;
}
return status;
}
diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
index 88fc87f2e90..47ef55b2fd3 100644
--- a/drivers/usb/gadget/f_thor.c
+++ b/drivers/usb/gadget/f_thor.c
@@ -30,6 +30,7 @@
#include <linux/usb/cdc.h>
#include <g_dnl.h>
#include <dfu.h>
+#include <thor.h>
#include "f_thor.h"
@@ -266,8 +267,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
switch (rqt->rqt_data) {
case RQT_DL_INIT:
- thor_file_size = (unsigned long long int)rqt->int_data[0] +
- (((unsigned long long int)rqt->int_data[1])
+ thor_file_size = (uint64_t)(uint32_t)rqt->int_data[0] +
+ (((uint64_t)(uint32_t)rqt->int_data[1])
<< 32);
debug("INIT: total %llu bytes\n", thor_file_size);
break;
@@ -280,8 +281,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
break;
}
- thor_file_size = (unsigned long long int)rqt->int_data[1] +
- (((unsigned long long int)rqt->int_data[2])
+ thor_file_size = (uint64_t)(uint32_t)rqt->int_data[1] +
+ (((uint64_t)(uint32_t)rqt->int_data[2])
<< 32);
memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE);
f_name[F_NAME_BUF_SIZE] = '\0';
@@ -735,6 +736,8 @@ int thor_handle(void)
printf("%s: No data received!\n", __func__);
break;
}
+ if (dfu_reinit_needed)
+ return THOR_DFU_REINIT_NEEDED;
}
return 0;
diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
index 86fdd16b012..afb7b74f305 100644
--- a/drivers/usb/gadget/g_dnl.c
+++ b/drivers/usb/gadget/g_dnl.c
@@ -286,6 +286,7 @@ static struct usb_composite_driver g_dnl_driver = {
.name = NULL,
.dev = &device_desc,
.strings = g_dnl_composite_strings,
+ .max_speed = USB_SPEED_SUPER,
.bind = g_dnl_bind,
.unbind = g_dnl_unbind,
diff --git a/drivers/usb/gadget/u_os_desc.h b/drivers/usb/gadget/u_os_desc.h
new file mode 100644
index 00000000000..4dab4814a36
--- /dev/null
+++ b/drivers/usb/gadget/u_os_desc.h
@@ -0,0 +1,123 @@
+/*
+ * u_os_desc.h
+ *
+ * Utility definitions for "OS Descriptors" support
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com
+ *
+ * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __U_OS_DESC_H__
+#define __U_OS_DESC_H__
+
+#include <linux/utf.h>
+
+#define USB_EXT_PROP_DW_SIZE 0
+#define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4
+#define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8
+#define USB_EXT_PROP_B_PROPERTY_NAME 10
+#define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10
+#define USB_EXT_PROP_B_PROPERTY_DATA 14
+
+#define USB_EXT_PROP_RESERVED 0
+#define USB_EXT_PROP_UNICODE 1
+#define USB_EXT_PROP_UNICODE_ENV 2
+#define USB_EXT_PROP_BINARY 3
+#define USB_EXT_PROP_LE32 4
+#define USB_EXT_PROP_BE32 5
+#define USB_EXT_PROP_UNICODE_LINK 6
+#define USB_EXT_PROP_UNICODE_MULTI 7
+
+static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
+{
+ return buf + offset;
+}
+
+static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
+{
+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
+}
+
+static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
+{
+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
+}
+
+static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
+{
+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
+}
+
+static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
+{
+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
+}
+
+static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
+{
+ return __usb_ext_prop_ptr(buf,
+ USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
+}
+
+static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
+{
+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
+}
+
+static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
+{
+ put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
+}
+
+static inline void usb_ext_prop_put_type(u8 *buf, int type)
+{
+ put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
+}
+
+static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
+{
+ int result;
+
+ put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
+ memset(usb_ext_prop_name_ptr(buf), 0, 2 * strlen(name));
+ result = utf8_to_utf16le(name, (__le16 *)usb_ext_prop_name_ptr(buf),
+ strlen(name));
+ if (result < 0)
+ return result;
+
+ put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
+
+ return pnl;
+}
+
+static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const char *data,
+ int data_len)
+{
+ put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
+ memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len);
+}
+
+static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string,
+ int data_len)
+{
+ int result;
+ put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
+ memset(usb_ext_prop_data_ptr(buf, pnl), 0, 2 * (data_len >> 1));
+ result = utf8_to_utf16le(string, (__le16 *) usb_ext_prop_data_ptr(buf, pnl),
+ data_len >> 1);
+ if (result < 0)
+ return result;
+
+ put_unaligned_le16(0,
+ &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
+
+ return data_len;
+}
+
+#endif /* __U_OS_DESC_H__ */
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index 83cdd8a2595..e2464ad923f 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -10,79 +10,7 @@
#include <linux/errno.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
-
-#include <asm/unaligned.h>
-
-
-static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len)
-{
- int count = 0;
- u8 c;
- u16 uchar;
-
- /*
- * this insists on correct encodings, though not minimal ones.
- * BUT it currently rejects legit 4-byte UTF-8 code points,
- * which need surrogate pairs. (Unicode 3.1 can use them.)
- */
- while (len != 0 && (c = (u8) *s++) != 0) {
- if ((c & 0x80)) {
- /*
- * 2-byte sequence:
- * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
- */
- if ((c & 0xe0) == 0xc0) {
- uchar = (c & 0x1f) << 6;
-
- c = (u8) *s++;
- if ((c & 0xc0) != 0x80)
- goto fail;
- c &= 0x3f;
- uchar |= c;
-
- /*
- * 3-byte sequence (most CJKV characters):
- * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
- */
- } else if ((c & 0xf0) == 0xe0) {
- uchar = (c & 0x0f) << 12;
-
- c = (u8) *s++;
- if ((c & 0xc0) != 0x80)
- goto fail;
- c &= 0x3f;
- uchar |= c << 6;
-
- c = (u8) *s++;
- if ((c & 0xc0) != 0x80)
- goto fail;
- c &= 0x3f;
- uchar |= c;
-
- /* no bogus surrogates */
- if (0xd800 <= uchar && uchar <= 0xdfff)
- goto fail;
-
- /*
- * 4-byte sequence (surrogate pairs, currently rare):
- * 11101110wwwwzzzzyy + 110111yyyyxxxxxx
- * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
- * (uuuuu = wwww + 1)
- * FIXME accept the surrogate code points (only)
- */
- } else
- goto fail;
- } else
- uchar = c;
- put_unaligned_le16(uchar, cp++);
- count++;
- len--;
- }
- return count;
-fail:
- return -1;
-}
-
+#include <linux/utf.h>
/**
* usb_gadget_get_string - fill out a string descriptor