public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Alsa modularisations and support for tsc2101 2/7
@ 2006-02-20 17:47 Daniel Petrini
  2006-02-21 13:31 ` Menon, Nishanth
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Petrini @ 2006-02-20 17:47 UTC (permalink / raw)
  To: OMAP-Linux

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

ALSA Omap Patch

This patch moves codec files to mach-omap1 file and adds supports in
makefile for this

signed-off by Daniel Petrini <d.pensator@gmail.com>
signed-off by Mika Laitio <lamikr@cc.jyu.fi>

Daniel
--
INdT - Manaus - Brazil

[-- Attachment #2: alsa2-20060214.patch --]
[-- Type: text/x-patch, Size: 9907 bytes --]

ALSA Omap Patch

This patch moves codec files to mach-omap1 file and adds supports in makefile for this

signed-off by Daniel Petrini <d.pensator@gmail.com>
signed-off by Mika Laitio <lamikr@cc.jyu.fi>

Index: linux-omap-2.6.git-q/arch/arm/mach-omap1/Makefile
===================================================================
--- linux-omap-2.6.git-q.orig/arch/arm/mach-omap1/Makefile	2006-02-14 10:33:48.000000000 -0400
+++ linux-omap-2.6.git-q/arch/arm/mach-omap1/Makefile	2006-02-14 10:36:39.000000000 -0400
@@ -35,3 +35,6 @@ led-$(CONFIG_MACH_OMAP_PERSEUS2)	+= leds
 led-$(CONFIG_MACH_OMAP_OSK)		+= leds-osk.o
 obj-$(CONFIG_LEDS)			+= $(led-y)
 
+#ALSA codec files
+obj-$(CONFIG_MACH_OMAP_H2) += omap-alsa-tsc2101.o
+obj-$(CONFIG_MACH_OMAP_OSK) += omap-alsa-aic23.o
Index: linux-omap-2.6.git-q/arch/arm/mach-omap1/omap-alsa-aic23.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6.git-q/arch/arm/mach-omap1/omap-alsa-aic23.c	2006-02-14 15:03:38.000000000 -0400
@@ -0,0 +1,221 @@
+/*
+ * arch/arm/mach-omap1/omap-alsa-aic23.c
+ * 
+ * Alsa codec Driver for AIC23 chip on OSK5912 platform board
+ *
+ * Copyright (C) 2005 Instituto Nokia de Tecnologia - INdT - Manaus Brazil
+ * Written by Daniel Petrini, David Cohen, Anderson Briglia
+ *            {daniel.petrini, david.cohen, anderson.briglia}@indt.org.br
+ * 
+ * Based in former alsa driver for osk and oss driver
+ *
+ * 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.
+ *
+ * History:
+ *
+ * 2006-02-07   Daniel Petrini  - Codec specific function separated. File 
+ *                                renamed to omap-alsa-aic23.c
+ * 2006-02-10	Mika Laitio	  Unified the implementation so that the samplerates available
+ * 				  are now in the aic23_samplerate_reg_info structure.
+ */
+
+#ifdef CONFIG_SND
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/control.h>
+#include <linux/clk.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/aic23.h>
+
+#include <asm/arch/omap-alsa.h>
+#include "omap-alsa-aic23.h"
+
+static struct clk *aic23_mclk = 0;
+
+/* aic23 related */
+static const struct aic23_samplerate_reg_info
+ rate_reg_info[NUMBER_SAMPLE_RATES_SUPPORTED] = {
+	{4000, 0x06, 1},		/*  4000 */
+	{8000, 0x06, 0},		/*  8000 */
+	{16000, 0x0C, 1},		/* 16000 */
+	{22050, 0x11, 1},               /* 22050 */
+	{24000, 0x00, 1},		/* 24000 */
+	{32000, 0x0C, 0},		/* 32000 */
+	{44100, 0x11, 0},		/* 44100 */
+	{48000, 0x00, 0},		/* 48000 */
+	{88200, 0x1F, 0},		/* 88200 */
+	{96000, 0x0E, 0},		/* 96000 */
+};
+/*
+ * Codec/mcbsp init and configuration section
+ * codec dependent code.
+ */
+
+extern int tlv320aic23_write_value(u8 reg, u16 value);
+
+/* TLV320AIC23 is a write only device */
+void audio_aic23_write(u8 address, u16 data)
+{
+	tlv320aic23_write_value(address, data);
+}
+EXPORT_SYMBOL_GPL(audio_aic23_write);
+
+/*
+ * Sample rate changing
+ */
+void aic23_set_samplerate(long rate)
+{
+	u8 count = 0;
+	u16 data = 0;
+
+	/* Fix the rate if it has a wrong value */
+	if (rate >= 96000)
+		rate = 96000;
+	else if (rate >= 88200)
+		rate = 88200;
+	else if (rate >= 48000)
+		rate = 48000;
+	else if (rate >= 44100)
+		rate = 44100;
+	else if (rate >= 32000)
+		rate = 32000;
+	else if (rate >= 24000)
+		rate = 24000;
+	else if (rate >= 22050)
+		rate = 22050;
+	else if (rate >= 16000)
+		rate = 16000;
+	else if (rate >= 8000)
+		rate = 8000;
+	else
+		rate = 4000;
+
+	/* Search for the right sample rate */
+	/* Verify what happens if the rate is not supported
+	 * now it goes to 96Khz */
+	while ((rate_reg_info[count].sample_rate != rate) &&
+	       (count < (NUMBER_SAMPLE_RATES_SUPPORTED - 1))) {
+		count++;
+	}
+
+	data = (rate_reg_info[count].divider << CLKIN_SHIFT) |
+	    (rate_reg_info[count].control << BOSR_SHIFT) | USB_CLK_ON;
+
+	audio_aic23_write(SAMPLE_RATE_CONTROL_ADDR, data);
+}
+
+inline void aic23_configure(void)
+{
+	/* Reset codec */
+	audio_aic23_write(RESET_CONTROL_ADDR, 0);
+
+	/* Initialize the AIC23 internal state */
+
+	/* Analog audio path control, DAC selected, delete INSEL_MIC for line in */
+	audio_aic23_write(ANALOG_AUDIO_CONTROL_ADDR, DEFAULT_ANALOG_AUDIO_CONTROL);
+
+	/* Digital audio path control, de-emphasis control 44.1kHz */
+	audio_aic23_write(DIGITAL_AUDIO_CONTROL_ADDR, DEEMP_44K);
+
+	/* Digital audio interface, master/slave mode, I2S, 16 bit */
+#ifdef AIC23_MASTER
+	audio_aic23_write(DIGITAL_AUDIO_FORMAT_ADDR,
+			  MS_MASTER | IWL_16 | FOR_DSP);
+#else
+	audio_aic23_write(DIGITAL_AUDIO_FORMAT_ADDR, IWL_16 | FOR_DSP);
+#endif
+
+	/* Enable digital interface */
+	audio_aic23_write(DIGITAL_INTERFACE_ACT_ADDR, ACT_ON);
+}
+
+/*
+ *  Omap MCBSP clock configuration and Power Management
+ *  
+ *  Here we have some functions that allows clock to be enabled and
+ *   disabled only when needed. Besides doing clock configuration 
+ *   it allows turn on/turn off audio when necessary. 
+ */
+/*
+ * Do clock framework mclk search
+ */
+void aic23_clock_setup(void)
+{
+	aic23_mclk = clk_get(0, "mclk");
+}
+
+/*
+ * Do some sanity check, set clock rate, starts it and
+ *  turn codec audio on 
+ */
+int aic23_clock_on(void)
+{
+	if (clk_get_usecount(aic23_mclk) > 0) {
+		/* MCLK is already in use */
+		printk(KERN_WARNING
+		       "MCLK in use at %d Hz. We change it to %d Hz\n",
+		       (uint) clk_get_rate(aic23_mclk),
+		       CODEC_CLOCK);
+	}
+	
+	if (clk_set_rate(aic23_mclk, CODEC_CLOCK)) {
+		printk(KERN_ERR
+		       "Cannot set MCLK for AIC23 CODEC\n");
+		return -ECANCELED;
+	}
+
+	clk_enable(aic23_mclk);
+
+	printk(KERN_DEBUG
+		"MCLK = %d [%d], usecount = %d\n",
+	       (uint) clk_get_rate(aic23_mclk), CODEC_CLOCK,
+	       clk_get_usecount(aic23_mclk));
+
+	/* Now turn the audio on */
+	audio_aic23_write(POWER_DOWN_CONTROL_ADDR, 
+			  ~DEVICE_POWER_OFF & ~OUT_OFF & ~DAC_OFF &
+			  ~ADC_OFF & ~MIC_OFF & ~LINE_OFF);	
+	return 0;
+}
+/*
+ * Do some sanity check, turn clock off and then turn
+ *  codec audio off
+ */
+int aic23_clock_off(void)
+{
+	if  (clk_get_usecount(aic23_mclk) > 0) { 
+		if (clk_get_rate(aic23_mclk) != CODEC_CLOCK) {
+			printk(KERN_WARNING
+			       "MCLK for audio should be %d Hz. But is %d Hz\n",
+			       (uint) clk_get_rate(aic23_mclk),
+			       CODEC_CLOCK);
+		}
+
+		clk_disable(aic23_mclk);
+	}
+	
+	audio_aic23_write(POWER_DOWN_CONTROL_ADDR,
+			  DEVICE_POWER_OFF | OUT_OFF | DAC_OFF |
+			  ADC_OFF | MIC_OFF | LINE_OFF);	
+	return 0;
+}
+
+int aic23_get_default_samplerate(void)
+{
+	return DEFAULT_SAMPLE_RATE;
+}
+
+#else
+void aic23_configure(void){}
+void aic23_set_samplerate(long rate){};
+void aic23_clock_setup(void){}
+int  aic23_clock_on(void){return 0;}
+int  aic23_clock_off(void){return 0;}
+void aic23_get_default_samplerate(void){}
+#endif
Index: linux-omap-2.6.git-q/arch/arm/mach-omap1/omap-alsa-aic23.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-omap-2.6.git-q/arch/arm/mach-omap1/omap-alsa-aic23.h	2006-02-14 10:36:39.000000000 -0400
@@ -0,0 +1,76 @@
+/*
+ * sound/arm/omap-alsa-aic23.h
+ * 
+ * Alsa Driver for AIC23 codec on OSK5912 platform board
+ *
+ * Copyright (C) 2005 Instituto Nokia de Tecnologia - INdT - Manaus Brazil
+ * Written by Daniel Petrini, David Cohen, Anderson Briglia
+ *            {daniel.petrini, david.cohen, anderson.briglia}@indt.org.br
+ *
+ * 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.
+ *
+ *  History
+ *  -------
+ *
+ *  2006/02/08 INdT - Daniel Petrini - Alsa driver for omap osk, codec
+ *                                     modularisation. File creation.
+ *  2006/02/10 Mika Laitio	     - aic23_samplerate_reg_info structure moved to here
+ * 				       and contains now the samplerate parameter.
+ *  					
+ */
+
+#ifndef __OMAP_ALSA_AIC23_H
+#define __OMAP_ALSA_AIC23_H
+
+#include <sound/driver.h>
+#include <asm/arch/dma.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <asm/arch/mcbsp.h>
+
+/* Define to set the AIC23 as the master w.r.t McBSP */
+#define AIC23_MASTER
+
+#define NUMBER_SAMPLE_RATES_SUPPORTED 10
+
+/*
+ * AUDIO related MACROS
+ */
+#define DEFAULT_BITPERSAMPLE          16
+#define DEFAULT_SAMPLE_RATE	      44100
+#define CODEC_CLOCK                   12000000
+#define AUDIO_MCBSP                   OMAP_MCBSP1
+
+#define DEFAULT_OUTPUT_VOLUME         0x60
+#define DEFAULT_INPUT_VOLUME          0x00	/* 0 ==> mute line in */
+
+#define OUTPUT_VOLUME_MIN             LHV_MIN
+#define OUTPUT_VOLUME_MAX             LHV_MAX
+#define OUTPUT_VOLUME_RANGE           (OUTPUT_VOLUME_MAX - OUTPUT_VOLUME_MIN)
+#define OUTPUT_VOLUME_MASK            OUTPUT_VOLUME_MAX
+
+#define INPUT_VOLUME_MIN 	      LIV_MIN
+#define INPUT_VOLUME_MAX 	      LIV_MAX
+#define INPUT_VOLUME_RANGE 	      (INPUT_VOLUME_MAX - INPUT_VOLUME_MIN)
+#define INPUT_VOLUME_MASK 	      INPUT_VOLUME_MAX
+
+#define SIDETONE_MASK                 0x1c0
+#define SIDETONE_0                    0x100
+#define SIDETONE_6                    0x000
+#define SIDETONE_9                    0x040
+#define SIDETONE_12                   0x080
+#define SIDETONE_18                   0x0c0
+
+#define DEFAULT_ANALOG_AUDIO_CONTROL  DAC_SELECTED | STE_ENABLED | BYPASS_ON | INSEL_MIC | MICB_20DB
+
+struct aic23_samplerate_reg_info {
+	u32 sample_rate;
+	u8 control;		/* SR3, SR2, SR1, SR0 and BOSR */
+	u8 divider;		/* if 0 CLKIN = MCLK, if 1 CLKIN = MCLK/2 */
+};
+
+#endif
+

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] Alsa modularisations and support for tsc2101 2/7
  2006-02-20 17:47 [PATCH] Alsa modularisations and support for tsc2101 2/7 Daniel Petrini
@ 2006-02-21 13:31 ` Menon, Nishanth
  2006-02-21 14:06   ` Daniel Petrini
  0 siblings, 1 reply; 6+ messages in thread
From: Menon, Nishanth @ 2006-02-21 13:31 UTC (permalink / raw)
  To: Daniel Petrini, OMAP-Linux

Nope, does not look a good idea to me, as we will not be able to pull these out for 2420/2430 platforms(unless we move it to plat). why keep the tsc2101/aic in platforms specific directory if:
1. it can have varied control path
2. data transfer paths?
3. defined set of apis which can be called  by an higher abstraction layer?
 
I can see the transfer configuration is mainly setup from board file, which is an excellent idea. however for codecs.. err.. sound/... is a nice place for it to remain..
 
This will allow:
1. Other platforms other than omap also to be able to use tsc2101 functionalilty
2. have common support for alsa and oss - i dont see oss dying a lot sooner ;)
why would we want to stop the cross leverage?
 
Regards,
Nishanth Menon

________________________________

From: linux-omap-open-source-bounces@linux.omap.com on behalf of Daniel Petrini
Sent: Mon 2/20/2006 11:47 AM
To: OMAP-Linux
Subject: [PATCH] Alsa modularisations and support for tsc2101 2/7



ALSA Omap Patch

This patch moves codec files to mach-omap1 file and adds supports in
makefile for this

signed-off by Daniel Petrini <d.pensator@gmail.com>
signed-off by Mika Laitio <lamikr@cc.jyu.fi>

Daniel
--
INdT - Manaus - Brazil

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Alsa modularisations and support for tsc2101 2/7
  2006-02-21 13:31 ` Menon, Nishanth
