168 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * For License see notice in hfc_multi.c4 *5 * special IO and init functions for the embedded XHFC board6 * from Speech Design7 *8 */9 10#include <asm/cpm1.h>11 12/* Change this to the value used by your board */13#ifndef IMAP_ADDR14#define IMAP_ADDR 0xFFF0000015#endif16 17static void18#ifdef HFC_REGISTER_DEBUG19HFC_outb_embsd(struct hfc_multi *hc, u_char reg, u_char val,20 const char *function, int line)21#else22 HFC_outb_embsd(struct hfc_multi *hc, u_char reg, u_char val)23#endif24{25 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;26 writeb(reg, hc->xhfc_memaddr);27 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);28 writeb(val, hc->xhfc_memdata);29}30static u_char31#ifdef HFC_REGISTER_DEBUG32HFC_inb_embsd(struct hfc_multi *hc, u_char reg, const char *function, int line)33#else34 HFC_inb_embsd(struct hfc_multi *hc, u_char reg)35#endif36{37 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;38 writeb(reg, hc->xhfc_memaddr);39 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);40 return readb(hc->xhfc_memdata);41}42static u_short43#ifdef HFC_REGISTER_DEBUG44HFC_inw_embsd(struct hfc_multi *hc, u_char reg, const char *function, int line)45#else46 HFC_inw_embsd(struct hfc_multi *hc, u_char reg)47#endif48{49 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;50 writeb(reg, hc->xhfc_memaddr);51 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);52 return readb(hc->xhfc_memdata);53}54static void55#ifdef HFC_REGISTER_DEBUG56HFC_wait_embsd(struct hfc_multi *hc, const char *function, int line)57#else58 HFC_wait_embsd(struct hfc_multi *hc)59#endif60{61 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;62 writeb(R_STATUS, hc->xhfc_memaddr);63 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);64 while (readb(hc->xhfc_memdata) & V_BUSY)65 cpu_relax();66}67 68/* write fifo data (EMBSD) */69void70write_fifo_embsd(struct hfc_multi *hc, u_char *data, int len)71{72 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;73 *hc->xhfc_memaddr = A_FIFO_DATA0;74 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);75 while (len) {76 *hc->xhfc_memdata = *data;77 data++;78 len--;79 }80}81 82/* read fifo data (EMBSD) */83void84read_fifo_embsd(struct hfc_multi *hc, u_char *data, int len)85{86 hc->immap->im_ioport.iop_padat |= PA_XHFC_A0;87 *hc->xhfc_memaddr = A_FIFO_DATA0;88 hc->immap->im_ioport.iop_padat &= ~(PA_XHFC_A0);89 while (len) {90 *data = (u_char)(*hc->xhfc_memdata);91 data++;92 len--;93 }94}95 96static int97setup_embedded(struct hfc_multi *hc, struct hm_map *m)98{99 printk(KERN_INFO100 "HFC-multi: card manufacturer: '%s' card name: '%s' clock: %s\n",101 m->vendor_name, m->card_name, m->clock2 ? "double" : "normal");102 103 hc->pci_dev = NULL;104 if (m->clock2)105 test_and_set_bit(HFC_CHIP_CLOCK2, &hc->chip);106 107 hc->leds = m->leds;108 hc->ledstate = 0xAFFEAFFE;109 hc->opticalsupport = m->opticalsupport;110 111 hc->pci_iobase = 0;112 hc->pci_membase = 0;113 hc->xhfc_membase = NULL;114 hc->xhfc_memaddr = NULL;115 hc->xhfc_memdata = NULL;116 117 /* set memory access methods */118 if (m->io_mode) /* use mode from card config */119 hc->io_mode = m->io_mode;120 switch (hc->io_mode) {121 case HFC_IO_MODE_EMBSD:122 test_and_set_bit(HFC_CHIP_EMBSD, &hc->chip);123 hc->slots = 128; /* required */124 hc->HFC_outb = HFC_outb_embsd;125 hc->HFC_inb = HFC_inb_embsd;126 hc->HFC_inw = HFC_inw_embsd;127 hc->HFC_wait = HFC_wait_embsd;128 hc->read_fifo = read_fifo_embsd;129 hc->write_fifo = write_fifo_embsd;130 hc->xhfc_origmembase = XHFC_MEMBASE + XHFC_OFFSET * hc->id;131 hc->xhfc_membase = (u_char *)ioremap(hc->xhfc_origmembase,132 XHFC_MEMSIZE);133 if (!hc->xhfc_membase) {134 printk(KERN_WARNING135 "HFC-multi: failed to remap xhfc address space. "136 "(internal error)\n");137 return -EIO;138 }139 hc->xhfc_memaddr = (u_long *)(hc->xhfc_membase + 4);140 hc->xhfc_memdata = (u_long *)(hc->xhfc_membase);141 printk(KERN_INFO142 "HFC-multi: xhfc_membase:%#lx xhfc_origmembase:%#lx "143 "xhfc_memaddr:%#lx xhfc_memdata:%#lx\n",144 (u_long)hc->xhfc_membase, hc->xhfc_origmembase,145 (u_long)hc->xhfc_memaddr, (u_long)hc->xhfc_memdata);146 break;147 default:148 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");149 return -EIO;150 }151 152 /* Prepare the MPC8XX PortA 10 as output (address/data selector) */153 hc->immap = (struct immap *)(IMAP_ADDR);154 hc->immap->im_ioport.iop_papar &= ~(PA_XHFC_A0);155 hc->immap->im_ioport.iop_paodr &= ~(PA_XHFC_A0);156 hc->immap->im_ioport.iop_padir |= PA_XHFC_A0;157 158 /* Prepare the MPC8xx PortB __X__ as input (ISDN__X__IRQ) */159 hc->pb_irqmsk = (PB_XHFC_IRQ1 << hc->id);160 hc->immap->im_cpm.cp_pbpar &= ~(hc->pb_irqmsk);161 hc->immap->im_cpm.cp_pbodr &= ~(hc->pb_irqmsk);162 hc->immap->im_cpm.cp_pbdir &= ~(hc->pb_irqmsk);163 164 /* At this point the needed config is done */165 /* fifos are still not enabled */166 return 0;167}168