[PATCH] mmc: sdhci: fix dma memory leak in sdhci_pre_req()

2015-08-24 Thread Haibo Chen
Currently one mrq->data maybe execute dma_map_sg() twice
when mmc subsystem prepare over one new request, and the
following log show up:
sdhci[sdhci_pre_dma_transfer] invalid cookie: 24, next-cookie 25

In this condition, mrq->date map a dma-memory(1) in sdhci_pre_req
for the first time, and map another dma-memory(2) in sdhci_prepare_data
for the second time. But driver only unmap the dma-memory(2), and
dma-memory(1) never unmapped, which cause the dma memory leak issue.

This patch use another method to map the dma memory for the mrq->data
which can fix this dma memory leak issue.

Fixes: commit 348487cb28e66b0 ("mmc: sdhci: use pipeline mmc requests to 
improve performance")
Cc: sta...@vger.kernel.org # 4.0+
Reported-and-tested-by: Jiri Slaby 
Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci.c | 67 ++--
 drivers/mmc/host/sdhci.h |  8 +++---
 2 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c83d110..8d2864b 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -54,8 +54,7 @@ static void sdhci_finish_command(struct sdhci_host *);
 static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
 static int sdhci_pre_dma_transfer(struct sdhci_host *host,
-   struct mmc_data *data,
-   struct sdhci_host_next *next);
+   struct mmc_data *data);
 static int sdhci_do_get_cd(struct sdhci_host *host);
 
 #ifdef CONFIG_PM
@@ -495,7 +494,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
goto fail;
BUG_ON(host->align_addr & host->align_mask);
 
-   host->sg_count = sdhci_pre_dma_transfer(host, data, NULL);
+   host->sg_count = sdhci_pre_dma_transfer(host, data);
if (host->sg_count < 0)
goto unmap_align;
 
@@ -634,9 +633,11 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
}
}
 
-   if (!data->host_cookie)
+   if (data->host_cookie == COOKIE_MAPPED) {
dma_unmap_sg(mmc_dev(host->mmc), data->sg,
data->sg_len, direction);
+   data->host_cookie = COOKIE_UNMAPPED;
+   }
 }
 
 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
@@ -832,7 +833,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, 
struct mmc_command *cmd)
} else {
int sg_cnt;
 
-   sg_cnt = sdhci_pre_dma_transfer(host, data, NULL);
+   sg_cnt = sdhci_pre_dma_transfer(host, data);
if (sg_cnt <= 0) {
/*
 * This only happens when someone fed
@@ -948,11 +949,13 @@ static void sdhci_finish_data(struct sdhci_host *host)
if (host->flags & SDHCI_USE_ADMA)
sdhci_adma_table_post(host, data);
else {
-   if (!data->host_cookie)
+   if (data->host_cookie == COOKIE_MAPPED) {
dma_unmap_sg(mmc_dev(host->mmc),
data->sg, data->sg_len,
(data->flags & MMC_DATA_READ) ?
DMA_FROM_DEVICE : DMA_TO_DEVICE);
+   data->host_cookie = COOKIE_UNMAPPED;
+   }
}
}
 
@@ -2105,49 +2108,36 @@ static void sdhci_post_req(struct mmc_host *mmc, struct 
mmc_request *mrq,
struct mmc_data *data = mrq->data;
 
if (host->flags & SDHCI_REQ_USE_DMA) {
-   if (data->host_cookie)
+   if (data->host_cookie == COOKIE_GIVEN ||
+   data->host_cookie == COOKIE_MAPPED)
dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
 data->flags & MMC_DATA_WRITE ?
 DMA_TO_DEVICE : DMA_FROM_DEVICE);
-   mrq->data->host_cookie = 0;
+   data->host_cookie = COOKIE_UNMAPPED;
}
 }
 
 static int sdhci_pre_dma_transfer(struct sdhci_host *host,
-  struct mmc_data *data,
-  struct sdhci_host_next *next)
+  struct mmc_data *data)
 {
int sg_count;
 
-   if (!next && data->host_cookie &&
-   data->host_cookie != host->next_data.cookie) {
-   pr_debug(DRIVER_NAME "[%s] invalid cookie: %d, next-cookie 
%d

Re: [PATCH v6 0/6] mmc: imx: a few fixes and new feature

2015-08-24 Thread Haibo Chen
On Thu, Aug 13, 2015 at 04:58:56PM +0800, Dong Aisheng wrote:
> On Tue, Aug 11, 2015 at 07:38:25PM +0800, Haibo Chen wrote:
> > Changes for v6:
> > -remove duplicate code in esdhc_set_uhs_signaling().
> > -fix a typo for patch-2.
> > -make commit log of patch-3 more specific.
> > 
> > Haibo Chen (6):
> >   mmc: sdhci-esdhc-imx: add imx7d support and support HS400
> >   mmc: sdhci-esdhc-imx: add tuning-step setting support
> >   mmc: sdhci-esdhc-imx: add imx7d support in bingding doc
> >   ARM: dts: imx7d-sdb: add eMMC5.0 support
> >   mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1
> >   mmc: sdhci-esdhc-imx: change default watermark level and burst length
> > 
> >  .../devicetree/bindings/mmc/fsl-imx-esdhc.txt  |   6 ++
> >  arch/arm/boot/dts/imx7d-sdb.dts|  13 +++
> >  drivers/mmc/host/sdhci-esdhc-imx.c | 114 
> > -
> >  include/linux/platform_data/mmc-esdhc-imx.h|   1 +
> >  4 files changed, 130 insertions(+), 4 deletions(-)
> > 
> > -- 
> > 1.9.1
> > 
> 
> The patch set looks good to me.
> 
> Acked-by: Dong Aisheng 
> 
> Regards
> Dong Aisheng

Hi Ulf,

Can you help pull these patches into your branch?


Best regards

Haibo
-- 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/5] Documentation: Detail permitted DT properties for the imx6ul_tsc

2015-08-28 Thread Haibo Chen
Here we apply required documentation for the imx6ul touch screen
controller driver which describe available properties and how to
use them.

Signed-off-by: Haibo Chen 
---
 .../bindings/input/touchscreen/imx6ul_tsc.txt  | 36 ++
 1 file changed, 36 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt

diff --git a/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt 
b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
new file mode 100644
index 000..853dff9
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
@@ -0,0 +1,36 @@
+* Freescale i.MX6UL Touch Controller
+
+Required properties:
+- compatible: must be "fsl,imx6ul-tsc".
+- reg: this touch controller address and the ADC2 address.
+- interrupts: the interrupt of this touch controller and ADC2.
+- clocks: the root clock of touch controller and ADC2.
+- clock-names; must be "tsc" and "adc".
+- xnur-gpio: the X- gpio this controller connect to.
+  This xnur-gpio returns to low once the finger leave the touch screen (The
+  last touch event the touch controller capture).
+
+Optional properties:
+- measure-delay-time: the value of measure delay time.
+  Before X-axis or Y-axis measurement, the screen need some time before
+  even potential distribution ready.
+  This value depends on the touch screen.
+- pre-charge-time: the touch screen need some time to precharge.
+  This value depends on the touch screen.
+
+Example:
+   tsc: tsc@0204 {
+   compatible = "fsl,imx6ul-tsc";
+   reg = <0x0204 0x4000>, <0x0219c000 0x4000>;
+   interrupts = ,
+;
+   clocks = <&clks IMX6UL_CLK_IPG>,
+<&clks IMX6UL_CLK_ADC2>;
+   clock-names = "tsc", "adc";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
+   measure-delay-time = <0xfff>;
+   pre-charge-time = <0x>;
+   status = "okay";
+   };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 4/5] ARM: dts: imx6ul.dtsi: add TSC support

2015-08-28 Thread Haibo Chen
Add imx6ul touchscreen controller support.

TSC module need ADC2 module to measure the touchscreen
coordinate value. This patch put TSC and ADC2 together,
make ADC2 module only be used for TSC, can't be used as
a normal ADC.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index 09edbed..ed86052 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -571,6 +571,17 @@
status = "disabled";
};
 
+   tsc: tsc@0204 {
+   compatible = "fsl,imx6ul-tsc";
+   reg = <0x0204 0x4000>, <0x0219c000 0x4000>;
+   interrupts = ,
+;
+   clocks = <&clks IMX6UL_CLK_IPG>,
+<&clks IMX6UL_CLK_ADC2>;
+   clock-names = "tsc", "adc";
+   status = "disabled";
+   };
+
usdhc1: usdhc@0219 {
compatible = "fsl,imx6ul-usdhc", 
"fsl,imx6sx-usdhc";
reg = <0x0219 0x4000>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/5] input: touchscreen: add imx6ul_tsc driver support

2015-08-28 Thread Haibo Chen
Freescale i.MX6UL contains a internal touchscreen controller,
this patch add a driver to support this controller.

Signed-off-by: Haibo Chen 
---
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 524 +
 3 files changed, 537 insertions(+)
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 059edeb..50a42b8 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -479,6 +479,18 @@ config TOUCHSCREEN_MTOUCH
  To compile this driver as a module, choose M here: the
  module will be called mtouch.
 
+config TOUCHSCREEN_IMX6UL_TSC
+   tristate "Freescale i.MX6UL touchscreen controller"
+   depends on (OF && GPIOLIB) || COMPILE_TEST
+   help
+ Say Y here if you have a Freescale i.MX6UL, and want to
+ use the internal touchscreen controller.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ moduel will be called imx6ul_tsc.
+
 config TOUCHSCREEN_INEXIO
tristate "iNexio serial touchscreens"
select SERIO
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index c85aae2..9379b32 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX)  += egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)  += fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)   += goodix.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)  += ili210x.o
+obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC)   += imx6ul_tsc.o
 obj-$(CONFIG_TOUCHSCREEN_INEXIO)   += inexio.o
 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID)+= intel-mid-touch.o
 obj-$(CONFIG_TOUCHSCREEN_IPROC)+= bcm_iproc_tsc.o
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c 
b/drivers/input/touchscreen/imx6ul_tsc.c
new file mode 100644
index 000..fe1d3d9
--- /dev/null
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -0,0 +1,524 @@
+/*
+ * Freescale i.MX6UL touchscreen controller driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* ADC configuration registers field define */
+#define ADC_AIEN   (0x1 << 7)
+#define ADC_CONV_DISABLE   0x1F
+#define ADC_CAL(0x1 << 7)
+#define ADC_CALF   0x2
+#define ADC_12BIT_MODE (0x2 << 2)
+#define ADC_IPG_CLK0x00
+#define ADC_CLK_DIV_8  (0x03 << 5)
+#define ADC_SHORT_SAMPLE_MODE  (0x0 << 4)
+#define ADC_HARDWARE_TRIGGER   (0x1 << 13)
+#define SELECT_CHANNEL_4   0x04
+#define SELECT_CHANNEL_1   0x01
+#define DISABLE_CONVERSION_INT (0x0 << 7)
+
+/* ADC registers */
+#define REG_ADC_HC00x00
+#define REG_ADC_HC10x04
+#define REG_ADC_HC20x08
+#define REG_ADC_HC30x0C
+#define REG_ADC_HC40x10
+#define REG_ADC_HS 0x14
+#define REG_ADC_R0 0x18
+#define REG_ADC_CFG0x2C
+#define REG_ADC_GC 0x30
+#define REG_ADC_GS 0x34
+
+#define ADC_TIMEOUTmsecs_to_jiffies(100)
+
+/* TSC registers */
+#define REG_TSC_BASIC_SETING   0x00
+#define REG_TSC_PRE_CHARGE_TIME0x10
+#define REG_TSC_FLOW_CONTROL   0x20
+#define REG_TSC_MEASURE_VALUE  0x30
+#define REG_TSC_INT_EN 0x40
+#define REG_TSC_INT_SIG_EN 0x50
+#define REG_TSC_INT_STATUS 0x60
+#define REG_TSC_DEBUG_MODE 0x70
+#define REG_TSC_DEBUG_MODE20x80
+
+/* TSC configuration registers field define */
+#define DETECT_4_WIRE_MODE (0x0 << 4)
+#define AUTO_MEASURE   0x1
+#define MEASURE_SIGNAL 0x1
+#define DETECT_SIGNAL  (0x1 << 4)
+#define VALID_SIGNAL   (0x1 << 8)
+#define MEASURE_INT_EN 0x1
+#define MEASURE_SIG_EN 0x1
+#define VALID_SIG_EN   (0x1 << 8)
+#define DE_GLITCH_2(0x2 << 29)
+#define START_SENSE(0x1 << 12)
+#define TSC_DISABLE(0x1 << 16)
+#define DETECT_MODE0x2
+
+struct imx6ul_tsc {
+   struct device *dev;
+   struct input_dev *input;
+   void __iomem *tsc_regs;
+   void __iomem *adc_regs;
+   struct clk *tsc_clk;
+   struct clk *adc_clk;
+   struct gpio_desc *xnur_gpio;
+
+   int measure_delay_time;
+   int pre_charge_time;
+
+   struct completion completion;
+};
+
+/*
+ * TSC module

[PATCH v3 5/5] ARM: dts: imx6ul-14x14-evk.dts: add tsc support

2015-08-28 Thread Haibo Chen
Add touch screen surpport for i.MX6UL-EVK board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul-14x14-evk.dts | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul-14x14-evk.dts 
b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
index 25746b1..f7ad467 100644
--- a/arch/arm/boot/dts/imx6ul-14x14-evk.dts
+++ b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
@@ -87,6 +87,15 @@
};
 };
 
+&tsc {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
+   measure-delay-time = <0x>;
+   pre-charge-time = <0xfff>;
+   status = "okay";
+};
+
 &uart1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart1>;
@@ -277,6 +286,15 @@
>;
};
 
+   pinctrl_tsc: tscgrp {
+   fsl,pins = <
+   MX6UL_PAD_GPIO1_IO01__GPIO1_IO010xb0
+   MX6UL_PAD_GPIO1_IO02__GPIO1_IO020xb0
+   MX6UL_PAD_GPIO1_IO03__GPIO1_IO030xb0
+   MX6UL_PAD_GPIO1_IO04__GPIO1_IO040xb0
+   >;
+   };
+
pinctrl_uart1: uart1grp {
fsl,pins = <
MX6UL_PAD_UART1_TX_DATA__UART1_DCE_TX 0x1b0b1
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/5] ARM: imx_v6_v7_defconfig: enable imx6ul_tsc

2015-08-28 Thread Haibo Chen
Enable imx6ul touchscreen controller

Signed-off-by: Haibo Chen 
---
 arch/arm/configs/imx_v6_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index 79194c6..61d4e02 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -159,6 +159,7 @@ CONFIG_MOUSE_PS2=m
 CONFIG_MOUSE_PS2_ELANTECH=y
 CONFIG_INPUT_TOUCHSCREEN=y
 CONFIG_TOUCHSCREEN_EGALAX=y
+CONFIG_TOUCHSCREEN_IMX6UL_TSC=y
 CONFIG_TOUCHSCREEN_MC13783=y
 CONFIG_TOUCHSCREEN_TSC2007=y
 CONFIG_TOUCHSCREEN_STMPE=y
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/5] Add imx6ul touch screen controller support

2015-08-28 Thread Haibo Chen
i.MX6UL contains a touch screen controller. This patch set add imx6ul
touch screen controller driver support.

Changes for v3:
-change GPIO xnur to active low.
-Add open and close API, and delete remove API.
-Use devm functions to allocate resource.
-Use gpiod method to request GPIO.

Changes for v2:
-Add property in devicetree documentation.
-Add tsc disable code in tsc_remove function.
-Remove some redundant code.

Haibo Chen (5):
  input: touchscreen: add imx6ul_tsc driver support
  Documentation: Detail permitted DT properties for the imx6ul_tsc
  ARM: imx_v6_v7_defconfig: enable imx6ul_tsc
  ARM: dts: imx6ul.dtsi: add TSC support
  ARM: dts: imx6ul-14x14-evk.dts: add tsc support

 .../bindings/input/touchscreen/imx6ul_tsc.txt  |  36 ++
 arch/arm/boot/dts/imx6ul-14x14-evk.dts |  18 +
 arch/arm/boot/dts/imx6ul.dtsi  |  11 +
 arch/arm/configs/imx_v6_v7_defconfig   |   1 +
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 524 +
 7 files changed, 603 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/5] Add imx6ul touch screen controller support

2015-07-27 Thread Haibo Chen
i.MX6UL contains a touch screen controller. This patch set add 
imx6ul touch screen controller driver support. 

Haibo Chen (5):
  input: touchscreen: add imx6ul_tsc driver support
  Documentation: Detail permitted DT properties for the imx6ul_tsc
  ARM: imx_v6_v7_defconfig: enable imx6ul_tsc
  ARM: dts: imx6ul.dtsi: add TSC support
  ARM: dts: imx6ul-14x14-evk.dts: add tsc support

 .../bindings/input/touchscreen/imx6ul_tsc.txt  |  14 +
 arch/arm/boot/dts/imx6ul-14x14-evk.dts |  18 +
 arch/arm/boot/dts/imx6ul.dtsi  |  11 +
 arch/arm/configs/imx_v6_v7_defconfig   |   1 +
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 510 +
 7 files changed, 567 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/5] ARM: imx_v6_v7_defconfig: enable imx6ul_tsc

2015-07-27 Thread Haibo Chen
Enable imx6ul touchscreen controller

Signed-off-by: Haibo Chen 
---
 arch/arm/configs/imx_v6_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index e1ba3e2..9823ddc 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -157,6 +157,7 @@ CONFIG_MOUSE_PS2=m
 CONFIG_MOUSE_PS2_ELANTECH=y
 CONFIG_INPUT_TOUCHSCREEN=y
 CONFIG_TOUCHSCREEN_EGALAX=y
+CONFIG_TOUCHSCREEN_IMX6UL_TSC=y
 CONFIG_TOUCHSCREEN_MC13783=y
 CONFIG_TOUCHSCREEN_TSC2007=y
 CONFIG_TOUCHSCREEN_STMPE=y
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/5] Documentation: Detail permitted DT properties for the imx6ul_tsc

2015-07-27 Thread Haibo Chen
Here we apply required documentation for the imx6ul touch screen
controller driver which describe available properties and how to
use them.

Signed-off-by: Haibo Chen 
---
 .../devicetree/bindings/input/touchscreen/imx6ul_tsc.txt   | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt

diff --git a/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt 
b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
new file mode 100644
index 000..e34d752
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
@@ -0,0 +1,14 @@
+* Freescale i.MX6UL Touch Controller
+
+Required properties:
+- compatible: must be "fsl,imx6ul-tsc"
+
+Example:
+   &tsc {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   status = "okay";
+   xnur-gpio = <&gpio1 3 GPIO_ACTIVE_HIGH>;
+   measure_delay_time = <0xfff>;
+   pre_charge_time = <0x>;
+   };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] ARM: dts: imx6ul-14x14-evk.dts: add tsc support

2015-07-27 Thread Haibo Chen
Add touch screen surpport for i.MX6UL-EVK board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul-14x14-evk.dts | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul-14x14-evk.dts 
b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
index 61b41ee..323d32d 100644
--- a/arch/arm/boot/dts/imx6ul-14x14-evk.dts
+++ b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
@@ -44,6 +44,15 @@
soc-supply = <®_soc>;
 };
 
+&tsc {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   status = "okay";
+   xnur-gpio = <&gpio1 3 0>;
+   measure_delay_time = <0x>;
+   pre_charge_time = <0xfff>;
+};
+
 &uart1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart1>;
@@ -212,6 +221,15 @@
>;
};
 
+   pinctrl_tsc: tscgrp {
+   fsl,pins = <
+   MX6UL_PAD_GPIO1_IO01__GPIO1_IO010xb0
+   MX6UL_PAD_GPIO1_IO02__GPIO1_IO020xb0
+   MX6UL_PAD_GPIO1_IO03__GPIO1_IO030xb0
+   MX6UL_PAD_GPIO1_IO04__GPIO1_IO040xb0
+   >;
+   };
+
pinctrl_uart1: uart1grp {
fsl,pins = <
MX6UL_PAD_UART1_TX_DATA__UART1_DCE_TX 0x1b0b1
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/5] ARM: dts: imx6ul.dtsi: add TSC support

2015-07-27 Thread Haibo Chen
Add imx6ul touchscreen controller support.

TSC module need ADC2 module to measure the touchscreen
coordinate value. This patch put TSC and ADC2 together,
make ADC2 module only be used for TSC, can't be used as
a normal ADC.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index dc0f5b4..33aac1f 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -484,6 +484,17 @@
reg = <0x0210 0x10>;
ranges;
 
+   tsc: tsc@0204 {
+   compatible = "fsl,imx6ul-tsc";
+   reg = <0x0204 0x4000>, <0x0219c000 0x4000>;
+   interrupts = ,
+;
+   clocks = <&clks IMX6UL_CLK_IPG>,
+<&clks IMX6UL_CLK_ADC2>;
+   clock-names = "tsc", "adc";
+   status = "disabled";
+   };
+
usdhc1: usdhc@0219 {
compatible = "fsl,imx6ul-usdhc", 
"fsl,imx6sx-usdhc";
reg = <0x0219 0x4000>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/5] input: touchscreen: add imx6ul_tsc driver support

2015-07-27 Thread Haibo Chen
Freescale i.MX6UL contains a internal touchscreen controller,
this patch add a driver to support this controller.

Signed-off-by: Haibo Chen 
---
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 510 +
 3 files changed, 523 insertions(+)
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 5b272ba..32c300d 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -479,6 +479,18 @@ config TOUCHSCREEN_MTOUCH
  To compile this driver as a module, choose M here: the
  module will be called mtouch.
 
+config TOUCHSCREEN_IMX6UL_TSC
+   tristate "Freescale i.MX6UL touchscreen controller"
+   depends on OF
+   help
+ Say Y here if you have a Freescale i.MX6UL, and want to
+ use the internal touchscreen controller.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ moduel will be called imx6ul_tsc.
+
 config TOUCHSCREEN_INEXIO
tristate "iNexio serial touchscreens"
select SERIO
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index c85aae2..9379b32 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX)  += egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)  += fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)   += goodix.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)  += ili210x.o
+obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC)   += imx6ul_tsc.o
 obj-$(CONFIG_TOUCHSCREEN_INEXIO)   += inexio.o
 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID)+= intel-mid-touch.o
 obj-$(CONFIG_TOUCHSCREEN_IPROC)+= bcm_iproc_tsc.o
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c 
b/drivers/input/touchscreen/imx6ul_tsc.c
new file mode 100644
index 000..5a5a368
--- /dev/null
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -0,0 +1,510 @@
+/*
+ * Freescale i.MX6UL touchscreen controller driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* ADC configuration registers field define */
+#define ADC_AIEN   (0x1 << 7)
+#define ADC_CONV_DISABLE   0x1F
+#define ADC_CAL(0x1 << 7)
+#define ADC_CALF   0x2
+#define ADC_12BIT_MODE (0x2 << 2)
+#define ADC_IPG_CLK0x00
+#define ADC_CLK_DIV_8  (0x03 << 5)
+#define ADC_SHORT_SAMPLE_MODE  (0x0 << 4)
+#define ADC_HARDWARE_TRIGGER   (0x1 << 13)
+#define SELECT_CHANNEL_4   0x04
+#define SELECT_CHANNEL_1   0x01
+#define DISABLE_CONVERSION_INT (0x0 << 7)
+
+/* ADC registers */
+#define REG_ADC_HC00x00
+#define REG_ADC_HC10x04
+#define REG_ADC_HC20x08
+#define REG_ADC_HC30x0C
+#define REG_ADC_HC40x10
+#define REG_ADC_HS 0x14
+#define REG_ADC_R0 0x18
+#define REG_ADC_CFG0x2C
+#define REG_ADC_GC 0x30
+#define REG_ADC_GS 0x34
+
+#define ADC_TIMEOUTmsecs_to_jiffies(100)
+
+/* TSC registers */
+#define REG_TSC_BASIC_SETING   0x00
+#define REG_TSC_PRE_CHARGE_TIME0x10
+#define REG_TSC_FLOW_CONTROL   0x20
+#define REG_TSC_MEASURE_VALUE  0x30
+#define REG_TSC_INT_EN 0x40
+#define REG_TSC_INT_SIG_EN 0x50
+#define REG_TSC_INT_STATUS 0x60
+#define REG_TSC_DEBUG_MODE 0x70
+#define REG_TSC_DEBUG_MODE20x80
+
+/* TSC configuration registers field define */
+#define DETECT_4_WIRE_MODE (0x0 << 4)
+#define AUTO_MEASURE   0x1
+#define MEASURE_SIGNAL 0x1
+#define DETECT_SIGNAL  (0x1 << 4)
+#define VALID_SIGNAL   (0x1 << 8)
+#define MEASURE_INT_EN 0x1
+#define MEASURE_SIG_EN 0x1
+#define VALID_SIG_EN   (0x1 << 8)
+#define DE_GLITCH_2(0x2 << 29)
+#define START_SENSE(0x1 << 12)
+#define TSC_DISABLE(0x1 << 16)
+#define DETECT_MODE0x2
+
+struct imx6ul_tsc {
+   struct device *dev;
+   struct input_dev *input;
+   void __iomem *tsc_regs;
+   void __iomem *adc_regs;
+   struct clk *tsc_clk;
+   struct clk *adc_clk;
+
+   int tsc_irq;
+   int adc_irq;
+   int value;
+   int xnur_gpio;
+   int measure_delay_time;
+   int pre_charge_time;
+
+   struct completion com

[PATCH v2 3/5] ARM: imx_v6_v7_defconfig: enable imx6ul_tsc

2015-07-28 Thread Haibo Chen
Enable imx6ul touchscreen controller

Signed-off-by: Haibo Chen 
---
 arch/arm/configs/imx_v6_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index e1ba3e2..9823ddc 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -157,6 +157,7 @@ CONFIG_MOUSE_PS2=m
 CONFIG_MOUSE_PS2_ELANTECH=y
 CONFIG_INPUT_TOUCHSCREEN=y
 CONFIG_TOUCHSCREEN_EGALAX=y
+CONFIG_TOUCHSCREEN_IMX6UL_TSC=y
 CONFIG_TOUCHSCREEN_MC13783=y
 CONFIG_TOUCHSCREEN_TSC2007=y
 CONFIG_TOUCHSCREEN_STMPE=y
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 4/5] ARM: dts: imx6ul.dtsi: add TSC support

2015-07-28 Thread Haibo Chen
Add imx6ul touchscreen controller support.

TSC module need ADC2 module to measure the touchscreen
coordinate value. This patch put TSC and ADC2 together,
make ADC2 module only be used for TSC, can't be used as
a normal ADC.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index dc0f5b4..33aac1f 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -484,6 +484,17 @@
reg = <0x0210 0x10>;
ranges;
 
+   tsc: tsc@0204 {
+   compatible = "fsl,imx6ul-tsc";
+   reg = <0x0204 0x4000>, <0x0219c000 0x4000>;
+   interrupts = ,
+;
+   clocks = <&clks IMX6UL_CLK_IPG>,
+<&clks IMX6UL_CLK_ADC2>;
+   clock-names = "tsc", "adc";
+   status = "disabled";
+   };
+
usdhc1: usdhc@0219 {
compatible = "fsl,imx6ul-usdhc", 
"fsl,imx6sx-usdhc";
reg = <0x0219 0x4000>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/5] Documentation: Detail permitted DT properties for the imx6ul_tsc

2015-07-28 Thread Haibo Chen
Here we apply required documentation for the imx6ul touch screen
controller driver which describe available properties and how to
use them.

Signed-off-by: Haibo Chen 
---
 .../bindings/input/touchscreen/imx6ul_tsc.txt  | 36 ++
 1 file changed, 36 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt

diff --git a/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt 
b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
new file mode 100644
index 000..ac41c32
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
@@ -0,0 +1,36 @@
+* Freescale i.MX6UL Touch Controller
+
+Required properties:
+- compatible: must be "fsl,imx6ul-tsc".
+- reg: this touch controller address and the ADC2 address.
+- interrupts: the interrupt of this touch controller and ADC2.
+- clocks: the root clock of touch controller and ADC2.
+- clock-names; must be "tsc" and "adc".
+- xnur-gpio: the X- gpio this controller connect to.
+  This xnur-gpio returns to high once the finger leave the touch screen (The
+  last touch event the touch controller capture).
+
+Optional properties:
+- measure-delay-time: the value of measure delay time.
+  Before X-axis or Y-axis measurement, the screen need some time before
+  even potential distribution ready.
+  This value depends on the touch screen.
+- pre-charge-time: the touch screen need some time to precharge.
+  This value depends on the touch screen.
+
+Example:
+   tsc: tsc@0204 {
+   compatible = "fsl,imx6ul-tsc";
+   reg = <0x0204 0x4000>, <0x0219c000 0x4000>;
+   interrupts = ,
+;
+   clocks = <&clks IMX6UL_CLK_IPG>,
+<&clks IMX6UL_CLK_ADC2>;
+   clock-names = "tsc", "adc";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   xnur-gpio = <&gpio1 3 GPIO_ACTIVE_HIGH>;
+   measure-delay-time = <0xfff>;
+   pre-charge-time = <0x>;
+   status = "okay";
+   };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 5/5] ARM: dts: imx6ul-14x14-evk.dts: add tsc support

2015-07-28 Thread Haibo Chen
Add touch screen surpport for i.MX6UL-EVK board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx6ul-14x14-evk.dts | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ul-14x14-evk.dts 
b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
index 61b41ee..9995656 100644
--- a/arch/arm/boot/dts/imx6ul-14x14-evk.dts
+++ b/arch/arm/boot/dts/imx6ul-14x14-evk.dts
@@ -44,6 +44,15 @@
soc-supply = <®_soc>;
 };
 
