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