Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 1 | /* |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 2 | * MFD driver for twl4030 audio submodule, which contains an audio codec, and |
| 3 | * the vibra control. |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 4 | * |
Peter Ujfalusi | 4a7c00c | 2011-05-10 08:59:23 +0300 | [diff] [blame] | 5 | * Author: Peter Ujfalusi <peter.ujfalusi@ti.com> |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 6 | * |
| 7 | * Copyright: (C) 2009 Nokia Corporation |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/fs.h> |
| 30 | #include <linux/platform_device.h> |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 31 | #include <linux/of.h> |
| 32 | #include <linux/of_platform.h> |
Stephen Rothwell | 8bea867 | 2009-12-15 16:33:10 +1100 | [diff] [blame] | 33 | #include <linux/i2c/twl.h> |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 34 | #include <linux/mfd/core.h> |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 35 | #include <linux/mfd/twl4030-audio.h> |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 36 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 37 | #define TWL4030_AUDIO_CELLS 2 |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 38 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 39 | static struct platform_device *twl4030_audio_dev; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 40 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 41 | struct twl4030_audio_resource { |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 42 | int request_count; |
| 43 | u8 reg; |
| 44 | u8 mask; |
| 45 | }; |
| 46 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 47 | struct twl4030_audio { |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 48 | unsigned int audio_mclk; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 49 | struct mutex mutex; |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 50 | struct twl4030_audio_resource resource[TWL4030_AUDIO_RES_MAX]; |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 51 | struct mfd_cell cells[TWL4030_AUDIO_CELLS]; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * Modify the resource, the function returns the content of the register |
| 56 | * after the modification. |
| 57 | */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 58 | static int twl4030_audio_set_resource(enum twl4030_audio_res id, int enable) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 59 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 60 | struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 61 | u8 val; |
| 62 | |
Stephen Rothwell | 8bea867 | 2009-12-15 16:33:10 +1100 | [diff] [blame] | 63 | twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val, |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 64 | audio->resource[id].reg); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 65 | |
| 66 | if (enable) |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 67 | val |= audio->resource[id].mask; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 68 | else |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 69 | val &= ~audio->resource[id].mask; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 70 | |
Stephen Rothwell | 8bea867 | 2009-12-15 16:33:10 +1100 | [diff] [blame] | 71 | twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 72 | val, audio->resource[id].reg); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 73 | |
| 74 | return val; |
| 75 | } |
| 76 | |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 77 | static inline int twl4030_audio_get_resource(enum twl4030_audio_res id) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 78 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 79 | struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 80 | u8 val; |
| 81 | |
Stephen Rothwell | 8bea867 | 2009-12-15 16:33:10 +1100 | [diff] [blame] | 82 | twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val, |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 83 | audio->resource[id].reg); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 84 | |
| 85 | return val; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Enable the resource. |
| 90 | * The function returns with error or the content of the register |
| 91 | */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 92 | int twl4030_audio_enable_resource(enum twl4030_audio_res id) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 93 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 94 | struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 95 | int val; |
| 96 | |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 97 | if (id >= TWL4030_AUDIO_RES_MAX) { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 98 | dev_err(&twl4030_audio_dev->dev, |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 99 | "Invalid resource ID (%u)\n", id); |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 103 | mutex_lock(&audio->mutex); |
| 104 | if (!audio->resource[id].request_count) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 105 | /* Resource was disabled, enable it */ |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 106 | val = twl4030_audio_set_resource(id, 1); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 107 | else |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 108 | val = twl4030_audio_get_resource(id); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 109 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 110 | audio->resource[id].request_count++; |
| 111 | mutex_unlock(&audio->mutex); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 112 | |
| 113 | return val; |
| 114 | } |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 115 | EXPORT_SYMBOL_GPL(twl4030_audio_enable_resource); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Disable the resource. |
| 119 | * The function returns with error or the content of the register |
| 120 | */ |
Mark Brown | 6049bce | 2013-03-02 15:30:35 +0800 | [diff] [blame] | 121 | int twl4030_audio_disable_resource(enum twl4030_audio_res id) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 122 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 123 | struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 124 | int val; |
| 125 | |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 126 | if (id >= TWL4030_AUDIO_RES_MAX) { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 127 | dev_err(&twl4030_audio_dev->dev, |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 128 | "Invalid resource ID (%u)\n", id); |
| 129 | return -EINVAL; |
| 130 | } |
| 131 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 132 | mutex_lock(&audio->mutex); |
| 133 | if (!audio->resource[id].request_count) { |
| 134 | dev_err(&twl4030_audio_dev->dev, |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 135 | "Resource has been disabled already (%u)\n", id); |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 136 | mutex_unlock(&audio->mutex); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 137 | return -EPERM; |
| 138 | } |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 139 | audio->resource[id].request_count--; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 140 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 141 | if (!audio->resource[id].request_count) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 142 | /* Resource can be disabled now */ |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 143 | val = twl4030_audio_set_resource(id, 0); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 144 | else |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 145 | val = twl4030_audio_get_resource(id); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 146 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 147 | mutex_unlock(&audio->mutex); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 148 | |
| 149 | return val; |
| 150 | } |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 151 | EXPORT_SYMBOL_GPL(twl4030_audio_disable_resource); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 152 | |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 153 | unsigned int twl4030_audio_get_mclk(void) |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 154 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 155 | struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev); |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 156 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 157 | return audio->audio_mclk; |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 158 | } |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 159 | EXPORT_SYMBOL_GPL(twl4030_audio_get_mclk); |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 160 | |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 161 | static bool twl4030_audio_has_codec(struct twl4030_audio_data *pdata, |
Johan Hovold | f4c0796 | 2017-11-11 16:38:43 +0100 | [diff] [blame] | 162 | struct device_node *parent) |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 163 | { |
Johan Hovold | f4c0796 | 2017-11-11 16:38:43 +0100 | [diff] [blame] | 164 | struct device_node *node; |
| 165 | |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 166 | if (pdata && pdata->codec) |
| 167 | return true; |
| 168 | |
Johan Hovold | f4c0796 | 2017-11-11 16:38:43 +0100 | [diff] [blame] | 169 | node = of_get_child_by_name(parent, "codec"); |
| 170 | if (node) { |
| 171 | of_node_put(node); |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 172 | return true; |
Johan Hovold | f4c0796 | 2017-11-11 16:38:43 +0100 | [diff] [blame] | 173 | } |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 174 | |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | static bool twl4030_audio_has_vibra(struct twl4030_audio_data *pdata, |
| 179 | struct device_node *node) |
| 180 | { |
| 181 | int vibra; |
| 182 | |
| 183 | if (pdata && pdata->vibra) |
| 184 | return true; |
| 185 | |
| 186 | if (!of_property_read_u32(node, "ti,enable-vibra", &vibra) && vibra) |
| 187 | return true; |
| 188 | |
| 189 | return false; |
| 190 | } |
| 191 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 192 | static int twl4030_audio_probe(struct platform_device *pdev) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 193 | { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 194 | struct twl4030_audio *audio; |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 195 | struct twl4030_audio_data *pdata = dev_get_platdata(&pdev->dev); |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 196 | struct device_node *node = pdev->dev.of_node; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 197 | struct mfd_cell *cell = NULL; |
| 198 | int ret, childs = 0; |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 199 | u8 val; |
| 200 | |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 201 | if (!pdata && !node) { |
Peter Ujfalusi | f9b4639 | 2009-11-04 09:58:19 +0200 | [diff] [blame] | 202 | dev_err(&pdev->dev, "Platform data is missing\n"); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
Peter Ujfalusi | 39c1421 | 2012-09-10 13:46:20 +0300 | [diff] [blame] | 206 | audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio), |
| 207 | GFP_KERNEL); |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 208 | if (!audio) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 209 | return -ENOMEM; |
| 210 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 211 | mutex_init(&audio->mutex); |
Peter Ujfalusi | c531241 | 2012-09-10 13:46:23 +0300 | [diff] [blame] | 212 | audio->audio_mclk = twl_get_hfclk_rate(); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 213 | |
Peter Ujfalusi | cdf4b67 | 2012-09-10 13:46:21 +0300 | [diff] [blame] | 214 | /* Configure APLL_INFREQ and disable APLL if enabled */ |
| 215 | switch (audio->audio_mclk) { |
| 216 | case 19200000: |
| 217 | val = TWL4030_APLL_INFREQ_19200KHZ; |
| 218 | break; |
| 219 | case 26000000: |
| 220 | val = TWL4030_APLL_INFREQ_26000KHZ; |
| 221 | break; |
| 222 | case 38400000: |
| 223 | val = TWL4030_APLL_INFREQ_38400KHZ; |
| 224 | break; |
| 225 | default: |
| 226 | dev_err(&pdev->dev, "Invalid audio_mclk\n"); |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, val, TWL4030_REG_APLL_CTL); |
| 230 | |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 231 | /* Codec power */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 232 | audio->resource[TWL4030_AUDIO_RES_POWER].reg = TWL4030_REG_CODEC_MODE; |
| 233 | audio->resource[TWL4030_AUDIO_RES_POWER].mask = TWL4030_CODECPDZ; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 234 | |
| 235 | /* PLL */ |
Peter Ujfalusi | 57fe725 | 2011-05-31 12:02:49 +0300 | [diff] [blame] | 236 | audio->resource[TWL4030_AUDIO_RES_APLL].reg = TWL4030_REG_APLL_CTL; |
| 237 | audio->resource[TWL4030_AUDIO_RES_APLL].mask = TWL4030_APLL_EN; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 238 | |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 239 | if (twl4030_audio_has_codec(pdata, node)) { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 240 | cell = &audio->cells[childs]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 241 | cell->name = "twl4030-codec"; |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 242 | if (pdata) { |
| 243 | cell->platform_data = pdata->codec; |
| 244 | cell->pdata_size = sizeof(*pdata->codec); |
| 245 | } |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 246 | childs++; |
| 247 | } |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 248 | if (twl4030_audio_has_vibra(pdata, node)) { |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 249 | cell = &audio->cells[childs]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 250 | cell->name = "twl4030-vibra"; |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 251 | if (pdata) { |
| 252 | cell->platform_data = pdata->vibra; |
| 253 | cell->pdata_size = sizeof(*pdata->vibra); |
| 254 | } |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 255 | childs++; |
| 256 | } |
| 257 | |
Peter Ujfalusi | cdf4b67 | 2012-09-10 13:46:21 +0300 | [diff] [blame] | 258 | platform_set_drvdata(pdev, audio); |
| 259 | twl4030_audio_dev = pdev; |
| 260 | |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 261 | if (childs) |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 262 | ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 263 | childs, NULL, 0, NULL); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 264 | else { |
| 265 | dev_err(&pdev->dev, "No platform data found for childs\n"); |
| 266 | ret = -ENODEV; |
| 267 | } |
| 268 | |
Jingoo Han | 96ac2d1 | 2013-05-06 13:06:31 +0900 | [diff] [blame] | 269 | if (ret) |
Peter Ujfalusi | 39c1421 | 2012-09-10 13:46:20 +0300 | [diff] [blame] | 270 | twl4030_audio_dev = NULL; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 271 | |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 272 | return ret; |
| 273 | } |
| 274 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 275 | static int twl4030_audio_remove(struct platform_device *pdev) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 276 | { |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 277 | mfd_remove_devices(&pdev->dev); |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 278 | twl4030_audio_dev = NULL; |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 283 | static const struct of_device_id twl4030_audio_of_match[] = { |
| 284 | {.compatible = "ti,twl4030-audio", }, |
| 285 | { }, |
| 286 | }; |
| 287 | MODULE_DEVICE_TABLE(of, twl4030_audio_of_match); |
| 288 | |
Peter Ujfalusi | 4fe5668 | 2011-05-03 18:03:43 +0300 | [diff] [blame] | 289 | static struct platform_driver twl4030_audio_driver = { |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 290 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 291 | .name = "twl4030-audio", |
Peter Ujfalusi | 019a7e6 | 2012-09-10 13:46:25 +0300 | [diff] [blame] | 292 | .of_match_table = twl4030_audio_of_match, |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 293 | }, |
Peter Ujfalusi | 41569a1 | 2012-09-10 13:46:19 +0300 | [diff] [blame] | 294 | .probe = twl4030_audio_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 295 | .remove = twl4030_audio_remove, |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 296 | }; |
| 297 | |
Mark Brown | 65349d6 | 2011-11-23 22:58:34 +0000 | [diff] [blame] | 298 | module_platform_driver(twl4030_audio_driver); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 299 | |
Peter Ujfalusi | 4a7c00c | 2011-05-10 08:59:23 +0300 | [diff] [blame] | 300 | MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>"); |
Peter Ujfalusi | 41569a1 | 2012-09-10 13:46:19 +0300 | [diff] [blame] | 301 | MODULE_DESCRIPTION("TWL4030 audio block MFD driver"); |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 302 | MODULE_LICENSE("GPL"); |
Peter Ujfalusi | 41569a1 | 2012-09-10 13:46:19 +0300 | [diff] [blame] | 303 | MODULE_ALIAS("platform:twl4030-audio"); |