blob: a164efbe835594b2ae4a7373135e8e1a721194aa [file] [log] [blame]
Michael Bohanc8020172012-01-23 19:17:10 -08001/* 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 Mucklef132c6c2012-06-06 18:30:57 -070017#include <linux/export.h>
Michael Bohanc8020172012-01-23 19:17:10 -080018#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 */
26struct 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}
40EXPORT_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 */
47int 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}
55EXPORT_SYMBOL_GPL(qpnp_get_irq);
56