aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-gpio.c
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2015-09-29 07:53:12 -0400
committerChanwoo Choi <cw00.choi@samsung.com>2015-09-30 06:22:49 -0400
commit60f9b9e65c82cc610cc9c02c1f555df8fb2ce4f0 (patch)
tree5f3e3ddacf48ea4e19ef6189ec51cdc1eccb3384 /drivers/extcon/extcon-gpio.c
parentae59f3a21fbe4b9ef3a9a09deabd2b0afb80942d (diff)
extcon: gpio: Remove duplicate data from struct gpio_extcon_data
There are duplicate data between struct gpio_extcon_data and struct gpio_extcon_platform_data. This patch removes them from struct gpio_extcon_data. Instead, this patch add pdata field to struct gpio_extcon_data. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon/extcon-gpio.c')
-rw-r--r--drivers/extcon/extcon-gpio.c70
1 files changed, 31 insertions, 39 deletions
diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 7e7fd8f5d838..2a89c89dfaf5 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -33,14 +33,11 @@
33 33
34struct gpio_extcon_data { 34struct gpio_extcon_data {
35 struct extcon_dev *edev; 35 struct extcon_dev *edev;
36 unsigned gpio;
37 bool gpio_active_low;
38 const char *state_on;
39 const char *state_off;
40 int irq; 36 int irq;
41 struct delayed_work work; 37 struct delayed_work work;
42 unsigned long debounce_jiffies; 38 unsigned long debounce_jiffies;
43 bool check_on_resume; 39
40 struct gpio_extcon_platform_data *pdata;
44}; 41};
45 42
46static void gpio_extcon_work(struct work_struct *work) 43static void gpio_extcon_work(struct work_struct *work)
@@ -50,25 +47,25 @@ static void gpio_extcon_work(struct work_struct *work)
50 container_of(to_delayed_work(work), struct gpio_extcon_data, 47 container_of(to_delayed_work(work), struct gpio_extcon_data,
51 work); 48 work);
52 49
53 state = gpio_get_value(data->gpio); 50 state = gpio_get_value(data->pdata->gpio);
54 if (data->gpio_active_low) 51 if (data->pdata->gpio_active_low)
55 state = !state; 52 state = !state;
56 extcon_set_state(data->edev, state); 53 extcon_set_state(data->edev, state);
57} 54}
58 55
59static irqreturn_t gpio_irq_handler(int irq, void *dev_id) 56static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
60{ 57{
61 struct gpio_extcon_data *extcon_data = dev_id; 58 struct gpio_extcon_data *data = dev_id;
62 59
63 queue_delayed_work(system_power_efficient_wq, &extcon_data->work, 60 queue_delayed_work(system_power_efficient_wq, &data->work,
64 extcon_data->debounce_jiffies); 61 data->debounce_jiffies);
65 return IRQ_HANDLED; 62 return IRQ_HANDLED;
66} 63}
67 64
68static int gpio_extcon_probe(struct platform_device *pdev) 65static int gpio_extcon_probe(struct platform_device *pdev)
69{ 66{
70 struct gpio_extcon_platform_data *pdata = dev_get_platdata(&pdev->dev); 67 struct gpio_extcon_platform_data *pdata = dev_get_platdata(&pdev->dev);
71 struct gpio_extcon_data *extcon_data; 68 struct gpio_extcon_data *data;
72 int ret; 69 int ret;
73 70
74 if (!pdata) 71 if (!pdata)
@@ -78,64 +75,59 @@ static int gpio_extcon_probe(struct platform_device *pdev)
78 return -EINVAL; 75 return -EINVAL;
79 } 76 }
80 77
81 extcon_data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data), 78 data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data),
82 GFP_KERNEL); 79 GFP_KERNEL);
83 if (!extcon_data) 80 if (!data)
84 return -ENOMEM; 81 return -ENOMEM;
85 82
86 extcon_data->edev = devm_extcon_dev_allocate(&pdev->dev, NULL); 83 data->edev = devm_extcon_dev_allocate(&pdev->dev, NULL);
87 if (IS_ERR(extcon_data->edev)) { 84 if (IS_ERR(data->edev)) {
88 dev_err(&pdev->dev, "failed to allocate extcon device\n"); 85 dev_err(&pdev->dev, "failed to allocate extcon device\n");
89 return -ENOMEM; 86 return -ENOMEM;
90 } 87 }
88 data->pdata = pdata;
91 89
92 extcon_data->gpio = pdata->gpio; 90 ret = devm_gpio_request_one(&pdev->dev, data->pdata->gpio, GPIOF_DIR_IN,
93 extcon_data->gpio_active_low = pdata->gpio_active_low;
94 extcon_data->state_on = pdata->state_on;
95 extcon_data->state_off = pdata->state_off;
96 extcon_data->check_on_resume = pdata->check_on_resume;
97
98 ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN,
99 pdev->name); 91 pdev->name);
100 if (ret < 0) 92 if (ret < 0)
101 return ret; 93 return ret;
102 94
103 if (pdata->debounce) { 95 if (pdata->debounce) {
104 ret = gpio_set_debounce(extcon_data->gpio, 96 ret = gpio_set_debounce(data->pdata->gpio,
105 pdata->debounce * 1000); 97 pdata->debounce * 1000);
106 if (ret < 0) 98 if (ret < 0)
107 extcon_data->debounce_jiffies = 99 data->debounce_jiffies =
108 msecs_to_jiffies(pdata->debounce); 100 msecs_to_jiffies(pdata->debounce);
109 } 101 }
110 102
111 ret = devm_extcon_dev_register(&pdev->dev, extcon_data->edev); 103 ret = devm_extcon_dev_register(&pdev->dev, data->edev);
112 if (ret < 0) 104 if (ret < 0)
113 return ret; 105 return ret;
114 106
115 INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work); 107 INIT_DELAYED_WORK(&data->work, gpio_extcon_work);
116 108
117 extcon_data->irq = gpio_to_irq(extcon_data->gpio); 109 data->irq = gpio_to_irq(data->pdata->gpio);
118 if (extcon_data->irq < 0) 110 if (data->irq < 0)
119 return extcon_data->irq; 111 return data->irq;
120 112
121 ret = devm_request_any_context_irq(&pdev->dev, extcon_data->irq, 113 ret = devm_request_any_context_irq(&pdev->dev, data->irq,
122 gpio_irq_handler, pdata->irq_flags, 114 gpio_irq_handler, pdata->irq_flags,
123 pdev->name, extcon_data); 115 pdev->name, data);
124 if (ret < 0) 116 if (ret < 0)
125 return ret; 117 return ret;
126 118
127 platform_set_drvdata(pdev, extcon_data); 119 platform_set_drvdata(pdev, data);
128 /* Perform initial detection */ 120 /* Perform initial detection */
129 gpio_extcon_work(&extcon_data->work.work); 121 gpio_extcon_work(&data->work.work);
130 122
131 return 0; 123 return 0;
132} 124}
133 125
134static int gpio_extcon_remove(struct platform_device *pdev) 126static int gpio_extcon_remove(struct platform_device *pdev)
135{ 127{
136 struct gpio_extcon_data *extcon_data = platform_get_drvdata(pdev); 128 struct gpio_extcon_data *data = platform_get_drvdata(pdev);
137 129
138 cancel_delayed_work_sync(&extcon_data->work); 130 cancel_delayed_work_sync(&data->work);
139 131
140 return 0; 132 return 0;
141} 133}
@@ -143,12 +135,12 @@ static int gpio_extcon_remove(struct platform_device *pdev)
143#ifdef CONFIG_PM_SLEEP 135#ifdef CONFIG_PM_SLEEP
144static int gpio_extcon_resume(struct device *dev) 136static int gpio_extcon_resume(struct device *dev)
145{ 137{
146 struct gpio_extcon_data *extcon_data; 138 struct gpio_extcon_data *data;
147 139
148 extcon_data = dev_get_drvdata(dev); 140 data = dev_get_drvdata(dev);
149 if (extcon_data->check_on_resume) 141 if (data->pdata->check_on_resume)
150 queue_delayed_work(system_power_efficient_wq, 142 queue_delayed_work(system_power_efficient_wq,
151 &extcon_data->work, extcon_data->debounce_jiffies); 143 &data->work, data->debounce_jiffies);
152 144
153 return 0; 145 return 0;
154} 146}