Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2002-3 Patrick Mochel |
| 2 | * Copyright (c) 2002-3 Open Source Development Labs |
| 3 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 and |
| 7 | * only version 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * Resource handling based on platform.c. |
| 15 | */ |
| 16 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame^] | 17 | #include <linux/export.h> |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 18 | #include <mach/qpnp.h> |
| 19 | |
| 20 | /** |
| 21 | * qpnp_get_resource - get a resource for a device |
| 22 | * @dev: qpnp device |
| 23 | * @type: resource type |
| 24 | * @num: resource index |
| 25 | */ |
| 26 | struct resource *qpnp_get_resource(struct spmi_device *dev, |
| 27 | unsigned int node_idx, unsigned int type, |
| 28 | unsigned int res_num) |
| 29 | { |
| 30 | int i; |
| 31 | |
| 32 | for (i = 0; i < dev->dev_node[node_idx].num_resources; i++) { |
| 33 | struct resource *r = &dev->dev_node[node_idx].resource[i]; |
| 34 | |
| 35 | if (type == resource_type(r) && res_num-- == 0) |
| 36 | return r; |
| 37 | } |
| 38 | return NULL; |
| 39 | } |
| 40 | EXPORT_SYMBOL_GPL(qpnp_get_resource); |
| 41 | |
| 42 | /** |
| 43 | * qpnp_get_irq - get an IRQ for a device |
| 44 | * @dev: qpnp device |
| 45 | * @num: IRQ number index |
| 46 | */ |
| 47 | int qpnp_get_irq(struct spmi_device *dev, unsigned int node_idx, |
| 48 | unsigned int res_num) |
| 49 | { |
| 50 | struct resource *r = qpnp_get_resource(dev, node_idx, |
| 51 | IORESOURCE_IRQ, res_num); |
| 52 | |
| 53 | return r ? r->start : -ENXIO; |
| 54 | } |
| 55 | EXPORT_SYMBOL_GPL(qpnp_get_irq); |
| 56 | |