@ 2006-02-21 14:06   ` Daniel Petrini
  2006-02-21 14:08     ` Menon, Nishanth
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Petrini @ 2006-02-21 14:06 UTC (permalink / raw)
  To: Menon, Nishanth; +Cc: OMAP-Linux

HI Nishanth,

Thanks for the comments.

On 2/21/06, Menon, Nishanth <x0nishan@ti.com> wrote:
>
>
> Nope, does not look a good idea to me, as we will not be able to pull these
> out for 2420/2430 platforms(unless we move it to plat). why keep the
> tsc2101/aic in platforms specific directory if:
> 1. it can have varied control path
> 2. data transfer paths?
> 3. defined set of apis which can be called  by an higher abstraction layer?

Indeed. We already make up our mind. These files will leave this directory :-) .

> I can see the transfer configuration is mainly setup from board file, which
> is an excellent idea. however for codecs.. err.. sound/... is a nice place
> for it to remain..

You mean the codec files moving to sound/ ? With this board file
approach this cause problems in linking the codec functions in the
board file. They had to stay in the omap tree not in the sound/ .
Maybe a better place to them could be plat-omap/ ?

> This will allow:
> 1. Other platforms other than omap also to be able to use tsc2101
> functionalilty
> 2. have common support for alsa and oss - i dont see oss dying a lot sooner
> ;)
> why would we want to stop the cross leverage?

