hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-htc-egpio.c
....@@ -118,20 +118,6 @@
118118 }
119119 }
120120
121
-int htc_egpio_get_wakeup_irq(struct device *dev)
122
-{
123
- struct egpio_info *ei = dev_get_drvdata(dev);
124
-
125
- /* Read current pins. */
126
- u16 readval = egpio_readw(ei, ei->ack_register);
127
- /* Ack/unmask interrupts. */
128
- ack_irqs(ei);
129
- /* Return first set pin. */
130
- readval &= ei->irqs_enabled;
131
- return ei->irq_start + ffs(readval) - 1;
132
-}
133
-EXPORT_SYMBOL(htc_egpio_get_wakeup_irq);
134
-
135121 static inline int egpio_pos(struct egpio_info *ei, int bit)
136122 {
137123 return bit >> ei->reg_shift;
....@@ -189,7 +175,6 @@
189175 unsigned long flag;
190176 struct egpio_chip *egpio;
191177 struct egpio_info *ei;
192
- unsigned bit;
193178 int pos;
194179 int reg;
195180 int shift;
....@@ -199,7 +184,6 @@
199184
200185 egpio = gpiochip_get_data(chip);
201186 ei = dev_get_drvdata(egpio->dev);
202
- bit = egpio_bit(ei, offset);
203187 pos = egpio_pos(ei, offset);
204188 reg = egpio->reg_start + pos;
205189 shift = pos << ei->reg_shift;
....@@ -236,7 +220,10 @@
236220
237221 egpio = gpiochip_get_data(chip);
238222
239
- return !test_bit(offset, &egpio->is_out);
223
+ if (test_bit(offset, &egpio->is_out))
224
+ return GPIO_LINE_DIRECTION_OUT;
225
+
226
+ return GPIO_LINE_DIRECTION_IN;
240227 }
241228
242229 static void egpio_write_cache(struct egpio_info *ei)
....@@ -281,7 +268,6 @@
281268 struct gpio_chip *chip;
282269 unsigned int irq, irq_end;
283270 int i;
284
- int ret;
285271
286272 /* Initialize ei data structure. */
287273 ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL);
....@@ -291,28 +277,24 @@
291277 spin_lock_init(&ei->lock);
292278
293279 /* Find chained irq */
294
- ret = -EINVAL;
295280 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
296281 if (res)
297282 ei->chained_irq = res->start;
298283
299284 /* Map egpio chip into virtual address space. */
300
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
301
- if (!res)
302
- goto fail;
303
- ei->base_addr = devm_ioremap_nocache(&pdev->dev, res->start,
304
- resource_size(res));
305
- if (!ei->base_addr)
306
- goto fail;
307
- pr_debug("EGPIO phys=%08x virt=%p\n", (u32)res->start, ei->base_addr);
285
+ ei->base_addr = devm_platform_ioremap_resource(pdev, 0);
286
+ if (IS_ERR(ei->base_addr))
287
+ return PTR_ERR(ei->base_addr);
308288
309289 if ((pdata->bus_width != 16) && (pdata->bus_width != 32))
310
- goto fail;
290
+ return -EINVAL;
291
+
311292 ei->bus_shift = fls(pdata->bus_width - 1) - 3;
312293 pr_debug("bus_shift = %d\n", ei->bus_shift);
313294
314295 if ((pdata->reg_width != 8) && (pdata->reg_width != 16))
315
- goto fail;
296
+ return -EINVAL;
297
+
316298 ei->reg_shift = fls(pdata->reg_width - 1);
317299 pr_debug("reg_shift = %d\n", ei->reg_shift);
318300
....@@ -324,17 +306,21 @@
324306 ei->chip = devm_kcalloc(&pdev->dev,
325307 ei->nchips, sizeof(struct egpio_chip),
326308 GFP_KERNEL);
327
- if (!ei->chip) {
328
- ret = -ENOMEM;
329
- goto fail;
330
- }
309
+ if (!ei->chip)
310
+ return -ENOMEM;
311
+
331312 for (i = 0; i < ei->nchips; i++) {
332313 ei->chip[i].reg_start = pdata->chip[i].reg_start;
333314 ei->chip[i].cached_values = pdata->chip[i].initial_values;
334315 ei->chip[i].is_out = pdata->chip[i].direction;
335316 ei->chip[i].dev = &(pdev->dev);
336317 chip = &(ei->chip[i].chip);
337
- chip->label = "htc-egpio";
318
+ chip->label = devm_kasprintf(&pdev->dev, GFP_KERNEL,
319
+ "htc-egpio-%d",
320
+ i);
321
+ if (!chip->label)
322
+ return -ENOMEM;
323
+
338324 chip->parent = &pdev->dev;
339325 chip->owner = THIS_MODULE;
340326 chip->get = egpio_get;
....@@ -376,10 +362,6 @@
376362 }
377363
378364 return 0;
379
-
380
-fail:
381
- printk(KERN_ERR "EGPIO failed to setup\n");
382
- return ret;
383365 }
384366
385367 #ifdef CONFIG_PM