Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add support for clk subsystem in imx6 CCM driver.



details:   https://anonhg.NetBSD.org/src/rev/f9e603b3b08a
branches:  trunk
changeset: 457337:f9e603b3b08a
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Thu Jun 20 08:16:19 2019 +0000

description:
Add support for clk subsystem in imx6 CCM driver.

diffstat:

 sys/arch/arm/imx/files.imx6               |     7 +-
 sys/arch/arm/imx/if_enet_imx6.c           |    64 +-
 sys/arch/arm/imx/if_enetvar.h             |     5 +-
 sys/arch/arm/imx/imx6_ahcisata.c          |    75 +-
 sys/arch/arm/imx/imx6_ccm.c               |  1934 ++++++++++++++++------------
 sys/arch/arm/imx/imx6_ccmreg.h            |    18 +-
 sys/arch/arm/imx/imx6_ccmvar.h            |   572 +++++++-
 sys/arch/arm/imx/imx6_i2c.c               |    29 +-
 sys/arch/arm/imx/imx6_pcie.c              |    81 +-
 sys/arch/arm/imx/imx6_usb.c               |    36 +-
 sys/arch/arm/imx/imx6_usbphy.c            |    35 +-
 sys/arch/arm/imx/imx6_usdhc.c             |    92 +-
 sys/arch/arm/imx/imxi2cvar.h              |     4 +-
 sys/arch/arm/imx/imxusbvar.h              |    29 +
 sys/arch/evbarm/nitrogen6/nitrogen6_usb.c |    26 +-
 15 files changed, 1985 insertions(+), 1022 deletions(-)

diffs (truncated from 3587 to 300 lines):

diff -r 6ebda1f02600 -r f9e603b3b08a sys/arch/arm/imx/files.imx6
--- a/sys/arch/arm/imx/files.imx6       Thu Jun 20 06:59:32 2019 +0000
+++ b/sys/arch/arm/imx/files.imx6       Thu Jun 20 08:16:19 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.imx6,v 1.14 2018/06/20 07:05:37 hkenken Exp $
+#      $NetBSD: files.imx6,v 1.15 2019/06/20 08:16:19 hkenken Exp $
 #
 # Configuration info for the Freescale i.MX6
 #
@@ -32,12 +32,15 @@
 file   arch/arm/imx/imx6_pcie.c                imxpcie
 
 # iMX6 Clock Control Module
-device imxccm
+device imxccm : clk
 attach imxccm at axi
 file   arch/arm/imx/imx6_ccm.c                 imxccm  needs-flag
 defflag opt_imx6clk.h                          IMXCCMDEBUG
 defparam opt_imx6clk.h                         IMX6_OSC_FREQ
 defparam opt_imx6clk.h                         IMX6_CKIL_FREQ
+defparam opt_imx6clk.h                         IMX6_CKIH_FREQ
+defparam opt_imx6clk.h                         IMX6_ANACLK1_FREQ
+defparam opt_imx6clk.h                         IMX6_ANACLK2_FREQ
 
 # iMX6 Enhanced Periodic Interrupt Timer
 device imxclock
