1 // SPDX-License-Identifier: GPL-2.0-only
3 * i2sbus driver -- bus control routines
5 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/kernel.h>
9 #include <linux/delay.h>
10 #include <linux/slab.h>
13 #include <asm/macio.h>
14 #include <asm/pmac_feature.h>
15 #include <asm/pmac_pfunc.h>
16 #include <asm/keylargo.h>
20 int i2sbus_control_init(struct macio_dev* dev, struct i2sbus_control **c)
22 *c = kzalloc(sizeof(struct i2sbus_control), GFP_KERNEL);
26 INIT_LIST_HEAD(&(*c)->list);
28 (*c)->macio = dev->bus->chip;
32 void i2sbus_control_destroy(struct i2sbus_control *c)
37 /* this is serialised externally */
38 int i2sbus_control_add_dev(struct i2sbus_control *c,
39 struct i2sbus_dev *i2sdev)
41 struct device_node *np;
43 np = i2sdev->sound.ofdev.dev.of_node;
44 i2sdev->enable = pmf_find_function(np, "enable");
45 i2sdev->cell_enable = pmf_find_function(np, "cell-enable");
46 i2sdev->clock_enable = pmf_find_function(np, "clock-enable");
47 i2sdev->cell_disable = pmf_find_function(np, "cell-disable");
48 i2sdev->clock_disable = pmf_find_function(np, "clock-disable");
50 /* if the bus number is not 0 or 1 we absolutely need to use
51 * the platform functions -- there's nothing in Darwin that
52 * would allow seeing a system behind what the FCRs are then,
53 * and I don't want to go parsing a bunch of platform functions
54 * by hand to try finding a system... */
55 if (i2sdev->bus_number != 0 && i2sdev->bus_number != 1 &&
57 !i2sdev->cell_enable || !i2sdev->clock_enable ||
58 !i2sdev->cell_disable || !i2sdev->clock_disable)) {
59 pmf_put_function(i2sdev->enable);
60 pmf_put_function(i2sdev->cell_enable);
61 pmf_put_function(i2sdev->clock_enable);
62 pmf_put_function(i2sdev->cell_disable);
63 pmf_put_function(i2sdev->clock_disable);
67 list_add(&i2sdev->item, &c->list);
72 void i2sbus_control_remove_dev(struct i2sbus_control *c,
73 struct i2sbus_dev *i2sdev)
75 /* this is serialised externally */
76 list_del(&i2sdev->item);
77 if (list_empty(&c->list))
78 i2sbus_control_destroy(c);
81 int i2sbus_control_enable(struct i2sbus_control *c,
82 struct i2sbus_dev *i2sdev)
84 struct pmf_args args = { .count = 0 };
85 struct macio_chip *macio = c->macio;
88 return pmf_call_one(i2sdev->enable, &args);
90 if (macio == NULL || macio->base == NULL)
93 switch (i2sdev->bus_number) {
95 /* these need to be locked or done through
96 * newly created feature calls! */
97 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_ENABLE);
100 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_ENABLE);
108 int i2sbus_control_cell(struct i2sbus_control *c,
109 struct i2sbus_dev *i2sdev,
112 struct pmf_args args = { .count = 0 };
113 struct macio_chip *macio = c->macio;
117 if (i2sdev->cell_disable)
118 return pmf_call_one(i2sdev->cell_disable, &args);
121 if (i2sdev->cell_enable)
122 return pmf_call_one(i2sdev->cell_enable, &args);
125 printk(KERN_ERR "i2sbus: INVALID CELL ENABLE VALUE\n");
129 if (macio == NULL || macio->base == NULL)
132 switch (i2sdev->bus_number) {
135 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_CELL_ENABLE);
137 MACIO_BIC(KEYLARGO_FCR1, KL1_I2S0_CELL_ENABLE);
141 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_CELL_ENABLE);
143 MACIO_BIC(KEYLARGO_FCR1, KL1_I2S1_CELL_ENABLE);
151 int i2sbus_control_clock(struct i2sbus_control *c,
152 struct i2sbus_dev *i2sdev,
155 struct pmf_args args = { .count = 0 };
156 struct macio_chip *macio = c->macio;
160 if (i2sdev->clock_disable)
161 return pmf_call_one(i2sdev->clock_disable, &args);
164 if (i2sdev->clock_enable)
165 return pmf_call_one(i2sdev->clock_enable, &args);
168 printk(KERN_ERR "i2sbus: INVALID CLOCK ENABLE VALUE\n");
172 if (macio == NULL || macio->base == NULL)
175 switch (i2sdev->bus_number) {
178 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S0_CLK_ENABLE_BIT);
180 MACIO_BIC(KEYLARGO_FCR1, KL1_I2S0_CLK_ENABLE_BIT);
184 MACIO_BIS(KEYLARGO_FCR1, KL1_I2S1_CLK_ENABLE_BIT);
186 MACIO_BIC(KEYLARGO_FCR1, KL1_I2S1_CLK_ENABLE_BIT);