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