summaryrefslogtreecommitdiff
path: root/drivers/phy/ti/phy-tusb1210.c
blob: 751fecd466e3e3b5d8bd1faf3071812dd3df3cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// SPDX-License-Identifier: GPL-2.0-only
/*
 * tusb1210.c - TUSB1210 USB ULPI PHY driver
 *
 * Copyright (C) 2015 Intel Corporation
 *
 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
 */
#include <linux/module.h>
#include <linux/bitfield.h>
#include <linux/delay.h>
#include <linux/ulpi/driver.h>
#include <linux/ulpi/regs.h>
#include <linux/gpio/consumer.h>
#include <linux/phy/ulpi_phy.h>
#include <linux/power_supply.h>
#include <linux/property.h>
#include <linux/workqueue.h>

#define TI_VENDOR_ID		0x0451
#define TI_DEVICE_TUSB1210	0x1507
#define TI_DEVICE_TUSB1211	0x1508

#define TUSB1211_POWER_CONTROL				0x3d
#define TUSB1211_POWER_CONTROL_SET			0x3e
#define TUSB1211_POWER_CONTROL_CLEAR			0x3f
#define TUSB1211_POWER_CONTROL_SW_CONTROL		BIT(0)
#define TUSB1211_POWER_CONTROL_DET_COMP			BIT(1)
#define TUSB1211_POWER_CONTROL_DP_VSRC_EN		BIT(6)

#define TUSB1210_VENDOR_SPECIFIC2			0x80
#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK		GENMASK(3, 0)
#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK		GENMASK(5, 4)
#define TUSB1210_VENDOR_SPECIFIC2_DP_MASK		BIT(6)

#define TUSB1211_VENDOR_SPECIFIC3			0x85
#define TUSB1211_VENDOR_SPECIFIC3_SET			0x86
#define TUSB1211_VENDOR_SPECIFIC3_CLEAR			0x87
#define TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET		BIT(4)
#define TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN	BIT(6)

#define TUSB1210_RESET_TIME_MS				50

#define TUSB1210_CHG_DET_MAX_RETRIES			5

/* TUSB1210 charger detection work states */
enum tusb1210_chg_det_state {
	TUSB1210_CHG_DET_CONNECTING,
	TUSB1210_CHG_DET_START_DET,
	TUSB1210_CHG_DET_READ_DET,
	TUSB1210_CHG_DET_FINISH_DET,
	TUSB1210_CHG_DET_CONNECTED,
	TUSB1210_CHG_DET_DISCONNECTING,
	TUSB1210_CHG_DET_DISCONNECTING_DONE,
	TUSB1210_CHG_DET_DISCONNECTED,
};

struct tusb1210 {
	struct device *dev;
	struct phy *phy;
	struct gpio_desc *gpio_reset;
	struct gpio_desc *gpio_cs;
	u8 otg_ctrl;
	u8 vendor_specific2;
#ifdef CONFIG_POWER_SUPPLY
	enum power_supply_usb_type chg_type;
	enum tusb1210_chg_det_state chg_det_state;
	int chg_det_retries;
	struct delayed_work chg_det_work;
	struct notifier_block psy_nb;
	struct power_supply *psy;
#endif
};

static int tusb1210_ulpi_write(struct tusb1210 *tusb, u8 reg, u8 val)
{
	struct device *dev = tusb->dev;
	int ret;

	ret = ulpi_write(to_ulpi_dev(dev), reg, val);
	if (ret)
		dev_err(dev, "error %d writing val 0x%02x to reg 0x%02x\n", ret, val, reg);

	return ret;
}

static int tusb1210_ulpi_read(struct tusb1210 *tusb, u8 reg, u8 *val)
{
	struct device *dev = tusb->dev;
	int ret;

	ret = ulpi_read(to_ulpi_dev(dev), reg);
	if (ret >= 0) {
		*val = ret;
		ret = 0;
	} else {
		dev_err(dev, "error %d reading reg 0x%02x\n", ret, reg);
	}

	return ret;
}

