ucb1400_core.c 3.7 KB

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