From patchwork Mon Jul 22 20:23:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1963881 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=eDDKg6Z9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSyq62v24z1ybY for ; Tue, 23 Jul 2024 23:36:34 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42454887E6; Tue, 23 Jul 2024 15:35:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="eDDKg6Z9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D4CF58845A; Mon, 22 Jul 2024 22:24:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B38787F82 for ; Mon, 22 Jul 2024 22:24:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42660b8dd27so33610515e9.3 for ; Mon, 22 Jul 2024 13:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1721679886; x=1722284686; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XGrPkQGQgBNeiqM+95Ef10zl3y1GW6QJFZow6A3e+Ko=; b=eDDKg6Z9bWM18MYVjyT+AzZLZkvMEBCs8W2D8mzFu/Orh2dxqD6jfZ/RqFo7yHo49T NErHM1HAe73+NMaISWMHFBeTlC77x9yPhHQQfvgMfvXodde7soUzFZcwZsOqdWJIoeju 0al4ssKIOfZHjPeztZTHMnfX4hlAT7geT3vjIuDPe7vc8He5X+z0APt+9VZYYeYuFPDK zzItesuQypcIw3jFInBFeHpx7aIdopxg7qQFMYM7iZdF3RrvMOZs36zxtpGAT0nPc2fu fAe0tYD3J0YW6mkESPoTFB28SKmn0lJqJrQuWeOhCXY79jmpKoDrUQK0N5xB5ms+x8Ux KBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721679886; x=1722284686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XGrPkQGQgBNeiqM+95Ef10zl3y1GW6QJFZow6A3e+Ko=; b=LZa8DhS0EEGTyvLTQeZEfjLbokLU5vKR7sGq8HknCf2xMJ+cyTidTp6WzclXCJLFOE uh4AAQsIjq6IIATBcqB2OBpvuCVfOkch2VsaSj0l/X0teAIcDYmVfcGpW6mLhibAbalz Lk/QX5J5bcMRzLtyi+KkIyZqyVwHbTlVUBcZ2QaVg79PL+TaAppbTeCi6Mm/xbLFRbRJ 8oZzIguPo3NWJgfk6PCasXCMV6jkqohTQ8qGTwCVwP+3cP2aKChn4utKxzdP7KoCf+C5 pTCj6YpTOwR9gPhu7sT549dD3n5tt2LwAfkz6qZgXPwXNhS6UHtcvOIpS1wK2eXI5XJ8 1MbA== X-Forwarded-Encrypted: i=1; AJvYcCWxMR4Tk/SeJkKGR/vsTeyduz/eo27MIIOFkpmLZIPA6Qu/Dd0PdLiV6+BzHLrC4kBtHa4aTlkr/sQ63HFGWTCftDNqPw== X-Gm-Message-State: AOJu0YyNdl+/emdhX5/tlusxqpFaGg8yC3GTF+i5N2iwuxE+/cpUiqGw GQJubaKTYLj2xvNATVDjcMNCKjbCqwyhkk4JEHWcvckj36ahz03uHbtRWX/6wGMQwg6m4JWk/gP S4pWtyQ== X-Google-Smtp-Source: AGHT+IE0aMML5tlLiPad59CfZ4i6w1jKLKJWEM/wplBEjxLCMixVgISK6Kd4L1El15i5YityPPWeGg== X-Received: by 2002:a05:600c:3542:b0:426:5c36:207c with SMTP id 5b1f17b1804b1-427dc569de8mr48664705e9.25.1721679885811; Mon, 22 Jul 2024 13:24:45 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d69071d0sm142982855e9.26.2024.07.22.13.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:24:45 -0700 (PDT) From: Zixun LI X-Google-Original-From: Zixun LI To: Lukasz Majewski , Mattijs Korpershoek , Marek Vasut , Tom Rini Cc: Zixun LI , u-boot@lists.denx.de Subject: [PATCH v2 1/4] usb: gadget: atmel: Code refactor part 1 Date: Mon, 22 Jul 2024 22:23:27 +0200 Message-ID: <20240722202426.190986-2-zli@ogga.fr> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240722202426.190986-1-zli@ogga.fr> References: <20240722202426.190986-1-zli@ogga.fr> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 23 Jul 2024 15:35:55 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean - Sort includes - Forward declare controller structures Signed-off-by: Zixun LI --- drivers/usb/gadget/atmel_usba_udc.c | 59 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index f99553df8d..476e7ed619 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c @@ -7,19 +7,22 @@ * Bo Shen */ -#include -#include +#include +#include +#include #include #include +#include +#include #include -#include #include #include #include -#include #include "atmel_usba_udc.h" +static struct usba_udc *controller; + static int vbus_is_present(struct usba_udc *udc) { /* No Vbus detection: Assume always present */ @@ -506,12 +509,6 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) return 0; } -static const struct usb_gadget_ops usba_udc_ops = { - .get_frame = usba_udc_get_frame, - .wakeup = usba_udc_wakeup, - .set_selfpowered = usba_udc_set_selfpowered, -}; - static struct usb_endpoint_descriptor usba_ep0_desc = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, @@ -1179,28 +1176,16 @@ static int atmel_usba_stop(struct usba_udc *udc) return 0; } -static struct usba_udc controller = { - .regs = (unsigned *)ATMEL_BASE_UDPHS, - .fifo = (unsigned *)ATMEL_BASE_UDPHS_FIFO, - .gadget = { - .ops = &usba_udc_ops, - .ep_list = LIST_HEAD_INIT(controller.gadget.ep_list), - .speed = USB_SPEED_HIGH, - .is_dualspeed = 1, - .name = "atmel_usba_udc", - }, -}; - int dm_usb_gadget_handle_interrupts(struct udevice *dev) { - struct usba_udc *udc = &controller; + struct usba_udc *udc = controller; return usba_udc_irq(udc); } int usb_gadget_register_driver(struct usb_gadget_driver *driver) { - struct usba_udc *udc = &controller; + struct usba_udc *udc = controller; int ret; if (!driver || !driver->bind || !driver->setup) { @@ -1228,7 +1213,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) { - struct usba_udc *udc = &controller; + struct usba_udc *udc = controller; if (!driver || !driver->unbind || !driver->disconnect) { pr_err("bad paramter\n"); @@ -1244,6 +1229,24 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) return 0; } +static const struct usb_gadget_ops usba_udc_ops = { + .get_frame = usba_udc_get_frame, + .wakeup = usba_udc_wakeup, + .set_selfpowered = usba_udc_set_selfpowered, +}; + +static struct usba_udc udc_controller = { + .regs = (unsigned int *)ATMEL_BASE_UDPHS, + .fifo = (unsigned int *)ATMEL_BASE_UDPHS_FIFO, + .gadget = { + .ops = &usba_udc_ops, + .ep_list = LIST_HEAD_INIT(udc_controller.gadget.ep_list), + .speed = USB_SPEED_HIGH, + .is_dualspeed = 1, + .name = "atmel_usba_udc", + }, +}; + static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata, struct usba_udc *udc) { @@ -1286,11 +1289,9 @@ static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata, int usba_udc_probe(struct usba_platform_data *pdata) { - struct usba_udc *udc; - - udc = &controller; + controller = &udc_controller; - udc->usba_ep = usba_udc_pdata(pdata, udc); + controller->usba_ep = usba_udc_pdata(pdata, controller); return 0; } From patchwork Mon Jul 22 20:23:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1963882 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=knmyaS3k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSyqW69hFz1ybY for ; Tue, 23 Jul 2024 23:36:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A1CBB887FD; Tue, 23 Jul 2024 15:35:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="knmyaS3k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 68F4888403; Mon, 22 Jul 2024 22:24:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0EC4088511 for ; Mon, 22 Jul 2024 22:24:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-426636ef8c9so33617275e9.2 for ; Mon, 22 Jul 2024 13:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1721679889; x=1722284689; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0pNODCazGyMQ2INzDmL5q8sZ5AMXZbSU5GN/d66SfA0=; b=knmyaS3kv3Q7/uMzuEvaaclU0NEw6oXPgpul4xXMnL2N8mOlRKPItPyYNaKoOoosqS g/cTvqdO9fz5CA/hZkBCwXq+2bE6bvQnGFRp/iAicNHloVK2GQOyQDlttp6qMnrGzKlL GBZykoioW39N3uoJPAw7GIXrb1DKgb9/LjAlttKLR5FXFSe/zuO3lVbVtL+DOjbJQOy5 mpyOyxPQkpDfj+fHk9pbVaxu2wIfC5xj7wq9sqfLVQFwSIZrpslePw1wgpCWt4ciZiQv ik096T/vDGj8uLHbbP4dS3BozXZx/s1X36yyD2IUulrCFcHZdahqzUtRsY8bGEWfLzgh rEEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721679889; x=1722284689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0pNODCazGyMQ2INzDmL5q8sZ5AMXZbSU5GN/d66SfA0=; b=Epx9Ycoul7lyjZMZXzZ8c/N2AApfU/MueHxt3V48zCjMAERCH8FYQUAMVbAm753+xP FVCzl9H38NcGDZxFz9TzIxDL/Yg/NxtssNWL9/7SUFA+yESD03kJN678usUUujFM+cGU 9RKKog2tzp7azcFQYdHJrk2p0oDEqrfkD9UCgG+OxShsEAbFylh0qhZ7lZwNBcp9poPj U4yLjJwJrbr47FpHwpN3aIYghq4XsDM4TDQOaz9eM2uhEaxX5p/cdDLdt7U/CcVDJ1iQ /jN+7LQ9QFmes2TSyRT9vRUeUoN+PIagq16rsRthwikL76ZgcQb17CILwm5tI0NhoTfo Yynw== X-Forwarded-Encrypted: i=1; AJvYcCVdY9RJSlVY10TdUozbQhWf6xa/ycS89hrnfgZZYWr7IHVb3wjtvt/WiWZYZzYFwyFij3eJ0dXT3vov46nkVnrE7Gj/6Q== X-Gm-Message-State: AOJu0YwRBdDSBaMwxFtup5XJBOt32gN/PF3ekVZxJ4BMf4yPDelKUKvM UscPwPzIQ3ES0nzElhfPZnZaH70WZgQVgiglPzPPBJ39VmXjP7ZwteRM8eEjv5k= X-Google-Smtp-Source: AGHT+IFYLou2rSjjtnL+s9Ce+GZvJxlBwyUwNaWWlZK6f7SEFidSHgFWrVFzdHtMqo3hmtJkbknRIw== X-Received: by 2002:a05:600c:46cb:b0:426:6773:17 with SMTP id 5b1f17b1804b1-427dc569ffemr48900295e9.30.1721679889547; Mon, 22 Jul 2024 13:24:49 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d69071d0sm142982855e9.26.2024.07.22.13.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:24:49 -0700 (PDT) From: Zixun LI X-Google-Original-From: Zixun LI To: Lukasz Majewski , Mattijs Korpershoek , Marek Vasut , Tom Rini Cc: Zixun LI , u-boot@lists.denx.de Subject: [PATCH v2 2/4] usb: gadget: atmel: Code refactor part 2 Date: Mon, 22 Jul 2024 22:23:28 +0200 Message-ID: <20240722202426.190986-3-zli@ogga.fr> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240722202426.190986-1-zli@ogga.fr> References: <20240722202426.190986-1-zli@ogga.fr> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 23 Jul 2024 15:35:55 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean - Rename atmel_usba_start() / atmel_usba_stop() to usba_udc_enable() / usba_udc_disable(), remove atmel_ prefix to be inline with other functions. Also avoid confusion with DM start() / stop() functions. - Replace printf() by log_err() - Spelling paramter -> parameter Signed-off-by: Zixun LI --- drivers/usb/gadget/atmel_usba_udc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 476e7ed619..3e3c5cb403 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c @@ -1150,7 +1150,7 @@ static int usba_udc_irq(struct usba_udc *udc) return 0; } -static int atmel_usba_start(struct usba_udc *udc) +static int usba_udc_enable(struct usba_udc *udc) { udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; @@ -1165,7 +1165,7 @@ static int atmel_usba_start(struct usba_udc *udc) return 0; } -static int atmel_usba_stop(struct usba_udc *udc) +static int usba_udc_disable(struct usba_udc *udc) { udc->gadget.speed = USB_SPEED_UNKNOWN; reset_all_endpoints(udc); @@ -1189,22 +1189,22 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) int ret; if (!driver || !driver->bind || !driver->setup) { - printf("bad paramter\n"); + log_err("bad parameter\n"); return -EINVAL; } if (udc->driver) { - printf("UDC already has a gadget driver\n"); + log_err("UDC already has a gadget driver\n"); return -EBUSY; } - atmel_usba_start(udc); + usba_udc_enable(udc); udc->driver = driver; ret = driver->bind(&udc->gadget); if (ret) { - pr_err("driver->bind() returned %d\n", ret); + log_err("driver->bind() returned %d\n", ret); udc->driver = NULL; } @@ -1216,7 +1216,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) struct usba_udc *udc = controller; if (!driver || !driver->unbind || !driver->disconnect) { - pr_err("bad paramter\n"); + log_err("bad parameter\n"); return -EINVAL; } @@ -1224,7 +1224,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) driver->unbind(&udc->gadget); udc->driver = NULL; - atmel_usba_stop(udc); + usba_udc_disable(udc); return 0; } @@ -1255,7 +1255,7 @@ static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata, eps = malloc(sizeof(struct usba_ep) * pdata->num_ep); if (!eps) { - pr_err("failed to alloc eps\n"); + log_err("failed to alloc eps\n"); return NULL; } From patchwork Mon Jul 22 20:23:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1963880 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=azQ113ZP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSypr3GMTz1ybY for ; Tue, 23 Jul 2024 23:36:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D3C76887CE; Tue, 23 Jul 2024 15:35:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="azQ113ZP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5908D88569; Mon, 22 Jul 2024 22:24:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7AE9D88440 for ; Mon, 22 Jul 2024 22:24:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4279c10a40eso34455065e9.3 for ; Mon, 22 Jul 2024 13:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1721679892; x=1722284692; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ow/MkZNhaN0Q+ALo6zog03L6AOiL3bQnBaB5IKkPxMA=; b=azQ113ZPuAGp9vZVAAVjfeJE3lOpB5FFfOOXPG21EJRQWSl6NpisUJPB6QRTFWkEwS 2KkQrlvXMmqbxIAnHrwZJu1pj2xWKWw0RRtrH/LZzXV5aHla/KLbrqTJPopnjFRuMiEf lxwOzed5nLluH02RH3ehjduf40AgeLPoC4NbIJXGPQl+S08LClysp8C53yZ+vOw3raGs X2G1OdTObmqxHnJy2YkTE2AC4lMK+JBexJFodKrhFZuxh/pyKzV4y/zCoHMBpZ8NkvoJ iVSkEMtHDblOa+eIG9lTFRedtvMMuu/JhCvryssEd2/5tECnb4nUywAd9JPreCv75v46 1oWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721679892; x=1722284692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ow/MkZNhaN0Q+ALo6zog03L6AOiL3bQnBaB5IKkPxMA=; b=cTxN1DdKjCY+hTHq/tRBBL6FDmUeCfEJXGRM+okmNpnZkKItod/tLk2W4gEm7CXBaI hFzJShfaW9KkiE9HGkJb2H+y7CKMhWgOhCxL6EgRZK1gX44bZRbBpnLme2F7JCLRebex TMfecJMgIR9e0algC294Nn1GmRFbd1sDpM2IoczUpimFR92t/yfF2Hywn6KEo7ikLoAO 8pnnrjhILHVKzpcIvBlOgJxTnm5FwipIzHOVT5vY/zXnhAVXMd7lEhhsv5vHe+I3Ho02 qG7vBZVsZ5EgTuOJq4zBvKC3L4BtpfhkwWdXhHMmrn1Y91/M/rCKYtgMKh8QJzy1qpJr AVwA== X-Forwarded-Encrypted: i=1; AJvYcCU56tHqvsYsEkAahQKbWYAW3X0u2lN6luGa1cyVSPt1Qhs4ufeNYkTX/hgtjJ44vFoBPOSaTPEjdQJOER2lI9QEuHZBtA== X-Gm-Message-State: AOJu0YyYHRln++1uTAJS72QLx+ZrVX5/XTbkH4VTEBg8ow54k6CfHJCJ ZB0DNgppC1fk/2RqfGbjVDUazSUvh2OzYxyhuLEjUB853NUcXx7XbH5xViSdZZk= X-Google-Smtp-Source: AGHT+IEQjcc9k/yEvANeepBaWrevidXran1qeHDEwmYiK9r/rqAA7x5KWwSrMgMJY7bOvdcfUOwS4Q== X-Received: by 2002:a05:600c:1f90:b0:426:6158:962d with SMTP id 5b1f17b1804b1-427dc529759mr52414105e9.23.1721679891943; Mon, 22 Jul 2024 13:24:51 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d69071d0sm142982855e9.26.2024.07.22.13.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:24:51 -0700 (PDT) From: Zixun LI X-Google-Original-From: Zixun LI To: Lukasz Majewski , Mattijs Korpershoek , Marek Vasut , Tom Rini Cc: Zixun LI , u-boot@lists.denx.de Subject: [PATCH v2 3/4] usb: gadget: atmel: Add attach/detach support Date: Mon, 22 Jul 2024 22:23:29 +0200 Message-ID: <20240722202426.190986-4-zli@ogga.fr> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240722202426.190986-1-zli@ogga.fr> References: <20240722202426.190986-1-zli@ogga.fr> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 23 Jul 2024 15:35:55 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add controller attach/detach support by using usb_gadget_ops.pullup() method. Signed-off-by: Zixun LI --- drivers/usb/gadget/atmel_usba_udc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 3e3c5cb403..46f7ae9a0c 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c @@ -1176,6 +1176,23 @@ static int usba_udc_disable(struct usba_udc *udc) return 0; } +static int usba_udc_pullup(struct usb_gadget *g, int is_on) +{ + struct usba_udc *udc = controller; + u32 ctrl; + + ctrl = usba_readl(udc, CTRL); + + if (is_on) + ctrl &= ~USBA_DETACH; + else + ctrl |= USBA_DETACH; + + usba_writel(udc, CTRL, ctrl); + + return 0; +} + int dm_usb_gadget_handle_interrupts(struct udevice *dev) { struct usba_udc *udc = controller; @@ -1233,6 +1250,7 @@ static const struct usb_gadget_ops usba_udc_ops = { .get_frame = usba_udc_get_frame, .wakeup = usba_udc_wakeup, .set_selfpowered = usba_udc_set_selfpowered, + .pullup = usba_udc_pullup, }; static struct usba_udc udc_controller = { From patchwork Mon Jul 22 20:23:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1963883 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=v5UKgD13; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSyqn4wHxz1ybY for ; Tue, 23 Jul 2024 23:37:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0EC8688804; Tue, 23 Jul 2024 15:35:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="v5UKgD13"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 23EFD88403; Mon, 22 Jul 2024 22:24:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D5CDA87F82 for ; Mon, 22 Jul 2024 22:24:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4279c924ca7so34463705e9.2 for ; Mon, 22 Jul 2024 13:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1721679894; x=1722284694; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nQ02ZX1txPMd10CED5ZPi4bo2deYGAzG9QzWytCBLBQ=; b=v5UKgD13LXyvEL3jjt5A+3DG24qndiTJWajEqGC4zMtpC9DoxT9jqUiFccoFydz3sC Dkb/nFRuvKSY8xat71Bq6a36KWxF8t7DB4IMVl7waUOizZqtF5/zbEn6s8p0QpFjxg3i qNSscV4YyyYG99O5C6cwY94EQkni1yviXgSVKTy8/JfqJG6bvJRZ/cLfrQm454+FrVca ibNs4Q7RsmRB44jvpbJtwnoIeUXzNc+XNH5/iXlVjR3vVWUI77UPfI/U+084vuFG/NfJ ZQr90SLdVZVEvpGwKx7uyUkSIzfF3lAcWHjhklK0R6uIfzHzk1CkLzijiHpPL4KbBZqS GCNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721679894; x=1722284694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nQ02ZX1txPMd10CED5ZPi4bo2deYGAzG9QzWytCBLBQ=; b=Mv/CPF3kTdojXWx/LDe5eWdWG3xM1iNTcUV0BA1HrAV4ANaPQD+2bsQL/vv5G3BgJs y60zlsSsoImv3rBJ5nupojsMbFX3wMrWVE22pWltChaZjIm/DPPaloe6PTlo7v3aWgbg yZgMjVrTiuZy0hMgE0shZQaplrSSgIwwnkQHgocElMxPAVQRQdwuz3vxP5lpBhLQMyfc BCMp6v98JZv7k0RAlVjJzsEZt2s+ckMf0hPhPNTbVfrKt+MpATrBBEK20ScxwzhSksxF IRLf1CYgs9aeZQs6r9OB73OH5s9xvy3YF4UAE6gwdygHFsfXa1k2FJSup24fzmyG21Q2 i/qg== X-Forwarded-Encrypted: i=1; AJvYcCU34yixXuh+rqVHIY19uJq/7F+OXlNLYnre0urQ0i1a3/57SUw64Mg4b1wB5gDzvAYKGaQRx2PMaOroMV7xBKd209btTQ== X-Gm-Message-State: AOJu0Yx8Kzt7fA0We1O0HqGTprKc6JHC71JHQT3lY9NRS9PvaC0/Gq1q wUC7MsyattC+gaqQY74yiieJOSLsFqrzSYVSWcAZQP9+LuGFtoPLAgjFXII40D0= X-Google-Smtp-Source: AGHT+IGwB8d89uQwxToS9Wdd9gXPHoJh9fRQDssEocWGSBAscMbSXA0f8J5UDZ6kyGtJJhE3sJVAkA== X-Received: by 2002:a05:600c:3c8c:b0:426:5dc8:6a63 with SMTP id 5b1f17b1804b1-427dc568cb5mr44404135e9.30.1721679894285; Mon, 22 Jul 2024 13:24:54 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d69071d0sm142982855e9.26.2024.07.22.13.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 13:24:53 -0700 (PDT) From: Zixun LI X-Google-Original-From: Zixun LI To: Lukasz Majewski , Mattijs Korpershoek , Marek Vasut , Tom Rini Cc: Zixun LI , u-boot@lists.denx.de Subject: [PATCH v2 4/4] usb: gadget: atmel: Add DM_USB_GADGET support Date: Mon, 22 Jul 2024 22:23:30 +0200 Message-ID: <20240722202426.190986-5-zli@ogga.fr> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240722202426.190986-1-zli@ogga.fr> References: <20240722202426.190986-1-zli@ogga.fr> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 23 Jul 2024 15:35:55 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add driver model support by using the uclass UCLASS_USB_GADGET_GENERIC. Disable local usb_gadget_register_driver()/usb_gadget_unregister_driver() implementation which is implemented in udc-core.c when DM_USB_GADGET is enabled. Replace dm_usb_gadget_handle_interrupts() with handle_interrupts ops when DM_USB_GADGET is enabled. Disable legacy usba_udc_probe() to avoid conflict with DM when it's enabled. Compared to Linux driver only supported devices' DT bindings are included (sorted as Linux driver) Signed-off-by: Zixun LI --- drivers/usb/gadget/atmel_usba_udc.c | 123 ++++++++++++++++++++++++++++ include/linux/usb/atmel_usba_udc.h | 2 + 2 files changed, 125 insertions(+) diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 46f7ae9a0c..95abb86840 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c @@ -8,10 +8,13 @@ */ #include +#include #include #include #include #include +#include +#include #include #include #include @@ -19,6 +22,10 @@ #include #include +#if CONFIG_IS_ENABLED(DM_USB_GADGET) +#include +#endif /* CONFIG_IS_ENABLED(DM_USB_GADGET) */ + #include "atmel_usba_udc.h" static struct usba_udc *controller; @@ -1193,6 +1200,7 @@ static int usba_udc_pullup(struct usb_gadget *g, int is_on) return 0; } +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) int dm_usb_gadget_handle_interrupts(struct udevice *dev) { struct usba_udc *udc = controller; @@ -1246,11 +1254,40 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) return 0; } +#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ +static int usba_udc_start(struct usb_gadget *g, + struct usb_gadget_driver *driver) +{ + struct usba_udc *udc = controller; + + usba_udc_enable(udc); + + udc->driver = driver; + + return 0; +} + +static int usba_udc_stop(struct usb_gadget *g) +{ + struct usba_udc *udc = controller; + + udc->driver = NULL; + + usba_udc_disable(udc); + + return 0; +} +#endif /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ + static const struct usb_gadget_ops usba_udc_ops = { .get_frame = usba_udc_get_frame, .wakeup = usba_udc_wakeup, .set_selfpowered = usba_udc_set_selfpowered, .pullup = usba_udc_pullup, +#if CONFIG_IS_ENABLED(DM_USB_GADGET) + .udc_start = usba_udc_start, + .udc_stop = usba_udc_stop, +#endif }; static struct usba_udc udc_controller = { @@ -1305,6 +1342,7 @@ static struct usba_ep *usba_udc_pdata(struct usba_platform_data *pdata, return eps; } +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) int usba_udc_probe(struct usba_platform_data *pdata) { controller = &udc_controller; @@ -1313,3 +1351,88 @@ int usba_udc_probe(struct usba_platform_data *pdata) return 0; } + +#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ +struct usba_priv_data { + struct clk_bulk clks; +}; + +static int usba_udc_clk_init(struct udevice *dev, struct clk_bulk *clks) +{ + int ret; + + ret = clk_get_bulk(dev, clks); + if (ret == -ENOSYS) + return 0; + + if (ret) + return ret; + + ret = clk_enable_bulk(clks); + if (ret) { + clk_release_bulk(clks); + return ret; + } + + return 0; +} + +static int usba_udc_probe(struct udevice *dev) +{ + struct usba_priv_data *priv = dev_get_priv(dev); + int ret; + + ret = usba_udc_clk_init(dev, &priv->clks); + if (ret) + return ret; + + controller = &udc_controller; + + controller->usba_ep = usba_udc_pdata(&pdata, controller); + + controller->driver = 0; + + ret = usb_add_gadget_udc((struct device *)dev, &controller->gadget); + + return ret; +} + +static int usba_udc_remove(struct udevice *dev) +{ + struct usba_priv_data *priv = dev_get_priv(dev); + + usb_del_gadget_udc(&controller->gadget); + + clk_release_bulk(&priv->clks); + + return dm_scan_fdt_dev(dev); +} + +static int usba_udc_handle_interrupts(struct udevice *dev) +{ + struct usba_udc *udc = controller; + + return usba_udc_irq(udc); +} + +static const struct usb_gadget_generic_ops usba_udc_gadget_ops = { + .handle_interrupts = usba_udc_handle_interrupts, +}; + +static const struct udevice_id usba_udc_ids[] = { + { .compatible = "atmel,at91sam9rl-udc" }, + { .compatible = "atmel,at91sam9g45-udc" }, + { .compatible = "atmel,sama5d3-udc" }, + {} +}; + +U_BOOT_DRIVER(ateml_usba_udc) = { + .name = "ateml_usba_udc", + .id = UCLASS_USB_GADGET_GENERIC, + .of_match = usba_udc_ids, + .ops = &usba_udc_gadget_ops, + .probe = usba_udc_probe, + .remove = usba_udc_remove, + .priv_auto = sizeof(struct usba_priv_data), +}; +#endif /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ diff --git a/include/linux/usb/atmel_usba_udc.h b/include/linux/usb/atmel_usba_udc.h index c1c810759c..37c4f21849 100644 --- a/include/linux/usb/atmel_usba_udc.h +++ b/include/linux/usb/atmel_usba_udc.h @@ -20,6 +20,8 @@ struct usba_platform_data { struct usba_ep_data *ep; }; +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) extern int usba_udc_probe(struct usba_platform_data *pdata); +#endif #endif /* __LINUX_USB_USBA_H */