control.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * i2sbus driver -- bus control routines
  4. *
  5. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/delay.h>
  9. #include <linux/slab.h>
  10. #include <linux/io.h>
  11. #include <asm/macio.h>
  12. #include <asm/pmac_feature.h>
  13. #include <asm/pmac_pfunc.h>
  14. #include <asm/keylargo.h>
  15. #include "i2sbus.h"
  16. int i2sbus_control_init(struct macio_dev* dev, struct i2sbus_control **c)
  17. {
  18. *c = kzalloc(sizeof(struct i2sbus_control), GFP_KERNEL);
  19. if (!*c)
  20. return -ENOMEM;
  21. INIT_LIST_HEAD(&(*c)->list);
  22. (*c)->macio = dev->bus->chip;
  23. return 0;
  24. }
  25. void i2sbus_control_destroy(struct i2sbus_control *c)
  26. {
  27. kfree(c);
  28. }
  29. /* this is serialised externally */
  30. int i2sbus_control_add_dev(struct i2sbus_control *c,
  31. struct i2sbus_dev *i2sdev)
  32. {
  33. struct device_node *np;
  34. np = i2sdev->sound.ofdev.dev.of_node;
  35. i2sdev->enable = pmf_find_function(np, "enable");
  36. i2sdev->cell_enable = pmf_find_function(np, "cell-enable");
  37. i2sdev->clock_enable = pmf_find_function(np, "clock-enable");
  38. i2sdev->cell_disable = pmf_find_function(np, "cell-disable");
  39. i2sdev->clock_disable = pmf_find_function(np, "clock-disable");
  40. /* if the bus number is not 0 or 1 we absolutely need to use
  41. * the platform functions -- there's nothing in Darwin that
  42. * would allow seeing a system behind what the FCRs are then,
  43. * and I don't want to go parsing a bunch of platform functions
  44. * by hand to try finding a system... */
  45. if (i2sdev->bus_number != 0 && i2sdev->bus_number != 1 &&
  46. (!i2sdev->enable ||
  47. !i2sdev->cell_enable || !i2sdev->clock_enable ||
  48. !i2sdev->cell_disable || !i2sdev->clock_disable)) {
  49. pmf_put_function(i2sdev->enable);
  50. pmf_put_function(i2sdev->cell_enable);
  51. pmf_put_function(i2sdev->clock_enable);
  52. pmf_put_function(i2sdev->cell_disable);
  53. pmf_put_function(i2sdev->clock_disable);
  54. return -ENODEV;
  55. }
  56. list_add(&i2sdev->item, &c->list);
  57. return 0;
  58. }
  59. void i2sbus_control_remove_dev(struct i2sbus_control *c,
  60. struct i2sbus_dev *i2sdev)
  61. {
  62. /* this is serialised externally */
  63. list_del(&i2sdev->item);
  64. if (list_empty(&c->list))
  65. i2sbus_control_destroy(c);
  66. }
  67. int i2sbus_control_enable(struct i2sbus_control *c,
  68. struct i2sbus_dev *i2sdev)
  69. {
  70. struct pmf_args args = { .count = 0 };
  71. struct macio_chip *macio = c->macio;
  72. if (i2sdev->enable)
  73. return pmf_call_one(i2sdev->enable, &args);
  74. if (macio == NULL || macio->base == NULL)
  75. return -ENODEV;
  76. switch (i2sdev->bus_number) {
  77. case 0:
  78. /* these need to be locked or done through
  79. * newly created feature calls! */
  80. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_ENABLE);
  81. break;
  82. case 1:
  83. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_ENABLE);
  84. break;
  85. default:
  86. return -ENODEV;
  87. }
  88. return 0;
  89. }
  90. int i2sbus_control_cell(struct i2sbus_control *c,
  91. struct i2sbus_dev *i2sdev,
  92. int enable)
  93. {
  94. struct pmf_args args = { .count = 0 };
  95. struct macio_chip *macio = c->macio;
  96. switch (enable) {
  97. case 0:
  98. if (i2sdev->cell_disable)
  99. return pmf_call_one(i2sdev->cell_disable, &args);
  100. break;
  101. case 1:
  102. if (i2sdev->cell_enable)
  103. return pmf_call_one(i2sdev->cell_enable, &args);
  104. break;
  105. default:
  106. printk(KERN_ERR "i2sbus: INVALID CELL ENABLE VALUE\n");
  107. return -ENODEV;
  108. }
  109. if (macio == NULL || macio->base == NULL)
  110. return -ENODEV;
  111. switch (i2sdev->bus_number) {
  112. case 0:
  113. if (enable)
  114. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_CELL_ENABLE);
  115. else
  116. MACIO_BIC(KEYLARGO_FCR1, KL1_I2S0_CELL_ENABLE);
  117. break;
  118. case 1:
  119. if (enable)
  120. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_CELL_ENABLE);
  121. else
  122. MACIO_BIC(KEYLARGO_FCR1, KL1_I2S1_CELL_ENABLE);
  123. break;
  124. default:
  125. return -ENODEV;
  126. }
  127. return 0;
  128. }
  129. int i2sbus_control_clock(struct i2sbus_control *c,
  130. struct i2sbus_dev *i2sdev,
  131. int enable)
  132. {
  133. struct pmf_args args = { .count = 0 };
  134. struct macio_chip *macio = c->macio;
  135. switch (enable) {
  136. case 0:
  137. if (i2sdev->clock_disable)
  138. return pmf_call_one(i2sdev->clock_disable, &args);
  139. break;
  140. case 1:
  141. if (i2sdev->clock_enable)
  142. return pmf_call_one(i2sdev->clock_enable, &args);
  143. break;
  144. default:
  145. printk(KERN_ERR "i2sbus: INVALID CLOCK ENABLE VALUE\n");
  146. return -ENODEV;
  147. }
  148. if (macio == NULL || macio->base == NULL)
  149. return -ENODEV;
  150. switch (i2sdev->bus_number) {
  151. case 0:
  152. if (enable)
  153. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_CLK_ENABLE_BIT);
  154. else
  155. MACIO_BIC(KEYLARGO_FCR1, KL1_I2S0_CLK_ENABLE_BIT);
  156. break;
  157. case 1:
  158. if (enable)
  159. MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_CLK_ENABLE_BIT);
  160. else
  161. MACIO_BIC(KEYLARGO_FCR1, KL1_I2S1_CLK_ENABLE_BIT);
  162. break;
  163. default:
  164. return -ENODEV;
  165. }
  166. return 0;
  167. }