+&tsc {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_tsc>;
+   xnur-gpio = <&gpio1 3 0>;
+   measure-delay-time = <0x>;
+   pre-charge-time = <0xfff>;
+   status = "okay";
+};
+
 &uart1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart1>;
@@ -212,6 +221,15 @@
>;
};
 
+   pinctrl_tsc: tscgrp {
+   fsl,pins = <
+   MX6UL_PAD_GPIO1_IO01__GPIO1_IO010xb0
+   MX6UL_PAD_GPIO1_IO02__GPIO1_IO020xb0
+   MX6UL_PAD_GPIO1_IO03__GPIO1_IO030xb0
+   MX6UL_PAD_GPIO1_IO04__GPIO1_IO040xb0
+   >;
+   };
+
pinctrl_uart1: uart1grp {
fsl,pins = <
MX6UL_PAD_UART1_TX_DATA__UART1_DCE_TX 0x1b0b1
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/5] Add imx6ul touch screen controller support

2015-07-28 Thread Haibo Chen
i.MX6UL contains a touch screen controller. This patch set add imx6ul
touch screen controller driver support.

Changes for v2:
-Add property in devicetree Documentation.
-Add tsc disable code in tsc_remove function.
-Remove some redundant code.


Haibo Chen (5):
  input: touchscreen: add imx6ul_tsc driver support
  Documentation: Detail permitted DT properties for the imx6ul_tsc
  ARM: imx_v6_v7_defconfig: enable imx6ul_tsc
  ARM: dts: imx6ul.dtsi: add TSC support
  ARM: dts: imx6ul-14x14-evk.dts: add tsc support

 .../bindings/input/touchscreen/imx6ul_tsc.txt  |  36 ++
 arch/arm/boot/dts/imx6ul-14x14-evk.dts |  18 +
 arch/arm/boot/dts/imx6ul.dtsi  |  11 +
 arch/arm/configs/imx_v6_v7_defconfig   |   1 +
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 504 +
 7 files changed, 583 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/5] input: touchscreen: add imx6ul_tsc driver support

2015-07-28 Thread Haibo Chen
Freescale i.MX6UL contains a internal touchscreen controller,
this patch add a driver to support this controller.

Signed-off-by: Haibo Chen 
---
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/imx6ul_tsc.c | 504 +
 3 files changed, 517 insertions(+)
 create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 5b272ba..32c300d 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -479,6 +479,18 @@ config TOUCHSCREEN_MTOUCH
  To compile this driver as a module, choose M here: the
  module will be called mtouch.
 
+config TOUCHSCREEN_IMX6UL_TSC
+   tristate "Freescale i.MX6UL touchscreen controller"
+   depends on OF
+   help
+ Say Y here if you have a Freescale i.MX6UL, and want to
+ use the internal touchscreen controller.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ moduel will be called imx6ul_tsc.
+
 config TOUCHSCREEN_INEXIO
tristate "iNexio serial touchscreens"
select SERIO
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index c85aae2..9379b32 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX)  += egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)  += fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)   += goodix.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)  += ili210x.o
+obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC)   += imx6ul_tsc.o
 obj-$(CONFIG_TOUCHSCREEN_INEXIO)   += inexio.o
 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID)+= intel-mid-touch.o
 obj-$(CONFIG_TOUCHSCREEN_IPROC)+= bcm_iproc_tsc.o
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c 
b/drivers/input/touchscreen/imx6ul_tsc.c
new file mode 100644
index 000..807f1db
--- /dev/null
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -0,0 +1,504 @@
+/*
+ * Freescale i.MX6UL touchscreen controller driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* ADC configuration registers field define */
+#define ADC_AIEN   (0x1 << 7)
+#define ADC_CONV_DISABLE   0x1F
+#define ADC_CAL(0x1 << 7)
+#define ADC_CALF   0x2
+#define ADC_12BIT_MODE (0x2 << 2)
+#define ADC_IPG_CLK0x00
+#define ADC_CLK_DIV_8  (0x03 << 5)
+#define ADC_SHORT_SAMPLE_MODE  (0x0 << 4)
+#define ADC_HARDWARE_TRIGGER   (0x1 << 13)
+#define SELECT_CHANNEL_4   0x04
+#define SELECT_CHANNEL_1   0x01
+#define DISABLE_CONVERSION_INT (0x0 << 7)
+
+/* ADC registers */
+#define REG_ADC_HC00x00
+#define REG_ADC_HC10x04
+#define REG_ADC_HC20x08
+#define REG_ADC_HC30x0C
+#define REG_ADC_HC40x10
+#define REG_ADC_HS 0x14
+#define REG_ADC_R0 0x18
+#define REG_ADC_CFG0x2C
+#define REG_ADC_GC 0x30
+#define REG_ADC_GS 0x34
+
+#define ADC_TIMEOUTmsecs_to_jiffies(100)
+
+/* TSC registers */
+#define REG_TSC_BASIC_SETING   0x00
+#define REG_TSC_PRE_CHARGE_TIME0x10
+#define REG_TSC_FLOW_CONTROL   0x20
+#define REG_TSC_MEASURE_VALUE  0x30
+#define REG_TSC_INT_EN 0x40
+#define REG_TSC_INT_SIG_EN 0x50
+#define REG_TSC_INT_STATUS 0x60
+#define REG_TSC_DEBUG_MODE 0x70
+#define REG_TSC_DEBUG_MODE20x80
+
+/* TSC configuration registers field define */
+#define DETECT_4_WIRE_MODE (0x0 << 4)
+#define AUTO_MEASURE   0x1
+#define MEASURE_SIGNAL 0x1
+#define DETECT_SIGNAL  (0x1 << 4)
+#define VALID_SIGNAL   (0x1 << 8)
+#define MEASURE_INT_EN 0x1
+#define MEASURE_SIG_EN 0x1
+#define VALID_SIG_EN   (0x1 << 8)
+#define DE_GLITCH_2(0x2 << 29)
+#define START_SENSE(0x1 << 12)
+#define TSC_DISABLE(0x1 << 16)
+#define DETECT_MODE0x2
+
+struct imx6ul_tsc {
+   struct device *dev;
+   struct input_dev *input;
+   void __iomem *tsc_regs;
+   void __iomem *adc_regs;
+   struct clk *tsc_clk;
+   struct clk *adc_clk;
+
+   int xnur_gpio;
+   int measure_delay_time;
+   int pre_charge_time;
+
+   struct completion completion;
+};
+
+/*
+ * TSC module need ADC to get the mea

[PATCH v3 4/6] mmc: sdhci-esdhc-imx: add compatible string in bingding doc

2015-07-29 Thread Haibo Chen
Add a required property "fsl,imx7d-usdhc" in binding doc.
Add an optional property "fsl,tuning-step" in binding doc.

Signed-off-by: Haibo Chen 
---
 Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 211e778..c6624bc 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -15,6 +15,7 @@ Required properties:
   "fsl,imx6q-usdhc"
   "fsl,imx6sl-usdhc"
   "fsl,imx6sx-usdhc"
+  "fsl,imx7d-usdhc"
 
 Optional properties:
 - fsl,wp-controller : Indicate to use controller internal write protection
@@ -27,6 +28,7 @@ Optional properties:
   transparent level shifters on the outputs of the controller. Two cells are
   required, first cell specifies minimum slot voltage (mV), second cell
   specifies maximum slot voltage (mV). Several ranges could be specified.
+- fsl,tuning-step: Specify the increasing delay cell steps in tuning procedure.
 
 Examples:
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 6/6] mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

2015-07-29 Thread Haibo Chen
Currently we find that if a usdhc is choosed to boot system, then ROM
code will set the burst length enable bit of this usdhc as 0.

This will make performance drop a lot if this usdhc's burst length is
16. So this patch set back the burst_length_enable bit as 1, which is
the default value, and means burst length is enabled for INCR.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 37d0095..dd945e5 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
 #include "sdhci-esdhc.h"
 
 #defineESDHC_CTRL_D3CD 0x08
+#define ESDHC_BURST_LEN_EN_INCR(1 << 27)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC  0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
@@ -1158,6 +1159,16 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+   /*
+* ROM code will change the burst_length_enable setting to
+* zero if this usdhc is choosed to boot system. Change it
+* back here, otherwise it will impact the performance a
+* lot if the burst length is 16.
+*/
+   writel(readl(host->ioaddr + SDHCI_HOST_CONTROL)
+   | ESDHC_BURST_LEN_EN_INCR,
+   host->ioaddr + SDHCI_HOST_CONTROL);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/6] mmc: imx: a few fixes and new feature

2015-07-29 Thread Haibo Chen
Changes for v3:
-Add property describe in binding doc.

Haibo Chen (6):
  mmc: sdhci-esdhc-imx: add imx7d support and support HS400
  mmc: sdhci-esdhc-imx: add tuning-step seting support
  ARM: dts: imx7d-sdb: add eMMC5.0 support
  mmc: sdhci-esdhc-imx: add compatible string in bingding doc
  mmc: sdhci-esdhc-imx: config watermark level and burst length
  mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

 .../devicetree/bindings/mmc/fsl-imx-esdhc.txt  |  2 +
 arch/arm/boot/dts/imx7d-sdb.dts| 13 +++
 drivers/mmc/host/sdhci-esdhc-imx.c | 97 +-
 include/linux/platform_data/mmc-esdhc-imx.h|  1 +
 4 files changed, 112 insertions(+), 1 deletion(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/6] mmc: sdhci-esdhc-imx: add imx7d support and support HS400

2015-07-29 Thread Haibo Chen
The imx7d usdhc is derived from imx6sx, the difference is that
imx7d support HS400.

