aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Dooks <ben@simtec.co.uk>2009-11-11 00:01:31 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-11-20 03:52:08 -0500
commitbc8f1eaf68a8aa1d993492f1ad2d74502665f578 (patch)
treecadf6c3f31ee6ae8dee14ccd66185faf994d51ff
parent111bc59c08c437e433bd5b9cc726adaa912c6e6c (diff)
Input: gpio_keys - seperate individual button setup to make code neater
Move the code that deals with setting up each individual button out into a new function to reduce the indentation and allow us to common up some of the error recovery code. Signed-off-by: Ben Dooks <ben@simtec.co.uk> Signed-off-by: Simtec Linux Team <linux@simtec.co.uk> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r--drivers/input/keyboard/gpio_keys.c93
1 files changed, 53 insertions, 40 deletions
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b236709a2c01..8941a8ba89bf 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -73,6 +73,57 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
73 return IRQ_HANDLED; 73 return IRQ_HANDLED;
74} 74}
75 75
76static int __devinit gpio_keys_setup_key(struct device *dev,
77 struct gpio_button_data *bdata,
78 struct gpio_keys_button *button)
79{
80 char *desc = button->desc ? button->desc : "gpio_keys";
81 int irq, error;
82
83 setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
84 INIT_WORK(&bdata->work, gpio_keys_report_event);
85
86 error = gpio_request(button->gpio, desc);
87 if (error < 0) {
88 dev_err(dev, "failed to request GPIO %d, error %d\n",
89 button->gpio, error);
90 goto fail2;
91 }
92
93 error = gpio_direction_input(button->gpio);
94 if (error < 0) {
95 dev_err(dev, "failed to configure"
96 " direction for GPIO %d, error %d\n",
97 button->gpio, error);
98 goto fail3;
99 }
100
101 irq = gpio_to_irq(button->gpio);
102 if (irq < 0) {
103 error = irq;
104 dev_err(dev, "Unable to get irq number for GPIO %d, error %d\n",
105 button->gpio, error);
106 goto fail3;
107 }
108
109 error = request_irq(irq, gpio_keys_isr,
110 IRQF_SHARED |
111 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
112 desc, bdata);
113 if (error) {
114 dev_err(dev, "Unable to claim irq %d; error %d\n",
115 irq, error);
116 goto fail3;
117 }
118
119 return 0;
120
121fail3:
122 gpio_free(button->gpio);
123fail2:
124 return error;
125}
126
76static int __devinit gpio_keys_probe(struct platform_device *pdev) 127static int __devinit gpio_keys_probe(struct platform_device *pdev)
77{ 128{
78 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 129 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -112,52 +163,14 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
112 for (i = 0; i < pdata->nbuttons; i++) { 163 for (i = 0; i < pdata->nbuttons; i++) {
113 struct gpio_keys_button *button = &pdata->buttons[i]; 164 struct gpio_keys_button *button = &pdata->buttons[i];
114 struct gpio_button_data *bdata = &ddata->data[i]; 165 struct gpio_button_data *bdata = &ddata->data[i];
115 int irq;
116 unsigned int type = button->type ?: EV_KEY; 166 unsigned int type = button->type ?: EV_KEY;
117 167
118 bdata->input = input; 168 bdata->input = input;
119 bdata->button = button; 169 bdata->button = button;
120 setup_timer(&bdata->timer,
121 gpio_keys_timer, (unsigned long)bdata);
122 INIT_WORK(&bdata->work, gpio_keys_report_event);
123
124 error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
125 if (error < 0) {
126 dev_err(dev, "failed to request GPIO %d, error %d\n",
127 button->gpio, error);
128 goto fail2;
129 }
130 170
131 error = gpio_direction_input(button->gpio); 171 error = gpio_keys_setup_key(dev, bdata, button);
132 if (error < 0) { 172 if (error)
133 dev_err(dev, "failed to configure"
134 " direction for GPIO %d, error %d\n",
135 button->gpio, error);
136 gpio_free(button->gpio);
137 goto fail2; 173 goto fail2;
138 }
139
140 irq = gpio_to_irq(button->gpio);
141 if (irq < 0) {
142 error = irq;
143 dev_err(dev, "Unable to get irq number "
144 "for GPIO %d, error %d\n",
145 button->gpio, error);
146 gpio_free(button->gpio);
147 goto fail2;
148 }
149
150 error = request_irq(irq, gpio_keys_isr,
151 IRQF_SHARED |
152 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
153 button->desc ? button->desc : "gpio_keys",
154 bdata);
155 if (error) {
156 dev_err(dev, "Unable to claim irq %d; error %d\n",
157 irq, error);
158 gpio_free(button->gpio);
159 goto fail2;
160 }
161 174
162 if (button->wakeup) 175 if (button->wakeup)
163 wakeup = 1; 176 wakeup = 1;