From mboxrd@z Thu Jan 1 00:00:00 1970 From: NeilBrown Subject: [PATCH] extcon-gpio: add devicetree support. Date: Fri, 1 Nov 2013 20:50:05 +1100 Message-ID: <20131101205005.659ba606@notabene.brown> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/09MumQEKt8uBs4t8FzqSLgU"; protocol="application/pgp-signature" Return-path: Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: MyungJoo Ham , Chanwoo Choi , Grant Likely Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Belisko Marek , "Dr. H. Nikolaus Schaller" List-Id: devicetree@vger.kernel.org --Sig_/09MumQEKt8uBs4t8FzqSLgU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable As this device is not vendor specific, I haven't included any "vendor," prefixes. For my model I used "regulator-gpio" which takes a similar approach. Signed-off-by: NeilBrown diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt b/Doc= umentation/devicetree/bindings/extcon/extcon-gpio.txt new file mode 100644 index 000000000000..2346b61cc620 --- /dev/null +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt @@ -0,0 +1,26 @@ +* EXTCON detector using GPIO + +Required Properties: + - compatible: "extcon-gpio" + - gpios: gpio line that detects connector + - interrupts: interrupt generated by that gpio + - debounce-delay-ms: debouncing delay + +Optional Properties: + - label: name for connector. If not given, device name is used. + - state-on: string to report when GPIO is high (else '0') + - state-off: string to report when GPIO is low (else '1') + +Example: + +antenna-detect { + compatible =3D "extcon-gpio"; + label =3D "gps_antenna"; + interrupt-parent =3D <&gpio5>; + interrupts =3D <16 IRQ_TYPE_EDGE_BOTH>; + gpios =3D <&gpio5 16 0>; + debounce-delay-ms =3D <10>; + state-on =3D "external"; + state-off =3D "internal"; +}; + diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index f874c30ddbff..a683d2b99213 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include =20 struct gpio_extcon_data { struct extcon_dev edev; @@ -76,6 +79,45 @@ static ssize_t extcon_gpio_print_state(struct extcon_dev= *edev, char *buf) return -EINVAL; } =20 +#ifdef CONFIG_OF +static struct gpio_extcon_platform_data * +gpio_extcon_parse(struct device *dev) +{ + struct gpio_extcon_platform_data *pdata; + struct device_node *np =3D dev->of_node; + u32 num; + int irq; + + if (!np) + return NULL; + pdata =3D devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + pdata->name =3D dev_name(dev); + of_property_read_string(np, "label", &pdata->name); + irq =3D irq_of_parse_and_map(np, 0); + pdata->irq_flags =3D irq_get_trigger_type(irq); + pdata->gpio =3D of_get_named_gpio(np, "gpios", 0); + if (pdata->gpio < 0) + return ERR_PTR(pdata->gpio); + if (irq !=3D gpio_to_irq(pdata->gpio)) { + dev_err(dev, "IRQ doesn't match GPIO\n"); + return ERR_PTR(-EINVAL); + } + if (of_property_read_u32(np, "debounce-delay-ms", &num) =3D=3D 0) + pdata->debounce =3D num; + of_property_read_string(np, "state-on", &pdata->state_on); + of_property_read_string(np, "state-off", &pdata->state_off); + return pdata; +} +#else +static inline struct gpio_extcon_platform_data * +gpio_extcon_parse(struct device *dev) +{ + return NULL; +} +#endif + static int gpio_extcon_probe(struct platform_device *pdev) { struct gpio_extcon_platform_data *pdata =3D pdev->dev.platform_data; @@ -83,7 +125,11 @@ static int gpio_extcon_probe(struct platform_device *pd= ev) int ret =3D 0; =20 if (!pdata) + pdata =3D gpio_extcon_parse(&pdev->dev); + if (!pdata) return -EBUSY; + if (IS_ERR(pdata)) + return PTR_ERR(pdata); if (!pdata->irq_flags) { dev_err(&pdev->dev, "IRQ flag is not specified.\n"); return -EINVAL; @@ -148,12 +194,19 @@ static int gpio_extcon_remove(struct platform_device = *pdev) return 0; } =20 +static const struct of_device_id gpio_extcon_match[] =3D { + { .compatible =3D "extcon-gpio" }, + {} +}; +MODULE_DEVICE_TABLE(of, gpio_extcon_mastch); + static struct platform_driver gpio_extcon_driver =3D { .probe =3D gpio_extcon_probe, .remove =3D gpio_extcon_remove, .driver =3D { .name =3D "extcon-gpio", .owner =3D THIS_MODULE, + .of_match_table =3D gpio_extcon_match, }, }; =20 --Sig_/09MumQEKt8uBs4t8FzqSLgU Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIVAwUBUnN5TTnsnt1WYoG5AQIlFw//VNrXoxkTP8Ju2orYcHY6WANxy1ldYg8s in3WGs/JFb2iVu91RyX+nfWnJ3HpYsQw3qr7U/DDFyfoepBw3ztYN2j2q+qhMqJU 5xyYvQ4XPf+5/74MhjtyGEtce0y+ZwYUBWmy21nw/ib9SgthxNpl4KcU1WpzbvOd wD8vPD12AFqJJwNVfGJBRMWbHjz8RymU3wElG7d//umAtJKR5gfXkRUz48xF+Q2i HEDiCkK+TmrD9nS1UMlt/6algJDpjV3k3PtvdcsVTrzl5fVGyBZFJ8hF2BPv/Ipy wsnb7hVgtcNy9nol12+5z4bhvz3gFTNry1Elq+y0j5mfSyIPGHFojGWhSPOsUmIU qkPuW23kORq7/hH+sYEdCUB6WIeA1VI647tJ6X9RDzTTZccleSJUQPeRUYAeOniO 2fXKMuVLD9VPm2j8GzGvvYLJzIPqeiZVLzG7eMFxM6kayXj55RaVAZXMZ9LrEERV i9aonvwkcHyPT9EJtF0vI7+0uZ/maVgHcW0ovIyUQy9+M4fJU/0X5wot7IU2ldi6 53e8sHUfxBT7ZzhXhgqZkJyXPy8H2j9BBpWMg1dUE1DaBkHZ+OBejKzdI0asSoin bdLF4YYypC6Gk18zDxMbAeRI5tIV/7X8uYnQcoMYWoAdtqEsffomSY1LBG1uABBA qA6BLfx4yRg= =9lMg -----END PGP SIGNATURE----- --Sig_/09MumQEKt8uBs4t8FzqSLgU-- -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html