Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753962AbdFVXnO (ORCPT ); Thu, 22 Jun 2017 19:43:14 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34800 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752714AbdFVXnM (ORCPT ); Thu, 22 Jun 2017 19:43:12 -0400 Date: Thu, 22 Jun 2017 16:43:07 -0700 From: Benson Leung To: Enric Balletbo i Serra Cc: olof@lixom.net, bleung@chromium.org, linux-kernel@vger.kernel.org, lee.jones@linaro.org, Eric Caruso , Guenter Roeck Subject: Re: [PATCH RESEND 10/13] platform/chrome: cros_ec_lightbar - Add lightbar program feature to sysfs Message-ID: <20170622234307.GA126262@decatoncale.mtv.corp.google.com> References: <20170516161319.13257-1-enric.balletbo@collabora.com> <20170516161319.13257-11-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline In-Reply-To: <20170516161319.13257-11-enric.balletbo@collabora.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6680 Lines: 217 --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Enric, On Tue, May 16, 2017 at 06:13:16PM +0200, Enric Balletbo i Serra wrote: > From: Eric Caruso >=20 > Add a program feature so we can upload and run programs for lightbar > sequences. We should be able to use this to shift sequences out of the > EC and save space there. >=20 > $ cat > /sys/devices/.../cros_ec/program > $ echo program > /sys/devices/.../cros_ec/sequence >=20 > Signed-off-by: Eric Caruso > Signed-off-by: Guenter Roeck > Signed-off-by: Enric Balletbo i Serra > Acked-by: Lee Jones Signed-off-by: Benson Leung Applied. > --- > drivers/platform/chrome/cros_ec_lightbar.c | 69 ++++++++++++++++++++++++= +++++- > include/linux/mfd/cros_ec_commands.h | 12 +++++- > 2 files changed, 79 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platfor= m/chrome/cros_ec_lightbar.c > index 8df3d44..2667505 100644 > --- a/drivers/platform/chrome/cros_ec_lightbar.c > +++ b/drivers/platform/chrome/cros_ec_lightbar.c > @@ -295,7 +295,8 @@ static ssize_t led_rgb_store(struct device *dev, stru= ct device_attribute *attr, > =20 > static char const *seqname[] =3D { > "ERROR", "S5", "S3", "S0", "S5S3", "S3S0", > - "S0S3", "S3S5", "STOP", "RUN", "PULSE", "TEST", "KONAMI", > + "S0S3", "S3S5", "STOP", "RUN", "KONAMI", > + "TAP", "PROGRAM", > }; > =20 > static ssize_t sequence_show(struct device *dev, > @@ -390,6 +391,69 @@ static ssize_t sequence_store(struct device *dev, st= ruct device_attribute *attr, > return ret; > } > =20 > +static ssize_t program_store(struct device *dev, struct device_attribute= *attr, > + const char *buf, size_t count) > +{ > + int extra_bytes, max_size, ret; > + struct ec_params_lightbar *param; > + struct cros_ec_command *msg; > + struct cros_ec_dev *ec =3D container_of(dev, struct cros_ec_dev, > + class_dev); > + > + /* > + * We might need to reject the program for size reasons. The EC > + * enforces a maximum program size, but we also don't want to try > + * and send a program that is too big for the protocol. In order > + * to ensure the latter, we also need to ensure we have extra bytes > + * to represent the rest of the packet. > + */ > + extra_bytes =3D sizeof(*param) - sizeof(param->set_program.data); > + max_size =3D min(EC_LB_PROG_LEN, ec->ec_dev->max_request - extra_bytes); > + if (count > max_size) { > + dev_err(dev, "Program is %u bytes, too long to send (max: %u)", > + (unsigned int)count, max_size); > + > + return -EINVAL; > + } > + > + msg =3D alloc_lightbar_cmd_msg(ec); > + if (!msg) > + return -ENOMEM; > + > + ret =3D lb_throttle(); > + if (ret) > + goto exit; > + > + dev_info(dev, "Copying %zu byte program to EC", count); > + > + param =3D (struct ec_params_lightbar *)msg->data; > + param->cmd =3D LIGHTBAR_CMD_SET_PROGRAM; > + > + param->set_program.size =3D count; > + memcpy(param->set_program.data, buf, count); > + > + /* > + * We need to set the message size manually or else it will use > + * EC_LB_PROG_LEN. This might be too long, and the program > + * is unlikely to use all of the space. > + */ > + msg->outsize =3D count + extra_bytes; > + > + ret =3D cros_ec_cmd_xfer(ec->ec_dev, msg); > + if (ret < 0) > + goto exit; > + if (msg->result !=3D EC_RES_SUCCESS) { > + ret =3D -EINVAL; > + goto exit; > + } > + > + ret =3D count; > +exit: > + kfree(msg); > + > + return ret; > +} > + > /* Module initialization */ > =20 > static DEVICE_ATTR_RW(interval_msec); > @@ -397,12 +461,15 @@ static DEVICE_ATTR_RO(version); > static DEVICE_ATTR_WO(brightness); > static DEVICE_ATTR_WO(led_rgb); > static DEVICE_ATTR_RW(sequence); > +static DEVICE_ATTR_WO(program); > + > static struct attribute *__lb_cmds_attrs[] =3D { > &dev_attr_interval_msec.attr, > &dev_attr_version.attr, > &dev_attr_brightness.attr, > &dev_attr_led_rgb.attr, > &dev_attr_sequence.attr, > + &dev_attr_program.attr, > NULL, > }; > =20 > diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cro= s_ec_commands.h > index 1b19e424..dbea580 100644 > --- a/include/linux/mfd/cros_ec_commands.h > +++ b/include/linux/mfd/cros_ec_commands.h > @@ -1162,6 +1162,13 @@ struct lightbar_params_v1 { > struct rgb_s color[8]; /* 0-3 are Google colors */ > } __packed; > =20 > +/* Lightbar program */ > +#define EC_LB_PROG_LEN 192 > +struct lightbar_program { > + uint8_t size; > + uint8_t data[EC_LB_PROG_LEN]; > +}; > + > struct ec_params_lightbar { > uint8_t cmd; /* Command (see enum lightbar_command) */ > union { > @@ -1188,6 +1195,7 @@ struct ec_params_lightbar { > =20 > struct lightbar_params_v0 set_params_v0; > struct lightbar_params_v1 set_params_v1; > + struct lightbar_program set_program; > }; > } __packed; > =20 > @@ -1220,7 +1228,8 @@ struct ec_response_lightbar { > struct { > /* no return params */ > } off, on, init, set_brightness, seq, reg, set_rgb, > - demo, set_params_v0, set_params_v1; > + demo, set_params_v0, set_params_v1, > + set_program; > }; > } __packed; > =20 > @@ -1244,6 +1253,7 @@ enum lightbar_command { > LIGHTBAR_CMD_GET_DEMO =3D 15, > LIGHTBAR_CMD_GET_PARAMS_V1 =3D 16, > LIGHTBAR_CMD_SET_PARAMS_V1 =3D 17, > + LIGHTBAR_CMD_SET_PROGRAM =3D 18, > LIGHTBAR_NUM_CMDS > }; > =20 > --=20 > 2.9.3 >=20 --=20 Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. bleung@google.com Chromium OS Project bleung@chromium.org --9jxsPFA5p3P2qPhR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJZTFYLAAoJEB8J9XsKL+ZYb10QALnMe0AKQ1txcpdHj0NNdR9x Mg/rf9MWj9eo7Z1xFvNjcHb8bVmv8r/coQ7OB8lCTa+SqUIrzTHEqacKfKkK5XEH xXSBbRJ3cCzcGISRS0aXmWSnPViVmgnGemGT0cf5dZKi7Y65vWaB+JYITDeTReZZ p+IWYs27Pq4cWNYAo5KoguDfoImRxUIAffU4+i6Y2li2XUVscrFJ3p7ViNTm7iRA xwIm9JHTt2UywQ4u2FKVWMSrpYNeiv7pAzJGQVmfW3uxyOVCjcwRBkDoQEszqgwc UWoVunJmCg+FKIdEu5+fqoemyDyJAi+H8t8umNeTgWZjCzXRKOTkQJfVPHLVzvEi p8yytayIVj1fGe9wVayyL4hxlkSc4T/3VXgwkRb6F85IjLOfglgt4eEiV43cYXmX NEgN8GwHarDlWv5kNIVU3/7dqHld+JONUUgCDhJuGWgopAL5o2pYYr606L7r2dW2 XDnV0je8GVIrAshIvTgDJC3nFBDO+INUv6kAqx2n5xqu9qo/7QafHXjoz1t6YX/k YwLRLzp+fXT+ZC1bR583UeCehDq32yKQgJ4ZZo3fbyjLEk4ZUbHdAugmb0xop6na gwBYy7tfTymc+1bbLzsHbrsbFBbte1D/lrnYc1P2uNzPrCHDf18Za6vNHWfFTJVJ ZkPfEEAaKvUpwlWey5g4 =VonE -----END PGP SIGNATURE----- --9jxsPFA5p3P2qPhR--