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 | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 18 | #include <linux/spmi.h> |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 19 | |
| 20 | /** |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 21 | * spmi_get_resource - get a resource for a device |
| 22 | * @dev: spmi device |
| 23 | * @node_idx: dev_node index |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 24 | * @type: resource type |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 25 | * @res_num: resource index |
| 26 | * |
| 27 | * Returns |
| 28 | * NULL on failure. |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 29 | */ |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 30 | struct resource *spmi_get_resource(struct spmi_device *dev, |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 31 | unsigned int node_idx, unsigned int type, |
| 32 | unsigned int res_num) |
| 33 | { |
| 34 | int i; |
| 35 | |
| 36 | for (i = 0; i < dev->dev_node[node_idx].num_resources; i++) { |
| 37 | struct resource *r = &dev->dev_node[node_idx].resource[i]; |
| 38 | |
| 39 | if (type == resource_type(r) && res_num-- == 0) |
| 40 | return r; |
| 41 | } |
| 42 | return NULL; |
| 43 | } |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 44 | EXPORT_SYMBOL_GPL(spmi_get_resource); |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 47 | * spmi_get_irq - get an IRQ for a device |
| 48 | * @dev: spmi device |
| 49 | * @node_idx: dev_node index |
| 50 | * @res_num: IRQ number index |
| 51 | * |
| 52 | * Returns |
| 53 | * -ENXIO on failure. |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 54 | */ |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 55 | int spmi_get_irq(struct spmi_device *dev, unsigned int node_idx, |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 56 | unsigned int res_num) |
| 57 | { |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 58 | struct resource *r = spmi_get_resource(dev, node_idx, |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 59 | IORESOURCE_IRQ, res_num); |
| 60 | |
| 61 | return r ? r->start : -ENXIO; |
| 62 | } |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame^] | 63 | EXPORT_SYMBOL_GPL(spmi_get_irq); |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 64 | |