blob: f867f04cccc99626bb7fc5dee97d34f2adaed9fa [file] [log] [blame]
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -03001/*
2 * drivers/media/radio/si470x/radio-si470x-i2c.c
3 *
4 * I2C driver for radios with Silicon Labs Si470x FM Radio Receivers
5 *
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -03006 * Copyright (c) 2009 Samsung Electronics Co.Ltd
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -03007 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
8 *
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -03009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030013 *
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030014 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030018 *
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030019 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030022 */
23
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030024
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030025/* driver definitions */
26#define DRIVER_AUTHOR "Joonyoung Shim <jy0922.shim@samsung.com>";
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030027#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
28#define DRIVER_DESC "I2C radio driver for Si470x FM Radio Receivers"
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -030029#define DRIVER_VERSION "1.0.2"
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030030
31/* kernel includes */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030032#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030034#include <linux/delay.h>
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030035#include <linux/interrupt.h>
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030036
37#include "radio-si470x.h"
38
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030039
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030040/* I2C Device ID List */
41static const struct i2c_device_id si470x_i2c_id[] = {
42 /* Generic Entry */
43 { "si470x", 0 },
44 /* Terminating entry */
45 { }
46};
47MODULE_DEVICE_TABLE(i2c, si470x_i2c_id);
48
49
50
51/**************************************************************************
52 * Module Parameters
53 **************************************************************************/
54
55/* Radio Nr */
56static int radio_nr = -1;
57module_param(radio_nr, int, 0444);
58MODULE_PARM_DESC(radio_nr, "Radio Nr");
59
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030060/* RDS buffer blocks */
61static unsigned int rds_buf = 100;
62module_param(rds_buf, uint, 0444);
63MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
64
65/* RDS maximum block errors */
66static unsigned short max_rds_errors = 1;
67/* 0 means 0 errors requiring correction */
68/* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
69/* 2 means 3-5 errors requiring correction */
70/* 3 means 6+ errors or errors in checkword, correction not possible */
71module_param(max_rds_errors, ushort, 0644);
72MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
73
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030074
75
76/**************************************************************************
77 * I2C Definitions
78 **************************************************************************/
79
80/* Write starts with the upper byte of register 0x02 */
81#define WRITE_REG_NUM 8
82#define WRITE_INDEX(i) (i + 0x02)
83
84/* Read starts with the upper byte of register 0x0a */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030085#define READ_REG_NUM RADIO_REGISTER_NUM
86#define READ_INDEX(i) ((i + RADIO_REGISTER_NUM - 0x0a) % READ_REG_NUM)
87
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030088
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030089
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030090/**************************************************************************
91 * General Driver Functions - REGISTERs
92 **************************************************************************/
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030093
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030094/*
95 * si470x_get_register - read register
96 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030097int si470x_get_register(struct si470x_device *radio, int regnr)
98{
99 u16 buf[READ_REG_NUM];
100 struct i2c_msg msgs[1] = {
101 { radio->client->addr, I2C_M_RD, sizeof(u16) * READ_REG_NUM,
102 (void *)buf },
103 };
104
105 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
106 return -EIO;
107
108 radio->registers[regnr] = __be16_to_cpu(buf[READ_INDEX(regnr)]);
109
110 return 0;
111}
112
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300113
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300114/*
115 * si470x_set_register - write register
116 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300117int si470x_set_register(struct si470x_device *radio, int regnr)
118{
119 int i;
120 u16 buf[WRITE_REG_NUM];
121 struct i2c_msg msgs[1] = {
122 { radio->client->addr, 0, sizeof(u16) * WRITE_REG_NUM,
123 (void *)buf },
124 };
125
126 for (i = 0; i < WRITE_REG_NUM; i++)
127 buf[i] = __cpu_to_be16(radio->registers[WRITE_INDEX(i)]);
128
129 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
130 return -EIO;
131
132 return 0;
133}
134
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300135
136
137/**************************************************************************
138 * General Driver Functions - ENTIRE REGISTERS
139 **************************************************************************/
140
141/*
142 * si470x_get_all_registers - read entire registers
143 */
144static int si470x_get_all_registers(struct si470x_device *radio)
145{
146 int i;
147 u16 buf[READ_REG_NUM];
148 struct i2c_msg msgs[1] = {
149 { radio->client->addr, I2C_M_RD, sizeof(u16) * READ_REG_NUM,
150 (void *)buf },
151 };
152
153 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
154 return -EIO;
155
156 for (i = 0; i < READ_REG_NUM; i++)
157 radio->registers[i] = __be16_to_cpu(buf[READ_INDEX(i)]);
158
159 return 0;
160}
161
162
163
164/**************************************************************************
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300165 * File Operations Interface
166 **************************************************************************/
167
168/*
169 * si470x_fops_open - file open
170 */
Joonyoung Shim1aa925c2009-12-10 16:49:34 -0300171int si470x_fops_open(struct file *file)
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300172{
173 struct si470x_device *radio = video_drvdata(file);
Hans Verkuil4967d532012-05-04 09:16:57 -0300174 int retval = v4l2_fh_open(file);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300175
Hans Verkuil4967d532012-05-04 09:16:57 -0300176 if (retval)
177 return retval;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300178
Hans Verkuil4967d532012-05-04 09:16:57 -0300179 if (v4l2_fh_is_singular_file(file)) {
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300180 /* start radio */
181 retval = si470x_start(radio);
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300182 if (retval < 0)
183 goto done;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300184
Joonyoung Shim0830be32011-03-11 03:54:46 -0300185 /* enable RDS / STC interrupt */
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300186 radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDSIEN;
Joonyoung Shim0830be32011-03-11 03:54:46 -0300187 radio->registers[SYSCONFIG1] |= SYSCONFIG1_STCIEN;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300188 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_GPIO2;
189 radio->registers[SYSCONFIG1] |= 0x1 << 2;
190 retval = si470x_set_register(radio, SYSCONFIG1);
191 }
192
193done:
Hans Verkuil4967d532012-05-04 09:16:57 -0300194 if (retval)
195 v4l2_fh_release(file);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300196 return retval;
197}
198
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300199
200/*
201 * si470x_fops_release - file release
202 */
Joonyoung Shim1aa925c2009-12-10 16:49:34 -0300203int si470x_fops_release(struct file *file)
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300204{
205 struct si470x_device *radio = video_drvdata(file);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300206
Hans Verkuil4967d532012-05-04 09:16:57 -0300207 if (v4l2_fh_is_singular_file(file))
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300208 /* stop radio */
Hans Verkuil4967d532012-05-04 09:16:57 -0300209 si470x_stop(radio);
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300210
Hans Verkuil4967d532012-05-04 09:16:57 -0300211 return v4l2_fh_release(file);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300212}
213
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300214
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300215
216/**************************************************************************
217 * Video4Linux Interface
218 **************************************************************************/
219
220/*
221 * si470x_vidioc_querycap - query device capabilities
222 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300223int si470x_vidioc_querycap(struct file *file, void *priv,
224 struct v4l2_capability *capability)
225{
226 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
227 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
Hans Verkuil32737812012-08-03 11:16:59 -0300228 capability->device_caps = V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_READWRITE |
229 V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_RDS_CAPTURE;
230 capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300231
232 return 0;
233}
234
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300235
236
237/**************************************************************************
238 * I2C Interface
239 **************************************************************************/
240
241/*
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300242 * si470x_i2c_interrupt - interrupt handler
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300243 */
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300244static irqreturn_t si470x_i2c_interrupt(int irq, void *dev_id)
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300245{
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300246 struct si470x_device *radio = dev_id;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300247 unsigned char regnr;
248 unsigned char blocknum;
249 unsigned short bler; /* rds block errors */
250 unsigned short rds;
251 unsigned char tmpbuf[3];
252 int retval = 0;
253
Joonyoung Shim0830be32011-03-11 03:54:46 -0300254 /* check Seek/Tune Complete */
255 retval = si470x_get_register(radio, STATUSRSSI);
256 if (retval < 0)
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300257 goto end;
Joonyoung Shim0830be32011-03-11 03:54:46 -0300258
259 if (radio->registers[STATUSRSSI] & STATUSRSSI_STC)
260 complete(&radio->completion);
261
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300262 /* safety checks */
263 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300264 goto end;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300265
266 /* Update RDS registers */
Joonyoung Shim0830be32011-03-11 03:54:46 -0300267 for (regnr = 1; regnr < RDS_REGISTER_NUM; regnr++) {
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300268 retval = si470x_get_register(radio, STATUSRSSI + regnr);
269 if (retval < 0)
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300270 goto end;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300271 }
272
273 /* get rds blocks */
274 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0)
275 /* No RDS group ready, better luck next time */
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300276 goto end;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300277
278 for (blocknum = 0; blocknum < 4; blocknum++) {
279 switch (blocknum) {
280 default:
281 bler = (radio->registers[STATUSRSSI] &
282 STATUSRSSI_BLERA) >> 9;
283 rds = radio->registers[RDSA];
284 break;
285 case 1:
286 bler = (radio->registers[READCHAN] &
287 READCHAN_BLERB) >> 14;
288 rds = radio->registers[RDSB];
289 break;
290 case 2:
291 bler = (radio->registers[READCHAN] &
292 READCHAN_BLERC) >> 12;
293 rds = radio->registers[RDSC];
294 break;
295 case 3:
296 bler = (radio->registers[READCHAN] &
297 READCHAN_BLERD) >> 10;
298 rds = radio->registers[RDSD];
299 break;
300 };
301
302 /* Fill the V4L2 RDS buffer */
303 put_unaligned_le16(rds, &tmpbuf);
304 tmpbuf[2] = blocknum; /* offset name */
305 tmpbuf[2] |= blocknum << 3; /* received offset */
306 if (bler > max_rds_errors)
307 tmpbuf[2] |= 0x80; /* uncorrectable errors */
308 else if (bler > 0)
309 tmpbuf[2] |= 0x40; /* corrected error(s) */
310
311 /* copy RDS block to internal buffer */
312 memcpy(&radio->buffer[radio->wr_index], &tmpbuf, 3);
313 radio->wr_index += 3;
314
315 /* wrap write pointer */
316 if (radio->wr_index >= radio->buf_size)
317 radio->wr_index = 0;
318
319 /* check for overflow */
320 if (radio->wr_index == radio->rd_index) {
321 /* increment and wrap read pointer */
322 radio->rd_index += 3;
323 if (radio->rd_index >= radio->buf_size)
324 radio->rd_index = 0;
325 }
326 }
327
328 if (radio->wr_index != radio->rd_index)
329 wake_up_interruptible(&radio->read_queue);
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300330
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300331end:
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300332 return IRQ_HANDLED;
333}
334
335
336/*
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300337 * si470x_i2c_probe - probe for the device
338 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300339static int __devinit si470x_i2c_probe(struct i2c_client *client,
340 const struct i2c_device_id *id)
341{
342 struct si470x_device *radio;
343 int retval = 0;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300344 unsigned char version_warning = 0;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300345
346 /* private data allocation and initialization */
347 radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL);
348 if (!radio) {
349 retval = -ENOMEM;
350 goto err_initial;
351 }
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300352
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300353 radio->client = client;
Hans de Goedef1406122012-07-12 16:55:48 -0300354 radio->band = 1; /* Default to 76 - 108 MHz */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300355 mutex_init(&radio->lock);
Hans de Goede77947112012-06-14 09:43:12 -0300356 init_completion(&radio->completion);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300357
Hans Verkuil4967d532012-05-04 09:16:57 -0300358 /* video device initialization */
359 radio->videodev = si470x_viddev_template;
360 video_set_drvdata(&radio->videodev, radio);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300361
362 /* power up : need 110ms */
363 radio->registers[POWERCFG] = POWERCFG_ENABLE;
364 if (si470x_set_register(radio, POWERCFG) < 0) {
365 retval = -EIO;
Hans Verkuil4967d532012-05-04 09:16:57 -0300366 goto err_radio;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300367 }
368 msleep(110);
369
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300370 /* get device and chip versions */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300371 if (si470x_get_all_registers(radio) < 0) {
372 retval = -EIO;
Hans Verkuil4967d532012-05-04 09:16:57 -0300373 goto err_radio;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300374 }
375 dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
376 radio->registers[DEVICEID], radio->registers[CHIPID]);
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300377 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE) < RADIO_FW_VERSION) {
378 dev_warn(&client->dev,
379 "This driver is known to work with "
380 "firmware version %hu,\n", RADIO_FW_VERSION);
381 dev_warn(&client->dev,
382 "but the device has firmware version %hu.\n",
383 radio->registers[CHIPID] & CHIPID_FIRMWARE);
384 version_warning = 1;
385 }
386
387 /* give out version warning */
388 if (version_warning == 1) {
389 dev_warn(&client->dev,
390 "If you have some trouble using this driver,\n");
391 dev_warn(&client->dev,
392 "please report to V4L ML at "
393 "linux-media@vger.kernel.org\n");
394 }
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300395
396 /* set initial frequency */
397 si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
398
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300399 /* rds buffer allocation */
400 radio->buf_size = rds_buf * 3;
401 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
402 if (!radio->buffer) {
403 retval = -EIO;
Hans Verkuil4967d532012-05-04 09:16:57 -0300404 goto err_radio;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300405 }
406
407 /* rds buffer configuration */
408 radio->wr_index = 0;
409 radio->rd_index = 0;
410 init_waitqueue_head(&radio->read_queue);
411
Joonyoung Shim474fdc02011-03-11 03:54:48 -0300412 retval = request_threaded_irq(client->irq, NULL, si470x_i2c_interrupt,
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300413 IRQF_TRIGGER_FALLING, DRIVER_NAME, radio);
414 if (retval) {
415 dev_err(&client->dev, "Failed to register interrupt\n");
416 goto err_rds;
417 }
418
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300419 /* register video device */
Hans Verkuil4967d532012-05-04 09:16:57 -0300420 retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO,
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300421 radio_nr);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300422 if (retval) {
423 dev_warn(&client->dev, "Could not register video device\n");
424 goto err_all;
425 }
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300426 i2c_set_clientdata(client, radio);
427
428 return 0;
429err_all:
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300430 free_irq(client->irq, radio);
431err_rds:
432 kfree(radio->buffer);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300433err_radio:
434 kfree(radio);
435err_initial:
436 return retval;
437}
438
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300439
440/*
441 * si470x_i2c_remove - remove the device
442 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300443static __devexit int si470x_i2c_remove(struct i2c_client *client)
444{
445 struct si470x_device *radio = i2c_get_clientdata(client);
446
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300447 free_irq(client->irq, radio);
Hans Verkuil4967d532012-05-04 09:16:57 -0300448 video_unregister_device(&radio->videodev);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300449 kfree(radio);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300450
451 return 0;
452}
453
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300454
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300455#ifdef CONFIG_PM
456/*
457 * si470x_i2c_suspend - suspend the device
458 */
Joonyoung Shim949cf312011-03-11 03:54:47 -0300459static int si470x_i2c_suspend(struct device *dev)
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300460{
Joonyoung Shim949cf312011-03-11 03:54:47 -0300461 struct i2c_client *client = to_i2c_client(dev);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300462 struct si470x_device *radio = i2c_get_clientdata(client);
463
464 /* power down */
465 radio->registers[POWERCFG] |= POWERCFG_DISABLE;
466 if (si470x_set_register(radio, POWERCFG) < 0)
467 return -EIO;
468
469 return 0;
470}
471
472
473/*
474 * si470x_i2c_resume - resume the device
475 */
Joonyoung Shim949cf312011-03-11 03:54:47 -0300476static int si470x_i2c_resume(struct device *dev)
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300477{
Joonyoung Shim949cf312011-03-11 03:54:47 -0300478 struct i2c_client *client = to_i2c_client(dev);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300479 struct si470x_device *radio = i2c_get_clientdata(client);
480
481 /* power up : need 110ms */
482 radio->registers[POWERCFG] |= POWERCFG_ENABLE;
483 if (si470x_set_register(radio, POWERCFG) < 0)
484 return -EIO;
485 msleep(110);
486
487 return 0;
488}
Joonyoung Shim949cf312011-03-11 03:54:47 -0300489
490static SIMPLE_DEV_PM_OPS(si470x_i2c_pm, si470x_i2c_suspend, si470x_i2c_resume);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300491#endif
492
493
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300494/*
495 * si470x_i2c_driver - i2c driver interface
496 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300497static struct i2c_driver si470x_i2c_driver = {
498 .driver = {
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300499 .name = "si470x",
500 .owner = THIS_MODULE,
Joonyoung Shim949cf312011-03-11 03:54:47 -0300501#ifdef CONFIG_PM
502 .pm = &si470x_i2c_pm,
503#endif
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300504 },
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300505 .probe = si470x_i2c_probe,
506 .remove = __devexit_p(si470x_i2c_remove),
507 .id_table = si470x_i2c_id,
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300508};
509
Axel Linc6e8d862012-02-12 06:56:32 -0300510module_i2c_driver(si470x_i2c_driver);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300511
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300512MODULE_LICENSE("GPL");
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300513MODULE_AUTHOR(DRIVER_AUTHOR);
514MODULE_DESCRIPTION(DRIVER_DESC);
515MODULE_VERSION(DRIVER_VERSION);