~ubuntu-branches/ubuntu/trusty/apex/trusty

« back to all changes in this revision

Viewing changes to src/mach-mx3/cmd-wm8955.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2009-11-10 11:55:15 UTC
  • mfrom: (2.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091110115515-6jjsf6rc8py35awe
Tags: 1.6.10ubuntu1
* Merge from debian testing, remaining changes:
  - Move apex VMA address to 4MiB to leave enough space for the ubuntu
  kernel and not overwrite apex in ram when loading.
  - nslu2 configuration: set CONFIG_RAMDISK_SIZE=0x0055FFF0 instead of
  0x005FFFF0 to make enough room for ubuntu initramfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* cmd-wm8955.c
 
2
 
 
3
   written by Marc Singer
 
4
   22 Dec 2008
 
5
 
 
6
   Copyright (C) 2008 Marc Singer
 
7
 
 
8
   -----------
 
9
   DESCRIPTION
 
10
   -----------
 
11
 
 
12
   APEX command for sending control messages to the WM8955 codec.
 
13
 
 
14
*/
 
15
 
 
16
 
 
17
 
 
18
#include <config.h>
 
19
#include <apex.h>
 
20
#include <driver.h>
 
21
#include <service.h>
 
22
#include <command.h>
 
23
#include <linux/string.h>
 
24
#include <linux/kernel.h>
 
25
#include <spinner.h>
 
26
#include <asm/reg.h>
 
27
#include <error.h>
 
28
#include <environment.h>
 
29
#include <lookup.h>
 
30
 
 
31
//#define TALK 1
 
32
#include <talk.h>
 
33
 
 
34
#include "hardware.h"
 
35
 
 
36
#if defined (CONFIG_ENV)
 
37
static __env struct env_d e_wm8955_i2c_drv = {
 
38
  .key = "wm8955-i2c-drv",
 
39
  .default_value = CONFIG_DRIVER_WM8955_I2C_DRIVER,
 
40
  .description = "I2C driver for wm8955 codec control interface",
 
41
};
 
42
#endif
 
43
 
 
44
static inline const char* i2c_driver (void)
 
45
{
 
46
  return lookup_alias_or_env ("wm8955-i2c-drv",
 
47
                              CONFIG_DRIVER_WM8955_I2C_DRIVER);
 
48
}
 
49
 
 
50
 
 
51
static int cmd_wm8955 (int argc, const char** argv)
 
52
{
 
53
  int reg;
 
54
  int data;
 
55
  char rgb[2];
 
56
  u16 message;
 
57
  struct descriptor_d d;
 
58
  int result;
 
59
 
 
60
  if (argc < 3)
 
61
    return ERROR_PARAM;
 
62
 
 
63
  reg  = simple_strtoul (argv[1], NULL, 0);
 
64
  data = simple_strtoul (argv[2], NULL, 0);
 
65
 
 
66
  if (   (result = parse_descriptor (i2c_driver (), &d))
 
67
      || (result = open_descriptor (&d))) {
 
68
    PRINTF ("%s: unable to open i2c driver '%s'\n", __FUNCTION__, sz);
 
69
    return result;
 
70
  }
 
71
 
 
72
  message = ((reg & 0x7f) << 9) | (data & 0x1ff);
 
73
  rgb[0] = (message >> 8) & 0xff;
 
74
  rgb[1] = (message >> 0) & 0xff;
 
75
 
 
76
  printf ("writing [%2d (0x%02x)]<- 0x%03x 0x%x 0x%x\n",
 
77
          reg, reg, data, rgb[0], rgb[1]);
 
78
 
 
79
  result = d.driver->write (&d, rgb, 2);
 
80
  close_descriptor (&d);
 
81
 
 
82
  return (result == 2) ? 0 : result;
 
83
}
 
84
 
 
85
 
 
86
void wm8955_init (void)
 
87
{
 
88
  /* MCLK pin to WM8955L */
 
89
  IOMUX_PIN_CONFIG_GPIO  (MX31_PIN_GPIO3_1);
 
90
  GPIO_PIN_CONFIG_OUTPUT (MX31_PIN_GPIO3_1);
 
91
  GPIO_PIN_SET           (MX31_PIN_GPIO3_1);
 
92
}
 
93
 
 
94
static __service_6 struct service_d wm8955_service = {
 
95
  .init = wm8955_init,
 
96
//  .release = wm8955_release,
 
97
#if !defined (CONFIG_SMALL)
 
98
//  .report = wm8955_report,
 
99
#endif
 
100
};
 
101
 
 
102
 
 
103
static __command struct command_d c_wm8955 = {
 
104
  .command = "wm8955",
 
105
  .func = (command_func_t) cmd_wm8955,
 
106
  COMMAND_DESCRIPTION ("send I2C commands to wm8955")
 
107
  COMMAND_HELP(
 
108
"wm8955 REG DATA\n"
 
109
"  Send DATA to REG of the WM8955L.\n"
 
110
  )
 
111
};