blob: 54dd2b16c80b4ad94311df81846ab9322cfd9d2f [file] [log] [blame]
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +01001/*
2 * drivers/usb/otg/ab8500_usb.c
3 *
4 * USB transceiver driver for AB8500 chip
5 *
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/usb/otg.h>
28#include <linux/slab.h>
29#include <linux/notifier.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
Mian Yousaf Kaukabd0ed0642013-05-15 14:03:26 +020032#include <linux/clk.h>
33#include <linux/err.h>
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010034#include <linux/mfd/abx500.h>
Linus Walleijee66e652011-12-02 14:16:33 +010035#include <linux/mfd/abx500/ab8500.h>
Fabio Baltieriaf6882b2013-03-08 10:27:09 +080036#include <linux/usb/musb-ux500.h>
Fabio Baltierie65b36c2013-04-03 10:45:06 +020037#include <linux/regulator/consumer.h>
Patrice Chotard899f0f52013-04-03 10:45:11 +020038#include <linux/pinctrl/consumer.h>
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010039
Sakethram Bommisetti71246312013-04-03 10:45:04 +020040/* Bank AB8500_SYS_CTRL2_BLOCK */
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010041#define AB8500_MAIN_WD_CTRL_REG 0x01
Sakethram Bommisetti71246312013-04-03 10:45:04 +020042
43/* Bank AB8500_USB */
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010044#define AB8500_USB_LINE_STAT_REG 0x80
Fabio Baltieriaf6882b2013-03-08 10:27:09 +080045#define AB8505_USB_LINE_STAT_REG 0x94
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010046#define AB8500_USB_PHY_CTRL_REG 0x8A
47
Sakethram Bommisetti71246312013-04-03 10:45:04 +020048/* Bank AB8500_DEVELOPMENT */
49#define AB8500_BANK12_ACCESS 0x00
50
51/* Bank AB8500_DEBUG */
52#define AB8500_USB_PHY_TUNE1 0x05
53#define AB8500_USB_PHY_TUNE2 0x06
54#define AB8500_USB_PHY_TUNE3 0x07
55
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010056#define AB8500_BIT_OTG_STAT_ID (1 << 0)
57#define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
58#define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
59#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
60#define AB8500_BIT_WD_CTRL_KICK (1 << 1)
61
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010062#define AB8500_WD_KICK_DELAY_US 100 /* usec */
63#define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
Fabio Baltieriaf6882b2013-03-08 10:27:09 +080064#define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +010065
66/* Usb line status register */
67enum ab8500_usb_link_status {
Fabio Baltieriaf6882b2013-03-08 10:27:09 +080068 USB_LINK_NOT_CONFIGURED_8500 = 0,
69 USB_LINK_STD_HOST_NC_8500,
70 USB_LINK_STD_HOST_C_NS_8500,
71 USB_LINK_STD_HOST_C_S_8500,
72 USB_LINK_HOST_CHG_NM_8500,
73 USB_LINK_HOST_CHG_HS_8500,
74 USB_LINK_HOST_CHG_HS_CHIRP_8500,
75 USB_LINK_DEDICATED_CHG_8500,
76 USB_LINK_ACA_RID_A_8500,
77 USB_LINK_ACA_RID_B_8500,
78 USB_LINK_ACA_RID_C_NM_8500,
79 USB_LINK_ACA_RID_C_HS_8500,
80 USB_LINK_ACA_RID_C_HS_CHIRP_8500,
81 USB_LINK_HM_IDGND_8500,
82 USB_LINK_RESERVED_8500,
83 USB_LINK_NOT_VALID_LINK_8500,
84};
85
86enum ab8505_usb_link_status {
87 USB_LINK_NOT_CONFIGURED_8505 = 0,
88 USB_LINK_STD_HOST_NC_8505,
89 USB_LINK_STD_HOST_C_NS_8505,
90 USB_LINK_STD_HOST_C_S_8505,
91 USB_LINK_CDP_8505,
92 USB_LINK_RESERVED0_8505,
93 USB_LINK_RESERVED1_8505,
94 USB_LINK_DEDICATED_CHG_8505,
95 USB_LINK_ACA_RID_A_8505,
96 USB_LINK_ACA_RID_B_8505,
97 USB_LINK_ACA_RID_C_NM_8505,
98 USB_LINK_RESERVED2_8505,
99 USB_LINK_RESERVED3_8505,
100 USB_LINK_HM_IDGND_8505,
101 USB_LINK_CHARGERPORT_NOT_OK_8505,
102 USB_LINK_CHARGER_DM_HIGH_8505,
103 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505,
104 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505,
105 USB_LINK_STD_UPSTREAM_8505,
106 USB_LINK_CHARGER_SE1_8505,
107 USB_LINK_CARKIT_CHGR_1_8505,
108 USB_LINK_CARKIT_CHGR_2_8505,
109 USB_LINK_ACA_DOCK_CHGR_8505,
110 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505,
111 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505,
112 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505,
113 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505,
114 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505,
115};
116
117enum ab8500_usb_mode {
118 USB_IDLE = 0,
119 USB_PERIPHERAL,
120 USB_HOST,
121 USB_DEDICATED_CHG
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100122};
123
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200124/* Register USB_LINK_STATUS interrupt */
125#define AB8500_USB_FLAG_USE_LINK_STATUS_IRQ (1 << 0)
126/* Register ID_WAKEUP_F interrupt */
127#define AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ (1 << 1)
128/* Register VBUS_DET_F interrupt */
129#define AB8500_USB_FLAG_USE_VBUS_DET_IRQ (1 << 2)
130/* Driver is using the ab-iddet driver*/
131#define AB8500_USB_FLAG_USE_AB_IDDET (1 << 3)
132/* Enable setting regulators voltage */
133#define AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE (1 << 4)
134
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100135struct ab8500_usb {
Heikki Krogerus144713f2012-02-13 13:24:05 +0200136 struct usb_phy phy;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100137 struct device *dev;
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800138 struct ab8500 *ab8500;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100139 unsigned vbus_draw;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100140 struct work_struct phy_dis_work;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800141 enum ab8500_usb_mode mode;
Mian Yousaf Kaukabd0ed0642013-05-15 14:03:26 +0200142 struct clk *sysclk;
Fabio Baltierie65b36c2013-04-03 10:45:06 +0200143 struct regulator *v_ape;
144 struct regulator *v_musb;
145 struct regulator *v_ulpi;
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200146 int saved_v_ulpi;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800147 int previous_link_status_state;
Patrice Chotard899f0f52013-04-03 10:45:11 +0200148 struct pinctrl *pinctrl;
149 struct pinctrl_state *pins_sleep;
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200150 unsigned int flags;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100151};
152
Heikki Krogerus144713f2012-02-13 13:24:05 +0200153static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100154{
Heikki Krogerus144713f2012-02-13 13:24:05 +0200155 return container_of(x, struct ab8500_usb, phy);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100156}
157
158static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
159{
160 abx500_set_register_interruptible(ab->dev,
161 AB8500_SYS_CTRL2_BLOCK,
162 AB8500_MAIN_WD_CTRL_REG,
163 AB8500_BIT_WD_CTRL_ENABLE);
164
165 udelay(AB8500_WD_KICK_DELAY_US);
166
167 abx500_set_register_interruptible(ab->dev,
168 AB8500_SYS_CTRL2_BLOCK,
169 AB8500_MAIN_WD_CTRL_REG,
170 (AB8500_BIT_WD_CTRL_ENABLE
171 | AB8500_BIT_WD_CTRL_KICK));
172
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800173 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100174
175 abx500_set_register_interruptible(ab->dev,
176 AB8500_SYS_CTRL2_BLOCK,
177 AB8500_MAIN_WD_CTRL_REG,
178 0);
179}
180
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200181static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
182{
183 int ret, volt;
184
Fabio Baltieri88b1c782013-04-03 16:02:25 +0200185 ret = regulator_enable(ab->v_ape);
186 if (ret)
187 dev_err(ab->dev, "Failed to enable v-ape\n");
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200188
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200189 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200190 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi);
191 if (ab->saved_v_ulpi < 0)
192 dev_err(ab->dev, "Failed to get v_ulpi voltage\n");
193
194 ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000);
195 if (ret < 0)
196 dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
197 ret);
198
199 ret = regulator_set_optimum_mode(ab->v_ulpi, 28000);
200 if (ret < 0)
201 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
202 ret);
203 }
204
Fabio Baltieri88b1c782013-04-03 16:02:25 +0200205 ret = regulator_enable(ab->v_ulpi);
206 if (ret)
207 dev_err(ab->dev, "Failed to enable vddulpivio18\n");
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200208
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200209 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200210 volt = regulator_get_voltage(ab->v_ulpi);
211 if ((volt != 1300000) && (volt != 1350000))
212 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n",
213 volt);
214 }
215
Fabio Baltieri88b1c782013-04-03 16:02:25 +0200216 ret = regulator_enable(ab->v_musb);
217 if (ret)
218 dev_err(ab->dev, "Failed to enable musb_1v8\n");
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200219}
220
221static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
222{
223 int ret;
224
225 regulator_disable(ab->v_musb);
226
227 regulator_disable(ab->v_ulpi);
228
229 /* USB is not the only consumer of Vintcore, restore old settings */
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200230 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) {
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200231 if (ab->saved_v_ulpi > 0) {
232 ret = regulator_set_voltage(ab->v_ulpi,
233 ab->saved_v_ulpi, ab->saved_v_ulpi);
234 if (ret < 0)
235 dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n",
236 ab->saved_v_ulpi, ret);
237 }
238
239 ret = regulator_set_optimum_mode(ab->v_ulpi, 0);
240 if (ret < 0)
241 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
242 ret);
243 }
244
245 regulator_disable(ab->v_ape);
246}
247
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800248static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit)
249{
250 /* Workaround for v2.0 bug # 31952 */
251 if (is_ab8500_2p0(ab->ab8500)) {
252 abx500_mask_and_set_register_interruptible(ab->dev,
253 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
254 bit, bit);
255 udelay(AB8500_V20_31952_DISABLE_DELAY_US);
256 }
257}
258
Fabio Baltieric0ea7062013-04-03 10:45:07 +0200259static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100260{
Fabio Baltieric0ea7062013-04-03 10:45:07 +0200261 u8 bit;
262 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
263 AB8500_BIT_PHY_CTRL_DEVICE_EN;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100264
Patrice Chotard899f0f52013-04-03 10:45:11 +0200265 /* mux and configure USB pins to DEFAULT state */
266 ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT);
267 if (IS_ERR(ab->pinctrl))
268 dev_err(ab->dev, "could not get/set default pinstate\n");
269
Mian Yousaf Kaukabd0ed0642013-05-15 14:03:26 +0200270 if (clk_prepare_enable(ab->sysclk))
271 dev_err(ab->dev, "can't prepare/enable clock\n");
272
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200273 ab8500_usb_regulator_enable(ab);
274
Fabio Baltieric0ea7062013-04-03 10:45:07 +0200275 abx500_mask_and_set_register_interruptible(ab->dev,
276 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
277 bit, bit);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100278}
279
Fabio Baltieric0ea7062013-04-03 10:45:07 +0200280static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host)
281{
282 u8 bit;
283 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
284 AB8500_BIT_PHY_CTRL_DEVICE_EN;
285
286 ab8500_usb_wd_linkstatus(ab, bit);
287
288 abx500_mask_and_set_register_interruptible(ab->dev,
289 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
290 bit, 0);
291
292 /* Needed to disable the phy.*/
293 ab8500_usb_wd_workaround(ab);
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200294
Mian Yousaf Kaukabd0ed0642013-05-15 14:03:26 +0200295 clk_disable_unprepare(ab->sysclk);
296
Fabio Baltieri54dfbb02013-04-03 10:45:08 +0200297 ab8500_usb_regulator_disable(ab);
Patrice Chotard899f0f52013-04-03 10:45:11 +0200298
299 if (!IS_ERR(ab->pinctrl)) {
300 /* configure USB pins to SLEEP state */
301 ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl,
302 PINCTRL_STATE_SLEEP);
303
304 if (IS_ERR(ab->pins_sleep))
305 dev_dbg(ab->dev, "could not get sleep pinstate\n");
306 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep))
307 dev_err(ab->dev, "could not set pins to sleep state\n");
308
Fabio Baltieri3147dad2013-05-15 14:03:25 +0200309 /*
310 * as USB pins are shared with iddet, release them to allow
Patrice Chotard899f0f52013-04-03 10:45:11 +0200311 * iddet to request them
312 */
313 pinctrl_put(ab->pinctrl);
314 }
Fabio Baltieric0ea7062013-04-03 10:45:07 +0200315}
316
317#define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
318#define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
319#define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
320#define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100321
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800322static int ab8505_usb_link_status_update(struct ab8500_usb *ab,
323 enum ab8505_usb_link_status lsts)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100324{
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800325 enum ux500_musb_vbus_id_status event = 0;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100326
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800327 dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100328
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800329 /*
330 * Spurious link_status interrupts are seen at the time of
331 * disconnection of a device in RIDA state
332 */
333 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 &&
334 (lsts == USB_LINK_STD_HOST_NC_8505))
335 return 0;
336
337 ab->previous_link_status_state = lsts;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100338
339 switch (lsts) {
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800340 case USB_LINK_ACA_RID_B_8505:
341 event = UX500_MUSB_RIDB;
342 case USB_LINK_NOT_CONFIGURED_8505:
343 case USB_LINK_RESERVED0_8505:
344 case USB_LINK_RESERVED1_8505:
345 case USB_LINK_RESERVED2_8505:
346 case USB_LINK_RESERVED3_8505:
347 ab->mode = USB_IDLE;
Heikki Krogerus144713f2012-02-13 13:24:05 +0200348 ab->phy.otg->default_a = false;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100349 ab->vbus_draw = 0;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800350 if (event != UX500_MUSB_RIDB)
351 event = UX500_MUSB_NONE;
352 /*
353 * Fallback to default B_IDLE as nothing
354 * is connected
355 */
356 ab->phy.state = OTG_STATE_B_IDLE;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100357 break;
358
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800359 case USB_LINK_ACA_RID_C_NM_8505:
360 event = UX500_MUSB_RIDC;
361 case USB_LINK_STD_HOST_NC_8505:
362 case USB_LINK_STD_HOST_C_NS_8505:
363 case USB_LINK_STD_HOST_C_S_8505:
364 case USB_LINK_CDP_8505:
365 if (ab->mode == USB_IDLE) {
366 ab->mode = USB_PERIPHERAL;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100367 ab8500_usb_peri_phy_en(ab);
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800368 atomic_notifier_call_chain(&ab->phy.notifier,
369 UX500_MUSB_PREPARE, &ab->vbus_draw);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100370 }
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800371 if (event != UX500_MUSB_RIDC)
372 event = UX500_MUSB_VBUS;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100373 break;
374
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800375 case USB_LINK_ACA_RID_A_8505:
376 case USB_LINK_ACA_DOCK_CHGR_8505:
377 event = UX500_MUSB_RIDA;
378 case USB_LINK_HM_IDGND_8505:
379 if (ab->mode == USB_IDLE) {
380 ab->mode = USB_HOST;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100381 ab8500_usb_host_phy_en(ab);
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800382 atomic_notifier_call_chain(&ab->phy.notifier,
383 UX500_MUSB_PREPARE, &ab->vbus_draw);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100384 }
Heikki Krogerus144713f2012-02-13 13:24:05 +0200385 ab->phy.otg->default_a = true;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800386 if (event != UX500_MUSB_RIDA)
387 event = UX500_MUSB_ID;
388 atomic_notifier_call_chain(&ab->phy.notifier,
389 event, &ab->vbus_draw);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100390 break;
391
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800392 case USB_LINK_DEDICATED_CHG_8505:
393 ab->mode = USB_DEDICATED_CHG;
394 event = UX500_MUSB_CHARGER;
395 atomic_notifier_call_chain(&ab->phy.notifier,
396 event, &ab->vbus_draw);
397 break;
398
399 default:
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100400 break;
401 }
402
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800403 return 0;
404}
405
406static int ab8500_usb_link_status_update(struct ab8500_usb *ab,
407 enum ab8500_usb_link_status lsts)
408{
409 enum ux500_musb_vbus_id_status event = 0;
410
411 dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts);
412
413 /*
414 * Spurious link_status interrupts are seen in case of a
415 * disconnection of a device in IDGND and RIDA stage
416 */
417 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 &&
418 (lsts == USB_LINK_STD_HOST_C_NS_8500 ||
419 lsts == USB_LINK_STD_HOST_NC_8500))
420 return 0;
421
422 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 &&
423 lsts == USB_LINK_STD_HOST_NC_8500)
424 return 0;
425
426 ab->previous_link_status_state = lsts;
427
428 switch (lsts) {
429 case USB_LINK_ACA_RID_B_8500:
430 event = UX500_MUSB_RIDB;
431 case USB_LINK_NOT_CONFIGURED_8500:
432 case USB_LINK_NOT_VALID_LINK_8500:
433 ab->mode = USB_IDLE;
434 ab->phy.otg->default_a = false;
435 ab->vbus_draw = 0;
436 if (event != UX500_MUSB_RIDB)
437 event = UX500_MUSB_NONE;
438 /* Fallback to default B_IDLE as nothing is connected */
439 ab->phy.state = OTG_STATE_B_IDLE;
440 break;
441
442 case USB_LINK_ACA_RID_C_NM_8500:
443 case USB_LINK_ACA_RID_C_HS_8500:
444 case USB_LINK_ACA_RID_C_HS_CHIRP_8500:
445 event = UX500_MUSB_RIDC;
446 case USB_LINK_STD_HOST_NC_8500:
447 case USB_LINK_STD_HOST_C_NS_8500:
448 case USB_LINK_STD_HOST_C_S_8500:
449 case USB_LINK_HOST_CHG_NM_8500:
450 case USB_LINK_HOST_CHG_HS_8500:
451 case USB_LINK_HOST_CHG_HS_CHIRP_8500:
452 if (ab->mode == USB_IDLE) {
453 ab->mode = USB_PERIPHERAL;
454 ab8500_usb_peri_phy_en(ab);
455 atomic_notifier_call_chain(&ab->phy.notifier,
456 UX500_MUSB_PREPARE, &ab->vbus_draw);
457 }
458 if (event != UX500_MUSB_RIDC)
459 event = UX500_MUSB_VBUS;
460 break;
461
462 case USB_LINK_ACA_RID_A_8500:
463 event = UX500_MUSB_RIDA;
464 case USB_LINK_HM_IDGND_8500:
465 if (ab->mode == USB_IDLE) {
466 ab->mode = USB_HOST;
467 ab8500_usb_host_phy_en(ab);
468 atomic_notifier_call_chain(&ab->phy.notifier,
469 UX500_MUSB_PREPARE, &ab->vbus_draw);
470 }
471 ab->phy.otg->default_a = true;
472 if (event != UX500_MUSB_RIDA)
473 event = UX500_MUSB_ID;
474 atomic_notifier_call_chain(&ab->phy.notifier,
475 event, &ab->vbus_draw);
476 break;
477
478 case USB_LINK_DEDICATED_CHG_8500:
479 ab->mode = USB_DEDICATED_CHG;
480 event = UX500_MUSB_CHARGER;
481 atomic_notifier_call_chain(&ab->phy.notifier,
482 event, &ab->vbus_draw);
483 break;
484
485 case USB_LINK_RESERVED_8500:
486 break;
487 }
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100488
489 return 0;
490}
491
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800492/*
493 * Connection Sequence:
494 * 1. Link Status Interrupt
495 * 2. Enable AB clock
496 * 3. Enable AB regulators
497 * 4. Enable USB phy
498 * 5. Reset the musb controller
499 * 6. Switch the ULPI GPIO pins to fucntion mode
500 * 7. Enable the musb Peripheral5 clock
501 * 8. Restore MUSB context
502 */
503static int abx500_usb_link_status_update(struct ab8500_usb *ab)
504{
505 u8 reg;
506 int ret = 0;
507
508 if (is_ab8500(ab->ab8500)) {
509 enum ab8500_usb_link_status lsts;
510
511 abx500_get_register_interruptible(ab->dev,
512 AB8500_USB, AB8500_USB_LINE_STAT_REG, &reg);
513 lsts = (reg >> 3) & 0x0F;
514 ret = ab8500_usb_link_status_update(ab, lsts);
515 } else if (is_ab8505(ab->ab8500)) {
516 enum ab8505_usb_link_status lsts;
517
518 abx500_get_register_interruptible(ab->dev,
519 AB8500_USB, AB8505_USB_LINE_STAT_REG, &reg);
520 lsts = (reg >> 3) & 0x1F;
521 ret = ab8505_usb_link_status_update(ab, lsts);
522 }
523
524 return ret;
525}
526
527/*
528 * Disconnection Sequence:
529 * 1. Disconect Interrupt
530 * 2. Disable regulators
531 * 3. Disable AB clock
532 * 4. Disable the Phy
533 * 5. Link Status Interrupt
534 * 6. Disable Musb Clock
535 */
536static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data)
537{
538 struct ab8500_usb *ab = (struct ab8500_usb *) data;
539 enum usb_phy_events event = UX500_MUSB_NONE;
540
541 /* Link status will not be updated till phy is disabled. */
542 if (ab->mode == USB_HOST) {
543 ab->phy.otg->default_a = false;
544 ab->vbus_draw = 0;
545 atomic_notifier_call_chain(&ab->phy.notifier,
546 event, &ab->vbus_draw);
547 ab8500_usb_host_phy_dis(ab);
548 ab->mode = USB_IDLE;
549 }
550
551 if (ab->mode == USB_PERIPHERAL) {
552 atomic_notifier_call_chain(&ab->phy.notifier,
553 event, &ab->vbus_draw);
554 ab8500_usb_peri_phy_dis(ab);
555 atomic_notifier_call_chain(&ab->phy.notifier,
556 UX500_MUSB_CLEAN, &ab->vbus_draw);
557 ab->mode = USB_IDLE;
558 ab->phy.otg->default_a = false;
559 ab->vbus_draw = 0;
560 }
561
562 if (is_ab8500_2p0(ab->ab8500)) {
563 if (ab->mode == USB_DEDICATED_CHG) {
564 ab8500_usb_wd_linkstatus(ab,
565 AB8500_BIT_PHY_CTRL_DEVICE_EN);
566 abx500_mask_and_set_register_interruptible(ab->dev,
567 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
568 AB8500_BIT_PHY_CTRL_DEVICE_EN, 0);
569 }
570 }
571
572 return IRQ_HANDLED;
573}
574
575static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data)
576{
Fabio Baltieri3147dad2013-05-15 14:03:25 +0200577 struct ab8500_usb *ab = (struct ab8500_usb *)data;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800578
579 abx500_usb_link_status_update(ab);
580
581 return IRQ_HANDLED;
582}
583
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100584static void ab8500_usb_phy_disable_work(struct work_struct *work)
585{
586 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
587 phy_dis_work);
588
Heikki Krogerus144713f2012-02-13 13:24:05 +0200589 if (!ab->phy.otg->host)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100590 ab8500_usb_host_phy_dis(ab);
591
Heikki Krogerus144713f2012-02-13 13:24:05 +0200592 if (!ab->phy.otg->gadget)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100593 ab8500_usb_peri_phy_dis(ab);
594}
595
Sakethram Bommisettic2a0ab62013-04-03 10:45:05 +0200596static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA)
597{
598 /*
599 * AB8500 V2 has eye diagram issues when drawing more than 100mA from
600 * VBUS. Set charging current to 100mA in case of standard host
601 */
602 if (is_ab8500_2p0_or_earlier(ab->ab8500))
603 if (mA > 100)
604 mA = 100;
605
606 return mA;
607}
608
Heikki Krogerus144713f2012-02-13 13:24:05 +0200609static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100610{
611 struct ab8500_usb *ab;
612
Heikki Krogerus144713f2012-02-13 13:24:05 +0200613 if (!phy)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100614 return -ENODEV;
615
Heikki Krogerus144713f2012-02-13 13:24:05 +0200616 ab = phy_to_ab(phy);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100617
Sakethram Bommisettic2a0ab62013-04-03 10:45:05 +0200618 mA = ab8500_eyediagram_workaroud(ab, mA);
619
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100620 ab->vbus_draw = mA;
621
Fabio Baltieri77f43962013-04-03 10:45:10 +0200622 atomic_notifier_call_chain(&ab->phy.notifier,
623 UX500_MUSB_VBUS, &ab->vbus_draw);
624
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100625 return 0;
626}
627
Heikki Krogerus86753812012-02-13 13:24:02 +0200628static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100629{
630 /* TODO */
631 return 0;
632}
633
Heikki Krogerus144713f2012-02-13 13:24:05 +0200634static int ab8500_usb_set_peripheral(struct usb_otg *otg,
635 struct usb_gadget *gadget)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100636{
637 struct ab8500_usb *ab;
638
639 if (!otg)
640 return -ENODEV;
641
Heikki Krogerus144713f2012-02-13 13:24:05 +0200642 ab = phy_to_ab(otg->phy);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100643
Sakethram Bommisetti58823372013-04-03 10:45:13 +0200644 ab->phy.otg->gadget = gadget;
645
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100646 /* Some drivers call this function in atomic context.
647 * Do not update ab8500 registers directly till this
648 * is fixed.
649 */
650
Fabio Baltieri3147dad2013-05-15 14:03:25 +0200651 if ((ab->mode != USB_IDLE) && !gadget) {
Sakethram Bommisetti58823372013-04-03 10:45:13 +0200652 ab->mode = USB_IDLE;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100653 schedule_work(&ab->phy_dis_work);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100654 }
655
656 return 0;
657}
658
Heikki Krogerus144713f2012-02-13 13:24:05 +0200659static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100660{
661 struct ab8500_usb *ab;
662
663 if (!otg)
664 return -ENODEV;
665
Heikki Krogerus144713f2012-02-13 13:24:05 +0200666 ab = phy_to_ab(otg->phy);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100667
Sakethram Bommisetti58823372013-04-03 10:45:13 +0200668 ab->phy.otg->host = host;
669
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100670 /* Some drivers call this function in atomic context.
671 * Do not update ab8500 registers directly till this
672 * is fixed.
673 */
674
Fabio Baltieri3147dad2013-05-15 14:03:25 +0200675 if ((ab->mode != USB_IDLE) && !host) {
Sakethram Bommisetti58823372013-04-03 10:45:13 +0200676 ab->mode = USB_IDLE;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100677 schedule_work(&ab->phy_dis_work);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100678 }
679
680 return 0;
681}
682
Sakethram Bommisettifb21f372013-05-15 14:03:27 +0200683static void ab8500_usb_restart_phy(struct ab8500_usb *ab)
684{
685 abx500_mask_and_set_register_interruptible(ab->dev,
686 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
687 AB8500_BIT_PHY_CTRL_DEVICE_EN,
688 AB8500_BIT_PHY_CTRL_DEVICE_EN);
689
690 udelay(100);
691
692 abx500_mask_and_set_register_interruptible(ab->dev,
693 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
694 AB8500_BIT_PHY_CTRL_DEVICE_EN,
695 0);
696
697 abx500_mask_and_set_register_interruptible(ab->dev,
698 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
699 AB8500_BIT_PHY_CTRL_HOST_EN,
700 AB8500_BIT_PHY_CTRL_HOST_EN);
701
702 udelay(100);
703
704 abx500_mask_and_set_register_interruptible(ab->dev,
705 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
706 AB8500_BIT_PHY_CTRL_HOST_EN,
707 0);
708}
709
Fabio Baltierie65b36c2013-04-03 10:45:06 +0200710static int ab8500_usb_regulator_get(struct ab8500_usb *ab)
711{
712 int err;
713
714 ab->v_ape = devm_regulator_get(ab->dev, "v-ape");
715 if (IS_ERR(ab->v_ape)) {
716 dev_err(ab->dev, "Could not get v-ape supply\n");
717 err = PTR_ERR(ab->v_ape);
718 return err;
719 }
720
721 ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18");
722 if (IS_ERR(ab->v_ulpi)) {
723 dev_err(ab->dev, "Could not get vddulpivio18 supply\n");
724 err = PTR_ERR(ab->v_ulpi);
725 return err;
726 }
727
728 ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8");
729 if (IS_ERR(ab->v_musb)) {
730 dev_err(ab->dev, "Could not get musb_1v8 supply\n");
731 err = PTR_ERR(ab->v_musb);
732 return err;
733 }
734
735 return 0;
736}
737
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800738static int ab8500_usb_irq_setup(struct platform_device *pdev,
739 struct ab8500_usb *ab)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100740{
741 int err;
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800742 int irq;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100743
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200744 if (ab->flags & AB8500_USB_FLAG_USE_LINK_STATUS_IRQ) {
745 irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS");
746 if (irq < 0) {
747 dev_err(&pdev->dev, "Link status irq not found\n");
748 return irq;
749 }
750 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
751 ab8500_usb_link_status_irq,
752 IRQF_NO_SUSPEND | IRQF_SHARED,
753 "usb-link-status", ab);
754 if (err < 0) {
755 dev_err(ab->dev, "request_irq failed for link status irq\n");
756 return err;
757 }
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100758 }
759
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200760 if (ab->flags & AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ) {
761 irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
762 if (irq < 0) {
763 dev_err(&pdev->dev, "ID fall irq not found\n");
764 return irq;
765 }
766 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
767 ab8500_usb_disconnect_irq,
768 IRQF_NO_SUSPEND | IRQF_SHARED,
769 "usb-id-fall", ab);
770 if (err < 0) {
771 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
772 return err;
773 }
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800774 }
775
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200776 if (ab->flags & AB8500_USB_FLAG_USE_VBUS_DET_IRQ) {
777 irq = platform_get_irq_byname(pdev, "VBUS_DET_F");
778 if (irq < 0) {
779 dev_err(&pdev->dev, "VBUS fall irq not found\n");
780 return irq;
781 }
782 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
783 ab8500_usb_disconnect_irq,
784 IRQF_NO_SUSPEND | IRQF_SHARED,
785 "usb-vbus-fall", ab);
786 if (err < 0) {
787 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
788 return err;
789 }
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100790 }
791
792 return 0;
793}
794
Fabio Baltieri16604a32013-05-15 14:03:30 +0200795static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb *ab)
796{
797 int err;
798
799 /* Enable the PBT/Bank 0x12 access */
800 err = abx500_set_register_interruptible(ab->dev,
801 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
802 if (err < 0)
803 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
804 err);
805
806 err = abx500_set_register_interruptible(ab->dev,
807 AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8);
808 if (err < 0)
809 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
810 err);
811
812 err = abx500_set_register_interruptible(ab->dev,
813 AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00);
814 if (err < 0)
815 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
816 err);
817
818 err = abx500_set_register_interruptible(ab->dev,
819 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78);
820 if (err < 0)
821 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
822 err);
823
824 /* Switch to normal mode/disable Bank 0x12 access */
825 err = abx500_set_register_interruptible(ab->dev,
826 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00);
827 if (err < 0)
828 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
829 err);
830}
831
832static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb *ab)
833{
834 int err;
835
836 /* Enable the PBT/Bank 0x12 access */
837 err = abx500_mask_and_set_register_interruptible(ab->dev,
838 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
839 0x01, 0x01);
840 if (err < 0)
841 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
842 err);
843
844 err = abx500_mask_and_set_register_interruptible(ab->dev,
845 AB8500_DEBUG, AB8500_USB_PHY_TUNE1,
846 0xC8, 0xC8);
847 if (err < 0)
848 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
849 err);
850
851 err = abx500_mask_and_set_register_interruptible(ab->dev,
852 AB8500_DEBUG, AB8500_USB_PHY_TUNE2,
853 0x60, 0x60);
854 if (err < 0)
855 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
856 err);
857
858 err = abx500_mask_and_set_register_interruptible(ab->dev,
859 AB8500_DEBUG, AB8500_USB_PHY_TUNE3,
860 0xFC, 0x80);
861
862 if (err < 0)
863 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
864 err);
865
866 /* Switch to normal mode/disable Bank 0x12 access */
867 err = abx500_mask_and_set_register_interruptible(ab->dev,
868 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
869 0x00, 0x00);
870 if (err < 0)
871 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
872 err);
873}
874
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500875static int ab8500_usb_probe(struct platform_device *pdev)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100876{
877 struct ab8500_usb *ab;
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800878 struct ab8500 *ab8500;
Heikki Krogerus144713f2012-02-13 13:24:05 +0200879 struct usb_otg *otg;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100880 int err;
881 int rev;
882
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800883 ab8500 = dev_get_drvdata(pdev->dev.parent);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100884 rev = abx500_get_chip_id(&pdev->dev);
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800885
886 if (is_ab8500_1p1_or_earlier(ab8500)) {
887 dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100888 return -ENODEV;
889 }
890
Fabio Baltieri81ef6722013-04-03 10:45:03 +0200891 ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100892 if (!ab)
893 return -ENOMEM;
894
Fabio Baltieri81ef6722013-04-03 10:45:03 +0200895 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
896 if (!otg)
Heikki Krogerus144713f2012-02-13 13:24:05 +0200897 return -ENOMEM;
Heikki Krogerus144713f2012-02-13 13:24:05 +0200898
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100899 ab->dev = &pdev->dev;
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800900 ab->ab8500 = ab8500;
Heikki Krogerus144713f2012-02-13 13:24:05 +0200901 ab->phy.dev = ab->dev;
902 ab->phy.otg = otg;
903 ab->phy.label = "ab8500";
904 ab->phy.set_suspend = ab8500_usb_set_suspend;
905 ab->phy.set_power = ab8500_usb_set_power;
906 ab->phy.state = OTG_STATE_UNDEFINED;
907
908 otg->phy = &ab->phy;
909 otg->set_host = ab8500_usb_set_host;
910 otg->set_peripheral = ab8500_usb_set_peripheral;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100911
Fabio Baltieribd4c9f02013-05-15 14:03:31 +0200912 if (is_ab8500(ab->ab8500)) {
913 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
914 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ |
915 AB8500_USB_FLAG_USE_VBUS_DET_IRQ |
916 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
917 } else if (is_ab8505(ab->ab8500)) {
918 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ |
919 AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ |
920 AB8500_USB_FLAG_USE_VBUS_DET_IRQ |
921 AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
922 }
923
924 /* Disable regulator voltage setting for AB8500 <= v2.0 */
925 if (is_ab8500_2p0_or_earlier(ab->ab8500))
926 ab->flags &= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE;
927
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100928 platform_set_drvdata(pdev, ab);
929
Heikki Krogerus144713f2012-02-13 13:24:05 +0200930 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100931
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100932 /* all: Disable phy when called from set_host and set_peripheral */
933 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
934
Fabio Baltierie65b36c2013-04-03 10:45:06 +0200935 err = ab8500_usb_regulator_get(ab);
936 if (err)
937 return err;
938
Mian Yousaf Kaukabd0ed0642013-05-15 14:03:26 +0200939 ab->sysclk = devm_clk_get(ab->dev, "sysclk");
940 if (IS_ERR(ab->sysclk)) {
941 dev_err(ab->dev, "Could not get sysclk.\n");
942 return PTR_ERR(ab->sysclk);
943 }
944
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800945 err = ab8500_usb_irq_setup(pdev, ab);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100946 if (err < 0)
Fabio Baltieri81ef6722013-04-03 10:45:03 +0200947 return err;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100948
Kishon Vijay Abraham I662dca52012-06-22 17:02:46 +0530949 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100950 if (err) {
951 dev_err(&pdev->dev, "Can't register transceiver\n");
Fabio Baltieri81ef6722013-04-03 10:45:03 +0200952 return err;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100953 }
954
Fabio Baltieri16604a32013-05-15 14:03:30 +0200955 if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500))
956 /* Phy tuning values for AB8500 > v2.0 */
957 ab8500_usb_set_ab8500_tuning_values(ab);
958 else if (is_ab8505(ab->ab8500))
959 /* Phy tuning values for AB8505 */
960 ab8500_usb_set_ab8505_tuning_values(ab);
Sakethram Bommisetti71246312013-04-03 10:45:04 +0200961
Fabio Baltieriaf6882b2013-03-08 10:27:09 +0800962 /* Needed to enable ID detection. */
963 ab8500_usb_wd_workaround(ab);
964
Sakethram Bommisettifb21f372013-05-15 14:03:27 +0200965 /*
966 * This is required for usb-link-status to work properly when a
967 * cable is connected at boot time.
968 */
969 ab8500_usb_restart_phy(ab);
970
Sakethram Bommisetti8db12232013-04-03 10:45:12 +0200971 abx500_usb_link_status_update(ab);
972
Fabio Baltieri73f226c2013-03-08 10:27:08 +0800973 dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100974
975 return 0;
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100976}
977
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500978static int ab8500_usb_remove(struct platform_device *pdev)
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100979{
980 struct ab8500_usb *ab = platform_get_drvdata(pdev);
981
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100982 cancel_work_sync(&ab->phy_dis_work);
983
Kishon Vijay Abraham I662dca52012-06-22 17:02:46 +0530984 usb_remove_phy(&ab->phy);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100985
Mian Yousaf Kaukabf5ef7b42013-04-03 10:45:09 +0200986 if (ab->mode == USB_HOST)
987 ab8500_usb_host_phy_dis(ab);
988 else if (ab->mode == USB_PERIPHERAL)
989 ab8500_usb_peri_phy_dis(ab);
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100990
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +0100991 return 0;
992}
993
Fabio Baltierib3affc32013-05-15 14:03:29 +0200994static struct platform_device_id ab8500_usb_devtype[] = {
995 { .name = "ab8500-usb", },
996 { /* sentinel */ }
997};
998MODULE_DEVICE_TABLE(platform, ab8500_usb_devtype);
999
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +01001000static struct platform_driver ab8500_usb_driver = {
1001 .probe = ab8500_usb_probe,
Bill Pemberton76904172012-11-19 13:21:08 -05001002 .remove = ab8500_usb_remove,
Fabio Baltierib3affc32013-05-15 14:03:29 +02001003 .id_table = ab8500_usb_devtype,
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +01001004 .driver = {
Fabio Baltierib3affc32013-05-15 14:03:29 +02001005 .name = "abx5x0-usb",
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +01001006 .owner = THIS_MODULE,
1007 },
1008};
1009
1010static int __init ab8500_usb_init(void)
1011{
1012 return platform_driver_register(&ab8500_usb_driver);
1013}
1014subsys_initcall(ab8500_usb_init);
1015
1016static void __exit ab8500_usb_exit(void)
1017{
1018 platform_driver_unregister(&ab8500_usb_driver);
1019}
1020module_exit(ab8500_usb_exit);
1021
Mian Yousaf Kaukab96915232010-12-07 15:00:09 +01001022MODULE_AUTHOR("ST-Ericsson AB");
1023MODULE_DESCRIPTION("AB8500 usb transceiver driver");
1024MODULE_LICENSE("GPL");