23 #include <linux/export.h>
25 #include <linux/slab.h>
34 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
38 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
42 static void udbg_putc_cpm(
char c)
49 while (
in_be32(&cpm_udbg_txdesc[0]) & 0x80000000)
53 out_be32(&cpm_udbg_txdesc[0], 0xa0000001);
56 void __init udbg_init_cpm(
void)
58 if (cpm_udbg_txdesc) {
74 #define OF_MAX_ADDR_CELLS 4
91 sizeof(cpm_boot_muram_rh_block) /
92 sizeof(cpm_boot_muram_rh_block[0]),
93 cpm_boot_muram_rh_block);
121 muram_vbase =
ioremap(muram_pbase, max - muram_pbase + 1);
148 start =
rh_alloc(&cpm_muram_info, size,
"commproc");
150 spin_unlock_irqrestore(&cpm_muram_lock, flags);
166 ret =
rh_free(&cpm_muram_info, offset);
167 spin_unlock_irqrestore(&cpm_muram_lock, flags);
189 start =
rh_alloc_fixed(&cpm_muram_info, offset, size,
"commproc");
190 spin_unlock_irqrestore(&cpm_muram_lock, flags);
202 return muram_vbase +
offset;
208 return addr - (
void __iomem *)muram_vbase;
218 return muram_pbase + ((
u8 __iomem *)addr - muram_vbase);
222 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
229 struct cpm2_gpio32_chip {
230 struct of_mm_gpio_chip mm_gc;
237 static inline struct cpm2_gpio32_chip *
238 to_cpm2_gpio32_chip(
struct of_mm_gpio_chip *mm_gc)
240 return container_of(mm_gc,
struct cpm2_gpio32_chip, mm_gc);
243 static void cpm2_gpio32_save_regs(
struct of_mm_gpio_chip *mm_gc)
245 struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
251 static int cpm2_gpio32_get(
struct gpio_chip *
gc,
unsigned int gpio)
253 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
257 pin_mask = 1 << (31 -
gpio);
262 static void __cpm2_gpio32_set(
struct of_mm_gpio_chip *mm_gc,
u32 pin_mask,
265 struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
269 cpm2_gc->cpdata |= pin_mask;
271 cpm2_gc->cpdata &= ~pin_mask;
276 static void cpm2_gpio32_set(
struct gpio_chip *
gc,
unsigned int gpio,
int value)
278 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
279 struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
281 u32 pin_mask = 1 << (31 -
gpio);
285 __cpm2_gpio32_set(mm_gc, pin_mask, value);
287 spin_unlock_irqrestore(&cpm2_gc->lock, flags);
290 static int cpm2_gpio32_dir_out(
struct gpio_chip *
gc,
unsigned int gpio,
int val)
292 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
293 struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
296 u32 pin_mask = 1 << (31 -
gpio);
300 setbits32(&iop->
dir, pin_mask);
301 __cpm2_gpio32_set(mm_gc, pin_mask, val);
303 spin_unlock_irqrestore(&cpm2_gc->lock, flags);
308 static int cpm2_gpio32_dir_in(
struct gpio_chip *
gc,
unsigned int gpio)
310 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
311 struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
314 u32 pin_mask = 1 << (31 -
gpio);
318 clrbits32(&iop->
dir, pin_mask);
320 spin_unlock_irqrestore(&cpm2_gc->lock, flags);
327 struct cpm2_gpio32_chip *cpm2_gc;
328 struct of_mm_gpio_chip *mm_gc;
329 struct gpio_chip *
gc;
331 cpm2_gc = kzalloc(
sizeof(*cpm2_gc),
GFP_KERNEL);
337 mm_gc = &cpm2_gc->mm_gc;
340 mm_gc->save_regs = cpm2_gpio32_save_regs;
342 gc->direction_input = cpm2_gpio32_dir_in;
343 gc->direction_output = cpm2_gpio32_dir_out;
344 gc->get = cpm2_gpio32_get;
345 gc->set = cpm2_gpio32_set;