wis-uda1342.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2005-2006 Micronas USA Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/i2c.h>
  20. #include <linux/videodev2.h>
  21. #include <media/tvaudio.h>
  22. #include <media/v4l2-common.h>
  23. #include "wis-i2c.h"
  24. static int write_reg(struct i2c_client *client, int reg, int value)
  25. {
  26. /* UDA1342 wants MSB first, but SMBus sends LSB first */
  27. i2c_smbus_write_word_data(client, reg, swab16(value));
  28. return 0;
  29. }
  30. static int wis_uda1342_command(struct i2c_client *client,
  31. unsigned int cmd, void *arg)
  32. {
  33. switch (cmd) {
  34. case VIDIOC_S_AUDIO:
  35. {
  36. int *inp = arg;
  37. switch (*inp) {
  38. case TVAUDIO_INPUT_TUNER:
  39. write_reg(client, 0x00, 0x1441); /* select input 2 */
  40. break;
  41. case TVAUDIO_INPUT_EXTERN:
  42. write_reg(client, 0x00, 0x1241); /* select input 1 */
  43. break;
  44. default:
  45. printk(KERN_ERR "wis-uda1342: input %d not supported\n",
  46. *inp);
  47. break;
  48. }
  49. break;
  50. }
  51. default:
  52. break;
  53. }
  54. return 0;
  55. }
  56. static int wis_uda1342_probe(struct i2c_client *client,
  57. const struct i2c_device_id *id)
  58. {
  59. struct i2c_adapter *adapter = client->adapter;
  60. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
  61. return -ENODEV;
  62. printk(KERN_DEBUG
  63. "wis-uda1342: initializing UDA1342 at address %d on %s\n",
  64. client->addr, adapter->name);
  65. write_reg(client, 0x00, 0x8000); /* reset registers */
  66. write_reg(client, 0x00, 0x1241); /* select input 1 */
  67. return 0;
  68. }
  69. static int wis_uda1342_remove(struct i2c_client *client)
  70. {
  71. return 0;
  72. }
  73. static const struct i2c_device_id wis_uda1342_id[] = {
  74. { "wis_uda1342", 0 },
  75. { }
  76. };
  77. MODULE_DEVICE_TABLE(i2c, wis_uda1342_id);
  78. static struct i2c_driver wis_uda1342_driver = {
  79. .driver = {
  80. .name = "WIS UDA1342 I2C driver",
  81. },
  82. .probe = wis_uda1342_probe,
  83. .remove = wis_uda1342_remove,
  84. .command = wis_uda1342_command,
  85. .id_table = wis_uda1342_id,
  86. };
  87. static int __init wis_uda1342_init(void)
  88. {
  89. return i2c_add_driver(&wis_uda1342_driver);
  90. }
  91. static void __exit wis_uda1342_cleanup(void)
  92. {
  93. i2c_del_driver(&wis_uda1342_driver);
  94. }
  95. module_init(wis_uda1342_init);
  96. module_exit(wis_uda1342_cleanup);
  97. MODULE_LICENSE("GPL v2");