So introduce a new compatible string for imx7d and add HS400
support for imx7d usdhc.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 66 ++
 1 file changed, 66 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index c6b9f64..b441eed 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -44,6 +44,7 @@
 #define  ESDHC_MIX_CTRL_EXE_TUNE   (1 << 22)
 #define  ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
 #define  ESDHC_MIX_CTRL_FBCLK_SEL  (1 << 25)
+#define  ESDHC_MIX_CTRL_HS400_EN   (1 << 26)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
 /* Tuning bits */
@@ -60,6 +61,16 @@
 #define  ESDHC_TUNE_CTRL_MIN   0
 #define  ESDHC_TUNE_CTRL_MAX   ((1 << 7) - 1)
 
+/* strobe dll register */
+#define ESDHC_STROBE_DLL_CTRL  0x70
+#define ESDHC_STROBE_DLL_CTRL_ENABLE   (1 << 0)
+#define ESDHC_STROBE_DLL_CTRL_RESET(1 << 1)
+#define ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT 3
+
+#define ESDHC_STROBE_DLL_STATUS0x74
+#define ESDHC_STROBE_DLL_STS_REF_LOCK  (1 << 1)
+#define ESDHC_STROBE_DLL_STS_SLV_LOCK  0x1
+
 #define ESDHC_TUNING_CTRL  0xcc
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
@@ -120,6 +131,8 @@
 #define ESDHC_FLAG_ERR004536   BIT(7)
 /* The IP supports HS200 mode */
 #define ESDHC_FLAG_HS200   BIT(8)
+/* The IP supports HS400 mode */
+#define ESDHC_FLAG_SUP_HS400   BIT(9)
 
 struct esdhc_soc_data {
u32 flags;
@@ -156,6 +169,12 @@ static struct esdhc_soc_data usdhc_imx6sx_data = {
| ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200,
 };
 
+static struct esdhc_soc_data usdhc_imx7d_data = {
+   .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+   | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
+   | ESDHC_FLAG_SUP_HS400,
+};
+
 struct pltfm_imx_data {
u32 scratchpad;
struct pinctrl *pinctrl;
@@ -199,6 +218,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
{ .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
{ .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
{ .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
+   { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -274,6 +294,10 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
| SDHCI_SUPPORT_SDR50
| SDHCI_USE_SDR50_TUNING;
+
+   /* imx7d does not have a support_hs400 register, fake 
one */
+   if (imx_data->socdata->flags & ESDHC_FLAG_SUP_HS400)
+   val |= SDHCI_SUPPORT_HS400;
}
}
 
@@ -774,6 +798,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
break;
case MMC_TIMING_UHS_SDR104:
case MMC_TIMING_MMC_HS200:
+   case MMC_TIMING_MMC_HS400:
pinctrl = imx_data->pins_200mhz;
break;
default:
@@ -784,6 +809,30 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
return pinctrl_select_state(imx_data->pinctrl, pinctrl);
 }
 
+static void esdhc_set_strobe_dll(struct sdhci_host *host)
+{
+   u32 v;
+
+   /* force a reset on strobe dll */
+   writel(ESDHC_STROBE_DLL_CTRL_RESET, host->ioaddr + 
ESDHC_STROBE_DLL_CTRL);
+   /*
+* enable strobe dll ctrl and adjust the delay target
+* for the uSDHC loopback read clock
+*/
+   v = ESDHC_STROBE_DLL_CTRL_ENABLE |
+   (7 << ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
+   writel(v, host->ioaddr + ESDHC_STROBE_DLL_CTRL);
+   /* wait 1us to make sure strobe dll status register stable */
+   udelay(1);
+   v = readl(host->ioaddr + ESDHC_STROBE_DLL_STATUS);
+   if (!(v & ESDHC_STROBE_DLL_STS_REF_LOCK))
+   dev_warn(mmc_dev(host->mmc),
+   "warning! HS400 strobe DLL status REF not lock!\n");
+   if (!(v & ESDHC_STROBE_DLL_STS_SLV_LOCK))
+   dev_warn(mmc_dev(host->mmc),
+   "warning! HS400 strobe DLL status SLV not lock!\n");
+}
+
 static void esdhc_set_uhs_signaling(struct sdhci_host *host, unsigned timing)
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(

[PATCH v3 5/6] mmc: sdhci-esdhc-imx: config watermark level and burst length

2015-07-29 Thread Haibo Chen
i.MX7D support eMMC HS400 mode, this mode can run in 8 bit,200MHZ
DDR mode. So the I/O speed improve a lot compare to SD3.0

The default burst length is 8, if we don't change this value, in
HS400 mode, when we do eMMC read operation, we can find that the
clock signal will stop for a period of time. This means the speed
of data moving on AHB bus is slower than I/O speed. So we should
improve the speed of data moving on AHB bus.

For imx7d usdhc, this patch set the burst length as 16, and set
watermark level as 64. The test result is the clock signal has
no stop during the eMMC HS400 operation. For other imx usdhc, remain
the default value: burst length as 8, watermark level as 16.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 158f93b..37d0095 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -239,6 +239,11 @@ static inline int is_imx6q_usdhc(struct pltfm_imx_data 
*data)
return data->socdata == &usdhc_imx6q_data;
 }
 
+static inline int is_imx7d_usdhc(struct pltfm_imx_data *data)
+{
+   return data->socdata == &usdhc_imx7d_data;
+}
+
 static inline int esdhc_is_usdhc(struct pltfm_imx_data *data)
 {
return !!(data->socdata->flags & ESDHC_FLAG_USDHC);
@@ -1145,7 +1150,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
 * to something insane.  Change it back here.
 */
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+   if (is_imx7d_usdhc(imx_data))
+   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+   else
+   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/6] mmc: sdhci-esdhc-imx: add tuning-step seting support

2015-07-29 Thread Haibo Chen
tuning-step is the delay cell steps in tuning procedure. The default value
of tuning-step is 1. For imx6 series usdhc, tuning procedure can be passed
when the tuning-step value is 1. But imx7d usdhc need the tuning-step value
as 2, otherwise it can't pass the tuning procedure.

So this patch add the tuning-step setting in driver, so that user can set
the tuning-step value in dts.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c  | 9 +
 include/linux/platform_data/mmc-esdhc-imx.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index b441eed..158f93b 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -75,6 +75,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
 #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
@@ -472,6 +473,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
} else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+   u32 tuning_ctrl;
if (val & SDHCI_CTRL_TUNED_CLK) {
v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
} else {
@@ -482,6 +484,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
if (val & SDHCI_CTRL_EXEC_TUNING) {
v |= ESDHC_MIX_CTRL_EXE_TUNE;
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+   tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
+   tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
+   if (imx_data->boarddata.tuning_step)
+   tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
@@ -949,6 +956,8 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
if (gpio_is_valid(boarddata->wp_gpio))
boarddata->wp_type = ESDHC_WP_GPIO;
 
+   of_property_read_u32(np, "fsl,tuning-step", &boarddata->tuning_step);
+
if (of_find_property(np, "no-1-8-v", NULL))
boarddata->support_vsel = false;
else
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h 
b/include/linux/platform_data/mmc-esdhc-imx.h
index e1571ef..95ccab3 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -45,5 +45,6 @@ struct esdhc_platform_data {
int max_bus_width;
bool support_vsel;
unsigned int delay_line;
+   unsigned int tuning_step;   /* The delay cell steps in tuning 
procedure */
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/6] ARM: dts: imx7d-sdb: add eMMC5.0 support

2015-07-29 Thread Haibo Chen
imx7d-sdb board has a eMMC5.0 on usdhc3. This eMMC support HS400.
This patch add usdhc3 support for HS400

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index fdd1d7c..8059458 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -241,6 +241,19 @@
status = "okay";
 };
 
+&usdhc3 {
+   pinctrl-names = "default", "state_100mhz", "state_200mhz";
+   pinctrl-0 = <&pinctrl_usdhc3>;
+   pinctrl-1 = <&pinctrl_usdhc3_100mhz>;
+   pinctrl-2 = <&pinctrl_usdhc3_200mhz>;
+   assigned-clocks = <&clks IMX7D_USDHC3_ROOT_CLK>;
+   assigned-clock-rates = <4>;
+   bus-width = <8>;
+   fsl,tuning-step = <2>;
+   non-removable;
+   status = "okay";
+};
+
 &iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mmc: sdhci: fix dma memory leak in sdhci_pre_req()

2015-08-07 Thread Haibo Chen
Currently one mrq->data maybe execute dma_map_sg() twice
when mmc subsystem prepare over one new request, and the
following log show up:
sdhci[sdhci_pre_dma_transfer] invalid cookie: 24, next-cookie 25

In this condition, mrq->date map a dma-memory(1) in sdhci_pre_req
for the first time, and map another dma-memory(2) in sdhci_prepare_data
for the second time. But driver only unmap the dma-memory(2), and
dma-memory(1) never unmapped, which cause the dma memory leak issue.

This patch use another method to map the dma memory for the mrq->data
which can fix this dma memory leak issue.

Fixes: commit 348487cb28e66b0 ("mmc: sdhci: use pipeline mmc requests to 
improve performance")
Cc: sta...@vger.kernel.org # 4.0+
Reported-by: Jiri Slaby 
Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci.c | 67 ++--
 drivers/mmc/host/sdhci.h |  8 +++---
 2 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c83d110..8d2864b 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -54,8 +54,7 @@ static void sdhci_finish_command(struct sdhci_host *);
 static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
 static int sdhci_pre_dma_transfer(struct sdhci_host *host,
-   struct mmc_data *data,
-   struct sdhci_host_next *next);
+   struct mmc_data *data);
 static int sdhci_do_get_cd(struct sdhci_host *host);
 
 #ifdef CONFIG_PM
@@ -495,7 +494,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
goto fail;
BUG_ON(host->align_addr & host->align_mask);
 
-   host->sg_count = sdhci_pre_dma_transfer(host, data, NULL);
+   host->sg_count = sdhci_pre_dma_transfer(host, data);
if (host->sg_count < 0)
goto unmap_align;
 
@@ -634,9 +633,11 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
}
}
 
-   if (!data->host_cookie)
+   if (data->host_cookie == COOKIE_MAPPED) {
dma_unmap_sg(mmc_dev(host->mmc), data->sg,
data->sg_len, direction);
+   data->host_cookie = COOKIE_UNMAPPED;
+   }
 }
 
 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
@@ -832,7 +833,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, 
struct mmc_command *cmd)
} else {
int sg_cnt;
 
-   sg_cnt = sdhci_pre_dma_transfer(host, data, NULL);
+   sg_cnt = sdhci_pre_dma_transfer(host, data);
if (sg_cnt <= 0) {
/*
 * This only happens when someone fed
@@ -948,11 +949,13 @@ static void sdhci_finish_data(struct sdhci_host *host)
if (host->flags & SDHCI_USE_ADMA)
sdhci_adma_table_post(host, data);
else {
-   if (!data->host_cookie)
+   if (data->host_cookie == COOKIE_MAPPED) {
dma_unmap_sg(mmc_dev(host->mmc),
data->sg, data->sg_len,
(data->flags & MMC_DATA_READ) ?
DMA_FROM_DEVICE : DMA_TO_DEVICE);
+   data->host_cookie = COOKIE_UNMAPPED;
+   }
}
}
 
@@ -2105,49 +2108,36 @@ static void sdhci_post_req(struct mmc_host *mmc, struct 
mmc_request *mrq,
struct mmc_data *data = mrq->data;
 
if (host->flags & SDHCI_REQ_USE_DMA) {
-   if (data->host_cookie)
+   if (data->host_cookie == COOKIE_GIVEN ||
+   data->host_cookie == COOKIE_MAPPED)
dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
 data->flags & MMC_DATA_WRITE ?
 DMA_TO_DEVICE : DMA_FROM_DEVICE);
-   mrq->data->host_cookie = 0;
+   data->host_cookie = COOKIE_UNMAPPED;
}
 }
 
 static int sdhci_pre_dma_transfer(struct sdhci_host *host,
-  struct mmc_data *data,
-  struct sdhci_host_next *next)
+  struct mmc_data *data)
 {
int sg_count;
 
-   if (!next && data->host_cookie &&
-   data->host_cookie != host->next_data.cookie) {
-   pr_debug(DRIVER_NAME "[%s] invalid cookie: %d, next-cookie 
%d\n",
- 

RE: [PATCH] sdhci: Add quirk and device tree parameter to force SD test mode

2016-08-22 Thread Haibo Chen
> -Original Message-
> From: linux-mmc-ow...@vger.kernel.org [mailto:linux-mmc-
> ow...@vger.kernel.org] On Behalf Of Zach Brown
> Sent: Tuesday, August 23, 2016 6:56 AM
> To: adrian.hun...@intel.com
> Cc: ulf.hans...@linaro.org; mark.rutl...@arm.com; robh...@kernel.org;
> linux-...@vger.kernel.org; devicet...@vger.kernel.org; linux-
> ker...@vger.kernel.org
> Subject: [PATCH] sdhci: Add quirk and device tree parameter to force SD test
> mode
> 
> From: Jaeden Amero 
> 
> On some devices, CD is broken so that we must force the SDHCI into test mode
> and set CD, so that it always detects an SD card as present.
> 
> In order to get a device with broken CD working, we had previously always set
> the SDHCI into test mode. Unfortunately, this had the side effect of making 
> all
> SD cards used with our Linux kernels undetectable and non-removable.

Why not use the poll mode? You can set the flag MMC_CAP_NEEDS_POLL, then 
the mmc core will detect the card every second.

> 
> By making this "SD test mode" setting optional via a quirk, we can avoid this
> side effect for devices other than the device with broken CD.
> Additionally, we add a device parameter to sdhci-pltfm to allow all SDHCI
> drivers to enable this quirk.
> 
> Signed-off-by: Jaeden Amero 
> Signed-off-by: Zach Brown 
> ---
>  Documentation/devicetree/bindings/mmc/mmc.txt | 2 ++
>  drivers/mmc/host/sdhci-pltfm.c| 4 
>  drivers/mmc/host/sdhci.c  | 9 +
>  drivers/mmc/host/sdhci.h  | 4 
>  4 files changed, 19 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mmc/mmc.txt
> b/Documentation/devicetree/bindings/mmc/mmc.txt
> index 22d1e1f..3a9be41 100644
> --- a/Documentation/devicetree/bindings/mmc/mmc.txt
> +++ b/Documentation/devicetree/bindings/mmc/mmc.txt
> @@ -52,6 +52,8 @@ Optional properties:
>  - no-sdio: controller is limited to send sdio cmd during initialization
>  - no-sd: controller is limited to send sd cmd during initialization
>  - no-mmc: controller is limited to send mmc cmd during initialization
> +- force-sd-cd-test-mode: card detection is broken on device, force cd
> +test
> +  enable and cd test inserted so host will always detect a card.
> 
>  *NOTE* on CD and WP polarity. To use common for all SD/MMC host
> controllers line  polarity properties, we have to fix the meaning of the 
> "normal"
> and "inverted"
> diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
> index 1d17dcf..056d101 100644
> --- a/drivers/mmc/host/sdhci-pltfm.c
> +++ b/drivers/mmc/host/sdhci-pltfm.c
> @@ -87,6 +87,10 @@ void sdhci_get_of_property(struct platform_device
> *pdev)
>   if (of_get_property(np, "broken-cd", NULL))
>   host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
> 
> + if (of_get_property(np, "force-sd-cd-test-mode", NULL))
> + host->quirks2 |=
> + SDHCI_QUIRK2_MUST_FORCE_SD_CD_TEST_MODE;
> +
>   if (of_get_property(np, "no-1-8-v", NULL))
>   host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index
> cd65d47..2f4c6f9 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -117,6 +117,15 @@ static inline bool sdhci_data_line_cmd(struct
> mmc_command *cmd)  static void sdhci_set_card_detection(struct sdhci_host
> *host, bool enable)  {
>   u32 present;
> + u8  ctrl;
> +
> + if (host->quirks2 & SDHCI_QUIRK2_MUST_FORCE_SD_CD_TEST_MODE)
> {
> + /* Put the card in test mode, with card inserted */
> + ctrl = sdhci_readl(host, SDHCI_HOST_CONTROL);
> + ctrl |= SDHCI_CTRL_CD_TEST_INSERTED |
> + SDHCI_CTRL_CD_TEST_ENABLE;
> + sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
> + }
> 
>   if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
>   !mmc_card_is_removable(host->mmc))
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index
> 0411c9f..dd609b2 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -84,6 +84,8 @@
>  #define   SDHCI_CTRL_ADMA32  0x10
>  #define   SDHCI_CTRL_ADMA64  0x18
>  #define   SDHCI_CTRL_8BITBUS 0x20
> +#define  SDHCI_CTRL_CD_TEST_INSERTED 0x40
> +#define  SDHCI_CTRL_CD_TEST_ENABLE   0x80
> 
>  #define SDHCI_POWER_CONTROL  0x29
>  #define  SDHCI_POWER_ON  0x01
> @@ -422,6 +424,8 @@ struct sdhci_host {
>  #define SDHCI_QUIRK2_ACMD23_BROKEN   (1<<14)
>  /* Broken Clock divider zero in controller */
>  #define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN   (1<<15)
> +/* Controller must support device with broken CD */
> +#define SDHCI_QUIRK2_MUST_FORCE_SD_CD_TEST_MODE  (1<<16)
> 
>   int irq;/* Device IRQ */
>   void __iomem *ioaddr;   /* Mapped address */
> --
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the
> body of a mess

[PATCH 2/5] Documentation: add the binding file for Freescale imx7d ADC driver

2015-10-08 Thread Haibo Chen
The patch adds the binding file for Freescale imx7d ADC driver.

Signed-off-by: Haibo Chen 
---
 .../devicetree/bindings/iio/adc/imx7d-adc.txt  | 26 ++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
new file mode 100644
index 000..6b21fd27
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
@@ -0,0 +1,26 @@
+Freescale imx7d ADC bindings
+
+The devicetree bingdings are for the nwe ADC driver written for
+imx7d SoC.
+
+Required properties:
+- compatible: Should be "fsl,imx7d-adc"
+- reg: Offset and length of the register set for the ADC device
+- interrupts: The interrupt number for the ADC device
+- clocks: The root clock of the ADC controller
+- clock-names: Must contain "adc", matching entry in the clocks property
+- vref-supply: The regulator supply ADC reference voltage
+
+Optional properties:
+- num-channels: the number of channels used
+
+Example:
+adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   num-channels = <4>;
+   vref-supply = <®_vcc_3v3_mcu>;
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/5] clk: imx7d: add ADC root clock

2015-10-08 Thread Haibo Chen
Add ADC root clock support in imx7d clock tree.

Signed-off-by: Haibo Chen 
---
 drivers/clk/imx/clk-imx7d.c | 1 +
 include/dt-bindings/clock/imx7d-clock.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-imx7d.c b/drivers/clk/imx/clk-imx7d.c
index f86b680..448ef32 100644
--- a/drivers/clk/imx/clk-imx7d.c
+++ b/drivers/clk/imx/clk-imx7d.c
@@ -829,6 +829,7 @@ static void __init imx7d_clocks_init(struct device_node 
*ccm_node)
clks[IMX7D_CSI_MCLK_ROOT_CLK] = imx_clk_gate2("csi_mclk_root_clk", 
"csi_mclk_post_div", base + 0x4490, 0);
clks[IMX7D_AUDIO_MCLK_ROOT_CLK] = imx_clk_gate2("audio_mclk_root_clk", 
"audio_mclk_post_div", base + 0x4790, 0);
clks[IMX7D_WRCLK_ROOT_CLK] = imx_clk_gate2("wrclk_root_clk", 
"wrclk_post_div", base + 0x47a0, 0);
+   clks[IMX7D_ADC_ROOT_CLK] = imx_clk_gate2("adc_root_clk", 
"ipg_root_clk", base + 0x4200, 0);
 
