2015-08-12 05:58:55

by Wang Dongsheng

[permalink] [raw]
Subject: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers

From: Wang Dongsheng <[email protected]>

Some Freescale device drivers need to move to soc/, because these
drivers are specific drivers. Before the soc/ to be created, the
drivers had been there arch/ or drivers/misc/, but now soc/ dir
is a better choice.

Signed-off-by: Wang Dongsheng <[email protected]>
---
*V2*
Rebase for last kernel. Resend this patch, this patch is one year ago.
Sorry I haven't had the time to push this patch before.

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 96ddecb..b5c5179 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -5,5 +5,6 @@ source "drivers/soc/qcom/Kconfig"
source "drivers/soc/sunxi/Kconfig"
source "drivers/soc/ti/Kconfig"
source "drivers/soc/versatile/Kconfig"
+source "drivers/soc/fsl/Kconfig"

endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 7dc7c0d..1caf1d6 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_ARCH_SUNXI) += sunxi/
obj-$(CONFIG_ARCH_TEGRA) += tegra/
obj-$(CONFIG_SOC_TI) += ti/
obj-$(CONFIG_PLAT_VERSATILE) += versatile/
+obj-$(CONFIG_FSL_SOC_DRIVERS) += fsl/
diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
new file mode 100644
index 0000000..863d1ef
--- /dev/null
+++ b/drivers/soc/fsl/Kconfig
@@ -0,0 +1,18 @@
+#
+# Freescale SOC drivers
+#
+menuconfig FSL_SOC_DRIVERS
+ bool "Freescale Soc Drivers"
+ default n
+ help
+ Say y here to enable Freescale Soc Device Drivers support.
+ The Soc Drivers provides the device driver that is a specific
+ block or feature on Freescale platform.
+
+if FSL_SOC_DRIVERS
+
+if ARM
+source "drivers/soc/fsl/Kconfig.arm"
+endif
+
+endif
diff --git a/drivers/soc/fsl/Kconfig.arm b/drivers/soc/fsl/Kconfig.arm
new file mode 100644
index 0000000..8c90b82
--- /dev/null
+++ b/drivers/soc/fsl/Kconfig.arm
@@ -0,0 +1,16 @@
+#
+# Freescale ARM SOC Drivers
+#
+
+config LS1_SOC_DRIVERS
+ bool "LS1021A Soc Drivers"
+ depends on SOC_LS1021A
+ default n
+ help
+ Say y here to enable Freescale LS1021A Soc Device Drivers support.
+ The Soc Drivers provides the device driver that is a specific block
+ or feature on LS1021A platform.
+
+if LS1_SOC_DRIVERS
+ source "drivers/soc/fsl/ls1/Kconfig"
+endif
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
new file mode 100644
index 0000000..b4215dd
--- /dev/null
+++ b/drivers/soc/fsl/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for Freescale Soc specific device drivers.
+#
+
+obj-$(CONFIG_LS1_SOC_DRIVERS) += ls1/
+
diff --git a/drivers/soc/fsl/ls1/Kconfig b/drivers/soc/fsl/ls1/Kconfig
new file mode 100644
index 0000000..7556f44
--- /dev/null
+++ b/drivers/soc/fsl/ls1/Kconfig
@@ -0,0 +1,3 @@
+#
+# LS-1 Soc drivers
+#
--
2.1.0.27.g96db324


2015-08-12 05:59:00

by Wang Dongsheng

[permalink] [raw]
Subject: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform

From: Wang Dongsheng <[email protected]>

Only Ftm0 can be used when system going to deep sleep. So this driver
to support ftm0 as a wakeup source.

Signed-off-by: Wang Dongsheng <[email protected]>
---
*V2*
Change Copyright 2014 to 2015.

