Annotation of funnyos/arch/sam7s64/dev/sapio.c, Revision 1.1
1.1 ! nbrk 1: /*
! 2: * $Id$
! 3: */
! 4: #include <sys/types.h>
! 5: #include <sys/device.h>
! 6: #include <sys/bus.h>
! 7: #include <sys/gpio.h>
! 8:
! 9: #include <arch/sam7s64/dev/sapioreg.h>
! 10: #include <arch/sam7s64/dev/sapiovar.h>
! 11:
! 12: /*
! 13: * Parallel Input Output controller.
! 14: */
! 15:
! 16: int sapio_attach(struct device *, uint32_t, uint8_t);
! 17: uint8_t sapio_pinread(void *selfdd, uint32_t pin);
! 18: void sapio_pinwrite(void *selfdd, uint32_t pin, uint8_t data);
! 19: void sapio_pinset(void *selfdd, struct gpio_pin pin);
! 20: struct gpio_pin sapio_pinget(void *selfdd, uint32_t pin);
! 21:
! 22:
! 23: struct driver sapio_dr = {
! 24: sizeof(struct sapio_dd),
! 25: sapio_attach,
! 26: NULL,
! 27: NULL
! 28: };
! 29:
! 30:
! 31: int
! 32: sapio_attach(struct device *self, uint32_t loc, uint8_t flags)
! 33: {
! 34: struct sapio_dd *ddp = self->dv_devdata;
! 35: struct gpio_controller *gcp = &ddp->pio_gc;
! 36:
! 37: /* acquire bus_handle from parent */
! 38: ddp->pio_bhp = self->dv_parent->dv_aux;
! 39:
! 40: /* save our location on parent (or use default if loc == 0) */
! 41: ddp->pio_ioaddr = (loc != 0) ? loc : SAPIO_BASE;
! 42:
! 43: gcp->gc_pinread = sapio_pinread;
! 44: gcp->gc_pinwrite = sapio_pinwrite;
! 45: gcp->gc_pinset = sapio_pinset;
! 46: gcp->gc_pinget = sapio_pinget;
! 47: gcp->gc_npins = SAPIO_NPINS;
! 48: gcp->gc_selfdd = ddp;
! 49:
! 50: /* export gpio_controller */
! 51: self->dv_aux = gcp;
! 52:
! 53: printf("SAM7 Parallel Input/Output controller, %d pins\n", SAPIO_NPINS);
! 54:
! 55: return(0);
! 56: }
! 57:
! 58:
! 59: uint8_t
! 60: sapio_pinread(void *selfdd, uint32_t pin)
! 61: {
! 62: /* TODO */
! 63: return(0);
! 64: }
! 65:
! 66:
! 67: void
! 68: sapio_pinwrite(void *selfdd, uint32_t pin, uint8_t data)
! 69: {
! 70: /* TODO */
! 71: }
! 72:
! 73:
! 74: void
! 75: sapio_pinset(void *selfdd, struct gpio_pin pin)
! 76: {
! 77: struct sapio_dd *sdd = (struct sapio_dd *)selfdd;
! 78: /*
! 79: * Configure pin.
! 80: */
! 81:
! 82: /* see if this i/o line is correct for us */
! 83: if (sdd->pio_gc.gc_npins < (pin.gp_pinno + 1)) {
! 84: /* out of range */
! 85: printf("sapio_pinset: WARNING: pin no. %d doesn't present on this controller\n", pin.gp_pinno);
! 86:
! 87: return;
! 88: }
! 89:
! 90: /* PIO or Periph. ? */
! 91: if (pin.gp_pio == 0)
! 92: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_PDR, 1 << pin.gp_pinno);
! 93: else
! 94: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_PER, 1 << pin.gp_pinno);
! 95:
! 96: /* flags */
! 97: if (pin.gp_flags & GPIO_PIN_OUTPUT)
! 98: /* enable output */
! 99: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_OER, 1 << pin.gp_pinno);
! 100: else
! 101: /* disable output */
! 102: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_ODR, 1 << pin.gp_pinno);
! 103:
! 104: /* data */
! 105: if (pin.gp_value == 1)
! 106: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_SODR, 1 << pin.gp_pinno);
! 107: else
! 108: bus_write_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_CODR, 1 << pin.gp_pinno);
! 109: }
! 110:
! 111:
! 112: struct gpio_pin
! 113: sapio_pinget(void *selfdd, uint32_t pin)
! 114: {
! 115: struct gpio_pin gp;
! 116: struct sapio_dd *sdd = (struct sapio_dd *)selfdd;
! 117: /*
! 118: * Get pin configuration.
! 119: */
! 120:
! 121: gp.gp_pinno = pin;
! 122:
! 123: /* see if this pin belongs to Peripherals (0) or to PIO (1) */
! 124: gp.gp_pio = bus_read_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_PSR) & (1 << pin);
! 125:
! 126: /* get state through Output Status Register */
! 127: gp.gp_flags = (bus_read_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_OSR) & (1 << pin)) ?
! 128: GPIO_PIN_INPUT | GPIO_PIN_OUTPUT : GPIO_PIN_INPUT; /* XXX how to determine input flag? */
! 129:
! 130: /* read value in Pin Data Status Register */
! 131: gp.gp_value = bus_read_4(sdd->pio_bhp, sdd->pio_ioaddr + SAPIO_PIO_PDSR) & (1 << pin);
! 132:
! 133: return(gp);
! 134: }
! 135:
CVSweb