static int tusb1210_power_on(struct phy *phy)
{
	struct tusb1210 *tusb = phy_get_drvdata(phy);

	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
	gpiod_set_value_cansleep(tusb->gpio_cs, 1);

	msleep(TUSB1210_RESET_TIME_MS);

	/* Restore the optional eye diagram optimization value */
	tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, tusb->vendor_specific2);

	return 0;
}

static int tusb1210_power_off(struct phy *phy)
{
	struct tusb1210 *tusb = phy_get_drvdata(phy);

	gpiod_set_value_cansleep(tusb->gpio_reset, 0);
	gpiod_set_value_cansleep(tusb->gpio_cs, 0);

	return 0;
}

static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
	struct tusb1210 *tusb = phy_get_drvdata(phy);
	int ret;
	u8 reg;

	ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &reg);
	if (ret < 0)
		return ret;

	switch (mode) {
	case PHY_MODE_USB_HOST:
		reg |= (ULPI_OTG_CTRL_DRVVBUS_EXT
			| ULPI_OTG_CTRL_ID_PULLUP
			| ULPI_OTG_CTRL_DP_PULLDOWN
			| ULPI_OTG_CTRL_DM_PULLDOWN);
		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
		reg |= ULPI_OTG_CTRL_DRVVBUS;
		break;
	case PHY_MODE_USB_DEVICE:
		reg &= ~(ULPI_OTG_CTRL_DRVVBUS
			 | ULPI_OTG_CTRL_DP_PULLDOWN
			 | ULPI_OTG_CTRL_DM_PULLDOWN);
		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
		reg &= ~ULPI_OTG_CTRL_DRVVBUS_EXT;
		break;
	default:
		/* nothing */
		return 0;
	}

	tusb->otg_ctrl = reg;
	return tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
}

#ifdef CONFIG_POWER_SUPPLY
static const char * const tusb1210_chg_det_states[] = {
	"CHG_DET_CONNECTING",
	"CHG_DET_START_DET",
	"CHG_DET_READ_DET",
	"CHG_DET_FINISH_DET",
	"CHG_DET_CONNECTED",
	"CHG_DET_DISCONNECTING",
	"CHG_DET_DISCONNECTING_DONE",
	"CHG_DET_DISCONNECTED",
};

static void tusb1210_reset(struct tusb1210 *tusb)
{
	gpiod_set_value_cansleep(tusb->gpio_reset, 0);
	usleep_range(200, 500);
	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
}

static void tusb1210_chg_det_set_type(struct tusb1210 *tusb,
				      enum power_supply_usb_type type)
{
	dev_dbg(tusb->dev, "charger type: %d\n", type);
	tusb->chg_type = type;
	tusb->chg_det_retries = 0;
	power_supply_changed(tusb->psy);
}

static void tusb1210_chg_det_set_state(struct tusb1210 *tusb,
				       enum tusb1210_chg_det_state new_state,
				       int delay_ms)
{
	if (delay_ms)
		dev_dbg(tusb->dev, "chg_det new state %s in %d ms\n",
			tusb1210_chg_det_states[new_state], delay_ms);

	tusb->chg_det_state = new_state;
	mod_delayed_work(system_long_wq, &tusb->chg_det_work,
			 msecs_to_jiffies(delay_ms));
}

static void tusb1210_chg_det_handle_ulpi_error(struct tusb1210 *tusb)
{
	tusb1210_reset(tusb);
	if (tusb->chg_det_retries < TUSB1210_CHG_DET_MAX_RETRIES) {
		tusb->chg_det_retries++;
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET,
					   TUSB1210_RESET_TIME_MS);
	} else {
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET,
					   TUSB1210_RESET_TIME_MS);
	}
}

/*
 * Boards using a TUSB121x for charger-detection have 3 power_supply class devs:
 *
 * tusb1211-charger-detect(1) -> charger -> fuel-gauge
 *
 * To determine if an USB charger is connected to the board, the online prop of
 * the charger psy needs to be read. Since the tusb1211-charger-detect psy is
 * the start of the supplier -> supplied-to chain, power_supply_am_i_supplied()
 * cannot be used here.
 *
 * Instead, below is a list of the power_supply names of known chargers for
 * these boards and the charger psy is looked up by name from this list.
 *
 * (1) modelling the external USB charger
 */
