From patchwork Tue May 1 22:21:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mats Karrman X-Patchwork-Id: 10374569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7240160234 for ; Tue, 1 May 2018 22:22:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5541028D52 for ; Tue, 1 May 2018 22:22:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51CDC28D64; Tue, 1 May 2018 22:22:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C6BF28D64 for ; Tue, 1 May 2018 22:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751216AbeEAWVs (ORCPT ); Tue, 1 May 2018 18:21:48 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33313 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750969AbeEAWVm (ORCPT ); Tue, 1 May 2018 18:21:42 -0400 Received: by mail-lf0-f65.google.com with SMTP id m18-v6so18093148lfb.0 for ; Tue, 01 May 2018 15:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sAwQV3BuCRLaFqyA8Udm2c+N3kj5u/OMKKmEd1sbEC0=; b=oD+HTMVQMtaKrimGmIzTIXT32m4HcARzdIw9DVhCL0SHy6OyXpKr9l/GAacrx59osQ 9e/uJrah/tS1UaZiFW4pwgonANIlS2jQ+bg12YLXtozw5Y+nduWL2a/i4/UO7hrTcSEP N3bfFVlq0a6nsMwrvDkfTGlPjBAJOoAhuiFT50U9iVdAxxRRpuJtTTAY14ciZFcMtgKd 4Upfdrsa/lcbaL1chV0yk8IWEQmJedxdMRlKrwLfyfnBdC214kfKNxMnaEwRu3ZX4vFD u5Si90IGfh1MsE9u3FYp9XYvkg1aRS7KJ8u6wSBHh9atLHWdEJqxK3N06aF2Y736hSVy V44g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sAwQV3BuCRLaFqyA8Udm2c+N3kj5u/OMKKmEd1sbEC0=; b=U4hHH70xE2mLMskLy91xYfcycUgjqGHE/P8zUvhCQ5HZklDvJe0Eoz+xOs6k1rIm4o 05QqKC7+Jv3Kp2SrD+DisnAGtmeoEecJwBhoA4H6UECXGSYO2yGDzwMNufk3TzEuwXHA o5leR7GHPKbrxLTw0WRjgsh5ns4IB+do+7Qo1zzBBSJFRcTqPm+9ApcEfqvn8XD3+NYp 4sjguXReNpm300sSx6BAAPlDKa5JPZGo2LiokizsvQflharjSik2B+IVGgCPCuTuIbDQ JFOhF/M5cUS8CKwPNw+HuzIeWxqJXdS/GTsLDKXNODhskHy3NLow/624Cu9w72iNSUNa ktuQ== X-Gm-Message-State: ALQs6tA8FeW1jfuUPtT13g2zjBZlR7NwMS+KgQh+qHtDdm7MXB1U6RvL EQPt0VZF3ZOjsWGUov0WUjg= X-Google-Smtp-Source: AB8JxZrDRbmTBQiUKW3bEJOcpdkwMimLGZHE/4QXPP48SNsHwRGf0B/tMaaJjFhm7XUiMHC5+mE1WA== X-Received: by 2002:a19:c1c9:: with SMTP id r192-v6mr933186lff.108.1525213301180; Tue, 01 May 2018 15:21:41 -0700 (PDT) Received: from matsnb.lan ([195.84.96.49]) by smtp.gmail.com with ESMTPSA id j85-v6sm2196840lfh.5.2018.05.01.15.21.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 May 2018 15:21:40 -0700 (PDT) From: Mats Karrman To: Heikki Krogerus , Hans de Goede , Guenter Roeck , Greg Kroah-Hartman Cc: Rob Herring , linux-usb@vger.kernel.org Subject: [RFC PATCH 5/7] usb: typec: mux: pi3usb30532: Add support for supported mode properties Date: Wed, 2 May 2018 00:21:11 +0200 Message-Id: <1525213273-6103-6-git-send-email-mats.dev.list@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525213273-6103-1-git-send-email-mats.dev.list@gmail.com> References: <1525213273-6103-1-git-send-email-mats.dev.list@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Mats Karrman --- drivers/usb/typec/mux/pi3usb30532.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/mux/pi3usb30532.c b/drivers/usb/typec/mux/pi3usb30532.c index d995883..3e564e6 100644 --- a/drivers/usb/typec/mux/pi3usb30532.c +++ b/drivers/usb/typec/mux/pi3usb30532.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ struct pi3usb30532 { struct mutex lock; /* protects the cached conf register */ struct typec_switch sw; struct typec_mux mux; + u8 mode_support; /* Modes supported by hardware as bit flags */ u8 conf; }; @@ -88,16 +90,19 @@ static int pi3usb30532_mux_set(struct typec_mux *mux, enum typec_mux_mode mode) new_conf = PI3USB30532_CONF_OPEN; break; case TYPEC_MUX_2CH_USBSS: - new_conf = (new_conf & PI3USB30532_CONF_SWAP) | - PI3USB30532_CONF_USB3; + if (pi->mode_support & (0x1 << TYPEC_MUX_2CH_USBSS)) + new_conf = (new_conf & PI3USB30532_CONF_SWAP) | + PI3USB30532_CONF_USB3; break; case TYPEC_MUX_4CH_AM: - new_conf = (new_conf & PI3USB30532_CONF_SWAP) | - PI3USB30532_CONF_4LANE_DP; + if (pi->mode_support & (0x1 << TYPEC_MUX_4CH_AM)) + new_conf = (new_conf & PI3USB30532_CONF_SWAP) | + PI3USB30532_CONF_4LANE_DP; break; case TYPEC_MUX_2CH_USBSS_2CH_AM: - new_conf = (new_conf & PI3USB30532_CONF_SWAP) | - PI3USB30532_CONF_USB3_AND_2LANE_DP; + if (pi->mode_support & (0x1 << TYPEC_MUX_2CH_USBSS_2CH_AM)) + new_conf = (new_conf & PI3USB30532_CONF_SWAP) | + PI3USB30532_CONF_USB3_AND_2LANE_DP; break; } @@ -124,6 +129,18 @@ static int pi3usb30532_probe(struct i2c_client *client) pi->mux.set = pi3usb30532_mux_set; mutex_init(&pi->lock); + if (device_property_present(dev, "have-2ch-usbss")) + pi->mode_support |= 0x1 << TYPEC_MUX_2CH_USBSS; + if (device_property_present(dev, "have-4ch-am")) + pi->mode_support |= 0x1 << TYPEC_MUX_4CH_AM; + if (device_property_present(dev, "have-2ch-usbss-2ch-am")) + pi->mode_support |= 0x1 << TYPEC_MUX_2CH_USBSS_2CH_AM; + + if (!pi->mode_support) { + dev_warn(dev, "No mode support found, assuming full support\n"); + pi->mode_support = (u8)-1; + } + ret = i2c_smbus_read_byte_data(client, PI3USB30532_CONF); if (ret < 0) { dev_err(dev, "Error reading config register %d\n", ret);