[[RFC] 3/5] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API

2009-10-19 Thread Bill Gatliff

Signed-off-by: Bill Gatliff b...@billgatliff.com
---
 drivers/misc/Makefile|6 +-
 drivers/misc/atmel_pwm.c |  409 --
 drivers/pwm/atmel-pwm.c  |  633 ++
 3 files changed, 638 insertions(+), 410 deletions(-)
 delete mode 100644 drivers/misc/atmel_pwm.c
 create mode 100644 drivers/pwm/atmel-pwm.c

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index f982d2e..35f13c2 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -4,7 +4,11 @@
 
 obj-$(CONFIG_IBM_ASM)  += ibmasm/
 obj-$(CONFIG_HDPU_FEATURES)+= hdpuftrs/
-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
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c
deleted file mode 100644
index 6aa5294..000
--- a/drivers/misc/atmel_pwm.c
+++ /dev/null
@@ -1,409 +0,0 @@
-#include linux/module.h
-#include linux/clk.h
-#include linux/err.h
-#include linux/io.h
-#include linux/interrupt.h
-#include linux/platform_device.h
-#include linux/atmel_pwm.h
-
-
-/*
- * This is a simple driver for the PWM controller found in various newer
- * Atmel SOCs, including the AVR32 series and the AT91sam9263.
- *
- * Chips with current Linux ports have only 4 PWM channels, out of max 32.
- * AT32UC3A and AT32UC3B chips have 7 channels (but currently no Linux).
- * Docs are inconsistent about the width of the channel counter registers;
- * it's at least 16 bits, but several places say 20 bits.
- */
-#definePWM_NCHAN   4   /* max 32 */
-
-struct pwm {
-   spinlock_t  lock;
-   struct platform_device  *pdev;
-   u32 mask;
-   int irq;
-   void __iomem*base;
-   struct clk  *clk;
-   struct pwm_channel  *channel[PWM_NCHAN];
-   void(*handler[PWM_NCHAN])(struct pwm_channel *);
-};
-
-
-/* global PWM controller registers */
-#define PWM_MR 0x00
-#define PWM_ENA0x04
-#define PWM_DIS0x08
-#define PWM_SR 0x0c
-#define PWM_IER0x10
-#define PWM_IDR0x14
-#define PWM_IMR0x18
-#define PWM_ISR0x1c
-
-static inline void pwm_writel(const struct pwm *p, unsigned offset, u32 val)
-{
-   __raw_writel(val, p-base + offset);
-}
-
-static inline u32 pwm_readl(const struct pwm *p, unsigned offset)
-{
-   return __raw_readl(p-base + offset);
-}
-
-static inline void __iomem *pwmc_regs(const struct pwm *p, int index)
-{
-   return p-base + 0x200 + index * 0x20;
-}
-
-static struct pwm *pwm;
-
-static void pwm_dumpregs(struct pwm_channel *ch, char *tag)
-{
-   struct device   *dev = pwm-pdev-dev;
-
-   dev_dbg(dev, %s: mr %08x, sr %08x, imr %08x\n,
-   tag,
-   pwm_readl(pwm, PWM_MR),
-   pwm_readl(pwm, PWM_SR),
-   pwm_readl(pwm, PWM_IMR));
-   dev_dbg(dev,
-   pwm ch%d - mr %08x, dty %u, prd %u, cnt %u\n,
-   ch-index,
-   pwm_channel_readl(ch, PWM_CMR),
-   pwm_channel_readl(ch, PWM_CDTY),
-   pwm_channel_readl(ch, PWM_CPRD),
-   pwm_channel_readl(ch, PWM_CCNT));
-}
-
-
-/**
- * pwm_channel_alloc - allocate an unused PWM channel
- * @index: identifies the channel
- * @ch: structure to be initialized
- *
- * Drivers allocate PWM channels according to the board's wiring, and
- * matching board-specific setup code.  Returns zero or negative errno.
- */
-int pwm_channel_alloc(int index, struct pwm_channel *ch)
-{
-   unsigned long   flags;
-   int status = 0;
-
-   /* insist on PWM init, with this signal pinned out */
-   if (!pwm || !(pwm-mask  1  index))
-   return -ENODEV;
-
-   if (index  0 || index = PWM_NCHAN || !ch)
-   return -EINVAL;
-   memset(ch, 0, sizeof *ch);
-
-   spin_lock_irqsave(pwm-lock, flags);
-   if (pwm-channel[index])
-   status = -EBUSY;
-   else {
-   clk_enable(pwm-clk);
-
-   ch-regs = pwmc_regs(pwm, index);
-   ch-index = index;
-
-   /* REVISIT: ap7000 seems to go 2x as fast as we expect!! */
-   ch-mck = clk_get_rate(pwm-clk);
-
-   pwm-channel[index] = ch;
-   pwm-handler[index] = NULL;
-
-   /* channel and irq are always disabled when we return */
-   pwm_writel(pwm, PWM_DIS, 1  index);
-   pwm_writel(pwm, PWM_IDR, 1  index);
-   }
-   

Re: [[RFC] 3/5] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API

2009-10-19 Thread Bill Gatliff

Mike Frysinger wrote:

+   ap-clk = clk_get(pdev-dev, pwm_clk);
+   if (IS_ERR(ap-clk)) {
+   pr_info(%s: clk_get error %ld\n,
+   ap-pwm.bus_id, PTR_ERR(ap-clk));
+   ret = -ENODEV;
+   goto err_clk_get;



shouldnt it be:
  ret = PTR_ERR(ap-clk);
  


Probably, because it's preferable to return the actual error code when 
it's known, rather than translating all error codes to -ENODEV.  Good catch.



b.g.

--
Bill Gatliff
b...@billgatliff.com

--
To unsubscribe from this list: send the line unsubscribe linux-embedded in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html