aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-gpio.c
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2014-04-21 07:51:08 -0400
committerChanwoo Choi <cw00.choi@samsung.com>2014-04-28 20:51:48 -0400
commit60cd62d4f7d681a99eccf49941229ccf3a0069cf (patch)
tree3bffec88592d0f9fa9a8f66b24f97d931741db80 /drivers/extcon/extcon-gpio.c
parent1876fd9af59904078a73bdd4283c3924fd6cf18e (diff)
extcon: gpio: Use devm_extcon_dev_allocate for extcon_dev
This patch use devm_extcon_dev_allocate() to simplify the memory control of extcon device. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Reviewed-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/extcon/extcon-gpio.c')
-rw-r--r--drivers/extcon/extcon-gpio.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 43af34c4a518..645b28356819 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -32,7 +32,7 @@
32#include <linux/extcon/extcon-gpio.h> 32#include <linux/extcon/extcon-gpio.h>
33 33
34struct gpio_extcon_data { 34struct gpio_extcon_data {
35 struct extcon_dev edev; 35 struct extcon_dev *edev;
36 unsigned gpio; 36 unsigned gpio;
37 bool gpio_active_low; 37 bool gpio_active_low;
38 const char *state_on; 38 const char *state_on;
@@ -53,7 +53,7 @@ static void gpio_extcon_work(struct work_struct *work)
53 state = gpio_get_value(data->gpio); 53 state = gpio_get_value(data->gpio);
54 if (data->gpio_active_low) 54 if (data->gpio_active_low)
55 state = !state; 55 state = !state;
56 extcon_set_state(&data->edev, state); 56 extcon_set_state(data->edev, state);
57} 57}
58 58
59static irqreturn_t gpio_irq_handler(int irq, void *dev_id) 59static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
@@ -67,9 +67,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
67 67
68static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf) 68static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
69{ 69{
70 struct gpio_extcon_data *extcon_data = 70 struct device *dev = edev->dev.parent;
71 container_of(edev, struct gpio_extcon_data, edev); 71 struct gpio_extcon_data *extcon_data = dev_get_drvdata(dev);
72 const char *state; 72 const char *state;
73
73 if (extcon_get_state(edev)) 74 if (extcon_get_state(edev))
74 state = extcon_data->state_on; 75 state = extcon_data->state_on;
75 else 76 else
@@ -98,15 +99,21 @@ static int gpio_extcon_probe(struct platform_device *pdev)
98 if (!extcon_data) 99 if (!extcon_data)
99 return -ENOMEM; 100 return -ENOMEM;
100 101
101 extcon_data->edev.name = pdata->name; 102 extcon_data->edev = devm_extcon_dev_allocate(&pdev->dev, NULL);
102 extcon_data->edev.dev.parent = &pdev->dev; 103 if (IS_ERR(extcon_data->edev)) {
104 dev_err(&pdev->dev, "failed to allocate extcon device\n");
105 return -ENOMEM;
106 }
107 extcon_data->edev->name = pdata->name;
108 extcon_data->edev->dev.parent = &pdev->dev;
109
103 extcon_data->gpio = pdata->gpio; 110 extcon_data->gpio = pdata->gpio;
104 extcon_data->gpio_active_low = pdata->gpio_active_low; 111 extcon_data->gpio_active_low = pdata->gpio_active_low;
105 extcon_data->state_on = pdata->state_on; 112 extcon_data->state_on = pdata->state_on;
106 extcon_data->state_off = pdata->state_off; 113 extcon_data->state_off = pdata->state_off;
107 extcon_data->check_on_resume = pdata->check_on_resume; 114 extcon_data->check_on_resume = pdata->check_on_resume;
108 if (pdata->state_on && pdata->state_off) 115 if (pdata->state_on && pdata->state_off)
109 extcon_data->edev.print_state = extcon_gpio_print_state; 116 extcon_data->edev->print_state = extcon_gpio_print_state;
110 117
111 ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN, 118 ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN,
112 pdev->name); 119 pdev->name);
@@ -121,7 +128,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
121 msecs_to_jiffies(pdata->debounce); 128 msecs_to_jiffies(pdata->debounce);
122 } 129 }
123 130
124 ret = devm_extcon_dev_register(&pdev->dev, &extcon_data->edev); 131 ret = devm_extcon_dev_register(&pdev->dev, extcon_data->edev);
125 if (ret < 0) 132 if (ret < 0)
126 return ret; 133 return ret;
127 134