cros: Update cros_ec code to use struct udevice

At present we pass around a private pointer to specify the cros_ec device.
With driver model it makes more sense to pass the device. Update the code
to do this.

Signed-off-by: Simon Glass <sjg@chromium.org>
lime2-spi
Simon Glass 6 years ago
parent 5592a633a0
commit 6322a7b63f
  1. 24
      cmd/cros_ec.c
  2. 147
      drivers/misc/cros_ec.c
  3. 4
      drivers/misc/cros_ec_sandbox.c
  4. 6
      drivers/tpm/tpm-uclass.c
  5. 66
      include/cros_ec.h

@ -49,7 +49,7 @@ static int cros_ec_decode_region(int argc, char * const argv[])
* @return 0 for ok, 1 for a usage error or -ve for ec command error * @return 0 for ok, 1 for a usage error or -ve for ec command error
* (negative EC_RES_...) * (negative EC_RES_...)
*/ */
static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc, static int do_read_write(struct udevice *dev, int is_write, int argc,
char * const argv[]) char * const argv[])
{ {
uint32_t offset, size = -1U, region_size; uint32_t offset, size = -1U, region_size;
@ -94,8 +94,7 @@ static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc,
static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{ {
struct cros_ec_dev *dev; struct udevice *dev;
struct udevice *udev;
const char *cmd; const char *cmd;
int ret = 0; int ret = 0;
@ -105,10 +104,10 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
cmd = argv[1]; cmd = argv[1];
if (0 == strcmp("init", cmd)) { if (0 == strcmp("init", cmd)) {
/* Remove any existing device */ /* Remove any existing device */
ret = uclass_find_device(UCLASS_CROS_EC, 0, &udev); ret = uclass_find_device(UCLASS_CROS_EC, 0, &dev);
if (!ret) if (!ret)
device_remove(udev, DM_REMOVE_NORMAL); device_remove(dev, DM_REMOVE_NORMAL);
ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev); ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev);
if (ret) { if (ret) {
printf("Could not init cros_ec device (err %d)\n", ret); printf("Could not init cros_ec device (err %d)\n", ret);
return 1; return 1;
@ -116,12 +115,11 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0; return 0;
} }
ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev); ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev);
if (ret) { if (ret) {
printf("Cannot get cros-ec device (err=%d)\n", ret); printf("Cannot get cros-ec device (err=%d)\n", ret);
return 1; return 1;
} }
dev = dev_get_uclass_priv(udev);
if (0 == strcmp("id", cmd)) { if (0 == strcmp("id", cmd)) {
char id[MSG_BYTES]; char id[MSG_BYTES];
@ -262,7 +260,8 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
unsigned long result; unsigned long result;
if (argc <= 2) { if (argc <= 2) {
ret = cros_ec_read_vbnvcontext(dev, block); ret = cros_ec_read_nvdata(dev, block,
EC_VBNV_BLOCK_SIZE);
if (!ret) { if (!ret) {
printf("vbnv_block: "); printf("vbnv_block: ");
for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++)
@ -288,7 +287,8 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
strict_strtoul(buf, 16, &result); strict_strtoul(buf, 16, &result);
block[i] = result; block[i] = result;
} }
ret = cros_ec_write_vbnvcontext(dev, block); ret = cros_ec_write_nvdata(dev, block,
EC_VBNV_BLOCK_SIZE);
} }
if (ret) { if (ret) {
debug("%s: Could not %s VbNvContext\n", __func__, debug("%s: Could not %s VbNvContext\n", __func__,
@ -336,9 +336,9 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
state = simple_strtoul(argv[3], &endp, 10); state = simple_strtoul(argv[3], &endp, 10);
if (*argv[3] == 0 || *endp != 0) if (*argv[3] == 0 || *endp != 0)
return CMD_RET_USAGE; return CMD_RET_USAGE;
ret = cros_ec_set_ldo(udev, index, state); ret = cros_ec_set_ldo(dev, index, state);
} else { } else {
ret = cros_ec_get_ldo(udev, index, &state); ret = cros_ec_get_ldo(dev, index, &state);
if (!ret) { if (!ret) {
printf("LDO%d: %s\n", index, printf("LDO%d: %s\n", index,
state == EC_LDO_STATE_ON ? state == EC_LDO_STATE_ON ?

@ -83,15 +83,15 @@ int cros_ec_calc_checksum(const uint8_t *data, int size)
* @param dout_len Size of output data in bytes * @param dout_len Size of output data in bytes
* @return packet size in bytes, or <0 if error. * @return packet size in bytes, or <0 if error.
*/ */
static int create_proto3_request(struct cros_ec_dev *dev, static int create_proto3_request(struct cros_ec_dev *cdev,
int cmd, int cmd_version, int cmd, int cmd_version,
const void *dout, int dout_len) const void *dout, int dout_len)
{ {
struct ec_host_request *rq = (struct ec_host_request *)dev->dout; struct ec_host_request *rq = (struct ec_host_request *)cdev->dout;
int out_bytes = dout_len + sizeof(*rq); int out_bytes = dout_len + sizeof(*rq);
/* Fail if output size is too big */ /* Fail if output size is too big */
if (out_bytes > (int)sizeof(dev->dout)) { if (out_bytes > (int)sizeof(cdev->dout)) {
debug("%s: Cannot send %d bytes\n", __func__, dout_len); debug("%s: Cannot send %d bytes\n", __func__, dout_len);
return -EC_RES_REQUEST_TRUNCATED; return -EC_RES_REQUEST_TRUNCATED;
} }
@ -108,9 +108,9 @@ static int create_proto3_request(struct cros_ec_dev *dev,
memcpy(rq + 1, dout, dout_len); memcpy(rq + 1, dout, dout_len);
/* Write checksum field so the entire packet sums to 0 */ /* Write checksum field so the entire packet sums to 0 */
rq->checksum = (uint8_t)(-cros_ec_calc_checksum(dev->dout, out_bytes)); rq->checksum = (uint8_t)(-cros_ec_calc_checksum(cdev->dout, out_bytes));
cros_ec_dump_data("out", cmd, dev->dout, out_bytes); cros_ec_dump_data("out", cmd, cdev->dout, out_bytes);
/* Return size of request packet */ /* Return size of request packet */
return out_bytes; return out_bytes;
@ -123,12 +123,12 @@ static int create_proto3_request(struct cros_ec_dev *dev,
* @param din_len Maximum size of response in bytes * @param din_len Maximum size of response in bytes
* @return maximum expected number of bytes in response, or <0 if error. * @return maximum expected number of bytes in response, or <0 if error.
*/ */
static int prepare_proto3_response_buffer(struct cros_ec_dev *dev, int din_len) static int prepare_proto3_response_buffer(struct cros_ec_dev *cdev, int din_len)
{ {
int in_bytes = din_len + sizeof(struct ec_host_response); int in_bytes = din_len + sizeof(struct ec_host_response);
/* Fail if input size is too big */ /* Fail if input size is too big */
if (in_bytes > (int)sizeof(dev->din)) { if (in_bytes > (int)sizeof(cdev->din)) {
debug("%s: Cannot receive %d bytes\n", __func__, din_len); debug("%s: Cannot receive %d bytes\n", __func__, din_len);
return -EC_RES_RESPONSE_TOO_BIG; return -EC_RES_RESPONSE_TOO_BIG;
} }
@ -197,7 +197,7 @@ static int handle_proto3_response(struct cros_ec_dev *dev,
return rs->data_len; return rs->data_len;
} }
static int send_command_proto3(struct cros_ec_dev *dev, static int send_command_proto3(struct cros_ec_dev *cdev,
int cmd, int cmd_version, int cmd, int cmd_version,
const void *dout, int dout_len, const void *dout, int dout_len,
uint8_t **dinp, int din_len) uint8_t **dinp, int din_len)
@ -207,23 +207,24 @@ static int send_command_proto3(struct cros_ec_dev *dev,
int rv; int rv;
/* Create request packet */ /* Create request packet */
out_bytes = create_proto3_request(dev, cmd, cmd_version, out_bytes = create_proto3_request(cdev, cmd, cmd_version,
dout, dout_len); dout, dout_len);
if (out_bytes < 0) if (out_bytes < 0)
return out_bytes; return out_bytes;
/* Prepare response buffer */ /* Prepare response buffer */
in_bytes = prepare_proto3_response_buffer(dev, din_len); in_bytes = prepare_proto3_response_buffer(cdev, din_len);
if (in_bytes < 0) if (in_bytes < 0)
return in_bytes; return in_bytes;
ops = dm_cros_ec_get_ops(dev->dev); ops = dm_cros_ec_get_ops(cdev->dev);
rv = ops->packet ? ops->packet(dev->dev, out_bytes, in_bytes) : -ENOSYS; rv = ops->packet ? ops->packet(cdev->dev, out_bytes, in_bytes) :
-ENOSYS;
if (rv < 0) if (rv < 0)
return rv; return rv;
/* Process the response */ /* Process the response */
return handle_proto3_response(dev, dinp, din_len); return handle_proto3_response(cdev, dinp, din_len);
} }
static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
@ -262,15 +263,16 @@ static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
* @param din_len Maximum size of response in bytes * @param din_len Maximum size of response in bytes
* @return number of bytes in response, or -ve on error * @return number of bytes in response, or -ve on error
*/ */
static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd, static int ec_command_inptr(struct udevice *dev, uint8_t cmd,
int cmd_version, const void *dout, int dout_len, int cmd_version, const void *dout, int dout_len,
uint8_t **dinp, int din_len) uint8_t **dinp, int din_len)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
uint8_t *din = NULL; uint8_t *din = NULL;
int len; int len;
len = send_command(dev, cmd, cmd_version, dout, dout_len, len = send_command(cdev, cmd, cmd_version, dout, dout_len, &din,
&din, din_len); din_len);
/* If the command doesn't complete, wait a while */ /* If the command doesn't complete, wait a while */
if (len == -EC_RES_IN_PROGRESS) { if (len == -EC_RES_IN_PROGRESS) {
@ -283,9 +285,9 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
int ret; int ret;
mdelay(50); /* Insert some reasonable delay */ mdelay(50); /* Insert some reasonable delay */
ret = send_command(dev, EC_CMD_GET_COMMS_STATUS, 0, ret = send_command(cdev, EC_CMD_GET_COMMS_STATUS, 0,
NULL, 0, NULL, 0,
(uint8_t **)&resp, sizeof(*resp)); (uint8_t **)&resp, sizeof(*resp));
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -298,8 +300,8 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
/* OK it completed, so read the status response */ /* OK it completed, so read the status response */
/* not sure why it was 0 for the last argument */ /* not sure why it was 0 for the last argument */
len = send_command(dev, EC_CMD_RESEND_RESPONSE, 0, len = send_command(cdev, EC_CMD_RESEND_RESPONSE, 0, NULL, 0,
NULL, 0, &din, din_len); &din, din_len);
} }
debug("%s: len=%d, din=%p\n", __func__, len, din); debug("%s: len=%d, din=%p\n", __func__, len, din);
@ -328,7 +330,7 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
* @param din_len Maximum size of response in bytes * @param din_len Maximum size of response in bytes
* @return number of bytes in response, or -ve on error * @return number of bytes in response, or -ve on error
*/ */
static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, static int ec_command(struct udevice *dev, uint8_t cmd, int cmd_version,
const void *dout, int dout_len, const void *dout, int dout_len,
void *din, int din_len) void *din, int din_len)
{ {
@ -337,7 +339,7 @@ static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
assert((din_len == 0) || din); assert((din_len == 0) || din);
len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len, len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len,
&in_buffer, din_len); &in_buffer, din_len);
if (len > 0) { if (len > 0) {
/* /*
* If we were asked to put it somewhere, do so, otherwise just * If we were asked to put it somewhere, do so, otherwise just
@ -353,16 +355,14 @@ static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan) int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev); if (ec_command(dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
if (ec_command(cdev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
sizeof(scan->data)) != sizeof(scan->data)) sizeof(scan->data)) != sizeof(scan->data))
return -1; return -1;
return 0; return 0;
} }
int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen) int cros_ec_read_id(struct udevice *dev, char *id, int maxlen)
{ {
struct ec_response_get_version *r; struct ec_response_get_version *r;
@ -388,8 +388,8 @@ int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen)
return 0; return 0;
} }
int cros_ec_read_version(struct cros_ec_dev *dev, int cros_ec_read_version(struct udevice *dev,
struct ec_response_get_version **versionp) struct ec_response_get_version **versionp)
{ {
if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0, if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
(uint8_t **)versionp, sizeof(**versionp)) (uint8_t **)versionp, sizeof(**versionp))
@ -399,7 +399,7 @@ int cros_ec_read_version(struct cros_ec_dev *dev,
return 0; return 0;
} }
int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp) int cros_ec_read_build_info(struct udevice *dev, char **strp)
{ {
if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0, if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0,
(uint8_t **)strp, EC_PROTO2_MAX_PARAM_SIZE) < 0) (uint8_t **)strp, EC_PROTO2_MAX_PARAM_SIZE) < 0)
@ -408,7 +408,7 @@ int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp)
return 0; return 0;
} }
int cros_ec_read_current_image(struct cros_ec_dev *dev, int cros_ec_read_current_image(struct udevice *dev,
enum ec_current_image *image) enum ec_current_image *image)
{ {
struct ec_response_get_version *r; struct ec_response_get_version *r;
@ -421,7 +421,7 @@ int cros_ec_read_current_image(struct cros_ec_dev *dev,
return 0; return 0;
} }
static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev, static int cros_ec_wait_on_hash_done(struct udevice *dev,
struct ec_response_vboot_hash *hash) struct ec_response_vboot_hash *hash)
{ {
struct ec_params_vboot_hash p; struct ec_params_vboot_hash p;
@ -445,8 +445,7 @@ static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev,
} }
int cros_ec_read_hash(struct cros_ec_dev *dev, int cros_ec_read_hash(struct udevice *dev, struct ec_response_vboot_hash *hash)
struct ec_response_vboot_hash *hash)
{ {
struct ec_params_vboot_hash p; struct ec_params_vboot_hash p;
int rv; int rv;
@ -489,7 +488,7 @@ int cros_ec_read_hash(struct cros_ec_dev *dev,
return 0; return 0;
} }
static int cros_ec_invalidate_hash(struct cros_ec_dev *dev) static int cros_ec_invalidate_hash(struct udevice *dev)
{ {
struct ec_params_vboot_hash p; struct ec_params_vboot_hash p;
struct ec_response_vboot_hash *hash; struct ec_response_vboot_hash *hash;
@ -514,8 +513,7 @@ static int cros_ec_invalidate_hash(struct cros_ec_dev *dev)
return 0; return 0;
} }
int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd, int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
uint8_t flags)
{ {
struct ec_params_reboot_ec p; struct ec_params_reboot_ec p;
@ -555,7 +553,7 @@ int cros_ec_interrupt_pending(struct udevice *dev)
return dm_gpio_get_value(&cdev->ec_int); return dm_gpio_get_value(&cdev->ec_int);
} }
int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_mkbp_info *info) int cros_ec_info(struct udevice *dev, struct ec_response_mkbp_info *info)
{ {
if (ec_command(dev, EC_CMD_MKBP_INFO, 0, NULL, 0, info, if (ec_command(dev, EC_CMD_MKBP_INFO, 0, NULL, 0, info,
sizeof(*info)) != sizeof(*info)) sizeof(*info)) != sizeof(*info))
@ -564,7 +562,7 @@ int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_mkbp_info *info)
return 0; return 0;
} }
int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr) int cros_ec_get_host_events(struct udevice *dev, uint32_t *events_ptr)
{ {
struct ec_response_host_event_mask *resp; struct ec_response_host_event_mask *resp;
@ -583,7 +581,7 @@ int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr)
return 0; return 0;
} }
int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events) int cros_ec_clear_host_events(struct udevice *dev, uint32_t events)
{ {
struct ec_params_host_event_mask params; struct ec_params_host_event_mask params;
@ -600,8 +598,8 @@ int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events)
return 0; return 0;
} }
int cros_ec_flash_protect(struct cros_ec_dev *dev, int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
uint32_t set_mask, uint32_t set_flags, uint32_t set_flags,
struct ec_response_flash_protect *resp) struct ec_response_flash_protect *resp)
{ {
struct ec_params_flash_protect params; struct ec_params_flash_protect params;
@ -617,17 +615,18 @@ int cros_ec_flash_protect(struct cros_ec_dev *dev,
return 0; return 0;
} }
static int cros_ec_check_version(struct cros_ec_dev *dev) 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_params_hello req;
struct ec_response_hello *resp; struct ec_response_hello *resp;
struct dm_cros_ec_ops *ops; struct dm_cros_ec_ops *ops;
int ret; int ret;
ops = dm_cros_ec_get_ops(dev->dev); ops = dm_cros_ec_get_ops(dev);
if (ops->check_version) { if (ops->check_version) {
ret = ops->check_version(dev->dev); ret = ops->check_version(dev);
if (ret) if (ret)
return ret; return ret;
} }
@ -647,7 +646,7 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)
*/ */
/* Try sending a version 3 packet */ /* Try sending a version 3 packet */
dev->protocol_version = 3; cdev->protocol_version = 3;
req.in_data = 0; req.in_data = 0;
if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
(uint8_t **)&resp, sizeof(*resp)) > 0) { (uint8_t **)&resp, sizeof(*resp)) > 0) {
@ -655,9 +654,9 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)
} }
/* Try sending a version 2 packet */ /* Try sending a version 2 packet */
dev->protocol_version = 2; cdev->protocol_version = 2;
if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
(uint8_t **)&resp, sizeof(*resp)) > 0) { (uint8_t **)&resp, sizeof(*resp)) > 0) {
return 0; return 0;
} }
@ -667,12 +666,12 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)
* version is no longer supported, and we don't know about any new * version is no longer supported, and we don't know about any new
* protocol versions. * protocol versions.
*/ */
dev->protocol_version = 0; cdev->protocol_version = 0;
printf("%s: ERROR: old EC interface not supported\n", __func__); printf("%s: ERROR: old EC interface not supported\n", __func__);
return -1; return -1;
} }
int cros_ec_test(struct cros_ec_dev *dev) int cros_ec_test(struct udevice *dev)
{ {
struct ec_params_hello req; struct ec_params_hello req;
struct ec_response_hello *resp; struct ec_response_hello *resp;
@ -691,7 +690,7 @@ int cros_ec_test(struct cros_ec_dev *dev)
return 0; return 0;
} }
int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region, int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region,
uint32_t *offset, uint32_t *size) uint32_t *offset, uint32_t *size)
{ {
struct ec_params_flash_region_info p; struct ec_params_flash_region_info p;
@ -713,7 +712,7 @@ int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region,
return 0; return 0;
} }
int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size) int cros_ec_flash_erase(struct udevice *dev, uint32_t offset, uint32_t size)
{ {
struct ec_params_flash_erase p; struct ec_params_flash_erase p;
@ -741,9 +740,8 @@ int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size)
* @param size Number of bytes to write * @param size Number of bytes to write
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
static int cros_ec_flash_write_block(struct cros_ec_dev *dev, static int cros_ec_flash_write_block(struct udevice *dev, const uint8_t *data,
const uint8_t *data, uint32_t offset, uint32_t offset, uint32_t size)
uint32_t size)
{ {
struct ec_params_flash_write *p; struct ec_params_flash_write *p;
int ret; int ret;
@ -768,7 +766,7 @@ static int cros_ec_flash_write_block(struct cros_ec_dev *dev,
/** /**
* Return optimal flash write burst size * Return optimal flash write burst size
*/ */
static int cros_ec_flash_write_burst_size(struct cros_ec_dev *dev) static int cros_ec_flash_write_burst_size(struct udevice *dev)
{ {
return EC_FLASH_WRITE_VER0_SIZE; return EC_FLASH_WRITE_VER0_SIZE;
} }
@ -802,7 +800,7 @@ static int cros_ec_data_is_erased(const uint32_t *data, int size)
* @param dev Pointer to device * @param dev Pointer to device
* @param info Pointer to output flash info struct * @param info Pointer to output flash info struct
*/ */
int cros_ec_read_flashinfo(struct cros_ec_dev *dev, int cros_ec_read_flashinfo(struct udevice *dev,
struct ec_response_flash_info *info) struct ec_response_flash_info *info)
{ {
int ret; int ret;
@ -815,9 +813,10 @@ int cros_ec_read_flashinfo(struct cros_ec_dev *dev,
return ret < sizeof(*info) ? -1 : 0; return ret < sizeof(*info) ? -1 : 0;
} }
int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
uint32_t offset, uint32_t size) uint32_t offset, uint32_t size)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t burst = cros_ec_flash_write_burst_size(dev);
uint32_t end, off; uint32_t end, off;
int ret; int ret;
@ -832,7 +831,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
/* If the data is empty, there is no point in programming it */ /* If the data is empty, there is no point in programming it */
todo = min(end - off, burst); todo = min(end - off, burst);
if (dev->optimise_flash_write && if (cdev->optimise_flash_write &&
cros_ec_data_is_erased((uint32_t *)data, todo)) cros_ec_data_is_erased((uint32_t *)data, todo))
continue; continue;
@ -859,7 +858,7 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
* @param size Number of bytes to read * @param size Number of bytes to read
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data, static int cros_ec_flash_read_block(struct udevice *dev, uint8_t *data,
uint32_t offset, uint32_t size) uint32_t offset, uint32_t size)
{ {
struct ec_params_flash_read p; struct ec_params_flash_read p;
@ -871,7 +870,7 @@ static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data,
&p, sizeof(p), data, size) >= 0 ? 0 : -1; &p, sizeof(p), data, size) >= 0 ? 0 : -1;
} }
int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, int cros_ec_flash_read(struct udevice *dev, uint8_t *data, uint32_t offset,
uint32_t size) uint32_t size)
{ {
uint32_t burst = cros_ec_flash_write_burst_size(dev); uint32_t burst = cros_ec_flash_write_burst_size(dev);
@ -889,7 +888,7 @@ int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
return 0; return 0;
} }
int cros_ec_flash_update_rw(struct cros_ec_dev *dev, const uint8_t *image, int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
int image_size) int image_size)
{ {
uint32_t rw_offset, rw_size; uint32_t rw_offset, rw_size;
@ -928,26 +927,31 @@ int cros_ec_flash_update_rw(struct cros_ec_dev *dev, const uint8_t *image,
return 0; return 0;
} }
int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block) int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size)
{ {
struct ec_params_vbnvcontext p; struct ec_params_vbnvcontext p;
int len; int len;
if (size != EC_VBNV_BLOCK_SIZE)
return -EINVAL;
p.op = EC_VBNV_CONTEXT_OP_READ; p.op = EC_VBNV_CONTEXT_OP_READ;
len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT, len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
&p, sizeof(p), block, EC_VBNV_BLOCK_SIZE); &p, sizeof(p), block, EC_VBNV_BLOCK_SIZE);
if (len < EC_VBNV_BLOCK_SIZE) if (len < EC_VBNV_BLOCK_SIZE)
return -1; return -EIO;
return 0; return 0;
} }
int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block) int cros_ec_write_nvdata(struct udevice *dev, const uint8_t *block, int size)
{ {
struct ec_params_vbnvcontext p; struct ec_params_vbnvcontext p;
int len; int len;
if (size != EC_VBNV_BLOCK_SIZE)
return -EINVAL;
p.op = EC_VBNV_CONTEXT_OP_WRITE; p.op = EC_VBNV_CONTEXT_OP_WRITE;
memcpy(p.block, block, sizeof(p.block)); memcpy(p.block, block, sizeof(p.block));
@ -961,13 +965,12 @@ int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block)
int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state) int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
struct ec_params_ldo_set params; struct ec_params_ldo_set params;
params.index = index; params.index = index;
params.state = state; params.state = state;
if (ec_command_inptr(cdev, EC_CMD_LDO_SET, 0, &params, sizeof(params), if (ec_command_inptr(dev, EC_CMD_LDO_SET, 0, &params, sizeof(params),
NULL, 0)) NULL, 0))
return -1; return -1;
@ -976,13 +979,12 @@ int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state) int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
struct ec_params_ldo_get params; struct ec_params_ldo_get params;
struct ec_response_ldo_get *resp; struct ec_response_ldo_get *resp;
params.index = index; params.index = index;
if (ec_command_inptr(cdev, EC_CMD_LDO_GET, 0, &params, sizeof(params), if (ec_command_inptr(dev, EC_CMD_LDO_GET, 0, &params, sizeof(params),
(uint8_t **)&resp, sizeof(*resp)) != (uint8_t **)&resp, sizeof(*resp)) !=
sizeof(*resp)) sizeof(*resp))
return -1; return -1;
@ -1002,12 +1004,12 @@ int cros_ec_register(struct udevice *dev)
GPIOD_IS_IN); GPIOD_IS_IN);
cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write"); cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write");
if (cros_ec_check_version(cdev)) { if (cros_ec_check_version(dev)) {
debug("%s: Could not detect CROS-EC version\n", __func__); debug("%s: Could not detect CROS-EC version\n", __func__);
return -CROS_EC_ERR_CHECK_VERSION; return -CROS_EC_ERR_CHECK_VERSION;
} }
if (cros_ec_read_id(cdev, id, sizeof(id))) { if (cros_ec_read_id(dev, id, sizeof(id))) {
debug("%s: Could not read KBC ID\n", __func__); debug("%s: Could not read KBC ID\n", __func__);
return -CROS_EC_ERR_READ_ID; return -CROS_EC_ERR_READ_ID;
} }
@ -1063,7 +1065,6 @@ int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)
int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in, int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
int nmsgs) int nmsgs)
{ {
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
union { union {
struct ec_params_i2c_passthru p; struct ec_params_i2c_passthru p;
uint8_t outbuf[EC_PROTO2_MAX_PARAM_SIZE]; uint8_t outbuf[EC_PROTO2_MAX_PARAM_SIZE];
@ -1113,7 +1114,7 @@ int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
} }
} }
rv = ec_command(cdev, EC_CMD_I2C_PASSTHRU, 0, p, pdata - (uint8_t *)p, rv = ec_command(dev, EC_CMD_I2C_PASSTHRU, 0, p, pdata - (uint8_t *)p,
r, sizeof(*r) + read_len); r, sizeof(*r) + read_len);
if (rv < 0) if (rv < 0)
return rv; return rv;

