blob: b692f82006c927963e734e7095caeadfd2acf04f [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 Bohan08e1e902012-05-23 10:55:22 -070018#include <linux/spmi.h>
Michael Bohanc8020172012-01-23 19:17:10 -080019
20/**
Michael Bohan08e1e902012-05-23 10:55:22 -070021 * spmi_get_resource - get a resource for a device
22 * @dev: spmi device
23 * @node_idx: dev_node index
Michael Bohanc8020172012-01-23 19:17:10 -080024 * @type: resource type
Michael Bohan08e1e902012-05-23 10:55:22 -070025 * @res_num: resource index
26 *
27 * Returns
28 * NULL on failure.
Michael Bohanc8020172012-01-23 19:17:10 -080029 */
Michael Bohan08e1e902012-05-23 10:55:22 -070030struct resource *spmi_get_resource(struct spmi_device *dev,
Michael Bohanc8020172012-01-23 19:17:10 -080031 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 Bohan08e1e902012-05-23 10:55:22 -070044EXPORT_SYMBOL_GPL(spmi_get_resource);
Michael Bohanc8020172012-01-23 19:17:10 -080045
46/**
Michael Bohan08e1e902012-05-23 10:55:22 -070047 * 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 Bohanc8020172012-01-23 19:17:10 -080054 */
Michael Bohan08e1e902012-05-23 10:55:22 -070055int spmi_get_irq(struct spmi_device *dev, unsigned int node_idx,
Michael Bohanc8020172012-01-23 19:17:10 -080056 unsigned int res_num)
57{
Michael Bohan08e1e902012-05-23 10:55:22 -070058 struct resource *r = spmi_get_resource(dev, node_idx,
Michael Bohanc8020172012-01-23 19:17:10 -080059 IORESOURCE_IRQ, res_num);
60
61 return r ? r->start : -ENXIO;
62}
Michael Bohan08e1e902012-05-23 10:55:22 -070063EXPORT_SYMBOL_GPL(spmi_get_irq);
Michael Bohanc8020172012-01-23 19:17:10 -080064