diff --git a/drivers/soc/fsl/ls1/Kconfig b/drivers/soc/fsl/ls1/Kconfig
index 7556f44..e6282dc 100644
--- a/drivers/soc/fsl/ls1/Kconfig
+++ b/drivers/soc/fsl/ls1/Kconfig
@@ -1,3 +1,11 @@
#
# LS-1 Soc drivers
#
+config FTM_ALARM
+ bool "FTM alarm driver"
+ depends on SOC_LS1021A
+ default n
+ help
+ Say y here to enable FTM alarm support. The FTM alarm provides
+ alarm functions for wakeup system from deep sleep. There is only
+ one FTM can be used in ALARM(FTM 0).
diff --git a/drivers/soc/fsl/ls1/Makefile b/drivers/soc/fsl/ls1/Makefile
new file mode 100644
index 0000000..6299aa1
--- /dev/null
+++ b/drivers/soc/fsl/ls1/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_FTM_ALARM) += ftm_alarm.o
diff --git a/drivers/soc/fsl/ls1/ftm_alarm.c b/drivers/soc/fsl/ls1/ftm_alarm.c
new file mode 100644
index 0000000..f7629cd
--- /dev/null
+++ b/drivers/soc/fsl/ls1/ftm_alarm.c
@@ -0,0 +1,272 @@
+/*
+ * Freescale FlexTimer Module (FTM) Alarm driver.
+ *
+ * Copyright 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 <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+
+#define FTM_SC 0x00
+#define FTM_SC_CLK_SHIFT 3
+#define FTM_SC_CLK_MASK (0x3 << FTM_SC_CLK_SHIFT)
+#define FTM_SC_CLK(c) ((c) << FTM_SC_CLK_SHIFT)
+#define FTM_SC_PS_MASK 0x7
+#define FTM_SC_TOIE BIT(6)
+#define FTM_SC_TOF BIT(7)
+
+#define FTM_SC_CLKS_FIXED_FREQ 0x02
+
+#define FTM_CNT 0x04
+#define FTM_MOD 0x08
+#define FTM_CNTIN 0x4C
+
+#define FIXED_FREQ_CLK 32000
+#define MAX_FREQ_DIV (1 << FTM_SC_PS_MASK)
+#define MAX_COUNT_VAL 0xffff
+
+static void __iomem *ftm1_base;
+static u32 alarm_freq;
+static bool big_endian;
+
+static inline u32 ftm_readl(void __iomem *addr)
+{
+ if (big_endian)
+ return ioread32be(addr);
+
+ return ioread32(addr);
+}
+
+static inline void ftm_writel(u32 val, void __iomem *addr)
+{
+ if (big_endian)
+ iowrite32be(val, addr);
+ else
+ iowrite32(val, addr);
+}
+
+static inline void ftm_counter_enable(void __iomem *base)
+{
+ u32 val;
+
+ /* select and enable counter clock source */
+ val = ftm_readl(base + FTM_SC);
+ val &= ~(FTM_SC_PS_MASK | FTM_SC_CLK_MASK);
+ val |= (FTM_SC_PS_MASK | FTM_SC_CLK(FTM_SC_CLKS_FIXED_FREQ));
+ ftm_writel(val, base + FTM_SC);
+}
+
+static inline void ftm_counter_disable(void __iomem *base)
+{
+ u32 val;
+
+ /* disable counter clock source */
+ val = ftm_readl(base + FTM_SC);
+ val &= ~(FTM_SC_PS_MASK | FTM_SC_CLK_MASK);
+ ftm_writel(val, base + FTM_SC);
+}
+
+static inline void ftm_irq_acknowledge(void __iomem *base)
+{
+ u32 val;
+
+ val = ftm_readl(base + FTM_SC);
+ val &= ~FTM_SC_TOF;
+ ftm_writel(val, base + FTM_SC);
+}
+
+static inline void ftm_irq_enable(void __iomem *base)
+{
+ u32 val;
+
+ val = ftm_readl(base + FTM_SC);
+ val |= FTM_SC_TOIE;
+ ftm_writel(val, base + FTM_SC);
+}
+
+static inline void ftm_irq_disable(void __iomem *base)
+{
+ u32 val;
+
+ val = ftm_readl(base + FTM_SC);
+ val &= ~FTM_SC_TOIE;
+ ftm_writel(val, base + FTM_SC);
+}
+
+static inline void ftm_reset_counter(void __iomem *base)
+{
+ /*
+ * The CNT register contains the FTM counter value.
+ * Reset clears the CNT register. Writing any value to COUNT
+ * updates the counter with its initial value, CNTIN.
+ */
+ ftm_writel(0x00, base + FTM_CNT);
+}
+
+static u32 time_to_cycle(unsigned long time)
+{
+ u32 cycle;
+
+ cycle = time * alarm_freq;
+ if (cycle > MAX_COUNT_VAL) {
+ pr_err("Out of alarm range.\n");
+ cycle = 0;
+ }
+
+ return cycle;
+}
+
+static u32 cycle_to_time(u32 cycle)
+{
+ return cycle / alarm_freq + 1;
+}
+
+static void ftm_clean_alarm(void)
+{
+ ftm_counter_disable(ftm1_base);
+
+ ftm_writel(0x00, ftm1_base + FTM_CNTIN);
+ ftm_writel(~0UL, ftm1_base + FTM_MOD);
+
+ ftm_reset_counter(ftm1_base);
+}
+
+static int ftm_set_alarm(u64 cycle)
+{
+ ftm_irq_disable(ftm1_base);
+
+ /*
+ * The counter increments until the value of MOD is reached,
+ * at which point the counter is reloaded with the value of CNTIN.
+ * The TOF (the overflow flag) bit is set when the FTM counter
+ * changes from MOD to CNTIN. So we should using the cycle - 1.
+ */
+ ftm_writel(cycle - 1, ftm1_base + FTM_MOD);
+
+ ftm_counter_enable(ftm1_base);
+
+ ftm_irq_enable(ftm1_base);
+
+ return 0;
+}
+
+static irqreturn_t ftm_alarm_interrupt(int irq, void *dev_id)
+{
+ ftm_irq_acknowledge(ftm1_base);
+ ftm_irq_disable(ftm1_base);
+ ftm_clean_alarm();
+
+ return IRQ_HANDLED;
+}
+
+static ssize_t ftm_alarm_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ u32 count, val;
+
+ count = ftm_readl(ftm1_base + FTM_MOD);
+ val = ftm_readl(ftm1_base + FTM_CNT);
+ val = (count & MAX_COUNT_VAL) - val;
+ val = cycle_to_time(val);
+
+ return sprintf(buf, "%u\n", val);
+}
+
+static ssize_t ftm_alarm_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ u32 cycle;
+ unsigned long time;
+
+ if (kstrtoul(buf, 0, &time))
+ return -EINVAL;
+
+ ftm_clean_alarm();
+
+ cycle = time_to_cycle(time);
+ if (!cycle)
+ return -EINVAL;
+
+ ftm_set_alarm(cycle);
+
+ return count;
+}
+
+static struct device_attribute ftm_alarm_attributes = __ATTR(ftm_alarm, 0644,
+ ftm_alarm_show, ftm_alarm_store);
+
+static int ftm_alarm_probe(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct resource *r;
+ int irq;
+ int ret;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r)
+ return -ENODEV;
+
+ ftm1_base = devm_ioremap_resource(&pdev->dev, r);
+ if (IS_ERR(ftm1_base))
+ return PTR_ERR(ftm1_base);
+
+ irq = irq_of_parse_and_map(np, 0);
+ if (irq <= 0) {
+ pr_err("ftm: unable to get IRQ from DT, %d\n", irq);
+ return -EINVAL;
+ }
+
+ big_endian = of_property_read_bool(np, "big-endian");
+
+ ret = devm_request_irq(&pdev->dev, irq, ftm_alarm_interrupt,
+ IRQF_NO_SUSPEND, dev_name(&pdev->dev), NULL);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "failed to request irq\n");
+ return ret;
+ }
+
+ ret = device_create_file(&pdev->dev, &ftm_alarm_attributes);
+ if (ret) {
+ dev_err(&pdev->dev, "create sysfs fail.\n");
+ return ret;
+ }
+
+ alarm_freq = (u32)FIXED_FREQ_CLK / (u32)MAX_FREQ_DIV;
+
+ ftm_clean_alarm();
+
+ return ret;
+}
+
+static const struct of_device_id ftm_alarm_match[] = {
+ { .compatible = "fsl,ftm-alarm", },
+ { .compatible = "fsl,ftm-timer", },
+ { },
+};
+
+static struct platform_driver ftm_alarm_driver = {
+ .probe = ftm_alarm_probe,
+ .driver = {
+ .name = "ftm-alarm",
+ .owner = THIS_MODULE,
+ .of_match_table = ftm_alarm_match,
+ },
+};
+
+static int __init ftm_alarm_init(void)
+{
+ return platform_driver_register(&ftm_alarm_driver);
+}
+device_initcall(ftm_alarm_init);
--
2.1.0.27.g96db324