clks[IMX7D_GPT_3M_CLK] = imx_clk_fixed_factor("gpt_3m", "osc", 1, 8);
 
diff --git a/include/dt-bindings/clock/imx7d-clock.h 
b/include/dt-bindings/clock/imx7d-clock.h
index 728df28..a4a7a9c 100644
--- a/include/dt-bindings/clock/imx7d-clock.h
+++ b/include/dt-bindings/clock/imx7d-clock.h
@@ -446,5 +446,6 @@
 #define IMX7D_MU_ROOT_CLK  433
 #define IMX7D_SEMA4_HS_ROOT_CLK434
 #define IMX7D_PLL_DRAM_TEST_DIV435
-#define IMX7D_CLK_END  436
+#define IMX7D_ADC_ROOT_CLK 436
+#define IMX7D_CLK_END  437
 #endif /* __DT_BINDINGS_CLOCK_IMX7D_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/5] iio: adc: add IMX7D ADC driver support

2015-10-08 Thread Haibo Chen
Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
driver support, and the driver only support ADC software trigger.

Signed-off-by: Haibo Chen 
---
 drivers/iio/adc/Kconfig |   9 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/imx7d_adc.c | 586 
 3 files changed, 596 insertions(+)
 create mode 100644 drivers/iio/adc/imx7d_adc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c74..bf0611c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -194,6 +194,15 @@ config HI8435
  This driver can also be built as a module. If so, the module will be
  called hi8435.
 
+config IMX7D_ADC
+   tristate "IMX7D ADC driver"
+   depends on OF
+   help
+ Say yes here to build support for IMX7D ADC.
+
+ This driver can also be built as a module. If so, the module will be
+ called imx7d_adc.
+
 config LP8788_ADC
tristate "LP8788 ADC driver"
depends on MFD_LP8788
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a9..282ffc01 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_HI8435) += hi8435.o
+obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
new file mode 100644
index 000..8be8bf8
--- /dev/null
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -0,0 +1,586 @@
+/*
+ * Freescale ADC driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* This will be the driver name the kernel reports */
+#define DRIVER_NAME "imx7d_adc"
+
+/* ADC register */
+#define REG_ADC_CH_A_CFG1  0x00
+#define REG_ADC_CH_A_CFG2  0x10
+#define REG_ADC_CH_B_CFG1  0x20
+#define REG_ADC_CH_B_CFG2  0x30
+#define REG_ADC_CH_C_CFG1  0x40
+#define REG_ADC_CH_C_CFG2  0x50
+#define REG_ADC_CH_D_CFG1  0x60
+#define REG_ADC_CH_D_CFG2  0x70
+#define REG_ADC_CH_SW_CFG  0x80
+#define REG_ADC_TIMER_UNIT 0x90
+#define REG_ADC_DMA_FIFO   0xa0
+#define REG_ADC_FIFO_STATUS0xb0
+#define REG_ADC_INT_SIG_EN 0xc0
+#define REG_ADC_INT_EN 0xd0
+#define REG_ADC_INT_STATUS 0xe0
+#define REG_ADC_CHA_B_CNV_RSLT 0xf0
+#define REG_ADC_CHC_D_CNV_RSLT 0x100
+#define REG_ADC_CH_SW_CNV_RSLT 0x110
+#define REG_ADC_DMA_FIFO_DAT   0x120
+#define REG_ADC_ADC_CFG0x130
+
+#define CHANNEL_REG_SHIF   0x20
+
+#define CHANNEL_EN (0x1 << 31)
+#define CHANNEL_DISABLE(0x0 << 31)
+#define CHANNEL_SINGLE (0x1 << 30)
+#define CHANNEL_AVG_EN (0x1 << 29)
+#define CHANNEL_SEL_SHIF   24
+
+#define PRE_DIV_4  (0x0 << 29)
+#define PRE_DIV_8  (0x1 << 29)
+#define PRE_DIV_16 (0x2 << 29)
+#define PRE_DIV_32 (0x3 << 29)
+#define PRE_DIV_64 (0x4 << 29)
+#define PRE_DIV_128(0x5 << 29)
+
+#define ADC_CLK_DOWN   (0x1 << 31)
+#define ADC_POWER_DOWN (0x1 << 1)
+#define ADC_EN 0x1
+
+#define AVG_NUM_4  (0x0 << 12)
+#define AVG_NUM_8  (0x1 << 12)
+#define AVG_NUM_16 (0x2 << 12)
+#define AVG_NUM_32 (0x3 << 12)
+
+#define CHA_COV_INT_EN (0x1 << 8)
+#define CHB_COV_INT_EN (0x1 << 9)
+#define CHC_COV_INT_EN (0x1 << 10)
+#define CHD_COV_INT_EN (0x1 << 11)
+#define CHANNEL_INT_EN (CHA_COV_INT_EN | CHB_COV_INT_EN | \
+   CHC_COV_INT_EN | CHD_COV_INT_EN)
+#define CHANNEL_INT_STATUS 0xf00
+
+#define IMX7D_ADC_TIMEOUT  msecs_to_jiffies(100)
+
+#define IMX7D_ADC_CHAN(_idx, _chan_type) { \
+ 

[PATCH 4/5] ARM: dts: imx7d.dtsi: add ADC support

2015-10-08 Thread Haibo Chen
Add imx7d ADC support.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d.dtsi | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index ebc053a..87c3319 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -583,6 +583,26 @@
reg = <0x3040 0x40>;
ranges;
 
+   adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   num-channels = <4>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
+   adc2: adc@3062 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3062 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   num-channels = <4>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
pwm1: pwm@3066 {
compatible = "fsl,imx7d-pwm", "fsl,imx27-pwm";
reg = <0x3066 0x1>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] ARM: dts: imx7d-sdb: add ADC support

2015-10-08 Thread Haibo Chen
Add ADC support for imx7d-sdb board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index 432aaf5..b2c4536 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -97,6 +97,16 @@
};
 };
 
+&adc1 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
+&adc2 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
 &cpu0 {
arm-supply = <&sw1a_reg>;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/4] iio: adc: add IMX7D ADC driver support

2015-11-13 Thread Haibo Chen
On Tue, Nov 10, 2015 at 03:58:14PM +0100, Lars-Peter Clausen wrote:
> On 11/09/2015 02:28 PM, Haibo Chen wrote:
> > Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
> > driver support, and the driver only support ADC software trigger.
> > 
> > Signed-off-by: Haibo Chen 
> 
> Looks pretty good, a few comments inline.
> 
> [...]
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> I don't think you need all of these.
> 
> [...]

Yes, I will remove delay.h slab.h of_irq.h and of_platform.h

