Re: [Intel-gfx] [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-23 Thread Shobhit Kumar
On Mon, Jun 22, 2015 at 4:46 PM, Varka Bhadram  wrote:
> Hi Shobhit Kumar,
>
> On 06/22/2015 04:24 PM, Shobhit Kumar wrote:
>
>> The Crystalcove PMIC provides three PWM signals and this driver exports
>> one of them on the BYT platform which is used to control backlight for
>> DSI panel. This is platform device implementation of the drivers/mfd
>> cell device for CRC PMIC.
>>
>> v2: Use the existing config callback with duty_ns and period_ns(Thierry)
>>
>> v3: Correct the subject line (Lee jones)
>>
>> v4: Address comment by Thierry & Paul
>>  - Commit message update and fixes for few syntax errors
>>  - Add PWM_CRC in Kconfig and Makefile sorted alphabetically
>>  - Use the PWM_BASE_CLK as 600 for better code readability
>>  - Remove the redundant rule of three while calculating pwm level
>>  - Use the platform_device in pwm_chip
>>  - Use builin_platform_driver
>>
>> CC: Samuel Ortiz 
>> Cc: Linus Walleij 
>> Cc: Alexandre Courbot 
>> Cc: Thierry Reding 
>> Cc: Paul Bolle 
>> Cc: Paul Gortmaker 
>> Signed-off-by: Shobhit Kumar 
>
>
> (...)
>
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define PWM0_CLK_DIV   0x4B
>> +#define  PWM_OUTPUT_ENABLE (1 << 7)
>
>
> Can't be BIT() macro ?
>

Can be done.

>> +#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
>> +#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
>> +#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
>> +
>> +#define PWM0_DUTY_CYCLE0x4E
>> +#define BACKLIGHT_EN   0x51
>
>
> (...)
>
>
>> +static int crystalcove_pwm_probe(struct platform_device *pdev)
>> +{
>> +   struct crystalcove_pwm *pwm;
>> +   int retval;
>> +   struct device *dev = pdev->dev.parent;
>> +   struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
>> +
>> +   pwm = devm_kzalloc(>dev, sizeof(*pwm), GFP_KERNEL);
>> +   if (!pwm)
>> +   return -ENOMEM;
>> +
>> +   pwm->chip.dev = >dev;
>> +   pwm->chip.ops = _pwm_ops;
>> +   pwm->chip.base = -1;
>> +   pwm->chip.npwm = 1;
>> +
>> +   /* get the PMIC regmap */
>> +   pwm->regmap = pmic->regmap;
>> +
>> +   retval = pwmchip_add(>chip);
>> +   if (retval < 0)
>> +   return retval;
>> +
>> +   platform_set_drvdata(pdev, pwm);
>> +
>
>
> If you can change this oder we can simply do something like this:
>
> platform_set_drvdata(pdev, pwm);
>
> return pwmchip_add(>chip);
>

Okay. seems better.

>> +   return 0;
>> +}
>> +
>> +static int crystalcove_pwm_remove(struct platform_device *pdev)
>> +{
>> +   struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
>> +   int retval;
>> +
>> +   retval = pwmchip_remove(>chip);
>> +   if (retval < 0)
>> +   return retval;
>> +
>> +   dev_dbg(>dev, "crc-pwm driver removed\n");
>
>
> This debug message may not be required  :-)
>
> you can directly do:
>
> return pwmchip_remove(>chip);

Yeah, will update.

Regards
Shobhit

>
>> +
>> +   return 0;
>> +}
>> +
>> +static struct platform_driver crystalcove_pwm_driver = {
>> +   .probe = crystalcove_pwm_probe,
>> +   .remove = crystalcove_pwm_remove,
>> +   .driver = {
>> +   .name = "crystal_cove_pwm",
>> +   },
>> +};
>> +
>> +builtin_platform_driver(crystalcove_pwm_driver);
>
>
>
> --
> Best regards,
> Varka Bhadram.
>
>
> ___
> Intel-gfx mailing list
> intel-...@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
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: [Intel-gfx] [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-23 Thread Shobhit Kumar
On Mon, Jun 22, 2015 at 4:46 PM, Varka Bhadram varkabhad...@gmail.com wrote:
 Hi Shobhit Kumar,

 On 06/22/2015 04:24 PM, Shobhit Kumar wrote:

 The Crystalcove PMIC provides three PWM signals and this driver exports
 one of them on the BYT platform which is used to control backlight for
 DSI panel. This is platform device implementation of the drivers/mfd
 cell device for CRC PMIC.

 v2: Use the existing config callback with duty_ns and period_ns(Thierry)

 v3: Correct the subject line (Lee jones)

 v4: Address comment by Thierry  Paul
  - Commit message update and fixes for few syntax errors
  - Add PWM_CRC in Kconfig and Makefile sorted alphabetically
  - Use the PWM_BASE_CLK as 600 for better code readability
  - Remove the redundant rule of three while calculating pwm level
  - Use the platform_device in pwm_chip
  - Use builin_platform_driver

 CC: Samuel Ortiz sa...@linux.intel.com
 Cc: Linus Walleij linus.wall...@linaro.org
 Cc: Alexandre Courbot gnu...@gmail.com
 Cc: Thierry Reding thierry.red...@gmail.com
 Cc: Paul Bolle pebo...@tiscali.nl
 Cc: Paul Gortmaker paul.gortma...@windriver.com
 Signed-off-by: Shobhit Kumar shobhit.ku...@intel.com


 (...)

 +
 +#include linux/platform_device.h
 +#include linux/regmap.h
 +#include linux/mfd/intel_soc_pmic.h
 +#include linux/pwm.h
 +
 +#define PWM0_CLK_DIV   0x4B
 +#define  PWM_OUTPUT_ENABLE (1  7)


 Can't be BIT() macro ?


Can be done.

 +#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
 +#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
 +#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
 +
 +#define PWM0_DUTY_CYCLE0x4E
 +#define BACKLIGHT_EN   0x51


 (...)


 +static int crystalcove_pwm_probe(struct platform_device *pdev)
 +{
 +   struct crystalcove_pwm *pwm;
 +   int retval;
 +   struct device *dev = pdev-dev.parent;
 +   struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
 +
 +   pwm = devm_kzalloc(pdev-dev, sizeof(*pwm), GFP_KERNEL);
 +   if (!pwm)
 +   return -ENOMEM;
 +
 +   pwm-chip.dev = pdev-dev;
 +   pwm-chip.ops = crc_pwm_ops;
 +   pwm-chip.base = -1;
 +   pwm-chip.npwm = 1;
 +
 +   /* get the PMIC regmap */
 +   pwm-regmap = pmic-regmap;
 +
 +   retval = pwmchip_add(pwm-chip);
 +   if (retval  0)
 +   return retval;
 +
 +   platform_set_drvdata(pdev, pwm);
 +


 If you can change this oder we can simply do something like this:

 platform_set_drvdata(pdev, pwm);

 return pwmchip_add(pwm-chip);


Okay. seems better.

 +   return 0;
 +}
 +
 +static int crystalcove_pwm_remove(struct platform_device *pdev)
 +{
 +   struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
 +   int retval;
 +
 +   retval = pwmchip_remove(pwm-chip);
 +   if (retval  0)
 +   return retval;
 +
 +   dev_dbg(pdev-dev, crc-pwm driver removed\n);


 This debug message may not be required  :-)

 you can directly do:

 return pwmchip_remove(pwm-chip);

Yeah, will update.

Regards
Shobhit


 +
 +   return 0;
 +}
 +
 +static struct platform_driver crystalcove_pwm_driver = {
 +   .probe = crystalcove_pwm_probe,
 +   .remove = crystalcove_pwm_remove,
 +   .driver = {
 +   .name = crystal_cove_pwm,
 +   },
 +};
 +
 +builtin_platform_driver(crystalcove_pwm_driver);



 --
 Best regards,
 Varka Bhadram.


 ___
 Intel-gfx mailing list
 intel-...@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
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: [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-22 Thread Varka Bhadram

Hi Shobhit Kumar,

On 06/22/2015 04:24 PM, Shobhit Kumar wrote:


The Crystalcove PMIC provides three PWM signals and this driver exports
one of them on the BYT platform which is used to control backlight for
DSI panel. This is platform device implementation of the drivers/mfd
cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry & Paul
 - Commit message update and fixes for few syntax errors
 - Add PWM_CRC in Kconfig and Makefile sorted alphabetically
 - Use the PWM_BASE_CLK as 600 for better code readability
 - Remove the redundant rule of three while calculating pwm level
 - Use the platform_device in pwm_chip
 - Use builin_platform_driver

CC: Samuel Ortiz 
Cc: Linus Walleij 
Cc: Alexandre Courbot 
Cc: Thierry Reding 
Cc: Paul Bolle 
Cc: Paul Gortmaker 
Signed-off-by: Shobhit Kumar 


(...)


+
+#include 
+#include 
+#include 
+#include 
+
+#define PWM0_CLK_DIV   0x4B
+#define  PWM_OUTPUT_ENABLE (1 << 7)


Can't be BIT() macro ?


+#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE0x4E
+#define BACKLIGHT_EN   0x51


(...)


+static int crystalcove_pwm_probe(struct platform_device *pdev)
+{
+   struct crystalcove_pwm *pwm;
+   int retval;
+   struct device *dev = pdev->dev.parent;
+   struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
+
+   pwm = devm_kzalloc(>dev, sizeof(*pwm), GFP_KERNEL);
+   if (!pwm)
+   return -ENOMEM;
+
+   pwm->chip.dev = >dev;
+   pwm->chip.ops = _pwm_ops;
+   pwm->chip.base = -1;
+   pwm->chip.npwm = 1;
+
+   /* get the PMIC regmap */
+   pwm->regmap = pmic->regmap;
+
+   retval = pwmchip_add(>chip);
+   if (retval < 0)
+   return retval;
+
+   platform_set_drvdata(pdev, pwm);
+


If you can change this oder we can simply do something like this:

platform_set_drvdata(pdev, pwm);

return pwmchip_add(>chip);


+   return 0;
+}
+
+static int crystalcove_pwm_remove(struct platform_device *pdev)
+{
+   struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
+   int retval;
+
+   retval = pwmchip_remove(>chip);
+   if (retval < 0)
+   return retval;
+
+   dev_dbg(>dev, "crc-pwm driver removed\n");


This debug message may not be required  :-)

you can directly do:

return pwmchip_remove(>chip);


+
+   return 0;
+}
+
+static struct platform_driver crystalcove_pwm_driver = {
+   .probe = crystalcove_pwm_probe,
+   .remove = crystalcove_pwm_remove,
+   .driver = {
+   .name = "crystal_cove_pwm",
+   },
+};
+
+builtin_platform_driver(crystalcove_pwm_driver);