2015-08-12 07:44:53

by Russell King - ARM Linux

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers

On Wed, Aug 12, 2015 at 01:53:26PM +0800, Dongsheng Wang wrote:
> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
> new file mode 100644
> index 0000000..863d1ef
> --- /dev/null
> +++ b/drivers/soc/fsl/Kconfig
> @@ -0,0 +1,18 @@
> +#
> +# Freescale SOC drivers
> +#
> +menuconfig FSL_SOC_DRIVERS
> + bool "Freescale Soc Drivers"
> + default n

No need for default n.

> diff --git a/drivers/soc/fsl/Kconfig.arm b/drivers/soc/fsl/Kconfig.arm
> new file mode 100644
> index 0000000..8c90b82
> --- /dev/null
> +++ b/drivers/soc/fsl/Kconfig.arm
> @@ -0,0 +1,16 @@
> +#
> +# Freescale ARM SOC Drivers
> +#
> +
> +config LS1_SOC_DRIVERS
> + bool "LS1021A Soc Drivers"
> + depends on SOC_LS1021A
> + default n

Ditto.

> + help
> + Say y here to enable Freescale LS1021A Soc Device Drivers support.
> + The Soc Drivers provides the device driver that is a specific block
> + or feature on LS1021A platform.

Help text should be indented by two spaces as per almost every other
help text.

> +
> +if LS1_SOC_DRIVERS
> + source "drivers/soc/fsl/ls1/Kconfig"
> +endif
> diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
> new file mode 100644
> index 0000000..b4215dd
> --- /dev/null
> +++ b/drivers/soc/fsl/Makefile
> @@ -0,0 +1,6 @@
> +#
> +# Makefile for Freescale Soc specific device drivers.
> +#
> +
> +obj-$(CONFIG_LS1_SOC_DRIVERS) += ls1/
> +
> diff --git a/drivers/soc/fsl/ls1/Kconfig b/drivers/soc/fsl/ls1/Kconfig
> new file mode 100644
> index 0000000..7556f44
> --- /dev/null
> +++ b/drivers/soc/fsl/ls1/Kconfig
> @@ -0,0 +1,3 @@
> +#
> +# LS-1 Soc drivers
> +#

