diff options
author | Robert Hodaszi <robert.hodaszi@digi.com> | 2011-06-02 14:28:56 +0200 |
---|---|---|
committer | Hector Palacios <hector.palacios@digi.com> | 2011-09-01 10:36:33 +0200 |
commit | f346685892b3f72f7896c51c2f799195f677e373 (patch) | |
tree | d3bc096dbe34f48fb48c6e2fb9727326718f85bd /drivers | |
parent | 5ea5e14ba2919ce14bd7d8f5f6f202b04e502517 (diff) |
merge: merged PWM releated CC9M2443 changes from 2.6.28
Signed-off-by: Robert Hodaszi <robert.hodaszi@digi.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/leds/leds-pwm.c | 228 | ||||
-rw-r--r-- | drivers/leds/ledtrig-dim.c | 1 | ||||
-rw-r--r-- | drivers/pwm/s3c24xx-pwm.c | 7 |
3 files changed, 137 insertions, 99 deletions
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index da3fa8dcdf5b..27caf64de437 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -1,153 +1,189 @@ /* - * linux/drivers/leds-pwm.c + * drivers/leds/leds-pwm.c * - * simple PWM based LED control + * Copyright (C) 2009 by Digi International Inc. + * All rights reserved. * - * Copyright 2009 Luotao Fu @ Pengutronix (l.fu@pengutronix.de) - * - * based on leds-gpio.c by Raphael Assenat <raph@8d.com> + * Code rebased on original leds-pwm.c from Bill Gatliff * * 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. + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <linux/module.h> + #include <linux/kernel.h> -#include <linux/init.h> #include <linux/platform_device.h> -#include <linux/fb.h> #include <linux/leds.h> -#include <linux/err.h> +#include <linux/io.h> #include <linux/pwm.h> -#include <linux/leds_pwm.h> +#include <linux/pwm-led.h> +#include <linux/err.h> +#include <linux/delay.h> #include <linux/slab.h> -struct led_pwm_data { - struct led_classdev cdev; - struct pwm_device *pwm; - unsigned int active_low; - unsigned int period; + +struct led_pwm { + struct led_classdev led; + struct pwm_channel *pwm; + unsigned long period; }; -static void led_pwm_set(struct led_classdev *led_cdev, - enum led_brightness brightness) +static void +led_pwm_brightness_set(struct led_classdev *c, + enum led_brightness b) +{ + struct led_pwm *led; + unsigned long period; + + period = 1000000000UL; + led = container_of(c, struct led_pwm, led); + led->period = period; + pwm_set_period_ns(led->pwm, period); +} + + +static enum led_brightness +led_pwm_brightness_get(struct led_classdev *c) { - struct led_pwm_data *led_dat = - container_of(led_cdev, struct led_pwm_data, cdev); - unsigned int max = led_dat->cdev.max_brightness; - unsigned int period = led_dat->period; - - if (brightness == 0) { - pwm_config(led_dat->pwm, 0, period); - pwm_disable(led_dat->pwm); - } else { - pwm_config(led_dat->pwm, brightness * period / max, period); - pwm_enable(led_dat->pwm); + struct led_pwm *led; + led = container_of(c, struct led_pwm, led); + return led->period; +} + +static int +led_pwm_blink_set(struct led_classdev *c, + unsigned long *on_ms, + unsigned long *off_ms) +{ + struct led_pwm *led; + struct pwm_channel_config cfg; + + led = container_of(c, struct led_pwm, led); + + if (*on_ms == 0 && *off_ms == 0) { + *on_ms = 1000UL; + *off_ms = 1000UL; } + + cfg.config_mask = PWM_CONFIG_DUTY_NS + | PWM_CONFIG_PERIOD_NS; + + cfg.duty_ns = *on_ms * 1000000000UL; + cfg.period_ns = (*on_ms + *off_ms) * 1000000000UL; + + return pwm_config(led->pwm, &cfg); } -static int led_pwm_probe(struct platform_device *pdev) + +static int __init +led_pwm_probe(struct platform_device *pdev) { - struct led_pwm_platform_data *pdata = pdev->dev.platform_data; - struct led_pwm *cur_led; - struct led_pwm_data *leds_data, *led_dat; - int i, ret = 0; + struct pwm_led_platform_data *pdata = pdev->dev.platform_data; + struct led_pwm *led; + int ret; - if (!pdata) - return -EBUSY; + if (!pdata || !pdata->led_info) { + return -EINVAL; + } - leds_data = kzalloc(sizeof(struct led_pwm_data) * pdata->num_leds, - GFP_KERNEL); - if (!leds_data) + led = kzalloc(sizeof(*led), GFP_KERNEL); + if (!led) return -ENOMEM; - for (i = 0; i < pdata->num_leds; i++) { - cur_led = &pdata->leds[i]; - led_dat = &leds_data[i]; - - led_dat->pwm = pwm_request(cur_led->pwm_id, - cur_led->name); - if (IS_ERR(led_dat->pwm)) { - dev_err(&pdev->dev, "unable to request PWM %d\n", - cur_led->pwm_id); - goto err; - } - - led_dat->cdev.name = cur_led->name; - led_dat->cdev.default_trigger = cur_led->default_trigger; - led_dat->active_low = cur_led->active_low; - led_dat->period = cur_led->pwm_period_ns; - led_dat->cdev.brightness_set = led_pwm_set; - led_dat->cdev.brightness = LED_OFF; - led_dat->cdev.max_brightness = cur_led->max_brightness; - led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; - - ret = led_classdev_register(&pdev->dev, &led_dat->cdev); - if (ret < 0) { - pwm_free(led_dat->pwm); - goto err; - } + led->pwm = pwm_request(pdata->bus_id, pdata->chan, + pdata->led_info->name); + + if (!led->pwm) { + ret = -EINVAL; + goto err_pwm_request; } - platform_set_drvdata(pdev, leds_data); + platform_set_drvdata(pdev, led); - return 0; + led->led.name = pdata->led_info->name; + led->led.default_trigger = pdata->led_info->default_trigger; + led->led.brightness_set = led_pwm_brightness_set; + led->led.brightness_get = led_pwm_brightness_get; + led->led.blink_set = led_pwm_blink_set; + led->led.brightness = LED_OFF; -err: - if (i > 0) { - for (i = i - 1; i >= 0; i--) { - led_classdev_unregister(&leds_data[i].cdev); - pwm_free(leds_data[i].pwm); - } - } + ret = pwm_config(led->pwm, pdata->config); + if (ret) + goto err_pwm_config; + + pwm_start(led->pwm); + + ret = led_classdev_register(&pdev->dev, &led->led); + if (ret < 0) + goto err_classdev_register; + + return 0; - kfree(leds_data); +err_classdev_register: + pwm_stop(led->pwm); +err_pwm_config: + pwm_free(led->pwm); +err_pwm_request: + kfree(led); return ret; } -static int __devexit led_pwm_remove(struct platform_device *pdev) +static int +led_pwm_remove(struct platform_device *pdev) { - int i; - struct led_pwm_platform_data *pdata = pdev->dev.platform_data; - struct led_pwm_data *leds_data; + struct led_pwm *led = platform_get_drvdata(pdev); - leds_data = platform_get_drvdata(pdev); + led_classdev_unregister(&led->led); - for (i = 0; i < pdata->num_leds; i++) { - led_classdev_unregister(&leds_data[i].cdev); - pwm_free(leds_data[i].pwm); + if (led->pwm) { + pwm_stop(led->pwm); + pwm_free(led->pwm); } - kfree(leds_data); + kfree(led); + platform_set_drvdata(pdev, NULL); return 0; } + static struct platform_driver led_pwm_driver = { - .probe = led_pwm_probe, - .remove = __devexit_p(led_pwm_remove), - .driver = { - .name = "leds_pwm", - .owner = THIS_MODULE, + .driver = { + .name = "leds-pwm", + .owner = THIS_MODULE, }, + .probe = led_pwm_probe, + .remove = led_pwm_remove, }; -static int __init led_pwm_init(void) + +static int __init led_pwm_modinit(void) { return platform_driver_register(&led_pwm_driver); } +late_initcall(led_pwm_modinit); + -static void __exit led_pwm_exit(void) +static void __exit led_pwm_modexit(void) { platform_driver_unregister(&led_pwm_driver); } +module_exit(led_pwm_modexit); -module_init(led_pwm_init); -module_exit(led_pwm_exit); -MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>"); -MODULE_DESCRIPTION("PWM LED driver for PXA"); +MODULE_AUTHOR("Hector Oron <Hector.Oron <at> digi.com>"); +MODULE_DESCRIPTION("Driver for LEDs with PWM-controlled brightness"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:leds-pwm"); diff --git a/drivers/leds/ledtrig-dim.c b/drivers/leds/ledtrig-dim.c index 04dbaf66a49e..ff99090a0a54 100644 --- a/drivers/leds/ledtrig-dim.c +++ b/drivers/leds/ledtrig-dim.c @@ -17,6 +17,7 @@ #include <linux/timer.h> #include <linux/sched.h> #include <linux/leds.h> +#include <linux/slab.h> #include "leds.h" diff --git a/drivers/pwm/s3c24xx-pwm.c b/drivers/pwm/s3c24xx-pwm.c index 22b742eab9fd..57fe954b61f8 100644 --- a/drivers/pwm/s3c24xx-pwm.c +++ b/drivers/pwm/s3c24xx-pwm.c @@ -27,8 +27,9 @@ #include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/pwm.h> +#include <linux/slab.h> #include <mach/gpio.h> -#include <asm/plat-s3c24xx/pwm.h> +#include <plat/pwm.h> #include <plat/regs-timer.h> #define MAX_TIMER_COUNT 0xffff @@ -420,7 +421,7 @@ static void s3c24xx_pwm_free(struct pwm_channel *p) gpio_free(pch->gpio); } -static int __init s3c24xx_pwmc_probe(struct platform_device *pdev) +static int __devinit s3c24xx_pwmc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct s3c24xx_pwm *np = NULL; @@ -481,7 +482,7 @@ static int __init s3c24xx_pwmc_probe(struct platform_device *pdev) } spin_lock_init(&np->lock); - np->pwm.bus_id = pdev->dev.bus_id; + np->pwm.bus_id = dev_name(&pdev->dev); np->pwm.nchan = pdata->number_channels; /* Copy the external platform data to our internal structure */ |