Changeset 1587

Show
Ignore:
Timestamp:
06/26/09 06:32:57 (15 years ago)
Author:
jwoithe
Message:

RME: add functions to erase and program device flash.
RME: add stub for function to send software configuration to device flash.
RME: minor source formatting fixups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/rme/fireface_def.h

    r1586 r1587  
    101101#define RME_FF800_FLASH_ERASE_CONFIG_REG    0x3fffffffcLL 
    102102 
    103 /* Flags and special values */ 
     103/* Flash erase command values for the FF400 */ 
    104104#define RME_FF400_FLASH_CMD_WRITE           0x00000001 
    105105#define RME_FF400_FLASH_CMD_READ            0x00000002 
     
    109109#define RME_FF400_FLASH_CMD_GET_REVISION    0x0000000f 
    110110 
     111/* Flags for use with erase_flash() */ 
     112#define RME_FF_FLASH_ERASE_VOLUME           1 
     113#define RME_FF_FLASH_ERASE_SETTINGS         2 
     114#define RME_FF_FLASH_ERASE_CONFIG           3 
    111115 
    112116/* Defines for components of the control registers */ 
  • trunk/libffado/src/rme/fireface_flash.cpp

    r1543 r1587  
    8282    // Read "n_quads" quadlets from the Fireface Flash starting at address 
    8383    // addr.  The result is written to "buf" which is assumed big enough to 
    84     // hold the result.  Return 0 on success, -1 on error. 
     84    // hold the result.  Return 0 on success, -1 on error.  The caller must ensure 
     85    // that the flash source address makes sense for the device in use. 
    8586 
    8687    unsigned int xfer_size; 
     
    102103        err |= writeRegister(RME_FF400_FLASH_CMD_REG, RME_FF400_FLASH_CMD_READ); 
    103104        if (!err) 
    104           wait_while_busy(2); 
     105            wait_while_busy(2); 
    105106        // Read from bounce buffer into final destination 
    106107        err |= readBlock(RME_FF400_FLASH_READ_BUFFER, buf, xfer_size); 
     
    114115} 
    115116 
     117signed int 
     118Device::erase_flash(unsigned int flags) 
     119{ 
     120    // Erase the requested flash block.  "flags" should be one of the  
     121    // RME_FF_FLASH_ERASE_* flags.  Return 0 on success, -1 on error. 
     122 
     123    fb_nodeaddr_t addr; 
     124    quadlet_t data; 
     125    unsigned int err = 0; 
     126 
     127    if (m_rme_model == RME_MODEL_FIREFACE800) { 
     128        switch (flags) { 
     129            case RME_FF_FLASH_ERASE_VOLUME: 
     130                addr = RME_FF800_FLASH_ERASE_VOLUME_REG; break; 
     131            case RME_FF_FLASH_ERASE_SETTINGS: 
     132                addr = RME_FF800_FLASH_ERASE_SETTINGS_REG; break; 
     133            case RME_FF_FLASH_ERASE_CONFIG: 
     134                addr = RME_FF800_FLASH_ERASE_CONFIG_REG; break; 
     135            default: 
     136                debugOutput(DEBUG_LEVEL_WARNING, "unknown flag %d\n", flags); 
     137                return -1; 
     138        } 
     139        data = 0; 
     140    } else { 
     141        addr = RME_FF400_FLASH_CMD_REG; 
     142        switch (flags) { 
     143            case RME_FF_FLASH_ERASE_VOLUME: 
     144                data = RME_FF400_FLASH_CMD_ERASE_VOLUME; break; 
     145            case RME_FF_FLASH_ERASE_SETTINGS: 
     146                data = RME_FF400_FLASH_CMD_ERASE_SETTINGS; break; 
     147            case RME_FF_FLASH_ERASE_CONFIG: 
     148                data = RME_FF400_FLASH_CMD_ERASE_CONFIG; break; 
     149            default: 
     150                debugOutput(DEBUG_LEVEL_WARNING, "unknown flag %d\n", flags); 
     151                return -1; 
     152        } 
     153    } 
     154 
     155    err |= writeRegister(addr, data); 
     156    if (!err) { 
     157        wait_while_busy(500); 
     158        // After the device is ready, wait a further 20 milliseconds.  The purpose 
     159        // of this is unclear.  Drivers from other OSes do it, so we should too. 
     160        usleep(20000); 
     161    } 
     162 
     163    return err?-1:0; 
     164} 
     165 
     166signed int  
     167Device::write_flash(fb_nodeaddr_t addr, quadlet_t *buf, unsigned int n_quads) 
     168{ 
     169    // Write "n_quads" quadlets to the Fireface Flash starting at address 
     170    // addr.  Return 0 on success, -1 on error.  The caller must ensure the 
     171    // supplied address is appropriate for the device in use. 
     172 
     173    unsigned int xfer_size; 
     174    unsigned int err = 0; 
     175    quadlet_t block_desc[2]; 
     176    quadlet_t ff400_addr = (addr & 0xffffffff); 
     177 
     178    if (m_rme_model == RME_MODEL_FIREFACE800) { 
     179        err |= readBlock(addr, buf, n_quads); 
     180        if (!err) 
     181            wait_while_busy(5); 
     182    } 
     183    // FF400 case follows 
     184    do { 
     185        xfer_size = (n_quads > 32)?32:n_quads; 
     186        // Send data to flash buffer 
     187        err |= writeBlock(RME_FF400_FLASH_WRITE_BUFFER, buf, xfer_size); 
     188        // Program the destination address and size 
     189        block_desc[0] = ff400_addr; 
     190        block_desc[1] = xfer_size * sizeof(quadlet_t); 
     191        err |= writeBlock(RME_FF400_FLASH_BLOCK_ADDR_REG, block_desc, 2); 
     192        // Execute the write and wait for its completion 
     193        err |= writeRegister(RME_FF400_FLASH_CMD_REG, RME_FF400_FLASH_CMD_WRITE); 
     194        if (!err) 
     195            wait_while_busy(2); 
     196 
     197        n_quads -= xfer_size; 
     198        ff400_addr += xfer_size*sizeof(quadlet_t); 
     199        buf += xfer_size; 
     200    } while (n_quads>0 && !err); 
     201 
     202    return err?-1:0; 
     203} 
     204 
     205 
    116206signed int  
    117207Device::read_device_settings(void)  
    118208{ 
     209    // Read the device's configuration flash RAM and use this to set up  
     210    // the object's "settings" data member field. 
     211 
    119212    FF_device_flash_settings_t hw_settings; 
    120213    signed int i; 
    121214    unsigned int rev; 
     215 
     216    // FIXME: this is mostly for testing at present.  Still need to interface from 
     217    // hw_settings to the object's "settings" field. 
    122218 
    123219    i = get_revision(&rev); 
     
    179275} 
    180276 
    181 
     277signed int  
     278Device::write_device_settings(void)  
     279
     280    // Write the current settings as held in the "settings" data member to 
     281    // the device configuration flash. 
     282 
     283    // FIXME: fairly obviously the detail needs to be filled in here. 
     284    return 0; 
     285
     286 
     287
  • trunk/libffado/src/rme/fireface_hw.cpp

    r1586 r1587  
    202202} 
    203203 
    204 signed int Device::read_tco(quadlet_t *tco_data, signed int size) 
     204signed int  
     205Device::read_tco(quadlet_t *tco_data, signed int size) 
    205206{ 
    206207    // Read the TCO registers and return the respective values in *tco_data.  
     
    236237} 
    237238 
    238 signed int Device::write_tco(quadlet_t *tco_data, signed int size) 
     239signed int  
     240Device::write_tco(quadlet_t *tco_data, signed int size) 
    239241{ 
    240242    // Writes data to the TCO.  No check is made as to whether a TCO is 
     
    258260} 
    259261 
    260 signed int Device::read_tco_state(FF_TCO_state_t *tco_state) 
     262signed int  
     263Device::read_tco_state(FF_TCO_state_t *tco_state) 
    261264{ 
    262265    // Reads the current TCO state into the supplied state structure 
     
    318321} 
    319322 
    320 signed int Device::write_tco_settings(FF_TCO_settings_t *tco_settings) 
     323signed int  
     324Device::write_tco_settings(FF_TCO_settings_t *tco_settings) 
    321325{ 
    322326    // Writes the supplied application-level settings to the device's TCO 
  • trunk/libffado/src/rme/rme_avdevice.h

    r1586 r1587  
    110110    signed int get_revision(unsigned int *revision); 
    111111    signed int read_flash(fb_nodeaddr_t addr, quadlet_t *buf, unsigned int n_quads); 
     112    signed int erase_flash(unsigned int flags); 
     113    signed int write_flash(fb_nodeaddr_t addr, quadlet_t *buf, unsigned int n_quads); 
    112114 
    113115    /* Upper level flash memory functions */ 
    114116    signed int read_device_settings(void); 
     117    signed int write_device_settings(void); 
    115118 
    116119    /* Hardware functions */