Module Name:    src
Committed By:   ryo
Date:           Tue Oct  7 09:36:09 UTC 2014

Modified Files:
        src/sys/arch/arm/imx: files.imx6 imx6_ccm.c imx6_ccmvar.h
Added Files:
        src/sys/arch/arm/imx: imx6_i2c.c

Log Message:
add support imx6 I2C Controller


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/imx/files.imx6
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/imx/imx6_ccm.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/imx/imx6_ccmvar.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/imx/imx6_i2c.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/imx/files.imx6
diff -u src/sys/arch/arm/imx/files.imx6:1.3 src/sys/arch/arm/imx/files.imx6:1.4
--- src/sys/arch/arm/imx/files.imx6:1.3	Mon Oct  6 10:15:40 2014
+++ src/sys/arch/arm/imx/files.imx6	Tue Oct  7 09:36:09 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.imx6,v 1.3 2014/10/06 10:15:40 ryo Exp $
+#	$NetBSD: files.imx6,v 1.4 2014/10/07 09:36:09 ryo Exp $
 #
 # Configuration info for the Freescale i.MX6
 #
@@ -61,6 +61,12 @@ device	imxiomux
 attach	imxiomux at axi
 file	arch/arm/imx/imx6_iomux.c		imxiomux
 
+# iMX iic Controler
+device	imxi2c: i2cbus
+attach	imxi2c at axi
+file	arch/arm/imx/imxi2c.c			imxi2c
+file	arch/arm/imx/imx6_i2c.c			imxi2c
+
 # iMX UART
 device	imxuart
 attach	imxuart at axi

