X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fusb%2Fulpi%2Fulpi.c;h=f3d18564b0147c4b881c610907fbd0d205c4a332;hb=18aa5a4134e8179c7c3e38675822284a2718a3d8;hp=805e29d76c4d945d8668e76936f98ffb02ca5a16;hpb=b2eb7d9bc6032e16b7dd898f7c0ea654f63b61db;p=u-boot diff --git a/drivers/usb/ulpi/ulpi.c b/drivers/usb/ulpi/ulpi.c index 805e29d76c..f3d18564b0 100644 --- a/drivers/usb/ulpi/ulpi.c +++ b/drivers/usb/ulpi/ulpi.c @@ -17,15 +17,7 @@ * Sascha Hauer * Freescale Semiconductors * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -37,18 +29,18 @@ static struct ulpi_regs *ulpi = (struct ulpi_regs *)0; -static int ulpi_integrity_check(u32 ulpi_viewport) +static int ulpi_integrity_check(struct ulpi_viewport *ulpi_vp) { - u32 err, val, tval = ULPI_TEST_VALUE; - int i; + u32 val, tval = ULPI_TEST_VALUE; + int err, i; /* Use the 'special' test value to check all bits */ for (i = 0; i < 2; i++, tval <<= 1) { - err = ulpi_write(ulpi_viewport, &ulpi->scratch, tval); + err = ulpi_write(ulpi_vp, &ulpi->scratch, tval); if (err) return err; - val = ulpi_read(ulpi_viewport, &ulpi->scratch); + val = ulpi_read(ulpi_vp, &ulpi->scratch); if (val != tval) { printf("ULPI integrity check failed\n"); return val; @@ -58,7 +50,7 @@ static int ulpi_integrity_check(u32 ulpi_viewport) return 0; } -int ulpi_init(u32 ulpi_viewport) +int ulpi_init(struct ulpi_viewport *ulpi_vp) { u32 val, id = 0; u8 *reg = &ulpi->product_id_high; @@ -66,7 +58,7 @@ int ulpi_init(u32 ulpi_viewport) /* Assemble ID from four ULPI ID registers (8 bits each). */ for (i = 0; i < ULPI_ID_REGS_COUNT; i++) { - val = ulpi_read(ulpi_viewport, reg - i); + val = ulpi_read(ulpi_vp, reg - i); if (val == ULPI_ERROR) return val; @@ -76,12 +68,12 @@ int ulpi_init(u32 ulpi_viewport) /* Split ID into vendor and product ID. */ debug("ULPI transceiver ID 0x%04x:0x%04x\n", id >> 16, id & 0xffff); - return ulpi_integrity_check(ulpi_viewport); + return ulpi_integrity_check(ulpi_vp); } -int ulpi_select_transceiver(u32 ulpi_viewport, u8 speed) +int ulpi_select_transceiver(struct ulpi_viewport *ulpi_vp, unsigned speed) { - u8 tspeed = ULPI_FC_FULL_SPEED; + u32 tspeed = ULPI_FC_FULL_SPEED; u32 val; switch (speed) { @@ -92,44 +84,69 @@ int ulpi_select_transceiver(u32 ulpi_viewport, u8 speed) tspeed = speed; break; default: - printf("ULPI: %s: wrong transceiver speed specified, " - "falling back to full speed\n", __func__); + printf("ULPI: %s: wrong transceiver speed specified: %u, " + "falling back to full speed\n", __func__, speed); } - val = ulpi_read(ulpi_viewport, &ulpi->function_ctrl); + val = ulpi_read(ulpi_vp, &ulpi->function_ctrl); if (val == ULPI_ERROR) return val; /* clear the previous speed setting */ val = (val & ~ULPI_FC_XCVRSEL_MASK) | tspeed; - return ulpi_write(ulpi_viewport, &ulpi->function_ctrl, val); + return ulpi_write(ulpi_vp, &ulpi->function_ctrl, val); } -int ulpi_set_vbus(u32 ulpi_viewport, int on, int ext_power, int ext_ind) +int ulpi_set_vbus(struct ulpi_viewport *ulpi_vp, int on, int ext_power) { u32 flags = ULPI_OTG_DRVVBUS; u8 *reg = on ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear; if (ext_power) flags |= ULPI_OTG_DRVVBUS_EXT; - if (ext_ind) - flags |= ULPI_OTG_EXTVBUSIND; - return ulpi_write(ulpi_viewport, reg, flags); + return ulpi_write(ulpi_vp, reg, flags); +} + +int ulpi_set_vbus_indicator(struct ulpi_viewport *ulpi_vp, int external, + int passthu, int complement) +{ + u32 flags, val; + u8 *reg; + + reg = external ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear; + val = ulpi_write(ulpi_vp, reg, ULPI_OTG_EXTVBUSIND); + if (val) + return val; + + flags = passthu ? ULPI_IFACE_PASSTHRU : 0; + flags |= complement ? ULPI_IFACE_EXTVBUS_COMPLEMENT : 0; + + val = ulpi_read(ulpi_vp, &ulpi->iface_ctrl); + if (val == ULPI_ERROR) + return val; + + val = val & ~(ULPI_IFACE_PASSTHRU & ULPI_IFACE_EXTVBUS_COMPLEMENT); + val |= flags; + val = ulpi_write(ulpi_vp, &ulpi->iface_ctrl, val); + if (val) + return val; + + return 0; } -int ulpi_set_pd(u32 ulpi_viewport, int enable) +int ulpi_set_pd(struct ulpi_viewport *ulpi_vp, int enable) { u32 val = ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN; u8 *reg = enable ? &ulpi->otg_ctrl_set : &ulpi->otg_ctrl_clear; - return ulpi_write(ulpi_viewport, reg, val); + return ulpi_write(ulpi_vp, reg, val); } -int ulpi_opmode_sel(u32 ulpi_viewport, u8 opmode) +int ulpi_opmode_sel(struct ulpi_viewport *ulpi_vp, unsigned opmode) { - u8 topmode = ULPI_FC_OPMODE_NORMAL; + u32 topmode = ULPI_FC_OPMODE_NORMAL; u32 val; switch (opmode) { @@ -140,40 +157,40 @@ int ulpi_opmode_sel(u32 ulpi_viewport, u8 opmode) topmode = opmode; break; default: - printf("ULPI: %s: wrong OpMode specified, " - "falling back to OpMode Normal\n", __func__); + printf("ULPI: %s: wrong OpMode specified: %u, " + "falling back to OpMode Normal\n", __func__, opmode); } - val = ulpi_read(ulpi_viewport, &ulpi->function_ctrl); + val = ulpi_read(ulpi_vp, &ulpi->function_ctrl); if (val == ULPI_ERROR) return val; /* clear the previous opmode setting */ val = (val & ~ULPI_FC_OPMODE_MASK) | topmode; - return ulpi_write(ulpi_viewport, &ulpi->function_ctrl, val); + return ulpi_write(ulpi_vp, &ulpi->function_ctrl, val); } -int ulpi_serial_mode_enable(u32 ulpi_viewport, u8 smode) +int ulpi_serial_mode_enable(struct ulpi_viewport *ulpi_vp, unsigned smode) { switch (smode) { case ULPI_IFACE_6_PIN_SERIAL_MODE: case ULPI_IFACE_3_PIN_SERIAL_MODE: break; default: - printf("ULPI: %s: unrecognized Serial Mode specified\n", - __func__); + printf("ULPI: %s: unrecognized Serial Mode specified: %u\n", + __func__, smode); return ULPI_ERROR; } - return ulpi_write(ulpi_viewport, &ulpi->iface_ctrl_set, smode); + return ulpi_write(ulpi_vp, &ulpi->iface_ctrl_set, smode); } -int ulpi_suspend(u32 ulpi_viewport) +int ulpi_suspend(struct ulpi_viewport *ulpi_vp) { - u32 err; + int err; - err = ulpi_write(ulpi_viewport, &ulpi->function_ctrl_clear, + err = ulpi_write(ulpi_vp, &ulpi->function_ctrl_clear, ULPI_FC_SUSPENDM); if (err) printf("ULPI: %s: failed writing the suspend bit\n", __func__); @@ -186,7 +203,7 @@ int ulpi_suspend(u32 ulpi_viewport) * Actual wait for reset must be done in a view port specific way, * because it involves checking the DIR line. */ -static int __ulpi_reset_wait(u32 ulpi_viewport) +static int __ulpi_reset_wait(struct ulpi_viewport *ulpi_vp) { u32 val; int timeout = CONFIG_USB_ULPI_TIMEOUT; @@ -199,7 +216,7 @@ static int __ulpi_reset_wait(u32 ulpi_viewport) * for the error of ulpi_read(), if there is one, then * there will be a timeout. */ - val = ulpi_read(ulpi_viewport, &ulpi->function_ctrl); + val = ulpi_read(ulpi_vp, &ulpi->function_ctrl); if (!(val & ULPI_FC_RESET)) return 0; @@ -210,18 +227,19 @@ static int __ulpi_reset_wait(u32 ulpi_viewport) return ULPI_ERROR; } -int ulpi_reset_wait(u32) __attribute__((weak, alias("__ulpi_reset_wait"))); +int ulpi_reset_wait(struct ulpi_viewport *ulpi_vp) + __attribute__((weak, alias("__ulpi_reset_wait"))); -int ulpi_reset(u32 ulpi_viewport) +int ulpi_reset(struct ulpi_viewport *ulpi_vp) { - u32 err; + int err; - err = ulpi_write(ulpi_viewport, + err = ulpi_write(ulpi_vp, &ulpi->function_ctrl_set, ULPI_FC_RESET); if (err) { printf("ULPI: %s: failed writing reset bit\n", __func__); return err; } - return ulpi_reset_wait(ulpi_viewport); + return ulpi_reset_wait(ulpi_vp); }