summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/ssi.c
blob: a9d6eee1abba3559213ffeab2659bdf8f22dad02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * linux/arch/arm/mach-omap2/ssi.c
 *
 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
 *
 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/platform_data/hsi-omap-ssi.h>
#include "omap_hwmod.h"
#include "omap_device.h"
#include "omap-pm.h"

static struct omap_ssi_platform_data ssi_pdata = {
	.num_ports      = SSI_NUM_PORTS,
	.cawake_gpio    = {0},
	.get_dev_context_loss_count  = omap_pm_get_dev_context_loss_count,
};

int __init omap_ssi_config(struct omap_ssi_board_config *ssi_config)
{
	unsigned int port, offset, cawake_gpio;
	int err;

	ssi_pdata.num_ports = ssi_config->num_ports;

	for (port = 0, offset = 7; port < ssi_config->num_ports; port++, offset += 5) {
		cawake_gpio = ssi_config->cawake_gpio[port];
		if (!cawake_gpio)
			continue; /* Nothing to do */
		err = gpio_request(cawake_gpio, "cawake");
		if (err < 0)
			goto rback;
		gpio_direction_input(cawake_gpio);

		ssi_pdata.cawake_gpio[port] = ssi_config->cawake_gpio[port];
	}

	return 0;

rback:
	pr_err("omap-ssi: Request cawake (gpio%d) failed\n", cawake_gpio);
	while (port > 0)
		gpio_free(ssi_config->cawake_gpio[--port]);

	return err;
}

static int __init omap_ssi_init(void)
{
	struct omap_hwmod *oh;
	struct platform_device *pdev;

	oh = omap_hwmod_lookup("ssi");
	if (!oh)
		return -EINVAL;

	pdev = omap_device_build("omap_ssi", 0, oh, &ssi_pdata, sizeof(struct omap_ssi_platform_data));
	WARN(IS_ERR(pdev), "Can't build omap_device for omap_ssi\n");

	return 0;
}
subsys_initcall(omap_ssi_init);