Blame view
drivers/mfd/wl1273-core.c
6.3 KB
383268a8e [media] MFD: WL12... |
1 2 3 |
/* * MFD driver for wl1273 FM radio and audio codec submodules. * |
94fd5b740 [media] MFD: WL12... |
4 |
* Copyright (C) 2011 Nokia Corporation |
383268a8e [media] MFD: WL12... |
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
* Author: Matti Aaltonen <matti.j.aaltonen@nokia.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include <linux/mfd/wl1273-core.h> #include <linux/slab.h> |
4e36dd331 mfd: Add module.h... |
25 |
#include <linux/module.h> |
383268a8e [media] MFD: WL12... |
26 27 |
#define DRIVER_DESC "WL1273 FM Radio Core" |
1206552b0 mfd: Constify i2c... |
28 |
static const struct i2c_device_id wl1273_driver_id_table[] = { |
383268a8e [media] MFD: WL12... |
29 30 31 32 |
{ WL1273_FM_DRIVER_NAME, 0 }, { } }; MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table); |
94fd5b740 [media] MFD: WL12... |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
static int wl1273_fm_read_reg(struct wl1273_core *core, u8 reg, u16 *value) { struct i2c_client *client = core->client; u8 b[2]; int r; r = i2c_smbus_read_i2c_block_data(client, reg, sizeof(b), b); if (r != 2) { dev_err(&client->dev, "%s: Read: %d fails. ", __func__, reg); return -EREMOTEIO; } *value = (u16)b[0] << 8 | b[1]; return 0; } static int wl1273_fm_write_cmd(struct wl1273_core *core, u8 cmd, u16 param) { struct i2c_client *client = core->client; u8 buf[] = { (param >> 8) & 0xff, param & 0xff }; int r; r = i2c_smbus_write_i2c_block_data(client, cmd, sizeof(buf), buf); if (r) { dev_err(&client->dev, "%s: Cmd: %d fails. ", __func__, cmd); return r; } return 0; } static int wl1273_fm_write_data(struct wl1273_core *core, u8 *data, u16 len) { struct i2c_client *client = core->client; struct i2c_msg msg; int r; msg.addr = client->addr; msg.flags = 0; msg.buf = data; msg.len = len; r = i2c_transfer(client->adapter, &msg, 1); if (r != 1) { dev_err(&client->dev, "%s: write error. ", __func__); return -EREMOTEIO; } return 0; } /** * wl1273_fm_set_audio() - Set audio mode. * @core: A pointer to the device struct. * @new_mode: The new audio mode. * * Audio modes are WL1273_AUDIO_DIGITAL and WL1273_AUDIO_ANALOG. */ static int wl1273_fm_set_audio(struct wl1273_core *core, unsigned int new_mode) { int r = 0; if (core->mode == WL1273_MODE_OFF || core->mode == WL1273_MODE_SUSPENDED) return -EPERM; if (core->mode == WL1273_MODE_RX && new_mode == WL1273_AUDIO_DIGITAL) { r = wl1273_fm_write_cmd(core, WL1273_PCM_MODE_SET, WL1273_PCM_DEF_MODE); if (r) goto out; r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET, core->i2s_mode); if (r) goto out; r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE, WL1273_AUDIO_ENABLE_I2S); if (r) goto out; } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_AUDIO_ANALOG) { r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE, WL1273_AUDIO_ENABLE_ANALOG); if (r) goto out; } else if (core->mode == WL1273_MODE_TX && new_mode == WL1273_AUDIO_DIGITAL) { r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET, core->i2s_mode); if (r) goto out; r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET, WL1273_AUDIO_IO_SET_I2S); if (r) goto out; } else if (core->mode == WL1273_MODE_TX && new_mode == WL1273_AUDIO_ANALOG) { r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET, WL1273_AUDIO_IO_SET_ANALOG); if (r) goto out; } core->audio_mode = new_mode; out: return r; } /** * wl1273_fm_set_volume() - Set volume. * @core: A pointer to the device struct. * @volume: The new volume value. */ static int wl1273_fm_set_volume(struct wl1273_core *core, unsigned int volume) { |
94fd5b740 [media] MFD: WL12... |
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
int r; if (volume > WL1273_MAX_VOLUME) return -EINVAL; if (core->volume == volume) return 0; r = wl1273_fm_write_cmd(core, WL1273_VOLUME_SET, volume); if (r) return r; core->volume = volume; return 0; } |
f791be492 mfd: remove use o... |
173 |
static int wl1273_core_probe(struct i2c_client *client, |
383268a8e [media] MFD: WL12... |
174 175 |
const struct i2c_device_id *id) { |
334a41ce9 mfd: Use dev_get_... |
176 |
struct wl1273_fm_platform_data *pdata = dev_get_platdata(&client->dev); |
383268a8e [media] MFD: WL12... |
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
struct wl1273_core *core; struct mfd_cell *cell; int children = 0; int r = 0; dev_dbg(&client->dev, "%s ", __func__); if (!pdata) { dev_err(&client->dev, "No platform data. "); return -EINVAL; } if (!(pdata->children & WL1273_RADIO_CHILD)) { dev_err(&client->dev, "Cannot function without radio child. "); return -EINVAL; } |
bba078273 mfd: wl1273: Use ... |
196 |
core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); |
383268a8e [media] MFD: WL12... |
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
if (!core) return -ENOMEM; core->pdata = pdata; core->client = client; mutex_init(&core->lock); i2c_set_clientdata(client, core); dev_dbg(&client->dev, "%s: Have V4L2. ", __func__); cell = &core->cells[children]; cell->name = "wl1273_fm_radio"; |
9e554696c mfd: Use mfd cell... |
211 212 |
cell->platform_data = &core; cell->pdata_size = sizeof(core); |
383268a8e [media] MFD: WL12... |
213 |
children++; |
94fd5b740 [media] MFD: WL12... |
214 215 216 217 218 |
core->read = wl1273_fm_read_reg; core->write = wl1273_fm_write_cmd; core->write_data = wl1273_fm_write_data; core->set_audio = wl1273_fm_set_audio; core->set_volume = wl1273_fm_set_volume; |
383268a8e [media] MFD: WL12... |
219 220 221 222 223 224 |
if (pdata->children & WL1273_CODEC_CHILD) { cell = &core->cells[children]; dev_dbg(&client->dev, "%s: Have codec. ", __func__); cell->name = "wl1273-codec"; |
9e554696c mfd: Use mfd cell... |
225 226 |
cell->platform_data = &core; cell->pdata_size = sizeof(core); |
383268a8e [media] MFD: WL12... |
227 228 229 230 231 232 |
children++; } dev_dbg(&client->dev, "%s: number of children: %d. ", __func__, children); |
14856f758 mfd: wl1273-core:... |
233 234 |
r = devm_mfd_add_devices(&client->dev, -1, core->cells, children, NULL, 0, NULL); |
383268a8e [media] MFD: WL12... |
235 236 237 238 239 240 |
if (r) goto err; return 0; err: |
383268a8e [media] MFD: WL12... |
241 |
pdata->free_resources(); |
383268a8e [media] MFD: WL12... |
242 243 244 245 246 247 248 249 250 251 252 253 254 |
dev_dbg(&client->dev, "%s ", __func__); return r; } static struct i2c_driver wl1273_core_driver = { .driver = { .name = WL1273_FM_DRIVER_NAME, }, .probe = wl1273_core_probe, .id_table = wl1273_driver_id_table, |
383268a8e [media] MFD: WL12... |
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
}; static int __init wl1273_core_init(void) { int r; r = i2c_add_driver(&wl1273_core_driver); if (r) { pr_err(WL1273_FM_DRIVER_NAME ": driver registration failed "); return r; } return r; } static void __exit wl1273_core_exit(void) { i2c_del_driver(&wl1273_core_driver); } late_initcall(wl1273_core_init); module_exit(wl1273_core_exit); MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>"); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); |