2012-06-29 06:32:15 -07:00
|
|
|
/* drivers/pwm/pwm-samsung.c
|
2008-07-01 05:17:24 -07:00
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Ben Dooks
|
|
|
|
* Copyright (c) 2008 Simtec Electronics
|
|
|
|
* Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
|
|
|
|
*
|
2009-07-01 08:47:07 -07:00
|
|
|
* S3C series PWM device core
|
2008-07-01 05:17:24 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-07-06 02:13:50 -07:00
|
|
|
#define pr_fmt(fmt) "pwm-samsung: " fmt
|
|
|
|
|
2011-11-16 09:14:38 -07:00
|
|
|
#include <linux/export.h>
|
2008-07-01 05:17:24 -07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 01:04:11 -07:00
|
|
|
#include <linux/slab.h>
|
2008-07-01 05:17:24 -07:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/pwm.h>
|
|
|
|
|
2009-07-01 08:47:07 -07:00
|
|
|
#include <mach/map.h>
|
[ARM] fix AT91, davinci, h720x, ks8695, msm, mx2, mx3, netx, omap1, omap2, pxa, s3c
arch/arm/mach-at91/at91cap9.c:337: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91rm9200.c:301: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9260.c:351: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9261.c:287: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9263.c:312: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9rl.c:304: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-h720x/h7202-eval.c:38: error: implicit declaration of function 'IRQ_CHAINED_GPIOB'
arch/arm/mach-ks8695/devices.c:46: error: 'KS8695_IRQ_WAN_RX_STATUS' undeclared here (not in a function)
arch/arm/mach-msm/devices.c:28: error: 'INT_UART1' undeclared here (not in a function)
arch/arm/mach-mx2/devices.c:233: error: 'MXC_GPIO_IRQ_START' undeclared here (not in a function)
arch/arm/mach-mx3/devices.c:128: error: 'MXC_GPIO_IRQ_START' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:140: error: 'INT_730_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:165: error: 'INT_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:200: error: 'INT_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap2/board-apollon.c:286: error: implicit declaration of function 'omap_set_gpio_direction'
arch/arm/mach-omap2/mcbsp.c:154: error: 'INT_24XX_MCBSP1_IRQ_RX' undeclared here (not in a function)
arch/arm/mach-omap2/mcbsp.c:181: error: 'INT_24XX_MCBSP1_IRQ_RX' undeclared here (not in a function)
arch/arm/mach-pxa/e350.c:36: error: 'IRQ_BOARD_START' undeclared here (not in a function)
arch/arm/plat-s3c/dev-i2c0.c:32: error: 'IRQ_IIC' undeclared here (not in a function)
...
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-01-08 03:01:47 -07:00
|
|
|
|
2008-10-07 14:26:09 -07:00
|
|
|
#include <plat/regs-timer.h>
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip {
|
2008-07-01 05:17:24 -07:00
|
|
|
struct platform_device *pdev;
|
|
|
|
|
|
|
|
struct clk *clk_div;
|
|
|
|
struct clk *clk;
|
|
|
|
const char *label;
|
|
|
|
|
|
|
|
unsigned int period_ns;
|
|
|
|
unsigned int duty_ns;
|
|
|
|
|
|
|
|
unsigned char tcon_base;
|
|
|
|
unsigned char pwm_id;
|
2012-03-15 02:04:36 -07:00
|
|
|
struct pwm_chip chip;
|
2008-07-01 05:17:24 -07:00
|
|
|
};
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
#define to_s3c_chip(chip) container_of(chip, struct s3c_chip, chip)
|
|
|
|
|
2008-08-26 14:54:06 -07:00
|
|
|
#define pwm_dbg(_pwm, msg...) dev_dbg(&(_pwm)->pdev->dev, msg)
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
static struct clk *clk_scaler[2];
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static inline int pwm_is_tdiv(struct s3c_chip *chip)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
2012-03-15 02:04:36 -07:00
|
|
|
return clk_get_parent(chip->clk) == chip->clk_div;
|
2008-07-01 05:17:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define pwm_tcon_start(pwm) (1 << (pwm->tcon_base + 0))
|
|
|
|
#define pwm_tcon_invert(pwm) (1 << (pwm->tcon_base + 2))
|
|
|
|
#define pwm_tcon_autoreload(pwm) (1 << (pwm->tcon_base + 3))
|
|
|
|
#define pwm_tcon_manulupdate(pwm) (1 << (pwm->tcon_base + 1))
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static int s3c_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip *s3c = to_s3c_chip(chip);
|
2008-07-01 05:17:24 -07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tcon;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
tcon = __raw_readl(S3C2410_TCON);
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon |= pwm_tcon_start(s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static void s3c_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip *s3c = to_s3c_chip(chip);
|
2008-07-01 05:17:24 -07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tcon;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
tcon = __raw_readl(S3C2410_TCON);
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon &= ~pwm_tcon_start(s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static unsigned long pwm_calc_tin(struct s3c_chip *s3c, unsigned long freq)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
|
|
|
unsigned long tin_parent_rate;
|
|
|
|
unsigned int div;
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
tin_parent_rate = clk_get_rate(clk_get_parent(s3c->clk_div));
|
|
|
|
pwm_dbg(s3c, "tin parent at %lu\n", tin_parent_rate);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
for (div = 2; div <= 16; div *= 2) {
|
|
|
|
if ((tin_parent_rate / (div << 16)) < freq)
|
|
|
|
return tin_parent_rate / div;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tin_parent_rate / 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_IN_HZ (1000000000UL)
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static int s3c_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
|
|
int duty_ns, int period_ns)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip *s3c = to_s3c_chip(chip);
|
2008-07-01 05:17:24 -07:00
|
|
|
unsigned long tin_rate;
|
|
|
|
unsigned long tin_ns;
|
|
|
|
unsigned long period;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tcon;
|
|
|
|
unsigned long tcnt;
|
|
|
|
long tcmp;
|
|
|
|
|
|
|
|
/* We currently avoid using 64bit arithmetic by using the
|
|
|
|
* fact that anything faster than 1Hz is easily representable
|
|
|
|
* by 32bits. */
|
|
|
|
|
|
|
|
if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ)
|
|
|
|
return -ERANGE;
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
if (period_ns == s3c->period_ns &&
|
|
|
|
duty_ns == s3c->duty_ns)
|
2008-07-01 05:17:24 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The TCMP and TCNT can be read without a lock, they're not
|
|
|
|
* shared between the timers. */
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
tcmp = __raw_readl(S3C2410_TCMPB(s3c->pwm_id));
|
|
|
|
tcnt = __raw_readl(S3C2410_TCNTB(s3c->pwm_id));
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
period = NS_IN_HZ / period_ns;
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
pwm_dbg(s3c, "duty_ns=%d, period_ns=%d (%lu)\n",
|
2008-07-01 05:17:24 -07:00
|
|
|
duty_ns, period_ns, period);
|
|
|
|
|
|
|
|
/* Check to see if we are changing the clock rate of the PWM */
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
if (s3c->period_ns != period_ns) {
|
|
|
|
if (pwm_is_tdiv(s3c)) {
|
|
|
|
tin_rate = pwm_calc_tin(s3c, period);
|
|
|
|
clk_set_rate(s3c->clk_div, tin_rate);
|
2008-07-01 05:17:24 -07:00
|
|
|
} else
|
2012-03-15 02:04:36 -07:00
|
|
|
tin_rate = clk_get_rate(s3c->clk);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
s3c->period_ns = period_ns;
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
pwm_dbg(s3c, "tin_rate=%lu\n", tin_rate);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
tin_ns = NS_IN_HZ / tin_rate;
|
|
|
|
tcnt = period_ns / tin_ns;
|
|
|
|
} else
|
2012-03-15 02:04:36 -07:00
|
|
|
tin_ns = NS_IN_HZ / clk_get_rate(s3c->clk);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
/* Note, counters count down */
|
|
|
|
|
|
|
|
tcmp = duty_ns / tin_ns;
|
|
|
|
tcmp = tcnt - tcmp;
|
2009-07-01 08:47:08 -07:00
|
|
|
/* the pwm hw only checks the compare register after a decrement,
|
|
|
|
so the pin never toggles if tcmp = tcnt */
|
|
|
|
if (tcmp == tcnt)
|
|
|
|
tcmp--;
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
pwm_dbg(s3c, "tin_ns=%lu, tcmp=%ld/%lu\n", tin_ns, tcmp, tcnt);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
if (tcmp < 0)
|
|
|
|
tcmp = 0;
|
|
|
|
|
|
|
|
/* Update the PWM register block. */
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
__raw_writel(tcmp, S3C2410_TCMPB(s3c->pwm_id));
|
|
|
|
__raw_writel(tcnt, S3C2410_TCNTB(s3c->pwm_id));
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
tcon = __raw_readl(S3C2410_TCON);
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon |= pwm_tcon_manulupdate(s3c);
|
|
|
|
tcon |= pwm_tcon_autoreload(s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon &= ~pwm_tcon_manulupdate(s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
static struct pwm_ops s3c_pwm_ops = {
|
|
|
|
.enable = s3c_pwm_enable,
|
|
|
|
.disable = s3c_pwm_disable,
|
|
|
|
.config = s3c_pwm_config,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
static int s3c_pwm_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip *s3c;
|
2008-07-01 05:17:24 -07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tcon;
|
|
|
|
unsigned int id = pdev->id;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (id == 4) {
|
|
|
|
dev_err(dev, "TIMER4 is currently not supported\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2012-06-29 06:32:15 -07:00
|
|
|
s3c = devm_kzalloc(&pdev->dev, sizeof(*s3c), GFP_KERNEL);
|
2012-03-15 02:04:36 -07:00
|
|
|
if (s3c == NULL) {
|
2008-07-01 05:17:24 -07:00
|
|
|
dev_err(dev, "failed to allocate pwm_device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate base of control bits in TCON */
|
2012-03-15 02:04:36 -07:00
|
|
|
s3c->tcon_base = id == 0 ? 0 : (id * 4) + 4;
|
2012-12-13 23:58:58 -07:00
|
|
|
s3c->pwm_id = id;
|
2012-08-02 01:55:54 -07:00
|
|
|
s3c->chip.dev = &pdev->dev;
|
2012-03-15 02:04:36 -07:00
|
|
|
s3c->chip.ops = &s3c_pwm_ops;
|
|
|
|
s3c->chip.base = -1;
|
|
|
|
s3c->chip.npwm = 1;
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-06-29 06:32:15 -07:00
|
|
|
s3c->clk = devm_clk_get(dev, "pwm-tin");
|
2012-03-15 02:04:36 -07:00
|
|
|
if (IS_ERR(s3c->clk)) {
|
2008-07-01 05:17:24 -07:00
|
|
|
dev_err(dev, "failed to get pwm tin clk\n");
|
2012-06-29 06:32:15 -07:00
|
|
|
return PTR_ERR(s3c->clk);
|
2008-07-01 05:17:24 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 06:32:15 -07:00
|
|
|
s3c->clk_div = devm_clk_get(dev, "pwm-tdiv");
|
2012-03-15 02:04:36 -07:00
|
|
|
if (IS_ERR(s3c->clk_div)) {
|
2008-07-01 05:17:24 -07:00
|
|
|
dev_err(dev, "failed to get pwm tdiv clk\n");
|
2012-06-29 06:32:15 -07:00
|
|
|
return PTR_ERR(s3c->clk_div);
|
2008-07-01 05:17:24 -07:00
|
|
|
}
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
clk_enable(s3c->clk);
|
|
|
|
clk_enable(s3c->clk_div);
|
2011-11-03 18:39:34 -07:00
|
|
|
|
2008-07-01 05:17:24 -07:00
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
tcon = __raw_readl(S3C2410_TCON);
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon |= pwm_tcon_invert(s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
ret = pwmchip_add(&s3c->chip);
|
|
|
|
if (ret < 0) {
|
2008-07-01 05:17:24 -07:00
|
|
|
dev_err(dev, "failed to register pwm\n");
|
|
|
|
goto err_clk_tdiv;
|
|
|
|
}
|
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
pwm_dbg(s3c, "config bits %02x\n",
|
|
|
|
(__raw_readl(S3C2410_TCON) >> s3c->tcon_base) & 0x0f);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
dev_info(dev, "tin at %lu, tdiv at %lu, tin=%sclk, base %d\n",
|
2012-03-15 02:04:36 -07:00
|
|
|
clk_get_rate(s3c->clk),
|
|
|
|
clk_get_rate(s3c->clk_div),
|
|
|
|
pwm_is_tdiv(s3c) ? "div" : "ext", s3c->tcon_base);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
platform_set_drvdata(pdev, s3c);
|
2008-07-01 05:17:24 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_clk_tdiv:
|
2012-03-15 02:04:36 -07:00
|
|
|
clk_disable(s3c->clk_div);
|
|
|
|
clk_disable(s3c->clk);
|
2008-07-01 05:17:24 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:26:09 -07:00
|
|
|
static int s3c_pwm_remove(struct platform_device *pdev)
|
2008-07-01 05:17:24 -07:00
|
|
|
{
|
2012-03-15 02:04:36 -07:00
|
|
|
struct s3c_chip *s3c = platform_get_drvdata(pdev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = pwmchip_remove(&s3c->chip);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2008-07-01 05:17:24 -07:00
|
|
|
|
2012-03-15 02:04:36 -07:00
|
|
|
clk_disable(s3c->clk_div);
|
|
|
|
clk_disable(s3c->clk);
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-07 21:03:31 -07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int s3c_pwm_suspend(struct device *dev)
|
2010-03-15 07:27:08 -07:00
|
|
|
{
|
2013-03-07 21:03:31 -07:00
|
|
|
struct s3c_chip *s3c = dev_get_drvdata(dev);
|
2010-03-15 07:27:08 -07:00
|
|
|
|
|
|
|
/* No one preserve these values during suspend so reset them
|
|
|
|
* Otherwise driver leaves PWM unconfigured if same values
|
|
|
|
* passed to pwm_config
|
|
|
|
*/
|
2012-03-15 02:04:36 -07:00
|
|
|
s3c->period_ns = 0;
|
|
|
|
s3c->duty_ns = 0;
|
2010-03-15 07:27:08 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-07 21:03:31 -07:00
|
|
|
static int s3c_pwm_resume(struct device *dev)
|
2010-03-15 07:27:08 -07:00
|
|
|
{
|
2013-03-07 21:03:31 -07:00
|
|
|
struct s3c_chip *s3c = dev_get_drvdata(dev);
|
2010-03-15 07:27:08 -07:00
|
|
|
unsigned long tcon;
|
|
|
|
|
|
|
|
/* Restore invertion */
|
|
|
|
tcon = __raw_readl(S3C2410_TCON);
|
2012-03-15 02:04:36 -07:00
|
|
|
tcon |= pwm_tcon_invert(s3c);
|
2010-03-15 07:27:08 -07:00
|
|
|
__raw_writel(tcon, S3C2410_TCON);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-07 21:03:31 -07:00
|
|
|
static SIMPLE_DEV_PM_OPS(s3c_pwm_pm_ops, s3c_pwm_suspend,
|
|
|
|
s3c_pwm_resume);
|
|
|
|
|
2008-07-01 05:17:24 -07:00
|
|
|
static struct platform_driver s3c_pwm_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "s3c24xx-pwm",
|
|
|
|
.owner = THIS_MODULE,
|
2013-03-07 21:03:31 -07:00
|
|
|
.pm = &s3c_pwm_pm_ops,
|
2008-07-01 05:17:24 -07:00
|
|
|
},
|
|
|
|
.probe = s3c_pwm_probe,
|
2012-11-19 11:21:28 -07:00
|
|
|
.remove = s3c_pwm_remove,
|
2008-07-01 05:17:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pwm_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
clk_scaler[0] = clk_get(NULL, "pwm-scaler0");
|
|
|
|
clk_scaler[1] = clk_get(NULL, "pwm-scaler1");
|
|
|
|
|
|
|
|
if (IS_ERR(clk_scaler[0]) || IS_ERR(clk_scaler[1])) {
|
2012-07-06 02:13:50 -07:00
|
|
|
pr_err("failed to get scaler clocks\n");
|
2008-07-01 05:17:24 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = platform_driver_register(&s3c_pwm_driver);
|
|
|
|
if (ret)
|
2012-07-06 02:13:50 -07:00
|
|
|
pr_err("failed to add pwm driver\n");
|
2008-07-01 05:17:24 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
arch_initcall(pwm_init);
|