ucb1400_core.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Core functions for:
  3. * Philips UCB1400 multifunction chip
  4. *
  5. * Based on ucb1400_ts.c:
  6. * Author: Nicolas Pitre
  7. * Created: September 25, 2006
  8. * Copyright: MontaVista Software, Inc.
  9. *
  10. * Spliting done by: Marek Vasut <marek.vasut@gmail.com>
  11. * If something doesnt work and it worked before spliting, e-mail me,
  12. * dont bother Nicolas please ;-)
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. * This code is heavily based on ucb1x00-*.c copyrighted by Russell King
  19. * covering the UCB1100, UCB1200 and UCB1300.. Support for the UCB1400 has
  20. * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/ucb1400.h>
  24. unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel,
  25. int adcsync)
  26. {
  27. unsigned int val;
  28. if (adcsync)
  29. adc_channel |= UCB_ADC_SYNC_ENA;
  30. ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel);
  31. ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel |
  32. UCB_ADC_START);
  33. while (!((val = ucb1400_reg_read(ac97, UCB_ADC_DATA))
  34. & UCB_ADC_DAT_VALID))
  35. schedule_timeout_uninterruptible(1);
  36. return val & UCB_ADC_DAT_MASK;
  37. }
  38. EXPORT_SYMBOL_GPL(ucb1400_adc_read);
  39. static int ucb1400_core_probe(struct device *dev)
  40. {
  41. int err;
  42. struct ucb1400 *ucb;
  43. struct ucb1400_ts ucb_ts;
  44. struct snd_ac97 *ac97;
  45. memset(&ucb_ts, 0, sizeof(ucb_ts));
  46. ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL);
  47. if (!ucb) {
  48. err = -ENOMEM;
  49. goto err;
  50. }
  51. dev_set_drvdata(dev, ucb);
  52. ac97 = to_ac97_t(dev);
  53. ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID);
  54. if (ucb_ts.id != UCB_ID_1400) {
  55. err = -ENODEV;
  56. goto err0;
  57. }
  58. /* TOUCHSCREEN */
  59. ucb_ts.ac97 = ac97;
  60. ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1);
  61. if (!ucb->ucb1400_ts) {
  62. err = -ENOMEM;
  63. goto err0;
  64. }
  65. err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts,
  66. sizeof(ucb_ts));
  67. if (err)
  68. goto err1;
  69. err = platform_device_add(ucb->ucb1400_ts);
  70. if (err)
  71. goto err1;
  72. return 0;
  73. err1:
  74. platform_device_put(ucb->ucb1400_ts);
  75. err0:
  76. kfree(ucb);
  77. err:
  78. return err;
  79. }
  80. static int ucb1400_core_remove(struct device *dev)
  81. {
  82. struct ucb1400 *ucb = dev_get_drvdata(dev);
  83. platform_device_unregister(ucb->ucb1400_ts);
  84. kfree(ucb);
  85. return 0;
  86. }
  87. static struct device_driver ucb1400_core_driver = {
  88. .name = "ucb1400_core",
  89. .bus = &ac97_bus_type,
  90. .probe = ucb1400_core_probe,
  91. .remove = ucb1400_core_remove,
  92. };
  93. static int __init ucb1400_core_init(void)
  94. {
  95. return driver_register(&ucb1400_core_driver);
  96. }
  97. static void __exit ucb1400_core_exit(void)
  98. {
  99. driver_unregister(&ucb1400_core_driver);
  100. }
  101. module_init(ucb1400_core_init);
  102. module_exit(ucb1400_core_exit);
  103. MODULE_DESCRIPTION("Philips UCB1400 driver");
  104. MODULE_LICENSE("GPL");