wm1250-ev1.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Driver for the 1250-EV1 audio I/O module
  3. *
  4. * Copyright 2011 Wolfson Microelectronics plc
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/i2c.h>
  15. #include <sound/soc.h>
  16. #include <sound/soc-dapm.h>
  17. static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets[] = {
  18. SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM, 0, 0),
  19. SND_SOC_DAPM_DAC("DAC", "wm1250-ev1 Playback", SND_SOC_NOPM, 0, 0),
  20. SND_SOC_DAPM_INPUT("WM1250 Input"),
  21. SND_SOC_DAPM_OUTPUT("WM1250 Output"),
  22. };
  23. static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
  24. { "ADC", NULL, "WM1250 Input" },
  25. { "WM1250 Output", NULL, "DAC" },
  26. };
  27. static struct snd_soc_dai_driver wm1250_ev1_dai = {
  28. .name = "wm1250-ev1",
  29. .playback = {
  30. .stream_name = "Playback",
  31. .channels_min = 1,
  32. .channels_max = 1,
  33. .rates = SNDRV_PCM_RATE_8000,
  34. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  35. },
  36. .capture = {
  37. .stream_name = "Capture",
  38. .channels_min = 1,
  39. .channels_max = 1,
  40. .rates = SNDRV_PCM_RATE_8000,
  41. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  42. },
  43. };
  44. static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
  45. .dapm_widgets = wm1250_ev1_dapm_widgets,
  46. .num_dapm_widgets = ARRAY_SIZE(wm1250_ev1_dapm_widgets),
  47. .dapm_routes = wm1250_ev1_dapm_routes,
  48. .num_dapm_routes = ARRAY_SIZE(wm1250_ev1_dapm_routes),
  49. };
  50. static int __devinit wm1250_ev1_probe(struct i2c_client *i2c,
  51. const struct i2c_device_id *i2c_id)
  52. {
  53. int id, board, rev;
  54. board = i2c_smbus_read_byte_data(i2c, 0);
  55. if (board < 0) {
  56. dev_err(&i2c->dev, "Failed to read ID: %d\n", board);
  57. return board;
  58. }
  59. id = (board & 0xfe) >> 2;
  60. rev = board & 0x3;
  61. if (id != 1) {
  62. dev_err(&i2c->dev, "Unknown board ID %d\n", id);
  63. return -ENODEV;
  64. }
  65. dev_info(&i2c->dev, "revision %d\n", rev + 1);
  66. return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm1250_ev1,
  67. &wm1250_ev1_dai, 1);
  68. }
  69. static int __devexit wm1250_ev1_remove(struct i2c_client *i2c)
  70. {
  71. snd_soc_unregister_codec(&i2c->dev);
  72. return 0;
  73. }
  74. static const struct i2c_device_id wm1250_ev1_i2c_id[] = {
  75. { "wm1250-ev1", 0 },
  76. { }
  77. };
  78. MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
  79. static struct i2c_driver wm1250_ev1_i2c_driver = {
  80. .driver = {
  81. .name = "wm1250-ev1",
  82. .owner = THIS_MODULE,
  83. },
  84. .probe = wm1250_ev1_probe,
  85. .remove = __devexit_p(wm1250_ev1_remove),
  86. .id_table = wm1250_ev1_i2c_id,
  87. };
  88. static int __init wm1250_ev1_modinit(void)
  89. {
  90. int ret = 0;
  91. ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
  92. if (ret != 0)
  93. pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
  94. return ret;
  95. }
  96. module_init(wm1250_ev1_modinit);
  97. static void __exit wm1250_ev1_exit(void)
  98. {
  99. i2c_del_driver(&wm1250_ev1_i2c_driver);
  100. }
  101. module_exit(wm1250_ev1_exit);
  102. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  103. MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
  104. MODULE_LICENSE("GPL");