diff -r 6ebda1f02600 -r f9e603b3b08a sys/arch/arm/imx/if_enet_imx6.c
--- a/sys/arch/arm/imx/if_enet_imx6.c   Thu Jun 20 06:59:32 2019 +0000
+++ b/sys/arch/arm/imx/if_enet_imx6.c   Thu Jun 20 08:16:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_enet_imx6.c,v 1.3 2017/06/09 18:14:59 ryo Exp $     */
+/*     $NetBSD: if_enet_imx6.c,v 1.4 2019/06/20 08:16:19 hkenken Exp $ */
 
 /*
  * Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_enet_imx6.c,v 1.3 2017/06/09 18:14:59 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_enet_imx6.c,v 1.4 2019/06/20 08:16:19 hkenken Exp $");
 
 #include "locators.h"
 #include "imxccm.h"
@@ -47,6 +47,8 @@
 #include <arm/imx/if_enetreg.h>
 #include <arm/imx/if_enetvar.h>
 
+static int enet_init_clocks(struct enet_softc *);
+
 int
 enet_match(device_t parent __unused, struct cfdata *match __unused, void *aux)
 {
@@ -108,28 +110,9 @@
        sc->sc_enaddr[5] = eaddr + sc->sc_unit;
 #endif
 
-#if NIMXCCM > 0
-       /* PLL power up */
-       if (imx6_pll_power(CCM_ANALOG_PLL_ENET, 1,
-           CCM_ANALOG_PLL_ENET_ENABLE) != 0) {
-               aprint_error_dev(sc->sc_dev,
-                   "couldn't enable CCM_ANALOG_PLL_ENET\n");
-               return;
-       }
-
        if (IMX6_CHIPID_MAJOR(imx6_chip_id()) == CHIPID_MAJOR_IMX6UL) {
                uint32_t v;
 
-               /* iMX6UL */
-               if ((imx6_pll_power(CCM_ANALOG_PLL_ENET, 1,
-                   CCM_ANALOG_PLL_ENET_ENET_25M_REF_EN) != 0) ||
-                   (imx6_pll_power(CCM_ANALOG_PLL_ENET, 1,
-                   CCM_ANALOG_PLL_ENET_ENET2_125M_EN) != 0)) {
-                       aprint_error_dev(sc->sc_dev,
-                           "couldn't enable CCM_ANALOG_PLL_ENET\n");
-                       return;
-               }
-
                v = iomux_read(IMX6UL_IOMUX_GPR1);
                switch (sc->sc_unit) {
                case 0:
@@ -144,11 +127,42 @@
                iomux_write(IMX6UL_IOMUX_GPR1, v);
        }
 
-       sc->sc_pllclock = imx6_get_clock(IMX6CLK_PLL6);
-#else
-       sc->sc_pllclock = 50000000;
-#endif
+       sc->sc_clk_enet = imx6_get_clock("enet");
+       if (sc->sc_clk_enet == NULL) {
+               aprint_error(": couldn't get clock enet\n");
+               return;
+       }
+       sc->sc_clk_enet_ref = imx6_get_clock("enet_ref");
+       if (sc->sc_clk_enet_ref == NULL) {
+               aprint_error(": couldn't get clock enet_ref\n");
+               return;
+       }
+       if (enet_init_clocks(sc) != 0) {
+               aprint_error_dev(self, "couldn't init clocks\n");
+               return;
+       }
+
+       sc->sc_pllclock = clk_get_rate(sc->sc_clk_enet_ref);
 
        enet_attach_common(self, aa->aa_iot, aa->aa_dmat, aa->aa_addr,
            aa->aa_size, aa->aa_irq);
 }
+
+static int
+enet_init_clocks(struct enet_softc *sc)
+{
+       int error;
+
+       error = clk_enable(sc->sc_clk_enet);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable enet: %d\n", error);
+               return error;
+       }
+       error = clk_enable(sc->sc_clk_enet_ref);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable enet-ref: %d\n", error);
+               return error;
+       }
+
+       return 0;
+}
diff -r 6ebda1f02600 -r f9e603b3b08a sys/arch/arm/imx/if_enetvar.h
--- a/sys/arch/arm/imx/if_enetvar.h     Thu Jun 20 06:59:32 2019 +0000
+++ b/sys/arch/arm/imx/if_enetvar.h     Thu Jun 20 08:16:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_enetvar.h,v 1.2 2017/06/09 18:14:59 ryo Exp $       */
+/*     $NetBSD: if_enetvar.h,v 1.3 2019/06/20 08:16:19 hkenken Exp $   */
 
 /*
  * Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -61,6 +61,9 @@
        int sc_rgmii;
        unsigned int sc_pllclock;
 
+       struct clk *sc_clk_enet;
+       struct clk *sc_clk_enet_ref;
+
        /* interrupts */
        void *sc_ih;
        void *sc_ih2;   /* for i.MX7 */