> > +static void imx7d_adc_feature_config(struct imx7d_adc *info)
> > +{
> > +   info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4;
> > +   info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32;
> > +   info->adc_feature.core_time_unit = 1;
> > +   info->adc_feature.average_en = true;
> 
> What's the plan for these? Right now they are always initialized to the same
> static value.
> 

In future, we can get these values from dts file, currently we just use the 
static value.

> 
> > +}
> [...]
> > +static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
> > +   struct iio_chan_spec const *chan,
> > +   int *val,
> > +   int *val2,
> > +   long mask)
> > +{
> > +   struct imx7d_adc *info = iio_priv(indio_dev);
> > +
> > +   u32 channel;
> > +   long ret;
> > +
> > +   switch (mask) {
> > +   case IIO_CHAN_INFO_RAW:
> > +   mutex_lock(&indio_dev->mlock);
> > +   reinit_completion(&info->completion);
> > +
> > +   channel = (chan->channel) & 0x0f;
> > +   info->channel = channel;
> > +   imx7d_adc_channel_set(info);
> 
> How about just passing channel directy adc_channel_set() instead of doing it
> implicitly through the info struct?
> 

I think there is no difference, besides, using this parameter info struct can 
keep align with other functions.
eg.  imx7d_adc_sample_set(), imx7d_adc_hw_init(), imx7d_adc_get_sample_rate(), 
all these functions have the same parameter.

> [...]
> > +static irqreturn_t imx7d_adc_isr(int irq, void *dev_id)
> > +{
> > +   struct imx7d_adc *info = (struct imx7d_adc *)dev_id;
> > +   int status;
> > +
> > +   status = readl(info->regs + IMX7D_REG_ADC_INT_STATUS);
> > +   if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS) {
> > +   info->value = imx7d_adc_read_data(info);
> > +   complete(&info->completion);
> > +   }
> > +   writel(0, info->regs + IMX7D_REG_ADC_INT_STATUS);
> 
> Is the hardware really this broken? If the interrupt happens between reading
> the status register and clearing it here it will be missed.
> 

I think interrupt can't happen between reading the status register and clearing 
it.
Because in function imx7d_adc_read_raw(), we call the function 
imx7d_adc_channel_set(info), in this function, we config the register
REG_ADC_CH_A\B\C\D_CFG1 and REG_ADC_CH_A\B\C\D_CFG2, only when these registers
is configed, ADC start a conversion. Once the conversion complete, ADC trigger 
an 
interrupt, and call the imx7d_adc_isr().

> > +
> > +   return IRQ_HANDLED;
> 
> You should only return IRQ_HANDLED if you actually handled are interrupt.
> 

Here in the interrupt, we just handle the channel conversion finished flag, for
other flag, ignore them this time, Will add other flag in future.

> > +}
> [...]
> > +
> > +static int imx7d_adc_probe(struct platform_device *pdev)
> > +{
> > +   struct imx7d_adc *info;
> > +   struct iio_dev *indio_dev;
> > +   struct resource *mem;
> > +   int irq;
> > +   int ret;
> > +   u32 channels;
> > +
> > +   indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct imx7d_adc));
> > +   if (!indio_dev) {
> > +   dev_err(&pdev->dev, "Failed allocating iio device\n");
> > +   return -ENOMEM;
> > +   }
> > +
> > +   info = iio_priv(indio_dev);
> > +   info->dev = &pdev->dev;
> > +
> > +   mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +   info->regs = devm_ioremap_resource(&pdev->dev, mem);
> > +   if (IS_ERR(info->regs)) {
> > +   ret = PTR_ERR(info->regs);
> > +   dev_err(&pdev->dev, "failed to remap a

[PATCH v4 1/4] iio: adc: add IMX7D ADC driver support

2015-12-01 Thread Haibo Chen
Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
driver support, and the driver only support ADC software trigger.

Signed-off-by: Haibo Chen 
---
 drivers/iio/adc/Kconfig |   9 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/imx7d_adc.c | 588 
 3 files changed, 598 insertions(+)
 create mode 100644 drivers/iio/adc/imx7d_adc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c74..3493a46 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -194,6 +194,15 @@ config HI8435
  This driver can also be built as a module. If so, the module will be
  called hi8435.
 
+config IMX7D_ADC
+   tristate "IMX7D ADC driver"
+   depends on ARCH_MXC || COMPILE_TEST
+   help
+ Say yes here to build support for IMX7D ADC.
+
+ This driver can also be built as a module. If so, the module will be
+ called imx7d_adc.
+
 config LP8788_ADC
tristate "LP8788 ADC driver"
depends on MFD_LP8788
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a9..282ffc01 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_HI8435) += hi8435.o
+obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
new file mode 100644
index 000..4780595
--- /dev/null
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -0,0 +1,588 @@
+/*
+ * Freescale i.MX7D ADC driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* ADC register */
+#define IMX7D_REG_ADC_CH_A_CFG10x00
+#define IMX7D_REG_ADC_CH_A_CFG20x10
+#define IMX7D_REG_ADC_CH_B_CFG10x20
+#define IMX7D_REG_ADC_CH_B_CFG20x30
+#define IMX7D_REG_ADC_CH_C_CFG10x40
+#define IMX7D_REG_ADC_CH_C_CFG20x50
+#define IMX7D_REG_ADC_CH_D_CFG10x60
+#define IMX7D_REG_ADC_CH_D_CFG20x70
+#define IMX7D_REG_ADC_CH_SW_CFG0x80
+#define IMX7D_REG_ADC_TIMER_UNIT   0x90
+#define IMX7D_REG_ADC_DMA_FIFO 0xa0
+#define IMX7D_REG_ADC_FIFO_STATUS  0xb0
+#define IMX7D_REG_ADC_INT_SIG_EN   0xc0
+#define IMX7D_REG_ADC_INT_EN   0xd0
+#define IMX7D_REG_ADC_INT_STATUS   0xe0
+#define IMX7D_REG_ADC_CHA_B_CNV_RSLT   0xf0
+#define IMX7D_REG_ADC_CHC_D_CNV_RSLT   0x100
+#define IMX7D_REG_ADC_CH_SW_CNV_RSLT   0x110
+#define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120
+#define IMX7D_REG_ADC_ADC_CFG  0x130
+
+#define IMX7D_REG_ADC_CHANNEL_CFG2_BASE0x10
+#define IMX7D_EACH_CHANNEL_REG_OFFSET  0x20
+
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN   (0x1 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE   BIT(30)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN   BIT(29)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(x)   ((x) << 24)
+
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4(0x0 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8(0x1 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16   (0x2 << 12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32   (0x3 << 12)
+
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16(0x2 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32(0x3 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64(0x4 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128   (0x5 << 29)
+
+#define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN   BIT(1)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_EN   BIT(0)
+
+#define IMX7D_REG_ADC_INT_CHA_COV_INT_EN   BIT(8)
+#define IMX7D_REG_A

[PATCH v4 2/4] Documentation: add the binding file for Freescale imx7d ADC driver

2015-12-01 Thread Haibo Chen
The patch adds the binding file for Freescale imx7d ADC driver.

Signed-off-by: Haibo Chen 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/iio/adc/imx7d-adc.txt  | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
new file mode 100644
index 000..5c184b9
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
@@ -0,0 +1,22 @@
+Freescale imx7d ADC bindings
+
+The devicetree bindings are for the ADC driver written for
+imx7d SoC.
+
+Required properties:
+- compatible: Should be "fsl,imx7d-adc"
+- reg: Offset and length of the register set for the ADC device
+- interrupts: The interrupt number for the ADC device
+- clocks: The root clock of the ADC controller
+- clock-names: Must contain "adc", matching entry in the clocks property
+- vref-supply: The regulator supply ADC reference voltage
+
+Example:
+adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   vref-supply = <®_vcc_3v3_mcu>;
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 0/4] Add i.mx7d adc driver support

2015-12-01 Thread Haibo Chen
This patch set add imx7d adc driver support.

Changes in v4:
-sort the include head file alphabetically
-really just clear the bit 31 of register REG_ADC_CH_A\B\C\D_CFG1 
 in function imx7d_adc_sample_rate_set()
-add document in imx7d_adc_isr() to clarify the clear operation
-add function imx7d_adc_power_down()
-adjust the format of the code and add some small changes

Changes in v3:
-move down the irq request in probe()
-remove the property 'num-channels' in dts
-remove some unused head file
-add clear register operation in imx7d_adc_isr()

Changes in v2:
-prefix defines with IMX7D_ for all the register
-use BIT macro to define a single bit
-remove the dma_en from struct adc_feature which is not support currently
-use static const array to replace the switch case code

Haibo Chen (4):
  iio: adc: add IMX7D ADC driver support
  Documentation: add the binding file for Freescale imx7d ADC driver
  ARM: dts: imx7d.dtsi: add ADC support
  ARM: dts: imx7d-sdb: add ADC support

 .../devicetree/bindings/iio/adc/imx7d-adc.txt  |  22 +
 arch/arm/boot/dts/imx7d-sdb.dts|  10 +
 arch/arm/boot/dts/imx7d.dtsi   |  18 +
 drivers/iio/adc/Kconfig|   9 +
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/imx7d_adc.c| 588 +
 6 files changed, 648 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
 create mode 100644 drivers/iio/adc/imx7d_adc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 3/4] ARM: dts: imx7d.dtsi: add ADC support

2015-12-01 Thread Haibo Chen
Add imx7d ADC support.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index ebc053a..aa0624d 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -583,6 +583,24 @@
reg = <0x3040 0x40>;
ranges;
 
+   adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
+   adc2: adc@3062 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3062 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
pwm1: pwm@3066 {
compatible = "fsl,imx7d-pwm", "fsl,imx27-pwm";
reg = <0x3066 0x1>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 4/4] ARM: dts: imx7d-sdb: add ADC support

2015-12-01 Thread Haibo Chen
Add ADC support for imx7d-sdb board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index 432aaf5..b2c4536 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -97,6 +97,16 @@
};
 };
 
+&adc1 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
+&adc2 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
 &cpu0 {
arm-supply = <&sw1a_reg>;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 1/6] mmc: sdhci-esdhc-imx: add imx7d support and support HS400

2015-08-05 Thread Haibo Chen
The imx7d usdhc is derived from imx6sx, the difference is that
imx7d support HS400.

So introduce a new compatible string for imx7d and add HS400
support for imx7d usdhc.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 81 ++
 1 file changed, 81 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index c6b9f64..48f009c 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -44,6 +44,7 @@
 #define  ESDHC_MIX_CTRL_EXE_TUNE   (1 << 22)
 #define  ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
 #define  ESDHC_MIX_CTRL_FBCLK_SEL  (1 << 25)
+#define  ESDHC_MIX_CTRL_HS400_EN   (1 << 26)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
 /* Tuning bits */
@@ -60,6 +61,16 @@
 #define  ESDHC_TUNE_CTRL_MIN   0
 #define  ESDHC_TUNE_CTRL_MAX   ((1 << 7) - 1)
 
+/* strobe dll register */
+#define ESDHC_STROBE_DLL_CTRL  0x70
+#define ESDHC_STROBE_DLL_CTRL_ENABLE   (1 << 0)
+#define ESDHC_STROBE_DLL_CTRL_RESET(1 << 1)
+#define ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT 3
+
+#define ESDHC_STROBE_DLL_STATUS0x74
+#define ESDHC_STROBE_DLL_STS_REF_LOCK  (1 << 1)
+#define ESDHC_STROBE_DLL_STS_SLV_LOCK  0x1
+
 #define ESDHC_TUNING_CTRL  0xcc
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
@@ -120,6 +131,11 @@
 #define ESDHC_FLAG_ERR004536   BIT(7)
 /* The IP supports HS200 mode */
 #define ESDHC_FLAG_HS200   BIT(8)
+/* The IP supports HS400 mode */
+#define ESDHC_FLAG_HS400   BIT(9)
+
+/* A higher clock ferquency than this rate requires strobell dll control */
+#define ESDHC_STROBE_DLL_CLK_FREQ  1
 
 struct esdhc_soc_data {
u32 flags;
@@ -156,6 +172,12 @@ static struct esdhc_soc_data usdhc_imx6sx_data = {
| ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200,
 };
 
+static struct esdhc_soc_data usdhc_imx7d_data = {
+   .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+   | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
+   | ESDHC_FLAG_HS400,
+};
+
 struct pltfm_imx_data {
u32 scratchpad;
struct pinctrl *pinctrl;
@@ -199,6 +221,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
{ .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
{ .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
{ .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
+   { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -274,6 +297,9 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
| SDHCI_SUPPORT_SDR50
| SDHCI_USE_SDR50_TUNING;
+
+   if (imx_data->socdata->flags & ESDHC_FLAG_HS400)
+   val |= SDHCI_SUPPORT_HS400;
}
}
 
@@ -774,6 +800,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
break;
case MMC_TIMING_UHS_SDR104:
case MMC_TIMING_MMC_HS200:
+   case MMC_TIMING_MMC_HS400:
pinctrl = imx_data->pins_200mhz;
break;
default:
@@ -784,6 +811,44 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
return pinctrl_select_state(imx_data->pinctrl, pinctrl);
 }
 
+/*
+ * For HS400 eMMC, there is a data_strobe line, this signal is generated
+ * by the device and used for data output and CRC status response output
+ * in HS400 mode. The frequency of this signal follows the frequency of
+ * CLK generated by host. Host receive the data which is aligned to the
+ * edge of data_strobe line. Due to the time delay between CLK line and
+ * data_strobe line, if the delay time is larger than one clock cycle,
+ * then CLK and data_strobe line will misaligned, read error shows up.
+ * So when the CLK is higher than 100MHz, each clock cycle is short enough,
+ * host should config the delay target.
+ */
+static void esdhc_set_strobe_dll(struct sdhci_host *host)
+{
+   u32 v;
+
+   if (host->mmc->actual_clock > ESDHC_STROBE_DLL_CLK_FREQ) {
+   /* force a reset on strobe dll */
+   writel(ESDHC_STROBE_DLL_CTRL_RESET,
+   host->ioaddr + ESDHC_STROBE_DLL_CTRL);
+   /*
+* enable strobe dll ctrl and adjust the delay target
+* for the uSDHC loopback read clock
+*/
+   v = ESDHC_

[PATCH v4 0/6] mmc: imx: a few fixes and new feature

2015-08-05 Thread Haibo Chen
Changes for v4:
-Call esdhc_set_strobe_dll() only when device clock is over 100MHz in HS400 
mode.
-Add detail description of tuning-step.
-Change to default watermark level and burst length for all imx SoC, not only 
imx7d.

Haibo Chen (6):
  mmc: sdhci-esdhc-imx: add imx7d support and support HS400
  mmc: sdhci-esdhc-imx: add tuning-step seting support
  mmc: sdhci-esdhc-imx: add compatible string in bingding doc
  ARM: dts: imx7d-sdb: add eMMC5.0 support
  mmc: sdhci-esdhc-imx: change default watermark level and burst length
  mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

 .../devicetree/bindings/mmc/fsl-imx-esdhc.txt  |   6 ++
 arch/arm/boot/dts/imx7d-sdb.dts|  13 +++
 drivers/mmc/host/sdhci-esdhc-imx.c | 109 -
 include/linux/platform_data/mmc-esdhc-imx.h|   1 +
 4 files changed, 128 insertions(+), 1 deletion(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 5/6] mmc: sdhci-esdhc-imx: change default watermark level and burst length

2015-08-05 Thread Haibo Chen
By default, for all imx SoC types, the watermark level is 16, and the
burst length is 8. But if the SDIO/SD/MMC I/O speed is fast enough,
this default watermark level and burst length will be the performance
bottleneck.

For example, i.MX7D support eMMC HS400 mode, this mode can run in 8 bit,
200MHZ DDR mode. So the I/O speed improve a lot compare to SD3.0.
The default burst length is 8, if we don't change this value, in
HS400 mode, when we do eMMC read operation, we can find that the
clock signal will stop for a period of time. This means the speed
of data moving on AHB bus is slower than I/O speed. So we should
improve the speed of data moving on AHB bus.

This patch set the default burst length as 16, and set the default
watermark level as 64. The test result is the clock signal has
no stop during the eMMC HS400 operation.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 803d24f..97aa944 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1160,7 +1160,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
 * to something insane.  Change it back here.
 */
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 3/6] mmc: sdhci-esdhc-imx: add compatible string in bingding doc

2015-08-05 Thread Haibo Chen
Add a required property "fsl,imx7d-usdhc" in binding doc.
Add an optional property "fsl,tuning-step" in binding doc.

Signed-off-by: Haibo Chen 
---
 Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 211e778..dca56d6 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -15,6 +15,7 @@ Required properties:
   "fsl,imx6q-usdhc"
   "fsl,imx6sl-usdhc"
   "fsl,imx6sx-usdhc"
+  "fsl,imx7d-usdhc"
 
 Optional properties:
 - fsl,wp-controller : Indicate to use controller internal write protection
@@ -27,6 +28,11 @@ Optional properties:
   transparent level shifters on the outputs of the controller. Two cells are
   required, first cell specifies minimum slot voltage (mV), second cell
   specifies maximum slot voltage (mV). Several ranges could be specified.
+- fsl,tuning-step: Specify the increasing delay cell steps in tuning procedure.
+  The uSDHC use one delay cell as default increasing step to do tuning process.
+  This property allows user to change the tuning step to more than one delay
+  cells which is useful for some special boards or cards when the default
+  tuning step can't find the proper delay window within limited tuning retries.
 
 Examples:
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 6/6] mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

2015-08-05 Thread Haibo Chen
Currently we find that if a usdhc is choosed to boot system, then ROM
code will set the burst length enable bit of this usdhc as 0.

This will make performance drop a lot if this usdhc's burst length is
configed. So this patch set back the burst_length_enable bit as 1,
which is the default value, and means burst length is enabled for INCR.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 97aa944..3334762 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
 #include "sdhci-esdhc.h"
 
 #defineESDHC_CTRL_D3CD 0x08
+#define ESDHC_BURST_LEN_EN_INCR(1 << 27)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC  0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
@@ -1165,6 +1166,21 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+   /*
+* ROM code will change the bit burst_length_enable setting
+* to zero if this usdhc is choosed to boot system. Change
+* it back here, otherwise it will impact the performance a
+* lot. This bit is used to enable/disable the burst length
+* for the external AHB2AXI bridge, it's usefully especially
+* for INCR transfer because without burst length indicator,
+* the AHB2AXI bridge does not know the burst length in
+* advance. And without burst length indicator, AHB INCR
+* transfer can only be converted to singles on the AXI side.
+*/
+   writel(readl(host->ioaddr + SDHCI_HOST_CONTROL)
+   | ESDHC_BURST_LEN_EN_INCR,
+   host->ioaddr + SDHCI_HOST_CONTROL);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 4/6] ARM: dts: imx7d-sdb: add eMMC5.0 support

2015-08-05 Thread Haibo Chen
imx7d-sdb board has a eMMC5.0 on usdhc3. This eMMC support HS400.
This patch add usdhc3 support for HS400

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index fdd1d7c..8059458 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -241,6 +241,19 @@
status = "okay";
 };
 
+&usdhc3 {
+   pinctrl-names = "default", "state_100mhz", "state_200mhz";
+   pinctrl-0 = <&pinctrl_usdhc3>;
+   pinctrl-1 = <&pinctrl_usdhc3_100mhz>;
+   pinctrl-2 = <&pinctrl_usdhc3_200mhz>;
+   assigned-clocks = <&clks IMX7D_USDHC3_ROOT_CLK>;
+   assigned-clock-rates = <4>;
+   bus-width = <8>;
+   fsl,tuning-step = <2>;
+   non-removable;
+   status = "okay";
+};
+
 &iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 2/6] mmc: sdhci-esdhc-imx: add tuning-step seting support

2015-08-05 Thread Haibo Chen
tuning-step is the delay cell steps in tuning procedure. The default value
of tuning-step is 1. Some boards or cards need another value to pass the
tuning procedure. For example, imx7d-sdb board need the tuning-step value
as 2, otherwise it can't pass the tuning procedure.

So this patch add the tuning-step setting in driver, so that user can set
the tuning-step value in dts.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c  | 9 +
 include/linux/platform_data/mmc-esdhc-imx.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 48f009c..803d24f 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -75,6 +75,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
 #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
@@ -474,6 +475,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
} else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+   u32 tuning_ctrl;
if (val & SDHCI_CTRL_TUNED_CLK) {
v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
} else {
@@ -484,6 +486,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
if (val & SDHCI_CTRL_EXEC_TUNING) {
v |= ESDHC_MIX_CTRL_EXE_TUNE;
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+   tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
+   tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
+   if (imx_data->boarddata.tuning_step)
+   tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
@@ -964,6 +971,8 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
if (gpio_is_valid(boarddata->wp_gpio))
boarddata->wp_type = ESDHC_WP_GPIO;
 
+   of_property_read_u32(np, "fsl,tuning-step", &boarddata->tuning_step);
+
if (of_find_property(np, "no-1-8-v", NULL))
boarddata->support_vsel = false;
else
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h 
b/include/linux/platform_data/mmc-esdhc-imx.h
index e1571ef..95ccab3 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -45,5 +45,6 @@ struct esdhc_platform_data {
int max_bus_width;
bool support_vsel;
unsigned int delay_line;
+   unsigned int tuning_step;   /* The delay cell steps in tuning 
procedure */
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 2/6] mmc: sdhci-esdhc-imx: add tuning-step seting support

2015-08-10 Thread Haibo Chen
tuning-step is the delay cell steps in tuning procedure. The default value
of tuning-step is 1. Some boards or cards need another value to pass the
tuning procedure. For example, imx7d-sdb board need the tuning-step value
as 2, otherwise it can't pass the tuning procedure.

So this patch add the tuning-step setting in driver, so that user can set
the tuning-step value in dts.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c  | 9 +
 include/linux/platform_data/mmc-esdhc-imx.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 2a816ad..03c9f33 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -75,6 +75,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
 #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
@@ -474,6 +475,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
} else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+   u32 tuning_ctrl;
if (val & SDHCI_CTRL_TUNED_CLK) {
v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
} else {
@@ -484,6 +486,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
if (val & SDHCI_CTRL_EXEC_TUNING) {
v |= ESDHC_MIX_CTRL_EXE_TUNE;
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+   tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
+   tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
+   if (imx_data->boarddata.tuning_step)
+   tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
@@ -965,6 +972,8 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
if (gpio_is_valid(boarddata->wp_gpio))
boarddata->wp_type = ESDHC_WP_GPIO;
 
+   of_property_read_u32(np, "fsl,tuning-step", &boarddata->tuning_step);
+
if (of_find_property(np, "no-1-8-v", NULL))
boarddata->support_vsel = false;
else
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h 
b/include/linux/platform_data/mmc-esdhc-imx.h
index e1571ef..95ccab3 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -45,5 +45,6 @@ struct esdhc_platform_data {
int max_bus_width;
bool support_vsel;
unsigned int delay_line;
+   unsigned int tuning_step;   /* The delay cell steps in tuning 
procedure */
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 4/6] ARM: dts: imx7d-sdb: add eMMC5.0 support

2015-08-10 Thread Haibo Chen
imx7d-sdb board has a eMMC5.0 on usdhc3. This eMMC support HS400.
This patch add usdhc3 support for HS400

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index fdd1d7c..8059458 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -241,6 +241,19 @@
status = "okay";
 };
 
+&usdhc3 {
+   pinctrl-names = "default", "state_100mhz", "state_200mhz";
+   pinctrl-0 = <&pinctrl_usdhc3>;
+   pinctrl-1 = <&pinctrl_usdhc3_100mhz>;
+   pinctrl-2 = <&pinctrl_usdhc3_200mhz>;
+   assigned-clocks = <&clks IMX7D_USDHC3_ROOT_CLK>;
+   assigned-clock-rates = <4>;
+   bus-width = <8>;
+   fsl,tuning-step = <2>;
+   non-removable;
+   status = "okay";
+};
+
 &iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 0/6] mmc: imx: a few fixes and new feature

2015-08-10 Thread Haibo Chen
Changes for v5:
-move the clear exist timing setting to a common place rather than only in 
HS200 mode.
-put the patch 6 ahead of patch 5.

Haibo Chen (6):
  mmc: sdhci-esdhc-imx: add imx7d support and support HS400
  mmc: sdhci-esdhc-imx: add tuning-step seting support
  mmc: sdhci-esdhc-imx: add compatible string in bingding doc
  ARM: dts: imx7d-sdb: add eMMC5.0 support
  mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1
  mmc: sdhci-esdhc-imx: change default watermark level and burst length

 .../devicetree/bindings/mmc/fsl-imx-esdhc.txt  |   6 ++
 arch/arm/boot/dts/imx7d-sdb.dts|  13 +++
 drivers/mmc/host/sdhci-esdhc-imx.c | 116 -
 include/linux/platform_data/mmc-esdhc-imx.h|   1 +
 4 files changed, 132 insertions(+), 4 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 5/6] mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

2015-08-10 Thread Haibo Chen
Currently we find that if a usdhc is choosed to boot system, then ROM
code will set the burst length enable bit of this usdhc as 0.

This will make performance drop a lot if this usdhc's burst length is
configed. So this patch set back the burst_length_enable bit as 1,
which is the default value, and means burst length is enabled for INCR.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 03c9f33..d7ec993 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
 #include "sdhci-esdhc.h"
 
 #defineESDHC_CTRL_D3CD 0x08
+#define ESDHC_BURST_LEN_EN_INCR(1 << 27)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC  0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
@@ -1165,6 +1166,21 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+   /*
+* ROM code will change the bit burst_length_enable setting
+* to zero if this usdhc is choosed to boot system. Change
+* it back here, otherwise it will impact the performance a
+* lot. This bit is used to enable/disable the burst length
+* for the external AHB2AXI bridge, it's usefully especially
+* for INCR transfer because without burst length indicator,
+* the AHB2AXI bridge does not know the burst length in
+* advance. And without burst length indicator, AHB INCR
+* transfer can only be converted to singles on the AXI side.
+*/
+   writel(readl(host->ioaddr + SDHCI_HOST_CONTROL)
+   | ESDHC_BURST_LEN_EN_INCR,
+   host->ioaddr + SDHCI_HOST_CONTROL);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 6/6] mmc: sdhci-esdhc-imx: change default watermark level and burst length

2015-08-10 Thread Haibo Chen
By default, for all imx SoC types, the watermark level is 16, and the
burst length is 8. But if the SDIO/SD/MMC I/O speed is fast enough,
this default watermark level and burst length will be the performance
bottleneck.

For example, i.MX7D support eMMC HS400 mode, this mode can run in 8 bit,
200MHZ DDR mode. So the I/O speed improve a lot compare to SD3.0.
The default burst length is 8, if we don't change this value, in
HS400 mode, when we do eMMC read operation, we can find that the
clock signal will stop for a period of time. This means the speed
of data moving on AHB bus is slower than I/O speed. So we should
improve the speed of data moving on AHB bus.

This patch set the default burst length as 16, and set the default
watermark level as 64. The test result is the clock signal has
no stop during the eMMC HS400 operation.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index d7ec993..1b31d36 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1162,7 +1162,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
 * to something insane.  Change it back here.
 */
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 3/6] mmc: sdhci-esdhc-imx: add compatible string in bingding doc

2015-08-10 Thread Haibo Chen
Add a required property "fsl,imx7d-usdhc" in binding doc.
Add an optional property "fsl,tuning-step" in binding doc.

Signed-off-by: Haibo Chen 
---
 Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 211e778..dca56d6 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -15,6 +15,7 @@ Required properties:
   "fsl,imx6q-usdhc"
   "fsl,imx6sl-usdhc"
   "fsl,imx6sx-usdhc"
+  "fsl,imx7d-usdhc"
 
 Optional properties:
 - fsl,wp-controller : Indicate to use controller internal write protection
@@ -27,6 +28,11 @@ Optional properties:
   transparent level shifters on the outputs of the controller. Two cells are
   required, first cell specifies minimum slot voltage (mV), second cell
   specifies maximum slot voltage (mV). Several ranges could be specified.
+- fsl,tuning-step: Specify the increasing delay cell steps in tuning procedure.
+  The uSDHC use one delay cell as default increasing step to do tuning process.
+  This property allows user to change the tuning step to more than one delay
+  cells which is useful for some special boards or cards when the default
+  tuning step can't find the proper delay window within limited tuning retries.
 
 Examples:
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/6] mmc: sdhci-esdhc-imx: add imx7d support and support HS400

2015-08-10 Thread Haibo Chen
The imx7d usdhc is derived from imx6sx, the difference is that
imx7d support HS400.

So introduce a new compatible string for imx7d and add HS400
support for imx7d usdhc.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 88 --
 1 file changed, 85 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index c6b9f64..2a816ad 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -44,6 +44,7 @@
 #define  ESDHC_MIX_CTRL_EXE_TUNE   (1 << 22)
 #define  ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
 #define  ESDHC_MIX_CTRL_FBCLK_SEL  (1 << 25)
+#define  ESDHC_MIX_CTRL_HS400_EN   (1 << 26)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
 /* Tuning bits */
@@ -60,6 +61,16 @@
 #define  ESDHC_TUNE_CTRL_MIN   0
 #define  ESDHC_TUNE_CTRL_MAX   ((1 << 7) - 1)
 
+/* strobe dll register */
+#define ESDHC_STROBE_DLL_CTRL  0x70
+#define ESDHC_STROBE_DLL_CTRL_ENABLE   (1 << 0)
+#define ESDHC_STROBE_DLL_CTRL_RESET(1 << 1)
+#define ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT 3
+
+#define ESDHC_STROBE_DLL_STATUS0x74
+#define ESDHC_STROBE_DLL_STS_REF_LOCK  (1 << 1)
+#define ESDHC_STROBE_DLL_STS_SLV_LOCK  0x1
+
 #define ESDHC_TUNING_CTRL  0xcc
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
@@ -120,6 +131,11 @@
 #define ESDHC_FLAG_ERR004536   BIT(7)
 /* The IP supports HS200 mode */
 #define ESDHC_FLAG_HS200   BIT(8)
