Files
OpenCellular/common/i2c_commands.c
Vic Yang dae19428a6 Fix a bug in I2C host command handler
Signed-off-by: Vic Yang <victoryang@chromium.org>

BUG=none
TEST='ectool i2cread' succeed.

Change-Id: I0639c340b600ff5e07b9c0aa707fe335e90771b5
Reviewed-on: https://gerrit.chromium.org/gerrit/27599
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
2012-07-16 23:10:01 -07:00

57 lines
1.4 KiB
C

/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* I2C host commands for Chrome EC */
#include "host_command.h"
#include "i2c.h"
#include "system.h"
int i2c_command_read(struct host_cmd_handler_args *args)
{
const struct ec_params_i2c_read *p =
(const struct ec_params_i2c_read *)args->params;
struct ec_response_i2c_read *r =
(struct ec_response_i2c_read *)args->response;
int data, rv = -1;
if (system_is_locked())
return EC_RES_ACCESS_DENIED;
if (p->read_size == 16)
rv = i2c_read16(p->port, p->addr, p->offset, &data);
else if (p->read_size == 8)
rv = i2c_read8(p->port, p->addr, p->offset, &data);
if (rv)
return EC_RES_ERROR;
r->data = data;
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_I2C_READ, i2c_command_read, EC_VER_MASK(0));
int i2c_command_write(struct host_cmd_handler_args *args)
{
const struct ec_params_i2c_write *p =
(const struct ec_params_i2c_write *)args->params;
int rv = -1;
if (system_is_locked())
return EC_RES_ACCESS_DENIED;
if (p->write_size == 16)
rv = i2c_write16(p->port, p->addr, p->offset, p->data);
else if (p->write_size == 8)
rv = i2c_write8(p->port, p->addr, p->offset, p->data);
if (rv)
return EC_RES_ERROR;
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_I2C_WRITE, i2c_command_write, EC_VER_MASK(0));