Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 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/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 20 | |
Tony Lindgren | dd7667a | 2009-01-15 13:09:51 +0200 | [diff] [blame] | 21 | #include <mach/irqs.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 22 | #include <plat/dma.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 23 | #include <plat/cpu.h> |
| 24 | #include <plat/mcbsp.h> |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 25 | #include <plat/omap_device.h> |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 27 | |
| 28 | #include "control.h" |
| 29 | |
Jarkko Nikula | 1743d14 | 2011-09-26 10:45:44 +0300 | [diff] [blame^] | 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 "cm2xxx_3xxx.h" |
| 35 | #include "cm-regbits-34xx.h" |
| 36 | |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 37 | /* McBSP internal signal muxing functions */ |
| 38 | |
| 39 | void omap2_mcbsp1_mux_clkr_src(u8 mux) |
| 40 | { |
| 41 | u32 v; |
| 42 | |
| 43 | v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 44 | if (mux == CLKR_SRC_CLKR) |
Jarkko Nikula | 425925d | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 45 | v &= ~OMAP2_MCBSP1_CLKR_MASK; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 46 | else if (mux == CLKR_SRC_CLKX) |
| 47 | v |= OMAP2_MCBSP1_CLKR_MASK; |
| 48 | omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0); |
| 49 | } |
| 50 | EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src); |
| 51 | |
| 52 | void omap2_mcbsp1_mux_fsr_src(u8 mux) |
| 53 | { |
| 54 | u32 v; |
| 55 | |
| 56 | v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
| 57 | if (mux == FSR_SRC_FSR) |
Jarkko Nikula | 425925d | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 58 | v &= ~OMAP2_MCBSP1_FSR_MASK; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 59 | else if (mux == FSR_SRC_FSX) |
| 60 | v |= OMAP2_MCBSP1_FSR_MASK; |
| 61 | omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0); |
| 62 | } |
| 63 | EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src); |
| 64 | |
Paul Walmsley | d135865 | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 65 | /* McBSP CLKS source switching function */ |
| 66 | |
| 67 | int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id) |
| 68 | { |
| 69 | struct omap_mcbsp *mcbsp; |
| 70 | struct clk *fck_src; |
| 71 | char *fck_src_name; |
| 72 | int r; |
| 73 | |
| 74 | if (!omap_mcbsp_check_valid_id(id)) { |
| 75 | pr_err("%s: Invalid id (%d)\n", __func__, id + 1); |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | mcbsp = id_to_mcbsp_ptr(id); |
| 79 | |
| 80 | if (fck_src_id == MCBSP_CLKS_PAD_SRC) |
| 81 | fck_src_name = "pad_fck"; |
| 82 | else if (fck_src_id == MCBSP_CLKS_PRCM_SRC) |
| 83 | fck_src_name = "prcm_fck"; |
| 84 | else |
| 85 | return -EINVAL; |
| 86 | |
| 87 | fck_src = clk_get(mcbsp->dev, fck_src_name); |
| 88 | if (IS_ERR_OR_NULL(fck_src)) { |
| 89 | pr_err("omap-mcbsp: %s: could not clk_get() %s\n", "clks", |
| 90 | fck_src_name); |
| 91 | return -EINVAL; |
| 92 | } |
| 93 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 94 | pm_runtime_put_sync(mcbsp->dev); |
Paul Walmsley | d135865 | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 95 | |
| 96 | r = clk_set_parent(mcbsp->fclk, fck_src); |
| 97 | if (IS_ERR_VALUE(r)) { |
| 98 | pr_err("omap-mcbsp: %s: could not clk_set_parent() to %s\n", |
| 99 | "clks", fck_src_name); |
| 100 | clk_put(fck_src); |
| 101 | return -EINVAL; |
| 102 | } |
| 103 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 104 | pm_runtime_get_sync(mcbsp->dev); |
Paul Walmsley | d135865 | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 105 | |
| 106 | clk_put(fck_src); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | EXPORT_SYMBOL(omap2_mcbsp_set_clks_src); |
| 111 | |
Jarkko Nikula | 1743d14 | 2011-09-26 10:45:44 +0300 | [diff] [blame^] | 112 | static int omap3_enable_st_clock(unsigned int id, bool enable) |
| 113 | { |
| 114 | unsigned int w; |
| 115 | |
| 116 | /* |
| 117 | * Sidetone uses McBSP ICLK - which must not idle when sidetones |
| 118 | * are enabled or sidetones start sounding ugly. |
| 119 | */ |
| 120 | w = omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE); |
| 121 | if (enable) |
| 122 | w &= ~(1 << (id - 2)); |
| 123 | else |
| 124 | w |= 1 << (id - 2); |
| 125 | omap2_cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 130 | struct omap_device_pm_latency omap2_mcbsp_latency[] = { |
Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 131 | { |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 132 | .deactivate_func = omap_device_idle_hwmods, |
| 133 | .activate_func = omap_device_enable_hwmods, |
| 134 | .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST, |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 135 | }, |
| 136 | }; |
| 137 | |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 138 | static int omap_init_mcbsp(struct omap_hwmod *oh, void *unused) |
| 139 | { |
| 140 | int id, count = 1; |
| 141 | char *name = "omap-mcbsp"; |
| 142 | struct omap_hwmod *oh_device[2]; |
| 143 | struct omap_mcbsp_platform_data *pdata = NULL; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 144 | struct platform_device *pdev; |
Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 145 | |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 146 | sscanf(oh->name, "mcbsp%d", &id); |
| 147 | |
| 148 | pdata = kzalloc(sizeof(struct omap_mcbsp_platform_data), GFP_KERNEL); |
| 149 | if (!pdata) { |
| 150 | pr_err("%s: No memory for mcbsp\n", __func__); |
| 151 | return -ENOMEM; |
| 152 | } |
| 153 | |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 154 | pdata->reg_step = 4; |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 155 | if (oh->class->rev < MCBSP_CONFIG_TYPE2) { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 156 | pdata->reg_size = 2; |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 157 | } else { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 158 | pdata->reg_size = 4; |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 159 | pdata->has_ccr = true; |
| 160 | } |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 161 | |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 162 | if (oh->class->rev == MCBSP_CONFIG_TYPE3) { |
| 163 | if (id == 2) |
| 164 | /* The FIFO has 1024 + 256 locations */ |
| 165 | pdata->buffer_size = 0x500; |
| 166 | else |
| 167 | /* The FIFO has 128 locations */ |
| 168 | pdata->buffer_size = 0x80; |
| 169 | } |
| 170 | |
Jarkko Nikula | 1a64588 | 2011-09-26 10:45:40 +0300 | [diff] [blame] | 171 | if (oh->class->rev >= MCBSP_CONFIG_TYPE3) |
| 172 | pdata->has_wakeup = true; |
| 173 | |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 174 | oh_device[0] = oh; |
| 175 | |
| 176 | if (oh->dev_attr) { |
| 177 | oh_device[1] = omap_hwmod_lookup(( |
| 178 | (struct omap_mcbsp_dev_attr *)(oh->dev_attr))->sidetone); |
Jarkko Nikula | 1743d14 | 2011-09-26 10:45:44 +0300 | [diff] [blame^] | 179 | pdata->enable_st_clock = omap3_enable_st_clock; |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 180 | count++; |
| 181 | } |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 182 | pdev = omap_device_build_ss(name, id, oh_device, count, pdata, |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 183 | sizeof(*pdata), omap2_mcbsp_latency, |
| 184 | ARRAY_SIZE(omap2_mcbsp_latency), false); |
| 185 | kfree(pdata); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 186 | if (IS_ERR(pdev)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 187 | pr_err("%s: Can't build omap_device for %s:%s.\n", __func__, |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 188 | name, oh->name); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 189 | return PTR_ERR(pdev); |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 190 | } |
| 191 | omap_mcbsp_count++; |
| 192 | return 0; |
| 193 | } |
Syed Rafiuddin | a5b92cc | 2009-07-28 18:57:10 +0530 | [diff] [blame] | 194 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 195 | static int __init omap2_mcbsp_init(void) |
Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 196 | { |
Kishon Vijay Abraham I | 64bcbd3 | 2011-02-24 15:16:52 +0530 | [diff] [blame] | 197 | omap_hwmod_for_each_by_class("mcbsp", omap_init_mcbsp, NULL); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 198 | |
| 199 | mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *), |
| 200 | GFP_KERNEL); |
| 201 | if (!mcbsp_ptr) |
| 202 | return -ENOMEM; |
| 203 | |
Eduardo Valentin | 78673bc | 2008-07-03 12:24:40 +0300 | [diff] [blame] | 204 | return omap_mcbsp_init(); |
| 205 | } |
| 206 | arch_initcall(omap2_mcbsp_init); |