static const char * const tusb1210_chargers[] = {
	"bq24190-charger",
};

static bool tusb1210_get_online(struct tusb1210 *tusb)
{
	struct power_supply *charger = NULL;
	union power_supply_propval val;
	bool online = false;
	int i, ret;

	for (i = 0; i < ARRAY_SIZE(tusb1210_chargers) && !charger; i++)
		charger = power_supply_get_by_name(tusb1210_chargers[i]);

	if (!charger)
		return false;

	ret = power_supply_get_property(charger, POWER_SUPPLY_PROP_ONLINE, &val);
	if (ret == 0)
		online = val.intval;

	power_supply_put(charger);

	return online;
}

static void tusb1210_chg_det_work(struct work_struct *work)
{
	struct tusb1210 *tusb = container_of(work, struct tusb1210, chg_det_work.work);
	bool vbus_present = tusb1210_get_online(tusb);
	int ret;
	u8 val;

	dev_dbg(tusb->dev, "chg_det state %s vbus_present %d\n",
		tusb1210_chg_det_states[tusb->chg_det_state], vbus_present);

	switch (tusb->chg_det_state) {
	case TUSB1210_CHG_DET_CONNECTING:
		tusb->chg_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
		tusb->chg_det_retries = 0;
		/* Power on USB controller for ulpi_read()/_write() */
		ret = pm_runtime_resume_and_get(tusb->dev->parent);
		if (ret < 0) {
			dev_err(tusb->dev, "error %d runtime-resuming\n", ret);
			/* Should never happen, skip charger detection */
			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
			return;
		}
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET, 0);
		break;
	case TUSB1210_CHG_DET_START_DET:
		/*
		 * Use the builtin charger detection FSM to keep things simple.
		 * This only detects DCP / SDP. This is good enough for the few
		 * boards which actually rely on the phy for charger detection.
		 */
		mutex_lock(&tusb->phy->mutex);
		ret = tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_SET,
					  TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET);
		mutex_unlock(&tusb->phy->mutex);
		if (ret) {
			tusb1210_chg_det_handle_ulpi_error(tusb);
			break;
		}

		/* Wait 400 ms for the charger detection FSM to finish */
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_READ_DET, 400);
		break;
	case TUSB1210_CHG_DET_READ_DET:
		mutex_lock(&tusb->phy->mutex);
		ret = tusb1210_ulpi_read(tusb, TUSB1211_POWER_CONTROL, &val);
		mutex_unlock(&tusb->phy->mutex);
		if (ret) {
			tusb1210_chg_det_handle_ulpi_error(tusb);
			break;
		}

		if (val & TUSB1211_POWER_CONTROL_DET_COMP)
			tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_DCP);
		else
			tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_SDP);

		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET, 0);
		break;
	case TUSB1210_CHG_DET_FINISH_DET:
		mutex_lock(&tusb->phy->mutex);

		/* Set SW_CONTROL to stop the charger-det FSM */
		ret = tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_SET,
					  TUSB1211_POWER_CONTROL_SW_CONTROL);

		/* Clear DP_VSRC_EN which may have been enabled by the charger-det FSM */
		ret |= tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_CLEAR,
					   TUSB1211_POWER_CONTROL_DP_VSRC_EN);

		/* Clear CHGD_IDP_SRC_EN (may have been enabled by the charger-det FSM) */
		ret |= tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_CLEAR,
					   TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN);

		/* If any of the above fails reset the phy */
		if (ret) {
			tusb1210_reset(tusb);
			msleep(TUSB1210_RESET_TIME_MS);
		}

		/* Restore phy-parameters and OTG_CTRL register */
		tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, tusb->otg_ctrl);
		tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2,
				    tusb->vendor_specific2);

		mutex_unlock(&tusb->phy->mutex);

		pm_runtime_put(tusb->dev->parent);
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
		break;
	case TUSB1210_CHG_DET_CONNECTED:
		if (!vbus_present)
			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING, 0);
		break;
	case TUSB1210_CHG_DET_DISCONNECTING:
		/*
		 * The phy seems to take approx. 600ms longer then the charger
		 * chip (which is used to get vbus_present) to determine Vbus
		 * session end. Wait 800ms to ensure the phy has detected and
		 * signalled Vbus session end.
		 */
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING_DONE, 800);
		break;
	case TUSB1210_CHG_DET_DISCONNECTING_DONE:
		/*
		 * The phy often stops reacting to ulpi_read()/_write requests
		 * after a Vbus-session end. Reset it to work around this.
		 */
		tusb1210_reset(tusb);
		tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_UNKNOWN);
		tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTED, 0);
		break;
	case TUSB1210_CHG_DET_DISCONNECTED:
		if (vbus_present)
			tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTING, 0);
		break;
	}
}

