Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * tusb1210.c - TUSB1210 USB ULPI PHY driver
0004  *
0005  * Copyright (C) 2015 Intel Corporation
0006  *
0007  * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
0008  */
0009 #include <linux/module.h>
0010 #include <linux/bitfield.h>
0011 #include <linux/delay.h>
0012 #include <linux/ulpi/driver.h>
0013 #include <linux/ulpi/regs.h>
0014 #include <linux/gpio/consumer.h>
0015 #include <linux/phy/ulpi_phy.h>
0016 #include <linux/power_supply.h>
0017 #include <linux/workqueue.h>
0018 
0019 #define TUSB1211_POWER_CONTROL              0x3d
0020 #define TUSB1211_POWER_CONTROL_SET          0x3e
0021 #define TUSB1211_POWER_CONTROL_CLEAR            0x3f
0022 #define TUSB1211_POWER_CONTROL_SW_CONTROL       BIT(0)
0023 #define TUSB1211_POWER_CONTROL_DET_COMP         BIT(1)
0024 #define TUSB1211_POWER_CONTROL_DP_VSRC_EN       BIT(6)
0025 
0026 #define TUSB1210_VENDOR_SPECIFIC2           0x80
0027 #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK        GENMASK(3, 0)
0028 #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK       GENMASK(5, 4)
0029 #define TUSB1210_VENDOR_SPECIFIC2_DP_MASK       BIT(6)
0030 
0031 #define TUSB1211_VENDOR_SPECIFIC3           0x85
0032 #define TUSB1211_VENDOR_SPECIFIC3_SET           0x86
0033 #define TUSB1211_VENDOR_SPECIFIC3_CLEAR         0x87
0034 #define TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET        BIT(4)
0035 #define TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN   BIT(6)
0036 
0037 #define TUSB1210_RESET_TIME_MS              50
0038 
0039 #define TUSB1210_CHG_DET_MAX_RETRIES            5
0040 
0041 /* TUSB1210 charger detection work states */
0042 enum tusb1210_chg_det_state {
0043     TUSB1210_CHG_DET_CONNECTING,
0044     TUSB1210_CHG_DET_START_DET,
0045     TUSB1210_CHG_DET_READ_DET,
0046     TUSB1210_CHG_DET_FINISH_DET,
0047     TUSB1210_CHG_DET_CONNECTED,
0048     TUSB1210_CHG_DET_DISCONNECTING,
0049     TUSB1210_CHG_DET_DISCONNECTING_DONE,
0050     TUSB1210_CHG_DET_DISCONNECTED,
0051 };
0052 
0053 struct tusb1210 {
0054     struct ulpi *ulpi;
0055     struct phy *phy;
0056     struct gpio_desc *gpio_reset;
0057     struct gpio_desc *gpio_cs;
0058     u8 otg_ctrl;
0059     u8 vendor_specific2;
0060 #ifdef CONFIG_POWER_SUPPLY
0061     enum power_supply_usb_type chg_type;
0062     enum tusb1210_chg_det_state chg_det_state;
0063     int chg_det_retries;
0064     struct delayed_work chg_det_work;
0065     struct notifier_block psy_nb;
0066     struct power_supply *psy;
0067     struct power_supply *charger;
0068 #endif
0069 };
0070 
0071 static int tusb1210_ulpi_write(struct tusb1210 *tusb, u8 reg, u8 val)
0072 {
0073     int ret;
0074 
0075     ret = ulpi_write(tusb->ulpi, reg, val);
0076     if (ret)
0077         dev_err(&tusb->ulpi->dev, "error %d writing val 0x%02x to reg 0x%02x\n",
0078             ret, val, reg);
0079 
0080     return ret;
0081 }
0082 
0083 static int tusb1210_ulpi_read(struct tusb1210 *tusb, u8 reg, u8 *val)
0084 {
0085     int ret;
0086 
0087     ret = ulpi_read(tusb->ulpi, reg);
0088     if (ret >= 0) {
0089         *val = ret;
0090         ret = 0;
0091     } else {
0092         dev_err(&tusb->ulpi->dev, "error %d reading reg 0x%02x\n", ret, reg);
0093     }
0094 
0095     return ret;
0096 }
0097 
0098 static int tusb1210_power_on(struct phy *phy)
0099 {
0100     struct tusb1210 *tusb = phy_get_drvdata(phy);
0101 
0102     gpiod_set_value_cansleep(tusb->gpio_reset, 1);
0103     gpiod_set_value_cansleep(tusb->gpio_cs, 1);
0104 
0105     msleep(TUSB1210_RESET_TIME_MS);
0106 
0107     /* Restore the optional eye diagram optimization value */
0108     tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, tusb->vendor_specific2);
0109 
0110     return 0;
0111 }
0112 
0113 static int tusb1210_power_off(struct phy *phy)
0114 {
0115     struct tusb1210 *tusb = phy_get_drvdata(phy);
0116 
0117     gpiod_set_value_cansleep(tusb->gpio_reset, 0);
0118     gpiod_set_value_cansleep(tusb->gpio_cs, 0);
0119 
0120     return 0;
0121 }
0122 
0123 static int tusb1210_set_mode(struct phy *phy, enum phy_mode mode, int submode)
0124 {
0125     struct tusb1210 *tusb = phy_get_drvdata(phy);
0126     int ret;
0127     u8 reg;
0128 
0129     ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &reg);
0130     if (ret < 0)
0131         return ret;
0132 
0133     switch (mode) {
0134     case PHY_MODE_USB_HOST:
0135         reg |= (ULPI_OTG_CTRL_DRVVBUS_EXT
0136             | ULPI_OTG_CTRL_ID_PULLUP
0137             | ULPI_OTG_CTRL_DP_PULLDOWN
0138             | ULPI_OTG_CTRL_DM_PULLDOWN);
0139         tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
0140         reg |= ULPI_OTG_CTRL_DRVVBUS;
0141         break;
0142     case PHY_MODE_USB_DEVICE:
0143         reg &= ~(ULPI_OTG_CTRL_DRVVBUS
0144              | ULPI_OTG_CTRL_DP_PULLDOWN
0145              | ULPI_OTG_CTRL_DM_PULLDOWN);
0146         tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
0147         reg &= ~ULPI_OTG_CTRL_DRVVBUS_EXT;
0148         break;
0149     default:
0150         /* nothing */
0151         return 0;
0152     }
0153 
0154     tusb->otg_ctrl = reg;
0155     return tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, reg);
0156 }
0157 
0158 #ifdef CONFIG_POWER_SUPPLY
0159 static const char * const tusb1210_chg_det_states[] = {
0160     "CHG_DET_CONNECTING",
0161     "CHG_DET_START_DET",
0162     "CHG_DET_READ_DET",
0163     "CHG_DET_FINISH_DET",
0164     "CHG_DET_CONNECTED",
0165     "CHG_DET_DISCONNECTING",
0166     "CHG_DET_DISCONNECTING_DONE",
0167     "CHG_DET_DISCONNECTED",
0168 };
0169 
0170 static void tusb1210_reset(struct tusb1210 *tusb)
0171 {
0172     gpiod_set_value_cansleep(tusb->gpio_reset, 0);
0173     usleep_range(200, 500);
0174     gpiod_set_value_cansleep(tusb->gpio_reset, 1);
0175 }
0176 
0177 static void tusb1210_chg_det_set_type(struct tusb1210 *tusb,
0178                       enum power_supply_usb_type type)
0179 {
0180     dev_dbg(&tusb->ulpi->dev, "charger type: %d\n", type);
0181     tusb->chg_type = type;
0182     tusb->chg_det_retries = 0;
0183     power_supply_changed(tusb->psy);
0184 }
0185 
0186 static void tusb1210_chg_det_set_state(struct tusb1210 *tusb,
0187                        enum tusb1210_chg_det_state new_state,
0188                        int delay_ms)
0189 {
0190     if (delay_ms)
0191         dev_dbg(&tusb->ulpi->dev, "chg_det new state %s in %d ms\n",
0192             tusb1210_chg_det_states[new_state], delay_ms);
0193 
0194     tusb->chg_det_state = new_state;
0195     mod_delayed_work(system_long_wq, &tusb->chg_det_work,
0196              msecs_to_jiffies(delay_ms));
0197 }
0198 
0199 static void tusb1210_chg_det_handle_ulpi_error(struct tusb1210 *tusb)
0200 {
0201     tusb1210_reset(tusb);
0202     if (tusb->chg_det_retries < TUSB1210_CHG_DET_MAX_RETRIES) {
0203         tusb->chg_det_retries++;
0204         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET,
0205                        TUSB1210_RESET_TIME_MS);
0206     } else {
0207         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET,
0208                        TUSB1210_RESET_TIME_MS);
0209     }
0210 }
0211 
0212 /*
0213  * Boards using a TUSB121x for charger-detection have 3 power_supply class devs:
0214  *
0215  * tusb1211-charger-detect(1) -> charger -> fuel-gauge
0216  *
0217  * To determine if an USB charger is connected to the board, the online prop of
0218  * the charger psy needs to be read. Since the tusb1211-charger-detect psy is
0219  * the start of the supplier -> supplied-to chain, power_supply_am_i_supplied()
0220  * cannot be used here.
0221  *
0222  * Instead, below is a list of the power_supply names of known chargers for
0223  * these boards and the charger psy is looked up by name from this list.
0224  *
0225  * (1) modelling the external USB charger
0226  */
0227 static const char * const tusb1210_chargers[] = {
0228     "bq24190-charger",
0229 };
0230 
0231 static bool tusb1210_get_online(struct tusb1210 *tusb)
0232 {
0233     union power_supply_propval val;
0234     int i;
0235 
0236     for (i = 0; i < ARRAY_SIZE(tusb1210_chargers) && !tusb->charger; i++)
0237         tusb->charger = power_supply_get_by_name(tusb1210_chargers[i]);
0238 
0239     if (!tusb->charger)
0240         return false;
0241 
0242     if (power_supply_get_property(tusb->charger, POWER_SUPPLY_PROP_ONLINE, &val))
0243         return false;
0244 
0245     return val.intval;
0246 }
0247 
0248 static void tusb1210_chg_det_work(struct work_struct *work)
0249 {
0250     struct tusb1210 *tusb = container_of(work, struct tusb1210, chg_det_work.work);
0251     bool vbus_present = tusb1210_get_online(tusb);
0252     int ret;
0253     u8 val;
0254 
0255     dev_dbg(&tusb->ulpi->dev, "chg_det state %s vbus_present %d\n",
0256         tusb1210_chg_det_states[tusb->chg_det_state], vbus_present);
0257 
0258     switch (tusb->chg_det_state) {
0259     case TUSB1210_CHG_DET_CONNECTING:
0260         tusb->chg_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
0261         tusb->chg_det_retries = 0;
0262         /* Power on USB controller for ulpi_read()/_write() */
0263         ret = pm_runtime_resume_and_get(tusb->ulpi->dev.parent);
0264         if (ret < 0) {
0265             dev_err(&tusb->ulpi->dev, "error %d runtime-resuming\n", ret);
0266             /* Should never happen, skip charger detection */
0267             tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
0268             return;
0269         }
0270         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_START_DET, 0);
0271         break;
0272     case TUSB1210_CHG_DET_START_DET:
0273         /*
0274          * Use the builtin charger detection FSM to keep things simple.
0275          * This only detects DCP / SDP. This is good enough for the few
0276          * boards which actually rely on the phy for charger detection.
0277          */
0278         mutex_lock(&tusb->phy->mutex);
0279         ret = tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_SET,
0280                       TUSB1211_VENDOR_SPECIFIC3_SW_USB_DET);
0281         mutex_unlock(&tusb->phy->mutex);
0282         if (ret) {
0283             tusb1210_chg_det_handle_ulpi_error(tusb);
0284             break;
0285         }
0286 
0287         /* Wait 400 ms for the charger detection FSM to finish */
0288         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_READ_DET, 400);
0289         break;
0290     case TUSB1210_CHG_DET_READ_DET:
0291         mutex_lock(&tusb->phy->mutex);
0292         ret = tusb1210_ulpi_read(tusb, TUSB1211_POWER_CONTROL, &val);
0293         mutex_unlock(&tusb->phy->mutex);
0294         if (ret) {
0295             tusb1210_chg_det_handle_ulpi_error(tusb);
0296             break;
0297         }
0298 
0299         if (val & TUSB1211_POWER_CONTROL_DET_COMP)
0300             tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_DCP);
0301         else
0302             tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_SDP);
0303 
0304         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_FINISH_DET, 0);
0305         break;
0306     case TUSB1210_CHG_DET_FINISH_DET:
0307         mutex_lock(&tusb->phy->mutex);
0308 
0309         /* Set SW_CONTROL to stop the charger-det FSM */
0310         ret = tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_SET,
0311                       TUSB1211_POWER_CONTROL_SW_CONTROL);
0312 
0313         /* Clear DP_VSRC_EN which may have been enabled by the charger-det FSM */
0314         ret |= tusb1210_ulpi_write(tusb, TUSB1211_POWER_CONTROL_CLEAR,
0315                        TUSB1211_POWER_CONTROL_DP_VSRC_EN);
0316 
0317         /* Clear CHGD_IDP_SRC_EN (may have been enabled by the charger-det FSM) */
0318         ret |= tusb1210_ulpi_write(tusb, TUSB1211_VENDOR_SPECIFIC3_CLEAR,
0319                        TUSB1211_VENDOR_SPECIFIC3_CHGD_IDP_SRC_EN);
0320 
0321         /* If any of the above fails reset the phy */
0322         if (ret) {
0323             tusb1210_reset(tusb);
0324             msleep(TUSB1210_RESET_TIME_MS);
0325         }
0326 
0327         /* Restore phy-parameters and OTG_CTRL register */
0328         tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, tusb->otg_ctrl);
0329         tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2,
0330                     tusb->vendor_specific2);
0331 
0332         mutex_unlock(&tusb->phy->mutex);
0333 
0334         pm_runtime_put(tusb->ulpi->dev.parent);
0335         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTED, 0);
0336         break;
0337     case TUSB1210_CHG_DET_CONNECTED:
0338         if (!vbus_present)
0339             tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING, 0);
0340         break;
0341     case TUSB1210_CHG_DET_DISCONNECTING:
0342         /*
0343          * The phy seems to take approx. 600ms longer then the charger
0344          * chip (which is used to get vbus_present) to determine Vbus
0345          * session end. Wait 800ms to ensure the phy has detected and
0346          * signalled Vbus session end.
0347          */
0348         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTING_DONE, 800);
0349         break;
0350     case TUSB1210_CHG_DET_DISCONNECTING_DONE:
0351         /*
0352          * The phy often stops reacting to ulpi_read()/_write requests
0353          * after a Vbus-session end. Reset it to work around this.
0354          */
0355         tusb1210_reset(tusb);
0356         tusb1210_chg_det_set_type(tusb, POWER_SUPPLY_USB_TYPE_UNKNOWN);
0357         tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_DISCONNECTED, 0);
0358         break;
0359     case TUSB1210_CHG_DET_DISCONNECTED:
0360         if (vbus_present)
0361             tusb1210_chg_det_set_state(tusb, TUSB1210_CHG_DET_CONNECTING, 0);
0362         break;
0363     }
0364 }
0365 
0366 static int tusb1210_psy_notifier(struct notifier_block *nb,
0367     unsigned long event, void *ptr)
0368 {
0369     struct tusb1210 *tusb = container_of(nb, struct tusb1210, psy_nb);
0370     struct power_supply *psy = ptr;
0371 
0372     if (psy != tusb->psy && psy->desc->type == POWER_SUPPLY_TYPE_USB)
0373         queue_delayed_work(system_long_wq, &tusb->chg_det_work, 0);
0374 
0375     return NOTIFY_OK;
0376 }
0377 
0378 static int tusb1210_psy_get_prop(struct power_supply *psy,
0379                  enum power_supply_property psp,
0380                  union power_supply_propval *val)
0381 {
0382     struct tusb1210 *tusb = power_supply_get_drvdata(psy);
0383 
0384     switch (psp) {
0385     case POWER_SUPPLY_PROP_ONLINE:
0386         val->intval = tusb1210_get_online(tusb);
0387         break;
0388     case POWER_SUPPLY_PROP_USB_TYPE:
0389         val->intval = tusb->chg_type;
0390         break;
0391     case POWER_SUPPLY_PROP_CURRENT_MAX:
0392         if (tusb->chg_type == POWER_SUPPLY_USB_TYPE_DCP)
0393             val->intval = 2000000;
0394         else
0395             val->intval = 500000;
0396         break;
0397     default:
0398         return -EINVAL;
0399     }
0400 
0401     return 0;
0402 }
0403 
0404 static const enum power_supply_usb_type tusb1210_psy_usb_types[] = {
0405     POWER_SUPPLY_USB_TYPE_SDP,
0406     POWER_SUPPLY_USB_TYPE_DCP,
0407     POWER_SUPPLY_USB_TYPE_UNKNOWN,
0408 };
0409 
0410 static const enum power_supply_property tusb1210_psy_props[] = {
0411     POWER_SUPPLY_PROP_ONLINE,
0412     POWER_SUPPLY_PROP_USB_TYPE,
0413     POWER_SUPPLY_PROP_CURRENT_MAX,
0414 };
0415 
0416 static const struct power_supply_desc tusb1210_psy_desc = {
0417     .name = "tusb1211-charger-detect",
0418     .type = POWER_SUPPLY_TYPE_USB,
0419     .usb_types = tusb1210_psy_usb_types,
0420     .num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types),
0421     .properties = tusb1210_psy_props,
0422     .num_properties = ARRAY_SIZE(tusb1210_psy_props),
0423     .get_property = tusb1210_psy_get_prop,
0424 };
0425 
0426 /* Setup charger detection if requested, on errors continue without chg-det */
0427 static void tusb1210_probe_charger_detect(struct tusb1210 *tusb)
0428 {
0429     struct power_supply_config psy_cfg = { .drv_data = tusb };
0430     struct device *dev = &tusb->ulpi->dev;
0431     int ret;
0432 
0433     if (!device_property_read_bool(dev->parent, "linux,phy_charger_detect"))
0434         return;
0435 
0436     if (tusb->ulpi->id.product != 0x1508) {
0437         dev_err(dev, "error charger detection is only supported on the TUSB1211\n");
0438         return;
0439     }
0440 
0441     ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &tusb->otg_ctrl);
0442     if (ret)
0443         return;
0444 
0445     tusb->psy = power_supply_register(dev, &tusb1210_psy_desc, &psy_cfg);
0446     if (IS_ERR(tusb->psy))
0447         return;
0448 
0449     /*
0450      * Delay initial run by 2 seconds to allow the charger driver,
0451      * which is used to determine vbus_present, to load.
0452      */
0453     tusb->chg_det_state = TUSB1210_CHG_DET_DISCONNECTED;
0454     INIT_DELAYED_WORK(&tusb->chg_det_work, tusb1210_chg_det_work);
0455     queue_delayed_work(system_long_wq, &tusb->chg_det_work, 2 * HZ);
0456 
0457     tusb->psy_nb.notifier_call = tusb1210_psy_notifier;
0458     power_supply_reg_notifier(&tusb->psy_nb);
0459 }
0460 
0461 static void tusb1210_remove_charger_detect(struct tusb1210 *tusb)
0462 {
0463 
0464     if (!IS_ERR_OR_NULL(tusb->psy)) {
0465         power_supply_unreg_notifier(&tusb->psy_nb);
0466         cancel_delayed_work_sync(&tusb->chg_det_work);
0467         power_supply_unregister(tusb->psy);
0468     }
0469 
0470     if (tusb->charger)
0471         power_supply_put(tusb->charger);
0472 }
0473 #else
0474 static void tusb1210_probe_charger_detect(struct tusb1210 *tusb) { }
0475 static void tusb1210_remove_charger_detect(struct tusb1210 *tusb) { }
0476 #endif
0477 
0478 static const struct phy_ops phy_ops = {
0479     .power_on = tusb1210_power_on,
0480     .power_off = tusb1210_power_off,
0481     .set_mode = tusb1210_set_mode,
0482     .owner = THIS_MODULE,
0483 };
0484 
0485 static int tusb1210_probe(struct ulpi *ulpi)
0486 {
0487     struct tusb1210 *tusb;
0488     u8 val, reg;
0489     int ret;
0490 
0491     tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
0492     if (!tusb)
0493         return -ENOMEM;
0494 
0495     tusb->ulpi = ulpi;
0496 
0497     tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset",
0498                            GPIOD_OUT_LOW);
0499     if (IS_ERR(tusb->gpio_reset))
0500         return PTR_ERR(tusb->gpio_reset);
0501 
0502     gpiod_set_value_cansleep(tusb->gpio_reset, 1);
0503 
0504     tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs",
0505                         GPIOD_OUT_LOW);
0506     if (IS_ERR(tusb->gpio_cs))
0507         return PTR_ERR(tusb->gpio_cs);
0508 
0509     gpiod_set_value_cansleep(tusb->gpio_cs, 1);
0510 
0511     /*
0512      * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye
0513      * diagram optimization and DP/DM swap.
0514      */
0515 
0516     ret = tusb1210_ulpi_read(tusb, TUSB1210_VENDOR_SPECIFIC2, &reg);
0517     if (ret)
0518         return ret;
0519 
0520     /* High speed output drive strength configuration */
0521     if (!device_property_read_u8(&ulpi->dev, "ihstx", &val))
0522         u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK);
0523 
0524     /* High speed output impedance configuration */
0525     if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val))
0526         u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK);
0527 
0528     /* DP/DM swap control */
0529     if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val))
0530         u8p_replace_bits(&reg, val, (u8)TUSB1210_VENDOR_SPECIFIC2_DP_MASK);
0531 
0532     ret = tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, reg);
0533     if (ret)
0534         return ret;
0535 
0536     tusb->vendor_specific2 = reg;
0537 
0538     tusb1210_probe_charger_detect(tusb);
0539 
0540     tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
0541     if (IS_ERR(tusb->phy)) {
0542         ret = PTR_ERR(tusb->phy);
0543         goto err_remove_charger;
0544     }
0545 
0546     phy_set_drvdata(tusb->phy, tusb);
0547     ulpi_set_drvdata(ulpi, tusb);
0548     return 0;
0549 
0550 err_remove_charger:
0551     tusb1210_remove_charger_detect(tusb);
0552     return ret;
0553 }
0554 
0555 static void tusb1210_remove(struct ulpi *ulpi)
0556 {
0557     struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
0558 
0559     ulpi_phy_destroy(ulpi, tusb->phy);
0560     tusb1210_remove_charger_detect(tusb);
0561 }
0562 
0563 #define TI_VENDOR_ID 0x0451
0564 
0565 static const struct ulpi_device_id tusb1210_ulpi_id[] = {
0566     { TI_VENDOR_ID, 0x1507, },  /* TUSB1210 */
0567     { TI_VENDOR_ID, 0x1508, },  /* TUSB1211 */
0568     { },
0569 };
0570 MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
0571 
0572 static struct ulpi_driver tusb1210_driver = {
0573     .id_table = tusb1210_ulpi_id,
0574     .probe = tusb1210_probe,
0575     .remove = tusb1210_remove,
0576     .driver = {
0577         .name = "tusb1210",
0578         .owner = THIS_MODULE,
0579     },
0580 };
0581 
0582 module_ulpi_driver(tusb1210_driver);
0583 
0584 MODULE_AUTHOR("Intel Corporation");
0585 MODULE_LICENSE("GPL v2");
0586 MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");