Doesn't this directory need a Makefile as well?

--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

2015-08-12 08:01:37

by Wang Dongsheng

[permalink] [raw]
Subject: RE: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers

Hi Russell,

Thanks for your review. :)

> -----Original Message-----
> From: Russell King - ARM Linux [mailto:[email protected]]
> Sent: Wednesday, August 12, 2015 3:45 PM
> To: Wang Dongsheng-B40534
> Cc: [email protected]; Wang Huan-B18965; [email protected]; linux-
> [email protected]; [email protected]; [email protected]; linux-arm-
> [email protected]
> Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers
>
> On Wed, Aug 12, 2015 at 01:53:26PM +0800, Dongsheng Wang wrote:
> > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig new
> > file mode 100644 index 0000000..863d1ef
> > --- /dev/null
> > +++ b/drivers/soc/fsl/Kconfig
> > @@ -0,0 +1,18 @@
> > +#
> > +# Freescale SOC drivers
> > +#
> > +menuconfig FSL_SOC_DRIVERS
> > + bool "Freescale Soc Drivers"
> > + default n
>
> No need for default n.

Thanks. Fix it in next version.

> > + help
> > + Say y here to enable Freescale LS1021A Soc Device Drivers support.
> > + The Soc Drivers provides the device driver that is a specific block
> > + or feature on LS1021A platform.
>
> Help text should be indented by two spaces as per almost every other help text.
>

Thanks. My mistake...

> > +
> > +if LS1_SOC_DRIVERS
> > + source "drivers/soc/fsl/ls1/Kconfig"
> > +endif
> > diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile new
> > file mode 100644 index 0000000..b4215dd
> > --- /dev/null
> > +++ b/drivers/soc/fsl/Makefile
> > @@ -0,0 +1,6 @@
> > +#
> > +# Makefile for Freescale Soc specific device drivers.
> > +#
> > +
> > +obj-$(CONFIG_LS1_SOC_DRIVERS) += ls1/
> > +
> > diff --git a/drivers/soc/fsl/ls1/Kconfig b/drivers/soc/fsl/ls1/Kconfig
> > new file mode 100644 index 0000000..7556f44
> > --- /dev/null
> > +++ b/drivers/soc/fsl/ls1/Kconfig
> > @@ -0,0 +1,3 @@
> > +#
> > +# LS-1 Soc drivers
> > +#
>
> Doesn't this directory need a Makefile as well?
>

2/2 patch add a config option and Makefile for this.

Regards,
-Dongsheng

2015-08-12 08:04:11

by Russell King - ARM Linux

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers

On Wed, Aug 12, 2015 at 08:01:32AM +0000, Wang Dongsheng wrote:
> Hi Russell,
>
> Thanks for your review. :)
>
> > -----Original Message-----
> > From: Russell King - ARM Linux [mailto:[email protected]]
> > Sent: Wednesday, August 12, 2015 3:45 PM
> > To: Wang Dongsheng-B40534
> > Cc: [email protected]; Wang Huan-B18965; [email protected]; linux-
> > [email protected]; [email protected]; [email protected]; linux-arm-
> > [email protected]
> > Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers
> >
> > On Wed, Aug 12, 2015 at 01:53:26PM +0800, Dongsheng Wang wrote:
> > > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig new
> > > file mode 100644 index 0000000..863d1ef
> > > --- /dev/null
> > > +++ b/drivers/soc/fsl/Kconfig
> > > @@ -0,0 +1,18 @@
> > > +#
> > > +# Freescale SOC drivers
> > > +#
> > > +menuconfig FSL_SOC_DRIVERS
> > > + bool "Freescale Soc Drivers"
> > > + default n
> >
> > No need for default n.
>
> Thanks. Fix it in next version.
>
> > > + help
> > > + Say y here to enable Freescale LS1021A Soc Device Drivers support.
> > > + The Soc Drivers provides the device driver that is a specific block
> > > + or feature on LS1021A platform.
> >
> > Help text should be indented by two spaces as per almost every other help text.
> >
>
> Thanks. My mistake...
>
> > > +
> > > +if LS1_SOC_DRIVERS
> > > + source "drivers/soc/fsl/ls1/Kconfig"
> > > +endif
> > > diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile new
> > > file mode 100644 index 0000000..b4215dd
> > > --- /dev/null
> > > +++ b/drivers/soc/fsl/Makefile
> > > @@ -0,0 +1,6 @@
> > > +#
> > > +# Makefile for Freescale Soc specific device drivers.
> > > +#
> > > +
> > > +obj-$(CONFIG_LS1_SOC_DRIVERS) += ls1/
> > > +
> > > diff --git a/drivers/soc/fsl/ls1/Kconfig b/drivers/soc/fsl/ls1/Kconfig
> > > new file mode 100644 index 0000000..7556f44
> > > --- /dev/null
> > > +++ b/drivers/soc/fsl/ls1/Kconfig
> > > @@ -0,0 +1,3 @@
> > > +#
> > > +# LS-1 Soc drivers
> > > +#
> >
> > Doesn't this directory need a Makefile as well?
> >
>
> 2/2 patch add a config option and Makefile for this.

