Re: [PATCH v2 09/13] OMAP: McBSP: use omap_device APIs to modify SYSCONFIG

2011-02-01 Thread ABRAHAM, KISHON VIJAY
On Tue, Feb 1, 2011 at 5:49 PM, Peter Ujfalusi  wrote:
> Hi,
>
> On 01/31/2011 04:50 PM, ext Kishon Vijay Abraham I wrote:
>> McBSP2/3 in OMAP3 has sidetone feature which requires autoidle
>> to be disabled before starting the sidetone. Also SYSCONFIG
>> register has to be set with smart idle or no idle depending on the
>> dma op mode (threshold or element sync). For doing these operations
>> dynamically at runtime, omap_device APIs are used to modify SYSCONFIG 
>> register.
>>
>> Signed-off-by: Kishon Vijay Abraham I 
>> ---
>>  arch/arm/plat-omap/mcbsp.c |   66 
>> +++
>>  1 files changed, 35 insertions(+), 31 deletions(-)
>>
>> diff --git a/arch/arm/plat-omap/mcbsp.c b/arch/arm/plat-omap/mcbsp.c
>
> ...
>
>>  static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
>>  {
>> +     struct omap_device *od;
>> +
>> +     od = find_omap_device_by_dev(mcbsp->dev);
>>       /*
>>        * Enable wakup behavior, smart idle and all wakeups
>>        * REVISIT: some wakeups may be unnecessary
>>        */
>>       if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
>> -             u16 syscon;
>> -
>> -             syscon = MCBSP_READ(mcbsp, SYSCON);
>> -             syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
>> -
>> -             if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) {
>> -                     syscon |= (ENAWAKEUP | SIDLEMODE(0x02) |
>> -                                     CLOCKACTIVITY(0x02));
>> +             if (mcbsp->dma_op_mode != MCBSP_DMA_MODE_THRESHOLD)
>> +                     omap_device_noidle(od);
>> +             else
>
> Would it make sense to call here:
> omap_device_smartidle(od); ?

   I dint explicitly call it because, pm_runtime_get_sync() would have
already set the
   SYSCONFIG to smartidle.

> What happens, if we configure McBSP to element mode, play a sample,
> configure it to threshold?
> I think we should explicitly as for smartidle, when we suppose to be in
> smartidle.

   In either ways, this function will be called when we do a request
and this function
   (omap34xx_mcbsp_request) gets called after pm_runtime_get_sync. So based on
   the value of dma_op_mode at the time of request, either noidle or
smartidle will
   be set.

>
>>                       MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
>> -             } else {
>> -                     syscon |= SIDLEMODE(0x01);
>> -             }
>> -
>> -             MCBSP_WRITE(mcbsp, SYSCON, syscon);
>>       }
>>  }
>>
>>  static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
>>  {
>> +     struct omap_device *od;
>> +
>> +     od = find_omap_device_by_dev(mcbsp->dev);
>> +
>>       /*
>>        * Disable wakup behavior, smart idle and all wakeups
>>        */
>>       if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
>> -             u16 syscon;
>> -
>> -             syscon = MCBSP_READ(mcbsp, SYSCON);
>> -             syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
>>               /*
>>                * HW bug workaround - If no_idle mode is taken, we need to
>>                * go to smart_idle before going to always_idle, or the
>>                * device will not hit retention anymore.
>>                */
>> -             syscon |= SIDLEMODE(0x02);
>> -             MCBSP_WRITE(mcbsp, SYSCON, syscon);
>> -
>> -             syscon &= ~(SIDLEMODE(0x03));
>> -             MCBSP_WRITE(mcbsp, SYSCON, syscon);
>> -
>> +             omap_device_default_idle(od);
>>               MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
>
> Hrm, it would be better to do it as the comment said:
> omap_device_smartidle(od);
> omap_device_forceidle(od);

  hmmm..ok. Will make this change in the next version.

>
> BTW: what is the default_idle in case of McBSP?

   The default idle mode for McBSP is SMARTIDLE. It is actually
   based on SWSUP flag. If it is set, the idlemode is NOIDLE else
   SMARTIDLE. Pls have a look at my patch that implements
   omap_device_default_idle() [1].

   [1]http://permalink.gmane.org/gmane.linux.ports.arm.omap/51134

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


Re: [PATCH v2 09/13] OMAP: McBSP: use omap_device APIs to modify SYSCONFIG

2011-02-01 Thread Peter Ujfalusi
Hi,

On 01/31/2011 04:50 PM, ext Kishon Vijay Abraham I wrote:
> McBSP2/3 in OMAP3 has sidetone feature which requires autoidle
> to be disabled before starting the sidetone. Also SYSCONFIG
> register has to be set with smart idle or no idle depending on the
> dma op mode (threshold or element sync). For doing these operations
> dynamically at runtime, omap_device APIs are used to modify SYSCONFIG 
> register.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  arch/arm/plat-omap/mcbsp.c |   66 +++
>  1 files changed, 35 insertions(+), 31 deletions(-)
> 
> diff --git a/arch/arm/plat-omap/mcbsp.c b/arch/arm/plat-omap/mcbsp.c

...

>  static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
>  {
> + struct omap_device *od;
> +
> + od = find_omap_device_by_dev(mcbsp->dev);
>   /*
>* Enable wakup behavior, smart idle and all wakeups
>* REVISIT: some wakeups may be unnecessary
>*/
>   if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
> - u16 syscon;
> -
> - syscon = MCBSP_READ(mcbsp, SYSCON);
> - syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
> -
> - if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) {
> - syscon |= (ENAWAKEUP | SIDLEMODE(0x02) |
> - CLOCKACTIVITY(0x02));
> + if (mcbsp->dma_op_mode != MCBSP_DMA_MODE_THRESHOLD)
> + omap_device_noidle(od);
> + else

Would it make sense to call here:
omap_device_smartidle(od); ?
What happens, if we configure McBSP to element mode, play a sample,
configure it to threshold?
I think we should explicitly as for smartidle, when we suppose to be in
smartidle.

>   MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
> - } else {
> - syscon |= SIDLEMODE(0x01);
> - }
> -
> - MCBSP_WRITE(mcbsp, SYSCON, syscon);
>   }
>  }
>  
>  static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
>  {
> + struct omap_device *od;
> +
> + od = find_omap_device_by_dev(mcbsp->dev);
> +
>   /*
>* Disable wakup behavior, smart idle and all wakeups
>*/
>   if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
> - u16 syscon;
> -
> - syscon = MCBSP_READ(mcbsp, SYSCON);
> - syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
>   /*
>* HW bug workaround - If no_idle mode is taken, we need to
>* go to smart_idle before going to always_idle, or the
>* device will not hit retention anymore.
>*/
> - syscon |= SIDLEMODE(0x02);
> - MCBSP_WRITE(mcbsp, SYSCON, syscon);
> -
> - syscon &= ~(SIDLEMODE(0x03));
> - MCBSP_WRITE(mcbsp, SYSCON, syscon);
> -
> + omap_device_default_idle(od);
>   MCBSP_WRITE(mcbsp, WAKEUPEN, 0);

Hrm, it would be better to do it as the comment said:
omap_device_smartidle(od);
omap_device_forceidle(od);

BTW: what is the default_idle in case of McBSP?

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


[PATCH v2 09/13] OMAP: McBSP: use omap_device APIs to modify SYSCONFIG

2011-01-31 Thread Kishon Vijay Abraham I
McBSP2/3 in OMAP3 has sidetone feature which requires autoidle
to be disabled before starting the sidetone. Also SYSCONFIG
register has to be set with smart idle or no idle depending on the
dma op mode (threshold or element sync). For doing these operations
dynamically at runtime, omap_device APIs are used to modify SYSCONFIG register.

Signed-off-by: Kishon Vijay Abraham I 
---
 arch/arm/plat-omap/mcbsp.c |   66 +++
 1 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/arch/arm/plat-omap/mcbsp.c b/arch/arm/plat-omap/mcbsp.c
index 275a37a..9bc2c73 100644
--- a/arch/arm/plat-omap/mcbsp.c
+++ b/arch/arm/plat-omap/mcbsp.c
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 /* XXX These "sideways" includes are a sign that something is wrong */
 #include "../mach-omap2/cm2xxx_3xxx.h"
@@ -228,9 +229,19 @@ void omap_mcbsp_config(unsigned int id, const struct 
omap_mcbsp_reg_cfg *config)
 EXPORT_SYMBOL(omap_mcbsp_config);
 
 #ifdef CONFIG_ARCH_OMAP3
+static struct omap_device *find_omap_device_by_dev(struct device *dev)
+{
+   struct platform_device *pdev = container_of(dev,
+   struct platform_device, dev);
+   return container_of(pdev, struct omap_device, pdev);
+}
+
 static void omap_st_on(struct omap_mcbsp *mcbsp)
 {
unsigned int w;
+   struct omap_device *od;
+
+   od = find_omap_device_by_dev(mcbsp->dev);
 
/*
 * Sidetone uses McBSP ICLK - which must not idle when sidetones
@@ -244,8 +255,7 @@ static void omap_st_on(struct omap_mcbsp *mcbsp)
w = MCBSP_READ(mcbsp, SSELCR);
MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
 
-   w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
-   MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w & ~(ST_AUTOIDLE));
+   omap_device_disable_autoidle(od);
 
/* Enable Sidetone from Sidetone Core */
w = MCBSP_ST_READ(mcbsp, SSELCR);
@@ -255,12 +265,14 @@ static void omap_st_on(struct omap_mcbsp *mcbsp)
 static void omap_st_off(struct omap_mcbsp *mcbsp)
 {
unsigned int w;
+   struct omap_device *od;
+
+   od = find_omap_device_by_dev(mcbsp->dev);
 
w = MCBSP_ST_READ(mcbsp, SSELCR);
MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
 
-   w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
-   MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w | ST_AUTOIDLE);
+   omap_device_enable_autoidle(od);
 
w = MCBSP_READ(mcbsp, SSELCR);
MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
@@ -273,9 +285,11 @@ static void omap_st_off(struct omap_mcbsp *mcbsp)
 static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
 {
u16 val, i;
+   struct omap_device *od;
 
-   val = MCBSP_ST_READ(mcbsp, SYSCONFIG);
-   MCBSP_ST_WRITE(mcbsp, SYSCONFIG, val & ~(ST_AUTOIDLE));
+   od = find_omap_device_by_dev(mcbsp->dev);
+
+   omap_device_disable_autoidle(od);
 
val = MCBSP_ST_READ(mcbsp, SSELCR);
 
@@ -303,9 +317,11 @@ static void omap_st_chgain(struct omap_mcbsp *mcbsp)
 {
u16 w;
struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
+   struct omap_device *od;
+
+   od = find_omap_device_by_dev(mcbsp->dev);
 
-   w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
-   MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w & ~(ST_AUTOIDLE));
+   omap_device_disable_autoidle(od);
 
w = MCBSP_ST_READ(mcbsp, SSELCR);
 
@@ -648,49 +664,37 @@ EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode);
 
 static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
 {
+   struct omap_device *od;
+
+   od = find_omap_device_by_dev(mcbsp->dev);
/*
 * Enable wakup behavior, smart idle and all wakeups
 * REVISIT: some wakeups may be unnecessary
 */
if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
-   u16 syscon;
-
-   syscon = MCBSP_READ(mcbsp, SYSCON);
-   syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
-
-   if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) {
-   syscon |= (ENAWAKEUP | SIDLEMODE(0x02) |
-   CLOCKACTIVITY(0x02));
+   if (mcbsp->dma_op_mode != MCBSP_DMA_MODE_THRESHOLD)
+   omap_device_noidle(od);
+   else
MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
-   } else {
-   syscon |= SIDLEMODE(0x01);
-   }
-
-   MCBSP_WRITE(mcbsp, SYSCON, syscon);
}
 }
 
 static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
 {
+   struct omap_device *od;
+
+   od = find_omap_device_by_dev(mcbsp->dev);
+
/*
 * Disable wakup behavior, smart idle and all wakeups
 */
if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
-   u16 syscon;
-
-   syscon = MCBSP_READ(mcbsp, SYSCON);
-   syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));