From patchwork Sat Nov 5 20:50:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jana Rapava X-Patchwork-Id: 123889 X-Patchwork-Delegate: linux@bohmer.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 29EA6B6F6F for ; Sun, 6 Nov 2011 07:46:45 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D8D0428FCA; Sat, 5 Nov 2011 21:46:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QG+yEgY0ibFO; Sat, 5 Nov 2011 21:46:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C7F9C28D15; Sat, 5 Nov 2011 21:46:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1A55328D15 for ; Sat, 5 Nov 2011 21:46:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7uZjw9VYR6T8 for ; Sat, 5 Nov 2011 21:46:38 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-fx0-f44.google.com (mail-fx0-f44.google.com [209.85.161.44]) by theia.denx.de (Postfix) with ESMTPS id 2BCE428CC3 for ; Sat, 5 Nov 2011 21:46:36 +0100 (CET) Received: by faas12 with SMTP id s12so3800217faa.3 for ; Sat, 05 Nov 2011 13:46:36 -0700 (PDT) Received: by 10.152.144.136 with SMTP id sm8mr3409252lab.33.1320525995396; Sat, 05 Nov 2011 13:46:35 -0700 (PDT) Received: from hex.kolej.mff.cuni.cz (janalaptop.kolej.mff.cuni.cz. [78.128.199.214]) by mx.google.com with ESMTPS id lq6sm3516357lab.16.2011.11.05.13.46.33 (version=SSLv3 cipher=OTHER); Sat, 05 Nov 2011 13:46:33 -0700 (PDT) From: Jana Rapava To: u-boot@lists.denx.de Date: Sat, 5 Nov 2011 21:50:23 +0100 Message-Id: <1320526223-30474-1-git-send-email-fermata7@gmail.com> X-Mailer: git-send-email 1.7.6.3 Cc: Jana Rapava Subject: [U-Boot] [PATCH] ulpi: add generic ULPI functionality X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Add generic functions for ULPI init and setting bits in ULPI registers. Signed-off-by: Jana Rapava Cc: Marek Vasut Cc: Remy Bohmer Cc: Stefano Babic Cc: Igor Grinberg --- Makefile | 1 + drivers/usb/ulpi/Makefile | 44 ++++++++++++++ drivers/usb/ulpi/ulpi-viewport.c | 87 +++++++++++++++++++++++++++ drivers/usb/ulpi/ulpi.c | 123 ++++++++++++++++++++++++++++++++++++++ include/usb/ulpi.h | 16 +++++ 5 files changed, 271 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/ulpi/Makefile create mode 100644 drivers/usb/ulpi/ulpi-viewport.c create mode 100644 drivers/usb/ulpi/ulpi.c diff --git a/Makefile b/Makefile index 571c3eb..a475cb9 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,7 @@ LIBS += drivers/usb/gadget/libusb_gadget.o LIBS += drivers/usb/host/libusb_host.o LIBS += drivers/usb/musb/libusb_musb.o LIBS += drivers/usb/phy/libusb_phy.o +LIBS += drivers/usb/ulpi/libusb_ulpi.o LIBS += drivers/video/libvideo.o LIBS += drivers/watchdog/libwatchdog.o LIBS += common/libcommon.o diff --git a/drivers/usb/ulpi/Makefile b/drivers/usb/ulpi/Makefile new file mode 100644 index 0000000..f7b6e20 --- /dev/null +++ b/drivers/usb/ulpi/Makefile @@ -0,0 +1,44 @@ +# +# Copyright (C) 2011 Jana Rapava +# See file CREDITS for list of people who contributed to this +# project. +# +# 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. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libusb_ulpi.o + +COBJS-$(CONFIG_USB_ULPI) += ulpi.o ulpi-viewport.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/drivers/usb/ulpi/ulpi-viewport.c b/drivers/usb/ulpi/ulpi-viewport.c new file mode 100644 index 0000000..a0c213e --- /dev/null +++ b/drivers/usb/ulpi/ulpi-viewport.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011 Jana Rapava + * Based on: + * linux/drivers/usb/otg/ulpi_viewport.c + * + * Original Copyright follow: + * Copyright (C) 2011 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#include +#include +#include +#include + +/* ULPI viewport control bits */ +#define ULPI_WU (1 << 31) +#define ULPI_SS (1 << 27) +#define ULPI_RWRUN (1 << 30) +#define ULPI_RWCTRL (1 << 29) + +#define ULPI_ADDR_SHIFT 16 +#define ulpi_write_mask(value) ((value) & 0xff) +#define ulpi_read_mask(value) (((value) >> 8) & 0xff) + +int ulpi_wait(struct usb_ehci *ehci, u32 ulpi_value, u32 ulpi_mask) +{ + int timeout = ULPI_TIMEOUT; + u32 tmp; + + writel(ulpi_value, &ehci->ulpi_viewpoint); + + /* Wait for the bits in ulpi_mask to become zero. */ + while (--timeout) { + tmp = readl(&ehci->ulpi_viewpoint); + if (!(tmp & ulpi_mask)) + break; + WATCHDOG_RESET(); + } + + return !timeout; +} + +int ulpi_wakeup(struct usb_ehci *ehci) +{ + if (readl(&ehci->ulpi_viewpoint) & ULPI_SS) + return 0; /* already awake */ + return ulpi_wait(ehci, ULPI_WU, ULPI_WU); +} + +void ulpi_write(struct usb_ehci *ehci, u32 reg, u32 value) +{ + u32 tmp; + if (ulpi_wakeup(ehci)) { + printf("ULPI wakeup timed out\n"); + return; + } + + tmp = ulpi_wait(ehci, ULPI_RWRUN | ULPI_RWCTRL | + reg << ULPI_ADDR_SHIFT | ulpi_write_mask(value), ULPI_RWRUN); + if (tmp) + printf("ULPI write timed out\n"); +} + +u32 ulpi_read(struct usb_ehci *ehci, u32 reg) +{ + if (ulpi_wakeup(ehci)) { + printf("ULPI wakeup timed out\n"); + return 0; + } + + if (ulpi_wait(ehci, ULPI_RWRUN | reg << ULPI_ADDR_SHIFT, ULPI_RWRUN)) { + printf("ULPI read timed out\n"); + return 0; + } + + return ulpi_read_mask(readl(&ehci->ulpi_viewpoint)); +} diff --git a/drivers/usb/ulpi/ulpi.c b/drivers/usb/ulpi/ulpi.c new file mode 100644 index 0000000..b1c482a --- /dev/null +++ b/drivers/usb/ulpi/ulpi.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011 Jana Rapava + * Based on: + * linux/drivers/usb/otg/ulpi.c + * Generic ULPI USB transceiver support + * + * Original Copyright follow: + * Copyright (C) 2009 Daniel Mack + * + * Based on sources from + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include + +#ifdef DEBUG +#define debug(fmt, args...) printf(fmt, ##args) +#else +#define debug(fmt, args...) +#endif /* DEBUG */ + +void ulpi_integrity_check(struct usb_ehci *ehci, struct ulpi_regs *ulpi) +{ + u32 tmp = 0; + int i; + for (i = 0; i < 2; i++) { + ulpi_write(ehci, (u32)&ulpi->scratch_write, + ULPI_TEST_VALUE << i); + tmp = ulpi_read(ehci, (u32)&ulpi->scratch_write); + + if (tmp != (ULPI_TEST_VALUE << i)) { + printf("ULPI integrity check failed\n"); + return; + } + } +} + +/* + * This is a family of wrapper functions which sets bits in ULPI registers. + * Access mode could be WRITE, SET or CLEAR. + * For further informations see ULPI 1.1 specification. + */ +void ulpi_otg_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags) +{ + switch (access_mode) { + case WRITE: + ulpi_write(ehci, (u32)&ulpi->otg_ctrl_write, flags); + break; + case SET: + ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, flags); + break; + case CLEAR: + ulpi_write(ehci, (u32)&ulpi->otg_ctrl_clear, flags); + break; + } +} + +void ulpi_function_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags) +{ + switch (access_mode) { + case WRITE: + ulpi_write(ehci, (u32)&ulpi->function_ctrl_write, flags); + break; + case SET: + ulpi_write(ehci, (u32)&ulpi->function_ctrl_set, flags); + break; + case CLEAR: + ulpi_write(ehci, (u32)&ulpi->function_ctrl_clear, flags); + break; + } +} + +void ulpi_iface_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags) +{ + switch (access_mode) { + case WRITE: + ulpi_write(ehci, (u32)&ulpi->iface_ctrl_write, flags); + break; + case SET: + ulpi_write(ehci, (u32)&ulpi->iface_ctrl_set, flags); + break; + case CLEAR: + ulpi_write(ehci, (u32)&ulpi->iface_ctrl_clear, flags); + break; + } + +} + +void ulpi_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) +{ + u32 tmp = 0; + int reg; + + /* Assemble ID from four ULPI ID registers (8 bits each). */ + for (reg = ULPI_ID_REGS_COUNT - 1; reg >= 0; reg--) + tmp |= ulpi_read(ehci, reg) << (reg * 8); + + /* Split ID into vendor and product ID. */ + debug("Found ULPI TX, ID %04x:%04x\n", tmp >> 16, tmp & 0xffff); + + ulpi_integrity_check(ehci, ulpi); +} diff --git a/include/usb/ulpi.h b/include/usb/ulpi.h index 1519cc5..a8625a1 100644 --- a/include/usb/ulpi.h +++ b/include/usb/ulpi.h @@ -15,6 +15,8 @@ #ifndef __USB_ULPI_H #define __USB_ULPI_H +#include + #define ULPI_ID_REGS_COUNT 4 #define ULPI_TEST_VALUE 0x55 #define ULPI_TIMEOUT 1000 /* some reasonable value */ @@ -25,6 +27,11 @@ #define ULPI_RWRUN (1 << 30) #define ULPI_RWCTRL (1 << 29) +/* ULPI access modes */ +#define WRITE 0x00 +#define SET 0x01 +#define CLEAR 0x02 + struct ulpi_regs { /* Vendor ID and Product ID: 0x00 - 0x03 Read-only */ u8 vendor_id_low; @@ -201,4 +208,13 @@ struct ulpi_regs { void ulpi_write(struct usb_ehci *ehci, u32 reg, u32 value); u32 ulpi_read(struct usb_ehci *ehci, u32 reg); +void ulpi_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi); + +void ulpi_otg_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags); +void ulpi_function_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags); +void ulpi_iface_ctrl_flags + (struct usb_ehci *ehci, struct ulpi_regs *ulpi, int access_mode, u32 flags); + #endif /* __USB_ULPI_H */