openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

quadra28_reg_access.c (3419B)


      1 /*
      2  *
      3  * 
      4  *
      5  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      6  * 
      7  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      8  */
      9 
     10 /*
     11  * Includes
     12  */
     13 #include <phymod/phymod_acc.h>
     14 #include <phymod/phymod_reg.h>
     15 
     16 /*
     17  *  Defines
     18  */
     19 
     20 /**   Read Register
     21  *    This function is used to read the register content of given
     22  *    register address
     23  *
     24  *    @param pa                 Pointer to phymod access structure
     25  *    @param addr               Register address supplied by user
     26  *    @param data               Regiser content/value of the given register
     27  *
     28  *    @return ioerr             Error return
     29  *                              0 - Success
     30  *                              any other value - Error
     31  */
     32 int phymod_raw_iblk_read(const phymod_access_t *pa, uint32_t reg_addr, uint32_t *data)
     33 {
     34     int ioerr = 0;
     35     uint32_t reg_val = 0;
     36     int32_t dev_add = ((reg_addr>>16) & 0x1f);
     37 
     38     if (pa == NULL) {
     39         PHYMOD_RETURN_WITH_ERR(PHYMOD_E_PARAM, (_PHYMOD_MSG("NULL parameter")));
     40     }
     41     if (dev_add == 0) {
     42         ioerr = PHYMOD_BUS_READ(pa, ((1<<16) | reg_addr), &reg_val);
     43     } else {
     44         ioerr = PHYMOD_BUS_READ(pa, reg_addr, &reg_val);
     45     }
     46     *data = reg_val;
     47     return ioerr;
     48 }
     49 
     50 
     51 /**   Write Register
     52  *    This function is used to write the content to given register
     53  *
     54  *    @param pa                 Pointer to phymod access structure
     55  *    @param addr               Register address supplied by user
     56  *    @param data               Regiser content/value to be written to register
     57  *
     58  *    @return ioerr             Error return
     59  *                              0 - Success
     60  *                              any other value - Error
     61  */
     62 int phymod_raw_iblk_write(const phymod_access_t *pa, uint32_t addr, uint32_t data)
     63 {
     64 
     65     int ioerr = 0;
     66     int32_t dev_add = ((addr>>16) & 0x1f);
     67     if (pa == NULL) {
     68         PHYMOD_RETURN_WITH_ERR(PHYMOD_E_PARAM, (_PHYMOD_MSG("NULL parameter")));
     69     }
     70     data &= 0xffff;
     71     if (dev_add == 0) {
     72         ioerr = PHYMOD_BUS_WRITE(pa, ((1<<16) | addr), data);
     73     } else {
     74         ioerr = PHYMOD_BUS_WRITE(pa, addr, data);
     75     }
     76 
     77     return ioerr;
     78 }
     79 
     80 
     81 /**   Modify Register
     82  *    This function is used to modify the content without overwriting it
     83  *
     84  *    @param pa                 Pointer to phymod access structure
     85  *    @param addr               Register address supplied by user
     86  *    @param reg_data           Regiser data for modified portion
     87  *    @param reg_mask           Register mask for the data bits to be modified
     88  *
     89  *    @return ioerr             Error return
     90  *                              0 - Success
     91  *                              any other value - Error
     92  */
     93 int quadra28_reg_modify(const phymod_access_t *pa,
     94                      uint32_t addr,
     95                      uint16_t reg_data,
     96                      uint16_t reg_mask)
     97 {
     98 
     99     int ioerr = 0;
    100 	uint16_t tmp, otmp;
    101 	uint32_t reg_val;
    102    
    103     if (pa == NULL) {
    104         PHYMOD_RETURN_WITH_ERR(PHYMOD_E_PARAM, (_PHYMOD_MSG("NULL parameter")));
    105     }
    106 
    107     reg_data = reg_data & reg_mask;
    108 
    109     /* Use clause 45 access if supported */
    110     ioerr += PHYMOD_BUS_READ(pa, addr, &reg_val);
    111         
    112     tmp = (uint16_t) (reg_val & 0xffff);
    113     otmp = tmp;
    114     tmp &= ~(reg_mask);
    115     tmp |= reg_data;
    116     if (otmp != tmp) {
    117         ioerr += PHYMOD_BUS_WRITE(pa, addr, tmp);
    118     }	
    119     return ioerr;
    120 
    121 
    122 }