Index: src/sys/arch/arm/imx/imx6_ccm.c
diff -u src/sys/arch/arm/imx/imx6_ccm.c:1.2 src/sys/arch/arm/imx/imx6_ccm.c:1.3
--- src/sys/arch/arm/imx/imx6_ccm.c:1.2	Mon Oct  6 10:27:13 2014
+++ src/sys/arch/arm/imx/imx6_ccm.c	Tue Oct  7 09:36:09 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: imx6_ccm.c,v 1.2 2014/10/06 10:27:13 ryo Exp $	*/
+/*	$NetBSD: imx6_ccm.c,v 1.3 2014/10/07 09:36:09 ryo Exp $	*/
 
 /*
  * Copyright (c) 2010-2012, 2014  Genetec Corporation.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_ccm.c,v 1.2 2014/10/06 10:27:13 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_ccm.c,v 1.3 2014/10/07 09:36:09 ryo Exp $");
 
 #include "opt_imx.h"
 #include "opt_imx6clk.h"
@@ -167,13 +167,13 @@ imxccm_attach(device_t parent, device_t 
 	    imx6_get_clock(IMX6CLK_AXI));
 
 	aprint_verbose_dev(self, "IMX6CLK_USDHC1=%d\n",
-	    imx6_get_clock(IMX6CLK_USDHC1_CLK_ROOT));
+	    imx6_get_clock(IMX6CLK_USDHC1));
 	aprint_verbose_dev(self, "IMX6CLK_USDHC2=%d\n",
-	    imx6_get_clock(IMX6CLK_USDHC2_CLK_ROOT));
+	    imx6_get_clock(IMX6CLK_USDHC2));
 	aprint_verbose_dev(self, "IMX6CLK_USDHC3=%d\n",
-	    imx6_get_clock(IMX6CLK_USDHC3_CLK_ROOT));
+	    imx6_get_clock(IMX6CLK_USDHC3));
 	aprint_verbose_dev(self, "IMX6CLK_USDHC4=%d\n",
-	    imx6_get_clock(IMX6CLK_USDHC4_CLK_ROOT));
+	    imx6_get_clock(IMX6CLK_USDHC4));
 }
 
 static int
@@ -630,28 +630,28 @@ imx6_get_clock(enum imx6_clock clk)
 		}
 		break;
 
-	case IMX6CLK_USDHC1_CLK_ROOT:
+	case IMX6CLK_USDHC1:
 		v = imx6_ccm_read(CCM_CSCMR1);
 		freq = imx6_get_clock((v & CCM_CSCMR1_USDHC1_CLK_SEL) ?
 		    IMX6CLK_PLL2_PFD0 : IMX6CLK_PLL2_PFD2);
 		v = imx6_ccm_read(CCM_CSCDR1);
 		freq = freq / (__SHIFTOUT(v, CCM_CSCDR1_USDHC1_PODF) + 1);
 		break;
-	case IMX6CLK_USDHC2_CLK_ROOT:
+	case IMX6CLK_USDHC2:
 		v = imx6_ccm_read(CCM_CSCMR1);
 		freq = imx6_get_clock((v & CCM_CSCMR1_USDHC2_CLK_SEL) ?
 		    IMX6CLK_PLL2_PFD0 : IMX6CLK_PLL2_PFD2);
 		v = imx6_ccm_read(CCM_CSCDR1);
 		freq = freq / (__SHIFTOUT(v, CCM_CSCDR1_USDHC2_PODF) + 1);
 		break;
-	case IMX6CLK_USDHC3_CLK_ROOT:
+	case IMX6CLK_USDHC3:
 		v = imx6_ccm_read(CCM_CSCMR1);
 		freq = imx6_get_clock((v & CCM_CSCMR1_USDHC3_CLK_SEL) ?
 		    IMX6CLK_PLL2_PFD0 : IMX6CLK_PLL2_PFD2);
 		v = imx6_ccm_read(CCM_CSCDR1);
 		freq = freq / (__SHIFTOUT(v, CCM_CSCDR1_USDHC3_PODF) + 1);
 		break;
-	case IMX6CLK_USDHC4_CLK_ROOT:
+	case IMX6CLK_USDHC4:
 		v = imx6_ccm_read(CCM_CSCMR1);
 		freq = imx6_get_clock((v & CCM_CSCMR1_USDHC4_CLK_SEL) ?
 		    IMX6CLK_PLL2_PFD0 : IMX6CLK_PLL2_PFD2);
@@ -659,6 +659,12 @@ imx6_get_clock(enum imx6_clock clk)
 		freq = freq / (__SHIFTOUT(v, CCM_CSCDR1_USDHC4_PODF) + 1);
 		break;
 
+	case IMX6CLK_PERCLK:
+		freq = imx6_get_clock(IMX6CLK_IPG);
+		v = imx6_ccm_read(CCM_CSCMR1);
+		freq = freq / (__SHIFTOUT(v, CCM_CSCMR1_PERCLK_PODF) + 1);
+		break;
+
 	default:
 		aprint_error_dev(ccm_softc->sc_dev,
 		    "clock %d: not supported yet\n", clk);

Index: src/sys/arch/arm/imx/imx6_ccmvar.h
diff -u src/sys/arch/arm/imx/imx6_ccmvar.h:1.1 src/sys/arch/arm/imx/imx6_ccmvar.h:1.2
--- src/sys/arch/arm/imx/imx6_ccmvar.h:1.1	Thu Sep 25 05:05:28 2014
+++ src/sys/arch/arm/imx/imx6_ccmvar.h	Tue Oct  7 09:36:09 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: imx6_ccmvar.h,v 1.1 2014/09/25 05:05:28 ryo Exp $	*/
+/*	$NetBSD: imx6_ccmvar.h,v 1.2 2014/10/07 09:36:09 ryo Exp $	*/
 /*
  * Copyright (c) 2012  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -54,10 +54,12 @@ enum imx6_clock {
 	IMX6CLK_MMDC_CH0,
 	IMX6CLK_MMDC_CH1,
 
-	IMX6CLK_USDHC1_CLK_ROOT,
-	IMX6CLK_USDHC2_CLK_ROOT,
-	IMX6CLK_USDHC3_CLK_ROOT,
-	IMX6CLK_USDHC4_CLK_ROOT,
+	IMX6CLK_USDHC1,
+	IMX6CLK_USDHC2,
+	IMX6CLK_USDHC3,
+	IMX6CLK_USDHC4,
+
+	IMX6CLK_PERCLK,
 };
 
 uint32_t imx6_get_clock(enum imx6_clock);

Added files:

Index: src/sys/arch/arm/imx/imx6_i2c.c
diff -u /dev/null src/sys/arch/arm/imx/imx6_i2c.c:1.1
--- /dev/null	Tue Oct  7 09:36:09 2014
+++ src/sys/arch/arm/imx/imx6_i2c.c	Tue Oct  7 09:36:09 2014
@@ -0,0 +1,83 @@
+/*	$NetBSD: imx6_i2c.c,v 1.1 2014/10/07 09:36:09 ryo Exp $	*/
+
+/*
+ * Copyright (c) 2014 Ryo Shimizu <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * i.MX6 I2C Controller
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: imx6_i2c.c,v 1.1 2014/10/07 09:36:09 ryo Exp $");
+
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/param.h>
+
+#include <arm/imx/imx6var.h>
+#include <arm/imx/imx6_reg.h>
+#include <arm/imx/imx6_ccmvar.h>
+#include <arm/imx/imxi2cvar.h>
+
+/* ARGSUSED */
+int
+imxi2c_match(device_t parent __unused, struct cfdata *match __unused, void *aux)
+{
+	struct axi_attach_args *aa;
+
+	aa = aux;
+
+	switch (aa->aa_addr) {
+	case IMX6_AIPS2_BASE + AIPS2_I2C1_BASE:
+	case IMX6_AIPS2_BASE + AIPS2_I2C2_BASE:
+	case IMX6_AIPS2_BASE + AIPS2_I2C3_BASE:
+		return 1;
+	}
+
+	return 0;
+}
+
+/* ARGSUSED */
+void
+imxi2c_attach(device_t parent __unused, device_t self, void *aux)
+{
+	struct imxi2c_softc *sc;
+	struct axi_attach_args *aa;
+	struct i2cbus_attach_args iba;
+
+	aa = aux;
+	sc = device_private(self);
+
+	imxi2c_attach_common(parent, self, aa->aa_iot, aa->aa_addr, aa->aa_size,
+	    aa->aa_irq, 0);
+
+	imxi2c_set_freq(self, imx6_get_clock(IMX6CLK_PERCLK), 400000);
+
+	memset(&iba, 0, sizeof(iba));
+	iba.iba_tag = &sc->sc_i2c;
+	config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
+}
+

Reply via email to