diff -r 6ebda1f02600 -r f9e603b3b08a sys/arch/arm/imx/imx6_ahcisata.c
--- a/sys/arch/arm/imx/imx6_ahcisata.c  Thu Jun 20 06:59:32 2019 +0000
+++ b/sys/arch/arm/imx/imx6_ahcisata.c  Thu Jun 20 08:16:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_ahcisata.c,v 1.8 2018/06/20 05:53:19 hkenken Exp $        */
+/*     $NetBSD: imx6_ahcisata.c,v 1.9 2019/06/20 08:16:19 hkenken Exp $        */
 
 /*
  * Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_ahcisata.c,v 1.8 2018/06/20 05:53:19 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_ahcisata.c,v 1.9 2019/06/20 08:16:19 hkenken Exp $");
 
 #include "locators.h"
 #include "opt_imx.h"
@@ -47,23 +47,28 @@
 #include <dev/ic/ahcisatavar.h>
 
 struct imx_ahci_softc {
+       struct ahci_softc sc_ahcisc;
+
        device_t sc_dev;
        bus_space_tag_t sc_iot;
        bus_space_handle_t sc_ioh;
        void *sc_ih;
 
-       struct ahci_softc sc_ahcisc;
+       struct clk *sc_clk_sata;
+       struct clk *sc_clk_sata_ref;
+       struct clk *sc_clk_ahb;
 };
 
 static int imx6_ahcisata_match(device_t, cfdata_t, void *);
 static void imx6_ahcisata_attach(device_t, device_t, void *);
 static int imx6_ahcisata_detach(device_t, int);
 
-static int imx6_ahcisata_init(struct imx_ahci_softc *);
 static int imx6_ahcisata_phy_ctrl(struct imx_ahci_softc *, uint32_t, int);
 static int imx6_ahcisata_phy_addr(struct imx_ahci_softc *, uint32_t);
 static int imx6_ahcisata_phy_write(struct imx_ahci_softc *, uint32_t, uint16_t);
 static int imx6_ahcisata_phy_read(struct imx_ahci_softc *, uint32_t);
+static int imx6_ahcisata_init(struct imx_ahci_softc *);
+static int imx6_ahcisata_init_clocks(struct imx_ahci_softc *);
 
 CFATTACH_DECL_NEW(imx6_ahcisata, sizeof(struct imx_ahci_softc),
     imx6_ahcisata_match, imx6_ahcisata_attach, imx6_ahcisata_detach, NULL);
@@ -114,6 +119,26 @@
                return;
        }
 
+       sc->sc_clk_sata = imx6_get_clock("sata");
+       if (sc->sc_clk_sata == NULL) {
+               aprint_error(": couldn't get clock sata\n");
+               return;
+       }
+       sc->sc_clk_sata_ref = imx6_get_clock("sata_ref");
+       if (sc->sc_clk_sata_ref == NULL) {
+               aprint_error(": couldn't get clock sata_ref\n");
+               return;
+       }
+       sc->sc_clk_ahb = imx6_get_clock("ahb");
+       if (sc->sc_clk_ahb == NULL) {
+               aprint_error(": couldn't get clock ahb\n");
+               return;
+       }
+       if (imx6_ahcisata_init_clocks(sc) != 0) {
+               aprint_error_dev(self, "couldn't init clocks\n");
+               return;
+       }
+
        if (imx6_ahcisata_init(sc) != 0) {
                aprint_error_dev(self, "couldn't init ahci\n");
                return;
@@ -262,21 +287,6 @@
        uint32_t v;
        int timeout, pllstat;
 
-       /* AHCISATA clock enable */
-       v = imx6_ccm_read(CCM_CCGR5);
-       imx6_ccm_write(CCM_CCGR5, v | __SHIFTIN(3, CCM_CCGR5_SATA_CLK_ENABLE));
-
-       /* PLL power up */
-       if (imx6_pll_power(CCM_ANALOG_PLL_ENET, 1,
-               CCM_ANALOG_PLL_ENET_ENABLE_100M) != 0) {
-               aprint_error_dev(sc->sc_dev,
-                   "couldn't enable CCM_ANALOG_PLL_ENET\n");
-               return -1;
-       }
-       v = imx6_ccm_analog_read(CCM_ANALOG_PLL_ENET);
-       v |= CCM_ANALOG_PLL_ENET_ENABLE_100M;
-       imx6_ccm_analog_write(CCM_ANALOG_PLL_ENET, v);
-
        v = iomux_read(IOMUX_GPR13);
        /* clear */
        v &= ~(IOMUX_GPR13_SATA_PHY_8(7) |
@@ -332,7 +342,32 @@
 
        /* set 1ms-timer = AHB clock / 1000 */
        bus_space_write_4(sc->sc_iot, sc->sc_ioh, SATA_TIMER1MS,
-           imx6_get_clock(IMX6CLK_AHB) / 1000);
+           clk_get_rate(sc->sc_clk_ahb) / 1000);
 
        return 0;
 }
+
+static int
+imx6_ahcisata_init_clocks(struct imx_ahci_softc *sc)
+{
+       int error;
+
+       error = clk_enable(sc->sc_clk_sata);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable sata: %d\n", error);
+               return error;
+       }
+       error = clk_enable(sc->sc_clk_sata_ref);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable sata-ref: %d\n", error);
+               return error;
+       }
+       error = clk_enable(sc->sc_clk_ahb);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable anb: %d\n", error);
+               return error;
+       }
+
+       return 0;
+}
+
diff -r 6ebda1f02600 -r f9e603b3b08a sys/arch/arm/imx/imx6_ccm.c
--- a/sys/arch/arm/imx/imx6_ccm.c       Thu Jun 20 06:59:32 2019 +0000
+++ b/sys/arch/arm/imx/imx6_ccm.c       Thu Jun 20 08:16:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_ccm.c,v 1.9 2018/06/20 07:05:37 hkenken Exp $     */
+/*     $NetBSD: imx6_ccm.c,v 1.10 2019/06/20 08:16:19 hkenken Exp $    */
 
 /*
  * Copyright (c) 2010-2012, 2014  Genetec Corporation.  All rights reserved.
@@ -25,13 +25,12 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-
 /*
  * Clock Controller Module (CCM) for i.MX6
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_ccm.c,v 1.9 2018/06/20 07:05:37 hkenken Exp $");



Home | Main Index | Thread Index | Old Index