Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756775AbbLAUep (ORCPT ); Tue, 1 Dec 2015 15:34:45 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:33759 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753880AbbLAUeo (ORCPT ); Tue, 1 Dec 2015 15:34:44 -0500 From: Felipe Balbi To: Heikki Krogerus , Chanwoo Choi , Greg Kroah-Hartman CC: MyungJoo Ham , David Cohen , Lu Baolu , Mathias Nyman , , Subject: Re: [PATCH 1/2] extcon: add driver for Intel USB mux In-Reply-To: <1448976758-35807-2-git-send-email-heikki.krogerus@linux.intel.com> References: <1448976758-35807-1-git-send-email-heikki.krogerus@linux.intel.com> <1448976758-35807-2-git-send-email-heikki.krogerus@linux.intel.com> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Tue, 1 Dec 2015 14:34:34 -0600 Message-ID: <87r3j5zz51.fsf@saruman.tx.rr.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5134 Lines: 170 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Heikki Krogerus writes: > Several Intel PCHs and SOCs have an internal mux that is > used to share one USB port between USB Device Controller and > xHCI. The mux is normally handled by System FW/BIOS, but not > always. For those platforms where the FW does not take care > of the mux, this driver is needed. except that this is not exactly a driver. Note that it lacks a module_init() of its own. > diff --git a/drivers/extcon/extcon-intel-usb.c b/drivers/extcon/extcon-in= tel-usb.c > new file mode 100644 > index 0000000..5534781 > --- /dev/null > +++ b/drivers/extcon/extcon-intel-usb.c > @@ -0,0 +1,112 @@ > +/** > + * extcon-intel-usb.c - Driver for Intel USB mux > + * > + * Copyright (C) 2015 Intel Corporation > + * Author: Heikki Krogerus > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > + > +#include > +#include > + > +#include > + > +#define INTEL_MUX_CFG0 0x00 > +#define INTEL_MUX_CFG1 0x04 > + > +#define CFG0_SW_DRD_MODE_MASK 0x3 > +#define CFG0_SW_DRD_DYN 0 > +#define CFG0_SW_DRD_STATIC_HOST 1 > +#define CFG0_SW_DRD_STATIC_DEV 2 > +#define CFG0_SW_SYNC_SS_AND_HS BIT(2) > +#define CFG0_SW_SWITCH_EN BIT(16) > +#define CFG0_SW_IDPIN BIT(20) > +#define CFG0_SW_IDPIN_EN BIT(21) > +#define CFG0_SW_VBUS_VALID BIT(24) > + > +#define CFG1_MODE BIT(29) > + > +struct intel_usb_mux { > + struct notifier_block nb; > + struct extcon_dev edev; > + void __iomem *regs; > + u32 cfg0_ctx; > +}; > + > +static const int intel_mux_cable[] =3D { > + EXTCON_USB_HOST, > + EXTCON_NONE, > +}; > + > +static int intel_usb_mux_notifier(struct notifier_block *nb, > + unsigned long old, void *ptr) > +{ > + struct intel_usb_mux *mux =3D container_of(nb, struct intel_usb_mux, nb= ); > + u32 val; > + > + if (mux->edev.state) > + val =3D CFG0_SW_IDPIN_EN | CFG0_SW_DRD_STATIC_HOST; > + else > + val =3D CFG0_SW_IDPIN_EN | CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID | > + CFG0_SW_DRD_STATIC_DEV; > + > + writel(val, mux->regs); > + return NOTIFY_OK; > +} > + > +struct intel_usb_mux *intel_usb_mux_register(struct device *dev, > + struct resource *r) > +{ > + struct intel_usb_mux *mux; > + int ret; > + > + mux =3D kzalloc(sizeof(*mux), GFP_KERNEL); > + if (!mux) > + return ERR_PTR(-ENOMEM); > + > + mux->regs =3D ioremap_nocache(r->start, resource_size(r)); > + if (!mux->regs) { > + kfree(mux); > + return ERR_PTR(-ENOMEM); > + } > + > + mux->cfg0_ctx =3D readl(mux->regs + INTEL_MUX_CFG0); > + > + mux->edev.dev.parent =3D dev; > + mux->edev.supported_cable =3D intel_mux_cable; > + > + ret =3D extcon_dev_register(&mux->edev); > + if (ret) > + goto err; > + > + mux->edev.name =3D "intel_usb_mux"; > + mux->edev.state =3D !!(readl(mux->regs + INTEL_MUX_CFG1) & CFG1_MODE); > + > + /* An external source needs to tell us what to do */ > + mux->nb.notifier_call =3D intel_usb_mux_notifier; > + ret =3D extcon_register_notifier(&mux->edev, EXTCON_USB_HOST, &mux->nb); > + if (ret) { > + dev_err(&mux->edev.dev, "failed to register notifier\n"); > + extcon_dev_unregister(&mux->edev); > + goto err; > + } > + return mux; > +err: > + iounmap(mux->regs); > + kfree(mux); > + return ERR_PTR(ret); > +} > +EXPORT_SYMBOL_GPL(intel_usb_mux_register); > + > +void intel_usb_mux_unregister(struct intel_usb_mux *mux) > +{ > + extcon_unregister_notifier(&mux->edev, EXTCON_USB_HOST, &mux->nb); > + extcon_dev_unregister(&mux->edev); > + writel(mux->cfg0_ctx, mux->regs + INTEL_MUX_CFG0); > + iounmap(mux->regs); > + kfree(mux); > +} > +EXPORT_SYMBOL_GPL(intel_usb_mux_unregister); so who's gonna call these two functions ? IMO, this looks like a recipe for randbuild breakage. =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWXgRbAAoJEIaOsuA1yqREcTIP/jpzQOEFDwra49Mc+8zLPNoQ g8FvnZpR8E2SaoOrHeZbGH0iNgCyOmPA6Fyub0sdIYs4If4yXHkJIpYhOZY1x4mI +VE+SDgFuv8RhqEIpIjz+vEg2DjWhKbAl2D9rQ/o8O0EJBXHYTVBRnHQMpmBFibd qfLraCECTyzGgCIKmh5Il9rkS/3QOSMbNjzjzrOOHhGyhCwnrwyHiS6E95bqIF70 Eb0IV67TstdjDfVLwZt/spcpxjBYuUv7B26ZzdE2BfYaqidHV9ZgLewn+mKul+Pb KO4XFthOr3R073TeZeiGeiGicPZdiRkh5WYOBsgiUGy3EDL3Xh7B1eUyB2L4hbcO iT0VJegnCmn2NOn2yrwPAUiS6ReGXFLsub/ipbxQ8bozpbySf2WJkTKBBB6B2m2j 1NaA4Pdtc7eQWkpYB7pP945p8QCCBz1RDaS4I0EGei+VxxXyFDYyGt48Wy++bqeE M7mLsi+PBA1JFIG8zu535iYooPUFVT+9u5N3LVwGRrUR+fZucCI0k19Y6d5j0RSJ xU9FRCfyb2ITAdjGaxQ3MHb42b0j8OEN8Q/uVZ837GGV24MqOMXx8Hb6VuXV9892 j7JJuKBE1oG/sFkG0twIvFkscNkt0NoapB7kiGDIG0VKGjE/rH0cm4OISRqp7GRL KKX/AskshA8Psv+SWiHO =odUp -----END PGP SIGNATURE----- --=-=-=-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/