blob: 898f68a83611e0fe0244c44f47b8d504903c1ff9 [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>";
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030027#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 1)
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030028#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
29#define DRIVER_DESC "I2C radio driver for Si470x FM Radio Receivers"
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030030#define DRIVER_VERSION "1.0.1"
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030031
32/* kernel includes */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030033#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030035#include <linux/delay.h>
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030036#include <linux/interrupt.h>
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030037
38#include "radio-si470x.h"
39
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030040
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030041/* I2C Device ID List */
42static const struct i2c_device_id si470x_i2c_id[] = {
43 /* Generic Entry */
44 { "si470x", 0 },
45 /* Terminating entry */
46 { }
47};
48MODULE_DEVICE_TABLE(i2c, si470x_i2c_id);
49
50
51
52/**************************************************************************
53 * Module Parameters
54 **************************************************************************/
55
56/* Radio Nr */
57static int radio_nr = -1;
58module_param(radio_nr, int, 0444);
59MODULE_PARM_DESC(radio_nr, "Radio Nr");
60
Joonyoung Shimfe2137d2009-12-10 16:50:34 -030061/* RDS buffer blocks */
62static unsigned int rds_buf = 100;
63module_param(rds_buf, uint, 0444);
64MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
65
66/* RDS maximum block errors */
67static unsigned short max_rds_errors = 1;
68/* 0 means 0 errors requiring correction */
69/* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
70/* 2 means 3-5 errors requiring correction */
71/* 3 means 6+ errors or errors in checkword, correction not possible */
72module_param(max_rds_errors, ushort, 0644);
73MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
74
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030075
76
77/**************************************************************************
78 * I2C Definitions
79 **************************************************************************/
80
81/* Write starts with the upper byte of register 0x02 */
82#define WRITE_REG_NUM 8
83#define WRITE_INDEX(i) (i + 0x02)
84
85/* Read starts with the upper byte of register 0x0a */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030086#define READ_REG_NUM RADIO_REGISTER_NUM
87#define READ_INDEX(i) ((i + RADIO_REGISTER_NUM - 0x0a) % READ_REG_NUM)
88
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030089
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030090
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030091/**************************************************************************
92 * General Driver Functions - REGISTERs
93 **************************************************************************/
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030094
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -030095/*
96 * si470x_get_register - read register
97 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -030098int si470x_get_register(struct si470x_device *radio, int regnr)
99{
100 u16 buf[READ_REG_NUM];
101 struct i2c_msg msgs[1] = {
102 { radio->client->addr, I2C_M_RD, sizeof(u16) * READ_REG_NUM,
103 (void *)buf },
104 };
105
106 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
107 return -EIO;
108
109 radio->registers[regnr] = __be16_to_cpu(buf[READ_INDEX(regnr)]);
110
111 return 0;
112}
113
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300114
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300115/*
116 * si470x_set_register - write register
117 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300118int si470x_set_register(struct si470x_device *radio, int regnr)
119{
120 int i;
121 u16 buf[WRITE_REG_NUM];
122 struct i2c_msg msgs[1] = {
123 { radio->client->addr, 0, sizeof(u16) * WRITE_REG_NUM,
124 (void *)buf },
125 };
126
127 for (i = 0; i < WRITE_REG_NUM; i++)
128 buf[i] = __cpu_to_be16(radio->registers[WRITE_INDEX(i)]);
129
130 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
131 return -EIO;
132
133 return 0;
134}
135
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300136
137
138/**************************************************************************
139 * General Driver Functions - ENTIRE REGISTERS
140 **************************************************************************/
141
142/*
143 * si470x_get_all_registers - read entire registers
144 */
145static int si470x_get_all_registers(struct si470x_device *radio)
146{
147 int i;
148 u16 buf[READ_REG_NUM];
149 struct i2c_msg msgs[1] = {
150 { radio->client->addr, I2C_M_RD, sizeof(u16) * READ_REG_NUM,
151 (void *)buf },
152 };
153
154 if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
155 return -EIO;
156
157 for (i = 0; i < READ_REG_NUM; i++)
158 radio->registers[i] = __be16_to_cpu(buf[READ_INDEX(i)]);
159
160 return 0;
161}
162
163
164
165/**************************************************************************
166 * General Driver Functions - DISCONNECT_CHECK
167 **************************************************************************/
168
169/*
170 * si470x_disconnect_check - check whether radio disconnects
171 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300172int si470x_disconnect_check(struct si470x_device *radio)
173{
174 return 0;
175}
176
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300177
178
179/**************************************************************************
180 * File Operations Interface
181 **************************************************************************/
182
183/*
184 * si470x_fops_open - file open
185 */
Joonyoung Shim1aa925c2009-12-10 16:49:34 -0300186int si470x_fops_open(struct file *file)
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300187{
188 struct si470x_device *radio = video_drvdata(file);
189 int retval = 0;
190
191 mutex_lock(&radio->lock);
192 radio->users++;
193
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300194 if (radio->users == 1) {
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300195 /* start radio */
196 retval = si470x_start(radio);
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300197 if (retval < 0)
198 goto done;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300199
Joonyoung Shim0830be32011-03-11 03:54:46 -0300200 /* enable RDS / STC interrupt */
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300201 radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDSIEN;
Joonyoung Shim0830be32011-03-11 03:54:46 -0300202 radio->registers[SYSCONFIG1] |= SYSCONFIG1_STCIEN;
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300203 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_GPIO2;
204 radio->registers[SYSCONFIG1] |= 0x1 << 2;
205 retval = si470x_set_register(radio, SYSCONFIG1);
206 }
207
208done:
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300209 mutex_unlock(&radio->lock);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300210 return retval;
211}
212
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300213
214/*
215 * si470x_fops_release - file release
216 */
Joonyoung Shim1aa925c2009-12-10 16:49:34 -0300217int si470x_fops_release(struct file *file)
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300218{
219 struct si470x_device *radio = video_drvdata(file);
220 int retval = 0;
221
222 /* safety check */
223 if (!radio)
224 return -ENODEV;
225
226 mutex_lock(&radio->lock);
227 radio->users--;
228 if (radio->users == 0)
229 /* stop radio */
230 retval = si470x_stop(radio);
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300231
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300232 mutex_unlock(&radio->lock);
233
234 return retval;
235}
236
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300237
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300238
239/**************************************************************************
240 * Video4Linux Interface
241 **************************************************************************/
242
243/*
244 * si470x_vidioc_querycap - query device capabilities
245 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300246int si470x_vidioc_querycap(struct file *file, void *priv,
247 struct v4l2_capability *capability)
248{
249 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
250 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
251 capability->version = DRIVER_KERNEL_VERSION;
252 capability->capabilities = V4L2_CAP_HW_FREQ_SEEK |
253 V4L2_CAP_TUNER | V4L2_CAP_RADIO;
254
255 return 0;
256}
257
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300258
259
260/**************************************************************************
261 * I2C Interface
262 **************************************************************************/
263
264/*
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300265 * si470x_i2c_interrupt_work - rds processing function
266 */
267static void si470x_i2c_interrupt_work(struct work_struct *work)
268{
269 struct si470x_device *radio = container_of(work,
270 struct si470x_device, radio_work);
271 unsigned char regnr;
272 unsigned char blocknum;
273 unsigned short bler; /* rds block errors */
274 unsigned short rds;
275 unsigned char tmpbuf[3];
276 int retval = 0;
277
Joonyoung Shim0830be32011-03-11 03:54:46 -0300278 /* check Seek/Tune Complete */
279 retval = si470x_get_register(radio, STATUSRSSI);
280 if (retval < 0)
281 return;
282
283 if (radio->registers[STATUSRSSI] & STATUSRSSI_STC)
284 complete(&radio->completion);
285
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300286 /* safety checks */
287 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
288 return;
289
290 /* Update RDS registers */
Joonyoung Shim0830be32011-03-11 03:54:46 -0300291 for (regnr = 1; regnr < RDS_REGISTER_NUM; regnr++) {
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300292 retval = si470x_get_register(radio, STATUSRSSI + regnr);
293 if (retval < 0)
294 return;
295 }
296
297 /* get rds blocks */
298 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0)
299 /* No RDS group ready, better luck next time */
300 return;
301
302 for (blocknum = 0; blocknum < 4; blocknum++) {
303 switch (blocknum) {
304 default:
305 bler = (radio->registers[STATUSRSSI] &
306 STATUSRSSI_BLERA) >> 9;
307 rds = radio->registers[RDSA];
308 break;
309 case 1:
310 bler = (radio->registers[READCHAN] &
311 READCHAN_BLERB) >> 14;
312 rds = radio->registers[RDSB];
313 break;
314 case 2:
315 bler = (radio->registers[READCHAN] &
316 READCHAN_BLERC) >> 12;
317 rds = radio->registers[RDSC];
318 break;
319 case 3:
320 bler = (radio->registers[READCHAN] &
321 READCHAN_BLERD) >> 10;
322 rds = radio->registers[RDSD];
323 break;
324 };
325
326 /* Fill the V4L2 RDS buffer */
327 put_unaligned_le16(rds, &tmpbuf);
328 tmpbuf[2] = blocknum; /* offset name */
329 tmpbuf[2] |= blocknum << 3; /* received offset */
330 if (bler > max_rds_errors)
331 tmpbuf[2] |= 0x80; /* uncorrectable errors */
332 else if (bler > 0)
333 tmpbuf[2] |= 0x40; /* corrected error(s) */
334
335 /* copy RDS block to internal buffer */
336 memcpy(&radio->buffer[radio->wr_index], &tmpbuf, 3);
337 radio->wr_index += 3;
338
339 /* wrap write pointer */
340 if (radio->wr_index >= radio->buf_size)
341 radio->wr_index = 0;
342
343 /* check for overflow */
344 if (radio->wr_index == radio->rd_index) {
345 /* increment and wrap read pointer */
346 radio->rd_index += 3;
347 if (radio->rd_index >= radio->buf_size)
348 radio->rd_index = 0;
349 }
350 }
351
352 if (radio->wr_index != radio->rd_index)
353 wake_up_interruptible(&radio->read_queue);
354}
355
356
357/*
358 * si470x_i2c_interrupt - interrupt handler
359 */
360static irqreturn_t si470x_i2c_interrupt(int irq, void *dev_id)
361{
362 struct si470x_device *radio = dev_id;
363
364 if (!work_pending(&radio->radio_work))
365 schedule_work(&radio->radio_work);
366
367 return IRQ_HANDLED;
368}
369
370
371/*
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300372 * si470x_i2c_probe - probe for the device
373 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300374static int __devinit si470x_i2c_probe(struct i2c_client *client,
375 const struct i2c_device_id *id)
376{
377 struct si470x_device *radio;
378 int retval = 0;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300379 unsigned char version_warning = 0;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300380
381 /* private data allocation and initialization */
382 radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL);
383 if (!radio) {
384 retval = -ENOMEM;
385 goto err_initial;
386 }
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300387
388 INIT_WORK(&radio->radio_work, si470x_i2c_interrupt_work);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300389 radio->users = 0;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300390 radio->client = client;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300391 mutex_init(&radio->lock);
392
393 /* video device allocation and initialization */
394 radio->videodev = video_device_alloc();
395 if (!radio->videodev) {
396 retval = -ENOMEM;
397 goto err_radio;
398 }
399 memcpy(radio->videodev, &si470x_viddev_template,
400 sizeof(si470x_viddev_template));
401 video_set_drvdata(radio->videodev, radio);
402
403 /* power up : need 110ms */
404 radio->registers[POWERCFG] = POWERCFG_ENABLE;
405 if (si470x_set_register(radio, POWERCFG) < 0) {
406 retval = -EIO;
Marek Szyprowskicc6e8532010-09-05 02:42:33 -0300407 goto err_video;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300408 }
409 msleep(110);
410
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300411 /* get device and chip versions */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300412 if (si470x_get_all_registers(radio) < 0) {
413 retval = -EIO;
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300414 goto err_video;
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300415 }
416 dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
417 radio->registers[DEVICEID], radio->registers[CHIPID]);
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300418 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE) < RADIO_FW_VERSION) {
419 dev_warn(&client->dev,
420 "This driver is known to work with "
421 "firmware version %hu,\n", RADIO_FW_VERSION);
422 dev_warn(&client->dev,
423 "but the device has firmware version %hu.\n",
424 radio->registers[CHIPID] & CHIPID_FIRMWARE);
425 version_warning = 1;
426 }
427
428 /* give out version warning */
429 if (version_warning == 1) {
430 dev_warn(&client->dev,
431 "If you have some trouble using this driver,\n");
432 dev_warn(&client->dev,
433 "please report to V4L ML at "
434 "linux-media@vger.kernel.org\n");
435 }
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300436
437 /* set initial frequency */
438 si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
439
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300440 /* rds buffer allocation */
441 radio->buf_size = rds_buf * 3;
442 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
443 if (!radio->buffer) {
444 retval = -EIO;
445 goto err_video;
446 }
447
448 /* rds buffer configuration */
449 radio->wr_index = 0;
450 radio->rd_index = 0;
451 init_waitqueue_head(&radio->read_queue);
452
Joonyoung Shim0830be32011-03-11 03:54:46 -0300453 /* mark Seek/Tune Complete Interrupt enabled */
454 radio->stci_enabled = true;
455 init_completion(&radio->completion);
456
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300457 retval = request_irq(client->irq, si470x_i2c_interrupt,
458 IRQF_TRIGGER_FALLING, DRIVER_NAME, radio);
459 if (retval) {
460 dev_err(&client->dev, "Failed to register interrupt\n");
461 goto err_rds;
462 }
463
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300464 /* register video device */
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300465 retval = video_register_device(radio->videodev, VFL_TYPE_RADIO,
466 radio_nr);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300467 if (retval) {
468 dev_warn(&client->dev, "Could not register video device\n");
469 goto err_all;
470 }
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300471 i2c_set_clientdata(client, radio);
472
473 return 0;
474err_all:
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300475 free_irq(client->irq, radio);
476err_rds:
477 kfree(radio->buffer);
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300478err_video:
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300479 video_device_release(radio->videodev);
480err_radio:
481 kfree(radio);
482err_initial:
483 return retval;
484}
485
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300486
487/*
488 * si470x_i2c_remove - remove the device
489 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300490static __devexit int si470x_i2c_remove(struct i2c_client *client)
491{
492 struct si470x_device *radio = i2c_get_clientdata(client);
493
Joonyoung Shimfe2137d2009-12-10 16:50:34 -0300494 free_irq(client->irq, radio);
495 cancel_work_sync(&radio->radio_work);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300496 video_unregister_device(radio->videodev);
497 kfree(radio);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300498
499 return 0;
500}
501
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300502
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300503#ifdef CONFIG_PM
504/*
505 * si470x_i2c_suspend - suspend the device
506 */
Joonyoung Shim949cf312011-03-11 03:54:47 -0300507static int si470x_i2c_suspend(struct device *dev)
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300508{
Joonyoung Shim949cf312011-03-11 03:54:47 -0300509 struct i2c_client *client = to_i2c_client(dev);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300510 struct si470x_device *radio = i2c_get_clientdata(client);
511
512 /* power down */
513 radio->registers[POWERCFG] |= POWERCFG_DISABLE;
514 if (si470x_set_register(radio, POWERCFG) < 0)
515 return -EIO;
516
517 return 0;
518}
519
520
521/*
522 * si470x_i2c_resume - resume the device
523 */
Joonyoung Shim949cf312011-03-11 03:54:47 -0300524static int si470x_i2c_resume(struct device *dev)
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300525{
Joonyoung Shim949cf312011-03-11 03:54:47 -0300526 struct i2c_client *client = to_i2c_client(dev);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300527 struct si470x_device *radio = i2c_get_clientdata(client);
528
529 /* power up : need 110ms */
530 radio->registers[POWERCFG] |= POWERCFG_ENABLE;
531 if (si470x_set_register(radio, POWERCFG) < 0)
532 return -EIO;
533 msleep(110);
534
535 return 0;
536}
Joonyoung Shim949cf312011-03-11 03:54:47 -0300537
538static SIMPLE_DEV_PM_OPS(si470x_i2c_pm, si470x_i2c_suspend, si470x_i2c_resume);
Joonyoung Shimd1471f02009-12-10 16:52:50 -0300539#endif
540
541
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300542/*
543 * si470x_i2c_driver - i2c driver interface
544 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300545static struct i2c_driver si470x_i2c_driver = {
546 .driver = {
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300547 .name = "si470x",
548 .owner = THIS_MODULE,
Joonyoung Shim949cf312011-03-11 03:54:47 -0300549#ifdef CONFIG_PM
550 .pm = &si470x_i2c_pm,
551#endif
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300552 },
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300553 .probe = si470x_i2c_probe,
554 .remove = __devexit_p(si470x_i2c_remove),
555 .id_table = si470x_i2c_id,
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300556};
557
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300558
559
560/**************************************************************************
561 * Module Interface
562 **************************************************************************/
563
564/*
565 * si470x_i2c_init - module init
566 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300567static int __init si470x_i2c_init(void)
568{
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300569 printk(KERN_INFO DRIVER_DESC ", Version " DRIVER_VERSION "\n");
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300570 return i2c_add_driver(&si470x_i2c_driver);
571}
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300572
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300573
574/*
575 * si470x_i2c_exit - module exit
576 */
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300577static void __exit si470x_i2c_exit(void)
578{
579 i2c_del_driver(&si470x_i2c_driver);
580}
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300581
582
583module_init(si470x_i2c_init);
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300584module_exit(si470x_i2c_exit);
585
Joonyoung Shimcc35bbd2009-08-09 14:23:35 -0300586MODULE_LICENSE("GPL");
Tobias Lorenz9dcb79c2009-08-10 18:44:14 -0300587MODULE_AUTHOR(DRIVER_AUTHOR);
588MODULE_DESCRIPTION(DRIVER_DESC);
589MODULE_VERSION(DRIVER_VERSION);