Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * ci.h - common structures, functions, and macros of the ChipIdea driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. |
| 5 | * |
| 6 | * Author: David Lopo |
| 7 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __DRIVERS_USB_CHIPIDEA_CI_H |
| 14 | #define __DRIVERS_USB_CHIPIDEA_CI_H |
| 15 | |
| 16 | #include <linux/list.h> |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 17 | #include <linux/irqreturn.h> |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 18 | #include <linux/usb.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 19 | #include <linux/usb/gadget.h> |
Li Jun | 57677be | 2014-04-23 15:56:44 +0800 | [diff] [blame] | 20 | #include <linux/usb/otg-fsm.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 21 | |
| 22 | /****************************************************************************** |
| 23 | * DEFINE |
| 24 | *****************************************************************************/ |
Michael Grzeschik | b983e51 | 2013-03-30 12:54:10 +0200 | [diff] [blame] | 25 | #define TD_PAGE_COUNT 5 |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 26 | #define CI_HDRC_PAGE_SIZE 4096ul /* page size for TD's */ |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 27 | #define ENDPT_MAX 32 |
| 28 | |
| 29 | /****************************************************************************** |
Marc Kleine-Budde | 21395a1 | 2014-01-06 10:10:38 +0800 | [diff] [blame] | 30 | * REGISTERS |
| 31 | *****************************************************************************/ |
| 32 | /* register indices */ |
| 33 | enum ci_hw_regs { |
| 34 | CAP_CAPLENGTH, |
| 35 | CAP_HCCPARAMS, |
| 36 | CAP_DCCPARAMS, |
| 37 | CAP_TESTMODE, |
| 38 | CAP_LAST = CAP_TESTMODE, |
| 39 | OP_USBCMD, |
| 40 | OP_USBSTS, |
| 41 | OP_USBINTR, |
| 42 | OP_DEVICEADDR, |
| 43 | OP_ENDPTLISTADDR, |
| 44 | OP_PORTSC, |
| 45 | OP_DEVLC, |
| 46 | OP_OTGSC, |
| 47 | OP_USBMODE, |
| 48 | OP_ENDPTSETUPSTAT, |
| 49 | OP_ENDPTPRIME, |
| 50 | OP_ENDPTFLUSH, |
| 51 | OP_ENDPTSTAT, |
| 52 | OP_ENDPTCOMPLETE, |
| 53 | OP_ENDPTCTRL, |
| 54 | /* endptctrl1..15 follow */ |
| 55 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, |
| 56 | }; |
| 57 | |
| 58 | /****************************************************************************** |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 59 | * STRUCTURES |
| 60 | *****************************************************************************/ |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 61 | /** |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 62 | * struct ci_hw_ep - endpoint representation |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 63 | * @ep: endpoint structure for gadget drivers |
| 64 | * @dir: endpoint direction (TX/RX) |
| 65 | * @num: endpoint number |
| 66 | * @type: endpoint type |
| 67 | * @name: string description of the endpoint |
| 68 | * @qh: queue head for this endpoint |
| 69 | * @wedge: is the endpoint wedged |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 70 | * @ci: pointer to the controller |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 71 | * @lock: pointer to controller's spinlock |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 72 | * @td_pool: pointer to controller's TD pool |
| 73 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 74 | struct ci_hw_ep { |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 75 | struct usb_ep ep; |
| 76 | u8 dir; |
| 77 | u8 num; |
| 78 | u8 type; |
| 79 | char name[16]; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 80 | struct { |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 81 | struct list_head queue; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 82 | struct ci_hw_qh *ptr; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 83 | dma_addr_t dma; |
| 84 | } qh; |
| 85 | int wedge; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 86 | |
| 87 | /* global resources */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 88 | struct ci_hdrc *ci; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 89 | spinlock_t *lock; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 90 | struct dma_pool *td_pool; |
Michael Grzeschik | 2e27041 | 2013-06-13 17:59:54 +0300 | [diff] [blame] | 91 | struct td_node *pending_td; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 92 | }; |
| 93 | |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 94 | enum ci_role { |
| 95 | CI_ROLE_HOST = 0, |
| 96 | CI_ROLE_GADGET, |
| 97 | CI_ROLE_END, |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * struct ci_role_driver - host/gadget role driver |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 102 | * @start: start this role |
| 103 | * @stop: stop this role |
| 104 | * @irq: irq handler for this role |
| 105 | * @name: role name string (host/gadget) |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 106 | */ |
| 107 | struct ci_role_driver { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 108 | int (*start)(struct ci_hdrc *); |
| 109 | void (*stop)(struct ci_hdrc *); |
| 110 | irqreturn_t (*irq)(struct ci_hdrc *); |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 111 | const char *name; |
| 112 | }; |
| 113 | |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 114 | /** |
| 115 | * struct hw_bank - hardware register mapping representation |
| 116 | * @lpm: set if the device is LPM capable |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 117 | * @phys: physical address of the controller's registers |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 118 | * @abs: absolute address of the beginning of register window |
| 119 | * @cap: capability registers |
| 120 | * @op: operational registers |
| 121 | * @size: size of the register window |
| 122 | * @regmap: register lookup table |
| 123 | */ |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 124 | struct hw_bank { |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 125 | unsigned lpm; |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 126 | resource_size_t phys; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 127 | void __iomem *abs; |
| 128 | void __iomem *cap; |
| 129 | void __iomem *op; |
| 130 | size_t size; |
Marc Kleine-Budde | 21395a1 | 2014-01-06 10:10:38 +0800 | [diff] [blame] | 131 | void __iomem *regmap[OP_LAST + 1]; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 132 | }; |
| 133 | |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 134 | /** |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 135 | * struct ci_hdrc - chipidea device representation |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 136 | * @dev: pointer to parent device |
| 137 | * @lock: access synchronization |
| 138 | * @hw_bank: hardware register mapping |
| 139 | * @irq: IRQ number |
| 140 | * @roles: array of supported roles for this controller |
| 141 | * @role: current role |
| 142 | * @is_otg: if the device is otg-capable |
Li Jun | 57677be | 2014-04-23 15:56:44 +0800 | [diff] [blame] | 143 | * @fsm: otg finite state machine |
Li Jun | 826cfe7 | 2014-04-23 15:56:48 +0800 | [diff] [blame] | 144 | * @fsm_timer: pointer to timer list of otg fsm |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 145 | * @work: work for role changing |
| 146 | * @wq: workqueue thread |
| 147 | * @qh_pool: allocation pool for queue heads |
| 148 | * @td_pool: allocation pool for transfer descriptors |
| 149 | * @gadget: device side representation for peripheral controller |
| 150 | * @driver: gadget driver |
| 151 | * @hw_ep_max: total number of endpoints supported by hardware |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 152 | * @ci_hw_ep: array of endpoints |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 153 | * @ep0_dir: ep0 direction |
| 154 | * @ep0out: pointer to ep0 OUT endpoint |
| 155 | * @ep0in: pointer to ep0 IN endpoint |
| 156 | * @status: ep0 status request |
| 157 | * @setaddr: if we should set the address on status completion |
| 158 | * @address: usb address received from the host |
| 159 | * @remote_wakeup: host-enabled remote wakeup |
| 160 | * @suspended: suspended by host |
| 161 | * @test_mode: the selected test mode |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 162 | * @platdata: platform specific information supplied by parent device |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 163 | * @vbus_active: is VBUS active |
| 164 | * @transceiver: pointer to USB PHY, if any |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 165 | * @hcd: pointer to usb_hcd for ehci host driver |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 166 | * @debugfs: root dentry for this controller in debugfs |
Peter Chen | a107f8c | 2013-08-14 12:44:11 +0300 | [diff] [blame] | 167 | * @id_event: indicates there is an id event, and handled at ci_otg_work |
| 168 | * @b_sess_valid_event: indicates there is a vbus event, and handled |
| 169 | * at ci_otg_work |
Peter Chen | ed8f831 | 2014-01-10 13:51:27 +0800 | [diff] [blame] | 170 | * @imx28_write_fix: Freescale imx28 needs swp instruction for writing |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 171 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 172 | struct ci_hdrc { |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 173 | struct device *dev; |
| 174 | spinlock_t lock; |
| 175 | struct hw_bank hw_bank; |
| 176 | int irq; |
| 177 | struct ci_role_driver *roles[CI_ROLE_END]; |
| 178 | enum ci_role role; |
| 179 | bool is_otg; |
Li Jun | 57677be | 2014-04-23 15:56:44 +0800 | [diff] [blame] | 180 | struct otg_fsm fsm; |
Li Jun | 826cfe7 | 2014-04-23 15:56:48 +0800 | [diff] [blame] | 181 | struct ci_otg_fsm_timer_list *fsm_timer; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 182 | struct work_struct work; |
| 183 | struct workqueue_struct *wq; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 184 | |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 185 | struct dma_pool *qh_pool; |
| 186 | struct dma_pool *td_pool; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 187 | |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 188 | struct usb_gadget gadget; |
| 189 | struct usb_gadget_driver *driver; |
| 190 | unsigned hw_ep_max; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 191 | struct ci_hw_ep ci_hw_ep[ENDPT_MAX]; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 192 | u32 ep0_dir; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 193 | struct ci_hw_ep *ep0out, *ep0in; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 194 | |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 195 | struct usb_request *status; |
| 196 | bool setaddr; |
| 197 | u8 address; |
| 198 | u8 remote_wakeup; |
| 199 | u8 suspended; |
| 200 | u8 test_mode; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 201 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 202 | struct ci_hdrc_platform_data *platdata; |
Alexander Shishkin | 551a8ac | 2012-05-11 17:25:49 +0300 | [diff] [blame] | 203 | int vbus_active; |
| 204 | struct usb_phy *transceiver; |
Alexander Shishkin | eb70e5a | 2012-05-11 17:25:54 +0300 | [diff] [blame] | 205 | struct usb_hcd *hcd; |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 206 | struct dentry *debugfs; |
Peter Chen | a107f8c | 2013-08-14 12:44:11 +0300 | [diff] [blame] | 207 | bool id_event; |
| 208 | bool b_sess_valid_event; |
Peter Chen | ed8f831 | 2014-01-10 13:51:27 +0800 | [diff] [blame] | 209 | bool imx28_write_fix; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 210 | }; |
| 211 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 212 | static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 213 | { |
| 214 | BUG_ON(ci->role >= CI_ROLE_END || !ci->roles[ci->role]); |
| 215 | return ci->roles[ci->role]; |
| 216 | } |
| 217 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 218 | static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role) |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 219 | { |
| 220 | int ret; |
| 221 | |
| 222 | if (role >= CI_ROLE_END) |
| 223 | return -EINVAL; |
| 224 | |
| 225 | if (!ci->roles[role]) |
| 226 | return -ENXIO; |
| 227 | |
| 228 | ret = ci->roles[role]->start(ci); |
| 229 | if (!ret) |
| 230 | ci->role = role; |
| 231 | return ret; |
| 232 | } |
| 233 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 234 | static inline void ci_role_stop(struct ci_hdrc *ci) |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 235 | { |
| 236 | enum ci_role role = ci->role; |
| 237 | |
| 238 | if (role == CI_ROLE_END) |
| 239 | return; |
| 240 | |
| 241 | ci->role = CI_ROLE_END; |
| 242 | |
| 243 | ci->roles[role]->stop(ci); |
| 244 | } |
| 245 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 246 | /** |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 247 | * hw_read: reads from a hw register |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 248 | * @ci: the controller |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 249 | * @reg: register index |
| 250 | * @mask: bitfield mask |
| 251 | * |
| 252 | * This function returns register contents |
| 253 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 254 | static inline u32 hw_read(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 255 | { |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 256 | return ioread32(ci->hw_bank.regmap[reg]) & mask; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 257 | } |
| 258 | |
Peter Chen | ed8f831 | 2014-01-10 13:51:27 +0800 | [diff] [blame] | 259 | #ifdef CONFIG_SOC_IMX28 |
| 260 | static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr) |
| 261 | { |
| 262 | __asm__ ("swp %0, %0, [%1]" : : "r"(val), "r"(addr)); |
| 263 | } |
| 264 | #else |
| 265 | static inline void imx28_ci_writel(u32 val, volatile void __iomem *addr) |
| 266 | { |
| 267 | } |
| 268 | #endif |
| 269 | |
| 270 | static inline void __hw_write(struct ci_hdrc *ci, u32 val, |
| 271 | void __iomem *addr) |
| 272 | { |
| 273 | if (ci->imx28_write_fix) |
| 274 | imx28_ci_writel(val, addr); |
| 275 | else |
| 276 | iowrite32(val, addr); |
| 277 | } |
| 278 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 279 | /** |
| 280 | * hw_write: writes to a hw register |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 281 | * @ci: the controller |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 282 | * @reg: register index |
| 283 | * @mask: bitfield mask |
| 284 | * @data: new value |
| 285 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 286 | static inline void hw_write(struct ci_hdrc *ci, enum ci_hw_regs reg, |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 287 | u32 mask, u32 data) |
| 288 | { |
| 289 | if (~mask) |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 290 | data = (ioread32(ci->hw_bank.regmap[reg]) & ~mask) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 291 | | (data & mask); |
| 292 | |
Peter Chen | ed8f831 | 2014-01-10 13:51:27 +0800 | [diff] [blame] | 293 | __hw_write(ci, data, ci->hw_bank.regmap[reg]); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /** |
| 297 | * hw_test_and_clear: tests & clears a hw register |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 298 | * @ci: the controller |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 299 | * @reg: register index |
| 300 | * @mask: bitfield mask |
| 301 | * |
| 302 | * This function returns register contents |
| 303 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 304 | static inline u32 hw_test_and_clear(struct ci_hdrc *ci, enum ci_hw_regs reg, |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 305 | u32 mask) |
| 306 | { |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 307 | u32 val = ioread32(ci->hw_bank.regmap[reg]) & mask; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 308 | |
Peter Chen | ed8f831 | 2014-01-10 13:51:27 +0800 | [diff] [blame] | 309 | __hw_write(ci, val, ci->hw_bank.regmap[reg]); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 310 | return val; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * hw_test_and_write: tests & writes a hw register |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 315 | * @ci: the controller |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 316 | * @reg: register index |
| 317 | * @mask: bitfield mask |
| 318 | * @data: new value |
| 319 | * |
| 320 | * This function returns register contents |
| 321 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 322 | static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg, |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 323 | u32 mask, u32 data) |
| 324 | { |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 325 | u32 val = hw_read(ci, reg, ~0); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 326 | |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 327 | hw_write(ci, reg, mask, data); |
Felipe Balbi | 727b4dd | 2013-03-30 12:53:55 +0200 | [diff] [blame] | 328 | return (val & mask) >> __ffs(mask); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 329 | } |
| 330 | |
Li Jun | 57677be | 2014-04-23 15:56:44 +0800 | [diff] [blame] | 331 | /** |
| 332 | * ci_otg_is_fsm_mode: runtime check if otg controller |
| 333 | * is in otg fsm mode. |
Peter Chen | 1935388 | 2014-09-22 08:14:17 +0800 | [diff] [blame^] | 334 | * |
| 335 | * @ci: chipidea device |
Li Jun | 57677be | 2014-04-23 15:56:44 +0800 | [diff] [blame] | 336 | */ |
| 337 | static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci) |
| 338 | { |
| 339 | #ifdef CONFIG_USB_OTG_FSM |
| 340 | return ci->is_otg && ci->roles[CI_ROLE_HOST] && |
| 341 | ci->roles[CI_ROLE_GADGET]; |
| 342 | #else |
| 343 | return false; |
| 344 | #endif |
| 345 | } |
| 346 | |
Li Jun | 36304b0 | 2014-04-23 15:56:39 +0800 | [diff] [blame] | 347 | u32 hw_read_intr_enable(struct ci_hdrc *ci); |
| 348 | |
| 349 | u32 hw_read_intr_status(struct ci_hdrc *ci); |
| 350 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 351 | int hw_device_reset(struct ci_hdrc *ci, u32 mode); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 352 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 353 | int hw_port_test_set(struct ci_hdrc *ci, u8 mode); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 354 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 355 | u8 hw_port_test_get(struct ci_hdrc *ci); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 356 | |
Peter Chen | 22fa844 | 2013-08-14 12:44:12 +0300 | [diff] [blame] | 357 | int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask, |
| 358 | u32 value, unsigned int timeout_ms); |
| 359 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 360 | #endif /* __DRIVERS_USB_CHIPIDEA_CI_H */ |