]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-omap2/mcbsp.c
ARM: OMAP3: pdata-quirks: Add support for McBSP2/3 sidetone handling
[karo-tx-linux.git] / arch / arm / mach-omap2 / mcbsp.c
1 /*
2  * linux/arch/arm/mach-omap2/mcbsp.c
3  *
4  * Copyright (C) 2008 Instituto Nokia de Tecnologia
5  * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * Multichannel mode not supported.
12  */
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/io.h>
18 #include <linux/of.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <linux/platform_data/asoc-ti-mcbsp.h>
22 #include <linux/pm_runtime.h>
23
24 #include <linux/omap-dma.h>
25
26 #include "soc.h"
27 #include "omap_device.h"
28 #include "clock.h"
29
30 /*
31  * FIXME: Find a mechanism to enable/disable runtime the McBSP ICLK autoidle.
32  * Sidetone needs non-gated ICLK and sidetone autoidle is broken.
33  */
34 #include "cm3xxx.h"
35 #include "cm-regbits-34xx.h"
36
37 static struct clk *mcbsp_iclks[5];
38
39 static int omap3_enable_st_clock(unsigned int id, bool enable)
40 {
41         /*
42          * Sidetone uses McBSP ICLK - which must not idle when sidetones
43          * are enabled or sidetones start sounding ugly.
44          */
45         if (enable)
46                 return omap2_clk_deny_idle(mcbsp_iclks[id]);
47         else
48                 return omap2_clk_allow_idle(mcbsp_iclks[id]);
49 }
50
51 static int omap3_mcbsp_force_ick_on(struct clk *clk, bool force_on)
52 {
53         if (!clk)
54                 return 0;
55
56         if (force_on)
57                 return omap2_clk_deny_idle(clk);
58         else
59                 return omap2_clk_allow_idle(clk);
60 }
61
62 void __init omap3_mcbsp_init_pdata_callback(
63                                         struct omap_mcbsp_platform_data *pdata)
64 {
65         if (!pdata)
66                 return;
67
68         pdata->force_ick_on = omap3_mcbsp_force_ick_on;
69 }
70
71 static int __init omap_init_mcbsp(struct omap_hwmod *oh, void *unused)
72 {
73         int id, count = 1;
74         char *name = "omap-mcbsp";
75         struct omap_hwmod *oh_device[2];
76         struct omap_mcbsp_platform_data *pdata = NULL;
77         struct platform_device *pdev;
78         char clk_name[11];
79
80         sscanf(oh->name, "mcbsp%d", &id);
81
82         pdata = kzalloc(sizeof(struct omap_mcbsp_platform_data), GFP_KERNEL);
83         if (!pdata) {
84                 pr_err("%s: No memory for mcbsp\n", __func__);
85                 return -ENOMEM;
86         }
87
88         pdata->reg_step = 4;
89         if (oh->class->rev < MCBSP_CONFIG_TYPE2) {
90                 pdata->reg_size = 2;
91         } else {
92                 pdata->reg_size = 4;
93                 pdata->has_ccr = true;
94         }
95
96         if (oh->class->rev == MCBSP_CONFIG_TYPE2) {
97                 /* The FIFO has 128 locations */
98                 pdata->buffer_size = 0x80;
99         } else if (oh->class->rev == MCBSP_CONFIG_TYPE3) {
100                 if (id == 2)
101                         /* The FIFO has 1024 + 256 locations */
102                         pdata->buffer_size = 0x500;
103                 else
104                         /* The FIFO has 128 locations */
105                         pdata->buffer_size = 0x80;
106         } else if (oh->class->rev == MCBSP_CONFIG_TYPE4) {
107                 /* The FIFO has 128 locations for all instances */
108                 pdata->buffer_size = 0x80;
109         }
110
111         if (oh->class->rev >= MCBSP_CONFIG_TYPE3)
112                 pdata->has_wakeup = true;
113
114         oh_device[0] = oh;
115
116         if (oh->dev_attr) {
117                 oh_device[1] = omap_hwmod_lookup((
118                 (struct omap_mcbsp_dev_attr *)(oh->dev_attr))->sidetone);
119                 pdata->enable_st_clock = omap3_enable_st_clock;
120                 pdata->force_ick_on = omap3_mcbsp_force_ick_on;
121                 sprintf(clk_name, "mcbsp%d_ick", id);
122                 mcbsp_iclks[id] = clk_get(NULL, clk_name);
123                 count++;
124         }
125         pdev = omap_device_build_ss(name, id, oh_device, count, pdata,
126                                     sizeof(*pdata));
127         kfree(pdata);
128         if (IS_ERR(pdev))  {
129                 pr_err("%s: Can't build omap_device for %s:%s.\n", __func__,
130                                         name, oh->name);
131                 return PTR_ERR(pdev);
132         }
133         return 0;
134 }
135
136 static int __init omap2_mcbsp_init(void)
137 {
138         if (!of_have_populated_dt())
139                 omap_hwmod_for_each_by_class("mcbsp", omap_init_mcbsp, NULL);
140
141         return 0;
142 }
143 omap_arch_initcall(omap2_mcbsp_init);