--
Best regards,
Varka Bhadram.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/


[v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-22 Thread Shobhit Kumar
The Crystalcove PMIC provides three PWM signals and this driver exports
one of them on the BYT platform which is used to control backlight for
DSI panel. This is platform device implementation of the drivers/mfd
cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry & Paul
- Commit message update and fixes for few syntax errors
- Add PWM_CRC in Kconfig and Makefile sorted alphabetically
- Use the PWM_BASE_CLK as 600 for better code readability
- Remove the redundant rule of three while calculating pwm level
- Use the platform_device in pwm_chip
- Use builin_platform_driver

CC: Samuel Ortiz 
Cc: Linus Walleij 
Cc: Alexandre Courbot 
Cc: Thierry Reding 
Cc: Paul Bolle 
Cc: Paul Gortmaker 
Signed-off-by: Shobhit Kumar 
---
 drivers/pwm/Kconfig   |   7 +++
 drivers/pwm/Makefile  |   1 +
 drivers/pwm/pwm-crc.c | 155 ++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/pwm/pwm-crc.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index b1541f4..948d9ab 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -111,6 +111,13 @@ config PWM_CLPS711X
  To compile this driver as a module, choose M here: the module
  will be called pwm-clps711x.
 
+config PWM_CRC
+   bool "Intel Crystalcove (CRC) PWM support"
+   depends on X86 && INTEL_SOC_PMIC
+   help
+ Generic PWM framework driver for Crystalcove (CRC) PMIC based PWM
+ control.
+
 config PWM_EP93XX
tristate "Cirrus Logic EP93xx PWM support"
depends on ARCH_EP93XX
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index ec50eb5..d186f35 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_PWM_BCM_KONA)  += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BCM2835)  += pwm-bcm2835.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_CLPS711X) += pwm-clps711x.o
+obj-$(CONFIG_PWM_CRC)  += pwm-crc.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)  += pwm-fsl-ftm.o
 obj-$(CONFIG_PWM_IMG)  += pwm-img.o
diff --git a/drivers/pwm/pwm-crc.c b/drivers/pwm/pwm-crc.c
new file mode 100644
index 000..dcd9782
--- /dev/null
+++ b/drivers/pwm/pwm-crc.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2015 Intel Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Shobhit Kumar 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define PWM0_CLK_DIV   0x4B
+#define  PWM_OUTPUT_ENABLE (1 << 7)
+#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE0x4E
+#define BACKLIGHT_EN   0x51
+
+#define PWM_MAX_LEVEL  0xFF
+
+#define PWM_BASE_CLK   600  /* 6 MHz */
+#define PWM_MAX_PERIOD_NS  21333/* 46.875KHz */
+
+/**
+ * struct crystalcove_pwm - Crystal Cove PWM controller
+ * @chip: the abstract pwm_chip structure.
+ * @regmap: the regmap from the parent device.
+ */
+struct crystalcove_pwm {
+   struct pwm_chip chip;
+   struct regmap *regmap;
+};
+
+static inline struct crystalcove_pwm *to_crc_pwm(struct pwm_chip *pc)
+{
+   return container_of(pc, struct crystalcove_pwm, chip);
+}
+
+static int crc_pwm_enable(struct pwm_chip *c, struct pwm_device *pwm)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+
+   regmap_write(crc_pwm->regmap, BACKLIGHT_EN, 1);
+
+   return 0;
+}
+
+static void crc_pwm_disable(struct pwm_chip *c, struct pwm_device *pwm)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+
+   regmap_write(crc_pwm->regmap, BACKLIGHT_EN, 0);
+}
+
+static int crc_pwm_config(struct pwm_chip *c, struct pwm_device *pwm,
+ int duty_ns, int period_ns)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+   struct device *dev = crc_pwm->chip.dev;
+   int level;
+
+   if (period_ns > PWM_MAX_PERIOD_NS) {
+   dev_err(dev, "un-supported period_ns\n");
+   return -EINVAL;
+   }
+
+   if (pwm->period != period_ns) {
+   int clk_div;
+
+   /* changing the clk divisor, need to disable fisrt */
+   crc_pwm_disable(c, pwm);
+   clk_div = PWM_BASE_CLK * period_ns / NSEC_PER_SEC;
+
+   

Re: [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-22 Thread Varka Bhadram

Hi Shobhit Kumar,

On 06/22/2015 04:24 PM, Shobhit Kumar wrote:


The Crystalcove PMIC provides three PWM signals and this driver exports
one of them on the BYT platform which is used to control backlight for
DSI panel. This is platform device implementation of the drivers/mfd
cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry  Paul
 - Commit message update and fixes for few syntax errors
 - Add PWM_CRC in Kconfig and Makefile sorted alphabetically
 - Use the PWM_BASE_CLK as 600 for better code readability
 - Remove the redundant rule of three while calculating pwm level
 - Use the platform_device in pwm_chip
 - Use builin_platform_driver

CC: Samuel Ortiz sa...@linux.intel.com
Cc: Linus Walleij linus.wall...@linaro.org
Cc: Alexandre Courbot gnu...@gmail.com
Cc: Thierry Reding thierry.red...@gmail.com
Cc: Paul Bolle pebo...@tiscali.nl
Cc: Paul Gortmaker paul.gortma...@windriver.com
Signed-off-by: Shobhit Kumar shobhit.ku...@intel.com


(...)


+
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/mfd/intel_soc_pmic.h
+#include linux/pwm.h
+
+#define PWM0_CLK_DIV   0x4B
+#define  PWM_OUTPUT_ENABLE (1  7)


Can't be BIT() macro ?


+#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE0x4E
+#define BACKLIGHT_EN   0x51


(...)


+static int crystalcove_pwm_probe(struct platform_device *pdev)
+{
+   struct crystalcove_pwm *pwm;
+   int retval;
+   struct device *dev = pdev-dev.parent;
+   struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
+
+   pwm = devm_kzalloc(pdev-dev, sizeof(*pwm), GFP_KERNEL);
+   if (!pwm)
+   return -ENOMEM;
+
+   pwm-chip.dev = pdev-dev;
+   pwm-chip.ops = crc_pwm_ops;
+   pwm-chip.base = -1;
+   pwm-chip.npwm = 1;
+
+   /* get the PMIC regmap */
+   pwm-regmap = pmic-regmap;
+
+   retval = pwmchip_add(pwm-chip);
+   if (retval  0)
+   return retval;
+
+   platform_set_drvdata(pdev, pwm);
+


If you can change this oder we can simply do something like this:

platform_set_drvdata(pdev, pwm);

return pwmchip_add(pwm-chip);


+   return 0;
+}
+
+static int crystalcove_pwm_remove(struct platform_device *pdev)
+{
+   struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
+   int retval;
+
+   retval = pwmchip_remove(pwm-chip);
+   if (retval  0)
+   return retval;
+
+   dev_dbg(pdev-dev, crc-pwm driver removed\n);


This debug message may not be required  :-)

you can directly do:

return pwmchip_remove(pwm-chip);


+
+   return 0;
+}
+
+static struct platform_driver crystalcove_pwm_driver = {
+   .probe = crystalcove_pwm_probe,
+   .remove = crystalcove_pwm_remove,
+   .driver = {
+   .name = crystal_cove_pwm,
+   },
+};
+
+builtin_platform_driver(crystalcove_pwm_driver);



--
Best regards,
Varka Bhadram.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
Please read the FAQ at  http://www.tux.org/lkml/


[v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

2015-06-22 Thread Shobhit Kumar
The Crystalcove PMIC provides three PWM signals and this driver exports
one of them on the BYT platform which is used to control backlight for
DSI panel. This is platform device implementation of the drivers/mfd
cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry  Paul
- Commit message update and fixes for few syntax errors
- Add PWM_CRC in Kconfig and Makefile sorted alphabetically
- Use the PWM_BASE_CLK as 600 for better code readability
- Remove the redundant rule of three while calculating pwm level
- Use the platform_device in pwm_chip
- Use builin_platform_driver

CC: Samuel Ortiz sa...@linux.intel.com
Cc: Linus Walleij linus.wall...@linaro.org
Cc: Alexandre Courbot gnu...@gmail.com
Cc: Thierry Reding thierry.red...@gmail.com
Cc: Paul Bolle pebo...@tiscali.nl
Cc: Paul Gortmaker paul.gortma...@windriver.com
Signed-off-by: Shobhit Kumar shobhit.ku...@intel.com
---
 drivers/pwm/Kconfig   |   7 +++
 drivers/pwm/Makefile  |   1 +
 drivers/pwm/pwm-crc.c | 155 ++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/pwm/pwm-crc.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index b1541f4..948d9ab 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -111,6 +111,13 @@ config PWM_CLPS711X
  To compile this driver as a module, choose M here: the module
  will be called pwm-clps711x.
 
+config PWM_CRC
+   bool Intel Crystalcove (CRC) PWM support
+   depends on X86  INTEL_SOC_PMIC
+   help
+ Generic PWM framework driver for Crystalcove (CRC) PMIC based PWM
+ control.
+
 config PWM_EP93XX
tristate Cirrus Logic EP93xx PWM support
depends on ARCH_EP93XX
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index ec50eb5..d186f35 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_PWM_BCM_KONA)  += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BCM2835)  += pwm-bcm2835.o
 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o
 obj-$(CONFIG_PWM_CLPS711X) += pwm-clps711x.o