If _just_ this patch is merged, it creates a build problem as
CONFIG_LS1_SOC_DRIVERS can be enabled, which will cause the kbuild to
decend into drivers/soc/fsl/ls1, where it will stop due to the missing
build error.

Please fix this by adding at least an empty Makefile to this directory.
Do not rely on patch 2 being merged to "fix" this.

--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

2015-08-12 08:10:29

by Wang Dongsheng

[permalink] [raw]
Subject: RE: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers



> -----Original Message-----
> From: Russell King - ARM Linux [mailto:[email protected]]
> Sent: Wednesday, August 12, 2015 4:04 PM
> To: Wang Dongsheng-B40534
> Cc: [email protected]; Wang Huan-B18965; [email protected]; linux-
> [email protected]; [email protected]; [email protected]; linux-arm-
> [email protected]
> Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers
>
> On Wed, Aug 12, 2015 at 08:01:32AM +0000, Wang Dongsheng wrote:
> > Hi Russell,
> >
> > Thanks for your review. :)
> >
> > > -----Original Message-----
> > > From: Russell King - ARM Linux [mailto:[email protected]]
> > > Sent: Wednesday, August 12, 2015 3:45 PM
> > > To: Wang Dongsheng-B40534
> > > Cc: [email protected]; Wang Huan-B18965;
> > > [email protected]; linux- [email protected];
> > > [email protected]; [email protected]; linux-arm-
> > > [email protected]
> > > Subject: Re: [PATCH v2 1/2] soc/fsl: add freescale dir for SOC
> > > specific drivers
> > >
> > > On Wed, Aug 12, 2015 at 01:53:26PM +0800, Dongsheng Wang wrote:
> > > > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig new
> > > > file mode 100644 index 0000000..863d1ef
> > > > --- /dev/null
> > > > +++ b/drivers/soc/fsl/Kconfig
> > > > @@ -0,0 +1,18 @@
> > > > +#
> > > > +# Freescale SOC drivers
> > > > +#
> > > > +menuconfig FSL_SOC_DRIVERS
> > > > + bool "Freescale Soc Drivers"
> > > > + default n
> > >
> > > No need for default n.
> >
> > Thanks. Fix it in next version.
> >
> > > > + help
> > > > + Say y here to enable Freescale LS1021A Soc Device Drivers support.
> > > > + The Soc Drivers provides the device driver that is a specific block
> > > > + or feature on LS1021A platform.
> > >
> > > Help text should be indented by two spaces as per almost every other help
> text.
> > >
> >
> > Thanks. My mistake...
> >
> > > > +
> > > > +if LS1_SOC_DRIVERS
> > > > + source "drivers/soc/fsl/ls1/Kconfig"
> > > > +endif
> > > > diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
> > > > new file mode 100644 index 0000000..b4215dd
> > > > --- /dev/null
> > > > +++ b/drivers/soc/fsl/Makefile
> > > > @@ -0,0 +1,6 @@
> > > > +#
> > > > +# Makefile for Freescale Soc specific device drivers.
> > > > +#
> > > > +
> > > > +obj-$(CONFIG_LS1_SOC_DRIVERS) += ls1/
> > > > +
> > > > diff --git a/drivers/soc/fsl/ls1/Kconfig
> > > > b/drivers/soc/fsl/ls1/Kconfig new file mode 100644 index
> > > > 0000000..7556f44
> > > > --- /dev/null
> > > > +++ b/drivers/soc/fsl/ls1/Kconfig
> > > > @@ -0,0 +1,3 @@
> > > > +#
> > > > +# LS-1 Soc drivers
> > > > +#
> > >
> > > Doesn't this directory need a Makefile as well?
> > >
> >
> > 2/2 patch add a config option and Makefile for this.
>
> If _just_ this patch is merged, it creates a build problem as
> CONFIG_LS1_SOC_DRIVERS can be enabled, which will cause the kbuild to decend
> into drivers/soc/fsl/ls1, where it will stop due to the missing build error.
>
> Please fix this by adding at least an empty Makefile to this directory.
> Do not rely on patch 2 being merged to "fix" this.
>

Um..Yes, miss it. Fix it in next version. :)

Regards,
-Dongsheng

2015-08-13 13:54:20

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform

On Wed, Aug 12, 2015 at 7:53 AM, Dongsheng Wang
<[email protected]> wrote:

