ARM: 6977/1: pmu: add platform_device_id table support
authorMark Rutland <mark.rutland@arm.com>
Wed, 22 Jun 2011 14:34:56 +0000 (15:34 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Wed, 29 Jun 2011 09:27:09 +0000 (10:27 +0100)
This patch adds support for platform_device_id tables, allowing new
PMU types to be registered with the correct type, without requiring
new platform_driver shims to provide the type. An single entry for
existing devices is provided.

Macros matching functionality of the of_device_id table macros are
provided for convenience.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Jamie Iles <jamie@jamieiles.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/kernel/pmu.c

index 2ce00be697eaa668ce453db78782660800b1f1d8..2b70709376c3271e1007b3e6bd7d829db997375e 100644 (file)
@@ -61,9 +61,22 @@ static struct of_device_id armpmu_of_device_ids[] = {
        {},
 };
 
+#define PLAT_MATCH_PMU(_name, _type) { \
+       .name           = _name,        \
+       .driver_data    = _type,        \
+}
+
+#define PLAT_MATCH_CPU(_name)  PLAT_MATCH_PMU(_name, ARM_PMU_DEVICE_CPU)
+
+static struct platform_device_id armpmu_plat_device_ids[] = {
+       PLAT_MATCH_CPU("arm-pmu"),
+       {},
+};
+
 enum arm_pmu_type armpmu_device_type(struct platform_device *pdev)
 {
        const struct of_device_id       *of_id;
+       const struct platform_device_id *pdev_id;
 
        /* provided by of_device_id table */
        if (pdev->dev.of_node) {
@@ -72,8 +85,10 @@ enum arm_pmu_type armpmu_device_type(struct platform_device *pdev)
                return (enum arm_pmu_type)of_id->data;
        }
 
-       /* Provided by a 'legacy' platform_device */
-       return ARM_PMU_DEVICE_CPU;
+       /* Provided by platform_device_id table */
+       pdev_id = platform_get_device_id(pdev);
+       BUG_ON(!pdev_id);
+       return pdev_id->driver_data;
 }
 
 static int __devinit armpmu_device_probe(struct platform_device *pdev)
@@ -87,6 +102,7 @@ static struct platform_driver armpmu_driver = {
                .of_match_table = armpmu_of_device_ids,
        },
        .probe          = armpmu_device_probe,
+       .id_table       = armpmu_plat_device_ids,
 };
 
 static int __init register_pmu_driver(void)