+obj-$(CONFIG_PWM_CRC)  += pwm-crc.o
 obj-$(CONFIG_PWM_EP93XX)   += pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)  += pwm-fsl-ftm.o
 obj-$(CONFIG_PWM_IMG)  += pwm-img.o
diff --git a/drivers/pwm/pwm-crc.c b/drivers/pwm/pwm-crc.c
new file mode 100644
index 000..dcd9782
--- /dev/null
+++ b/drivers/pwm/pwm-crc.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2015 Intel Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Author: Shobhit Kumar shobhit.ku...@intel.com
+ */
+
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/mfd/intel_soc_pmic.h
+#include linux/pwm.h
+
+#define PWM0_CLK_DIV   0x4B
+#define  PWM_OUTPUT_ENABLE (1  7)
+#define  PWM_DIV_CLK_0 0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100   0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128   0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE0x4E
+#define BACKLIGHT_EN   0x51
+
+#define PWM_MAX_LEVEL  0xFF
+
+#define PWM_BASE_CLK   600  /* 6 MHz */
+#define PWM_MAX_PERIOD_NS  21333/* 46.875KHz */
+
+/**
+ * struct crystalcove_pwm - Crystal Cove PWM controller
+ * @chip: the abstract pwm_chip structure.
+ * @regmap: the regmap from the parent device.
+ */
+struct crystalcove_pwm {
+   struct pwm_chip chip;
+   struct regmap *regmap;
+};
+
+static inline struct crystalcove_pwm *to_crc_pwm(struct pwm_chip *pc)
+{
+   return container_of(pc, struct crystalcove_pwm, chip);
+}
+
+static int crc_pwm_enable(struct pwm_chip *c, struct pwm_device *pwm)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+
+   regmap_write(crc_pwm-regmap, BACKLIGHT_EN, 1);
+
+   return 0;
+}
+
+static void crc_pwm_disable(struct pwm_chip *c, struct pwm_device *pwm)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+
+   regmap_write(crc_pwm-regmap, BACKLIGHT_EN, 0);
+}
+
+static int crc_pwm_config(struct pwm_chip *c, struct pwm_device *pwm,
+ int duty_ns, int period_ns)
+{
+   struct crystalcove_pwm *crc_pwm = to_crc_pwm(c);
+   struct device *dev = crc_pwm-chip.dev;
+   int level;
+
+   if (period_ns  PWM_MAX_PERIOD_NS) {
+   dev_err(dev, un-supported period_ns\n);
+   return -EINVAL;
+   }
+
+   if (pwm-period !=