static int tusb1210_psy_notifier(struct notifier_block *nb,
	unsigned long event, void *ptr)
{
	struct tusb1210 *tusb = container_of(nb, struct tusb1210, psy_nb);
	struct power_supply *psy = ptr;

	if (psy != tusb->psy && psy->desc->type == POWER_SUPPLY_TYPE_USB)
		queue_delayed_work(system_long_wq, &tusb->chg_det_work, 0);

	return NOTIFY_OK;
}

static int tusb1210_psy_get_prop(struct power_supply *psy,
				 enum power_supply_property psp,
				 union power_supply_propval *val)
{
	struct tusb1210 *tusb = power_supply_get_drvdata(psy);

	switch (psp) {
	case POWER_SUPPLY_PROP_ONLINE:
		val->intval = tusb1210_get_online(tusb);
		break;
	case POWER_SUPPLY_PROP_USB_TYPE:
		val->intval = tusb->chg_type;
		break;
	case POWER_SUPPLY_PROP_CURRENT_MAX:
		if (tusb->chg_type == POWER_SUPPLY_USB_TYPE_DCP)
			val->intval = 2000000;
		else
			val->intval = 500000;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static const enum power_supply_usb_type tusb1210_psy_usb_types[] = {
	POWER_SUPPLY_USB_TYPE_SDP,
	POWER_SUPPLY_USB_TYPE_DCP,
	POWER_SUPPLY_USB_TYPE_UNKNOWN,
};

static const enum power_supply_property tusb1210_psy_props[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_USB_TYPE,
	POWER_SUPPLY_PROP_CURRENT_MAX,
};

static const struct power_supply_desc tusb1210_psy_desc = {
	.name = "tusb1211-charger-detect",
	.type = POWER_SUPPLY_TYPE_USB,
	.usb_types = tusb1210_psy_usb_types,
	.num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types),
	.properties = tusb1210_psy_props,
	.num_properties = ARRAY_SIZE(tusb1210_psy_props),
	.get_property = tusb1210_psy_get_prop,
};

/* Setup charger detection if requested, on errors continue without chg-det */
static void tusb1210_probe_charger_detect(struct tusb1210 *tusb)
{
	struct power_supply_config psy_cfg = { .drv_data = tusb };
	struct device *dev = tusb->dev;
	struct ulpi *ulpi = to_ulpi_dev(dev);
	int ret;

	if (!device_property_read_bool(dev->parent, "linux,phy_charger_detect"))
		return;

	if (ulpi->id.product != TI_DEVICE_TUSB1211) {
		dev_err(dev, "error charger detection is only supported on the TUSB1211\n");
		return;
	}

	ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &tusb->otg_ctrl);
	if (ret)
		return;

	tusb->psy = power_supply_register(dev, &tusb1210_psy_desc, &psy_cfg);
	if (IS_ERR(tusb->psy))
		return;

