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

bscbus.c (1919B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 #ifdef INCLUDE_I2C
      9 
     10 #include <sal/types.h>
     11 #include <soc/debug.h>
     12 #include <soc/error.h>
     13 #include <soc/drv.h>
     14 #include <soc/cm.h>
     15 #include <soc/i2c.h>
     16 #include <soc/bsc.h>
     17 
     18 #define TEST_DATA	0xfe
     19 
     20 /*
     21  * Function: soc_bsc_attach
     22  *
     23  * Purpose: I2C Bus attach routine, main entry point for I2C startup.
     24  * Initialize the I2C controller configuration for the specified
     25  * device.
     26  *
     27  * Parameters:
     28  *    unit - device number
     29  *
     30  * Returns:
     31  *	SOC_E_* if negative
     32  *	count of found devices if positive or zero
     33  *
     34  * Notes: Default is Interrupt mode, if both are selected Interrupt is
     35  *       chosen.
     36  */
     37 int
     38 soc_bsc_attach(int unit)
     39 {
     40 	soc_bsc_bus_t *bscbus;
     41 
     42 	bscbus = BSCBUS(unit);
     43 	if (bscbus == NULL) {
     44 		bscbus = sal_alloc(sizeof(*bscbus), "bsc_bus");
     45 		if (bscbus == NULL) {
     46 			return SOC_E_MEMORY;
     47 		}
     48 		SOC_CONTROL(unit)->bsc_bus = bscbus;
     49 		sal_memset(bscbus, 0, sizeof(*bscbus));
     50 	}
     51 
     52 	/* If not yet done, create synchronization semaphores/mutex */
     53 	if (bscbus->bsc_mutex == NULL) {
     54 		bscbus->bsc_mutex = sal_mutex_create("BSC Mutex");
     55 		if (bscbus->bsc_mutex == NULL) {
     56 			return SOC_E_MEMORY;
     57 		}
     58 	}
     59 
     60 	/* Set semaphore timeout values */
     61 	bscbus->flags = SOC_BSC_ATTACHED;
     62 
     63 	/*
     64 	 * Probe for BSC devices, update device list for detected devices ...
     65 	 */
     66 	return soc_bsc_probe(unit);
     67 }
     68 
     69 /*
     70  * Function: soc_bsc_detach
     71  *
     72  * Purpose: BSC detach routine: free resources used by BSC bus driver.
     73  *
     74  * Paremeters:
     75  *    unit - device number
     76  * Returns:
     77  *    SOC_E_NONE - no error
     78  * Notes:
     79  *    none
     80  */
     81 int
     82 soc_bsc_detach(int unit)
     83 {
     84 	soc_bsc_bus_t *bscbus = BSCBUS(unit);
     85 
     86 	if (bscbus != NULL) {
     87 		sal_free(bscbus);
     88 		SOC_CONTROL(unit)->bsc_bus = NULL;
     89 	}
     90 
     91 	return SOC_E_NONE;
     92 }
     93 #endif /* INCLUDE_I2C */