From ae49f6216d0a7bdf1f53f0586326a24114bbd6f4 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Mon, 24 Jun 2013 17:54:16 +0200 Subject: [PATCH] Add regulators for EHCI controller on Arndale Fix #780 --- .../lib/usb/arm/platform_arndale/platform.cc | 7 ++ .../platform/arndale/regulator/consts.h | 4 ++ os/src/drivers/platform/arndale/cmu.h | 16 +++-- os/src/drivers/platform/arndale/main.cc | 2 + os/src/drivers/platform/arndale/pmu.h | 69 ++++++++++--------- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/dde_linux/src/lib/usb/arm/platform_arndale/platform.cc b/dde_linux/src/lib/usb/arm/platform_arndale/platform.cc index 280f460ab8..b55ac93d2f 100644 --- a/dde_linux/src/lib/usb/arm/platform_arndale/platform.cc +++ b/dde_linux/src/lib/usb/arm/platform_arndale/platform.cc @@ -125,6 +125,13 @@ static void arndale_ehci_init() { enum Gpio_offset { D1 = 0x180, X3 = 0xc60 }; + /* enable USB3 clock and power up */ + Regulator::Connection reg_clk(Regulator::CLK_USB20); + reg_clk.state(true); + + Regulator::Connection reg_pwr(Regulator::PWR_USB20); + reg_pwr.state(true); + /* reset hub via GPIO */ Io_mem_connection io_gpio(GPIO_BASE, 0x1000); addr_t gpio_base = (addr_t)env()->rm_session()->attach(io_gpio.dataspace()); diff --git a/os/include/platform/arndale/regulator/consts.h b/os/include/platform/arndale/regulator/consts.h index 7d4a64b497..80264a25c7 100644 --- a/os/include/platform/arndale/regulator/consts.h +++ b/os/include/platform/arndale/regulator/consts.h @@ -22,9 +22,11 @@ namespace Regulator { CLK_CPU, CLK_SATA, CLK_USB30, + CLK_USB20, CLK_MMC0, PWR_SATA, PWR_USB30, + PWR_USB20, MAX, INVALID }; @@ -38,9 +40,11 @@ namespace Regulator { { CLK_CPU, "clock-cpu" }, { CLK_SATA, "clock-sata" }, { CLK_USB30, "clock-usb3.0" }, + { CLK_USB20, "clock-usb2.0" }, { CLK_MMC0, "clock-mmc0" }, { PWR_SATA, "power-sata" }, { PWR_USB30, "power-usb3.0" }, + { PWR_USB20, "power-usb2.0" }, }; Regulator_id regulator_id_by_name(const char * name) diff --git a/os/src/drivers/platform/arndale/cmu.h b/os/src/drivers/platform/arndale/cmu.h index 1501b170f2..b8d84a3cb5 100644 --- a/os/src/drivers/platform/arndale/cmu.h +++ b/os/src/drivers/platform/arndale/cmu.h @@ -197,8 +197,8 @@ class Cmu : public Regulator::Driver, struct Pdma0 : Bitfield<1, 1> { }; struct Pdma1 : Bitfield<2, 1> { }; struct Sata : Bitfield<6, 1> { }; - struct Clk_sdmmc0 : Bitfield<12, 1> { }; - struct Clk_usbhost20 : Bitfield<18, 1> { }; + struct Sdmmc0 : Bitfield<12, 1> { }; + struct Usbhost20 : Bitfield<18, 1> { }; struct Usbdrd30 : Bitfield<19, 1> { }; struct Sata_phy_ctrl : Bitfield<24, 1> { }; struct Sata_phy_i2c : Bitfield<25, 1> { }; @@ -361,8 +361,10 @@ class Cmu : public Regulator::Driver, case CLK_USB30: _usb30_enable(); break; + case CLK_USB20: + return write(1); case CLK_MMC0: - write(1); + write(1); write(1); break; default: @@ -383,8 +385,10 @@ class Cmu : public Regulator::Driver, write(0); write(0); break; + case CLK_USB20: + return write(0); case CLK_MMC0: - write(0); + write(0); write(0); break; default: @@ -483,8 +487,10 @@ class Cmu : public Regulator::Driver, case CLK_USB30: return read() && read(); + case CLK_USB20: + return read(); case CLK_MMC0: - return read() && + return read() && read(); default: PWRN("Unsupported for %s", names[id].name); diff --git a/os/src/drivers/platform/arndale/main.cc b/os/src/drivers/platform/arndale/main.cc index 422612ffa9..8f3b08d16e 100644 --- a/os/src/drivers/platform/arndale/main.cc +++ b/os/src/drivers/platform/arndale/main.cc @@ -31,10 +31,12 @@ struct Driver_factory : Regulator::Driver_factory case Regulator::CLK_CPU: case Regulator::CLK_SATA: case Regulator::CLK_USB30: + case Regulator::CLK_USB20: case Regulator::CLK_MMC0: return _cmu; case Regulator::PWR_SATA: case Regulator::PWR_USB30: + case Regulator::PWR_USB20: return _pmu; default: throw Root::Invalid_args(); /* invalid regulator */ diff --git a/os/src/drivers/platform/arndale/pmu.h b/os/src/drivers/platform/arndale/pmu.h index eeaf53278e..7f82b30e39 100644 --- a/os/src/drivers/platform/arndale/pmu.h +++ b/os/src/drivers/platform/arndale/pmu.h @@ -99,27 +99,38 @@ class Pmu : public Regulator::Driver, } - /*********************** - ** USB 3.0 functions ** - ***********************/ - - void _usb30_enable() + void _enable(unsigned long id) { - write(1); - write(1); + switch (id) { + case PWR_USB30: + write(1); + break; + case PWR_USB20: + write(1); + break; + case PWR_SATA : + write(1); + break; + default: + PWRN("Unsupported for %s", names[id].name); + } } - void _usb30_disable() + void _disable(unsigned long id) { - write(0); - write(0); - } - - bool _usb30_enabled() - { - return read() && - read(); - + switch (id) { + case PWR_USB30: + write(0); + break; + case PWR_USB20: + write(0); + break; + case PWR_SATA : + write(0); + break; + default: + PWRN("Unsupported for %s", names[id].name); + } } public: @@ -176,29 +187,19 @@ class Pmu : public Regulator::Driver, void state(Regulator_id id, bool enable) { - switch (id) { - case PWR_USB30: - if (enable) - _usb30_enable(); - else - _usb30_disable(); - break; - case PWR_SATA : - if (enable) - write(1); - else - write(0); - break; - default: - PWRN("Unsupported for %s", names[id].name); - } + if (enable) + _enable(id); + else + _disable(id); } bool state(Regulator_id id) { switch (id) { case PWR_USB30: - return _usb30_enabled(); + return read(); + case PWR_USB20: + return read(); case PWR_SATA: return read(); default: