Commit 79a3d603 authored by Gwendal Grignou's avatar Gwendal Grignou Committed by Benson Leung

platform/chrome: Use to_cros_ec_dev more broadly

Move to_cros_ec_dev macro to cros_ec.h and use it when the private ec
object is needed from device object.
Signed-off-by: default avatarGwendal Grignou <gwendal@chromium.org>
Reviewed-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: default avatarBenson Leung <bleung@chromium.org>
parent 683b6473
...@@ -170,8 +170,7 @@ static ssize_t version_show(struct device *dev, ...@@ -170,8 +170,7 @@ static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
uint32_t version = 0, flags = 0; uint32_t version = 0, flags = 0;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
int ret; int ret;
ret = lb_throttle(); ret = lb_throttle();
...@@ -193,8 +192,7 @@ static ssize_t brightness_store(struct device *dev, ...@@ -193,8 +192,7 @@ static ssize_t brightness_store(struct device *dev,
struct cros_ec_command *msg; struct cros_ec_command *msg;
int ret; int ret;
unsigned int val; unsigned int val;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
if (kstrtouint(buf, 0, &val)) if (kstrtouint(buf, 0, &val))
return -EINVAL; return -EINVAL;
...@@ -238,8 +236,7 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr, ...@@ -238,8 +236,7 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
{ {
struct ec_params_lightbar *param; struct ec_params_lightbar *param;
struct cros_ec_command *msg; struct cros_ec_command *msg;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
unsigned int val[4]; unsigned int val[4];
int ret, i = 0, j = 0, ok = 0; int ret, i = 0, j = 0, ok = 0;
...@@ -311,8 +308,7 @@ static ssize_t sequence_show(struct device *dev, ...@@ -311,8 +308,7 @@ static ssize_t sequence_show(struct device *dev,
struct ec_response_lightbar *resp; struct ec_response_lightbar *resp;
struct cros_ec_command *msg; struct cros_ec_command *msg;
int ret; int ret;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
msg = alloc_lightbar_cmd_msg(ec); msg = alloc_lightbar_cmd_msg(ec);
if (!msg) if (!msg)
...@@ -439,8 +435,7 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr, ...@@ -439,8 +435,7 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
struct cros_ec_command *msg; struct cros_ec_command *msg;
unsigned int num; unsigned int num;
int ret, len; int ret, len;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
for (len = 0; len < count; len++) for (len = 0; len < count; len++)
if (!isalnum(buf[len])) if (!isalnum(buf[len]))
...@@ -488,8 +483,7 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr, ...@@ -488,8 +483,7 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
int extra_bytes, max_size, ret; int extra_bytes, max_size, ret;
struct ec_params_lightbar *param; struct ec_params_lightbar *param;
struct cros_ec_command *msg; struct cros_ec_command *msg;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
class_dev);
/* /*
* We might need to reject the program for size reasons. The EC * We might need to reject the program for size reasons. The EC
...@@ -599,8 +593,7 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj, ...@@ -599,8 +593,7 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n) struct attribute *a, int n)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
struct platform_device *pdev = to_platform_device(ec->dev); struct platform_device *pdev = to_platform_device(ec->dev);
struct cros_ec_platform *pdata = pdev->dev.platform_data; struct cros_ec_platform *pdata = pdev->dev.platform_data;
int is_cros_ec; int is_cros_ec;
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
/* Accessor functions */ /* Accessor functions */
static ssize_t reboot_show(struct device *dev, static ssize_t reboot_show(struct device *dev,
......
...@@ -29,8 +29,7 @@ static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj, ...@@ -29,8 +29,7 @@ static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
loff_t pos, size_t count) loff_t pos, size_t count)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
class_dev);
struct cros_ec_device *ecdev = ec->ec_dev; struct cros_ec_device *ecdev = ec->ec_dev;
struct ec_params_vbnvcontext *params; struct ec_params_vbnvcontext *params;
struct cros_ec_command *msg; struct cros_ec_command *msg;
...@@ -70,8 +69,7 @@ static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj, ...@@ -70,8 +69,7 @@ static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj,
loff_t pos, size_t count) loff_t pos, size_t count)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
class_dev);
struct cros_ec_device *ecdev = ec->ec_dev; struct cros_ec_device *ecdev = ec->ec_dev;
struct ec_params_vbnvcontext *params; struct ec_params_vbnvcontext *params;
struct cros_ec_command *msg; struct cros_ec_command *msg;
...@@ -111,8 +109,7 @@ static umode_t cros_ec_vbc_is_visible(struct kobject *kobj, ...@@ -111,8 +109,7 @@ static umode_t cros_ec_vbc_is_visible(struct kobject *kobj,
struct bin_attribute *a, int n) struct bin_attribute *a, int n)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
class_dev);
struct device_node *np = ec->ec_dev->dev->of_node; struct device_node *np = ec->ec_dev->dev->of_node;
if (IS_ENABLED(CONFIG_OF) && np) { if (IS_ENABLED(CONFIG_OF) && np) {
......
...@@ -197,6 +197,8 @@ struct cros_ec_dev { ...@@ -197,6 +197,8 @@ struct cros_ec_dev {
u32 features[2]; u32 features[2];
}; };
#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
/** /**
* cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device * cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment