linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: Russell King <linux@arm.linux.org.uk>,
	Daniel Mack <daniel@zonque.org>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Jingoo Han <jg1.han@samsung.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Andrea Adami <andrea.adami@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-input@vger.kernel.org, linux-spi@vger.kernel.org,
	alsa-devel@alsa-project.org
Subject: [PATCH v4 02/18] leds: port locomo leds driver to new locomo core
Date: Mon, 25 May 2015 14:41:37 +0300	[thread overview]
Message-ID: <1432554113-26280-3-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1432554113-26280-1-git-send-email-dbaryshkov@gmail.com>

Adapt locomo leds driver to new locomo core setup.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>
---
 drivers/leds/Kconfig       |   2 +-
 drivers/leds/leds-locomo.c | 117 +++++++++++++++++++++++----------------------
 2 files changed, 61 insertions(+), 58 deletions(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 966b960..d086aac 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -79,7 +79,7 @@ config LEDS_LM3642
 config LEDS_LOCOMO
 	tristate "LED Support for Locomo device"
 	depends on LEDS_CLASS
-	depends on SHARP_LOCOMO
+	depends on MFD_LOCOMO
 	help
 	  This option enables support for the LEDs on Sharp Locomo.
 	  Zaurus models SL-5500 and SL-5600.
diff --git a/drivers/leds/leds-locomo.c b/drivers/leds/leds-locomo.c
index 80ba048..a4286e9 100644
--- a/drivers/leds/leds-locomo.c
+++ b/drivers/leds/leds-locomo.c
@@ -9,89 +9,92 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/device.h>
 #include <linux/leds.h>
+#include <linux/mfd/locomo.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
 
-#include <mach/hardware.h>
-#include <asm/hardware/locomo.h>
+struct locomo_led {
+	struct led_classdev led;
+	struct regmap *regmap;
+	unsigned int reg;
+};
 
 static void locomoled_brightness_set(struct led_classdev *led_cdev,
-				enum led_brightness value, int offset)
-{
-	struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->dev->parent);
-	unsigned long flags;
-
-	local_irq_save(flags);
-	if (value)
-		locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset);
-	else
-		locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset);
-	local_irq_restore(flags);
-}
-
-static void locomoled_brightness_set0(struct led_classdev *led_cdev,
 				enum led_brightness value)
 {
-	locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0);
+	struct locomo_led *led = container_of(led_cdev, struct locomo_led, led);
+
+	regmap_write(led->regmap, led->reg,
+			value ? LOCOMO_LPT_TOFH : LOCOMO_LPT_TOFL);
 }
 
-static void locomoled_brightness_set1(struct led_classdev *led_cdev,
-				enum led_brightness value)
+static int locomo_led_register(
+		struct device *dev,
+		struct locomo_led *led,
+		const char *name,
+		const char *trigger,
+		struct regmap *regmap,
+		unsigned int reg)
 {
-	locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1);
+	led->led.name = name;
+	led->led.flags = LED_CORE_SUSPENDRESUME;
+	led->led.default_trigger = trigger;
+	led->led.brightness_set = locomoled_brightness_set;
+	led->regmap = regmap;
+	led->reg = reg;
+
+	return devm_led_classdev_register(dev, &led->led);
 }
 
-static struct led_classdev locomo_led0 = {
-	.name			= "locomo:amber:charge",
-	.default_trigger	= "main-battery-charging",
-	.brightness_set		= locomoled_brightness_set0,
-};
-
-static struct led_classdev locomo_led1 = {
-	.name			= "locomo:green:mail",
-	.default_trigger	= "nand-disk",
-	.brightness_set		= locomoled_brightness_set1,
-};
-
-static int locomoled_probe(struct locomo_dev *ldev)
+static int locomoled_probe(struct platform_device *pdev)
 {
 	int ret;
-
-	ret = led_classdev_register(&ldev->dev, &locomo_led0);
+	struct locomo_led *leds;
+	struct regmap *regmap;
+
+	leds = devm_kzalloc(&pdev->dev, 2 * sizeof(*leds), GFP_KERNEL);
+	if (!leds)
+		return -ENOMEM;
+
+	regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!regmap)
+		return -ENODEV;
+
+	ret = locomo_led_register(
+			&pdev->dev,
+			leds,
+			"locomo:amber:charge",
+			"main-battery-charging",
+			regmap,
+			LOCOMO_LPT0);
 	if (ret < 0)
 		return ret;
 
