int crisv32_pinmux_init(void) { static int initialized; if (!initialized) { initialized = 1; REG_WR_INT(pinmux, regi_pinmux, rw_hwprot, 0); crisv32_pinmux_alloc(PORT_A, 0, 31, pinmux_gpio); crisv32_pinmux_alloc(PORT_B, 0, 31, pinmux_gpio); crisv32_pinmux_alloc(PORT_C, 0, 15, pinmux_gpio); } return 0; }
int crisv32_io_get_name(struct crisv32_iopin *iopin, const char *name) { int port; int pin; if (toupper(*name) == 'P') name++; if (toupper(*name) < 'A' || toupper(*name) > 'E') return -EINVAL; port = toupper(*name) - 'A'; name++; pin = simple_strtoul(name, NULL, 10); if (pin < 0 || pin > crisv32_ioports[port].pin_count) return -EINVAL; iopin->bit = 1 << pin; iopin->port = &crisv32_ioports[port]; if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio)) return -EIO; return 0; }
int crisv32_pinmux_init(void) { static int initialized; if (!initialized) { reg_pinmux_rw_pa pa = REG_RD(pinmux, regi_pinmux, rw_pa); initialized = 1; REG_WR_INT(pinmux, regi_pinmux, rw_hwprot, 0); pa.pa0 = pa.pa1 = pa.pa2 = pa.pa3 = pa.pa4 = pa.pa5 = pa.pa6 = pa.pa7 = regk_pinmux_yes; REG_WR(pinmux, regi_pinmux, rw_pa, pa); crisv32_pinmux_alloc(PORT_B, 0, PORT_PINS - 1, pinmux_gpio); crisv32_pinmux_alloc(PORT_C, 0, PORT_PINS - 1, pinmux_gpio); crisv32_pinmux_alloc(PORT_D, 0, PORT_PINS - 1, pinmux_gpio); crisv32_pinmux_alloc(PORT_E, 0, PORT_PINS - 1, pinmux_gpio); } return 0; }
int crisv32_io_get(struct crisv32_iopin *iopin, unsigned int port, unsigned int pin) { if (port > NBR_OF_PORTS) return -EINVAL; if (port > crisv32_ioports[port].pin_count) return -EINVAL; iopin->bit = 1 << pin; iopin->port = &crisv32_ioports[port]; if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio)) return -EIO; return 0; }
int crisv32_pinmux_alloc_fixed(enum fixed_function function) { int ret = -EINVAL; char saved[sizeof pins]; unsigned long flags; spin_lock_irqsave(&pinmux_lock, flags); /* Save internal data for recovery */ memcpy(saved, pins, sizeof pins); crisv32_pinmux_init(); /* Must be done before we read rw_hwprot */ reg_pinmux_rw_hwprot hwprot = REG_RD(pinmux, regi_pinmux, rw_hwprot); switch (function) { case pinmux_ser1: ret = crisv32_pinmux_alloc(PORT_C, 4, 7, pinmux_fixed); hwprot.ser1 = regk_pinmux_yes; break; case pinmux_ser2: ret = crisv32_pinmux_alloc(PORT_C, 8, 11, pinmux_fixed); hwprot.ser2 = regk_pinmux_yes; break; case pinmux_ser3: ret = crisv32_pinmux_alloc(PORT_C, 12, 15, pinmux_fixed); hwprot.ser3 = regk_pinmux_yes; break; case pinmux_sser0: ret = crisv32_pinmux_alloc(PORT_C, 0, 3, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_C, 16, 16, pinmux_fixed); hwprot.sser0 = regk_pinmux_yes; break; case pinmux_sser1: ret = crisv32_pinmux_alloc(PORT_D, 0, 4, pinmux_fixed); hwprot.sser1 = regk_pinmux_yes; break; case pinmux_ata0: ret = crisv32_pinmux_alloc(PORT_D, 5, 7, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_D, 15, 17, pinmux_fixed); hwprot.ata0 = regk_pinmux_yes; break; case pinmux_ata1: ret = crisv32_pinmux_alloc(PORT_D, 0, 4, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_E, 17, 17, pinmux_fixed); hwprot.ata1 = regk_pinmux_yes; break; case pinmux_ata2: ret = crisv32_pinmux_alloc(PORT_C, 11, 15, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_E, 3, 3, pinmux_fixed); hwprot.ata2 = regk_pinmux_yes; break; case pinmux_ata3: ret = crisv32_pinmux_alloc(PORT_C, 8, 10, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_C, 0, 2, pinmux_fixed); hwprot.ata2 = regk_pinmux_yes; break; case pinmux_ata: ret = crisv32_pinmux_alloc(PORT_B, 0, 15, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_D, 8, 15, pinmux_fixed); hwprot.ata = regk_pinmux_yes; break; case pinmux_eth1: ret = crisv32_pinmux_alloc(PORT_E, 0, 17, pinmux_fixed); hwprot.eth1 = regk_pinmux_yes; hwprot.eth1_mgm = regk_pinmux_yes; break; case pinmux_timer: ret = crisv32_pinmux_alloc(PORT_C, 16, 16, pinmux_fixed); hwprot.timer = regk_pinmux_yes; spin_unlock_irqrestore(&pinmux_lock, flags); return ret; } if (!ret) REG_WR(pinmux, regi_pinmux, rw_hwprot, hwprot); else memcpy(pins, saved, sizeof pins); spin_unlock_irqrestore(&pinmux_lock, flags); return ret; }
int crisv32_pinmux_alloc_fixed(enum fixed_function function) { int ret = -EINVAL; char saved[sizeof pins]; unsigned long flags; spin_lock_irqsave(&pinmux_lock, flags); /* Save internal data for recovery */ memcpy(saved, pins, sizeof pins); crisv32_pinmux_init(); /* must be done before we read rw_hwprot */ reg_pinmux_rw_hwprot hwprot = REG_RD(pinmux, regi_pinmux, rw_hwprot); reg_clkgen_rw_clk_ctrl clk_ctrl = REG_RD(clkgen, regi_clkgen, rw_clk_ctrl); switch (function) { case pinmux_eth: clk_ctrl.eth = regk_clkgen_yes; clk_ctrl.dma0_1_eth = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_B, 8, 23, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_B, 24, 25, pinmux_fixed); hwprot.eth = hwprot.eth_mdio = regk_pinmux_yes; break; case pinmux_geth: ret = crisv32_pinmux_alloc(PORT_B, 0, 7, pinmux_fixed); hwprot.geth = regk_pinmux_yes; break; case pinmux_tg_cmos: clk_ctrl.ccd_tg_100 = clk_ctrl.ccd_tg_200 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_B, 27, 29, pinmux_fixed); hwprot.tg_clk = regk_pinmux_yes; break; case pinmux_tg_ccd: clk_ctrl.ccd_tg_100 = clk_ctrl.ccd_tg_200 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_B, 27, 31, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_C, 0, 15, pinmux_fixed); hwprot.tg = hwprot.tg_clk = regk_pinmux_yes; break; case pinmux_vout: clk_ctrl.strdma0_2_video = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 8, 18, pinmux_fixed); hwprot.vout = hwprot.vout_sync = regk_pinmux_yes; break; case pinmux_ser1: clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 24, 25, pinmux_fixed); hwprot.ser1 = regk_pinmux_yes; break; case pinmux_ser2: clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 26, 27, pinmux_fixed); hwprot.ser2 = regk_pinmux_yes; break; case pinmux_ser3: clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 28, 29, pinmux_fixed); hwprot.ser3 = regk_pinmux_yes; break; case pinmux_ser4: clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 30, 31, pinmux_fixed); hwprot.ser4 = regk_pinmux_yes; break; case pinmux_sser: clk_ctrl.sser_ser_dma6_7 = regk_clkgen_yes; ret = crisv32_pinmux_alloc(PORT_A, 19, 23, pinmux_fixed); hwprot.sser = regk_pinmux_yes; break; case pinmux_pio: hwprot.pio = regk_pinmux_yes; ret = 0; break; case pinmux_pwm0: ret = crisv32_pinmux_alloc(PORT_A, 30, 30, pinmux_fixed); hwprot.pwm0 = regk_pinmux_yes; break; case pinmux_pwm1: ret = crisv32_pinmux_alloc(PORT_A, 31, 31, pinmux_fixed); hwprot.pwm1 = regk_pinmux_yes; break; case pinmux_pwm2: ret = crisv32_pinmux_alloc(PORT_B, 26, 26, pinmux_fixed); hwprot.pwm2 = regk_pinmux_yes; break; case pinmux_i2c0: ret = crisv32_pinmux_alloc(PORT_A, 0, 1, pinmux_fixed); hwprot.i2c0 = regk_pinmux_yes; break; case pinmux_i2c1: ret = crisv32_pinmux_alloc(PORT_A, 2, 3, pinmux_fixed); hwprot.i2c1 = regk_pinmux_yes; break; case pinmux_i2c1_3wire: ret = crisv32_pinmux_alloc(PORT_A, 2, 3, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_A, 7, 7, pinmux_fixed); hwprot.i2c1 = hwprot.i2c1_sen = regk_pinmux_yes; break; case pinmux_i2c1_sda1: ret = crisv32_pinmux_alloc(PORT_A, 2, 4, pinmux_fixed); hwprot.i2c1 = hwprot.i2c1_sda1 = regk_pinmux_yes; break; case pinmux_i2c1_sda2: ret = crisv32_pinmux_alloc(PORT_A, 2, 3, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_A, 5, 5, pinmux_fixed); hwprot.i2c1 = hwprot.i2c1_sda2 = regk_pinmux_yes; break; case pinmux_i2c1_sda3: ret = crisv32_pinmux_alloc(PORT_A, 2, 3, pinmux_fixed); ret |= crisv32_pinmux_alloc(PORT_A, 6, 6, pinmux_fixed); hwprot.i2c1 = hwprot.i2c1_sda3 = regk_pinmux_yes; break; default: ret = -EINVAL; break; } if (!ret) { REG_WR(pinmux, regi_pinmux, rw_hwprot, hwprot); REG_WR(clkgen, regi_clkgen, rw_clk_ctrl, clk_ctrl); } else memcpy(pins, saved, sizeof pins); spin_unlock_irqrestore(&pinmux_lock, flags); return ret; }