Implements a common PWM API
Subsystems (5)
cover Implements a common PWM API
This patch series implements a common PWM API. This series incorporates the feedback from the linux-embedded mailing list and elsewhere; the author greatly appreciates the efforts of everyone who reviewed the previous version of this code.
Bill Gatliff (5):
API to consolidate PWM devices behind a common user and kernel
interface
Emulates PWM hardware using a high-resolution timer and a GPIO pin Expunge old Atmel PWMC driver, replacing it with one that conforms to
the PWM API
PWM-based LED control
LED "dimmer" trigger
Documentation/pwm.txt | 260 ++++++++++++++++++ drivers/leds/leds-pwm.c | 224 +++++++++------- drivers/leds/ledtrig-dim.c | 95 +++++++ drivers/misc/Makefile | 6 +- drivers/misc/atmel_pwm.c | 409 ---------------------------- drivers/pwm/atmel-pwm.c | 589 ++++++++++++++++++++++++++++++++++++++++ drivers/pwm/gpio.c | 307 +++++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 -- include/linux/pwm/pwm-led.h | 34 +++ include/linux/pwm/pwm.h | 170 ++++++++++++ 11 files changed, 2217 insertions(+), 541 deletions(-) create mode 100644 Documentation/pwm.txt create mode 100644 drivers/leds/ledtrig-dim.c delete mode 100644 drivers/misc/atmel_pwm.c create mode 100644 drivers/pwm/atmel-pwm.c create mode 100644 drivers/pwm/gpio.c create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm-led.h create mode 100644 include/linux/pwm/pwm.h
PATCH 1/5 API to consolidate PWM devices behind a common user and kernel interface
--- Documentation/pwm.txt | 260 +++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 --- include/linux/pwm/pwm.h | 170 +++++++++++++ 4 files changed, 1063 insertions(+), 31 deletions(-) create mode 100644 Documentation/pwm.txt create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm.h
Documentation/pwm.txt new file +260 -0
@@ -0,0 +1,260 @@ + Generic PWM Device API + + February 1, 2010 + Bill Gatliff + <[email protected]> + + + +The code in drivers/pwm and include/linux/pwm/ implements an API for +applications involving pulse-width-modulation signals. This document +describes how the API implementation facilitates both PWM-generating +devices, and users of those devices. + + + +Motivation + +The primary goals for implementing the "generic PWM API" are to +consolidate the various PWM implementations within a consistent and +redundancy-reducing framework, and to facilitate the use of +hotpluggable PWM devices. + +Previous PWM-related implementations within the Linux kernel achieved +their consistency via cut-and-paste, but did not need to (and didn't) +facilitate more than one PWM-generating device within the system--- +hotplug or otherwise. The Generic PWM Device API might be most +appropriately viewed as an update to those implementations, rather +than a complete rewrite. + + + +Challenges + +One of the difficulties in implementing a generic PWM framework is the +fact that pulse-width-modulation applications involve real-world +signals, which often must be carefully managed to prevent destruction +of hardware that is linked to those signals. A DC motor that +experiences a brief interruption in the PWM signal controlling it +might destructively overheat; it could suddenly change speed, losing +synchronization with a sensor; it could even suddenly change direction +or torque, breaking the mechanical device connected to it. + +(A generic PWM device framework is not directly responsible for +preventing the above scenarios: that responsibility lies with the +hardware designer, and the application and driver authors. But it +must to the greatest extent possible make it easy to avoid such +problems). + +A generic PWM device framework must accommodate the substantial +differences between available PWM-generating hardware devices, without +becoming sub-optimal for any of them. + +Finally, a generic PWM device framework must be relatively +lightweight, computationally speaking. Some PWM users demand +high-speed outputs, plus the ability to regulate those outputs +quickly. A device framework must be able to "keep up" with such +hardware, while still leaving time to do real work. + +The Generic PWM Device API is an attempt to meet all of the above +requirements. At its initial publication, the API was already in use +managing small DC motors, sensors and solenoids through a +custom-designed, optically-isolated H-bridge driver. + + + +Functional Overview + +The Generic PWM Device API framework is implemented in +include/linux/pwm/pwm.h and drivers/pwm/pwm.c. The functions therein +use information from pwm_device, pwm_channel and pwm_channel_config +structures to invoke services in PWM peripheral device drivers. +Consult drivers/pwm/atmel-pwm.c for an example driver. + +There are two classes of adopters of the PWM framework: + + "Users" -- those wishing to employ the API merely to produce PWM + signals; once they have identified the appropriate physical output + on the platform in question, they don't care about the details of + the underlying hardware + + "Driver authors" -- those wishing to bind devices that can generate + PWM signals to the Generic PWM Device API, so that the services of + those devices become available to users. Assuming the hardware can + support the needs of a user, driver authors don't care about the + details of the user's application + +Generally speaking, users will first invoke pwm_request() to obtain a +handle to a PWM device. They will then pass that handle to functions +like pwm_duty_ns() and pwm_period_ns() to set the duty cycle and +period of the PWM signal, respectively. They will also invoke +pwm_start() and pwm_stop() to turn the signal on and off. + +The Generic PWM API framework also provides a sysfs interface to PWM +devices, which is adequate for basic application needs and testing. + +Driver authors fill out a pwm_device structure, which describes the +capabilities of the PWM hardware being constructed--- including the +number of distinct output "channels" the peripheral offers. They then +invoke pwm_register() (usually from within their device's probe() +handler) to make the PWM API aware of their device. The framework +will call back to the methods described in the pwm_device structure as +users begin to configure and utilize the hardware. + +Note that PWM signals can be produced by a variety of peripherals, +beyond the true "PWM hardware" offered by many system-on-chip devices. +Other possibilities include timer/counters with compare-match +capabilities, carefully-programmed synchronous serial ports +(e.g. SPI), and GPIO pins driven by kernel interval timers. With a +proper pwm_device structure, these devices and pseudo-devices can all +be accommodated by the Generic PWM Device API framework. + + + +Using the API to Generate PWM Signals -- Basic Functions for Users + + +pwm_request() -- Returns a pwm_channel pointer, which is subsequently +passed to the other user-related PWM functions. Once requested, a PWM +channel is marked as in-use and subsequent requests prior to +pwm_free() will fail. + +The names used to refer to PWM devices are defined by driver authors. +Typically they are platform device bus identifiers, and this +convention is encouraged for consistency. + + +pwm_free() -- Marks a PWM channel as no longer in use. The PWM device +is stopped before it is released by the API. + + +pwm_period_ns() -- Specifies the PWM signal's period, in nanoseconds. + + +pwm_duty_ns() -- Specifies the PWM signal's active duration, in nanoseconds. + + +pwm_duty_percent() -- Specifies the PWM signal's active duration, as a +percentage of the current period of the signal. NOTE: this value is +not recalculated if the period of the signal is subsequently changed. + + +pwm_start(), pwm_stop() -- Turns the PWM signal on and off. Except +where stated otherwise by a driver author, signals are stopped at the +end of the current period, at which time the output is set to its +inactive state. + + +pwm_polarity() -- Defines whether the PWM signal output's active +region is "1" or "0". A 10% duty-cycle, polarity=1 signal will +conventionally be at 5V (or 3.3V, or 1000V, or whatever the platform +hardware does) for 10% of the period. The same configuration of a +polarity=0 signal will be at 5V (or 3.3V, or ...) for 90% of the +period. + + + +Using the API to Generate PWM Signals -- Advanced Functions + + +pwm_config() -- Passes a pwm_channel_config structure to the +associated device driver. This function is invoked by pwm_start(), +pwm_duty_ns(), etc. and is one of two main entry points to the PWM +driver for the hardware being used. The configuration change is +guaranteed atomic if multiple configuration changes are specified. +This function might sleep, depending on what the device driver has to +do to satisfy the request. All PWM device drivers must support this +entry point. + + +pwm_config_nosleep() -- Passes a pwm_channel_config structure to the +associated device driver. If the driver must sleep in order to +implement the requested configuration change, -EWOULDBLOCK is +returned. Users may call this function from interrupt handlers, for +example. This is the other main entry point into the PWM hardware +driver, but not all device drivers support this entry point. + + +pwm_synchronize(), pwm_unsynchronize() -- "Synchronizes" two or more +PWM channels, if the underlying hardware permits. (If it doesn't, the +framework facilitates emulating this capability but it is not yet +implemented). Synchronized channels will start and stop +simultaneously when any single channel in the group is started or +stopped. Use pwm_unsynchronize(..., NULL) to completely detach a +channel from any other synchronized channels. By default, all PWM +channels are unsynchronized. + + +pwm_set_handler() -- Defines an end-of-period callback. The indicated +function will be invoked in a worker thread at the end of each PWM +period, and can subsequently invoke pwm_config(), etc. Must be used +with extreme care for high-speed PWM outputs. Set the handler +function to NULL to un-set the handler. + + + +Implementing a PWM Device API Driver -- Functions for Driver Authors + + +Fill out the appropriate fields in a pwm_device structure, and submit +to pwm_register(): + + +bus_id -- the plain-text name of the device. Users will bind to a +channel on the device using this name plus the channel number. For +example, the Atmel PWMC's bus_id is "atmel_pwmc", the same as used by +the platform device driver (recommended). The first device registered +thereby receives bus_id "atmel_pwmc.0", which is what you put in +pwm_device.bus_id. Channels are then named "atmel_pwmc.0:[0-3]". +(Hint: just use pdev->dev.bus_id in your probe() method). + + +nchan -- the number of distinct output channels provided by the device. + + +request -- (optional) Invoked each time a user requests a channel. +Use to turn on clocks, clean up register states, etc. The framework +takes care of device locking/unlocking; you will see only successful +requests. + + +free -- (optional) Callback for each time a user relinquishes a +channel. The framework will have already stopped, unsynchronized and +un-handled the channel. Use to turn off clocks, etc. as necessary. + + +synchronize, unsynchronize -- (optional) Callbacks to +synchronize/unsynchronize channels. Some devices provide this +capability in hardware; for others, it can be emulated (see +atmel_pwmc.c's sync_mask for an example). + + +set_callback -- (optional) Invoked when a user requests a handler. If +the hardware supports an end-of-period interrupt, invoke the function +indicated during your interrupt handler. The callback function itself +is always internal to the API, and does not map directly to the user's +callback function. + + +config -- Invoked to change the device configuration, always from a +sleep-capable context. All the changes indicated must be performed +atomically, ideally synchronized to an end-of-period event (so that +you avoid short or long output pulses). You may sleep, etc. as +necessary within this function. + + +config_nosleep -- (optional) Invoked to change device configuration +from within a context that is not allowed to sleep. If you cannot +perform the requested configuration changes without sleeping, return +-EWOULDBLOCK. + + + +Acknowledgements + + +The author expresses his gratitude to the countless developers who +have reviewed and submitted feedback on the various versions of the +Generic PWM Device API code, and those who have submitted drivers and +applications that use the framework. You know who you are. ;) +
drivers/pwm/pwm.c new file +633 -0
633 lines not on this page · raw message
include/linux/pwm.h deleted +0 -31
@@ -1,31 +0,0 @@ -#ifndef __LINUX_PWM_H -#define __LINUX_PWM_H - -struct pwm_device ; - -/* -* pwm_request - request a PWM device -*/ -struct pwm_device *pwm_request (int pwm_id,const char *label); - -/* -* pwm_free - free a PWM device -*/ -void pwm_free (struct pwm_device *pwm); - -/* -* pwm_config - change a PWM device configuration -*/ -int pwm_config (struct pwm_device *pwm,int duty_ns,int period_ns); - -/* -* pwm_enable - start a PWM output toggling -*/ -int pwm_enable (struct pwm_device *pwm); - -/* -* pwm_disable - stop a PWM output toggling -*/ -void pwm_disable (struct pwm_device *pwm); - -#endif /* __LINUX_PWM_H */
include/linux/pwm/pwm.h new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
1.6.5
PATCH 2/5 Emulates PWM hardware using a high-resolution timer and a GPIO pin
--- drivers/pwm/gpio.c | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 drivers/pwm/gpio.c
drivers/pwm/gpio.c new file +307 -0
@@ -0,0 +1,307 @@ +/* +* drivers/pwm/gpio.c +* +* Models a single-channel PWM device using a kernel interval timer +* and a GPIO pin. +* +* Copyright (C) 2010 Bill Gatliff <[email protected]> +* +* This program is free software; you may redistribute 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. +* +* 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/init.h> +#include <linux/hrtimer.h> +#include <linux/err.h> +#include <linux/platform_device.h> +#include <linux/workqueue.h> +#include <mach/gpio.h> +#include <linux/pwm/pwm.h> + +struct gpio_pwm { +struct pwm_device pwm; +struct hrtimer t; +struct work_struct work; +pwm_callback_t callback; +int gpio; +unsigned long polarity :1 ; +unsigned long active :1 ; +}; + +static inline struct gpio_pwm *to_gpio_pwm (const struct pwm_channel *p) +{ + return container_of(p->pwm, struct gpio_pwm, pwm); +} + +static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); + +if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +} + +static enum hrtimer_restart +gpio_pwm_timeout (struct hrtimer *t) +{ + struct gpio_pwm *gp = container_of(t, struct gpio_pwm, t); + +if (unlikely (gp->pwm.channels[0 ].duty_ticks ==0 )) + gp->active =0 ; +else if (unlikely (gp->pwm.channels[0 ].duty_ticks + == gp->pwm.channels[0 ].period_ticks)) + gp->active =1 ; +else + gp->active ^=1 ; + +if (gpio_cansleep (gp->gpio)) +schedule_work (&gp->work); +else +gpio_pwm_work (&gp->work); + +if (!gp->active && gp->pwm.channels[0 ].callback) + gp->pwm.channels[0 ].callback (&gp->pwm.channels[0 ]); + +if (unlikely (!gp->active && + (gp->pwm.channels[0 ].flags &BIT (FLAG_STOP )))) { +clear_bit (FLAG_STOP , &gp->pwm.channels[0 ].flags); +complete_all (&gp->pwm.channels[0 ].complete); +return HRTIMER_NORESTART ; + } + +if (gp->active) +hrtimer_start (&gp->t, +ktime_set (0 , gp->pwm.channels[0 ].duty_ticks), +HRTIMER_MODE_REL ); +else +hrtimer_start (&gp->t, +ktime_set (0 ,gp->pwm.channels[0 ].period_ticks + - gp->pwm.channels[0 ].duty_ticks), +HRTIMER_MODE_REL ); +return HRTIMER_NORESTART ; +} + +static void gpio_pwm_start (struct pwm_channel *p) +{ +struct gpio_pwm *gp =to_gpio_pwm (p); + + gp->active =0 ; +gpio_pwm_timeout (&gp->t); +pr_debug ("%s:%d start, %lu ticks\n" , +dev_name (p->pwm->dev), p->chan, p->duty_ticks); +} + +static int +gpio_pwm_config_nosleep (struct pwm_channel *p, +struct pwm_channel_config *c) +{ +struct gpio_pwm *gp =to_gpio_pwm (p); +int ret =0 ; +unsigned long flags; + +spin_lock_irqsave (&p->lock, flags); + +switch (c->config_mask) { + +case PWM_CONFIG_DUTY_TICKS : + p->duty_ticks = c->duty_ticks; +dev_dbg (p->pwm->dev,":%d duty_ticks %lu\n" , + p->chan, p->duty_ticks); +break ; + +case PWM_CONFIG_START : +if (!hrtimer_active (&gp->t)) { +gpio_pwm_start (p); + } +break ; +default : + ret = -EINVAL ; +break ; + } + +spin_unlock_irqrestore (&p->lock, flags); +return ret; +} + +static int +gpio_pwm_stop_sync (struct pwm_channel *p) +{ +struct gpio_pwm *gp =to_gpio_pwm (p); +int ret; +int was_on =hrtimer_active (&gp->t); + +if (was_on) { +do { +init_completion (&p->complete); +set_bit (FLAG_STOP , &p->flags); + +dev_dbg (p->pwm->dev,":%d waiting on stop_sync completion...\n" , + p->chan); + + ret =wait_for_completion_interruptible (&p->complete); + +dev_dbg (p->pwm->dev,":%d stop_sync complete (%d)\n" , + p->chan, ret); + +if (ret) +return ret; + }while (p->flags &BIT (FLAG_STOP )); + } + +dev_dbg (p->pwm->dev,":%d stop_sync returning %d\n" , + p->chan, was_on); + +return was_on; +} + +static int +gpio_pwm_config (struct pwm_channel *p, +struct pwm_channel_config *c) +{ +struct gpio_pwm *gp =to_gpio_pwm (p); +int was_on =0 ; + +if (p->pwm->config_nosleep) { +if (!p->pwm->config_nosleep (p, c)) +return 0 ; + } + +might_sleep (); +dev_dbg (p->pwm->dev,":%d config_mask %x\n" , + p->chan, c->config_mask); + + was_on =gpio_pwm_stop_sync (p); +if (was_on <0 ) +return was_on; + +if (c->config_mask &PWM_CONFIG_PERIOD_TICKS ) + p->period_ticks = c->period_ticks; + +if (c->config_mask &PWM_CONFIG_DUTY_TICKS ) + p->duty_ticks = c->duty_ticks; + +if (c->config_mask &PWM_CONFIG_POLARITY ) + gp->polarity = c->polarity ?1 :0 ; + +if ((c->config_mask &PWM_CONFIG_START ) + || (was_on && !(c->config_mask &PWM_CONFIG_STOP ))) +gpio_pwm_start (p); + +return 0 ; +} + +static int +gpio_pwm_set_callback (struct pwm_channel *p, +pwm_callback_t callback) +{ +struct gpio_pwm *gp =to_gpio_pwm (p); + gp->callback = callback; +return 0 ; +} + +static int +gpio_pwm_request (struct pwm_channel *p) +{ + p->tick_hz =1000000000UL ; +return 0 ; +} + +static int __devinit +gpio_pwm_probe (struct platform_device *pdev) +{ +struct gpio_pwm *gp; +struct gpio_pwm_platform_data *gpd = pdev->dev.platform_data; +int ret =0 ; + +if (!gpd ||gpio_request (gpd->gpio,dev_name (&pdev->dev))) +return -EINVAL ; + + gp =kzalloc (sizeof (*gp),GFP_KERNEL ); +if (!gp) { + ret = -ENOMEM ; + goto err_alloc; + } + +platform_set_drvdata (pdev, gp); + + gp->pwm.bus_id =dev_name (&pdev->dev); + gp->pwm.nchan =1 ; + gp->gpio = gpd->gpio; + +INIT_WORK (&gp->work, gpio_pwm_work); + +hrtimer_init (&gp->t,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + gp->t.function = gpio_pwm_timeout; + + gp->pwm.owner =THIS_MODULE ; + gp->pwm.config_nosleep = gpio_pwm_config_nosleep; + gp->pwm.config = gpio_pwm_config; + gp->pwm.request = gpio_pwm_request; + gp->pwm.set_callback = gpio_pwm_set_callback; + + ret =pwm_register (&gp->pwm); +if (ret) + goto err_pwm_register; + +return 0 ; + +err_pwm_register: +kfree (gp); +err_alloc: +return ret; +} + +static int __devexit +gpio_pwm_remove (struct platform_device *pdev) +{ +struct gpio_pwm *gp =platform_get_drvdata (pdev); +int ret; + + ret =pwm_unregister (&gp->pwm); +hrtimer_cancel (&gp->t); +cancel_work_sync (&gp->work); +kfree (gp); + +return 0 ; +} + +static struct platform_driver gpio_pwm_driver = { + .driver = { + .name ="gpio_pwm" , + .owner =THIS_MODULE , + }, + .probe = gpio_pwm_probe, + .remove =__devexit_p (gpio_pwm_remove), +}; + +static int __init gpio_pwm_init (void ) +{ +return platform_driver_register (&gpio_pwm_driver); +} +module_init (gpio_pwm_init); + +static void __exit gpio_pwm_exit(void) +{ +platform_driver_unregister (&gpio_pwm_driver); +} +module_exit (gpio_pwm_exit); + +MODULE_AUTHOR ("Bill Gatliff <[email protected]>" ); +MODULE_DESCRIPTION ("PWM output using GPIO and a high-resolution timer" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:gpio_pwm" );
Signature · 1 line
1.6.5
PATCH 3/5 Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API
--- drivers/misc/Makefile | 6 +- drivers/misc/atmel_pwm.c | 409 -------------------------------- drivers/pwm/atmel-pwm.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+), 410 deletions(-) delete mode 100644 drivers/misc/atmel_pwm.c create mode 100644 drivers/pwm/atmel-pwm.c
drivers/misc/Makefile +5 -1
@@ -5,7 +5,11 @@ obj-$(CONFIG_IBM_ASM) += ibmasm/ obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o -obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o +obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o +obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o +obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o +obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o +obj-$(CONFIG_ACER_WMI) += acer-wmi.o obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o obj-$(CONFIG_ICS932S401) += ics932s401.o
drivers/misc/atmel_pwm.c deleted +0 -409
409 lines not on this page · raw message
drivers/pwm/atmel-pwm.c new file +589 -0
589 lines not on this page · raw message
Signature · 1 line
1.6.5
PATCH 4/5 PWM-based LED control
--- drivers/leds/leds-pwm.c | 224 ++++++++++++++++++++++++------------------- include/linux/pwm/pwm-led.h | 34 +++++++ 2 files changed, 158 insertions(+), 100 deletions(-) create mode 100644 include/linux/pwm/pwm-led.h
drivers/leds/leds-pwm.c +124 -100
@@ -1,152 +1,176 @@/* -* linux/drivers/leds-pwm.c +* drivers/leds/leds-pwm.c * -* simple PWM based LED control +* Copyright (C) 2010 Bill Gatliff <[email protected]> +* Copyright (C) 2009 Loutao Fu, Pengutronix <[email protected]> * -* Copyright 2009 Luotao Fu @ Pengutronix ([email protected]) +* Based on leds-gpio.c by Raphael Assenat <[email protected]> * -* based on leds-gpio.c by Raphael Assenat <[email protected]> -* -* 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 +* This program is Free Software. You may redistribute 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. +* +* 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/pwm.h> -#include <linux/leds_pwm.h> - -struct led_pwm_data { -struct led_classdev cdev; -struct pwm_device *pwm; -unsigned int active_low; -unsigned int period; +#include <linux/io.h> +#include <linux/pwm/pwm.h> +#include <linux/pwm/pwm-led.h> + +struct led_pwm { +struct led_classdev led; +struct pwm_channel *pwm; +int percent; }; -static void led_pwm_set (struct led_classdev *led_cdev, -enum led_brightness brightness) +static inline struct led_pwm *to_led_pwm (const struct led_classdev *c) +{ + return container_of(c, struct led_pwm, led); +} + +static void +led_pwm_brightness_set (struct led_classdev *c, +enum led_brightness b) +{ +struct led_pwm *led =to_led_pwm (c); +int percent; + + percent = (b *100 ) / (LED_FULL -LED_OFF ); + led->percent = percent; +pwm_set_duty_percent (led->pwm, percent); +} + +static enum led_brightness +led_pwm_brightness_get (struct led_classdev *c) +{ +struct led_pwm *led =to_led_pwm (c); +return led->percent; +} + +static int +led_pwm_blink_set (struct led_classdev *c, +unsigned long *on_ms, +unsigned long *off_ms) { -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 =to_led_pwm (c); +struct pwm_channel_config cfg; + +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 *1000000UL ; + cfg.period_ns = (*on_ms + *off_ms) *1000000UL ; + +return pwm_config (led->pwm, &cfg); } -static int led_pwm_probe (struct platform_device *pdev) +static int __devinit +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; +struct device *d = &pdev->dev; +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; -kfree (leds_data); +return 0 ; + +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 __devexit +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); +struct device *d = &pdev->dev; - 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);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); } +module_init (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 <[email protected]>" ); -MODULE_DESCRIPTION ("PWM LED driver for PXA" ); +MODULE_AUTHOR ("Bill Gatliff <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for LEDs with PWM-controlled brightness" );MODULE_LICENSE ("GPL" );MODULE_ALIAS ("platform:leds-pwm" );
include/linux/pwm/pwm-led.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef __LINUX_PWM_LED_H +#define __LINUX_PWM_LED_H + +/* +* include/linux/pwm-led.h +* +* Copyright (C) 2008 Bill Gatliff +* +* 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. +* +* 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 +*/ + +struct led_info ; +struct pwm_channel_config ; + +struct pwm_led_platform_data { +const char *bus_id; +int chan; +struct pwm_channel_config *config; +struct led_info *led_info; +}; + +#endif /* __LINUX_PWM_LED_H */
Signature · 1 line
1.6.5
PATCH 5/5 LED "dimmer" trigger
--- drivers/leds/ledtrig-dim.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 95 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/ledtrig-dim.c
drivers/leds/ledtrig-dim.c new file +95 -0
@@ -0,0 +1,95 @@ +/* +* LED Dim Trigger +* +* Copyright (C) 2008 Bill Gatliff <[email protected]> +* +* "Dims" an LED based on system load. Derived from Atsushi Nemoto's +* ledtrig-heartbeat.c. +* +* 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 <linux/module.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/timer.h> +#include <linux/sched.h> +#include <linux/leds.h> + +#include "leds.h" + +struct dim_trig_data { +struct timer_list timer; +}; + + +static void +led_dim_function (unsigned long data) +{ +struct led_classdev *led_cdev = (struct led_classdev *)data; +struct dim_trig_data *dim_data = led_cdev->trigger_data; +unsigned int brightness; + + brightness = ((LED_FULL -LED_OFF ) * avenrun[0 ]) /EXP_1 ; +if (brightness >LED_FULL ) + brightness =LED_FULL ; + +led_set_brightness (led_cdev, brightness); +mod_timer (&dim_data->timer, jiffies +msecs_to_jiffies (500 )); +} + + +static void +dim_trig_activate (struct led_classdev *led_cdev) +{ +struct dim_trig_data *dim_data; + + dim_data =kzalloc (sizeof (*dim_data),GFP_KERNEL ); +if (!dim_data) +return ; + + led_cdev->trigger_data = dim_data; +setup_timer (&dim_data->timer, + led_dim_function, (unsigned long )led_cdev); +led_dim_function (dim_data->timer.data); +} + + +static void +dim_trig_deactivate (struct led_classdev *led_cdev) +{ +struct dim_trig_data *dim_data = led_cdev->trigger_data; + +if (dim_data) { +del_timer_sync (&dim_data->timer); +kfree (dim_data); + } +} + + +static struct led_trigger dim_led_trigger = { + .name ="dim" , + .activate = dim_trig_activate, + .deactivate = dim_trig_deactivate, +}; + + +static int __init dim_trig_init (void ) +{ +return led_trigger_register (&dim_led_trigger); +} +module_init (dim_trig_init); + + +static void __exit dim_trig_exit(void) +{ +led_trigger_unregister (&dim_led_trigger); +} +module_exit (dim_trig_exit); + + +MODULE_AUTHOR ("Bill Gatliff <[email protected]>" ); +MODULE_DESCRIPTION ("Dim LED trigger" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
1.6.5
Re: [PWM PATCH 3/5] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API
In reply to Bill GatliffQuoted 6 lines · Bill Gatliff
drivers/misc/Makefile +0
-0
drivers/misc/Makefile line 13
Quoted 10 lines
drivers/misc/Makefile +5
-1@@ -5,7 +5,11 @@ obj-$(CONFIG_IBM_ASM) += ibmasm/ obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o -obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o +obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o +obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o +obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o +obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o +obj-$(CONFIG_ACER_WMI) += acer-wmi.o
Darn it!! I'll clean this one up in the final post.
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
RE: [PWM PATCH 3/5] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API
In reply to Bill GatliffQuoted 8 lines · Bill Gatliff
Signed-off-by Bill Gatliff <[email protected]>--- drivers/misc/Makefile | 6 +- drivers/misc/atmel_pwm.c | 409 -------------------------------- drivers/pwm/atmel-pwm.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+), 410 deletions(-) delete mode 100644 drivers/misc/atmel_pwm.c create mode 100644 drivers/pwm/atmel-pwm.c
A couple quick comments, more after a better review.
[snip]
Quoted 5 lines
drivers/misc/atmel_pwm.c deleted +0
-0
[snip]
Quoted 5 lines
drivers/misc/atmel_pwm.c deleted +0
-5-static struct platform_driver atmel_pwm_driver = { - .driver = { - .name ="atmel_pwm" , - .owner =THIS_MODULE , - },
[snip]
Quoted 8 lines
drivers/misc/atmel_pwm.c deleted +0
-3-MODULE_DESCRIPTION ("Driver for AT32/AT91 PWM module" ); -MODULE_LICENSE ("GPL" ); -MODULE_ALIAS ("platform:atmel_pwm" );drivers/pwm/atmel-pwm.c new file +0
-0
[snip]
Quoted 5 lines
drivers/pwm/atmel-pwm.c new file +5
-0+static struct platform_driver atmel_pwm_driver = { + .driver = { + .name ="atmel_pwmc" , + .owner =THIS_MODULE , + },
[snip]
drivers/pwm/atmel-pwm.c line 589
Quoted 4 lines
drivers/pwm/atmel-pwm.c new file +4
-0+MODULE_AUTHOR ("Bill Gatliff <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for Atmel PWMC peripheral" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:atmel_pwmc" );
You have a couple name changes here, were they intentional?
Filename: atmel_pwm.c -> atmel-pwm.c
Driver name: atmel_pwm -> atmel_pwmc
Module alias: platform:atmel_pwm -> platform:atmel_pwmc
Also, will this new driver still work for all the existing users of the old one? Are there any platform changes that need to be done?
Regards,
Hartley
Re: [PWM PATCH 3/5] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API
Quoted 8 lines · H Hartley Sweeten
You have a couple name changes here, were they intentional?
Filename: atmel_pwm.c -> atmel-pwm.cDriver name:
atmel_pwm->atmel_pwmc
Module alias: platform:atmel_pwm -> platform:atmel_pwmc
Yes. In the datasheet, the peripheral is called the "PWMC" and so that's why the driver name changed. For consistency, I guess I should have named the file atmel-pwmc.c as well. Finally, I find it easier to type file names with dashes rather than underscores. :)
Quoted 3 lines
Also, will this new driver still work for all the existing users of the old one? Are there any platform changes that need to be done?
There are platform changes necessary, to register and use the devices. The driver API is different from the previous code, so there are changes there as well. Functionally, however, the new stuff is a superset of what the previous driver provided.
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
In reply to Bill Gatliffdrivers/pwm/gpio.c line 57
Quoted 11 lines
drivers/pwm/gpio.c new file +10
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); + +if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}
...polarity ^ active ?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
Quoted 5 lines · Pavel Machek
Quoted 5 lines
drivers/pwm/gpio.c new file +5
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); +
Quoted 9 lines
drivers/pwm/gpio.c line 57
Quoted 6 lines
drivers/pwm/gpio.c new file +5
-0+if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}...polarity ^ active ?
... except that if polarity and/or active are >1, I don't send the values 1 or 0 to gpio_direction_output. I don't know if the API is specifically intended to accept nonzero values that are greater than 1.
b.g.
Signature · 4 lines
Bill Gatliff Embedded systems training and consulting http://billgatliff.com [email protected]
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
Quoted 16 lines · Bill Gatliff
Quoted 5 lines · Pavel Machek
Quoted 5 lines
drivers/pwm/gpio.c new file +5
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); +Quoted 9 lines
drivers/pwm/gpio.c line 57
Quoted 6 lines
drivers/pwm/gpio.c new file +5
-0+if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}...polarity ^ active ?
Quoted 3 lines
... except that if polarity and/or active are >1, I don't send the values 1 or 0 to
gpio_direction_output. I don't know if the API is specifically intended to accept nonzero values that are greater than 1.
!polarity ^ !active ? :-).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
11.02.2010, в 23:58, Pavel Machek написал(а):
Quoted 17 lines · Bill Gatliff
Quoted 16 lines
Quoted 14 lines · Pavel Machek
drivers/pwm/gpio.c line 57
Quoted 11 lines
drivers/pwm/gpio.c new file +10
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); + +if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}...polarity ^ active ?
Quoted 5 lines
Quoted 3 lines
... except that if polarity and/or active are >1, I don't send the values 1 or 0 to
gpio_direction_output. I don't know if the API is specifically intended to accept nonzero values that are greater than 1.!polarity ^ !active ? :-).
One the one hand that wouldn't be 100% right because according to ANSI C !(0) is just != 0 but no one says it is 1.
On another hand as far as I can see polarity and active fields are both defined as "unsigned long <name> :1" in the gpio_pwm structure. And that means they can be equal only to 0 or 1. So simple (polarity ^ active) is the right choice as far as the original decision.
What is strange for me is that resulting control flow is not right representation of what is happening. I mean that actually one should perform a call to an external function with an argument that depends on values of two variables. While this code is equal to call function A if some variable is not equal to 0 with argument depending on value of some other variable else call function B. I hope you understood what I'm trying to say. Therefore even if you wish to leave if statement (not sure that gcc would optimize that) the right control flow representation should be the following:
.....
if (gp->active) value = ((gp->polarity)?1:0); else value = ((gp->polarity)?0:1); gpio_direction_output(gp->gpio, value);
.....
The second strange thing is "unsigned long <name>:1". I'm not sure but as far as I can remember the right way to define several-bits field is "int <name>:1". But I might be mistaken.
Best regards. Stas.
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
2010/2/12 Stanislav O. Bezzubtsev <[email protected]>:
Quoted 1 line
The second strange thing is "unsigned long <name>:1". I'm not sure but as far as I can remember the right way to define several-bits field is "int <name>:1". But I might be mistaken.
A bitfield of size 1 should not be signed, as there's no space for a sign bit. Usually, you want all bitfields to be unsigned anyway.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
In reply to Stanislav O. BezzubtsevQuoted 24 lines
11.02.2010, ? 23:58, Pavel Machek ???????(?):
Quoted 21 lines · Bill Gatliff
Quoted 19 lines
Quoted 5 lines · Pavel Machek
Quoted 5 lines
drivers/pwm/gpio.c new file +5
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); +Quoted 9 lines
drivers/pwm/gpio.c line 57
Quoted 6 lines
drivers/pwm/gpio.c new file +5
-0+if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}...polarity ^ active ?
... except that if polarity and/or active are >1, I don't send the values 1 or 0 to
gpio_direction_output. I don't know if the API is specifically intended to accept nonzero values that are greater than 1.
Quoted 5 lines
Quoted 1 line
!polarity ^ !active ? :-).
One the one hand that wouldn't be 100% right because according to ANSI C !(0) is just != 0 but no one says it is 1.
I believe you are wrong here.
!!x is common idiom using to turn anything into 0/1, used all over kernel.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
RE: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
In reply to Bill GatliffQuoted 16 lines · Bill Gatliff
Quoted 5 lines · Pavel Machek
Quoted 5 lines
drivers/pwm/gpio.c new file +5
-0+static void +gpio_pwm_work (struct work_struct *work) +{ + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work); +Quoted 9 lines
drivers/pwm/gpio.c line 57
Quoted 6 lines
drivers/pwm/gpio.c new file +5
-0+if (gp->active) +gpio_direction_output (gp->gpio, gp->polarity ?1 :0 ); +else +gpio_direction_output (gp->gpio, gp->polarity ?0 :1 ); +}...polarity ^ active ?
Quoted 3 lines
... except that if polarity and/or active are >1, I don't send the values 1 or 0 to
gpio_direction_output. I don't know if the API is specifically intended to accept nonzero values that are greater than 1.
FWIW, the gpiolib API will accept any non-zero value to "set" a gpio pin and a zero value to "clear" the pin.
For that matter, some of the gpiolib drivers end up returning the bit position mask for a given gpio pin and not 1 or 0. For instance if the gpio pin in question is bit 6 in an 8-bit register and it is set, a __gpio_get_value will end up returning 0x40 and not '1'.
Regards,
Hartley
Re: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
Quoted 4 lines · H Hartley Sweeten
FWIW, the gpiolib API will accept any non-zero value to "set" a gpio pin and a zero value to "clear" the pin.
It makes me sort of cringe to say this, but I'm going to assume that the API is intended to work that way so that I can take advantage of it. But I'd love to someday have the reassurance that gpiolib really *is* intended to work that way (might be a bad idea though, see below). Call me paranoid, but I've lost a lot of hair over the years undoing the damage of similar failed assumptions.
I've found the Linux kernel code to be refreshingly forgiving of such things, however, so I'm willing to risk it this time. :)
Quoted 5 lines
For that matter, some of the gpiolib drivers end up returning the bit position mask for a given gpio pin and not 1 or 0. For instance if the gpio pin in question is bit 6 in an 8-bit register and it is set, a
__gpio_get_valuewill end up returning0x40and not '1'.
Who's to say that gpios should always be boolean? On the output side, a "gpio" that's four bits wide might be a useful way of dealing with bar graphs, seven-segment displays, etc. (but more specialized abstractions might be more appropriate, of course).
A two-bit "gpio" input might make it easier to deal with rotary encoders.
But for now, GPIOs are assumed to be booleans and that's why I'm hesitant to feed the API non-boolean values. Someday, those values might mean something subtly but disastrously different. And given my luck lately with such things...
b.g.
Signature · 4 lines
Bill Gatliff Embedded systems training and consulting http://billgatliff.com [email protected]
RE: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
Quoted 22 lines · Bill Gatliff
Quoted 4 lines · H Hartley Sweeten
FWIW, the gpiolib API will accept any non-zero value to "set" a gpio pin and a zero value to "clear" the pin.
It makes me sort of cringe to say this, but I'm going to assume that the API is intended to work that way so that I can take advantage of it. But I'd love to someday have the reassurance that gpiolib really *is* intended to work that way (might be a bad idea though, see below). Call me paranoid, but I've lost a lot of hair over the years undoing the damage of similar failed assumptions.
I've found the Linux kernel code to be refreshingly forgiving of such things, however, so I'm willing to risk it this time. :)
Quoted 5 lines
For that matter, some of the gpiolib drivers end up returning the bit position mask for a given gpio pin and not 1 or 0. For instance if the gpio pin in question is bit 6 in an 8-bit register and it is set, a
__gpio_get_valuewill end up returning0x40and not '1'.
Quoted 4 lines
Who's to say that gpios should always be boolean? On the output side, a "gpio" that's four bits wide might be a useful way of dealing with bar graphs, seven-segment displays, etc. (but more specialized abstractions might be more appropriate, of course).
I think the original intention of gpiolib was to deal with individual pins.
Quoted 1 line
A two-bit "gpio" input might make it easier to deal with rotary encoders.
True. But a two-bit "gpio" is no longer a "pin" it's now a "port".
I have been messing with a "port" extension for gpiolib but it's not even close to being mergable yet. But, that's a different topic...
Quoted 4 lines
But for now, GPIOs are assumed to be booleans and that's why I'm hesitant to feed the API non-boolean values. Someday, those values might mean something subtly but disastrously different. And given my luck lately with such things...
True. As such just use ! and !! to make the values boolean.
gpio is bit 6
val = 0x40 -> !(0x40) = 0
val = 0x40 -> !!(0x40) = 1
Just my .02... Regards,
Hartley
RE: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
In reply to Bill GatliffQuoted 11 lines · Bill Gatliff
Signed-off-by Bill Gatliff <[email protected]>--- Documentation/pwm.txt | 260 +++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 --- include/linux/pwm/pwm.h | 170 +++++++++++++ 4 files changed, 1063 insertions(+), 31 deletions(-) create mode 100644 Documentation/pwm.txt create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm.h
A couple quick comments, more after a better review.
[snip]
Quoted 5 lines
drivers/pwm/pwm.c new file +0
-0
[snip]
Quoted 2 lines
drivers/pwm/pwm.c new file +2
-0+int pwm_unregister (struct pwm_device *pwm) +{
[snip]
drivers/pwm/pwm.c
Quoted 2 lines
drivers/pwm/pwm.c new file +2
-0+for (wchan =0 ; wchan < pwm->nchan; wchan++) { +if (pwm->channels[wchan].flags &FLAG_REQUESTED ) {
Shouldn't this be:
& BIT(FLAG_REQUESTED)
[snip]
include/linux/pwm/pwm.h line 2
Quoted 8 lines
include/linux/pwm/pwm.h new file +2
-0@@ -0,0 +1,170 @@ +#ifndef __LINUX_PWM_H +#define __LINUX_PWM_H
Nitpick... Can you move the #ifndef/#define to after the comment?
Regards,
Hartley
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
Quoted 9 lines · H Hartley Sweeten
Review
Quoted 3 lines
(quoted diff) +2
-0+ for (wchan = 0; wchan < pwm->nchan; wchan++) { + if (pwm->channels[wchan].flags & FLAG_REQUESTED) {Shouldn't this be:
&
BIT(FLAG_REQUESTED)
Yes. I've fixed that one several times now! I think I need to review my git-fu, especially rebasing.
Quoted 2 lines
Nitpick... Can you move the #ifndef/#define to after the comment?
I did that in all the others, I guess I missed this one...
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
RE: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
In reply to Bill GatliffQuoted 11 lines · Bill Gatliff
Signed-off-by Bill Gatliff <[email protected]>--- Documentation/pwm.txt | 260 +++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 --- include/linux/pwm/pwm.h | 170 +++++++++++++ 4 files changed, 1063 insertions(+), 31 deletions(-) create mode 100644 Documentation/pwm.txt create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm.h
[snip]
Quoted 5 lines
drivers/pwm/pwm.c new file +0
-0
[snip]
Quoted 32 lines
drivers/pwm/pwm.c new file +32
-0+int pwm_register (struct pwm_device *pwm) +{ +struct pwm_channel *p; +int wchan; +int ret; + +spin_lock_init (&pwm->list_lock); + + p =kcalloc (pwm->nchan,sizeof (*p),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + +for (wchan =0 ; wchan < pwm->nchan; wchan++) { +spin_lock_init (&p[wchan].lock); +init_completion (&p[wchan].complete); + p[wchan].chan = wchan; + p[wchan].pwm = pwm; + } + + pwm->channels = p; + +mutex_lock (&device_list_mutex); + +list_add_tail (&pwm->list, &pwm_device_list); + ret =__pwm_create_sysfs (pwm); +if (ret) { +mutex_unlock (&device_list_mutex); + goto err_create_sysfs; + } + +mutex_unlock (&device_list_mutex); +
drivers/pwm/pwm.c line 79
Quoted 10 lines
drivers/pwm/pwm.c new file +10
-0+dev_info (pwm->dev,"%d channel%s\n" , pwm->nchan, + pwm->nchan >1 ?"s" :"" ); +return 0 ; + +err_create_sysfs: +kfree (p); + +return ret; +} +EXPORT_SYMBOL (pwm_register);
Bill,
I'm trying to test your latest pwm patches using the ep93xx pwm driver I wrote based on your previous patches. I'm getting an Oops when booting this that is hanging my system. I put in the printascii hack to see what's going on and got this:
<1>Unable to handle kernel NULL pointer dereference at virtual address 00000044 <1>pgd = c0004000
<1>[00000044] *pgd=00000000
<0>Internal error: Oops: 5 [#1] PREEMPT
<0>last sysfs file:
<d>Modules linked in:
CPU: 0 Not tainted (2.6.32.7 #5) PC is at dev_driver_string+0x0/0x38 LR is at pwm_register+0x17c/0x1e8 pc : [<c01b1b10>] lr : [<c0187dfc>] psr: 60000013
sp : c581bee0 ip : c036efa5 fp : 00000000
r10: c4511e60 r9 : 00000000 r8 : 00000000
r7 : c036ef6c r6 : 00000050 r5 : c44c9b20 r4 : 00000001
r3 : 00000001 r2 : 00000001 r1 : 00000000 r0 : 00000000
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: c000717f Table: c0004000 DAC: 00000017
<0>Process swapper (pid: 1, stack limit = 0xc581a270)
<0>Stack: (0xc581bee0 to 0xc581c000)
<0>bee0: c036ef6c c58449a0 00000000 c44c9b20 00000000 c44c9b20 00000000 c03bece8 <0>bf00: c58839c0 c03bece0 00000000 c0016784 00000000 00000000 c03bece8 c03bece8 <0>bf20: c03d105c c03d105c c03d4c40 c01b5e70 c03d105c c01b4f08 c0054498 c03bece8 <0>bf40: c03bed1c c03d105c c581bf60 c01b5038 00000000 c01b4fdc c03d105c c01b473c <0>bf60: c58034d8 c5852dd0 c03d4c40 c00211c4 c03d105c c03d105c c4511ec0 c01b4028 <0>bf80: c0351a5d c581bf90 c01756c4 c00211c4 c002133c c03d105c c001666c 00000001 <0>bfa0: 00000000 c01b533c c00211c4 c002133c 00000000 c001666c 00000001 c00273a8 <0>bfc0: 00000000 00000078 c03c2aa0 00000000 c00211c4 c002133c 00000000 00000000 <0>bfe0: 00000000 c0008588 00000000 00000000 00000000 c00289d4 33cc33cc 33cc33cc [<c01b1b10>] (dev_driver_string+0x0/0x38) from [<c0187dfc>] (pwm_register+0x17c/0x1e8) [<c0187dfc>] (pwm_register+0x17c/0x1e8) from [<c0016784>] (ep93xx_pwm_probe+0x10c/0x17c) [<c0016784>] (ep93xx_pwm_probe+0x10c/0x17c) from [<c01b5e70>] (platform_drv_probe+0x1c/0x24) [<c01b5e70>] (platform_drv_probe+0x1c/0x24) from [<c01b4f08>] (driver_probe_device+0xac/0x180) [<c01b4f08>] (driver_probe_device+0xac/0x180) from [<c01b5038>] (__driver_attach+0x5c/0x7c) [<c01b5038>] (__driver_attach+0x5c/0x7c) from [<c01b473c>] (bus_for_each_dev+0x50/0x90) [<c01b473c>] (bus_for_each_dev+0x50/0x90) from [<c01b4028>] (bus_add_driver+0xa0/0x224) [<c01b4028>] (bus_add_driver+0xa0/0x224) from [<c01b533c>] (driver_register+0xbc/0x14c) [<c01b533c>] (driver_register+0xbc/0x14c) from [<c00273a8>] (do_one_initcall+0x60/0x1c0) [<c00273a8>] (do_one_initcall+0x60/0x1c0) from [<c0008588>] (kernel_init+0x9c/0x114) [<c0008588>] (kernel_init+0x9c/0x114) from [<c00289d4>] (kernel_thread_exit+0x0/0x8) <0>Code: c03c5c28 000080d0 c03d49c8 c03d4958 (e5903044)
<4>---[ end trace da227214a82491b7 ]---
<0>Kernel panic - not syncing: Attempted to kill init!
[<c002c7dc>] (unwind_backtrace+0x0/0xdc) from [<c02d7050>] (panic+0x3c/0x128) [<c02d7050>] (panic+0x3c/0x128) from [<c003ee2c>] (do_exit+0x60/0x608) [<c003ee2c>] (do_exit+0x60/0x608) from [<c002b5f8>] (die+0x178/0x19c) [<c002b5f8>] (die+0x178/0x19c) from [<c002db1c>] (__do_kernel_fault+0x68/0x80) [<c002db1c>] (__do_kernel_fault+0x68/0x80) from [<c002dcf8>] (do_page_fault+0x1c4/0x1dc) [<c002dcf8>] (do_page_fault+0x1c4/0x1dc) from [<c00272e8>] (do_DataAbort+0x34/0x94) [<c00272e8>] (do_DataAbort+0x34/0x94) from [<c0027ae0>] (__dabt_svc+0x40/0x60)
Exception stack(0xc581be98 to 0xc581bee0)
be80: 00000000 00000000
bea0: 00000001 00000001 00000001 c44c9b20 00000050 c036ef6c 00000000 00000000
bec0: c4511e60 00000000 c036efa5 c581bee0 c0187dfc c01b1b10 60000013 ffffffff [<c0027ae0>] (__dabt_svc+0x40/0x60) from [<c01b1b10>] (dev_driver_string+0x0/0x38) [<c01b1b10>] (dev_driver_string+0x0/0x38) from [<c0187dfc>] (pwm_register+0x17c/0x1e8) [<c0187dfc>] (pwm_register+0x17c/0x1e8) from [<c0016784>] (ep93xx_pwm_probe+0x10c/0x17c) [<c0016784>] (ep93xx_pwm_probe+0x10c/0x17c) from [<c01b5e70>] (platform_drv_probe+0x1c/0x24) [<c01b5e70>] (platform_drv_probe+0x1c/0x24) from [<c01b4f08>] (driver_probe_device+0xac/0x180) [<c01b4f08>] (driver_probe_device+0xac/0x180) from [<c01b5038>] (__driver_attach+0x5c/0x7c) [<c01b5038>] (__driver_attach+0x5c/0x7c) from [<c01b473c>] (bus_for_each_dev+0x50/0x90) [<c01b473c>] (bus_for_each_dev+0x50/0x90) from [<c01b4028>] (bus_add_driver+0xa0/0x224) [<c01b4028>] (bus_add_driver+0xa0/0x224) from [<c01b533c>] (driver_register+0xbc/0x14c) [<c01b533c>] (driver_register+0xbc/0x14c) from [<c00273a8>] (do_one_initcall+0x60/0x1c0) [<c00273a8>] (do_one_initcall+0x60/0x1c0) from [<c0008588>] (kernel_init+0x9c/0x114) [<c0008588>] (kernel_init+0x9c/0x114) from [<c00289d4>] (kernel_thread_exit+0x0/0x8)
Your older patch just used printk's to output the messages. I think the Oops is being caused by the dev_<level>(pwm->dev, ...). Where is pwm->dev being setup?
Regards,
Hartley
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
Quoted 5 lines · H Hartley Sweeten
Your older patch just used printk's to output the messages. I think the Oops is being caused by the dev_<level>(pwm->dev, ...). Where is
pwm->devbeing setup?
Good question! Makes me think that it isn't...
I'm traveling back to my office at the moment, should be back in late tomorrow or Friday a.m. I'll look at this then.
The intention was to save the result from device_create() called from __pwm_create_sysfs(), but I'm suspicious that the patch I posted doesn't have that code for some reason. My local git repo here doesn't seem to have it. Hmmm...
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
Quoted 8 lines · Bill Gatliff
Quoted 5 lines · H Hartley Sweeten
Your older patch just used printk's to output the messages. I think the Oops is being caused by the dev_<level>(pwm->dev, ...). Where is
pwm->devbeing setup?
Quoted 5 lines
The intention was to save the result from
device_create()called from__pwm_create_sysfs(), but I'm suspicious that the patch I posted doesn't have that code for some reason. My local git repo here doesn't seem to have it. Hmmm...
No, that's not right. Disregard the above.
If the PWM device in question is already known to the kernel, then before you call pwm_register() you must set pwm->dev to the address of that device structure. I need to come up with a better way to handle this.
If the PWM device isn't already known to the kernel as a true struct device, then I don't yet have a Plan B. Drat. :(
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
In reply to Bill GatliffHi!
Documentation/pwm.txt line 41
Quoted 10 lines
Documentation/pwm.txt new file +10
-0+Challenges + +One of the difficulties in implementing a generic PWM framework is the +fact that pulse-width-modulation applications involve real-world +signals, which often must be carefully managed to prevent destruction +of hardware that is linked to those signals. A DC motor that +experiences a brief interruption in the PWM signal controlling it +might destructively overheat; it could suddenly change speed, losing +synchronization with a sensor; it could even suddenly change direction +or torque, breaking the mechanical device connected to it.
Stop right here. Linux is not hard realtime os, nor is it an os that never crashes.
Documentation/pwm.txt line 45
Quoted 3 lines
Documentation/pwm.txt new file +3
-0+(A generic PWM device framework is not directly responsible for +preventing the above scenarios: that responsibility lies with the +hardware designer, and the application and driver authors. But it
Exactly; if your hw can be damaged by software, it was misdesigned.
Is the paragraph #1 really neccessary?
Quoted 5 lines
Documentation/pwm.txt new file +5
-0+Using the API to Generate PWM Signals -- Basic Functions for Users + + +pwm_request() -- Returns a pwm_channel pointer, which is subsequently +passed to the other user-related PWM functions. Once requested, a PWM
Documentation/pwm.txt line 128
Quoted 10 lines
Documentation/pwm.txt new file +10
-0+channel is marked as in-use and subsequent requests prior to +pwm_free() will fail. + +The names used to refer to PWM devices are defined by driver authors. +Typically they are platform device bus identifiers, and this +convention is encouraged for consistency. + + +pwm_free() -- Marks a PWM channel as no longer in use. The PWM device +is stopped before it is released by the API.
free is normally used for something else. Rename to open/close?
Documentation/pwm.txt line 145
Quoted 4 lines
Documentation/pwm.txt new file +4
-0+pwm_start(), pwm_stop() -- Turns the PWM signal on and off. Except +where stated otherwise by a driver author, signals are stopped at the +end of the current period, at which time the output is set to its +inactive state.
What does it mean to stop a signal? What is the difference between 0% duty cycle and stop() ?
Documentation/pwm.txt line 153
Quoted 6 lines
Documentation/pwm.txt new file +6
-0+pwm_polarity() -- Defines whether the PWM signal output's active +region is "1" or "0". A 10% duty-cycle, polarity=1 signal will +conventionally be at 5V (or 3.3V, or 1000V, or whatever the platform +hardware does) for 10% of the period. The same configuration of a +polarity=0 signal will be at 5V (or 3.3V, or ...) for 90% of the +period.
Is polarity realy required? Can't driver just replace duty with 100%-duty?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
Quoted 4 lines · Pavel Machek
Exactly; if your hw can be damaged by software, it was misdesigned.
Is the paragraph #1 really neccessary?
It provides a little background on the subject matter. I don't think it's mandatory, but I don't see the harm in keeping it. I think it improves the document overall from an editorial perspective, however.
Quoted 6 lines
Documentation/pwm.txt line 128
Quoted 3 lines
Documentation/pwm.txt new file +2
-0+pwm_free() -- Marks a PWM channel as no longer in use. The PWM device +is stopped before it is released by the API.free is normally used for something else. Rename to open/close?
... or request/release?
Quoted 9 lines
Documentation/pwm.txt line 145
Quoted 5 lines
Documentation/pwm.txt new file +4
-0+pwm_start(), pwm_stop() -- Turns the PWM signal on and off. Except +where stated otherwise by a driver author, signals are stopped at the +end of the current period, at which time the output is set to its +inactive state.What does it mean to stop a signal? What is the difference between 0% duty cycle and
stop()?
Depends on the hardware. For a true PWM peripheral, a 0% duty cycle might still have the base peripheral clock for the device running. Whereas a pwm_stop() signal could be used to turn off the clock to the peripheral.
Quoted 2 lines
Is polarity realy required? Can't driver just replace duty with 100%-duty
Actually, yes in some cases. Users can always do the 100%-duty math, but some hardware asserts a specific output state when you stop the peripheral that's potentially different from 0% duty. Also, some hardware begins the PWM cycle with the output high, while others do with the output low. It isn't necessarily the case that the user cares, but I was thinking that having the API allow for different polarity might prevent some applications having to optionally do the %duty vs. 100-%duty conversion themselves.
b.g.
Signature · 4 lines
Bill Gatliff Embedded systems training and consulting http://billgatliff.com [email protected]
Re: [PWM PATCH 1/5] API to consolidate PWM devices behind a common user and kernel interface
Quoted 8 lines
Quoted 6 lines
Documentation/pwm.txt line 128
Quoted 4 lines
Documentation/pwm.txt new file +2
-0+pwm_free() -- Marks a PWM channel as no longer in use. The PWM device +is stopped before it is released by the API.free is normally used for something else. Rename to open/close?
... or request/release?
Works for me.
Quoted 10 lines
Quoted 9 lines
Documentation/pwm.txt line 145
Quoted 5 lines
Documentation/pwm.txt new file +4
-0+pwm_start(), pwm_stop() -- Turns the PWM signal on and off. Except +where stated otherwise by a driver author, signals are stopped at the +end of the current period, at which time the output is set to its +inactive state.What does it mean to stop a signal? What is the difference between 0% duty cycle and
stop()?
Quoted 4 lines
Depends on the hardware. For a true PWM peripheral, a 0% duty cycle might still have the base peripheral clock for the device running. Whereas a
pwm_stop()signal could be used to turn off the clock to the peripheral.
If it is just powersaving... I'd do it automatically when 0% duty is selected...? Or is that infeasible due to latency...?
Quoted 11 lines
Quoted 2 lines
Is polarity realy required? Can't driver just replace duty with 100%-duty
Actually, yes in some cases. Users can always do the 100%-duty math, but some hardware asserts a specific output state when you stop the peripheral that's potentially different from 0% duty. Also, some hardware begins the PWM cycle with the output high, while others do with the output low. It isn't necessarily the case that the user cares, but I was thinking that having the API allow for different polarity might prevent some applications having to optionally do the %duty vs. 100-%duty conversion themselves.
Ok, ok, but this should go into the docs.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 27 lines · Bill Gatliff
This patch series implements a common PWM API. This series incorporates the feedback from the linux-embedded mailing list and elsewhere; the author greatly appreciates the efforts of everyone who reviewed the previous version of this code.
Bill Gatliff (5):
API to consolidate PWM devices behind a common user and kernel
interface
Emulates PWM hardware using a high-resolution timer and a GPIO pin Expunge old Atmel PWMC driver, replacing it with one that conforms to
the PWM API
PWM-based LED control
LED "dimmer" triggerDocumentation/pwm.txt | 260 ++++++++++++++++++ drivers/leds/leds-pwm.c | 224 +++++++++------- drivers/leds/ledtrig-dim.c | 95 +++++++ drivers/misc/Makefile | 6 +- drivers/misc/atmel_pwm.c | 409 ---------------------------- drivers/pwm/atmel-pwm.c | 589 ++++++++++++++++++++++++++++++++++++++++ drivers/pwm/gpio.c | 307 +++++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 -- include/linux/pwm/pwm-led.h | 34 +++ include/linux/pwm/pwm.h | 170 ++++++++++++ 11 files changed, 2217 insertions(+), 541 deletions(-) create mode 100644 Documentation/pwm.txt
Quoted 8 lines
create mode 100644 drivers/leds/ledtrig-dim.c delete mode 100644 drivers/misc/atmel_pwm.c create mode 100644 drivers/pwm/atmel-pwm.c create mode 100644 drivers/pwm/gpio.c create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm-led.h create mode 100644 include/linux/pwm/pwm.h
I think the following files/patches are missing from this series:
drivers/Kconfigdrivers/Makefiledrivers/leds/Kconfigdrivers/leds/Makefiledrivers/pwm/Kconfigdrivers/pwm/Makefile
Regards,
Hartley
Quoted 9 lines · H Hartley Sweeten
I think the following files/patches are missing from this series:
drivers/Kconfigdrivers/Makefiledrivers/leds/Kconfigdrivers/leds/Makefiledrivers/pwm/Kconfigdrivers/pwm/Makefile
Quoted 3 lines
Regards,
Hartley
Agreed! I wonder how that happened? :(
I'll make doubly sure they are present in the next (final?) posting...
b.g.
Signature · 2 lines
Bill Gatliff [email protected]
Quoted 37 lines · H Hartley Sweeten
Quoted 27 lines · Bill Gatliff
This patch series implements a common PWM API. This series incorporates the feedback from the linux-embedded mailing list and elsewhere; the author greatly appreciates the efforts of everyone who reviewed the previous version of this code.
Bill Gatliff (5):
API to consolidate PWM devices behind a common user and kernel
interface
Emulates PWM hardware using a high-resolution timer and a GPIO pin Expunge old Atmel PWMC driver, replacing it with one that conforms to
the PWM API
PWM-based LED control
LED "dimmer" triggerDocumentation/pwm.txt | 260 ++++++++++++++++++ drivers/leds/leds-pwm.c | 224 +++++++++------- drivers/leds/ledtrig-dim.c | 95 +++++++ drivers/misc/Makefile | 6 +- drivers/misc/atmel_pwm.c | 409 ---------------------------- drivers/pwm/atmel-pwm.c | 589 ++++++++++++++++++++++++++++++++++++++++ drivers/pwm/gpio.c | 307 +++++++++++++++++++++ drivers/pwm/pwm.c | 633 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pwm.h | 31 -- include/linux/pwm/pwm-led.h | 34 +++ include/linux/pwm/pwm.h | 170 ++++++++++++ 11 files changed, 2217 insertions(+), 541 deletions(-) create mode 100644 Documentation/pwm.txtQuoted 8 lines
create mode 100644 drivers/leds/ledtrig-dim.c delete mode 100644 drivers/misc/atmel_pwm.c create mode 100644 drivers/pwm/atmel-pwm.c create mode 100644 drivers/pwm/gpio.c create mode 100644 drivers/pwm/pwm.c delete mode 100644 include/linux/pwm.h create mode 100644 include/linux/pwm/pwm-led.h create mode 100644 include/linux/pwm/pwm.h
Quoted 8 lines
I think the following files/patches are missing from this series:
drivers/Kconfigdrivers/Makefiledrivers/leds/Kconfigdrivers/leds/Makefiledrivers/pwm/Kconfigdrivers/pwm/Makefile
Bill,
When you do repost this series please make sure that pwm support can only be selected if CONFIG_SYSFS is enabled. Your original patches did not have this.
I look forward to seeing the update.
BTW, setting pwm.dev = &pdev->dev in my driver did fix the Ooops.
Regards,
Hartley
Quoted 4 lines · H Hartley Sweeten
When you do repost this series please make sure that pwm support can only be selected if
CONFIG_SYSFSis enabled. Your original patches did not have this.
Hmmm. You mean CONFIG_SYSFS isn't pretty much mandatory nowadays?
Quoted 2 lines
BTW, setting pwm.dev =
&pdev->devin my driver did fix the Ooops.
Glad to hear that! I'm hoping to get updated patches out next week.
b.g.
Signature · 4 lines
Bill Gatliff Embedded systems training and consulting http://billgatliff.com [email protected]