diff options
author | Matti Aaltonen <matti.j.aaltonen@nokia.com> | 2011-03-01 08:10:35 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-21 19:32:39 -0400 |
commit | 94fd5b7401e330498331ea3667d796e74c63d08a (patch) | |
tree | 037c0c0d24d0440994e2ff209b4707d0a1028300 /drivers/mfd | |
parent | 3822f18d8f1c2cf13ade623b2bba6d4a7a1a3f53 (diff) |
[media] MFD: WL1273 FM Radio: MFD driver for the FM radio
This is the core of the WL1273 FM radio driver, it connects
the two child modules. The two child drivers are
drivers/media/radio/radio-wl1273.c and sound/soc/codecs/wl1273.c.
The radio-wl1273 driver implements the V4L2 interface and communicates
with the device. The ALSA codec offers digital audio, without it only
analog audio is available.
Signed-off-by: Matti J. Aaltonen <matti.j.aaltonen@nokia.com>
Acked-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/Kconfig | 2 | ||||
-rw-r--r-- | drivers/mfd/wl1273-core.c | 149 |
2 files changed, 147 insertions, 4 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index fd018366d670..9db079be0e08 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -615,7 +615,7 @@ config MFD_VX855 | |||
615 | and/or vx855_gpio drivers for this to do anything useful. | 615 | and/or vx855_gpio drivers for this to do anything useful. |
616 | 616 | ||
617 | config MFD_WL1273_CORE | 617 | config MFD_WL1273_CORE |
618 | tristate | 618 | tristate "Support for TI WL1273 FM radio." |
619 | depends on I2C | 619 | depends on I2C |
620 | select MFD_CORE | 620 | select MFD_CORE |
621 | default n | 621 | default n |
diff --git a/drivers/mfd/wl1273-core.c b/drivers/mfd/wl1273-core.c index d2ecc2435736..4025a4bec8d5 100644 --- a/drivers/mfd/wl1273-core.c +++ b/drivers/mfd/wl1273-core.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * MFD driver for wl1273 FM radio and audio codec submodules. | 2 | * MFD driver for wl1273 FM radio and audio codec submodules. |
3 | * | 3 | * |
4 | * Copyright (C) 2010 Nokia Corporation | 4 | * Copyright (C) 2011 Nokia Corporation |
5 | * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com> | 5 | * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
@@ -31,6 +31,145 @@ static struct i2c_device_id wl1273_driver_id_table[] = { | |||
31 | }; | 31 | }; |
32 | MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table); | 32 | MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table); |
33 | 33 | ||
34 | static int wl1273_fm_read_reg(struct wl1273_core *core, u8 reg, u16 *value) | ||
35 | { | ||
36 | struct i2c_client *client = core->client; | ||
37 | u8 b[2]; | ||
38 | int r; | ||
39 | |||
40 | r = i2c_smbus_read_i2c_block_data(client, reg, sizeof(b), b); | ||
41 | if (r != 2) { | ||
42 | dev_err(&client->dev, "%s: Read: %d fails.\n", __func__, reg); | ||
43 | return -EREMOTEIO; | ||
44 | } | ||
45 | |||
46 | *value = (u16)b[0] << 8 | b[1]; | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static int wl1273_fm_write_cmd(struct wl1273_core *core, u8 cmd, u16 param) | ||
52 | { | ||
53 | struct i2c_client *client = core->client; | ||
54 | u8 buf[] = { (param >> 8) & 0xff, param & 0xff }; | ||
55 | int r; | ||
56 | |||
57 | r = i2c_smbus_write_i2c_block_data(client, cmd, sizeof(buf), buf); | ||
58 | if (r) { | ||
59 | dev_err(&client->dev, "%s: Cmd: %d fails.\n", __func__, cmd); | ||
60 | return r; | ||
61 | } | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static int wl1273_fm_write_data(struct wl1273_core *core, u8 *data, u16 len) | ||
67 | { | ||
68 | struct i2c_client *client = core->client; | ||
69 | struct i2c_msg msg; | ||
70 | int r; | ||
71 | |||
72 | msg.addr = client->addr; | ||
73 | msg.flags = 0; | ||
74 | msg.buf = data; | ||
75 | msg.len = len; | ||
76 | |||
77 | r = i2c_transfer(client->adapter, &msg, 1); | ||
78 | if (r != 1) { | ||
79 | dev_err(&client->dev, "%s: write error.\n", __func__); | ||
80 | return -EREMOTEIO; | ||
81 | } | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * wl1273_fm_set_audio() - Set audio mode. | ||
88 | * @core: A pointer to the device struct. | ||
89 | * @new_mode: The new audio mode. | ||
90 | * | ||
91 | * Audio modes are WL1273_AUDIO_DIGITAL and WL1273_AUDIO_ANALOG. | ||
92 | */ | ||
93 | static int wl1273_fm_set_audio(struct wl1273_core *core, unsigned int new_mode) | ||
94 | { | ||
95 | int r = 0; | ||
96 | |||
97 | if (core->mode == WL1273_MODE_OFF || | ||
98 | core->mode == WL1273_MODE_SUSPENDED) | ||
99 | return -EPERM; | ||
100 | |||
101 | if (core->mode == WL1273_MODE_RX && new_mode == WL1273_AUDIO_DIGITAL) { | ||
102 | r = wl1273_fm_write_cmd(core, WL1273_PCM_MODE_SET, | ||
103 | WL1273_PCM_DEF_MODE); | ||
104 | if (r) | ||
105 | goto out; | ||
106 | |||
107 | r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET, | ||
108 | core->i2s_mode); | ||
109 | if (r) | ||
110 | goto out; | ||
111 | |||
112 | r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE, | ||
113 | WL1273_AUDIO_ENABLE_I2S); | ||
114 | if (r) | ||
115 | goto out; | ||
116 | |||
117 | } else if (core->mode == WL1273_MODE_RX && | ||
118 | new_mode == WL1273_AUDIO_ANALOG) { | ||
119 | r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE, | ||
120 | WL1273_AUDIO_ENABLE_ANALOG); | ||
121 | if (r) | ||
122 | goto out; | ||
123 | |||
124 | } else if (core->mode == WL1273_MODE_TX && | ||
125 | new_mode == WL1273_AUDIO_DIGITAL) { | ||
126 | r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET, | ||
127 | core->i2s_mode); | ||
128 | if (r) | ||
129 | goto out; | ||
130 | |||
131 | r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET, | ||
132 | WL1273_AUDIO_IO_SET_I2S); | ||
133 | if (r) | ||
134 | goto out; | ||
135 | |||
136 | } else if (core->mode == WL1273_MODE_TX && | ||
137 | new_mode == WL1273_AUDIO_ANALOG) { | ||
138 | r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET, | ||
139 | WL1273_AUDIO_IO_SET_ANALOG); | ||
140 | if (r) | ||
141 | goto out; | ||
142 | } | ||
143 | |||
144 | core->audio_mode = new_mode; | ||
145 | out: | ||
146 | return r; | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * wl1273_fm_set_volume() - Set volume. | ||
151 | * @core: A pointer to the device struct. | ||
152 | * @volume: The new volume value. | ||
153 | */ | ||
154 | static int wl1273_fm_set_volume(struct wl1273_core *core, unsigned int volume) | ||
155 | { | ||
156 | u16 val; | ||
157 | int r; | ||
158 | |||
159 | if (volume > WL1273_MAX_VOLUME) | ||
160 | return -EINVAL; | ||
161 | |||
162 | if (core->volume == volume) | ||
163 | return 0; | ||
164 | |||
165 | r = wl1273_fm_write_cmd(core, WL1273_VOLUME_SET, volume); | ||
166 | if (r) | ||
167 | return r; | ||
168 | |||
169 | core->volume = volume; | ||
170 | return 0; | ||
171 | } | ||
172 | |||
34 | static int wl1273_core_remove(struct i2c_client *client) | 173 | static int wl1273_core_remove(struct i2c_client *client) |
35 | { | 174 | { |
36 | struct wl1273_core *core = i2c_get_clientdata(client); | 175 | struct wl1273_core *core = i2c_get_clientdata(client); |
@@ -38,7 +177,6 @@ static int wl1273_core_remove(struct i2c_client *client) | |||
38 | dev_dbg(&client->dev, "%s\n", __func__); | 177 | dev_dbg(&client->dev, "%s\n", __func__); |
39 | 178 | ||
40 | mfd_remove_devices(&client->dev); | 179 | mfd_remove_devices(&client->dev); |
41 | i2c_set_clientdata(client, NULL); | ||
42 | kfree(core); | 180 | kfree(core); |
43 | 181 | ||
44 | return 0; | 182 | return 0; |
@@ -83,6 +221,12 @@ static int __devinit wl1273_core_probe(struct i2c_client *client, | |||
83 | cell->data_size = sizeof(core); | 221 | cell->data_size = sizeof(core); |
84 | children++; | 222 | children++; |
85 | 223 | ||
224 | core->read = wl1273_fm_read_reg; | ||
225 | core->write = wl1273_fm_write_cmd; | ||
226 | core->write_data = wl1273_fm_write_data; | ||
227 | core->set_audio = wl1273_fm_set_audio; | ||
228 | core->set_volume = wl1273_fm_set_volume; | ||
229 | |||
86 | if (pdata->children & WL1273_CODEC_CHILD) { | 230 | if (pdata->children & WL1273_CODEC_CHILD) { |
87 | cell = &core->cells[children]; | 231 | cell = &core->cells[children]; |
88 | 232 | ||
@@ -104,7 +248,6 @@ static int __devinit wl1273_core_probe(struct i2c_client *client, | |||
104 | return 0; | 248 | return 0; |
105 | 249 | ||
106 | err: | 250 | err: |
107 | i2c_set_clientdata(client, NULL); | ||
108 | pdata->free_resources(); | 251 | pdata->free_resources(); |
109 | kfree(core); | 252 | kfree(core); |
110 | 253 | ||