blob: ddf9000114a67a068b47921fd864389a53fee475 [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
17#include <mach/qpnp.h>
18
19/**
20 * qpnp_get_resource - get a resource for a device
21 * @dev: qpnp device
22 * @type: resource type
23 * @num: resource index
24 */
25struct resource *qpnp_get_resource(struct spmi_device *dev,
26 unsigned int node_idx, unsigned int type,
27 unsigned int res_num)
28{
29 int i;
30
31 for (i = 0; i < dev->dev_node[node_idx].num_resources; i++) {
32 struct resource *r = &dev->dev_node[node_idx].resource[i];
33
34 if (type == resource_type(r) && res_num-- == 0)
35 return r;
36 }
37 return NULL;
38}
39EXPORT_SYMBOL_GPL(qpnp_get_resource);
40
41/**
42 * qpnp_get_irq - get an IRQ for a device
43 * @dev: qpnp device
44 * @num: IRQ number index
45 */
46int qpnp_get_irq(struct spmi_device *dev, unsigned int node_idx,
47 unsigned int res_num)
48{
49 struct resource *r = qpnp_get_resource(dev, node_idx,
50 IORESOURCE_IRQ, res_num);
51
52 return r ? r->start : -ENXIO;
53}
54EXPORT_SYMBOL_GPL(qpnp_get_irq);
55