diff mbox series

[U-Boot,v2] musb: sunxi: Use base address from device tree

Message ID 20171230124407.14988-1-wens@csie.org
State Accepted
Commit f4f9896ac310402de0e4f5d2c15a93cb89425aca
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot,v2] musb: sunxi: Use base address from device tree | expand

Commit Message

Chen-Yu Tsai Dec. 30, 2017, 12:44 p.m. UTC
Now that the musb sunxi glue driver is completely device model / device
tree driven, we should use the base address from the device tree,
instead of hard-coding it in the source code.

Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
Changes since v1:

  - Check return value dev_read_addr_ptr()

IMHO, having NULL represent an error for dev_read_addr_ptr() doesn't
work so well as in the kernel, because U-boot doesn't acually map
addresses. So NULL (or 0x0) is in fact a valid address. Something
like ~0x0 might work better, but that's a whole other changeset.

---
 drivers/usb/musb-new/sunxi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Maxime Ripard Jan. 4, 2018, 1:25 p.m. UTC | #1
On Sat, Dec 30, 2017 at 08:44:07PM +0800, Chen-Yu Tsai wrote:
> Now that the musb sunxi glue driver is completely device model / device
> tree driven, we should use the base address from the device tree,
> instead of hard-coding it in the source code.
> 
> Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime
Jagan Teki Jan. 10, 2018, 6:10 a.m. UTC | #2
On Thu, Jan 4, 2018 at 6:55 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> On Sat, Dec 30, 2017 at 08:44:07PM +0800, Chen-Yu Tsai wrote:
>> Now that the musb sunxi glue driver is completely device model / device
>> tree driven, we should use the base address from the device tree,
>> instead of hard-coding it in the source code.
>>
>> Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Applied to u-boot-sunxi/master
Marek Vasut Jan. 10, 2018, 10:17 a.m. UTC | #3
On 01/10/2018 07:10 AM, Jagan Teki wrote:
> On Thu, Jan 4, 2018 at 6:55 PM, Maxime Ripard
> <maxime.ripard@free-electrons.com> wrote:
>> On Sat, Dec 30, 2017 at 08:44:07PM +0800, Chen-Yu Tsai wrote:
>>> Now that the musb sunxi glue driver is completely device model / device
>>> tree driven, we should use the base address from the device tree,
>>> instead of hard-coding it in the source code.
>>>
>>> Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>
>> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> 
> Applied to u-boot-sunxi/master

This is a USB patch, this goes through USB tree, so drop it.
Jun Nie Jan. 10, 2018, 2:01 p.m. UTC | #4
2017-12-30 20:44 GMT+08:00 Chen-Yu Tsai <wens@csie.org>:
> Now that the musb sunxi glue driver is completely device model / device
> tree driven, we should use the base address from the device tree,
> instead of hard-coding it in the source code.
>
> Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
> Changes since v1:
>
>   - Check return value dev_read_addr_ptr()
>
> IMHO, having NULL represent an error for dev_read_addr_ptr() doesn't
> work so well as in the kernel, because U-boot doesn't acually map
> addresses. So NULL (or 0x0) is in fact a valid address. Something
> like ~0x0 might work better, but that's a whole other changeset.
>
> ---
>  drivers/usb/musb-new/sunxi.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
> index 7ee44ea91900..aedc24b93711 100644
> --- a/drivers/usb/musb-new/sunxi.c
> +++ b/drivers/usb/musb-new/sunxi.c
> @@ -312,13 +312,16 @@ static int musb_usb_probe(struct udevice *dev)
>  {
>         struct musb_host_data *host = dev_get_priv(dev);
>         struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
> +       void *base = dev_read_addr_ptr(dev);
>         int ret;

Chenyu,

I am not familiar with MUSB and not sure whether this driver support
both host and peripheral mode. I suppose it support both mode in
different build config according to macro CONFIG_USB_MUSB_HOST. H3
user manual says register address space is different for the two
modes,  0x1c19000 for device mode and 0x1c1a000 for host mode.
If my understanding is correct, we need different address in dts for
different mode. Or I misunderstand anything? Thank you for explaining
it!

Jun
Chen-Yu Tsai Jan. 10, 2018, 2:04 p.m. UTC | #5
On Wed, Jan 10, 2018 at 10:01 PM, Jun Nie <jun.nie@linaro.org> wrote:
> 2017-12-30 20:44 GMT+08:00 Chen-Yu Tsai <wens@csie.org>:
>> Now that the musb sunxi glue driver is completely device model / device
>> tree driven, we should use the base address from the device tree,
>> instead of hard-coding it in the source code.
>>
>> Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>> Changes since v1:
>>
>>   - Check return value dev_read_addr_ptr()
>>
>> IMHO, having NULL represent an error for dev_read_addr_ptr() doesn't
>> work so well as in the kernel, because U-boot doesn't acually map
>> addresses. So NULL (or 0x0) is in fact a valid address. Something
>> like ~0x0 might work better, but that's a whole other changeset.
>>
>> ---
>>  drivers/usb/musb-new/sunxi.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
>> index 7ee44ea91900..aedc24b93711 100644
>> --- a/drivers/usb/musb-new/sunxi.c
>> +++ b/drivers/usb/musb-new/sunxi.c
>> @@ -312,13 +312,16 @@ static int musb_usb_probe(struct udevice *dev)
>>  {
>>         struct musb_host_data *host = dev_get_priv(dev);
>>         struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
>> +       void *base = dev_read_addr_ptr(dev);
>>         int ret;
>
> Chenyu,
>
> I am not familiar with MUSB and not sure whether this driver support
> both host and peripheral mode. I suppose it support both mode in
> different build config according to macro CONFIG_USB_MUSB_HOST. H3
> user manual says register address space is different for the two
> modes,  0x1c19000 for device mode and 0x1c1a000 for host mode.
> If my understanding is correct, we need different address in dts for
> different mode. Or I misunderstand anything? Thank you for explaining
> it!

For host mode, the SoC provides a proper EHCI/OHCI host pair. Those
are found at 0x1c1a000. However the MUSB controller can do host mode.
It's just not as good as a proper host pair.

ChenYu
diff mbox series

Patch

diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index 7ee44ea91900..aedc24b93711 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -312,13 +312,16 @@  static int musb_usb_probe(struct udevice *dev)
 {
 	struct musb_host_data *host = dev_get_priv(dev);
 	struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
+	void *base = dev_read_addr_ptr(dev);
 	int ret;
 
+	if (!base)
+		return -EINVAL;
+
 	priv->desc_before_addr = true;
 
 #ifdef CONFIG_USB_MUSB_HOST
-	host->host = musb_init_controller(&musb_plat, NULL,
-					  (void *)SUNXI_USB0_BASE);
+	host->host = musb_init_controller(&musb_plat, NULL, base);
 	if (!host->host)
 		return -EIO;
 
@@ -326,7 +329,7 @@  static int musb_usb_probe(struct udevice *dev)
 	if (!ret)
 		printf("Allwinner mUSB OTG (Host)\n");
 #else
-	ret = musb_register(&musb_plat, NULL, (void *)SUNXI_USB0_BASE);
+	ret = musb_register(&musb_plat, NULL, base);
 	if (!ret)
 		printf("Allwinner mUSB OTG (Peripheral)\n");
 #endif