lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1455281825-23526-8-git-send-email-tomeu.vizoso@collabora.com>
Date:	Fri, 12 Feb 2016 13:57:04 +0100
From:	Tomeu Vizoso <tomeu.vizoso@...labora.com>
To:	linux-kernel@...r.kernel.org
Cc:	Sameer Nanda <snanda@...omium.org>,
	Lee Jones <lee.jones@...aro.org>,
	Benson Leung <bleung@...omium.org>,
	Enric Balletbò <enric.balletbo@...labora.co.uk>,
	Vic Yang <victoryang@...omium.org>,
	Vincent Palatin <vpalatin@...omium.org>,
	Randall Spangler <rspangler@...omium.org>,
	Todd Broch <tbroch@...omium.org>,
	Gwendal Grignou <gwendal@...omium.org>,
	Tomeu Vizoso <tomeu.vizoso@...labora.com>,
	Olof Johansson <olof@...om.net>
Subject: [PATCH v2 7/8] platform/chrome: Register USB PD charger device

Check if a EC considers EC_CMD_USB_PD_PORTS a valid command and register
a USB PD charger device if so. This check is needed for older versions
of the ChromeOS EC firmware that don't support the EC_CMD_GET_FEATURES
command.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@...labora.com>
---

Changes in v2:
- Move cros_ec_usb_pd_charger_register into cros_ec_dev.c

 drivers/platform/chrome/cros_ec_dev.c | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index d45cd254ed1c..a66d52539f3f 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -22,6 +22,7 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/mfd/core.h>
 
 #include "cros_ec_dev.h"
 
@@ -87,6 +88,29 @@ exit:
 	return ret;
 }
 
+static int cros_ec_has_cmd_usb_pd_ports(struct cros_ec_dev *ec)
+{
+	struct cros_ec_command *msg;
+	int ret;
+
+	msg = kmalloc(sizeof(*msg) + sizeof(struct ec_response_usb_pd_ports),
+		      GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	msg->version = 0;
+	msg->command = EC_CMD_USB_PD_PORTS + ec->cmd_offset;
+	msg->insize = sizeof(struct ec_response_usb_pd_ports);
+	msg->outsize = 0;
+
+	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+	ret = ret >= 0 && msg->result == EC_RES_SUCCESS;
+
+	kfree(msg);
+
+	return ret;
+}
+
 /* Device file ops */
 static int ec_device_open(struct inode *inode, struct file *filp)
 {
@@ -217,6 +241,13 @@ static void __remove(struct device *dev)
 	kfree(ec);
 }
 
+static const struct mfd_cell cros_usb_pd_charger_devs[] = {
+	{
+		.name = "cros-usb-pd-charger",
+		.id   = -1,
+	},
+};
+
 static int ec_device_probe(struct platform_device *pdev)
 {
 	int retval = -ENOMEM;
@@ -269,8 +300,21 @@ static int ec_device_probe(struct platform_device *pdev)
 		goto dev_reg_failed;
 	}
 
+	/* check whether this EC instance has the PD charge manager */
+	if (cros_ec_has_cmd_usb_pd_ports(ec)) {
+		retval = mfd_add_devices(dev, 0, cros_usb_pd_charger_devs,
+					 ARRAY_SIZE(cros_usb_pd_charger_devs),
+					 NULL, 0, NULL);
+		if (retval) {
+			dev_err(dev, "failed to add usb-pd-charger device\n");
+			goto pd_reg_failed;
+		}
+	}
+
 	return 0;
 
+pd_reg_failed:
+	put_device(&ec->class_dev);
 dev_reg_failed:
 set_named_failed:
 	dev_set_drvdata(dev, NULL);
-- 
2.5.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