summaryrefslogtreecommitdiff
path: root/drivers/otg/hardware/mxc91321-gpio.c
blob: df925771a05c7185a6666d8e0de0a2f37a9b47b7 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */
/*
 * otg/hardware/mxc91321-gpio.c - Freescale USBOTG ArgonLV gpio and iomux setting
 * @(#) sp/root@belcarra.com/debian-black.(none)|otg/platform/mxc/mxc91321-gpio.c|20070822230929|24222
 *
 *      Copyright (c) 2004-2005 Belcarra Technologies Corp
 *      Copyright (c) 2005-2007 Belcarra Technologies 2005 Corp
 *
 * By:
 *      Stuart Lynne <sl@belcarra.com>,
 *      Bruce Balden <balden@belcarra.com>,
 *      Shahrad Payandeh <sp@belcarra.com>
 */
/*!
 * @file otg/hardware/mxc91321-gpio.c
 * @brief Freescale USB Host Controller Driver
 *
 * @ingroup FSOTG
 */

#include <linux/irq.h>
#include <otg/pcd-include.h>
#include <../arch/arm/mach-mxc91321/iomux.h>

#if defined(CONFIG_OTG_ZASEVB_MC13783_CONNECTIVITY) || defined(CONFIG_OTG_ZASEVB_MC13783_PMIC)
#include <asm/arch/gpio.h>
#include "mxc-lnx.h"
#include "mxc-hardware.h"
#include "isp1301.h"
#include "isp1301-hardware.h"
#endif

#if defined(CONFIG_OTG_ZASEVB_ISP1301)
#include <asm/arch/gpio.h>
#include "mxc-lnx.h"
#include "mxc-hardware.h"
#include "isp1301.h"
#include "isp1301-hardware.h"
#endif

#define ZGPIO_PORT 0
#define ZGPIO_PIN  2


#if defined(CONFIG_OTG_ZASEVB_ISP1301) || defined(_OTG_DOXYGEN)

BOOL zasevb_int_disabled = FALSE;
/* ********************************************************************************************* */
/*!
 * zasevb_gpio_int_hndlr() - gpio interrupt handler
 * @param irq
 * @param dev_id
 * @param regs
 * @return interrupt handler status
 * This disables the gpio interrup and schedules the isp1301 bottom half handler.
 *
 */
static irqreturn_t zasevb_gpio_int_hndlr (int irq, void *dev_id, struct pt_regs *regs)
{
        disable_irq(IOMUX_TO_IRQ(PIN_GPIO2));
        zasevb_int_disabled = TRUE;

        TRACE_MSG0(REMOVE_TCD, "ZASEVB GPIO INTERRUPT: SCHEDULE WORK");
        //        printk(KERN_INFO"%s:\n", __FUNCTION__);
        isp1301_bh_wakeup(REMOVE_tcd_instance->otg, FALSE);

        return IRQ_HANDLED;
}

/*!
 * zasevb_isp1301_bh()- call isp1301 bottom half handler
 * @param arg
 * This is a wrapper to the isp1301 bottom half handler, it
 * re-enables the gpio interrupt after processing complete.
 */
void *zasevb_isp1301_bh(void *arg)
{
        TRACE_MSG0(REMOVE_TCD, "ZASEVB GPIO INTERRUPT: ISP1301_BH");
        isp1301_bh(arg);
        TRACE_MSG0(REMOVE_TCD, "ZASEVB GPIO INTERRUPT: REENABLE");

        if (zasevb_int_disabled) {
                zasevb_int_disabled = FALSE;
                enable_irq(IOMUX_TO_IRQ(PIN_GPIO2));
        }
        return NULL;
}



/*! mxc_iomux_gpio_isp1301_set
 * This function set iomux settings depends on platform and usb mode.
 *
 * @param otg - otg instance
 * @param  usb_mode     setting usb mode.
 *
 */

