From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754286AbcEYMcK (ORCPT ); Wed, 25 May 2016 08:32:10 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:47298 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbcEYMcF (ORCPT ); Wed, 25 May 2016 08:32:05 -0400 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: cbfee68e-f79b26d0000013da-1e-57459b429774 Content-transfer-encoding: 8BIT Message-id: <57459B41.3060507@samsung.com> Date: Wed, 25 May 2016 21:32:01 +0900 From: Chanwoo Choi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Venkat Reddy Talla , MyungJoo Ham , Rob Herring , Pawel Moll Cc: Mark Rutland , Ian Campbell , devicetree@vger.kernel.org, Kumar Gala , linux-kernel@vger.kernel.org, Laxman Dewangan Subject: Re: [PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio References: <1464176133-10742-1-git-send-email-vreddytalla@nvidia.com> In-reply-to: <1464176133-10742-1-git-send-email-vreddytalla@nvidia.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRmVeSWpSXmKPExsWyRsSkQNdptmu4QesePov5R86xWvS/Wchq ce7VSkaLpftWs1hc3jWHzWLp9YtMFrcbV7BZTJi+lsWide8RdotVd96zOHB5rJm3htHjcl8v k8fK5V/YPDat6mTz6G1+x+bRt2UVo8fnTXIB7FFcNimpOZllqUX6dglcGcd+GBWs1q/YPnMi UwNjv1oXIyeHhICJxL4j/UwQtpjEhXvr2UBsIYEVjBLn26xhap4d/sLYxcgFFF/KKDF7Uxsr SIJXQFDix+R7LF2MHBzMAvISRy5lg4SZBdQlJs1bxAxR/4BRYuq2P4wQ9VoSe1ZdZQSpZxFQ lTg3gQ8kzAYU3v/iBhtIWFQgQqL7RC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guKk9Fyj vNRyveLE3OLSvHS95PzcTYzgRPBMegfj4V3uhxgFOBiVeHgF1rmEC7EmlhVX5h5ilOBgVhLh PTLTNVyINyWxsiq1KD++qDQntfgQoynQfxOZpUST84FJKq8k3tDYxMzI0sjc0MLI2FxJnPfx /3VhQgLpiSWp2ampBalFMH1MHJxSwChQ2sGZ5bKA682p0DUrFoa/N3nItSs9PD03JaNnbaas 25f4cF+Louh7nPURx+KuGRSo1qRLnHjN+ndnubp8Pjd7yraQ3PbTlRcLJmpa/5l5+8TGihen 7Cc+/L6hTPjj47l6Ozfsev6aubDj5QrbHed4y75d1xW2SHv4c/bX96repkvEHquFNyqxFGck GmoxFxUnAgDd37LaGgMAAA== 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 Venkat, I'm already working the support the device-tree for extcon-gpio [1]. [1] https://lkml.org/lkml/2015/10/21/8 - [PATCH v3] extcon: gpio: Add the support for Device tree bindings So, I just apply this patch the temporay extcon-test[2] branch on extcon.git. [2] https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-test&id=294d13e8d79fb0997e1bb146892cd75ec02221c0 But, Rob Herring gave me the some comment[2]. [3] https://lkml.org/lkml/2015/10/21/906 [4] https://lkml.org/lkml/2015/10/26/80 So, if you possible, do you improve the extcon-gpio.c for device-tree using by my patch[1]? I think that you could improve the extcon-gpio.c driver as comment of Rob Herring. I'm sorry for late reply. Thanks, Chanwoo Choi On 2016년 05월 25일 20:35, Venkat Reddy Talla wrote: > Adding device tree support for extcon-gpio driver. > > Signed-off-by: Venkat Reddy Talla > > --- > changes in v2: > - using gpio flag cell to handle gpio active state > - change dts property name gpio to gpios > - removed prefix for debounce > --- > --- > drivers/extcon/extcon-gpio.c | 80 +++++++++++++++++++++++++++++++++++--- > include/linux/extcon/extcon-gpio.h | 4 +- > 2 files changed, 77 insertions(+), 7 deletions(-) > > diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c > index d023789..f29032c 100644 > --- a/drivers/extcon/extcon-gpio.c > +++ b/drivers/extcon/extcon-gpio.c > @@ -28,6 +28,8 @@ > #include > #include > #include > +#include > +#include > > struct gpio_extcon_data { > struct extcon_dev *edev; > @@ -90,21 +92,80 @@ static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data) > return 0; > } > > +static struct gpio_extcon_pdata *gpio_extcon_of_pdata( > + struct platform_device *pdev) > +{ > + struct gpio_extcon_pdata *pdata; > + struct device_node *np = pdev->dev.of_node; > + enum of_gpio_flags flags; > + int gpio; > + u32 pval; > + int ret; > + > + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > + if (!pdata) > + return ERR_PTR(-ENOMEM); > + > + gpio = of_get_named_gpio_flags(np, "gpios", 0, &flags); > + if (gpio < 0) > + return ERR_PTR(gpio); > + > + pdata->gpio = gpio; > + > + if (flags & OF_GPIO_ACTIVE_LOW) > + pdata->gpio_active_low = 1; > + > + ret = of_property_read_u32(np, "extcon-gpio,irq-flags", &pval); > + if (!ret) > + pdata->irq_flags = pval; > + else > + pdata->irq_flags = IRQF_TRIGGER_RISING | > + IRQF_TRIGGER_FALLING; > + > + ret = of_property_read_u32(np, "debounce-ms", &pval); > + if (!ret) > + pdata->debounce = pval; > + > + pdata->extcon_cable_cnt = of_property_count_u32_elems(np, > + "extcon-gpio,cable-names"); > + if (pdata->extcon_cable_cnt <= 0) { > + dev_err(&pdev->dev, "not found out cable names\n"); > + return ERR_PTR(-EINVAL); > + } > + > + pdata->extcon_id = devm_kzalloc(&pdev->dev, > + (pdata->extcon_cable_cnt) * > + sizeof(*pdata->extcon_id), GFP_KERNEL); > + if (!pdata->extcon_id) > + return ERR_PTR(-ENOMEM); > + > + ret = of_property_read_u32_array(np, "extcon-gpio,cable-names", > + pdata->extcon_id, pdata->extcon_cable_cnt); > + if (ret) > + return ERR_PTR(-EINVAL); > + > + return pdata; > +} > + > static int gpio_extcon_probe(struct platform_device *pdev) > { > struct gpio_extcon_pdata *pdata = dev_get_platdata(&pdev->dev); > struct gpio_extcon_data *data; > int ret; > > - if (!pdata) > - return -EBUSY; > - if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE) > - return -EINVAL; > - > data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data), > GFP_KERNEL); > if (!data) > return -ENOMEM; > + > + if (!pdata && pdev->dev.of_node) > + pdata = gpio_extcon_of_pdata(pdev); > + > + if (IS_ERR(pdata)) > + return PTR_ERR(pdata); > + if (!pdata->irq_flags || !pdata->extcon_id) > + return -EINVAL; > + > data->pdata = pdata; > > /* Initialize the gpio */ > @@ -113,7 +174,7 @@ static int gpio_extcon_probe(struct platform_device *pdev) > return ret; > > /* Allocate the memory of extcon devie and register extcon device */ > - data->edev = devm_extcon_dev_allocate(&pdev->dev, &pdata->extcon_id); > + data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->extcon_id); > if (IS_ERR(data->edev)) { > dev_err(&pdev->dev, "failed to allocate extcon device\n"); > return -ENOMEM; > @@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev) > > static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume); > > +static const struct of_device_id of_extcon_gpio_tbl[] = { > + { .compatible = "extcon-gpio", }, > + { /* end */ } > +}; > +MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl); > + > static struct platform_driver gpio_extcon_driver = { > .probe = gpio_extcon_probe, > .remove = gpio_extcon_remove, > .driver = { > .name = "extcon-gpio", > .pm = &gpio_extcon_pm_ops, > + .of_match_table = of_extcon_gpio_tbl, > }, > }; > > diff --git a/include/linux/extcon/extcon-gpio.h b/include/linux/extcon/extcon-gpio.h > index 7cacafb..1914894 100644 > --- a/include/linux/extcon/extcon-gpio.h > +++ b/include/linux/extcon/extcon-gpio.h > @@ -31,15 +31,17 @@ > * If false, high state of gpio means active. > * @debounce: Debounce time for GPIO IRQ in ms. > * @irq_flags: IRQ Flags (e.g., IRQF_TRIGGER_LOW). > + * extcon_cable_cnt: External cable count. > * @check_on_resume: Boolean describing whether to check the state of gpio > * while resuming from sleep. > */ > struct gpio_extcon_pdata { > - unsigned int extcon_id; > + unsigned int *extcon_id; > unsigned gpio; > bool gpio_active_low; > unsigned long debounce; > unsigned long irq_flags; > + int extcon_cable_cnt; > > bool check_on_resume; > }; >