@ -491,9 +491,9 @@ int cros_ec_sandbox_packet(struct udevice *udev, int out_bytes, int in_bytes)
return in_bytes; return in_bytes;
} }
void cros_ec_check_keyboard(struct cros_ec_dev *dev) void cros_ec_check_keyboard(struct udevice *dev)
{ {
struct ec_state *ec = dev_get_priv(dev->dev); struct ec_state *ec = dev_get_priv(dev);
ulong start; ulong start;
printf("Press keys for EC to detect on reset (ESC=recovery)..."); printf("Press keys for EC to detect on reset (ESC=recovery)...");

@ -126,8 +126,8 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
} }
UCLASS_DRIVER(tpm) = { UCLASS_DRIVER(tpm) = {
.id = UCLASS_TPM, .id = UCLASS_TPM,
.name = "tpm", .name = "tpm",
.flags = DM_UC_FLAG_SEQ_ALIAS, .flags = DM_UC_FLAG_SEQ_ALIAS,
.per_device_auto_alloc_size = sizeof(struct tpm_chip_priv), .per_device_auto_alloc_size = sizeof(struct tpm_chip_priv),
}; };

@ -69,7 +69,7 @@ struct fdt_cros_ec {
* @param maxlen Maximum length of the ID field * @param maxlen Maximum length of the ID field
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen); int cros_ec_read_id(struct udevice *dev, char *id, int maxlen);
/** /**
* Read a keyboard scan from the CROS-EC device * Read a keyboard scan from the CROS-EC device
@ -89,8 +89,8 @@ int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan);
* @param image Destination for image identifier * @param image Destination for image identifier
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_read_current_image(struct cros_ec_dev *dev, int cros_ec_read_current_image(struct udevice *dev,
enum ec_current_image *image); enum ec_current_image *image);
/** /**
* Read the hash of the CROS-EC device firmware. * Read the hash of the CROS-EC device firmware.
@ -99,8 +99,7 @@ int cros_ec_read_current_image(struct cros_ec_dev *dev,
* @param hash Destination for hash information * @param hash Destination for hash information
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_read_hash(struct cros_ec_dev *dev, int cros_ec_read_hash(struct udevice *dev, struct ec_response_vboot_hash *hash);
struct ec_response_vboot_hash *hash);
/** /**
* Send a reboot command to the CROS-EC device. * Send a reboot command to the CROS-EC device.
@ -112,8 +111,7 @@ int cros_ec_read_hash(struct cros_ec_dev *dev,
* @param flags Flags for reboot command (EC_REBOOT_FLAG_*) * @param flags Flags for reboot command (EC_REBOOT_FLAG_*)
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd, int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags);
uint8_t flags);
/** /**
* Check if the CROS-EC device has an interrupt pending. * Check if the CROS-EC device has an interrupt pending.
@ -144,7 +142,7 @@ enum {
* expected), -ve if we should have an cros_ec device but failed to find * expected), -ve if we should have an cros_ec device but failed to find
* one, or init failed (-CROS_EC_ERR_...). * one, or init failed (-CROS_EC_ERR_...).
*/ */
int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp); int cros_ec_init(const void *blob, struct udevice**cros_ecp);
/** /**
* Read information about the keyboard matrix * Read information about the keyboard matrix
@ -152,8 +150,7 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp);
* @param dev CROS-EC device * @param dev CROS-EC device
* @param info Place to put the info structure * @param info Place to put the info structure
*/ */
int cros_ec_info(struct cros_ec_dev *dev, int cros_ec_info(struct udevice *dev, struct ec_response_mkbp_info *info);
struct ec_response_mkbp_info *info);
/** /**
* Read the host event flags * Read the host event flags
@ -162,7 +159,7 @@ int cros_ec_info(struct cros_ec_dev *dev,
* @param events_ptr Destination for event flags. Not changed on error. * @param events_ptr Destination for event flags. Not changed on error.
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr); int cros_ec_get_host_events(struct udevice *dev, uint32_t *events_ptr);
/** /**
* Clear the specified host event flags * Clear the specified host event flags
@ -171,7 +168,7 @@ int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr);
* @param events Event flags to clear * @param events Event flags to clear
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events); int cros_ec_clear_host_events(struct udevice *dev, uint32_t events);
/** /**
* Get/set flash protection * Get/set flash protection
@ -184,9 +181,9 @@ int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events);
* @param prot Destination for updated protection state from EC. * @param prot Destination for updated protection state from EC.
* @return 0 if ok, <0 on error * @return 0 if ok, <0 on error
*/ */
int cros_ec_flash_protect(struct cros_ec_dev *dev, int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
uint32_t set_mask, uint32_t set_flags, uint32_t set_flags,
struct ec_response_flash_protect *resp); struct ec_response_flash_protect *resp);
/** /**
@ -195,7 +192,7 @@ int cros_ec_flash_protect(struct cros_ec_dev *dev,
* @param dev CROS-EC device * @param dev CROS-EC device
* @return 0 if ok, <0 if the test failed * @return 0 if ok, <0 if the test failed
*/ */
int cros_ec_test(struct cros_ec_dev *dev); int cros_ec_test(struct udevice *dev);
/** /**
* Update the EC RW copy. * Update the EC RW copy.
@ -205,8 +202,8 @@ int cros_ec_test(struct cros_ec_dev *dev);
* @param imafge_size content length * @param imafge_size content length
* @return 0 if ok, <0 if the test failed * @return 0 if ok, <0 if the test failed
*/ */
int cros_ec_flash_update_rw(struct cros_ec_dev *dev, int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
const uint8_t *image, int image_size); int image_size);
/** /**
* Return a pointer to the board's CROS-EC device * Return a pointer to the board's CROS-EC device
@ -249,8 +246,7 @@ void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len);
*/ */
int cros_ec_calc_checksum(const uint8_t *data, int size); int cros_ec_calc_checksum(const uint8_t *data, int size);
int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, int cros_ec_flash_erase(struct udevice *dev, uint32_t offset, uint32_t size);
uint32_t size);
/** /**
* Read data from the flash * Read data from the flash
@ -267,8 +263,8 @@ int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset,
* @param size Number of bytes to read * @param size Number of bytes to read
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset, int cros_ec_flash_read(struct udevice *dev, uint8_t *data, uint32_t offset,
uint32_t size); uint32_t size);
/** /**
* Read back flash parameters * Read back flash parameters
@ -278,8 +274,8 @@ int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
* @param dev Pointer to device * @param dev Pointer to device
* @param info Pointer to output flash info struct * @param info Pointer to output flash info struct
*/ */
int cros_ec_read_flashinfo(struct cros_ec_dev *dev, int cros_ec_read_flashinfo(struct udevice *dev,
struct ec_response_flash_info *info); struct ec_response_flash_info *info);
/** /**
* Write data to the flash * Write data to the flash
@ -299,8 +295,8 @@ int cros_ec_read_flashinfo(struct cros_ec_dev *dev,
* @param size Number of bytes to write * @param size Number of bytes to write
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data, int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
uint32_t offset, uint32_t size); uint32_t offset, uint32_t size);
/** /**
* Obtain position and size of a flash region * Obtain position and size of a flash region
@ -311,18 +307,18 @@ int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
* @param size Returns size of flash region * @param size Returns size of flash region
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region, int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region,
uint32_t *offset, uint32_t *size); uint32_t *offset, uint32_t *size);
/** /**
* Read/write VbNvContext from/to a CROS-EC device. * Read/write non-volatile data from/to a CROS-EC device.
* *
* @param dev CROS-EC device * @param dev CROS-EC device
* @param block Buffer of VbNvContext to be read/write * @param block Buffer of VbNvContext to be read/write
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block); int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size);
int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block); int cros_ec_write_nvdata(struct udevice *dev, const uint8_t *block, int size);
/** /**
* Read the version information for the EC images * Read the version information for the EC images
@ -331,8 +327,8 @@ int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block);
* @param versionp This is set to point to the version information * @param versionp This is set to point to the version information
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_read_version(struct cros_ec_dev *dev, int cros_ec_read_version(struct udevice *dev,
struct ec_response_get_version **versionp); struct ec_response_get_version **versionp);
/** /**
* Read the build information for the EC * Read the build information for the EC
@ -341,7 +337,7 @@ int cros_ec_read_version(struct cros_ec_dev *dev,
* @param versionp This is set to point to the build string * @param versionp This is set to point to the build string
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp); int cros_ec_read_build_info(struct udevice *dev, char **strp);
/** /**
* Switch on/off a LDO / FET. * Switch on/off a LDO / FET.
@ -387,7 +383,7 @@ int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config);
* *
* @param ec CROS-EC device * @param ec CROS-EC device
*/ */
void cros_ec_check_keyboard(struct cros_ec_dev *dev); void cros_ec_check_keyboard(struct udevice *dev);
struct i2c_msg; struct i2c_msg;
/* /*

Loading…
Cancel
Save