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 |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 23 | * @node: device node resource |
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 | * |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 27 | * If 'node' is specified as NULL, then the API treats this as a special |
| 28 | * case to assume the first devnode. For configurations that do not use |
| 29 | * spmi-dev-container, there is only one node to begin with, so NULL should |
| 30 | * be passed in this case. |
| 31 | * |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 32 | * Returns |
| 33 | * NULL on failure. |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 34 | */ |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 35 | struct resource *spmi_get_resource(struct spmi_device *dev, |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 36 | struct spmi_resource *node, |
| 37 | unsigned int type, unsigned int res_num) |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 38 | { |
| 39 | int i; |
| 40 | |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 41 | /* if a node is not specified, default to the first node */ |
| 42 | if (!node) |
| 43 | node = &dev->dev_node[0]; |
| 44 | |
| 45 | for (i = 0; i < node->num_resources; i++) { |
| 46 | struct resource *r = &node->resource[i]; |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 47 | |
| 48 | if (type == resource_type(r) && res_num-- == 0) |
| 49 | return r; |
| 50 | } |
| 51 | return NULL; |
| 52 | } |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 53 | EXPORT_SYMBOL_GPL(spmi_get_resource); |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 56 | * spmi_get_irq - get an IRQ for a device |
| 57 | * @dev: spmi device |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 58 | * @node: device node resource |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 59 | * @res_num: IRQ number index |
| 60 | * |
| 61 | * Returns |
| 62 | * -ENXIO on failure. |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 63 | */ |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 64 | int spmi_get_irq(struct spmi_device *dev, struct spmi_resource *node, |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 65 | unsigned int res_num) |
| 66 | { |
Michael Bohan | 0e5534d | 2012-05-22 17:33:45 -0700 | [diff] [blame^] | 67 | struct resource *r = spmi_get_resource(dev, node, |
Michael Bohan | c802017 | 2012-01-23 19:17:10 -0800 | [diff] [blame] | 68 | IORESOURCE_IRQ, res_num); |
| 69 | |
| 70 | return r ? r->start : -ENXIO; |
| 71 | } |
Michael Bohan | 08e1e90 | 2012-05-23 10:55:22 -0700 | [diff] [blame] | 72 | EXPORT_SYMBOL_GPL(spmi_get_irq); |