23 #include <linux/errno.h>
24 #include <linux/sched.h>
25 #include <linux/kernel.h>
28 #include <linux/string.h>
32 #include <linux/module.h>
34 #include <linux/slab.h>
36 #include <asm/pgtable.h>
40 #include <asm/tlbflush.h>
47 #ifdef CONFIG_8xx_GPIO
51 #define CPM_MAP_SIZE (0x4000)
55 static cpic8xx_t
__iomem *cpic_reg;
59 static void cpm_mask_irq(
struct irq_data *
d)
61 unsigned int cpm_vec = (
unsigned int)irqd_to_hwirq(d);
63 clrbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec));
66 static void cpm_unmask_irq(
struct irq_data *
d)
68 unsigned int cpm_vec = (
unsigned int)irqd_to_hwirq(d);
70 setbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec));
73 static void cpm_end_irq(
struct irq_data *d)
75 unsigned int cpm_vec = (
unsigned int)irqd_to_hwirq(d);
77 out_be32(&cpic_reg->cpic_cisr, (1 << cpm_vec));
82 .irq_mask = cpm_mask_irq,
83 .irq_unmask = cpm_unmask_irq,
84 .irq_eoi = cpm_end_irq,
95 cpm_vec =
in_be16(&cpic_reg->cpic_civr);
101 static int cpm_pic_host_map(
struct irq_domain *
h,
unsigned int virq,
104 pr_debug(
"cpm_pic_host_map(%d, 0x%lx)\n", virq, hw);
121 static struct irqaction cpm_error_irqaction = {
122 .handler = cpm_error_interrupt,
127 .map = cpm_pic_host_map,
134 unsigned int sirq =
NO_IRQ, hwirq, eirq;
152 if (cpic_reg ==
NULL)
168 if (cpm_pic_host ==
NULL) {
187 if (
setup_irq(eirq, &cpm_error_irqaction))
190 setbits32(&cpic_reg->cpic_cicr,
CICR_IEN);
199 sysconf8xx_t
__iomem *siu_conf;
209 #ifndef CONFIG_PPC_EARLY_DEBUG_CPM
219 #ifdef CONFIG_UCODE_PATCH
229 siu_conf = immr_map(im_siu_conf);
231 immr_unmap(siu_conf);
238 #define MAX_CR_CMD_LOOPS 10000
245 if (command & 0xffffff0f)
256 printk(
KERN_ERR "%s(): Not able to issue CPM command\n", __func__);
259 spin_unlock_irqrestore(&
cmd_lock, flags);
269 #define BRG_INT_CLK (get_brgfreq())
270 #define BRG_UART_CLK (BRG_INT_CLK/16)
271 #define BRG_UART_CLK_DIV16 (BRG_UART_CLK/16)
280 bp = &
cpmp->cp_brgc1;
305 static void cpm1_set_pin32(
int port,
int pin,
int flags)
308 pin = 1 << (31 -
pin);
318 setbits32(&iop->
dir, pin);
320 clrbits32(&iop->
dir, pin);
323 setbits32(&iop->
par, pin);
325 clrbits32(&iop->
par, pin);
336 setbits32(&iop->
sor, pin);
338 clrbits32(&iop->
sor, pin);
347 static void cpm1_set_pin16(
int port,
int pin,
int flags)
352 pin = 1 << (15 - pin);
357 if (flags & CPM_PIN_OUTPUT)
358 setbits16(&iop->
dir, pin);
360 clrbits16(&iop->
dir, pin);
362 if (!(flags & CPM_PIN_GPIO))
363 setbits16(&iop->
par, pin);
365 clrbits16(&iop->
par, pin);
384 cpm1_set_pin32(port, pin, flags);
386 cpm1_set_pin16(port, pin, flags);
489 if (clk_map[i][0] == target && clk_map[i][1] == clock) {
490 bits = clk_map[
i][2];
521 #ifdef CONFIG_8xx_GPIO
523 struct cpm1_gpio16_chip {
524 struct of_mm_gpio_chip mm_gc;
531 static inline struct cpm1_gpio16_chip *
532 to_cpm1_gpio16_chip(
struct of_mm_gpio_chip *mm_gc)
534 return container_of(mm_gc,
struct cpm1_gpio16_chip, mm_gc);
537 static void cpm1_gpio16_save_regs(
struct of_mm_gpio_chip *mm_gc)
539 struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
545 static int cpm1_gpio16_get(
struct gpio_chip *
gc,
unsigned int gpio)
547 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
551 pin_mask = 1 << (15 -
gpio);
556 static void __cpm1_gpio16_set(
struct of_mm_gpio_chip *mm_gc,
u16 pin_mask,
559 struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
563 cpm1_gc->cpdata |= pin_mask;
565 cpm1_gc->cpdata &= ~pin_mask;
570 static void cpm1_gpio16_set(
struct gpio_chip *
gc,
unsigned int gpio,
int value)
572 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
573 struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
575 u16 pin_mask = 1 << (15 -
gpio);
579 __cpm1_gpio16_set(mm_gc, pin_mask, value);
581 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
584 static int cpm1_gpio16_dir_out(
struct gpio_chip *
gc,
unsigned int gpio,
int val)
586 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
587 struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
590 u16 pin_mask = 1 << (15 -
gpio);
594 setbits16(&iop->
dir, pin_mask);
595 __cpm1_gpio16_set(mm_gc, pin_mask, val);
597 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
602 static int cpm1_gpio16_dir_in(
struct gpio_chip *
gc,
unsigned int gpio)
604 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
605 struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
608 u16 pin_mask = 1 << (15 -
gpio);
612 clrbits16(&iop->
dir, pin_mask);
614 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
621 struct cpm1_gpio16_chip *cpm1_gc;
622 struct of_mm_gpio_chip *mm_gc;
623 struct gpio_chip *
gc;
625 cpm1_gc = kzalloc(
sizeof(*cpm1_gc),
GFP_KERNEL);
631 mm_gc = &cpm1_gc->mm_gc;
634 mm_gc->save_regs = cpm1_gpio16_save_regs;
636 gc->direction_input = cpm1_gpio16_dir_in;
637 gc->direction_output = cpm1_gpio16_dir_out;
638 gc->get = cpm1_gpio16_get;
639 gc->set = cpm1_gpio16_set;
644 struct cpm1_gpio32_chip {
645 struct of_mm_gpio_chip mm_gc;
652 static inline struct cpm1_gpio32_chip *
653 to_cpm1_gpio32_chip(
struct of_mm_gpio_chip *mm_gc)
655 return container_of(mm_gc,
struct cpm1_gpio32_chip, mm_gc);
658 static void cpm1_gpio32_save_regs(
struct of_mm_gpio_chip *mm_gc)
660 struct cpm1_gpio32_chip *cpm1_gc = to_cpm1_gpio32_chip(mm_gc);
666 static int cpm1_gpio32_get(
struct gpio_chip *gc,
unsigned int gpio)
668 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
672 pin_mask = 1 << (31 -
gpio);
677 static void __cpm1_gpio32_set(
struct of_mm_gpio_chip *mm_gc,
u32 pin_mask,
680 struct cpm1_gpio32_chip *cpm1_gc = to_cpm1_gpio32_chip(mm_gc);
684 cpm1_gc->cpdata |= pin_mask;
686 cpm1_gc->cpdata &= ~pin_mask;
691 static void cpm1_gpio32_set(
struct gpio_chip *gc,
unsigned int gpio,
int value)
693 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
694 struct cpm1_gpio32_chip *cpm1_gc = to_cpm1_gpio32_chip(mm_gc);
696 u32 pin_mask = 1 << (31 -
gpio);
700 __cpm1_gpio32_set(mm_gc, pin_mask, value);
702 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
705 static int cpm1_gpio32_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
707 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
708 struct cpm1_gpio32_chip *cpm1_gc = to_cpm1_gpio32_chip(mm_gc);
711 u32 pin_mask = 1 << (31 -
gpio);
715 setbits32(&iop->
dir, pin_mask);
716 __cpm1_gpio32_set(mm_gc, pin_mask, val);
718 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
723 static int cpm1_gpio32_dir_in(
struct gpio_chip *gc,
unsigned int gpio)
725 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
726 struct cpm1_gpio32_chip *cpm1_gc = to_cpm1_gpio32_chip(mm_gc);
729 u32 pin_mask = 1 << (31 -
gpio);
733 clrbits32(&iop->
dir, pin_mask);
735 spin_unlock_irqrestore(&cpm1_gc->lock, flags);
742 struct cpm1_gpio32_chip *cpm1_gc;
743 struct of_mm_gpio_chip *mm_gc;
744 struct gpio_chip *gc;
746 cpm1_gc = kzalloc(
sizeof(*cpm1_gc),
GFP_KERNEL);
752 mm_gc = &cpm1_gc->mm_gc;
755 mm_gc->save_regs = cpm1_gpio32_save_regs;
757 gc->direction_input = cpm1_gpio32_dir_in;
758 gc->direction_output = cpm1_gpio32_dir_out;
759 gc->get = cpm1_gpio32_get;
760 gc->set = cpm1_gpio32_set;
765 static int cpm_init_par_io(
void)
769 for_each_compatible_node(np,
NULL,
"fsl,cpm1-pario-bank-a")
770 cpm1_gpiochip_add16(np);
772 for_each_compatible_node(np,
NULL, "fsl,cpm1-pario-bank-
b")
773 cpm1_gpiochip_add32(np);
775 for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-
c")
776 cpm1_gpiochip_add16(np);
778 for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-d")
779 cpm1_gpiochip_add16(np);
782 for_each_compatible_node(np, NULL, "fsl,cpm1-pario-bank-
e")