+/* The IP supports HS400 mode */
+#define ESDHC_FLAG_HS400   BIT(9)
+
+/* A higher clock ferquency than this rate requires strobell dll control */
+#define ESDHC_STROBE_DLL_CLK_FREQ  1
 
 struct esdhc_soc_data {
u32 flags;
@@ -156,6 +172,12 @@ static struct esdhc_soc_data usdhc_imx6sx_data = {
| ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200,
 };
 
+static struct esdhc_soc_data usdhc_imx7d_data = {
+   .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+   | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
+   | ESDHC_FLAG_HS400,
+};
+
 struct pltfm_imx_data {
u32 scratchpad;
struct pinctrl *pinctrl;
@@ -199,6 +221,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
{ .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
{ .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
{ .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
+   { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -274,6 +297,9 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
| SDHCI_SUPPORT_SDR50
| SDHCI_USE_SDR50_TUNING;
+
+   if (imx_data->socdata->flags & ESDHC_FLAG_HS400)
+   val |= SDHCI_SUPPORT_HS400;
}
}
 
@@ -774,6 +800,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
break;
case MMC_TIMING_UHS_SDR104:
case MMC_TIMING_MMC_HS200:
+   case MMC_TIMING_MMC_HS400:
pinctrl = imx_data->pins_200mhz;
break;
default:
@@ -784,12 +811,57 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
return pinctrl_select_state(imx_data->pinctrl, pinctrl);
 }
 
+/*
+ * For HS400 eMMC, there is a data_strobe line, this signal is generated
+ * by the device and used for data output and CRC status response output
+ * in HS400 mode. The frequency of this signal follows the frequency of
+ * CLK generated by host. Host receive the data which is aligned to the
+ * edge of data_strobe line. Due to the time delay between CLK line and
+ * data_strobe line, if the delay time is larger than one clock cycle,
+ * then CLK and data_strobe line will misaligned, read error shows up.
+ * So when the CLK is higher than 100MHz, each clock cycle is short enough,
+ * host should config the delay target.
+ */
+static void esdhc_set_strobe_dll(struct sdhci_host *host)
+{
+   u32 v;
+
+   if (host->mmc->actual_clock > ESDHC_STROBE_DLL_CLK_FREQ) {
+   /* force a reset on strobe dll */
+   writel(ESDHC_STROBE_DLL_CTRL_RESET,
+   host->ioaddr + ESDHC_STROBE_DLL_CTRL);
+   /*
+* enable strobe dll ctrl and adjust the delay target
+* for the uSDHC loopback read clock
+*/
+   v 

[PATCH v6 6/6] mmc: sdhci-esdhc-imx: change default watermark level and burst length

2015-08-11 Thread Haibo Chen
By default, for all imx SoC types, the watermark level is 16, and the
burst length is 8. But if the SDIO/SD/MMC I/O speed is fast enough,
this default watermark level and burst length will be the performance
bottleneck.

For example, i.MX7D support eMMC HS400 mode, this mode can run in 8 bit,
200MHZ DDR mode. So the I/O speed improve a lot compare to SD3.0.
The default burst length is 8, if we don't change this value, in
HS400 mode, when we do eMMC read operation, we can find that the
clock signal will stop for a period of time. This means the speed
of data moving on AHB bus is slower than I/O speed. So we should
improve the speed of data moving on AHB bus.

This patch set the default burst length as 16, and set the default
watermark level as 64. The test result is the clock signal has
no stop during the eMMC HS400 operation.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index ac8ec01..886d230 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1160,7 +1160,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
 * to something insane.  Change it back here.
 */
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 5/6] mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

2015-08-11 Thread Haibo Chen
Currently we find that if a usdhc is choosed to boot system, then ROM
code will set the burst length enable bit of this usdhc as 0.

This will make performance drop a lot if this usdhc's burst length is
configed. So this patch set back the burst_length_enable bit as 1,
which is the default value, and means burst length is enabled for INCR.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 298551d..ac8ec01 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
 #include "sdhci-esdhc.h"
 
 #defineESDHC_CTRL_D3CD 0x08
+#define ESDHC_BURST_LEN_EN_INCR(1 << 27)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC  0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
@@ -1163,6 +1164,21 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+   /*
+* ROM code will change the bit burst_length_enable setting
+* to zero if this usdhc is choosed to boot system. Change
+* it back here, otherwise it will impact the performance a
+* lot. This bit is used to enable/disable the burst length
+* for the external AHB2AXI bridge, it's usefully especially
+* for INCR transfer because without burst length indicator,
+* the AHB2AXI bridge does not know the burst length in
+* advance. And without burst length indicator, AHB INCR
+* transfer can only be converted to singles on the AXI side.
+*/
+   writel(readl(host->ioaddr + SDHCI_HOST_CONTROL)
+   | ESDHC_BURST_LEN_EN_INCR,
+   host->ioaddr + SDHCI_HOST_CONTROL);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 0/6] mmc: imx: a few fixes and new feature

2015-08-11 Thread Haibo Chen
Changes for v6:
-remove duplicate code in esdhc_set_uhs_signaling().
-fix a typo for patch-2.
-make commit log of patch-3 more specific.

Haibo Chen (6):
  mmc: sdhci-esdhc-imx: add imx7d support and support HS400
  mmc: sdhci-esdhc-imx: add tuning-step setting support
  mmc: sdhci-esdhc-imx: add imx7d support in bingding doc
  ARM: dts: imx7d-sdb: add eMMC5.0 support
  mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1
  mmc: sdhci-esdhc-imx: change default watermark level and burst length

 .../devicetree/bindings/mmc/fsl-imx-esdhc.txt  |   6 ++
 arch/arm/boot/dts/imx7d-sdb.dts|  13 +++
 drivers/mmc/host/sdhci-esdhc-imx.c | 114 -
 include/linux/platform_data/mmc-esdhc-imx.h|   1 +
 4 files changed, 130 insertions(+), 4 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 4/6] ARM: dts: imx7d-sdb: add eMMC5.0 support

2015-08-11 Thread Haibo Chen
imx7d-sdb board has a eMMC5.0 on usdhc3. This eMMC support HS400.
This patch add usdhc3 support for HS400

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index fdd1d7c..8059458 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -241,6 +241,19 @@
status = "okay";
 };
 
+&usdhc3 {
+   pinctrl-names = "default", "state_100mhz", "state_200mhz";
+   pinctrl-0 = <&pinctrl_usdhc3>;
+   pinctrl-1 = <&pinctrl_usdhc3_100mhz>;
+   pinctrl-2 = <&pinctrl_usdhc3_200mhz>;
+   assigned-clocks = <&clks IMX7D_USDHC3_ROOT_CLK>;
+   assigned-clock-rates = <4>;
+   bus-width = <8>;
+   fsl,tuning-step = <2>;
+   non-removable;
+   status = "okay";
+};
+
 &iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 2/6] mmc: sdhci-esdhc-imx: add tuning-step setting support

2015-08-11 Thread Haibo Chen
tuning-step is the delay cell steps in tuning procedure. The default value
of tuning-step is 1. Some boards or cards need another value to pass the
tuning procedure. For example, imx7d-sdb board need the tuning-step value
as 2, otherwise it can't pass the tuning procedure.

So this patch add the tuning-step setting in driver, so that user can set
the tuning-step value in dts.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c  | 9 +
 include/linux/platform_data/mmc-esdhc-imx.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index b8b7e88..298551d 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -75,6 +75,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
 #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