Anyway, with this approach they can be used in other architectures as
well with small modifications. And in omap oss too.

> Regards,
> Nishanth Menon

Regards,
Daniel
--
INdT - Manaus - Brazil

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] Alsa modularisations and support for tsc2101 2/7
  2006-02-21 14:06   ` Daniel Petrini
@ 2006-02-21 14:08     ` Menon, Nishanth
  2006-02-21 23:53       ` lamikr
  0 siblings, 1 reply; 6+ messages in thread
From: Menon, Nishanth @ 2006-02-21 14:08 UTC (permalink / raw)
  To: Daniel Petrini; +Cc: OMAP-Linux

Hi Daniel,
>You mean the codec files moving to sound/ ? With this board file
>approach this cause problems in linking the codec functions in the
>board file. They had to stay in the omap tree not in the sound/ .
>Maybe a better place to them could be plat-omap/ ?
I dont see plat-omap having stuff other than omap specific code - such as dma etc.. if we put peripheral chip specific code there, i dont see kernel directory's abstraction happening properly sound/.. is the perfect place for this. The issue of linking is a minor problem - which can be handled by using proper include files.
Regards,
Nishanth Menon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Alsa modularisations and support for tsc2101 2/7
  2006-02-21 14:08     ` Menon, Nishanth
@ 2006-02-21 23:53       ` lamikr
  2006-02-22 18:15         ` Tony Lindgren
  0 siblings, 1 reply; 6+ messages in thread
