From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752874AbbHJCqN (ORCPT ); Sun, 9 Aug 2015 22:46:13 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:44459 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752360AbbHJCqK (ORCPT ); Sun, 9 Aug 2015 22:46:10 -0400 X-AuditID: cbfee68e-f79c56d000006efb-1f-55c8106861ec Message-id: <55C81068.5030703@samsung.com> Date: Mon, 10 Aug 2015 11:46:00 +0900 From: Chanwoo Choi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-version: 1.0 To: Roger Quadros , lee.jones@linaro.org Cc: sameo@linux.intel.com, myungjoo.ham@samsung.com, tony@atomide.com, nm@ti.com, balbi@ti.com, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection References: <1438002617-15152-1-git-send-email-rogerq@ti.com> <1438002617-15152-2-git-send-email-rogerq@ti.com> <55BB5730.8030600@ti.com> <55BF7D73.1040805@ti.com> <55C46B56.5070107@ti.com> In-reply-to: <55C46B56.5070107@ti.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDIsWRmVeSWpSXmKPExsWyRsSkRDdT4ESowaa9TBYH79db3P96lNHi 8q45bBazl/SzWNxuXMFm8ebHWSaLnkdaFqe7WS32X/Fy4PT49nUSi8eda3vYPOadDPTo27KK 0eP4je1MHp83yQWwRXHZpKTmZJalFunbJXBl3P09i61gRVTFih02DYxbPbsYOTkkBEwkFkz5 zwhhi0lcuLeerYuRi0NIYAWjxP7u/ewwRRNeHAcrEhKYxSgx8bo8RNEDRombx7YygSR4BbQk pu18yQxiswioSsxZ1AFmswHF97+4wQZiiwqESaycfoUFol5Q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jMyrGCVSC5ILipPScw3zUsv1ihNzi0vz0vWS83M3MYKj /ZnUDsaDu9wPMQpwMCrx8DpsPB4qxJpYVlyZe4hRgoNZSYTX7yxQiDclsbIqtSg/vqg0J7X4 EKMpMBAmMkuJJucDE1FeSbyhsYmZkaWRuaGFkbG5kjiv7IbNoUIC6YklqdmpqQWpRTB9TByc Ug2MnisfFE9ka/HpfTTx5GG7ztU/n9qsnfBk/fXVlQ76NQbfPKVM0q8HcD2NPZi8ca35n4hO SYYPcjHbHc4e0wgpmWCxsl0rvFKp7Ur3FoHHO7silsUIZ1YfnVJ241nE86XO74WUo/KXrDsa sDVqo2xgqF/lkVidz0LTD+TctTk0T0dDJe9Zs0KKEktxRqKhFnNRcSIAomftogwDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lee, This patch modified the header file in the MFD directory (include/linux/mfd/palmas.h). After you review this patch, I'll apply it on extcon-next and sent the pull request for Linux 4.3. Thanks, Chanwoo Choi On 08/07/2015 05:24 PM, Roger Quadros wrote: > Hi Lee / Samuel, > > On 03/08/15 17:40, Roger Quadros wrote: >> Some palmas based chip variants do not have OTG based ID logic. >> For these variants we rely on GPIO based USB ID detection. >> >> These chips do have VBUS comparator for VBUS detection so we >> continue to use the old way of detecting VBUS. >> >> Acked-by: Chanwoo Choi >> Signed-off-by: Roger Quadros > > It seems the extcon maintainer Chanwoo needs either of your Ack > to accept this patch. > > Can you please take a look and Ack if OK? Thanks. > > cheers, > -roger > >> --- >> v4: updated gpio debounce logic to use delayed_workqueue. >> >> .../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- >> drivers/extcon/extcon-palmas.c | 129 ++++++++++++++++++--- >> drivers/extcon/extcon-usb-gpio.c | 1 + >> include/linux/mfd/palmas.h | 7 ++ >> 4 files changed, 126 insertions(+), 16 deletions(-) >> >> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt >> index 45414bb..f61d5af 100644 >> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt >> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt >> @@ -10,8 +10,11 @@ Required Properties: >> >> Optional Properties: >> - ti,wakeup : To enable the wakeup comparator in probe >> - - ti,enable-id-detection: Perform ID detection. >> + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified >> + it performs id-detection using GPIO else using OTG core. >> - ti,enable-vbus-detection: Perform VBUS detection. >> + - id-gpio: gpio for GPIO ID detection. See gpio binding. >> + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. >> >> palmas-usb { >> compatible = "ti,twl6035-usb", "ti,palmas-usb"; >> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c >> index 8933e7e..662e917 100644 >> --- a/drivers/extcon/extcon-palmas.c >> +++ b/drivers/extcon/extcon-palmas.c >> @@ -28,6 +28,10 @@ >> #include >> #include >> #include >> +#include >> +#include >> + >> +#define USB_GPIO_DEBOUNCE_MS 20 /* ms */ >> >> static const unsigned int palmas_extcon_cable[] = { >> EXTCON_USB, >> @@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) >> return IRQ_HANDLED; >> } >> >> +static void palmas_gpio_id_detect(struct work_struct *work) >> +{ >> + int id; >> + struct palmas_usb *palmas_usb = container_of(to_delayed_work(work), >> + struct palmas_usb, >> + wq_detectid); >> + struct extcon_dev *edev = palmas_usb->edev; >> + >> + if (!palmas_usb->id_gpiod) >> + return; >> + >> + id = gpiod_get_value_cansleep(palmas_usb->id_gpiod); >> + >> + if (id) { >> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); >> + dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); >> + } else { >> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); >> + dev_info(palmas_usb->dev, "USB-HOST cable is attached\n"); >> + } >> +} >> + >> +static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb) >> +{ >> + struct palmas_usb *palmas_usb = _palmas_usb; >> + >> + queue_delayed_work(system_power_efficient_wq, &palmas_usb->wq_detectid, >> + palmas_usb->sw_debounce_jiffies); >> + >> + return IRQ_HANDLED; >> +} >> + >> static void palmas_enable_irq(struct palmas_usb *palmas_usb) >> { >> palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, >> PALMAS_USB_VBUS_CTRL_SET, >> PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP); >> >> - palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, >> - PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP); >> + if (palmas_usb->enable_id_detection) { >> + palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, >> + PALMAS_USB_ID_CTRL_SET, >> + PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP); >> >> - palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, >> - PALMAS_USB_ID_INT_EN_HI_SET, >> - PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | >> - PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT); >> + palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, >> + PALMAS_USB_ID_INT_EN_HI_SET, >> + PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | >> + PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT); >> + } >> >> if (palmas_usb->enable_vbus_detection) >> palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb); >> @@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device *pdev) >> palmas_usb->wakeup = pdata->wakeup; >> } >> >> + palmas_usb->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id"); >> + if (IS_ERR(palmas_usb->id_gpiod)) { >> + dev_err(&pdev->dev, "failed to get id gpio\n"); >> + return PTR_ERR(palmas_usb->id_gpiod); >> + } >> + >> + if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { >> + palmas_usb->enable_id_detection = false; >> + palmas_usb->enable_gpio_id_detection = true; >> + } >> + >> + if (palmas_usb->enable_gpio_id_detection) { >> + u32 debounce; >> + >> + if (of_property_read_u32(node, "debounce-delay-ms", &debounce)) >> + debounce = USB_GPIO_DEBOUNCE_MS; >> + >> + status = gpiod_set_debounce(palmas_usb->id_gpiod, >> + debounce * 1000); >> + if (status < 0) >> + palmas_usb->sw_debounce_jiffies = msecs_to_jiffies(debounce); >> + } >> + >> + INIT_DELAYED_WORK(&palmas_usb->wq_detectid, palmas_gpio_id_detect); >> + >> palmas->usb = palmas_usb; >> palmas_usb->palmas = palmas; >> >> palmas_usb->dev = &pdev->dev; >> >> - palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data, >> - PALMAS_ID_OTG_IRQ); >> - palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data, >> - PALMAS_ID_IRQ); >> - palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, >> - PALMAS_VBUS_OTG_IRQ); >> - palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, >> - PALMAS_VBUS_IRQ); >> - >> palmas_usb_wakeup(palmas, palmas_usb->wakeup); >> >> platform_set_drvdata(pdev, palmas_usb); >> @@ -201,6 +256,10 @@ static int palmas_usb_probe(struct platform_device *pdev) >> } >> >> if (palmas_usb->enable_id_detection) { >> + palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data, >> + PALMAS_ID_OTG_IRQ); >> + palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data, >> + PALMAS_ID_IRQ); >> status = devm_request_threaded_irq(palmas_usb->dev, >> palmas_usb->id_irq, >> NULL, palmas_id_irq_handler, >> @@ -212,9 +271,33 @@ static int palmas_usb_probe(struct platform_device *pdev) >> palmas_usb->id_irq, status); >> return status; >> } >> + } else if (palmas_usb->enable_gpio_id_detection) { >> + palmas_usb->gpio_id_irq = gpiod_to_irq(palmas_usb->id_gpiod); >> + if (palmas_usb->gpio_id_irq < 0) { >> + dev_err(&pdev->dev, "failed to get id irq\n"); >> + return palmas_usb->gpio_id_irq; >> + } >> + status = devm_request_threaded_irq(&pdev->dev, >> + palmas_usb->gpio_id_irq, >> + NULL, >> + palmas_gpio_id_irq_handler, >> + IRQF_TRIGGER_RISING | >> + IRQF_TRIGGER_FALLING | >> + IRQF_ONESHOT, >> + "palmas_usb_id", >> + palmas_usb); >> + if (status < 0) { >> + dev_err(&pdev->dev, >> + "failed to request handler for id irq\n"); >> + return status; >> + } >> } >> >> if (palmas_usb->enable_vbus_detection) { >> + palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, >> + PALMAS_VBUS_OTG_IRQ); >> + palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, >> + PALMAS_VBUS_IRQ); >> status = devm_request_threaded_irq(palmas_usb->dev, >> palmas_usb->vbus_irq, NULL, >> palmas_vbus_irq_handler, >> @@ -229,10 +312,21 @@ static int palmas_usb_probe(struct platform_device *pdev) >> } >> >> palmas_enable_irq(palmas_usb); >> + /* perform initial detection */ >> + palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); >> device_set_wakeup_capable(&pdev->dev, true); >> return 0; >> } >> >> +static int palmas_usb_remove(struct platform_device *pdev) >> +{ >> + struct palmas_usb *palmas_usb = platform_get_drvdata(pdev); >> + >> + cancel_delayed_work_sync(&palmas_usb->wq_detectid); >> + >> + return 0; >> +} >> + >> #ifdef CONFIG_PM_SLEEP >> static int palmas_usb_suspend(struct device *dev) >> { >> @@ -243,6 +337,8 @@ static int palmas_usb_suspend(struct device *dev) >> enable_irq_wake(palmas_usb->vbus_irq); >> if (palmas_usb->enable_id_detection) >> enable_irq_wake(palmas_usb->id_irq); >> + if (palmas_usb->enable_gpio_id_detection) >> + enable_irq_wake(palmas_usb->gpio_id_irq); >> } >> return 0; >> } >> @@ -256,6 +352,8 @@ static int palmas_usb_resume(struct device *dev) >> disable_irq_wake(palmas_usb->vbus_irq); >> if (palmas_usb->enable_id_detection) >> disable_irq_wake(palmas_usb->id_irq); >> + if (palmas_usb->enable_gpio_id_detection) >> + disable_irq_wake(palmas_usb->gpio_id_irq); >> } >> return 0; >> }; >> @@ -273,6 +371,7 @@ static const struct of_device_id of_palmas_match_tbl[] = { >> >> static struct platform_driver palmas_usb_driver = { >> .probe = palmas_usb_probe, >> + .remove = palmas_usb_remove, >> .driver = { >> .name = "palmas-usb", >> .of_match_table = of_palmas_match_tbl, >> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c >> index a2a4453..2b2fecf 100644 >> --- a/drivers/extcon/extcon-usb-gpio.c >> +++ b/drivers/extcon/extcon-usb-gpio.c >> @@ -15,6 +15,7 @@ >> */ >> >> #include >> +#include >> #include >> #include >> #include >> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h >> index bb270bd..13e1d96 100644 >> --- a/include/linux/mfd/palmas.h >> +++ b/include/linux/mfd/palmas.h >> @@ -21,6 +21,7 @@ >> #include >> #include >> #include >> +#include >> #include >> >> #define PALMAS_NUM_CLIENTS 3 >> @@ -551,10 +552,16 @@ struct palmas_usb { >> int vbus_otg_irq; >> int vbus_irq; >> >> + int gpio_id_irq; >> + struct gpio_desc *id_gpiod; >> + unsigned long sw_debounce_jiffies; >> + struct delayed_work wq_detectid; >> + >> enum palmas_usb_state linkstat; >> int wakeup; >> bool enable_vbus_detection; >> bool enable_id_detection; >> + bool enable_gpio_id_detection; >> }; >> >> #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator) >> > -- > 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/ >