ucb1400_core.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/sched.h>
  24. #include <linux/ucb1400.h>
  25. unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel,
  26. int adcsync)
  27. {
  28. unsigned int val;
  29. if (adcsync)
  30. adc_channel |= UCB_ADC_SYNC_ENA;
  31. ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel);
  32. ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel |
  33. UCB_ADC_START);
  34. while (!((val = ucb1400_reg_read(ac97, UCB_ADC_DATA))
  35. & UCB_ADC_DAT_VALID))
  36. schedule_timeout_uninterruptible(1);
  37. return val & UCB_ADC_DAT_MASK;
  38. }
  39. EXPORT_SYMBOL_GPL(ucb1400_adc_read);
  40. static int ucb1400_core_probe(struct device *dev)
  41. {
  42. int err;
  43. struct ucb1400 *ucb;
  44. struct ucb1400_ts ucb_ts;
  45. struct ucb1400_gpio ucb_gpio;
  46. struct snd_ac97 *ac97;
  47. struct ucb1400_pdata *pdata = dev->platform_data;
  48. memset(&ucb_ts, 0, sizeof(ucb_ts));
  49. memset(&ucb_gpio, 0, sizeof(ucb_gpio));
  50. ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL);
  51. if (!ucb) {
  52. err = -ENOMEM;
  53. goto err;
  54. }
  55. dev_set_drvdata(dev, ucb);
  56. ac97 = to_ac97_t(dev);
  57. ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID);
  58. if (ucb_ts.id != UCB_ID_1400) {
  59. err = -ENODEV;
  60. goto err0;
  61. }
  62. /* GPIO */
  63. ucb_gpio.ac97 = ac97;
  64. ucb->ucb1400_gpio = platform_device_alloc("ucb1400_gpio", -1);
  65. if (!ucb->ucb1400_gpio) {
  66. err = -ENOMEM;
  67. goto err0;
  68. }
  69. err = platform_device_add_data(ucb->ucb1400_gpio, &ucb_gpio,
  70. sizeof(ucb_gpio));
  71. if (err)
  72. goto err1;
  73. err = platform_device_add(ucb->ucb1400_gpio);
  74. if (err)
  75. goto err1;
  76. /* TOUCHSCREEN */
  77. ucb_ts.ac97 = ac97;
  78. if (pdata != NULL && pdata->irq >= 0)
  79. ucb_ts.irq = pdata->irq;
  80. else
  81. ucb_ts.irq = -1;
  82. ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1);
  83. if (!ucb->ucb1400_ts) {
  84. err = -ENOMEM;
  85. goto err2;
  86. }
  87. err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts,
  88. sizeof(ucb_ts));
  89. if (err)
  90. goto err3;
  91. err = platform_device_add(ucb->ucb1400_ts);
  92. if (err)
  93. goto err3;
  94. return 0;
  95. err3:
  96. platform_device_put(ucb->ucb1400_ts);
  97. err2:
  98. platform_device_unregister(ucb->ucb1400_gpio);
  99. err1:
  100. platform_device_put(ucb->ucb1400_gpio);
  101. err0:
  102. kfree(ucb);
  103. err:
  104. return err;
  105. }
  106. static int ucb1400_core_remove(struct device *dev)
  107. {
  108. struct ucb1400 *ucb = dev_get_drvdata(dev);
  109. platform_device_unregister(ucb->ucb1400_ts);
  110. platform_device_unregister(ucb->ucb1400_gpio);
  111. kfree(ucb);
  112. return 0;
  113. }
  114. static struct device_driver ucb1400_core_driver = {
  115. .name = "ucb1400_core",
  116. .bus = &ac97_bus_type,
  117. .probe = ucb1400_core_probe,
  118. .remove = ucb1400_core_remove,
  119. };
  120. static int __init ucb1400_core_init(void)
  121. {
  122. return driver_register(&ucb1400_core_driver);
  123. }
  124. static void __exit ucb1400_core_exit(void)
  125. {
  126. driver_unregister(&ucb1400_core_driver);
  127. }
  128. module_init(ucb1400_core_init);
  129. module_exit(ucb1400_core_exit);
  130. MODULE_DESCRIPTION("Philips UCB1400 driver");
  131. MODULE_LICENSE("GPL");