ucb1400_core.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 ucb1400_gpio ucb_gpio;
  45. struct snd_ac97 *ac97;
  46. memset(&ucb_ts, 0, sizeof(ucb_ts));
  47. memset(&ucb_gpio, 0, sizeof(ucb_gpio));
  48. ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL);
  49. if (!ucb) {
  50. err = -ENOMEM;
  51. goto err;
  52. }
  53. dev_set_drvdata(dev, ucb);
  54. ac97 = to_ac97_t(dev);
  55. ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID);
  56. if (ucb_ts.id != UCB_ID_1400) {
  57. err = -ENODEV;
  58. goto err0;
  59. }
  60. /* GPIO */
  61. ucb_gpio.ac97 = ac97;
  62. ucb->ucb1400_gpio = platform_device_alloc("ucb1400_gpio", -1);
  63. if (!ucb->ucb1400_gpio) {
  64. err = -ENOMEM;
  65. goto err0;
  66. }
  67. err = platform_device_add_data(ucb->ucb1400_gpio, &ucb_gpio,
  68. sizeof(ucb_gpio));
  69. if (err)
  70. goto err1;
  71. err = platform_device_add(ucb->ucb1400_gpio);
  72. if (err)
  73. goto err1;
  74. /* TOUCHSCREEN */
  75. ucb_ts.ac97 = ac97;
  76. ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1);
  77. if (!ucb->ucb1400_ts) {
  78. err = -ENOMEM;
  79. goto err2;
  80. }
  81. err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts,
  82. sizeof(ucb_ts));
  83. if (err)
  84. goto err3;
  85. err = platform_device_add(ucb->ucb1400_ts);
  86. if (err)
  87. goto err3;
  88. return 0;
  89. err3:
  90. platform_device_put(ucb->ucb1400_ts);
  91. err2:
  92. platform_device_unregister(ucb->ucb1400_gpio);
  93. err1:
  94. platform_device_put(ucb->ucb1400_gpio);
  95. err0:
  96. kfree(ucb);
  97. err:
  98. return err;
  99. }
  100. static int ucb1400_core_remove(struct device *dev)
  101. {
  102. struct ucb1400 *ucb = dev_get_drvdata(dev);
  103. platform_device_unregister(ucb->ucb1400_ts);
  104. platform_device_unregister(ucb->ucb1400_gpio);
  105. kfree(ucb);
  106. return 0;
  107. }
  108. static struct device_driver ucb1400_core_driver = {
  109. .name = "ucb1400_core",
  110. .bus = &ac97_bus_type,
  111. .probe = ucb1400_core_probe,
  112. .remove = ucb1400_core_remove,
  113. };
  114. static int __init ucb1400_core_init(void)
  115. {
  116. return driver_register(&ucb1400_core_driver);
  117. }
  118. static void __exit ucb1400_core_exit(void)
  119. {
  120. driver_unregister(&ucb1400_core_driver);
  121. }
  122. module_init(ucb1400_core_init);
  123. module_exit(ucb1400_core_exit);
  124. MODULE_DESCRIPTION("Philips UCB1400 driver");
  125. MODULE_LICENSE("GPL");