> From: Wang Dongsheng <[email protected]>
>
> Only Ftm0 can be used when system going to deep sleep. So this driver
> to support ftm0 as a wakeup source.
>
> Signed-off-by: Wang Dongsheng <[email protected]>
> ---
> *V2*
> Change Copyright 2014 to 2015.
(...)
> +config FTM_ALARM
> + bool "FTM alarm driver"
> + depends on SOC_LS1021A
> + default n
> + help
> + Say y here to enable FTM alarm support. The FTM alarm provides
> + alarm functions for wakeup system from deep sleep. There is only
> + one FTM can be used in ALARM(FTM 0).
(...)
> +static u32 time_to_cycle(unsigned long time)
> +static u32 cycle_to_time(u32 cycle)
> +static int ftm_set_alarm(u64 cycle)
> +static irqreturn_t ftm_alarm_interrupt(int irq, void *dev_id)
> +static ssize_t ftm_alarm_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +static ssize_t ftm_alarm_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
(...)
> +static struct device_attribute ftm_alarm_attributes = __ATTR(ftm_alarm, 0644,
> + ftm_alarm_show, ftm_alarm_store);

If you're gonna invent ABIs, document then in Documentation/ABI/testing/*.

But I don't get it. Why is this driver not in drivers/rtc?

It does a subset of what an RTC does. The ioctl()'s of an RTC
can do what you want to do. And much much more.

If it can't do all an RTC can do, surely the RTC subsystem
can be augmented to host it anyway. It's way to close to
an RTC to have it's own random sysfs driver like this.

Unless I'm totally off, rewrite this to an RTC driver and post
it to the RTC maintainers.

Yours,
Linus Walleij

2015-08-14 03:12:19

by Wang Dongsheng

[permalink] [raw]
Subject: RE: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform



> -----Original Message-----
> From: Linus Walleij [mailto:[email protected]]
> Sent: Thursday, August 13, 2015 9:54 PM
> To: Wang Dongsheng-B40534; John Stultz; Alessandro Zummo; Alexandre Belloni
> Cc: Shawn Guo; Nair, Sandeep; Hans de Goede; Wang Huan-B18965; linux-arm-
> [email protected]; [email protected]; rtc-
> [email protected]
> Subject: Re: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform
>
> On Wed, Aug 12, 2015 at 7:53 AM, Dongsheng Wang
> <[email protected]> wrote:
>
> > From: Wang Dongsheng <[email protected]>
> >
> > Only Ftm0 can be used when system going to deep sleep. So this driver
> > to support ftm0 as a wakeup source.
> >
> > Signed-off-by: Wang Dongsheng <[email protected]>
> > ---
> > *V2*
> > Change Copyright 2014 to 2015.
> (...)
> > +config FTM_ALARM
> > + bool "FTM alarm driver"
> > + depends on SOC_LS1021A
> > + default n
> > + help
> > + Say y here to enable FTM alarm support. The FTM alarm provides
> > + alarm functions for wakeup system from deep sleep. There is only
> > + one FTM can be used in ALARM(FTM 0).
> (...)
> > +static u32 time_to_cycle(unsigned long time)
> > +static u32 cycle_to_time(u32 cycle)
> > +static int ftm_set_alarm(u64 cycle)
> > +static irqreturn_t ftm_alarm_interrupt(int irq, void *dev_id)
> > +static ssize_t ftm_alarm_show(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +static ssize_t ftm_alarm_store(struct device *dev,
> > + struct device_attribute *attr,
> > + const char *buf, size_t count)
> (...)
> > +static struct device_attribute ftm_alarm_attributes = __ATTR(ftm_alarm, 0644,
> > + ftm_alarm_show, ftm_alarm_store);
>
> If you're gonna invent ABIs, document then in Documentation/ABI/testing/*.
>
> But I don't get it. Why is this driver not in drivers/rtc?
>
> It does a subset of what an RTC does. The ioctl()'s of an RTC
> can do what you want to do. And much much more.
>
> If it can't do all an RTC can do, surely the RTC subsystem
> can be augmented to host it anyway. It's way to close to
> an RTC to have it's own random sysfs driver like this.
>
> Unless I'm totally off, rewrite this to an RTC driver and post
> it to the RTC maintainers.
>

FlexTimer is not a RTC device and not have any rtc deivce function. They belong to
different devices, why we need to register this to RTC framework? I am confused about this.

Now in freescale layerscape platform this driver is only for FlexTimer0, and not
fit for each flextimer. Because only FlexTimer0 still turn-on when system in the Deep Sleep.

If the "alarm" make you feel confused or mislead you think this is a RTC devices. I think
I need to change the "alarm" to "timer".

Regards,
-Dongsheng
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2015-08-14 10:06:36

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform

On Fri, Aug 14, 2015 at 5:12 AM, Wang Dongsheng
<[email protected]> wrote:
>> On Wed, Aug 12, 2015 at 7:53 AM, Dongsheng Wang
>> <[email protected]> wrote:
>>
>> > From: Wang Dongsheng <[email protected]>
>> >
>> > Only Ftm0 can be used when system going to deep sleep. So this driver
>> > to support ftm0 as a wakeup source.
>> >
>> > Signed-off-by: Wang Dongsheng <[email protected]>
>> > ---
>> > *V2*
>> > Change Copyright 2014 to 2015.
>> (...)
>> > +config FTM_ALARM
>> > + bool "FTM alarm driver"
>> > + depends on SOC_LS1021A
>> > + default n
>> > + help
>> > + Say y here to enable FTM alarm support. The FTM alarm provides
>> > + alarm functions for wakeup system from deep sleep. There is only
>> > + one FTM can be used in ALARM(FTM 0).
>> (...)
>> > +static u32 time_to_cycle(unsigned long time)
>> > +static u32 cycle_to_time(u32 cycle)
>> > +static int ftm_set_alarm(u64 cycle)
>> > +static irqreturn_t ftm_alarm_interrupt(int irq, void *dev_id)
>> > +static ssize_t ftm_alarm_show(struct device *dev,
>> > + struct device_attribute *attr,
>> > + char *buf)
>> > +static ssize_t ftm_alarm_store(struct device *dev,
>> > + struct device_attribute *attr,
>> > + const char *buf, size_t count)
>> (...)
>> > +static struct device_attribute ftm_alarm_attributes = __ATTR(ftm_alarm, 0644,
>> > + ftm_alarm_show, ftm_alarm_store);
>>
>> If you're gonna invent ABIs, document then in Documentation/ABI/testing/*.
>>
>> But I don't get it. Why is this driver not in drivers/rtc?
>>
>> It does a subset of what an RTC does. The ioctl()'s of an RTC
>> can do what you want to do. And much much more.
>>
>> If it can't do all an RTC can do, surely the RTC subsystem
>> can be augmented to host it anyway. It's way to close to
>> an RTC to have it's own random sysfs driver like this.
>>
>> Unless I'm totally off, rewrite this to an RTC driver and post
>> it to the RTC maintainers.
>
> FlexTimer is not a RTC device and not have any rtc deivce function. They belong to
> different devices, why we need to register this to RTC framework? I am confused about this.
>
> Now in freescale layerscape platform this driver is only for FlexTimer0, and not
> fit for each flextimer. Because only FlexTimer0 still turn-on when system in the Deep Sleep.
>
> If the "alarm" make you feel confused or mislead you think this is a RTC devices. I think
> I need to change the "alarm" to "timer".

I think it is an RTC, it is just that the hardware engineer
designed it with a wakeup usecase in mind and did not call
it an RTC. Wakeup is one of the things RTCs do.

If you inspect a few drivers in drivers/rtc such as drivers/rtc/rtc-pl030.c
you will find that they are just as crude as this "alarm" thing.

It has a counter that counts cycles, it has a comparator
and an alarm function. It is an on-chip RTC, just like PL030
no matter what the datasheet or hardware engineer thinks it
should be called, the Linux kernel calls this an RTC, and it
has a subsystem for handling it, so we should use it and
not invent random new stuff.

If the hardware is really so strange that the counter can only
be started if you also put an alarm at the same time (I doubt
it, but OK if you say so) it is a subset of an RTC that can
only be used for alarms but not timekeeping, but it should
*still* live in drivers/rtc.

Think for a moment on the huge effort that John Stultz put into
integrating Android alarm timers with POSIX and the RTC
subsystem and fixing it all from the smallest handset to
the largest S360 supercomputer. The approach of a custom
device just throws all of that out the window and reinvents the
mechanism in userspace, forcing all standardized userspace to
have special code to handle this special alarm with its
special sysfs ABI.

Check
commit ff3ead96d17f47ee70c294a5cc2cce9b61e82f0f
"timers: Introduce in-kernel alarm-timer interface"
for example.

Even if you persist on keeping it in its own magic driver
like this, it should implement the alarm timer interface
from <linux/alarmtimer.h> and I bet after that you don't
need the sysfs files anymore, as the system will sleep
and wake up from the regular syscalls instead of using
magic poking in sysfs from userspace. AFAICT this hardware
is designed for exactly this usecase.

tools/testing/selftests/timers/alarmtimer-suspend.c
is there for you to test your driver with alarmtimer
support.

Needless to say: if you implement it as an RTC you get the
alarmtimer interaction for free. That is why we have the
subsystem after all: to be helpful.

Yours,
Linus Walleij

2015-08-21 03:22:23

by Wang Dongsheng

[permalink] [raw]
Subject: RE: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform

Hi Walleij and Russell,

I will drop this patch. Thanks for your review.

[PATCH v2 1/2] soc/fsl: add freescale dir for SOC specific drivers

But the 1/2 of the patches also need, because there has another patch(Freescale FPGA driver) need 1/2 patch.
Need I push the 1/2 patch with another patches(Freescale FPGA driver) or push 1/2 standalone without another
patch?

Regards,
-Dongsheng

> -----Original Message-----
> From: Linus Walleij [mailto:[email protected]]
> Sent: Friday, August 14, 2015 6:07 PM
> To: Wang Dongsheng-B40534; John Stultz
> Cc: Alessandro Zummo; Alexandre Belloni; Shawn Guo; Nair, Sandeep; Hans de Goede;
> Wang Huan-B18965; [email protected]; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH 2/2] soc/fsl: add ftm alarm driver for ls1021a platform
>
> On Fri, Aug 14, 2015 at 5:12 AM, Wang Dongsheng
> <[email protected]> wrote:
> >> On Wed, Aug 12, 2015 at 7:53 AM, Dongsheng Wang
> >> <[email protected]> wrote:
> >>
> >> > From: Wang Dongsheng <[email protected]>
> >> >
> >> > Only Ftm0 can be used when system going to deep sleep. So this driver
> >> > to support ftm0 as a wakeup source.
> >> >
> >> > Signed-off-by: Wang Dongsheng <[email protected]>
> >> > ---
> >> > *V2*
> >> > Change Copyright 2014 to 2015.
> >> (...)
> >> > +config FTM_ALARM
> >> > + bool "FTM alarm driver"
> >> > + depends on SOC_LS1021A
> >> > + default n
> >> > + help
> >> > + Say y here to enable FTM alarm support. The FTM alarm provides
> >> > + alarm functions for wakeup system from deep sleep. There is only
> >> > + one FTM can be used in ALARM(FTM 0).
> >> (...)
> >> > +static u32 time_to_cycle(unsigned long time)
> >> > +static u32 cycle_to_time(u32 cycle)
> >> > +static int ftm_set_alarm(u64 cycle)
> >> > +static irqreturn_t ftm_alarm_interrupt(int irq, void *dev_id)
> >> > +static ssize_t ftm_alarm_show(struct device *dev,
> >> > + struct device_attribute *attr,
> >> > + char *buf)
> >> > +static ssize_t ftm_alarm_store(struct device *dev,
> >> > + struct device_attribute *attr,
> >> > + const char *buf, size_t count)
> >> (...)
> >> > +static struct device_attribute ftm_alarm_attributes = __ATTR(ftm_alarm,
> 0644,
> >> > + ftm_alarm_show, ftm_alarm_store);
> >>
> >> If you're gonna invent ABIs, document then in Documentation/ABI/testing/*.
> >>
> >> But I don't get it. Why is this driver not in drivers/rtc?
> >>
> >> It does a subset of what an RTC does. The ioctl()'s of an RTC
> >> can do what you want to do. And much much more.
> >>
> >> If it can't do all an RTC can do, surely the RTC subsystem
> >> can be augmented to host it anyway. It's way to close to
> >> an RTC to have it's own random sysfs driver like this.
> >>
> >> Unless I'm totally off, rewrite this to an RTC driver and post
> >> it to the RTC maintainers.
> >
> > FlexTimer is not a RTC device and not have any rtc deivce function. They
> belong to
> > different devices, why we need to register this to RTC framework? I am
> confused about this.
> >
> > Now in freescale layerscape platform this driver is only for FlexTimer0, and
> not
> > fit for each flextimer. Because only FlexTimer0 still turn-on when system in
> the Deep Sleep.
> >
> > If the "alarm" make you feel confused or mislead you think this is a RTC
> devices. I think
> > I need to change the "alarm" to "timer".
>
> I think it is an RTC, it is just that the hardware engineer
> designed it with a wakeup usecase in mind and did not call
> it an RTC. Wakeup is one of the things RTCs do.
>
> If you inspect a few drivers in drivers/rtc such as drivers/rtc/rtc-pl030.c
> you will find that they are just as crude as this "alarm" thing.
>
> It has a counter that counts cycles, it has a comparator
> and an alarm function. It is an on-chip RTC, just like PL030
> no matter what the datasheet or hardware engineer thinks it
> should be called, the Linux kernel calls this an RTC, and it
> has a subsystem for handling it, so we should use it and
> not invent random new stuff.
>
> If the hardware is really so strange that the counter can only
> be started if you also put an alarm at the same time (I doubt
> it, but OK if you say so) it is a subset of an RTC that can
> only be used for alarms but not timekeeping, but it should
> *still* live in drivers/rtc.
>
> Think for a moment on the huge effort that John Stultz put into
> integrating Android alarm timers with POSIX and the RTC
> subsystem and fixing it all from the smallest handset to
> the largest S360 supercomputer. The approach of a custom
> device just throws all of that out the window and reinvents the
> mechanism in userspace, forcing all standardized userspace to
> have special code to handle this special alarm with its
> special sysfs ABI.
>
> Check
> commit ff3ead96d17f47ee70c294a5cc2cce9b61e82f0f
> "timers: Introduce in-kernel alarm-timer interface"
> for example.
>
> Even if you persist on keeping it in its own magic driver
> like this, it should implement the alarm timer interface
> from <linux/alarmtimer.h> and I bet after that you don't
> need the sysfs files anymore, as the system will sleep
> and wake up from the regular syscalls instead of using
> magic poking in sysfs from userspace. AFAICT this hardware
> is designed for exactly this usecase.
>
> tools/testing/selftests/timers/alarmtimer-suspend.c
> is there for you to test your driver with alarmtimer
> support.
>
> Needless to say: if you implement it as an RTC you get the
> alarmtimer interaction for free. That is why we have the
> subsystem after all: to be helpful.
>
> Yours,
> Linus Walleij
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?