int mxc_iomux_gpio_isp1301_set (struct otg_instance *otg, int usb_mode)
{

        int gpio = 1;

        printk (KERN_INFO"MXC gpio setting for isp1301\n");

        isp1301_mod_init(otg, &zasevb_isp1301_bh);

        TRACE_MSG0(REMOVE_TCD, "5. IOMUX and GPIO Interrupt Configuration");
        iomux_config_mux(PIN_GPIO2, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);

        //Setting interrupt for ISP1301
        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
        set_irq_type(IOMUX_TO_IRQ(PIN_GPIO2), IRQF_TRIGGER_FALLING);
        #else
        set_irq_type(IOMUX_TO_IRQ(PIN_GPIO2), IRQT_FALLING);
        #endif
        gpio = request_irq(IOMUX_TO_IRQ(PIN_GPIO2), zasevb_gpio_int_hndlr,
                        0, "ISP1301", (void *)&ocd_ops);
        THROW_IF(gpio, error);


        iomux_config_mux(PIN_USB_XRXD,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_TXENB, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);



        CATCH(error) {
                printk(KERN_INFO"%s: failed\n", __FUNCTION__);
                UNLESS (gpio) gpio_free_irq (ZGPIO_PORT, ZGPIO_PIN, GPIO_HIGH_PRIO);
                return -EINVAL;
        }

        return 0;
}
/*! mxc_iomux_gpio_isp1301_reset - clear isp1301 iomux settings
 */
int mxc_iomux_gpio_isp1301_reset (void)
{
        free_irq(IOMUX_TO_IRQ(PIN_GPIO2), &ocd_ops);
        return 0;
}

#endif  //CONFIG_OTG_ZASEVB_ISP1301



#if defined(CONFIG_OTG_ZASEVB_MC13783_CONNECTIVITY) || defined(CONFIG_OTG_ZASEVB_MC13783_PMIC)
/*! mxc_iomux_gpio_mc13783_set - set mc13783 iomux settings
 * @param usb_mode
 * @return 0
 */
int mxc_iomux_gpio_mc13783_set (int usb_mode)
{

        printk (KERN_INFO"MXC gpio setting for Atlas\n");

        printk(KERN_INFO"IOMUX setting for Argon+\n");
        iomux_config_mux(PIN_USB_XRXD,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_TXENB, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);


        return 0;
}

/*! mxc_iomux_gpio_mc13783_reset - clear mc13783 iomux settings
 */
int mxc_iomux_gpio_mc13783_reset (void)
{

        iomux_config_mux(PIN_USB_XRXD,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPOUT, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VPIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_TXENB, OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);
        iomux_config_mux(PIN_USB_VMIN,  OUTPUTCONFIG_FUNC, INPUTCONFIG_FUNC);

        return 0;
}
#endif  //CONFIG_OTG_ZASEVB_MC13783_CONNECTIVITY


int mxc_host_gpio (void)
{
        iomux_config_mux(PIN_GPIO5,  OUTPUTCONFIG_ALT1, INPUTCONFIG_ALT1);      // USB1_OC
        printk(KERN_INFO"%s: NONE/GPIO\n", __FUNCTION__);
        return 0;
}

#if defined(CONFIG_OTG_ZASEVB_ISP1301)
OTG_EXPORT_SYMBOL(mxc_iomux_gpio_isp1301_set);
OTG_EXPORT_SYMBOL(mxc_iomux_gpio_isp1301_reset);
#endif
#if defined(CONFIG_OTG_ZASEVB_MC13783_CONNECTIVITY) || defined(CONFIG_OTG_ZASEVB_MC13783_PMIC)
OTG_EXPORT_SYMBOL(mxc_iomux_gpio_mc13783_set);
OTG_EXPORT_SYMBOL(mxc_iomux_gpio_mc13783_reset);
#endif

OTG_EXPORT_SYMBOL(mxc_host_gpio);