uda1342.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/i2c.h>
  16. #include <linux/videodev2.h>
  17. #include <media/v4l2-device.h>
  18. #include <media/i2c/uda1342.h>
  19. #include <linux/slab.h>
  20. static int write_reg(struct i2c_client *client, int reg, int value)
  21. {
  22. /* UDA1342 wants MSB first, but SMBus sends LSB first */
  23. i2c_smbus_write_word_data(client, reg, swab16(value));
  24. return 0;
  25. }
  26. static int uda1342_s_routing(struct v4l2_subdev *sd,
  27. u32 input, u32 output, u32 config)
  28. {
  29. struct i2c_client *client = v4l2_get_subdevdata(sd);
  30. switch (input) {
  31. case UDA1342_IN1:
  32. write_reg(client, 0x00, 0x1241); /* select input 1 */
  33. break;
  34. case UDA1342_IN2:
  35. write_reg(client, 0x00, 0x1441); /* select input 2 */
  36. break;
  37. default:
  38. v4l2_err(sd, "input %d not supported\n", input);
  39. break;
  40. }
  41. return 0;
  42. }
  43. static const struct v4l2_subdev_audio_ops uda1342_audio_ops = {
  44. .s_routing = uda1342_s_routing,
  45. };
  46. static const struct v4l2_subdev_ops uda1342_ops = {
  47. .audio = &uda1342_audio_ops,
  48. };
  49. static int uda1342_probe(struct i2c_client *client,
  50. const struct i2c_device_id *id)
  51. {
  52. struct i2c_adapter *adapter = client->adapter;
  53. struct v4l2_subdev *sd;
  54. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
  55. return -ENODEV;
  56. dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
  57. client->addr, adapter->name);
  58. sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
  59. if (sd == NULL)
  60. return -ENOMEM;
  61. v4l2_i2c_subdev_init(sd, client, &uda1342_ops);
  62. write_reg(client, 0x00, 0x8000); /* reset registers */
  63. write_reg(client, 0x00, 0x1241); /* select input 1 */
  64. v4l_info(client, "chip found @ 0x%02x (%s)\n",
  65. client->addr << 1, client->adapter->name);
  66. return 0;
  67. }
  68. static int uda1342_remove(struct i2c_client *client)
  69. {
  70. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  71. v4l2_device_unregister_subdev(sd);
  72. return 0;
  73. }
  74. static const struct i2c_device_id uda1342_id[] = {
  75. { "uda1342", 0 },
  76. { }
  77. };
  78. MODULE_DEVICE_TABLE(i2c, uda1342_id);
  79. static struct i2c_driver uda1342_driver = {
  80. .driver = {
  81. .name = "uda1342",
  82. },
  83. .probe = uda1342_probe,
  84. .remove = uda1342_remove,
  85. .id_table = uda1342_id,
  86. };
  87. module_i2c_driver(uda1342_driver);
  88. MODULE_LICENSE("GPL v2");