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>
14 #include <asm/macio.h>
15 #include <asm/pmac_feature.h>
16 #include <asm/pmac_pfunc.h>
17 #include <asm/keylargo.h>
21 int i2sbus_control_init(struct macio_dev
* dev
, struct i2sbus_control
**c
)
23 *c
= kzalloc(sizeof(struct i2sbus_control
), GFP_KERNEL
);
27 INIT_LIST_HEAD(&(*c
)->list
);
29 (*c
)->macio
= dev
->bus
->chip
;
33 void i2sbus_control_destroy(struct i2sbus_control
*c
)
38 /* this is serialised externally */
39 int i2sbus_control_add_dev(struct i2sbus_control
*c
,
40 struct i2sbus_dev
*i2sdev
)
42 struct device_node
*np
;
44 np
= i2sdev
->sound
.ofdev
.node
;
45 i2sdev
->enable
= pmf_find_function(np
, "enable");
46 i2sdev
->cell_enable
= pmf_find_function(np
, "cell-enable");
47 i2sdev
->clock_enable
= pmf_find_function(np
, "clock-enable");
48 i2sdev
->cell_disable
= pmf_find_function(np
, "cell-disable");
49 i2sdev
->clock_disable
= pmf_find_function(np
, "clock-disable");
51 /* if the bus number is not 0 or 1 we absolutely need to use
52 * the platform functions -- there's nothing in Darwin that
53 * would allow seeing a system behind what the FCRs are then,
54 * and I don't want to go parsing a bunch of platform functions
55 * by hand to try finding a system... */
56 if (i2sdev
->bus_number
!= 0 && i2sdev
->bus_number
!= 1 &&
58 !i2sdev
->cell_enable
|| !i2sdev
->clock_enable
||
59 !i2sdev
->cell_disable
|| !i2sdev
->clock_disable
)) {
60 pmf_put_function(i2sdev
->enable
);
61 pmf_put_function(i2sdev
->cell_enable
);
62 pmf_put_function(i2sdev
->clock_enable
);
63 pmf_put_function(i2sdev
->cell_disable
);
64 pmf_put_function(i2sdev
->clock_disable
);
68 list_add(&i2sdev
->item
, &c
->list
);
73 void i2sbus_control_remove_dev(struct i2sbus_control
*c
,
74 struct i2sbus_dev
*i2sdev
)
76 /* this is serialised externally */
77 list_del(&i2sdev
->item
);
78 if (list_empty(&c
->list
))
79 i2sbus_control_destroy(c
);
82 int i2sbus_control_enable(struct i2sbus_control
*c
,
83 struct i2sbus_dev
*i2sdev
)
85 struct pmf_args args
= { .count
= 0 };
86 struct macio_chip
*macio
= c
->macio
;
89 return pmf_call_one(i2sdev
->enable
, &args
);
91 if (macio
== NULL
|| macio
->base
== NULL
)
94 switch (i2sdev
->bus_number
) {
96 /* these need to be locked or done through
97 * newly created feature calls! */
98 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_ENABLE
);
101 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_ENABLE
);
109 int i2sbus_control_cell(struct i2sbus_control
*c
,
110 struct i2sbus_dev
*i2sdev
,
113 struct pmf_args args
= { .count
= 0 };
114 struct macio_chip
*macio
= c
->macio
;
118 if (i2sdev
->cell_disable
)
119 return pmf_call_one(i2sdev
->cell_disable
, &args
);
122 if (i2sdev
->cell_enable
)
123 return pmf_call_one(i2sdev
->cell_enable
, &args
);
126 printk(KERN_ERR
"i2sbus: INVALID CELL ENABLE VALUE\n");
130 if (macio
== NULL
|| macio
->base
== NULL
)
133 switch (i2sdev
->bus_number
) {
136 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_CELL_ENABLE
);
138 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S0_CELL_ENABLE
);
142 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_CELL_ENABLE
);
144 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S1_CELL_ENABLE
);
152 int i2sbus_control_clock(struct i2sbus_control
*c
,
153 struct i2sbus_dev
*i2sdev
,
156 struct pmf_args args
= { .count
= 0 };
157 struct macio_chip
*macio
= c
->macio
;
161 if (i2sdev
->clock_disable
)
162 return pmf_call_one(i2sdev
->clock_disable
, &args
);
165 if (i2sdev
->clock_enable
)
166 return pmf_call_one(i2sdev
->clock_enable
, &args
);
169 printk(KERN_ERR
"i2sbus: INVALID CLOCK ENABLE VALUE\n");
173 if (macio
== NULL
|| macio
->base
== NULL
)
176 switch (i2sdev
->bus_number
) {
179 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S0_CLK_ENABLE_BIT
);
181 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S0_CLK_ENABLE_BIT
);
185 MACIO_BIS(KEYLARGO_FCR1
, KL1_I2S1_CLK_ENABLE_BIT
);
187 MACIO_BIC(KEYLARGO_FCR1
, KL1_I2S1_CLK_ENABLE_BIT
);