2 * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 * This file mainly handles OTG fsm, it includes OTG fsm operations
18 #include <linux/usb/otg.h>
19 #include <linux/usb/gadget.h>
20 #include <linux/usb/hcd.h>
21 #include <linux/usb/chipidea.h>
28 int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
32 otg = devm_kzalloc(ci->dev,
33 sizeof(struct usb_otg), GFP_KERNEL);
36 "Failed to allocate usb_otg structure for ci hdrc otg!\n");
40 otg->phy = ci->transceiver;
41 otg->gadget = &ci->gadget;
43 ci->transceiver->otg = ci->fsm.otg;
45 ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0;
46 ci->transceiver->state = OTG_STATE_UNDEFINED;
48 mutex_init(&ci->fsm.lock);
50 /* Enable A vbus valid irq */
51 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE);
55 hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1;
57 hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0;
59 hw_write_otgsc(ci, OTGSC_BSVIE, OTGSC_BSVIE);