From: lamikr @ 2006-02-21 23:53 UTC (permalink / raw)
  To: Menon, Nishanth; +Cc: OMAP-Linux


>>You mean the codec files moving to sound/ ? With this board file
>>approach this cause problems in linking the codec functions in the
>>board file. They had to stay in the omap tree not in the sound/ .
>>Maybe a better place to them could be plat-omap/ ?
>>    
>>
>I dont see plat-omap having stuff other than omap specific code - such as dma etc.. if we put peripheral chip specific code there, i dont see kernel directory's abstraction happening properly sound/.. is the perfect place for this. The issue of linking is a minor problem - which can be handled by using proper include files.
>Regards,
>  
>
Hi,

We have put the audio codec files under /arm/arch because we have wanted
to share the same omap-alsa.c between both codecs.
And for that reason we need to set the function pointers to omap-alsa.c
so that the calls from omap-alsa.c ends up to correct codec.

We have tried to do couple of different method for implementing this and
have not sofar found any perfect solution.

In our first attempt we kept all alsa related files in sound/arm/omap
directory.
In addition we put get_codec_functions() method to both of the drivers
and when the module was loaded the omap-alsa.c
called this get_codec_functions() method. The method had one
disadvantage, user could not build aic23 and tsc2101 drivers to same kernel
as both of the drivers had this one function with the same name.