-	ret = led_classdev_register(&ldev->dev, &locomo_led1);
+	ret = locomo_led_register(
+			&pdev->dev,
+			leds + 1,
+			"locomo:green:mail",
+			"mmc0",
+			regmap,
+			LOCOMO_LPT1);
 	if (ret < 0)
-		led_classdev_unregister(&locomo_led0);
-
-	return ret;
-}
+		return ret;
 
-static int locomoled_remove(struct locomo_dev *dev)
-{
-	led_classdev_unregister(&locomo_led0);
-	led_classdev_unregister(&locomo_led1);
 	return 0;
 }
 
-static struct locomo_driver locomoled_driver = {
-	.drv = {
-		.name = "locomoled"
+static struct platform_driver locomoled_driver = {
+	.driver = {
+		.name = "locomo-led"
 	},
-	.devid	= LOCOMO_DEVID_LED,
 	.probe	= locomoled_probe,
-	.remove	= locomoled_remove,
 };
 
-static int __init locomoled_init(void)
-{
-	return locomo_driver_register(&locomoled_driver);
-}
-module_init(locomoled_init);
+module_platform_driver(locomoled_driver);
 
 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
 MODULE_DESCRIPTION("Locomo LED driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:locomo-led");
-- 
2.1.4


  parent reply	other threads:[~2015-05-25 11:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-25 11:41 [PATCH v4 00/18] new MFD LoCoMo driver set Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 01/18] mfd: add new driver for Sharp LoCoMo Dmitry Eremin-Solenikov
2015-05-27 10:27   ` Lee Jones
2015-05-27 14:55     ` Dmitry Eremin-Solenikov
2015-05-28 11:58       ` Lee Jones
2015-05-28 19:07         ` Dmitry Eremin-Solenikov
2015-06-02 11:33           ` Linus Walleij
2015-05-25 11:41 ` Dmitry Eremin-Solenikov [this message]
2015-05-25 11:41 ` [PATCH v4 03/18] input: convert LoCoMo keyboard driver to use new locomo core Dmitry Eremin-Solenikov
     [not found]   ` <1432554113-26280-4-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-26 17:44     ` Dmitry Torokhov
2015-05-25 11:41 ` [PATCH v4 05/18] input: make LoCoMo keyboard driver support both poodle and collie Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 12/18] ARM: sa1100: make collie use new locomo drivers Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 14/18] ASoC: pxa: poodle: make use of new locomo GPIO interface Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 15/18] ARM: pxa: poodle: use new LoCoMo driver Dmitry Eremin-Solenikov
2015-05-26 21:18   ` Robert Jarzmik
     [not found] ` <1432554113-26280-1-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-25 11:41   ` [PATCH v4 04/18] input: locomokbd: differentiate between two Enter keys Dmitry Eremin-Solenikov
     [not found]     ` <1432554113-26280-5-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-26 17:45       ` Dmitry Torokhov
2015-05-25 11:41   ` [PATCH v4 06/18] video: backlight: add new locomo backlight driver Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 07/18] video: lcd: add LoCoMo LCD driver Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 08/18] gpio: port LoCoMo gpio support from old driver Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 09/18] gpio: locomo: implement per-pin irq handling Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 10/18] spi: add locomo SPI driver Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 11/18] i2c: add locomo i2c driver Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 13/18] ARM: sa1100: don't preallocate IRQ space for locomo Dmitry Eremin-Solenikov
2015-05-25 11:41   ` [PATCH v4 16/18] ARM: pxa: poodle: " Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 17/18] video: backlight: drop old locomo bl/lcd driver Dmitry Eremin-Solenikov
2015-05-25 11:41 ` [PATCH v4 18/18] ARM: drop old LoCoMo driver Dmitry Eremin-Solenikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432554113-26280-3-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andrea.adami@gmail.com \
    --cc=broonie@kernel.org \
    --cc=daniel@zonque.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gnurou@gmail.com \
    --cc=jg1.han@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=robert.jarzmik@free.fr \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).