/* SPDX-License-Identifier: GPL-2.0 */ /* * ci.h - common structures, functions, and macros of the ChipIdea driver * * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. * * Author: David Lopo
*/
/** * struct ci_role_driver - host/gadget role driver * @start: start this role * @stop: stop this role * @suspend: system suspend handler for this role * @resume: system resume handler for this role * @irq: irq handler for this role * @name: role name string (host/gadget)
*/ struct ci_role_driver { int (*start)(struct ci_hdrc *); void (*stop)(struct ci_hdrc *); void (*suspend)(struct ci_hdrc *ci); void (*resume)(struct ci_hdrc *ci, bool power_lost);
irqreturn_t (*irq)(struct ci_hdrc *); constchar *name;
};
/** * struct hw_bank - hardware register mapping representation * @lpm: set if the device is LPM capable * @phys: physical address of the controller's registers * @abs: absolute address of the beginning of register window * @cap: capability registers * @op: operational registers * @size: size of the register window * @regmap: register lookup table
*/ struct hw_bank { unsigned lpm;
resource_size_t phys; void __iomem *abs; void __iomem *cap; void __iomem *op;
size_t size; void __iomem *regmap[OP_LAST + 1];
};
/** * struct ci_hdrc - chipidea device representation * @dev: pointer to parent device * @lock: access synchronization * @hw_bank: hardware register mapping * @irq: IRQ number * @roles: array of supported roles for this controller * @role: current role * @is_otg: if the device is otg-capable * @fsm: otg finite state machine * @otg_fsm_hrtimer: hrtimer for otg fsm timers * @hr_timeouts: time out list for active otg fsm timers * @enabled_otg_timer_bits: bits of enabled otg timers * @next_otg_timer: next nearest enabled timer to be expired * @work: work for role changing * @power_lost_work: work for power lost handling * @wq: workqueue thread * @qh_pool: allocation pool for queue heads * @td_pool: allocation pool for transfer descriptors * @gadget: device side representation for peripheral controller * @driver: gadget driver * @resume_state: save the state of gadget suspend from * @hw_ep_max: total number of endpoints supported by hardware * @ci_hw_ep: array of endpoints * @ep0_dir: ep0 direction * @ep0out: pointer to ep0 OUT endpoint * @ep0in: pointer to ep0 IN endpoint * @status: ep0 status request * @setaddr: if we should set the address on status completion * @address: usb address received from the host * @remote_wakeup: host-enabled remote wakeup * @suspended: suspended by host * @test_mode: the selected test mode * @platdata: platform specific information supplied by parent device * @vbus_active: is VBUS active * @ulpi: pointer to ULPI device, if any * @ulpi_ops: ULPI read/write ops for this device * @phy: pointer to PHY, if any * @usb_phy: pointer to USB PHY, if any and if using the USB PHY framework * @hcd: pointer to usb_hcd for ehci host driver * @id_event: indicates there is an id event, and handled at ci_otg_work * @b_sess_valid_event: indicates there is a vbus event, and handled * at ci_otg_work * @imx28_write_fix: Freescale imx28 needs swp instruction for writing * @supports_runtime_pm: if runtime pm is supported * @in_lpm: if the core in low power mode * @wakeup_int: if wakeup interrupt occur * @rev: The revision number for controller * @mutex: protect code from concorrent running when doing role switch
*/ struct ci_hdrc { struct device *dev;
spinlock_t lock; struct hw_bank hw_bank; int irq; struct ci_role_driver *roles[CI_ROLE_END]; enum ci_role role; bool is_otg; struct usb_otg otg; struct otg_fsm fsm; struct hrtimer otg_fsm_hrtimer;
ktime_t hr_timeouts[NUM_OTG_FSM_TIMERS]; unsigned enabled_otg_timer_bits; enum otg_fsm_timer next_otg_timer; struct usb_role_switch *role_switch; struct work_struct work; struct work_struct power_lost_work; struct workqueue_struct *wq;
staticinlineint ci_role_start(struct ci_hdrc *ci, enum ci_role role)
{ int ret;
if (role >= CI_ROLE_END) return -EINVAL;
if (!ci->roles[role]) return -ENXIO;
ret = ci->roles[role]->start(ci); if (ret) return ret;
ci->role = role;
if (ci->usb_phy) { if (role == CI_ROLE_HOST)
usb_phy_set_event(ci->usb_phy, USB_EVENT_ID); else /* in device mode but vbus is invalid*/
usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE);
}
return ret;
}
staticinlinevoid ci_role_stop(struct ci_hdrc *ci)
{ enum ci_role role = ci->role;
if (role == CI_ROLE_END) return;
ci->role = CI_ROLE_END;
ci->roles[role]->stop(ci);
if (ci->usb_phy)
usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE);
}
/** * hw_read_id_reg: reads from a identification register * @ci: the controller * @offset: offset from the beginning of identification registers region * @mask: bitfield mask * * This function returns register contents
*/ staticinline u32 hw_read_id_reg(struct ci_hdrc *ci, u32 offset, u32 mask)
{ return ioread32(ci->hw_bank.abs + offset) & mask;
}
/** * hw_write_id_reg: writes to a identification register * @ci: the controller * @offset: offset from the beginning of identification registers region * @mask: bitfield mask * @data: new value
*/ staticinlinevoid hw_write_id_reg(struct ci_hdrc *ci, u32 offset,
u32 mask, u32 data)
{ if (~mask)
data = (ioread32(ci->hw_bank.abs + offset) & ~mask)
| (data & mask);
iowrite32(data, ci->hw_bank.abs + offset);
}
/** * hw_read: reads from a hw register * @ci: the controller * @reg: register index * @mask: bitfield mask * * This function returns register contents
*/ staticinline u32 hw_read(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask)
{ return ioread32(ci->hw_bank.regmap[reg]) & mask;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.