In our second attemt (the one included in patches) we put the board-code
to set the function pointers. The drawback in this
method is that the functions defined in the board-code must itself be
linked within the board-code, otherwise we
got linking errors in the end.

Third (non tested) alternative could work in the following way
- Move the alsa modules probe method to codecs.
- when probe is called, it could define the function pointers and set
them to omap-alsa.c

Fourth possibility I know would be to make own implementation from
omap-alsa.c both for both of the codecs
but that is something I would like to avoid.

So if you have some idea how to do this, can you give us some info how
to do that.

Mika

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Alsa modularisations and support for tsc2101 2/7
  2006-02-21 23:53       ` lamikr
@ 2006-02-22 18:15         ` Tony Lindgren
  0 siblings, 0 replies; 6+ messages in thread
From: Tony Lindgren @ 2006-02-22 18:15 UTC (permalink / raw)
  To: lamikr; +Cc: OMAP-Linux

* lamikr <lamikr@cc.jyu.fi> [060222 09:26]:
> 
> >>You mean the codec files moving to sound/ ? With this board file
> >>approach this cause problems in linking the codec functions in the
> >>board file. They had to stay in the omap tree not in the sound/ .
> >>Maybe a better place to them could be plat-omap/ ?
> >>    
> >>
> >I dont see plat-omap having stuff other than omap specific code - such as dma etc.. if we put peripheral chip specific code there, i dont see kernel directory's abstraction happening properly sound/.. is the perfect place for this. The issue of linking is a minor problem - which can be handled by using proper include files.
> >Regards,
> >  
> >
> Hi,
> 
> We have put the audio codec files under /arm/arch because we have wanted
> to share the same omap-alsa.c between both codecs.
> And for that reason we need to set the function pointers to omap-alsa.c
> so that the calls from omap-alsa.c ends up to correct codec.
> 
> We have tried to do couple of different method for implementing this and
> have not sofar found any perfect solution.
> 
> In our first attempt we kept all alsa related files in sound/arm/omap
> directory.
> In addition we put get_codec_functions() method to both of the drivers
> and when the module was loaded the omap-alsa.c
> called this get_codec_functions() method. The method had one
> disadvantage, user could not build aic23 and tsc2101 drivers to same kernel
> as both of the drivers had this one function with the same name.
> 
> In our second attemt (the one included in patches) we put the board-code
> to set the function pointers. The drawback in this
> method is that the functions defined in the board-code must itself be
> linked within the board-code, otherwise we
> got linking errors in the end.
> 
> Third (non tested) alternative could work in the following way
> - Move the alsa modules probe method to codecs.
> - when probe is called, it could define the function pointers and set
> them to omap-alsa.c

We should really have all the audio related stuff in sound/arm/omap.
Only core functionality and board init should be in plat-omap and
mach-omap* directories. I could see having some dma-audio related
functions in the plat-omap, but since they are only used with audio,
they may as well be in sound/arm/omap.
 
> Fourth possibility I know would be to make own implementation from
> omap-alsa.c both for both of the codecs
> but that is something I would like to avoid.
> 
> So if you have some idea how to do this, can you give us some info how
> to do that.

Why can't you just have a common module in sound/arm/omap for the codecs,
and then the aic23 and tsc2101 drivers register their functions with it?

Regards,

Tony

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-22 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-20 17:47 [PATCH] Alsa modularisations and support for tsc2101 2/7 Daniel Petrini
2006-02-21 13:31 ` Menon, Nishanth
2006-02-21 14:06   ` Daniel Petrini
2006-02-21 14:08     ` Menon, Nishanth
2006-02-21 23:53       ` lamikr
2006-02-22 18:15         ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox