Re: [U-Boot] [PATCH 2/7 V2] Sound: MAX98095: Add the driver for codec

2013-01-25 Thread Simon Glass
On Thu, Jan 24, 2013 at 10:43 PM, Rajeshwari Shinde
rajeshwar...@samsung.com wrote:
 This patch adds the driver for codec MAX98095 required by Snow
 Board

 Signed-off-by: Rajeshwari Shinde rajeshwar...@samsung.com

Acked-by: Simon Glass s...@chromium.org

 ---
 Changes in V2:
 - None
  drivers/sound/Makefile   |1 +
  drivers/sound/max98095.c |  550 
 ++
  drivers/sound/max98095.h |  311 ++
  3 files changed, 862 insertions(+), 0 deletions(-)
  create mode 100644 drivers/sound/max98095.c
  create mode 100644 drivers/sound/max98095.h

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/7 V2] Sound: MAX98095: Add the driver for codec

2013-01-24 Thread Rajeshwari Shinde
This patch adds the driver for codec MAX98095 required by Snow
Board

Signed-off-by: Rajeshwari Shinde rajeshwar...@samsung.com
---
Changes in V2:
- None
 drivers/sound/Makefile   |1 +
 drivers/sound/max98095.c |  550 ++
 drivers/sound/max98095.h |  311 ++
 3 files changed, 862 insertions(+), 0 deletions(-)
 create mode 100644 drivers/sound/max98095.c
 create mode 100644 drivers/sound/max98095.h

diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile
index 8fdffb1..1987ca1 100644
--- a/drivers/sound/Makefile
+++ b/drivers/sound/Makefile
@@ -28,6 +28,7 @@ LIB   := $(obj)libsound.o
 COBJS-$(CONFIG_SOUND)  += sound.o
 COBJS-$(CONFIG_I2S)+= samsung-i2s.o
 COBJS-$(CONFIG_SOUND_WM8994)   += wm8994.o
+COBJS-$(CONFIG_SOUND_MAX98095) += max98095.o
 
 COBJS  := $(COBJS-y)
 SRCS   := $(COBJS:.o=.c)
diff --git a/drivers/sound/max98095.c b/drivers/sound/max98095.c
new file mode 100644
index 000..0beee56
--- /dev/null
+++ b/drivers/sound/max98095.c
@@ -0,0 +1,550 @@
+/*
+ * max98095.c -- MAX98095 ALSA SoC Audio driver
+ *
+ * Copyright 2011 Maxim Integrated Products
+ *
+ * Modified for uboot by R. Chandrasekar (rcse...@samsung.com)
+ *
+ * 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 asm/arch/clk.h
+#include asm/arch/cpu.h
+#include asm/arch/power.h
+#include asm/gpio.h
+#include asm/io.h
+#include common.h
+#include div64.h
+#include fdtdec.h
+#include i2c.h
+#include sound.h
+#include i2s.h
+#include max98095.h
+
+enum max98095_type {
+   MAX98095,
+};
+
+struct max98095_priv {
+   enum max98095_type devtype;
+   unsigned int sysclk;
+   unsigned int rate;
+   unsigned int fmt;
+};
+
+static struct sound_codec_info g_codec_info;
+struct max98095_priv g_max98095_info;
+unsigned int g_max98095_i2c_dev_addr;
+
+/* Index 0 is reserved. */
+int rate_table[] = {0, 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
+   88200, 96000};
+
+/*
+ * Writes value to a device register through i2c
+ *
+ * @param reg  reg number to be write
+ * @param data data to be writen to the above registor
+ *
+ * @return int value 1 for change, 0 for no change or negative error code.
+ */
+static int max98095_i2c_write(unsigned int reg, unsigned char data)
+{
+   debug(%s: Write Addr : 0x%02X, Data :  0x%02X\n,
+   __func__, reg, data);
+   return i2c_write(g_max98095_i2c_dev_addr, reg, 1, data, 1);
+}
+
+/*
+ * Read a value from a device register through i2c
+ *
+ * @param reg  reg number to be read
+ * @param data address of read data to be stored
+ *
+ * @return int value 0 for success, -1 in case of error.
+ */
+static unsigned int max98095_i2c_read(unsigned int reg, unsigned char *data)
+{
+   int ret;
+
+   ret = i2c_read(g_max98095_i2c_dev_addr, reg, 1, data, 1);
+   if (ret != 0) {
+   debug(%s: Error while reading register %#04x\n,
+   __func__, reg);
+   return -1;
+   }
+
+   return 0;
+}
+
+/*
+ * update device register bits through i2c
+ *
+ * @param reg  codec register
+ * @param mask register mask
+ * @param valuenew value
+ *
+ * @return int value 0 for success, non-zero error code.
+ */
+static int max98095_update_bits(unsigned int reg, unsigned char mask,
+   unsigned char value)
+{
+   int change, ret = 0;
+   unsigned char old, new;
+
+   if (max98095_i2c_read(reg, old) != 0)
+   return -1;
+   new = (old  ~mask) | (value  mask);
+   change  = (old != new) ? 1 : 0;
+   if (change)
+   ret = max98095_i2c_write(reg, new);
+   if (ret  0)
+   return ret;
+
+   return change;
+}
+
+/*
+ * codec mclk clock divider coefficients based on sampling rate
+ *
+ * @param rate sampling rate
+ * @param value address of indexvalue to be stored
+ *
+ * @return 0 for success or negative error code.
+ */
+static int rate_value(int rate, u8 *value)
+{
+   int i;
+
+   for (i = 1; i  ARRAY_SIZE(rate_table); i++) {
+   if (rate_table[i] = rate) {
+   *value = i;
+   return 0;
+   }
+   }
+   *value = 1;
+
+   return -1;
+}
+
+/*
+ * Sets hw params for max98095
+ *
+ * @param max98095 max98095 information pointer
+ * @param rate Sampling rate
+ * @param bits_per_sample  Bits per sample
+ *
+ * @return -1 for error  and 0  Success.
+ */
+static int max98095_hw_params(struct max98095_priv *max98095,
+   unsigned int rate, unsigned int bits_per_sample)
+{
+   u8 regval;
+   int error;
+
+   switch (bits_per_sample) {
+   case 16:
+   error = max98095_update_bits(M98095_034_DAI2_FORMAT,
+   M98095_DAI_WS, 0);
+