@@ -474,6 +475,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
} else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+   u32 tuning_ctrl;
if (val & SDHCI_CTRL_TUNED_CLK) {
v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
} else {
@@ -484,6 +486,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
if (val & SDHCI_CTRL_EXEC_TUNING) {
v |= ESDHC_MIX_CTRL_EXE_TUNE;
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+   tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
+   tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
+   if (imx_data->boarddata.tuning_step)
+   tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
@@ -963,6 +970,8 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
if (gpio_is_valid(boarddata->wp_gpio))
boarddata->wp_type = ESDHC_WP_GPIO;
 
+   of_property_read_u32(np, "fsl,tuning-step", &boarddata->tuning_step);
+
if (of_find_property(np, "no-1-8-v", NULL))
boarddata->support_vsel = false;
else
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h 
b/include/linux/platform_data/mmc-esdhc-imx.h
index e1571ef..95ccab3 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -45,5 +45,6 @@ struct esdhc_platform_data {
int max_bus_width;
bool support_vsel;
unsigned int delay_line;
+   unsigned int tuning_step;   /* The delay cell steps in tuning 
procedure */
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 1/6] mmc: sdhci-esdhc-imx: add imx7d support and support HS400

2015-08-11 Thread Haibo Chen
The imx7d usdhc is derived from imx6sx, the difference is that
imx7d support HS400.

So introduce a new compatible string for imx7d and add HS400
support for imx7d usdhc.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 86 --
 1 file changed, 83 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index c6b9f64..b8b7e88 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -44,6 +44,7 @@
 #define  ESDHC_MIX_CTRL_EXE_TUNE   (1 << 22)
 #define  ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
 #define  ESDHC_MIX_CTRL_FBCLK_SEL  (1 << 25)
+#define  ESDHC_MIX_CTRL_HS400_EN   (1 << 26)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
 /* Tuning bits */
@@ -60,6 +61,16 @@
 #define  ESDHC_TUNE_CTRL_MIN   0
 #define  ESDHC_TUNE_CTRL_MAX   ((1 << 7) - 1)
 
+/* strobe dll register */
+#define ESDHC_STROBE_DLL_CTRL  0x70
+#define ESDHC_STROBE_DLL_CTRL_ENABLE   (1 << 0)
+#define ESDHC_STROBE_DLL_CTRL_RESET(1 << 1)
+#define ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT 3
+
+#define ESDHC_STROBE_DLL_STATUS0x74
+#define ESDHC_STROBE_DLL_STS_REF_LOCK  (1 << 1)
+#define ESDHC_STROBE_DLL_STS_SLV_LOCK  0x1
+
 #define ESDHC_TUNING_CTRL  0xcc
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
@@ -120,6 +131,11 @@
 #define ESDHC_FLAG_ERR004536   BIT(7)
 /* The IP supports HS200 mode */
 #define ESDHC_FLAG_HS200   BIT(8)
+/* The IP supports HS400 mode */
+#define ESDHC_FLAG_HS400   BIT(9)
+
+/* A higher clock ferquency than this rate requires strobell dll control */
+#define ESDHC_STROBE_DLL_CLK_FREQ  1
 
 struct esdhc_soc_data {
u32 flags;
@@ -156,6 +172,12 @@ static struct esdhc_soc_data usdhc_imx6sx_data = {
| ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200,
 };
 
+static struct esdhc_soc_data usdhc_imx7d_data = {
+   .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+   | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
+   | ESDHC_FLAG_HS400,
+};
+
 struct pltfm_imx_data {
u32 scratchpad;
struct pinctrl *pinctrl;
@@ -199,6 +221,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
{ .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
{ .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
{ .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
+   { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -274,6 +297,9 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
| SDHCI_SUPPORT_SDR50
| SDHCI_USE_SDR50_TUNING;
+
+   if (imx_data->socdata->flags & ESDHC_FLAG_HS400)
+   val |= SDHCI_SUPPORT_HS400;
}
}
 
@@ -774,6 +800,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
break;
case MMC_TIMING_UHS_SDR104:
case MMC_TIMING_MMC_HS200:
+   case MMC_TIMING_MMC_HS400:
pinctrl = imx_data->pins_200mhz;
break;
default:
@@ -784,24 +811,68 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
return pinctrl_select_state(imx_data->pinctrl, pinctrl);
 }
 
+/*
+ * For HS400 eMMC, there is a data_strobe line, this signal is generated
+ * by the device and used for data output and CRC status response output
+ * in HS400 mode. The frequency of this signal follows the frequency of
+ * CLK generated by host. Host receive the data which is aligned to the
+ * edge of data_strobe line. Due to the time delay between CLK line and
+ * data_strobe line, if the delay time is larger than one clock cycle,
+ * then CLK and data_strobe line will misaligned, read error shows up.
+ * So when the CLK is higher than 100MHz, each clock cycle is short enough,
+ * host should config the delay target.
+ */
+static void esdhc_set_strobe_dll(struct sdhci_host *host)
+{
+   u32 v;
+
+   if (host->mmc->actual_clock > ESDHC_STROBE_DLL_CLK_FREQ) {
+   /* force a reset on strobe dll */
+   writel(ESDHC_STROBE_DLL_CTRL_RESET,
+   host->ioaddr + ESDHC_STROBE_DLL_CTRL);
+   /*
+* enable strobe dll ctrl and adjust the delay target
+* for the uSDHC loopback read clock
+*/
+   v 

[PATCH v6 3/6] mmc: sdhci-esdhc-imx: add imx7d support in bingding doc

2015-08-11 Thread Haibo Chen
Add a required property "fsl,imx7d-usdhc" in binding doc.
Add an optional property "fsl,tuning-step" in binding doc.

Signed-off-by: Haibo Chen 
---
 Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 211e778..dca56d6 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -15,6 +15,7 @@ Required properties:
   "fsl,imx6q-usdhc"
   "fsl,imx6sl-usdhc"
   "fsl,imx6sx-usdhc"
+  "fsl,imx7d-usdhc"
 
 Optional properties:
 - fsl,wp-controller : Indicate to use controller internal write protection
@@ -27,6 +28,11 @@ Optional properties:
   transparent level shifters on the outputs of the controller. Two cells are
   required, first cell specifies minimum slot voltage (mV), second cell
   specifies maximum slot voltage (mV). Several ranges could be specified.
+- fsl,tuning-step: Specify the increasing delay cell steps in tuning procedure.
+  The uSDHC use one delay cell as default increasing step to do tuning process.
+  This property allows user to change the tuning step to more than one delay
+  cells which is useful for some special boards or cards when the default
+  tuning step can't find the proper delay window within limited tuning retries.
 
 Examples:
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 2/2] regulator: core: Ensure we are at least in bounds for our constraints

2016-03-30 Thread Haibo Chen
Hi Brown,

I also meet the similar issue on i.MX6 platforms.

With your patch   ---> regulator: core: Ensure we are at least in bounds for 
our constraints
When I insert an SD3.0 card, shows the following log:

root@imx6qdlsolo:~# [   59.733941] sdhci-esdhc-imx 219.usdhc: could not set 
regulator OCR (-22)
[   60.829911] sdhci-esdhc-imx 219.usdhc: could not set regulator OCR (-22)
[   61.917951] sdhci-esdhc-imx 219.usdhc: could not set regulator OCR (-22)
[   63.009498] sdhci-esdhc-imx 219.usdhc: could not set regulator OCR (-22)

I did a quick debug, and find when I change the operator   &&  to  !=  , this 
issue gone.
-   if (constraints->min_uV != constraints->max_uV) {
+   if (constraints->min_uV && constraints->max_uV) {


In our sdhci.c, we call the function 
regulator_set_voltage ---> regulator_set_voltage_unlocked(struct regulator 
*regulator, int min_uV, int max_uV)
here, the parameter min_uV is 330, and the max_uV is 340

currently with your patch (the upper operator is &&), when insert a SD3.0 card, 
it will do the sanity check, and return -EINVAL

but when I change the upper operator from && to !=, 
before the sanity check, it will first get the current_uV, and then go to out.

I'm not familiar with regulator common code. Hope the upper describe can help 
you debug this issue.

The following attach our dts piece code.

126 &usdhc1 {
127 pinctrl-names = "default", "state_100mhz", "state_200mhz";
128 pinctrl-0 = <&pinctrl_usdhc1>;
129 pinctrl-1 = <&pinctrl_usdhc1_100mhz>;
130 pinctrl-2 = <&pinctrl_usdhc1_200mhz>;
131 cd-gpios = <&gpio1 19 GPIO_ACTIVE_LOW>;
132 keep-power-in-suspend;
133 wakeup-source;
134 vmmc-supply = <®_sd1_vmmc>;
135 status = "okay";
136 };

regulators {
 26 compatible = "simple-bus";
 27 #address-cells = <1>;
 28 #size-cells = <0>;
 29
 30 reg_sd1_vmmc: sd1_regulator {
 31 compatible = "regulator-fixed";
 32 regulator-name = "VSD_3V3";
 33 regulator-min-microvolt = <330>;
 34 regulator-max-microvolt = <330>;
 35 gpio = <&gpio1 9 GPIO_ACTIVE_HIGH>;
 36 enable-active-high;
 37 };
 38 };

Best Regards
Haibo Chen



> -Original Message-
> From: linux-mmc-ow...@vger.kernel.org [mailto:linux-mmc-
> ow...@vger.kernel.org] On Behalf Of Mark Brown
> Sent: Wednesday, March 30, 2016 2:27 AM
> To: Geert Uytterhoeven 
> Cc: Bjorn Andersson ; Krzysztof Kozlowski
> ; Ivaylo Dimitrov ;
> Liam Girdwood ; linux-kernel@vger.kernel.org; Ulf
> Hansson ; linux-mmc ;
> linux-samsung-soc ; Javier Martinez
> Canillas ; Marek Szyprowski
> ; linux-renesas-...@vger.kernel.org
> Subject: Re: [PATCH 2/2] regulator: core: Ensure we are at least in bounds for
> our constraints
> 
> On Tue, Mar 29, 2016 at 08:05:34PM +0200, Geert Uytterhoeven wrote:
> 
> > sh_mobile_sdhi ee10.sd: Got WP GPIO ==> sh_mobile_sdhi
> > ee10.sd: could not set regulator OCR (-22)
> > gpio_rcar e6055400.gpio: sense irq = 6, type = 3
> > sh_mobile_sdhi ee10.sd: mmc0 base at 0xee10 clock rate
> > 97 MHz
> 
> > The line marked with the arrow is introduced by the changed check, and
> > looks to be the origin of the failure.
> 
> This isn't making any sense.  Why would a change in how we apply voltage
> constraints on initial probe of the regulator have an impact here?  The 
> changed
> code shouldn't even be executing at the point where the SDHCI driver is trying
> to use the regulator.  There's something else going on here.


[PATCH v3 4/4] ARM: dts: imx7d-sdb: add ADC support

2015-11-20 Thread Haibo Chen
Add ADC support for imx7d-sdb board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index 432aaf5..b2c4536 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -97,6 +97,16 @@
};
 };
 
+&adc1 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
+&adc2 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
 &cpu0 {
arm-supply = <&sw1a_reg>;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/4] Documentation: add the binding file for Freescale imx7d ADC driver

2015-11-20 Thread Haibo Chen
The patch adds the binding file for Freescale imx7d ADC driver.

Signed-off-by: Haibo Chen 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/iio/adc/imx7d-adc.txt  | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
new file mode 100644
index 000..5c184b9
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
@@ -0,0 +1,22 @@
+Freescale imx7d ADC bindings
+
+The devicetree bindings are for the ADC driver written for
+imx7d SoC.
+
+Required properties:
+- compatible: Should be "fsl,imx7d-adc"
+- reg: Offset and length of the register set for the ADC device
+- interrupts: The interrupt number for the ADC device
+- clocks: The root clock of the ADC controller
+- clock-names: Must contain "adc", matching entry in the clocks property
+- vref-supply: The regulator supply ADC reference voltage
+
+Example:
+adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   vref-supply = <®_vcc_3v3_mcu>;
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/4] Add i.mx7d adc driver support

2015-11-20 Thread Haibo Chen
This patch add imx7d adc driver support.

Changes in v3:
-move down the irq request in probe()
-remove the property 'num-channels' in dts
-remove some unused head file
-add clear register operation in imx7d_adc_isr()

Changes in V2:
-prefix defines with IMX7D_ for all the register
-use BIT macro to define a single bit
-remove the dma_en from struct adc_feature which is not support currently
-use static const array to replace the switch case code


*** BLURB HERE ***

Haibo Chen (4):
  iio: adc: add IMX7D ADC driver support
  Documentation: add the binding file for Freescale imx7d ADC driver
  ARM: dts: imx7d.dtsi: add ADC support
  ARM: dts: imx7d-sdb: add ADC support

 .../devicetree/bindings/iio/adc/imx7d-adc.txt  |  25 +
 arch/arm/boot/dts/imx7d-sdb.dts|  10 +
 arch/arm/boot/dts/imx7d.dtsi   |  18 +
 drivers/iio/adc/Kconfig|   9 +
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/imx7d_adc.c| 570 +
 6 files changed, 633 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
 create mode 100644 drivers/iio/adc/imx7d_adc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/4] iio: adc: add IMX7D ADC driver support

2015-11-20 Thread Haibo Chen
Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
driver support, and the driver only support ADC software trigger.

Signed-off-by: Haibo Chen 
---
 drivers/iio/adc/Kconfig |   9 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/imx7d_adc.c | 570 
 3 files changed, 580 insertions(+)
 create mode 100644 drivers/iio/adc/imx7d_adc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c74..bf0611c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -194,6 +194,15 @@ config HI8435
  This driver can also be built as a module. If so, the module will be
  called hi8435.
 
+config IMX7D_ADC
+   tristate "IMX7D ADC driver"
+   depends on OF
+   help
+ Say yes here to build support for IMX7D ADC.
+
+ This driver can also be built as a module. If so, the module will be
+ called imx7d_adc.
+
 config LP8788_ADC
tristate "LP8788 ADC driver"
depends on MFD_LP8788
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a9..282ffc01 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_HI8435) += hi8435.o
+obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
new file mode 100644
index 000..d9547bf
--- /dev/null
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -0,0 +1,570 @@
+/*
+ * Freescale i.MX7D ADC driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* ADC register */
+#define IMX7D_REG_ADC_CH_A_CFG10x00
+#define IMX7D_REG_ADC_CH_A_CFG20x10
+#define IMX7D_REG_ADC_CH_B_CFG10x20
+#define IMX7D_REG_ADC_CH_B_CFG20x30
+#define IMX7D_REG_ADC_CH_C_CFG10x40
+#define IMX7D_REG_ADC_CH_C_CFG20x50
+#define IMX7D_REG_ADC_CH_D_CFG10x60
+#define IMX7D_REG_ADC_CH_D_CFG20x70
+#define IMX7D_REG_ADC_CH_SW_CFG0x80
+#define IMX7D_REG_ADC_TIMER_UNIT   0x90
+#define IMX7D_REG_ADC_DMA_FIFO 0xa0
+#define IMX7D_REG_ADC_FIFO_STATUS  0xb0
+#define IMX7D_REG_ADC_INT_SIG_EN   0xc0
+#define IMX7D_REG_ADC_INT_EN   0xd0
+#define IMX7D_REG_ADC_INT_STATUS   0xe0
+#define IMX7D_REG_ADC_CHA_B_CNV_RSLT   0xf0
+#define IMX7D_REG_ADC_CHC_D_CNV_RSLT   0x100
+#define IMX7D_REG_ADC_CH_SW_CNV_RSLT   0x110
+#define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120
+#define IMX7D_REG_ADC_ADC_CFG  0x130
+
+#define IMX7D_EACH_CHANNEL_REG_SHIF0x20
+
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN   (0x1 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_DISABLE  (0x0 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE   BIT(30)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN   BIT(29)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL_SHIF 24
+
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4(0x0 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8(0x1 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16   (0x2 << 12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32   (0x3 << 12)
+
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16(0x2 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32(0x3 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64(0x4 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128   (0x5 << 29)
+
+#define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN   BIT(1)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_EN   BIT(0)
+
+#define IMX7D_REG_ADC_INT_CHA_COV_INT_EN   BIT(8)
+#define IMX7D_REG_A

[PATCH v3 3/4] ARM: dts: imx7d.dtsi: add ADC support

2015-11-20 Thread Haibo Chen
Add imx7d ADC support.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index ebc053a..aa0624d 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -583,6 +583,24 @@
reg = <0x3040 0x40>;
ranges;
 
+   adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
+   adc2: adc@3062 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3062 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
pwm1: pwm@3066 {
compatible = "fsl,imx7d-pwm", "fsl,imx27-pwm";
reg = <0x3066 0x1>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 14/21] mmc: sdhci-esdhc-imx: remove SDHCI_QUIRK_BROKEN_CARD_DETECTION

2016-01-26 Thread Haibo Chen
Hi Shawn, 

Comments below.



> -Original Message-
> From: Shawn Lin [mailto:shawn@rock-chips.com]
> Sent: Wednesday, January 27, 2016 1:09 PM
> To: Ulf Hansson 
> Cc: bcm-kernel-feedback-l...@broadcom.com; linux-rpi-
> ker...@lists.infradead.org; linux-...@vger.kernel.org; linux-
> ker...@vger.kernel.org; Shawn Lin ; Dong
> Aisheng ; Haibo Chen
> 
> Subject: [RFC PATCH 14/21] mmc: sdhci-esdhc-imx: remove
> SDHCI_QUIRK_BROKEN_CARD_DETECTION
> 
> sdhci_esdhc_imx_pdata need SDHCI_QUIRK_BROKEN_CARD_DETECTION,
> so we replace it with MMC_CAP_NEEDS_POLL while probing. For other cases,
> we directly remove SDHCI_QUIRK_BROKEN_CARD_DETECTION.
> 
> Cc: Dong Aisheng 
> Cc: Haibo Chen 
> Signed-off-by: Shawn Lin 
> ---
> 
>  drivers/mmc/host/sdhci-esdhc-imx.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-
> esdhc-imx.c
> index f25f292..5705be1 100644
> --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> @@ -952,8 +952,7 @@ static struct sdhci_ops sdhci_esdhc_ops = {  static const
> struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
>   .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
>   | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
> - | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
> - | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
> + | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC,
>   .ops = &sdhci_esdhc_ops,
>  };
> 
> @@ -1012,7 +1011,7 @@ sdhci_esdhc_imx_probe_dt(struct platform_device
> *pdev,
>   return ret;
> 
>   if (!IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc)))
> - host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
> + host->mmc->caps &= MMC_CAP_NEEDS_POLL;

You miss ' ~', seems you need to change to:
host->mmc->caps &=~ MMC_CAP_NEEDS_POLL;

> 
>   return 0;
>  }
> @@ -1064,7 +1063,7 @@ static int sdhci_esdhc_imx_probe_nondt(struct
> platform_device *pdev,
> 
>   case ESDHC_CD_CONTROLLER:
>   /* we have a working card_detect back */
> - host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
> + host->mmc->caps &= MMC_CAP_NEEDS_POLL;

The same issue.

>   break;
> 
>   case ESDHC_CD_PERMANENT:
> @@ -1104,6 +1103,8 @@ static int sdhci_esdhc_imx_probe(struct
> platform_device *pdev)
>   if (IS_ERR(host))
>   return PTR_ERR(host);
> 
> + host->mmc->caps |= MMC_CAP_NEEDS_POLL;
> +
>   pltfm_host = sdhci_priv(host);
> 
>   imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data),
> GFP_KERNEL);
> --
> 2.3.7
> 



RE: [RFC PATCH 10/21] mmc: sdhci: remove SDHCI_QUIRK_BROKEN_CARD_DETECTION

2016-01-26 Thread Haibo Chen


Hi Shawn,


> -Original Message-
> From: linux-mmc-ow...@vger.kernel.org [mailto:linux-mmc-
> ow...@vger.kernel.org] On Behalf Of Shawn Lin
> Sent: Wednesday, January 27, 2016 1:08 PM
> To: Ulf Hansson 
> Cc: bcm-kernel-feedback-l...@broadcom.com; linux-rpi-
> ker...@lists.infradead.org; linux-...@vger.kernel.org; linux-
> ker...@vger.kernel.org; Shawn Lin 
> Subject: [RFC PATCH 10/21] mmc: sdhci: remove
> SDHCI_QUIRK_BROKEN_CARD_DETECTION
> 
> SDHCI_QUIRK_BROKEN_CARD_DETECTION is for "broken-cd".
> If we add MMC_CAP_NONREMOVABLE("non-removeble"), we shoud not add
> "broken-cd" together according to mmc.txt for dt-bingdings. Also, "broken-cd"
> can obtain from mmc_of_parse, which will add MMC_CAP_NEEDS_POLL into
> mmc->caps.
> 
> Signed-off-by: Shawn Lin 
> ---
> 
>  drivers/mmc/host/sdhci.c | 14 +-
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index
> d622435..b208cb7 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -145,7 +145,7 @@ static void sdhci_set_card_detection(struct sdhci_host
> *host, bool enable)  {
>   u32 present;
> 
> - if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
> + if ((host->mmc->caps & MMC_CAP_NEEDS_POLL) ||
>   (host->mmc->caps & MMC_CAP_NONREMOVABLE))
>   return;
> 
> @@ -1618,7 +1618,8 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
>   return 0;
> 
>   /* If nonremovable, assume that the card is always present. */
> - if (host->mmc->caps & MMC_CAP_NONREMOVABLE)
> + if (host->mmc->caps & MMC_CAP_NONREMOVABLE ||
> + host->mmc->caps & MMC_CAP_NEEDS_POLL)
>   return 1;
> 
>   /*
> @@ -1628,10 +1629,6 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
>   if (!IS_ERR_VALUE(gpio_cd))
>   return !!gpio_cd;
> 
> - /* If polling, assume that the card is always present. */
> - if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
> - return 1;

Why simply  remove these code rather than use this:
If(host->mmc->caps & MMC_CAP_NEEDS_POLL)
   Return 1;

According to the comment, if polling, need to return 1,
But if you just simply remove this code, it will read the sdhci register 
SDHCI_PRESENT_STATE


Best Regards

Haibo Chen

> -
>   /* Host native card detect */
>   return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
> SDHCI_CARD_PRESENT);  } @@ -2658,7 +2655,7 @@ void
> sdhci_enable_irq_wakeups(struct sdhci_host *host)
>   val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL);
>   val |= mask ;
>   /* Avoid fake wake up */
> - if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
> + if (host->mmc->caps & MMC_CAP_NEEDS_POLL)
>   val &= ~(SDHCI_WAKE_ON_INSERT |
> SDHCI_WAKE_ON_REMOVE);
>   sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL);  } @@ -3112,8
> +3109,7 @@ int sdhci_add_host(struct sdhci_host *host)
>   if (caps[0] & SDHCI_CAN_DO_HISPD)
>   mmc->caps |= MMC_CAP_SD_HIGHSPEED |
> MMC_CAP_MMC_HIGHSPEED;
> 
> - if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
> - !(mmc->caps & MMC_CAP_NONREMOVABLE) &&
> + if (!(mmc->caps & MMC_CAP_NONREMOVABLE) &&
>   IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc)))
>   mmc->caps |= MMC_CAP_NEEDS_POLL;
> 
> --
> 2.3.7
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/4] iio: adc: add IMX7D ADC driver support

2015-12-08 Thread Haibo Chen
Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
driver support, and the driver only support ADC software trigger.

Signed-off-by: Haibo Chen 
---
 drivers/iio/adc/Kconfig |   9 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/imx7d_adc.c | 589 
 3 files changed, 599 insertions(+)
 create mode 100644 drivers/iio/adc/imx7d_adc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c74..3493a46 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -194,6 +194,15 @@ config HI8435
  This driver can also be built as a module. If so, the module will be
  called hi8435.
 
+config IMX7D_ADC
+   tristate "IMX7D ADC driver"
+   depends on ARCH_MXC || COMPILE_TEST
+   help
+ Say yes here to build support for IMX7D ADC.
+
+ This driver can also be built as a module. If so, the module will be
+ called imx7d_adc.
+
 config LP8788_ADC
tristate "LP8788 ADC driver"
depends on MFD_LP8788
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a9..282ffc01 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_HI8435) += hi8435.o
+obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
new file mode 100644
index 000..d3511b9
--- /dev/null
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -0,0 +1,589 @@
+/*
+ * Freescale i.MX7D ADC driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* ADC register */
+#define IMX7D_REG_ADC_CH_A_CFG10x00
+#define IMX7D_REG_ADC_CH_A_CFG20x10
+#define IMX7D_REG_ADC_CH_B_CFG10x20
+#define IMX7D_REG_ADC_CH_B_CFG20x30
+#define IMX7D_REG_ADC_CH_C_CFG10x40
+#define IMX7D_REG_ADC_CH_C_CFG20x50
+#define IMX7D_REG_ADC_CH_D_CFG10x60
+#define IMX7D_REG_ADC_CH_D_CFG20x70
+#define IMX7D_REG_ADC_CH_SW_CFG0x80
+#define IMX7D_REG_ADC_TIMER_UNIT   0x90
+#define IMX7D_REG_ADC_DMA_FIFO 0xa0
+#define IMX7D_REG_ADC_FIFO_STATUS  0xb0
+#define IMX7D_REG_ADC_INT_SIG_EN   0xc0
+#define IMX7D_REG_ADC_INT_EN   0xd0
+#define IMX7D_REG_ADC_INT_STATUS   0xe0
+#define IMX7D_REG_ADC_CHA_B_CNV_RSLT   0xf0
+#define IMX7D_REG_ADC_CHC_D_CNV_RSLT   0x100
+#define IMX7D_REG_ADC_CH_SW_CNV_RSLT   0x110
+#define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120
+#define IMX7D_REG_ADC_ADC_CFG  0x130
+
+#define IMX7D_REG_ADC_CHANNEL_CFG2_BASE0x10
+#define IMX7D_EACH_CHANNEL_REG_OFFSET  0x20
+
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN   (0x1 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE   BIT(30)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN   BIT(29)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(x)   ((x) << 24)
+
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4(0x0 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8(0x1 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16   (0x2 << 12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32   (0x3 << 12)
+
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16(0x2 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32(0x3 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64(0x4 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128   (0x5 << 29)
+
+#define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN   BIT(1)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_EN   BIT(0)
+
+#define IMX7D_REG_ADC_INT_CHA_COV_INT_EN   BIT(8)
+#define IMX7D_REG_A

[PATCH v5 0/4] Add i.mx7d adc driver support

2015-12-08 Thread Haibo Chen
This patch set add imx7d adc driver support.

Changes in v5:
-call imx7d_adc_power_down() in driver probe when iio_device_register() failed
-handle with adc channel conversion timeout in imx7d_adc_isr()

Changes in v4:
-sort the include head file alphabetically
-really just clear the bit 31 of register REG_ADC_CH_A\B\C\D_CFG1 
 in function imx7d_adc_sample_rate_set()
-add document in imx7d_adc_isr() to clarify the clear operation
-add function imx7d_adc_power_down()
-adjust the format of the code and add some small changes

Changes in v3:
-move down the irq request in probe()
-remove the property 'num-channels' in dts
-remove some unused head file
-add clear register operation in imx7d_adc_isr()

Changes in v2:
-prefix defines with IMX7D_ for all the register
-use BIT macro to define a single bit
-remove the dma_en from struct adc_feature which is not support currently
-use static const array to replace the switch case code

Haibo Chen (4):
  iio: adc: add IMX7D ADC driver support
  Documentation: add the binding file for Freescale imx7d ADC driver
  ARM: dts: imx7d.dtsi: add ADC support
  ARM: dts: imx7d-sdb: add ADC support

 .../devicetree/bindings/iio/adc/imx7d-adc.txt  |  22 +
 arch/arm/boot/dts/imx7d-sdb.dts|  10 +
 arch/arm/boot/dts/imx7d.dtsi   |  18 +
 drivers/iio/adc/Kconfig|   9 +
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/imx7d_adc.c| 589 +
 6 files changed, 649 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
 create mode 100644 drivers/iio/adc/imx7d_adc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 4/4] ARM: dts: imx7d-sdb: add ADC support

2015-12-08 Thread Haibo Chen
Add ADC support for imx7d-sdb board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index 432aaf5..b2c4536 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -97,6 +97,16 @@
};
 };
 
+&adc1 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
+&adc2 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
 &cpu0 {
arm-supply = <&sw1a_reg>;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 3/4] ARM: dts: imx7d.dtsi: add ADC support

2015-12-08 Thread Haibo Chen
Add imx7d ADC support.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index ebc053a..aa0624d 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -583,6 +583,24 @@
reg = <0x3040 0x40>;
ranges;
 
+   adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
+   adc2: adc@3062 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3062 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
pwm1: pwm@3066 {
compatible = "fsl,imx7d-pwm", "fsl,imx27-pwm";
reg = <0x3066 0x1>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 2/4] Documentation: add the binding file for Freescale imx7d ADC driver

2015-12-08 Thread Haibo Chen
The patch adds the binding file for Freescale imx7d ADC driver.

Signed-off-by: Haibo Chen 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/iio/adc/imx7d-adc.txt  | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
new file mode 100644
index 000..5c184b9
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
@@ -0,0 +1,22 @@
+Freescale imx7d ADC bindings
+
+The devicetree bindings are for the ADC driver written for
+imx7d SoC.
+
+Required properties:
+- compatible: Should be "fsl,imx7d-adc"
+- reg: Offset and length of the register set for the ADC device
+- interrupts: The interrupt number for the ADC device
+- clocks: The root clock of the ADC controller
+- clock-names: Must contain "adc", matching entry in the clocks property
+- vref-supply: The regulator supply ADC reference voltage
+
+Example:
+adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   vref-supply = <®_vcc_3v3_mcu>;
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/4] Add i.mx7d adc driver support

2015-11-09 Thread Haibo Chen
This patch add imx7d adc driver support.

Changes in V2:
-prefix defines with IMX7D_ for all the register
-use BIT macro to define a single bit
-remove the dma_en from struct adc_feature which is not support currently
-use static const array to replace the switch case code

Haibo Chen (4):
  iio: adc: add IMX7D ADC driver support
  Documentation: add the binding file for Freescale imx7d ADC driver
  ARM: dts: imx7d.dtsi: add ADC support
  ARM: dts: imx7d-sdb: add ADC support

 .../devicetree/bindings/iio/adc/imx7d-adc.txt  |  26 +
 arch/arm/boot/dts/imx7d-sdb.dts|  10 +
 arch/arm/boot/dts/imx7d.dtsi   |  20 +
 drivers/iio/adc/Kconfig|   9 +
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/imx7d_adc.c| 571 +
 6 files changed, 637 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
 create mode 100644 drivers/iio/adc/imx7d_adc.c

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/4] iio: adc: add IMX7D ADC driver support

2015-11-09 Thread Haibo Chen
Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC
driver support, and the driver only support ADC software trigger.

Signed-off-by: Haibo Chen 
---
 drivers/iio/adc/Kconfig |   9 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/imx7d_adc.c | 571 
 3 files changed, 581 insertions(+)
 create mode 100644 drivers/iio/adc/imx7d_adc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c74..bf0611c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -194,6 +194,15 @@ config HI8435
  This driver can also be built as a module. If so, the module will be
  called hi8435.
 
+config IMX7D_ADC
+   tristate "IMX7D ADC driver"
+   depends on OF
+   help
+ Say yes here to build support for IMX7D ADC.
+
+ This driver can also be built as a module. If so, the module will be
+ called imx7d_adc.
+
 config LP8788_ADC
tristate "LP8788 ADC driver"
depends on MFD_LP8788
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a9..282ffc01 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_HI8435) += hi8435.o
+obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
new file mode 100644
index 000..7e25e4e
--- /dev/null
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -0,0 +1,571 @@
+/*
+ * Freescale i.MX7D ADC driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* This will be the driver name the kernel reports */
+#define DRIVER_NAME "imx7d_adc"
+
+/* ADC register */
+#define IMX7D_REG_ADC_CH_A_CFG10x00
+#define IMX7D_REG_ADC_CH_A_CFG20x10
+#define IMX7D_REG_ADC_CH_B_CFG10x20
+#define IMX7D_REG_ADC_CH_B_CFG20x30
+#define IMX7D_REG_ADC_CH_C_CFG10x40
+#define IMX7D_REG_ADC_CH_C_CFG20x50
+#define IMX7D_REG_ADC_CH_D_CFG10x60
+#define IMX7D_REG_ADC_CH_D_CFG20x70
+#define IMX7D_REG_ADC_CH_SW_CFG0x80
+#define IMX7D_REG_ADC_TIMER_UNIT   0x90
+#define IMX7D_REG_ADC_DMA_FIFO 0xa0
+#define IMX7D_REG_ADC_FIFO_STATUS  0xb0
+#define IMX7D_REG_ADC_INT_SIG_EN   0xc0
+#define IMX7D_REG_ADC_INT_EN   0xd0
+#define IMX7D_REG_ADC_INT_STATUS   0xe0
+#define IMX7D_REG_ADC_CHA_B_CNV_RSLT   0xf0
+#define IMX7D_REG_ADC_CHC_D_CNV_RSLT   0x100
+#define IMX7D_REG_ADC_CH_SW_CNV_RSLT   0x110
+#define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120
+#define IMX7D_REG_ADC_ADC_CFG  0x130
+
+#define IMX7D_EACH_CHANNEL_REG_SHIF0x20
+
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN   (0x1 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_DISABLE  (0x0 << 31)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE   BIT(30)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN   BIT(29)
+#define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL_SHIF 24
+
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4(0x0 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8(0x1 << 
12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16   (0x2 << 12)
+#define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32   (0x3 << 12)
+
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16(0x2 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32(0x3 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64(0x4 << 29)
+#define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128   (0x5 << 29)
+
+#define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31)
+#define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN   BIT(1)
+#define IMX

[PATCH v2 4/4] ARM: dts: imx7d-sdb: add ADC support

2015-11-09 Thread Haibo Chen
Add ADC support for imx7d-sdb board.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d-sdb.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-sdb.dts b/arch/arm/boot/dts/imx7d-sdb.dts
index 432aaf5..b2c4536 100644
--- a/arch/arm/boot/dts/imx7d-sdb.dts
+++ b/arch/arm/boot/dts/imx7d-sdb.dts
@@ -97,6 +97,16 @@
};
 };
 
+&adc1 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
+&adc2 {
+   vref-supply = <®_vref_1v8>;
+   status = "okay";
+};
+
 &cpu0 {
arm-supply = <&sw1a_reg>;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/4] Documentation: add the binding file for Freescale imx7d ADC driver

2015-11-09 Thread Haibo Chen
The patch adds the binding file for Freescale imx7d ADC driver.

Signed-off-by: Haibo Chen 
---
 .../devicetree/bindings/iio/adc/imx7d-adc.txt  | 26 ++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt 
b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
new file mode 100644
index 000..7f4ec1b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/imx7d-adc.txt
@@ -0,0 +1,26 @@
+Freescale imx7d ADC bindings
+
+The devicetree bindings are for the ADC driver written for
+imx7d SoC.
+
+Required properties:
+- compatible: Should be "fsl,imx7d-adc"
+- reg: Offset and length of the register set for the ADC device
+- interrupts: The interrupt number for the ADC device
+- clocks: The root clock of the ADC controller
+- clock-names: Must contain "adc", matching entry in the clocks property
+- vref-supply: The regulator supply ADC reference voltage
+
+Optional properties:
+- num-channels: the number of channels used
+
+Example:
+adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   clock-names = "adc";
+   num-channels = <4>;
+   vref-supply = <®_vcc_3v3_mcu>;
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/4] ARM: dts: imx7d.dtsi: add ADC support

2015-11-09 Thread Haibo Chen
Add imx7d ADC support.

Signed-off-by: Haibo Chen 
---
 arch/arm/boot/dts/imx7d.dtsi | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index ebc053a..87c3319 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -583,6 +583,26 @@
reg = <0x3040 0x40>;
ranges;
 
+   adc1: adc@3061 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3061 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   num-channels = <4>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
+   adc2: adc@3062 {
+   compatible = "fsl,imx7d-adc";
+   reg = <0x3062 0x1>;
+   interrupts = ;
+   clocks = <&clks IMX7D_ADC_ROOT_CLK>;
+   num-channels = <4>;
+   clock-names = "adc";
+   status = "disabled";
+   };
+
pwm1: pwm@3066 {
compatible = "fsl,imx7d-pwm", "fsl,imx27-pwm";
reg = <0x3066 0x1>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] mmc: sdhci-esdhc-imx: correct the tuning-step setting

2015-11-10 Thread Haibo Chen
Here we use '|=' to set the tuning-step, but before that, we should
clear the tuning-step, otherwise we could got the wrong setting.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 1508949..64275c7 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -76,6 +76,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_MASK 0x0007
 #define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
@@ -489,9 +490,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
-   if (imx_data->boarddata.tuning_step)
+   if (imx_data->boarddata.tuning_step) {
+   tuning_ctrl &= ~ESDHC_TUNING_STEP_MASK;
tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
-   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
+   }
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] mmc: sdhci-esdhc-imx: move the setting of watermark level out of probe

2015-11-10 Thread Haibo Chen
Currently, we config the watermark_level register only in probe.
This will cause the mmc write operation timeout issue after system
resume back in LPSR mode. Because in LPSR mode, after system resume
back, the watermark_level register(0x44) changes to 0x08000880, which
set the write watermark level as 0, and set the read watermark level
as 128. This value is incorrect.

This patch move the setting of watermark level register out of probe,
so after system resume back, mmc driver can set this watermark level
register back to 0x10401040.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 1f1582f..1508949 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -584,6 +584,14 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 
val, int reg)
mask = 0x & ~(ESDHC_CTRL_BUSWIDTH_MASK | ESDHC_CTRL_D3CD);
 
esdhc_clrset_le(host, mask, new_val, reg);
+
+   /*
+* The imx6q/imx7d ROM code will change the default watermark
+* level setting to something insane.  Change it back here.
+*/
+if (esdhc_is_usdhc(imx_data))
+writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+
return;
}
esdhc_clrset_le(host, 0xff, val, reg);
@@ -1155,13 +1163,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
| SDHCI_QUIRK_BROKEN_ADMA;
 
