Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934644AbcCNPqO (ORCPT ); Mon, 14 Mar 2016 11:46:14 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34922 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934547AbcCNPpy (ORCPT ); Mon, 14 Mar 2016 11:45:54 -0400 From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Cc: Sameer Nanda , Javier Martinez Canillas , Lee Jones , Benson Leung , =?UTF-8?q?Enric=20Balletb=C3=B2?= , Vic Yang , Stephen Boyd , Vincent Palatin , Randall Spangler , Todd Broch , Gwendal Grignou , Tomeu Vizoso , Olof Johansson Subject: [PATCH v5 6/6] platform/chrome: Register USB PD charger device Date: Mon, 14 Mar 2016 16:45:01 +0100 Message-Id: <1457970301-24616-7-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457970301-24616-1-git-send-email-tomeu.vizoso@collabora.com> References: <1457970301-24616-1-git-send-email-tomeu.vizoso@collabora.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2632 Lines: 103 Check if a EC has andy PD ports and register a USB PD charger device if so. Signed-off-by: Tomeu Vizoso --- Changes in v5: None Changes in v4: None Changes in v3: - Only register the PD charger device if there are any PD ports in this EC. - Dropped patch using EC_CMD_GET_FEATURES to decide whether to create a charger device because we are now only creating one if a EC has any PD ports. - Dropped patch adding power_supply types because it has been merged already. 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..b1251f4a04c1 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "cros_ec_dev.h" @@ -87,6 +88,30 @@ exit: return ret; } +static int cros_ec_has_usb_pd_ports(struct cros_ec_dev *ec) +{ + struct cros_ec_command *msg; + struct ec_response_usb_pd_ports *resp; + int ret; + + msg = kmalloc(sizeof(*msg) + sizeof(*resp), 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); + resp = (struct ec_response_usb_pd_ports *)msg->data; + ret = ret >= 0 && msg->result == EC_RES_SUCCESS && resp->num_ports; + + kfree(msg); + + return ret; +} + /* Device file ops */ static int ec_device_open(struct inode *inode, struct file *filp) { @@ -217,6 +242,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 +301,20 @@ static int ec_device_probe(struct platform_device *pdev) goto dev_reg_failed; } + if (cros_ec_has_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