aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Aaltonen <matti.j.aaltonen@nokia.com>2010-12-10 09:41:33 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-12-29 05:17:02 -0500
commit383268a8e282fb549dabe3a33ccafc9434ab6006 (patch)
treee4f4f03c0a609086f43860da1da4d7051f86bcb6
parent00765f16f116b45aa67de306ac923ed4ba262bf9 (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>
-rw-r--r--drivers/mfd/Kconfig10
-rw-r--r--drivers/mfd/Makefile1
-rw-r--r--drivers/mfd/wl1273-core.c148
-rw-r--r--include/linux/mfd/wl1273-core.h288
4 files changed, 447 insertions, 0 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3a1493b8b5e5..05ccab6fa919 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -606,6 +606,16 @@ config MFD_VX855
606 VIA VX855/VX875 south bridge. You will need to enable the vx855_spi 606 VIA VX855/VX875 south bridge. You will need to enable the vx855_spi
607 and/or vx855_gpio drivers for this to do anything useful. 607 and/or vx855_gpio drivers for this to do anything useful.
608 608
609config MFD_WL1273_CORE
610 tristate
611 depends on I2C
612 select MFD_CORE
613 default n
614 help
615 This is the core driver for the TI WL1273 FM radio. This MFD
616 driver connects the radio-wl1273 V4L2 module and the wl1273
617 audio codec.
618
609endif # MFD_SUPPORT 619endif # MFD_SUPPORT
610 620
611menu "Multimedia Capabilities Port drivers" 621menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f54b3659abbb..ae2f9153174a 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -81,3 +81,4 @@ obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o
81obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o 81obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o
82obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o 82obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o
83obj-$(CONFIG_MFD_VX855) += vx855.o 83obj-$(CONFIG_MFD_VX855) += vx855.o
84obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o
diff --git a/drivers/mfd/wl1273-core.c b/drivers/mfd/wl1273-core.c
new file mode 100644
index 000000000000..d2ecc2435736
--- /dev/null
+++ b/drivers/mfd/wl1273-core.c
@@ -0,0 +1,148 @@
1/*
2 * MFD driver for wl1273 FM radio and audio codec submodules.
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com>
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 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/mfd/wl1273-core.h>
24#include <linux/slab.h>
25
26#define DRIVER_DESC "WL1273 FM Radio Core"
27
28static struct i2c_device_id wl1273_driver_id_table[] = {
29 { WL1273_FM_DRIVER_NAME, 0 },
30 { }
31};
32MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table);
33
34static int wl1273_core_remove(struct i2c_client *client)
35{
36 struct wl1273_core *core = i2c_get_clientdata(client);
37
38 dev_dbg(&client->dev, "%s\n", __func__);
39
40 mfd_remove_devices(&client->dev);
41 i2c_set_clientdata(client, NULL);
42 kfree(core);
43
44 return 0;
45}
46
47static int __devinit wl1273_core_probe(struct i2c_client *client,
48 const struct i2c_device_id *id)
49{
50 struct wl1273_fm_platform_data *pdata = client->dev.platform_data;
51 struct wl1273_core *core;
52 struct mfd_cell *cell;
53 int children = 0;
54 int r = 0;
55
56 dev_dbg(&client->dev, "%s\n", __func__);
57
58 if (!pdata) {
59 dev_err(&client->dev, "No platform data.\n");
60 return -EINVAL;
61 }
62
63 if (!(pdata->children & WL1273_RADIO_CHILD)) {
64 dev_err(&client->dev, "Cannot function without radio child.\n");
65 return -EINVAL;
66 }
67
68 core = kzalloc(sizeof(*core), GFP_KERNEL);
69 if (!core)
70 return -ENOMEM;
71
72 core->pdata = pdata;
73 core->client = client;
74 mutex_init(&core->lock);
75
76 i2c_set_clientdata(client, core);
77
78 dev_dbg(&client->dev, "%s: Have V4L2.\n", __func__);
79
80 cell = &core->cells[children];
81 cell->name = "wl1273_fm_radio";
82 cell->platform_data = &core;
83 cell->data_size = sizeof(core);
84 children++;
85
86 if (pdata->children & WL1273_CODEC_CHILD) {
87 cell = &core->cells[children];
88
89 dev_dbg(&client->dev, "%s: Have codec.\n", __func__);
90 cell->name = "wl1273-codec";
91 cell->platform_data = &core;
92 cell->data_size = sizeof(core);
93 children++;
94 }
95
96 dev_dbg(&client->dev, "%s: number of children: %d.\n",
97 __func__, children);
98
99 r = mfd_add_devices(&client->dev, -1, core->cells,
100 children, NULL, 0);
101 if (r)
102 goto err;
103
104 return 0;
105
106err:
107 i2c_set_clientdata(client, NULL);
108 pdata->free_resources();
109 kfree(core);
110
111 dev_dbg(&client->dev, "%s\n", __func__);
112
113 return r;
114}
115
116static struct i2c_driver wl1273_core_driver = {
117 .driver = {
118 .name = WL1273_FM_DRIVER_NAME,
119 },
120 .probe = wl1273_core_probe,
121 .id_table = wl1273_driver_id_table,
122 .remove = __devexit_p(wl1273_core_remove),
123};
124
125static int __init wl1273_core_init(void)
126{
127 int r;
128
129 r = i2c_add_driver(&wl1273_core_driver);
130 if (r) {
131 pr_err(WL1273_FM_DRIVER_NAME
132 ": driver registration failed\n");
133 return r;
134 }
135
136 return r;
137}
138
139static void __exit wl1273_core_exit(void)
140{
141 i2c_del_driver(&wl1273_core_driver);
142}
143late_initcall(wl1273_core_init);
144module_exit(wl1273_core_exit);
145
146MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
147MODULE_DESCRIPTION(DRIVER_DESC);
148MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/wl1273-core.h b/include/linux/mfd/wl1273-core.h
new file mode 100644
index 000000000000..9787293eae5f
--- /dev/null
+++ b/include/linux/mfd/wl1273-core.h
@@ -0,0 +1,288 @@
1/*
2 * include/linux/mfd/wl1273-core.h
3 *
4 * Some definitions for the wl1273 radio receiver/transmitter chip.
5 *
6 * Copyright (C) 2010 Nokia Corporation
7 * Author: Matti J. Aaltonen <matti.j.aaltonen@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as 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#ifndef WL1273_CORE_H
25#define WL1273_CORE_H
26
27#include <linux/i2c.h>
28#include <linux/mfd/core.h>
29
30#define WL1273_FM_DRIVER_NAME "wl1273-fm"
31#define RX71_FM_I2C_ADDR 0x22
32
33#define WL1273_STEREO_GET 0
34#define WL1273_RSSI_LVL_GET 1
35#define WL1273_IF_COUNT_GET 2
36#define WL1273_FLAG_GET 3
37#define WL1273_RDS_SYNC_GET 4
38#define WL1273_RDS_DATA_GET 5
39#define WL1273_FREQ_SET 10
40#define WL1273_AF_FREQ_SET 11
41#define WL1273_MOST_MODE_SET 12
42#define WL1273_MOST_BLEND_SET 13
43#define WL1273_DEMPH_MODE_SET 14
44#define WL1273_SEARCH_LVL_SET 15
45#define WL1273_BAND_SET 16
46#define WL1273_MUTE_STATUS_SET 17
47#define WL1273_RDS_PAUSE_LVL_SET 18
48#define WL1273_RDS_PAUSE_DUR_SET 19
49#define WL1273_RDS_MEM_SET 20
50#define WL1273_RDS_BLK_B_SET 21
51#define WL1273_RDS_MSK_B_SET 22
52#define WL1273_RDS_PI_MASK_SET 23
53#define WL1273_RDS_PI_SET 24
54#define WL1273_RDS_SYSTEM_SET 25
55#define WL1273_INT_MASK_SET 26
56#define WL1273_SEARCH_DIR_SET 27
57#define WL1273_VOLUME_SET 28
58#define WL1273_AUDIO_ENABLE 29
59#define WL1273_PCM_MODE_SET 30
60#define WL1273_I2S_MODE_CONFIG_SET 31
61#define WL1273_POWER_SET 32
62#define WL1273_INTX_CONFIG_SET 33
63#define WL1273_PULL_EN_SET 34
64#define WL1273_HILO_SET 35
65#define WL1273_SWITCH2FREF 36
66#define WL1273_FREQ_DRIFT_REPORT 37
67
68#define WL1273_PCE_GET 40
69#define WL1273_FIRM_VER_GET 41
70#define WL1273_ASIC_VER_GET 42
71#define WL1273_ASIC_ID_GET 43
72#define WL1273_MAN_ID_GET 44
73#define WL1273_TUNER_MODE_SET 45
74#define WL1273_STOP_SEARCH 46
75#define WL1273_RDS_CNTRL_SET 47
76
77#define WL1273_WRITE_HARDWARE_REG 100
78#define WL1273_CODE_DOWNLOAD 101
79#define WL1273_RESET 102
80
81#define WL1273_FM_POWER_MODE 254
82#define WL1273_FM_INTERRUPT 255
83
84/* Transmitter API */
85
86#define WL1273_CHANL_SET 55
87#define WL1273_SCAN_SPACING_SET 56
88#define WL1273_REF_SET 57
89#define WL1273_POWER_ENB_SET 90
90#define WL1273_POWER_ATT_SET 58
91#define WL1273_POWER_LEV_SET 59
92#define WL1273_AUDIO_DEV_SET 60
93#define WL1273_PILOT_DEV_SET 61
94#define WL1273_RDS_DEV_SET 62
95#define WL1273_PUPD_SET 91
96#define WL1273_AUDIO_IO_SET 63
97#define WL1273_PREMPH_SET 64
98#define WL1273_MONO_SET 66
99#define WL1273_MUTE 92
100#define WL1273_MPX_LMT_ENABLE 67
101#define WL1273_PI_SET 93
102#define WL1273_ECC_SET 69
103#define WL1273_PTY 70
104#define WL1273_AF 71
105#define WL1273_DISPLAY_MODE 74
106#define WL1273_RDS_REP_SET 77
107#define WL1273_RDS_CONFIG_DATA_SET 98
108#define WL1273_RDS_DATA_SET 99
109#define WL1273_RDS_DATA_ENB 94
110#define WL1273_TA_SET 78
111#define WL1273_TP_SET 79
112#define WL1273_DI_SET 80
113#define WL1273_MS_SET 81
114#define WL1273_PS_SCROLL_SPEED 82
115#define WL1273_TX_AUDIO_LEVEL_TEST 96
116#define WL1273_TX_AUDIO_LEVEL_TEST_THRESHOLD 73
117#define WL1273_TX_AUDIO_INPUT_LEVEL_RANGE_SET 54
118#define WL1273_RX_ANTENNA_SELECT 87
119#define WL1273_I2C_DEV_ADDR_SET 86
120#define WL1273_REF_ERR_CALIB_PARAM_SET 88
121#define WL1273_REF_ERR_CALIB_PERIODICITY_SET 89
122#define WL1273_SOC_INT_TRIGGER 52
123#define WL1273_SOC_AUDIO_PATH_SET 83
124#define WL1273_SOC_PCMI_OVERRIDE 84
125#define WL1273_SOC_I2S_OVERRIDE 85
126#define WL1273_RSSI_BLOCK_SCAN_FREQ_SET 95
127#define WL1273_RSSI_BLOCK_SCAN_START 97
128#define WL1273_RSSI_BLOCK_SCAN_DATA_GET 5
129#define WL1273_READ_FMANT_TUNE_VALUE 104
130
131#define WL1273_RDS_OFF 0
132#define WL1273_RDS_ON 1
133#define WL1273_RDS_RESET 2
134
135#define WL1273_AUDIO_DIGITAL 0
136#define WL1273_AUDIO_ANALOG 1
137
138#define WL1273_MODE_RX BIT(0)
139#define WL1273_MODE_TX BIT(1)
140#define WL1273_MODE_OFF BIT(2)
141#define WL1273_MODE_SUSPENDED BIT(3)
142
143#define WL1273_RADIO_CHILD BIT(0)
144#define WL1273_CODEC_CHILD BIT(1)
145
146#define WL1273_RX_MONO 1
147#define WL1273_RX_STEREO 0
148#define WL1273_TX_MONO 0
149#define WL1273_TX_STEREO 1
150
151#define WL1273_MAX_VOLUME 0xffff
152#define WL1273_DEFAULT_VOLUME 0x78b8
153
154/* I2S protocol, left channel first, data width 16 bits */
155#define WL1273_PCM_DEF_MODE 0x00
156
157/* Rx */
158#define WL1273_AUDIO_ENABLE_I2S BIT(0)
159#define WL1273_AUDIO_ENABLE_ANALOG BIT(1)
160
161/* Tx */
162#define WL1273_AUDIO_IO_SET_ANALOG 0
163#define WL1273_AUDIO_IO_SET_I2S 1
164
165#define WL1273_PUPD_SET_OFF 0x00
166#define WL1273_PUPD_SET_ON 0x01
167#define WL1273_PUPD_SET_RETENTION 0x10
168
169/* I2S mode */
170#define WL1273_IS2_WIDTH_32 0x0
171#define WL1273_IS2_WIDTH_40 0x1
172#define WL1273_IS2_WIDTH_22_23 0x2
173#define WL1273_IS2_WIDTH_23_22 0x3
174#define WL1273_IS2_WIDTH_48 0x4
175#define WL1273_IS2_WIDTH_50 0x5
176#define WL1273_IS2_WIDTH_60 0x6
177#define WL1273_IS2_WIDTH_64 0x7
178#define WL1273_IS2_WIDTH_80 0x8
179#define WL1273_IS2_WIDTH_96 0x9
180#define WL1273_IS2_WIDTH_128 0xa
181#define WL1273_IS2_WIDTH 0xf
182
183#define WL1273_IS2_FORMAT_STD (0x0 << 4)
184#define WL1273_IS2_FORMAT_LEFT (0x1 << 4)
185#define WL1273_IS2_FORMAT_RIGHT (0x2 << 4)
186#define WL1273_IS2_FORMAT_USER (0x3 << 4)
187
188#define WL1273_IS2_MASTER (0x0 << 6)
189#define WL1273_IS2_SLAVEW (0x1 << 6)
190
191#define WL1273_IS2_TRI_AFTER_SENDING (0x0 << 7)
192#define WL1273_IS2_TRI_ALWAYS_ACTIVE (0x1 << 7)
193
194#define WL1273_IS2_SDOWS_RR (0x0 << 8)
195#define WL1273_IS2_SDOWS_RF (0x1 << 8)
196#define WL1273_IS2_SDOWS_FR (0x2 << 8)
197#define WL1273_IS2_SDOWS_FF (0x3 << 8)
198
199#define WL1273_IS2_TRI_OPT (0x0 << 10)
200#define WL1273_IS2_TRI_ALWAYS (0x1 << 10)
201
202#define WL1273_IS2_RATE_48K (0x0 << 12)
203#define WL1273_IS2_RATE_44_1K (0x1 << 12)
204#define WL1273_IS2_RATE_32K (0x2 << 12)
205#define WL1273_IS2_RATE_22_05K (0x4 << 12)
206#define WL1273_IS2_RATE_16K (0x5 << 12)
207#define WL1273_IS2_RATE_12K (0x8 << 12)
208#define WL1273_IS2_RATE_11_025 (0x9 << 12)
209#define WL1273_IS2_RATE_8K (0xa << 12)
210#define WL1273_IS2_RATE (0xf << 12)
211
212#define WL1273_I2S_DEF_MODE (WL1273_IS2_WIDTH_32 | \
213 WL1273_IS2_FORMAT_STD | \
214 WL1273_IS2_MASTER | \
215 WL1273_IS2_TRI_AFTER_SENDING | \
216 WL1273_IS2_SDOWS_RR | \
217 WL1273_IS2_TRI_OPT | \
218 WL1273_IS2_RATE_48K)
219
220#define SCHAR_MIN (-128)
221#define SCHAR_MAX 127
222
223#define WL1273_FR_EVENT BIT(0)
224#define WL1273_BL_EVENT BIT(1)
225#define WL1273_RDS_EVENT BIT(2)
226#define WL1273_BBLK_EVENT BIT(3)
227#define WL1273_LSYNC_EVENT BIT(4)
228#define WL1273_LEV_EVENT BIT(5)
229#define WL1273_IFFR_EVENT BIT(6)
230#define WL1273_PI_EVENT BIT(7)
231#define WL1273_PD_EVENT BIT(8)
232#define WL1273_STIC_EVENT BIT(9)
233#define WL1273_MAL_EVENT BIT(10)
234#define WL1273_POW_ENB_EVENT BIT(11)
235#define WL1273_SCAN_OVER_EVENT BIT(12)
236#define WL1273_ERROR_EVENT BIT(13)
237
238#define TUNER_MODE_STOP_SEARCH 0
239#define TUNER_MODE_PRESET 1
240#define TUNER_MODE_AUTO_SEEK 2
241#define TUNER_MODE_AF 3
242#define TUNER_MODE_AUTO_SEEK_PI 4
243#define TUNER_MODE_AUTO_SEEK_BULK 5
244
245#define RDS_BLOCK_SIZE 3
246
247struct wl1273_fm_platform_data {
248 int (*request_resources) (struct i2c_client *client);
249 void (*free_resources) (void);
250 void (*enable) (void);
251 void (*disable) (void);
252
253 u8 forbidden_modes;
254 unsigned int children;
255};
256
257#define WL1273_FM_CORE_CELLS 2
258
259#define WL1273_BAND_OTHER 0
260#define WL1273_BAND_JAPAN 1
261
262#define WL1273_BAND_JAPAN_LOW 76000
263#define WL1273_BAND_JAPAN_HIGH 90000
264#define WL1273_BAND_OTHER_LOW 87500
265#define WL1273_BAND_OTHER_HIGH 108000
266
267#define WL1273_BAND_TX_LOW 76000
268#define WL1273_BAND_TX_HIGH 108000
269
270struct wl1273_core {
271 struct mfd_cell cells[WL1273_FM_CORE_CELLS];
272 struct wl1273_fm_platform_data *pdata;
273
274 unsigned int mode;
275 unsigned int i2s_mode;
276 unsigned int volume;
277 unsigned int audio_mode;
278 unsigned int channel_number;
279 struct mutex lock; /* for serializing fm radio operations */
280
281 struct i2c_client *client;
282
283 int (*write)(struct wl1273_core *core, u8, u16);
284 int (*set_audio)(struct wl1273_core *core, unsigned int);
285 int (*set_volume)(struct wl1273_core *core, unsigned int);
286};
287
288#endif /* ifndef WL1273_CORE_H */