2 * i2sbus driver -- bus control routines
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 #include <linux/kernel.h>
10 #include <linux/delay.h>
11 #include <linux/slab.h>
15 #include <asm/macio.h>
16 #include <asm/pmac_feature.h>
17 #include <asm/pmac_pfunc.h>
18 #include <asm/keylargo.h>
22 int i2sbus_control_init(struct macio_dev
* dev
, struct i2sbus_control
**c
)
24 *c
= kzalloc(sizeof(struct i2sbus_control
), GFP_KERNEL
);
28 INIT_LIST_HEAD(&(*c
)->list
);
30 (*c
)->macio
= dev
->bus
->chip
;
34 void i2sbus_control_destroy(struct i2sbus_control
*c
)
39 /* this is serialised externally */
40 int i2sbus_control_add_dev(struct i2sbus_control
*c
,
41 struct i2sbus_dev
*i2sdev
)
43 struct device_node
*np
;
45 np
= i2sdev
->sound
.ofdev
.dev
.of_node
;
46 i2sdev
->enable
= pmf_find_function(np
, "enable");
47 i2sdev
->cell_enable
= pmf_find_function(np
, "cell-enable");
48 i2sdev
->clock_enable
= pmf_find_function(np
, "clock-enable");
49 i2sdev
->cell_disable
= pmf_find_function(np
, "cell-disable");
50 i2sdev
->clock_disable
= pmf_find_function(np
, "clock-disable");
52 /* if the bus number is not 0 or 1 we absolutely need to use
53 * the platform functions -- there's nothing in Darwin that
54 * would allow seeing a system behind what the FCRs are then,
55 * and I don't want to go parsing a bunch of platform functions
56 * by hand to try finding a system... */
57 if (i2sdev
->bus_number
!= 0 && i2sdev
->bus_number
!= 1 &&
59 !i2sdev
->cell_enable
|| !i2sdev
->clock_enable
||
60 !i2sdev
->cell_disable
|| !i2sdev
->clock_disable
)) {
61 pmf_put_function(i2sdev
->enable
);
62 pmf_put_function(i2sdev
->cell_enable
);
63 pmf_put_function(i2sdev
->clock_enable
);
64 pmf_put_function(i2sdev
->cell_disable
);
65 pmf_put_function(i2sdev
->clock_disable
);
69 list_add(&i2sdev
->item
, &c
->list
);
74 void i2sbus_control_remove_dev(struct i2sbus_control
*c
,
75 struct i2sbus_dev
*i2sdev
)
77 /* this is serialised externally */
78 list_del(&i2sdev
->item
);
79 if (list_empty(&c
->list
))
80 i2sbus_control_destroy(c
);
83 int i2sbus_control_enable(struct i2sbus_control
*c
,
84 struct i2sbus_dev
*i2sdev
)
86 struct pmf_args args
= { .count
= 0 };
87 struct macio_chip
*macio
= c
->macio
;
90 return pmf_call_one(i2sdev
->enable
, &args
);
92 if (macio
== NULL
|| macio
->base
== NULL
)
95 switch (i2sdev
->bus_number
) {
97 /* these need to be locked or done through
98 * newly created feature calls! */
99 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_ENABLE
);
102 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_ENABLE
);
110 int i2sbus_control_cell(struct i2sbus_control
*c
,
111 struct i2sbus_dev
*i2sdev
,
114 struct pmf_args args
= { .count
= 0 };
115 struct macio_chip
*macio
= c
->macio
;
119 if (i2sdev
->cell_disable
)
120 return pmf_call_one(i2sdev
->cell_disable
, &args
);
123 if (i2sdev
->cell_enable
)
124 return pmf_call_one(i2sdev
->cell_enable
, &args
);
127 printk(KERN_ERR
"i2sbus: INVALID CELL ENABLE VALUE\n");
131 if (macio
== NULL
|| macio
->base
== NULL
)
134 switch (i2sdev
->bus_number
) {
137 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_CELL_ENABLE
);
139 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S0_CELL_ENABLE
);
143 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_CELL_ENABLE
);
145 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S1_CELL_ENABLE
);
153 int i2sbus_control_clock(struct i2sbus_control
*c
,
154 struct i2sbus_dev
*i2sdev
,
157 struct pmf_args args
= { .count
= 0 };
158 struct macio_chip
*macio
= c
->macio
;
162 if (i2sdev
->clock_disable
)
163 return pmf_call_one(i2sdev
->clock_disable
, &args
);
166 if (i2sdev
->clock_enable
)
167 return pmf_call_one(i2sdev
->clock_enable
, &args
);
170 printk(KERN_ERR
"i2sbus: INVALID CLOCK ENABLE VALUE\n");
174 if (macio
== NULL
|| macio
->base
== NULL
)
177 switch (i2sdev
->bus_number
) {
180 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_CLK_ENABLE_BIT
);
182 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S0_CLK_ENABLE_BIT
);
186 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_CLK_ENABLE_BIT
);
188 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S1_CLK_ENABLE_BIT
);