-   /*
-* The imx6q ROM code will change the default watermark level setting
-* to something insane.  Change it back here.
-*/
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
-
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mmc: sdhci: call sdhci_init() before request irq

2015-09-15 Thread Haibo Chen
sdhci_init() will clear all irqs and set the needed irqs. So
logically sdhci_init() should be called before request irq.

If not, some irqs may be triggled and handled wrongly. Take
the following into consideration, after request irq, if
SDIO card interrupt enabled, a sd card in the sd slot will
trigger a mass of interrupt(SDHCI_INT_CARD_INT), because at
this time, the vmmc-regulator still not restore, no voltage
supply for the sd card, so the pin of data0~data3 change and
keep low, interrupt(SDHCI_INT_CARD_INT) will rise up ceaselessly.
Due to we already reguest irq, system will be busy in handling
this endless irq, can't response to other event.

So we should call sdhci_init() before request irq in sd resume.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 64b7fdb..6861573 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -2714,17 +2714,6 @@ int sdhci_resume_host(struct sdhci_host *host)
host->ops->enable_dma(host);
}
 
-   if (!device_may_wakeup(mmc_dev(host->mmc))) {
-   ret = request_threaded_irq(host->irq, sdhci_irq,
-  sdhci_thread_irq, IRQF_SHARED,
-  mmc_hostname(host->mmc), host);
-   if (ret)
-   return ret;
-   } else {
-   sdhci_disable_irq_wakeups(host);
-   disable_irq_wake(host->irq);
-   }
-
if ((host->mmc->pm_flags & MMC_PM_KEEP_POWER) &&
(host->quirks2 & SDHCI_QUIRK2_HOST_OFF_CARD_ON)) {
/* Card keeps power but host controller does not */
@@ -2737,6 +2726,17 @@ int sdhci_resume_host(struct sdhci_host *host)
mmiowb();
}
 
+   if (!device_may_wakeup(mmc_dev(host->mmc))) {
+   ret = request_threaded_irq(host->irq, sdhci_irq,
+  sdhci_thread_irq, IRQF_SHARED,
+  mmc_hostname(host->mmc), host);
+   if (ret)
+   return ret;
+   } else {
+   sdhci_disable_irq_wakeups(host);
+   disable_irq_wake(host->irq);
+   }
+
sdhci_enable_card_detection(host);
 
return ret;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mmc: sdhci: disable irq in sdhci host suspend ranther than free this irq

2016-01-28 Thread Haibo Chen
Currently sdhci driver free irq in host suspend, and call
request_threaded_irq() in host resume. But during host resume,
Ctrl+C can impact sdhci host resume, see the error log:

CPU1 is up
PM: noirq resume of devices complete after 0.637 msecs imx-sdma 30bd.sdma: 
loaded firmware 4.1
PM: early resume of devices complete after 0.774 msecs
dpm_run_callback(): platform_pm_resume+0x0/0x44 returns -4
PM: Device 30b4.usdhc failed to resume: error -4
dpm_run_callback(): platform_pm_resume+0x0/0x44 returns -4
PM: Device 30b5.usdhc failed to resume: error -4
dpm_run_callback(): platform_pm_resume+0x0/0x44 returns -4
PM: Device 30b6.usdhc failed to resume: error -4 fec 30be.ethernet 
eth0: Link is Up - 100Mbps/Full - flow control rx/tx
mmc0: Timeout waiting for hardware interrupt.
mmc0: Timeout waiting for hardware interrupt.
mmc0: Timeout waiting for hardware interrupt.
mmc0: Timeout waiting for hardware interrupt.
mmc0: Timeout waiting for hardware interrupt.
mmc0: Timeout waiting for hardware interrupt.
mmc0: error -110 during resume (card was removed?)
mmc2: Timeout waiting for hardware interrupt.
mmc2: Timeout waiting for hardware interrupt.
mmc2: error -110 during resume (card was removed?)

In request_threaded_irq-> __setup_irq-> kthread_create
->kthread_create_on_node, the comment shows that SIGKILLed will
impact the kthread create, and return -EINTR.

This patch replace them with disable|enable_irq(), that will prevent
IRQs from being propagated to the sdhci driver.

Fixes: 781e989cf593 ("mmc: sdhci: convert to new SDIO IRQ handling")
Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index d622435..4b1646b 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -2686,7 +2686,7 @@ int sdhci_suspend_host(struct sdhci_host *host)
host->ier = 0;
sdhci_writel(host, 0, SDHCI_INT_ENABLE);
sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
-   free_irq(host->irq, host);
+   disable_irq(host->irq);
} else {
sdhci_enable_irq_wakeups(host);
enable_irq_wake(host->irq);
@@ -2698,8 +2698,6 @@ EXPORT_SYMBOL_GPL(sdhci_suspend_host);
 
 int sdhci_resume_host(struct sdhci_host *host)
 {
-   int ret = 0;
-
if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
if (host->ops->enable_dma)
host->ops->enable_dma(host);
@@ -2718,11 +2716,7 @@ int sdhci_resume_host(struct sdhci_host *host)
}
 
if (!device_may_wakeup(mmc_dev(host->mmc))) {
-   ret = request_threaded_irq(host->irq, sdhci_irq,
-  sdhci_thread_irq, IRQF_SHARED,
-  mmc_hostname(host->mmc), host);
-   if (ret)
-   return ret;
+   enable_irq(host->irq);
} else {
sdhci_disable_irq_wakeups(host);
disable_irq_wake(host->irq);
@@ -2730,7 +2724,7 @@ int sdhci_resume_host(struct sdhci_host *host)
 
sdhci_enable_card_detection(host);
 
-   return ret;
+   return 0;
 }
 
 EXPORT_SYMBOL_GPL(sdhci_resume_host);
-- 
1.9.1



[PATCH v2 0/4] mmc: imx: a few fixes and add a new feature

2015-06-23 Thread Haibo Chen
Patch 1 add imx7d support, and also add HS400 mode support.
Patch 2 add tuning-step, which can be get from dts.
Patch 3 and Patch 4 do some small fixes.

Haibo Chen (4):
  mmc: sdhci-esdhc-imx: add imx7d support and support HS400
  mmc: sdhci-esdhc-imx: add tuning-step seting support
  mmc: sdhci-esdhc-imx: config watermark level and burst length
  mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

 drivers/mmc/host/sdhci-esdhc-imx.c  | 97 -
 include/linux/platform_data/mmc-esdhc-imx.h |  1 +
 2 files changed, 97 insertions(+), 1 deletion(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/4] mmc: sdhci-esdhc-imx: add imx7d support and support HS400

2015-06-23 Thread Haibo Chen
The imx7d usdhc is derived from imx6sx, the difference is that
imx7d support HS400.

So introduce a new compatible string for imx7d and add HS400
support for imx7d usdhc.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 66 ++
 1 file changed, 66 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index faf0cb9..763b928 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -44,6 +44,7 @@
 #define  ESDHC_MIX_CTRL_EXE_TUNE   (1 << 22)
 #define  ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
 #define  ESDHC_MIX_CTRL_FBCLK_SEL  (1 << 25)
+#define  ESDHC_MIX_CTRL_HS400_EN   (1 << 26)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
 /* Tuning bits */
@@ -60,6 +61,16 @@
 #define  ESDHC_TUNE_CTRL_MIN   0
 #define  ESDHC_TUNE_CTRL_MAX   ((1 << 7) - 1)
 
+/* strobe dll register */
+#define ESDHC_STROBE_DLL_CTRL  0x70
+#define ESDHC_STROBE_DLL_CTRL_ENABLE   (1 << 0)
+#define ESDHC_STROBE_DLL_CTRL_RESET(1 << 1)
+#define ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT 3
+
+#define ESDHC_STROBE_DLL_STATUS0x74
+#define ESDHC_STROBE_DLL_STS_REF_LOCK  (1 << 1)
+#define ESDHC_STROBE_DLL_STS_SLV_LOCK  0x1
+
 #define ESDHC_TUNING_CTRL  0xcc
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
@@ -120,6 +131,8 @@
 #define ESDHC_FLAG_ERR004536   BIT(7)
 /* The IP supports HS200 mode */
 #define ESDHC_FLAG_HS200   BIT(8)
+/* The IP supports HS400 mode */
+#define ESDHC_FLAG_SUP_HS400   BIT(9)
 
 struct esdhc_soc_data {
u32 flags;
@@ -156,6 +169,12 @@ static struct esdhc_soc_data usdhc_imx6sx_data = {
| ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200,
 };
 
+static struct esdhc_soc_data usdhc_imx7d_data = {
+   .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+   | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
+   | ESDHC_FLAG_SUP_HS400,
+};
+
 struct pltfm_imx_data {
u32 scratchpad;
struct pinctrl *pinctrl;
@@ -199,6 +218,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
{ .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
{ .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
{ .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
+   { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -274,6 +294,10 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
| SDHCI_SUPPORT_SDR50
| SDHCI_USE_SDR50_TUNING;
+
+   /* imx7d does not have a support_hs400 register, fake 
one */
+   if (imx_data->socdata->flags & ESDHC_FLAG_SUP_HS400)
+   val |= SDHCI_SUPPORT_HS400;
}
}
 
@@ -779,6 +803,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
break;
case MMC_TIMING_UHS_SDR104:
case MMC_TIMING_MMC_HS200:
+   case MMC_TIMING_MMC_HS400:
pinctrl = imx_data->pins_200mhz;
break;
default:
@@ -789,6 +814,30 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
return pinctrl_select_state(imx_data->pinctrl, pinctrl);
 }
 
+static void esdhc_set_strobe_dll(struct sdhci_host *host)
+{
+   u32 v;
+
+   /* force a reset on strobe dll */
+   writel(ESDHC_STROBE_DLL_CTRL_RESET, host->ioaddr + 
ESDHC_STROBE_DLL_CTRL);
+   /*
+* enable strobe dll ctrl and adjust the delay target
+* for the uSDHC loopback read clock
+*/
+   v = ESDHC_STROBE_DLL_CTRL_ENABLE |
+   (7 << ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
+   writel(v, host->ioaddr + ESDHC_STROBE_DLL_CTRL);
+   /* wait 1us to make sure strobe dll status register stable */
+   udelay(1);
+   v = readl(host->ioaddr + ESDHC_STROBE_DLL_STATUS);
+   if (!(v & ESDHC_STROBE_DLL_STS_REF_LOCK))
+   dev_warn(mmc_dev(host->mmc),
+   "warning! HS400 strobe DLL status REF not lock!\n");
+   if (!(v & ESDHC_STROBE_DLL_STS_SLV_LOCK))
+   dev_warn(mmc_dev(host->mmc),
+   "warning! HS400 strobe DLL status SLV not lock!\n");
+}
+
 static void esdhc_set_uhs_signaling(struct sdhci_host *host, unsigned timing)
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(

[PATCH v2 4/4] mmc: sdhci-esdhc-imx: set back the burst_length_enable bit to 1

2015-06-23 Thread Haibo Chen
Currently we find that if a usdhc is choosed to boot system, then ROM
code will set the burst length enable bit of this usdhc as 0.

This will make performance drop a lot if this usdhc's burst length is
16. So this patch set back the burst_length_enable bit as 1, which is
the default value, and means burst length is enabled for INCR.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 1f0e0d9..e6a1995 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
 #include "sdhci-esdhc.h"
 
 #defineESDHC_CTRL_D3CD 0x08
+#define ESDHC_BURST_LEN_EN_INCR(1 << 27)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC  0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
@@ -1088,6 +1089,16 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+   /*
+* ROM code will change the burst_length_enable setting to
+* zero if this usdhc is choosed to boot system. Change it
+* back here, otherwise it will impact the performance a
+* lot if the burst length is 16.
+*/
+   writel(readl(host->ioaddr + SDHCI_HOST_CONTROL)
+   | ESDHC_BURST_LEN_EN_INCR,
+   host->ioaddr + SDHCI_HOST_CONTROL);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/4] mmc: sdhci-esdhc-imx: add tuning-step seting support

2015-06-23 Thread Haibo Chen
tuning-step is the delay cell steps in tuning procedure. The default value
of tuning-step is 1. For imx6 series usdhc, tuning procedure can be passed
when the tuning-step value is 1. But imx7d usdhc need the tuning-step value
as 2, otherwise it can't pass the tuning procedure.

This patch add the tuning-step setting in driver, so that user can set the
tuning-step value in dts.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c  | 9 +
 include/linux/platform_data/mmc-esdhc-imx.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 763b928..f7ec66e 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -75,6 +75,7 @@
 #define ESDHC_STD_TUNING_EN(1 << 24)
 /* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
 #define ESDHC_TUNING_START_TAP 0x1
+#define ESDHC_TUNING_STEP_SHIFT16
 
 /* pinctrl state */
 #define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
@@ -472,6 +473,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
} else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+   u32 tuning_ctrl;
if (val & SDHCI_CTRL_TUNED_CLK) {
v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
} else {
@@ -482,6 +484,11 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 
val, int reg)
if (val & SDHCI_CTRL_EXEC_TUNING) {
v |= ESDHC_MIX_CTRL_EXE_TUNE;
m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+   tuning_ctrl = readl(host->ioaddr + 
ESDHC_TUNING_CTRL);
+   tuning_ctrl |= ESDHC_STD_TUNING_EN | 
ESDHC_TUNING_START_TAP;
+   if (imx_data->boarddata.tuning_step)
+   tuning_ctrl |= 
imx_data->boarddata.tuning_step << ESDHC_TUNING_STEP_SHIFT;
+   writel(tuning_ctrl, host->ioaddr + 
ESDHC_TUNING_CTRL);
} else {
v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
}
@@ -969,6 +976,8 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
 
of_property_read_u32(np, "max-frequency", &boarddata->f_max);
 
+   of_property_read_u32(np, "tuning-step", &boarddata->tuning_step);
+
if (of_find_property(np, "no-1-8-v", NULL))
boarddata->support_vsel = false;
else
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h 
b/include/linux/platform_data/mmc-esdhc-imx.h
index 75f70f6..cedbf8e 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -46,5 +46,6 @@ struct esdhc_platform_data {
unsigned int f_max;
bool support_vsel;
unsigned int delay_line;
+   unsigned int tuning_step;   /* The delay cell steps in tuning 
procedure */
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/4] mmc: sdhci-esdhc-imx: config watermark level and burst length

2015-06-23 Thread Haibo Chen
i.MX7D support eMMC HS400 mode, this mode can run in 8 bit,200MHZ
DDR mode. So the I/O speed improve a lot compare to SD3.0

The default burst length is 8, if we don't change this value, in
HS400 mode, when we do eMMC read operation, we can find that the
clock signal will stop for a period of time. This means the speed
of data moving on AHB bus is slower than I/O speed. So we should
improve the speed of data moving on AHB bus.

For imx7d usdhc, this patch set the burst length as 16, and set
watermark level as 64. The test result is the clock signal has
no stop during the eMMC HS400 operation. For other imx usdhc, remain
the default value: burst length as 8, watermark level as 16.

Signed-off-by: Haibo Chen 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index f7ec66e..1f0e0d9 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -239,6 +239,11 @@ static inline int is_imx6q_usdhc(struct pltfm_imx_data 
*data)
return data->socdata == &usdhc_imx6q_data;
 }
 
+static inline int is_imx7d_usdhc(struct pltfm_imx_data *data)
+{
+   return data->socdata == &usdhc_imx7d_data;
+}
+
 static inline int esdhc_is_usdhc(struct pltfm_imx_data *data)
 {
return !!(data->socdata->flags & ESDHC_FLAG_USDHC);
@@ -1075,7 +1080,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device 
*pdev)
 * to something insane.  Change it back here.
 */
if (esdhc_is_usdhc(imx_data)) {
-   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+   if (is_imx7d_usdhc(imx_data))
+   writel(0x10401040, host->ioaddr + ESDHC_WTMK_LVL);
+   else
+   writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/