WS cleanup: remove SPACE(s) followed by TAB
[platform/kernel/u-boot.git] / drivers / misc / cros_ec.c
index fd2f2ab..c627c1d 100644 (file)
@@ -414,7 +414,7 @@ static int ec_command(struct udevice *dev, uint cmd, int cmd_version,
 
 int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
 {
-       if (ec_command(dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
+       if (ec_command(dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
                       sizeof(scan->data)) != sizeof(scan->data))
                return -1;
 
@@ -754,17 +754,6 @@ int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
        return 0;
 }
 
-int cros_ec_entering_mode(struct udevice *dev, int mode)
-{
-       int rc;
-
-       rc = ec_command(dev, EC_CMD_ENTERING_MODE, 0, &mode, sizeof(mode),
-                       NULL, 0);
-       if (rc)
-               return -1;
-       return 0;
-}
-
 static int cros_ec_check_version(struct udevice *dev)
 {
        struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
@@ -1170,6 +1159,23 @@ int cros_ec_battery_cutoff(struct udevice *dev, uint8_t flags)
        return 0;
 }
 
+int cros_ec_set_pwm_duty(struct udevice *dev, uint8_t index, uint16_t duty)
+{
+       struct ec_params_pwm_set_duty p;
+       int ret;
+
+       p.duty = duty;
+       p.pwm_type = EC_PWM_TYPE_GENERIC;
+       p.index = index;
+
+       ret = ec_command(dev, EC_CMD_PWM_SET_DUTY, 0, &p, sizeof(p),
+                        NULL, 0);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
 int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
 {
        struct ec_params_ldo_set params;
@@ -1557,10 +1563,116 @@ 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;
+}
+
+int cros_ec_read_batt_charge(struct udevice *dev, uint *chargep)
+{
+       struct ec_params_charge_state req;
+       struct ec_response_charge_state resp;
+       int ret;
+
+       req.cmd = CHARGE_STATE_CMD_GET_STATE;
+       ret = ec_command(dev, EC_CMD_CHARGE_STATE, 0, &req, sizeof(req),
+                        &resp, sizeof(resp));
+       if (ret)
+               return log_msg_ret("read", ret);
+
+       *chargep = resp.get_state.batt_state_of_charge;
+
+       return 0;
+}
+
 UCLASS_DRIVER(cros_ec) = {
        .id             = UCLASS_CROS_EC,
        .name           = "cros-ec",
        .per_device_auto        = sizeof(struct cros_ec_dev),
+#if CONFIG_IS_ENABLED(OF_REAL)
        .post_bind      = dm_scan_fdt_dev,
+#endif
        .flags          = DM_UC_FLAG_ALLOC_PRIV_DMA,
 };