xref: /openbmc/linux/drivers/phy/ti/phy-tusb1210.c (revision 73224a5d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * tusb1210.c - TUSB1210 USB ULPI PHY driver
4  *
5  * Copyright (C) 2015 Intel Corporation
6  *
7  * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
8  */
9 #include <linux/module.h>
10 #include <linux/bitfield.h>
11 #include <linux/delay.h>
12 #include <linux/ulpi/driver.h>
13 #include <linux/ulpi/regs.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/phy/ulpi_phy.h>
16 #include <linux/power_supply.h>
17 #include <linux/property.h>
18 #include <linux/workqueue.h>
19 
20 #define TUSB1211_POWER_CONTROL				0x3d
21 #define TUSB1211_POWER_CONTROL_SET			0x3e
22 #define TUSB1211_POWER_CONTROL_CLEAR			0x3f
23 #define TUSB1211_POWER_CONTROL_SW_CONTROL		BIT(0)
24 #define TUSB1211_POWER_CONTROL_DET_COMP			BIT(1)
25 #define TUSB1211_POWER_CONTROL_DP_VSRC_EN		BIT(6)
26 
27 #define TUSB1210_VENDOR_SPECIFIC2			0x80
28 #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK		GENMASK(3, 0)
29 #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK		GENMASK(5, 4)
30 #define TUSB1210_VENDOR_SPECIFIC2_DP_MASK		BIT(6)
31 
32 #define TUSB1211_VENDOR_SPECIFIC3			0x85
33 #define TUSB1211_VENDOR_SPECIFIC3_SET			0x86
34 #define TUSB1211_VENDOR_SPECIFIC3_CLEAR			0x87
35 #define TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET		BIT(4)
36 #define TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN	BIT(6)
37 
38 #define TUSB1210_RESET_TIME_MS				50
39 
40 #define TUSB1210_CHG_DET_MAX_RETRIES			5
41 
42 /* TUSB1210 charger detection work states */
43 enum tusb1210_chg_det_state {
44 	TUSB1210_CHG_DET_CONNECTING,
45 	TUSB1210_CHG_DET_START_DET,
46 	TUSB1210_CHG_DET_READ_DET,
47 	TUSB1210_CHG_DET_FINISH_DET,
48 	TUSB1210_CHG_DET_CONNECTED,
49 	TUSB1210_CHG_DET_DISCONNECTING,
50 	TUSB1210_CHG_DET_DISCONNECTING_DONE,
51 	TUSB1210_CHG_DET_DISCONNECTED,
52 };
53 
54 struct tusb1210 {
55 	struct ulpi *ulpi;
56 	struct phy *phy;
57 	struct gpio_desc *gpio_reset;
58 	struct gpio_desc *gpio_cs;
59 	u8 otg_ctrl;
60 	u8 vendor_specific2;
61 #ifdef CONFIG_POWER_SUPPLY
62 	enum power_supply_usb_type chg_type;
63 	enum tusb1210_chg_det_state chg_det_state;
64 	int chg_det_retries;
65 	struct delayed_work chg_det_work;
66 	struct notifier_block psy_nb;
67 	struct power_supply *psy;
68 #endif
69 };
70 
tusb1210_ulpi_write(struct tusb1210 * tusb,u8 reg,u8 val)71 static int tusb1210_ulpi_write(struct tusb1210 *tusb, u8 reg, u8 val)
72 {
73 	int ret;
74 
75 	ret = ulpi_write(tusb->ulpi, reg, val);
76 	if (ret)
77 		dev_err(&tusb->ulpi->dev, "error %d writing val 0x%02x to reg 0x%02x\n",
78 			ret, val, reg);
79 
80 	return ret;
81 }
82 
tusb1210_ulpi_read(struct tusb1210 * tusb,u8 reg,u8 * val)83 static int tusb1210_ulpi_read(struct tusb1210 *tusb, u8 reg, u8 *val)
84 {
85 	int ret;
86 
87 	ret = ulpi_read(tusb->ulpi, reg);
88 	if (ret >= 0) {
89 		*val = ret;
90 		ret = 0;
91 	} else {
92 		dev_err(&tusb->ulpi->dev, "error %d reading reg 0x%02x\n", ret, reg);
93 	}
94 
95 	return ret;
96 }
97 
tusb1210_power_on(struct phy * phy)98 static int tusb1210_power_on(struct phy *phy)
99 {
100 	struct tusb1210 *tusb = phy_get_drvdata(phy);
101 
102 	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
103 	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
104 
105 	msleep(TUSB1210_RESET_TIME_MS);
106 
107 	/* Restore the optional eye diagram optimization value */
108 	tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, tusb->vendor_specific2);
109 
110 	return 0;
111 }
112 
tusb1210_power_off(struct phy * phy)113 static int tusb1210_power_off(struct phy *phy)
114 {
115 	struct tusb1210 *tusb = phy_get_drvdata(phy);
116 
117 	gpiod_set_value_cansleep(tusb->gpio_reset, 0);
118 	gpiod_set_value_cansleep(tusb->gpio_cs, 0);
119 
120 	return 0;
121 }
122 
tusb1210_set_mode(struct phy * phy,enum phy_mode mode,int submode)123 static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode, int submode)
124 {
125 	struct tusb1210 *tusb = phy_get_drvdata(phy);
126 	int ret;
127 	u8 reg;
128 
129 	ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &reg);
130 	if (ret < 0)
131 		return ret;
132 
133 	switch (mode) {
134 	case PHY_MODE_USB_HOST:
135 		reg |= (ULPI_OTG_CTRL_DRVVBUS_EXT
136 			| ULPI_OTG_CTRL_ID_PULLUP
137 			| ULPI_OTG_CTRL_DP_PULLDOWN
138 			| ULPI_OTG_CTRL_DM_PULLDOWN);
139 		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
140 		reg |= ULPI_OTG_CTRL_DRVVBUS;
141 		break;
142 	case PHY_MODE_USB_DEVICE:
143 		reg &= ~(ULPI_OTG_CTRL_DRVVBUS
144 			 | ULPI_OTG_CTRL_DP_PULLDOWN
145 			 | ULPI_OTG_CTRL_DM_PULLDOWN);
146 		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
147 		reg &= ~ULPI_OTG_CTRL_DRVVBUS_EXT;
148 		break;
149 	default:
150 		/* nothing */
151 		return 0;
152 	}
153 
154 	tusb->otg_ctrl = reg;
155 	return tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
156 }
157 
158 #ifdef CONFIG_POWER_SUPPLY
159 static const char * const tusb1210_chg_det_states[] = {
160 	"CHG_DET_CONNECTING",
161 	"CHG_DET_START_DET",
162 	"CHG_DET_READ_DET",
163 	"CHG_DET_FINISH_DET",
164 	"CHG_DET_CONNECTED",
165 	"CHG_DET_DISCONNECTING",
166 	"CHG_DET_DISCONNECTING_DONE",
167 	"CHG_DET_DISCONNECTED",
168 };
169 
tusb1210_reset(struct tusb1210 * tusb)170 static void tusb1210_reset(struct tusb1210 *tusb)
171 {
172 	gpiod_set_value_cansleep(tusb->gpio_reset, 0);
173 	usleep_range(200, 500);
174 	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
175 }
176 
tusb1210_chg_det_set_type(struct tusb1210 * tusb,enum power_supply_usb_type type)177 static void tusb1210_chg_det_set_type(struct tusb1210 *tusb,
178 				      enum power_supply_usb_type type)
179 {
180 	dev_dbg(&tusb->ulpi->dev, "charger type: %d\n", type);
181 	tusb->chg_type = type;
182 	tusb->chg_det_retries = 0;
183 	power_supply_changed(tusb->psy);
184 }
185 
tusb1210_chg_det_set_state(struct tusb1210 * tusb,enum tusb1210_chg_det_state new_state,int delay_ms)186 static void tusb1210_chg_det_set_state(struct tusb1210 *tusb,
187 				       enum tusb1210_chg_det_state new_state,
188 				       int delay_ms)
189 {
190 	if (delay_ms)
191 		dev_dbg(&tusb->ulpi->dev, "chg_det new state %s in %d ms\n",
192 			tusb1210_chg_det_states[new_state], delay_ms);
193 
194 	tusb->chg_det_state = new_state;
195 	mod_delayed_work(system_long_wq, &tusb->chg_det_work,
196 			 msecs_to_jiffies(delay_ms));
197 }
198 
tusb1210_chg_det_handle_ulpi_error(struct tusb1210 * tusb)199 static void tusb1210_chg_det_handle_ulpi_error(struct tusb1210 *tusb)
200 {
201 	tusb1210_reset(tusb);
202 	if (tusb->chg_det_retries < TUSB1210_CHG_DET_MAX_RETRIES) {
203 		tusb->chg_det_retries++;
204 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET,
205 					   TUSB1210_RESET_TIME_MS);
206 	} else {
207 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET,
208 					   TUSB1210_RESET_TIME_MS);
209 	}
210 }
211 
212 /*
213  * Boards using a TUSB121x for charger-detection have 3 power_supply class devs:
214  *
215  * tusb1211-charger-detect(1) -> charger -> fuel-gauge
216  *
217  * To determine if an USB charger is connected to the board, the online prop of
218  * the charger psy needs to be read. Since the tusb1211-charger-detect psy is
219  * the start of the supplier -> supplied-to chain, power_supply_am_i_supplied()
220  * cannot be used here.
221  *
222  * Instead, below is a list of the power_supply names of known chargers for
223  * these boards and the charger psy is looked up by name from this list.
224  *
225  * (1) modelling the external USB charger
226  */
227 static const char * const tusb1210_chargers[] = {
228 	"bq24190-charger",
229 };
230 
tusb1210_get_online(struct tusb1210 * tusb)231 static bool tusb1210_get_online(struct tusb1210 *tusb)
232 {
233 	struct power_supply *charger = NULL;
234 	union power_supply_propval val;
235 	bool online = false;
236 	int i, ret;
237 
238 	for (i = 0; i < ARRAY_SIZE(tusb1210_chargers) && !charger; i++)
239 		charger = power_supply_get_by_name(tusb1210_chargers[i]);
240 
241 	if (!charger)
242 		return false;
243 
244 	ret = power_supply_get_property(charger, POWER_SUPPLY_PROP_ONLINE, &val);
245 	if (ret == 0)
246 		online = val.intval;
247 
248 	power_supply_put(charger);
249 
250 	return online;
251 }
252 
tusb1210_chg_det_work(struct work_struct * work)253 static void tusb1210_chg_det_work(struct work_struct *work)
254 {
255 	struct tusb1210 *tusb = container_of(work, struct tusb1210, chg_det_work.work);
256 	bool vbus_present = tusb1210_get_online(tusb);
257 	int ret;
258 	u8 val;
259 
260 	dev_dbg(&tusb->ulpi->dev, "chg_det state %s vbus_present %d\n",
261 		tusb1210_chg_det_states[tusb->chg_det_state], vbus_present);
262 
263 	switch (tusb->chg_det_state) {
264 	case TUSB1210_CHG_DET_CONNECTING:
265 		tusb->chg_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
266 		tusb->chg_det_retries = 0;
267 		/* Power on USB controller for ulpi_read()/_write() */
268 		ret = pm_runtime_resume_and_get(tusb->ulpi->dev.parent);
269 		if (ret < 0) {
270 			dev_err(&tusb->ulpi->dev, "error %d runtime-resuming\n", ret);
271 			/* Should never happen, skip charger detection */
272 			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
273 			return;
274 		}
275 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET, 0);
276 		break;
277 	case TUSB1210_CHG_DET_START_DET:
278 		/*
279 		 * Use the builtin charger detection FSM to keep things simple.
280 		 * This only detects DCP / SDP. This is good enough for the few
281 		 * boards which actually rely on the phy for charger detection.
282 		 */
283 		mutex_lock(&tusb->phy->mutex);
284 		ret = tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_SET,
285 					  TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET);
286 		mutex_unlock(&tusb->phy->mutex);
287 		if (ret) {
288 			tusb1210_chg_det_handle_ulpi_error(tusb);
289 			break;
290 		}
291 
292 		/* Wait 400 ms for the charger detection FSM to finish */
293 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_READ_DET, 400);
294 		break;
295 	case TUSB1210_CHG_DET_READ_DET:
296 		mutex_lock(&tusb->phy->mutex);
297 		ret = tusb1210_ulpi_read(tusb, TUSB1211_POWER_CONTROL, &val);
298 		mutex_unlock(&tusb->phy->mutex);
299 		if (ret) {
300 			tusb1210_chg_det_handle_ulpi_error(tusb);
301 			break;
302 		}
303 
304 		if (val & TUSB1211_POWER_CONTROL_DET_COMP)
305 			tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_DCP);
306 		else
307 			tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_SDP);
308 
309 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET, 0);
310 		break;
311 	case TUSB1210_CHG_DET_FINISH_DET:
312 		mutex_lock(&tusb->phy->mutex);
313 
314 		/* Set SW_CONTROL to stop the charger-det FSM */
315 		ret = tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_SET,
316 					  TUSB1211_POWER_CONTROL_SW_CONTROL);
317 
318 		/* Clear DP_VSRC_EN which may have been enabled by the charger-det FSM */
319 		ret |= tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_CLEAR,
320 					   TUSB1211_POWER_CONTROL_DP_VSRC_EN);
321 
322 		/* Clear CHGD_IDP_SRC_EN (may have been enabled by the charger-det FSM) */
323 		ret |= tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_CLEAR,
324 					   TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN);
325 
326 		/* If any of the above fails reset the phy */
327 		if (ret) {
328 			tusb1210_reset(tusb);
329 			msleep(TUSB1210_RESET_TIME_MS);
330 		}
331 
332 		/* Restore phy-parameters and OTG_CTRL register */
333 		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, tusb->otg_ctrl);
334 		tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2,
335 				    tusb->vendor_specific2);
336 
337 		mutex_unlock(&tusb->phy->mutex);
338 
339 		pm_runtime_put(tusb->ulpi->dev.parent);
340 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
341 		break;
342 	case TUSB1210_CHG_DET_CONNECTED:
343 		if (!vbus_present)
344 			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING, 0);
345 		break;
346 	case TUSB1210_CHG_DET_DISCONNECTING:
347 		/*
348 		 * The phy seems to take approx. 600ms longer then the charger
349 		 * chip (which is used to get vbus_present) to determine Vbus
350 		 * session end. Wait 800ms to ensure the phy has detected and
351 		 * signalled Vbus session end.
352 		 */
353 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING_DONE, 800);
354 		break;
355 	case TUSB1210_CHG_DET_DISCONNECTING_DONE:
356 		/*
357 		 * The phy often stops reacting to ulpi_read()/_write requests
358 		 * after a Vbus-session end. Reset it to work around this.
359 		 */
360 		tusb1210_reset(tusb);
361 		tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_UNKNOWN);
362 		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTED, 0);
363 		break;
364 	case TUSB1210_CHG_DET_DISCONNECTED:
365 		if (vbus_present)
366 			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTING, 0);
367 		break;
368 	}
369 }
370 
tusb1210_psy_notifier(struct notifier_block * nb,unsigned long event,void * ptr)371 static int tusb1210_psy_notifier(struct notifier_block *nb,
372 	unsigned long event, void *ptr)
373 {
374 	struct tusb1210 *tusb = container_of(nb, struct tusb1210, psy_nb);
375 	struct power_supply *psy = ptr;
376 
377 	if (psy != tusb->psy && psy->desc->type == POWER_SUPPLY_TYPE_USB)
378 		queue_delayed_work(system_long_wq, &tusb->chg_det_work, 0);
379 
380 	return NOTIFY_OK;
381 }
382 
tusb1210_psy_get_prop(struct power_supply * psy,enum power_supply_property psp,union power_supply_propval * val)383 static int tusb1210_psy_get_prop(struct power_supply *psy,
384 				 enum power_supply_property psp,
385 				 union power_supply_propval *val)
386 {
387 	struct tusb1210 *tusb = power_supply_get_drvdata(psy);
388 
389 	switch (psp) {
390 	case POWER_SUPPLY_PROP_ONLINE:
391 		val->intval = tusb1210_get_online(tusb);
392 		break;
393 	case POWER_SUPPLY_PROP_USB_TYPE:
394 		val->intval = tusb->chg_type;
395 		break;
396 	case POWER_SUPPLY_PROP_CURRENT_MAX:
397 		if (tusb->chg_type == POWER_SUPPLY_USB_TYPE_DCP)
398 			val->intval = 2000000;
399 		else
400 			val->intval = 500000;
401 		break;
402 	default:
403 		return -EINVAL;
404 	}
405 
406 	return 0;
407 }
408 
409 static const enum power_supply_usb_type tusb1210_psy_usb_types[] = {
410 	POWER_SUPPLY_USB_TYPE_SDP,
411 	POWER_SUPPLY_USB_TYPE_DCP,
412 	POWER_SUPPLY_USB_TYPE_UNKNOWN,
413 };
414 
415 static const enum power_supply_property tusb1210_psy_props[] = {
416 	POWER_SUPPLY_PROP_ONLINE,
417 	POWER_SUPPLY_PROP_USB_TYPE,
418 	POWER_SUPPLY_PROP_CURRENT_MAX,
419 };
420 
421 static const struct power_supply_desc tusb1210_psy_desc = {
422 	.name = "tusb1211-charger-detect",
423 	.type = POWER_SUPPLY_TYPE_USB,
424 	.usb_types = tusb1210_psy_usb_types,
425 	.num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types),
426 	.properties = tusb1210_psy_props,
427 	.num_properties = ARRAY_SIZE(tusb1210_psy_props),
428 	.get_property = tusb1210_psy_get_prop,
429 };
430 
431 /* Setup charger detection if requested, on errors continue without chg-det */
tusb1210_probe_charger_detect(struct tusb1210 * tusb)432 static void tusb1210_probe_charger_detect(struct tusb1210 *tusb)
433 {
434 	struct power_supply_config psy_cfg = { .drv_data = tusb };
435 	struct device *dev = &tusb->ulpi->dev;
436 	int ret;
437 
438 	if (!device_property_read_bool(dev->parent, "linux,phy_charger_detect"))
439 		return;
440 
441 	if (tusb->ulpi->id.product != 0x1508) {
442 		dev_err(dev, "error charger detection is only supported on the TUSB1211\n");
443 		return;
444 	}
445 
446 	ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &tusb->otg_ctrl);
447 	if (ret)
448 		return;
449 
450 	tusb->psy = power_supply_register(dev, &tusb1210_psy_desc, &psy_cfg);
451 	if (IS_ERR(tusb->psy))
452 		return;
453 
454 	/*
455 	 * Delay initial run by 2 seconds to allow the charger driver,
456 	 * which is used to determine vbus_present, to load.
457 	 */
458 	tusb->chg_det_state = TUSB1210_CHG_DET_DISCONNECTED;
459 	INIT_DELAYED_WORK(&tusb->chg_det_work, tusb1210_chg_det_work);
460 	queue_delayed_work(system_long_wq, &tusb->chg_det_work, 2 * HZ);
461 
462 	tusb->psy_nb.notifier_call = tusb1210_psy_notifier;
463 	power_supply_reg_notifier(&tusb->psy_nb);
464 }
465 
tusb1210_remove_charger_detect(struct tusb1210 * tusb)466 static void tusb1210_remove_charger_detect(struct tusb1210 *tusb)
467 {
468 
469 	if (!IS_ERR_OR_NULL(tusb->psy)) {
470 		power_supply_unreg_notifier(&tusb->psy_nb);
471 		cancel_delayed_work_sync(&tusb->chg_det_work);
472 		power_supply_unregister(tusb->psy);
473 	}
474 }
475 #else
tusb1210_probe_charger_detect(struct tusb1210 * tusb)476 static void tusb1210_probe_charger_detect(struct tusb1210 *tusb) { }
tusb1210_remove_charger_detect(struct tusb1210 * tusb)477 static void tusb1210_remove_charger_detect(struct tusb1210 *tusb) { }
478 #endif
479 
480 static const struct phy_ops phy_ops = {
481 	.power_on = tusb1210_power_on,
482 	.power_off = tusb1210_power_off,
483 	.set_mode = tusb1210_set_mode,
484 	.owner = THIS_MODULE,
485 };
486 
tusb1210_probe(struct ulpi * ulpi)487 static int tusb1210_probe(struct ulpi *ulpi)
488 {
489 	struct tusb1210 *tusb;
490 	u8 val, reg;
491 	int ret;
492 
493 	tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
494 	if (!tusb)
495 		return -ENOMEM;
496 
497 	tusb->ulpi = ulpi;
498 
499 	tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
500 						   GPIOD_OUT_LOW);
501 	if (IS_ERR(tusb->gpio_reset))
502 		return PTR_ERR(tusb->gpio_reset);
503 
504 	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
505 
506 	tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
507 						GPIOD_OUT_LOW);
508 	if (IS_ERR(tusb->gpio_cs))
509 		return PTR_ERR(tusb->gpio_cs);
510 
511 	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
512 
513 	/*
514 	 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
515 	 * diagram optimization and DP/DM swap.
516 	 */
517 
518 	ret = tusb1210_ulpi_read(tusb, TUSB1210_VENDOR_SPECIFIC2, &reg);
519 	if (ret)
520 		return ret;
521 
522 	/* High speed output drive strength configuration */
523 	if (!device_property_read_u8(&ulpi->dev, "ihstx", &val))
524 		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK);
525 
526 	/* High speed output impedance configuration */
527 	if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val))
528 		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK);
529 
530 	/* DP/DM swap control */
531 	if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val))
532 		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK);
533 
534 	ret = tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, reg);
535 	if (ret)
536 		return ret;
537 
538 	tusb->vendor_specific2 = reg;
539 
540 	tusb1210_probe_charger_detect(tusb);
541 
542 	tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
543 	if (IS_ERR(tusb->phy)) {
544 		ret = PTR_ERR(tusb->phy);
545 		goto err_remove_charger;
546 	}
547 
548 	phy_set_drvdata(tusb->phy, tusb);
549 	ulpi_set_drvdata(ulpi, tusb);
550 	return 0;
551 
552 err_remove_charger:
553 	tusb1210_remove_charger_detect(tusb);
554 	return ret;
555 }
556 
tusb1210_remove(struct ulpi * ulpi)557 static void tusb1210_remove(struct ulpi *ulpi)
558 {
559 	struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
560 
561 	ulpi_phy_destroy(ulpi, tusb->phy);
562 	tusb1210_remove_charger_detect(tusb);
563 }
564 
565 #define TI_VENDOR_ID 0x0451
566 
567 static const struct ulpi_device_id tusb1210_ulpi_id[] = {
568 	{ TI_VENDOR_ID, 0x1507, },  /* TUSB1210 */
569 	{ TI_VENDOR_ID, 0x1508, },  /* TUSB1211 */
570 	{ },
571 };
572 MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
573 
574 static struct ulpi_driver tusb1210_driver = {
575 	.id_table = tusb1210_ulpi_id,
576 	.probe = tusb1210_probe,
577 	.remove = tusb1210_remove,
578 	.driver = {
579 		.name = "tusb1210",
580 		.owner = THIS_MODULE,
581 	},
582 };
583 
584 module_ulpi_driver(tusb1210_driver);
585 
586 MODULE_AUTHOR("Intel Corporation");
587 MODULE_LICENSE("GPL v2");
588 MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");
589