	/*
	 * Delay initial run by 2 seconds to allow the charger driver,
	 * which is used to determine vbus_present, to load.
	 */
	tusb->chg_det_state = TUSB1210_CHG_DET_DISCONNECTED;
	INIT_DELAYED_WORK(&tusb->chg_det_work, tusb1210_chg_det_work);
	queue_delayed_work(system_long_wq, &tusb->chg_det_work, 2 * HZ);

	tusb->psy_nb.notifier_call = tusb1210_psy_notifier;
	power_supply_reg_notifier(&tusb->psy_nb);
}

static void tusb1210_remove_charger_detect(struct tusb1210 *tusb)
{

	if (!IS_ERR_OR_NULL(tusb->psy)) {
		power_supply_unreg_notifier(&tusb->psy_nb);
		cancel_delayed_work_sync(&tusb->chg_det_work);
		power_supply_unregister(tusb->psy);
	}
}
#else
static void tusb1210_probe_charger_detect(struct tusb1210 *tusb) { }
static void tusb1210_remove_charger_detect(struct tusb1210 *tusb) { }
#endif

static const struct phy_ops phy_ops = {
	.power_on = tusb1210_power_on,
	.power_off = tusb1210_power_off,
	.set_mode = tusb1210_set_mode,
	.owner = THIS_MODULE,
};

static int tusb1210_probe(struct ulpi *ulpi)
{
	struct device *dev = &ulpi->dev;
	struct tusb1210 *tusb;
	u8 val, reg;
	int ret;

	tusb = devm_kzalloc(dev, sizeof(*tusb), GFP_KERNEL);
	if (!tusb)
		return -ENOMEM;

	tusb->dev = dev;

	tusb->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(tusb->gpio_reset))
		return PTR_ERR(tusb->gpio_reset);

	gpiod_set_value_cansleep(tusb->gpio_reset, 1);

	tusb->gpio_cs = devm_gpiod_get_optional(dev, "cs", GPIOD_OUT_LOW);
	if (IS_ERR(tusb->gpio_cs))
		return PTR_ERR(tusb->gpio_cs);

	gpiod_set_value_cansleep(tusb->gpio_cs, 1);

	/*
	 * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
	 * diagram optimization and DP/DM swap.
	 */

	ret = tusb1210_ulpi_read(tusb, TUSB1210_VENDOR_SPECIFIC2, &reg);
	if (ret)
		return ret;

	/* High speed output drive strength configuration */
	if (!device_property_read_u8(dev, "ihstx", &val))
		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK);

	/* High speed output impedance configuration */
	if (!device_property_read_u8(dev, "zhsdrv", &val))
		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK);

	/* DP/DM swap control */
	if (!device_property_read_u8(dev, "datapolarity", &val))
		u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK);

	ret = tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, reg);
	if (ret)
		return ret;

	tusb->vendor_specific2 = reg;

	tusb1210_probe_charger_detect(tusb);

	tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
	if (IS_ERR(tusb->phy)) {
		ret = PTR_ERR(tusb->phy);
		goto err_remove_charger;
	}

	phy_set_drvdata(tusb->phy, tusb);
	ulpi_set_drvdata(ulpi, tusb);
	return 0;

err_remove_charger:
	tusb1210_remove_charger_detect(tusb);
	return ret;
}

static void tusb1210_remove(struct ulpi *ulpi)
{
	struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);

	ulpi_phy_destroy(ulpi, tusb->phy);
	tusb1210_remove_charger_detect(tusb);
}

static const struct ulpi_device_id tusb1210_ulpi_id[] = {
	{ TI_VENDOR_ID, TI_DEVICE_TUSB1210 },
	{ TI_VENDOR_ID, TI_DEVICE_TUSB1211 },
	{ },
};
MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);

static struct ulpi_driver tusb1210_driver = {
	.id_table = tusb1210_ulpi_id,
	.probe = tusb1210_probe,
	.remove = tusb1210_remove,
	.driver = {
		.name = "tusb1210",
		.owner = THIS_MODULE,
	},
};

module_ulpi_driver(tusb1210_driver);

MODULE_AUTHOR("Intel Corporation");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");