aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@stericsson.com>2012-02-03 05:19:05 -0500
committerLee Jones <lee.jones@linaro.org>2013-02-04 03:31:48 -0500
commitddba25f17dc7015f44fbcdf79ce72f69996f2be3 (patch)
treea2f6063663416fbaf2429e5aec0ce8b8343f4cf8
parent1d843a6c8c2067615fea0ff8cb62d4a5c4a6f8ae (diff)
mfd: ab8500-debugfs: Allow number of IRQs to be provided more dynamically
With the introduction of new AB* platforms, it's important to allow as much code reuse as possible. By allowing a system's number of IRQs to be dynamically passed, we can reuse almost all of the -debugfs driver. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
-rw-r--r--drivers/mfd/ab8500-debugfs.c51
1 files changed, 41 insertions, 10 deletions
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index af6f774e658a..8617b132e730 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -94,10 +94,11 @@ static u32 debug_address;
94 94
95static int irq_first; 95static int irq_first;
96static int irq_last; 96static int irq_last;
97static u32 irq_count[AB8500_NR_IRQS]; 97static u32 *irq_count;
98static int num_irqs;
98 99
99static struct device_attribute *dev_attr[AB8500_NR_IRQS]; 100static struct device_attribute **dev_attr;
100static char *event_name[AB8500_NR_IRQS]; 101static char **event_name;
101 102
102/** 103/**
103 * struct ab8500_reg_range 104 * struct ab8500_reg_range
@@ -483,7 +484,7 @@ static irqreturn_t ab8500_debug_handler(int irq, void *data)
483 struct kobject *kobj = (struct kobject *)data; 484 struct kobject *kobj = (struct kobject *)data;
484 unsigned int irq_abb = irq - irq_first; 485 unsigned int irq_abb = irq - irq_first;
485 486
486 if (irq_abb < AB8500_NR_IRQS) 487 if (irq_abb < num_irqs)
487 irq_count[irq_abb]++; 488 irq_count[irq_abb]++;
488 /* 489 /*
489 * This makes it possible to use poll for events (POLLPRI | POLLERR) 490 * This makes it possible to use poll for events (POLLPRI | POLLERR)
@@ -1340,7 +1341,7 @@ static ssize_t show_irq(struct device *dev,
1340 return err; 1341 return err;
1341 1342
1342 irq_index = name - irq_first; 1343 irq_index = name - irq_first;
1343 if (irq_index >= AB8500_NR_IRQS) 1344 if (irq_index >= num_irqs)
1344 return -EINVAL; 1345 return -EINVAL;
1345 else 1346 else
1346 return sprintf(buf, "%u\n", irq_count[irq_index]); 1347 return sprintf(buf, "%u\n", irq_count[irq_index]);
@@ -1376,7 +1377,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1376 } 1377 }
1377 1378
1378 irq_index = user_val - irq_first; 1379 irq_index = user_val - irq_first;
1379 if (irq_index >= AB8500_NR_IRQS) 1380 if (irq_index >= num_irqs)
1380 return -EINVAL; 1381 return -EINVAL;
1381 1382
1382 /* 1383 /*
@@ -1440,7 +1441,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
1440 } 1441 }
1441 1442
1442 irq_index = user_val - irq_first; 1443 irq_index = user_val - irq_first;
1443 if (irq_index >= AB8500_NR_IRQS) 1444 if (irq_index >= num_irqs)
1444 return -EINVAL; 1445 return -EINVAL;
1445 1446
1446 /* Set irq count to 0 when unsubscribe */ 1447 /* Set irq count to 0 when unsubscribe */
@@ -1521,21 +1522,40 @@ static struct dentry *ab8500_gpadc_dir;
1521static int ab8500_debug_probe(struct platform_device *plf) 1522static int ab8500_debug_probe(struct platform_device *plf)
1522{ 1523{
1523 struct dentry *file; 1524 struct dentry *file;
1525 int ret = -ENOMEM;
1526 struct ab8500 *ab8500;
1524 debug_bank = AB8500_MISC; 1527 debug_bank = AB8500_MISC;
1525 debug_address = AB8500_REV_REG & 0x00FF; 1528 debug_address = AB8500_REV_REG & 0x00FF;
1526 1529
1530 ab8500 = dev_get_drvdata(plf->dev.parent);
1531 num_irqs = ab8500->mask_size;
1532
1533 irq_count = kzalloc(sizeof(irq_count)*num_irqs, GFP_KERNEL);
1534 if (!irq_count)
1535 return -ENOMEM;
1536
1537 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
1538 if (!dev_attr)
1539 goto out_freeirq_count;
1540
1541 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
1542 if (!event_name)
1543 goto out_freedev_attr;
1544
1527 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); 1545 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1528 if (irq_first < 0) { 1546 if (irq_first < 0) {
1529 dev_err(&plf->dev, "First irq not found, err %d\n", 1547 dev_err(&plf->dev, "First irq not found, err %d\n",
1530 irq_first); 1548 irq_first);
1531 return irq_first; 1549 ret = irq_first;
1550 goto out_freeevent_name;
1532 } 1551 }
1533 1552
1534 irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); 1553 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1535 if (irq_last < 0) { 1554 if (irq_last < 0) {
1536 dev_err(&plf->dev, "Last irq not found, err %d\n", 1555 dev_err(&plf->dev, "Last irq not found, err %d\n",
1537 irq_last); 1556 irq_last);
1538 return irq_last; 1557 ret = irq_last;
1558 goto out_freeevent_name;
1539 } 1559 }
1540 1560
1541 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); 1561 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
@@ -1658,12 +1678,23 @@ err:
1658 if (ab8500_dir) 1678 if (ab8500_dir)
1659 debugfs_remove_recursive(ab8500_dir); 1679 debugfs_remove_recursive(ab8500_dir);
1660 dev_err(&plf->dev, "failed to create debugfs entries.\n"); 1680 dev_err(&plf->dev, "failed to create debugfs entries.\n");
1661 return -ENOMEM; 1681out_freeevent_name:
1682 kfree(event_name);
1683out_freedev_attr:
1684 kfree(dev_attr);
1685out_freeirq_count:
1686 kfree(irq_count);
1687
1688 return ret;
1662} 1689}
1663 1690
1664static int ab8500_debug_remove(struct platform_device *plf) 1691static int ab8500_debug_remove(struct platform_device *plf)
1665{ 1692{
1666 debugfs_remove_recursive(ab8500_dir); 1693 debugfs_remove_recursive(ab8500_dir);
1694 kfree(event_name);
1695 kfree(dev_attr);
1696 kfree(irq_count);
1697
1667 return 0; 1698 return 0;
1668} 1699}
1669 1700