@@ -1499,6 +1499,7 @@ static int cdns_i3c_do_daa(const struct device *dev)
1499
1499
struct cdns_i3c_data * data = dev -> data ;
1500
1500
const struct cdns_i3c_config * config = dev -> config ;
1501
1501
struct i3c_config_controller * ctrl_config = & data -> common .ctrl_config ;
1502
+ uint8_t last_addr = 0 ;
1502
1503
1503
1504
/* DAA should not be done by secondary controllers */
1504
1505
if (ctrl_config -> is_secondary ) {
@@ -1510,6 +1511,23 @@ static int cdns_i3c_do_daa(const struct device *dev)
1510
1511
/* ignore the controller register */
1511
1512
olddevs |= BIT (0 );
1512
1513
1514
+ /* Assign dynamic addressses to available RRs */
1515
+ /* Loop through each clear bit */
1516
+ for (uint8_t i = find_lsb_set (~olddevs ); i <= data -> max_devs ; i ++ ) {
1517
+ uint8_t rr_idx = i - 1 ;
1518
+
1519
+ if (~olddevs & BIT (rr_idx )) {
1520
+ /* Read RRx registers */
1521
+ last_addr = i3c_addr_slots_next_free_find (
1522
+ & data -> common .attached_dev .addr_slots , last_addr + 1 );
1523
+ /* Write RRx registers */
1524
+ sys_write32 (prepare_rr0_dev_address (last_addr ) | DEV_ID_RR0_IS_I3C ,
1525
+ config -> base + DEV_ID_RR0 (rr_idx ));
1526
+ sys_write32 (0 , config -> base + DEV_ID_RR1 (rr_idx ));
1527
+ sys_write32 (0 , config -> base + DEV_ID_RR2 (rr_idx ));
1528
+ }
1529
+ }
1530
+
1513
1531
/* the Cadence I3C IP will assign an address for it from the RR */
1514
1532
struct i3c_ccc_payload entdaa_ccc ;
1515
1533
@@ -1915,7 +1933,10 @@ static int cdns_i3c_master_get_rr_slot(const struct device *dev, uint8_t dyn_add
1915
1933
{
1916
1934
struct cdns_i3c_data * data = dev -> data ;
1917
1935
const struct cdns_i3c_config * config = dev -> config ;
1936
+ uint8_t rr_idx , i ;
1937
+ uint32_t rr , activedevs ;
1918
1938
1939
+ /* If it does not have a dynamic address, then assign it a free one */
1919
1940
if (dyn_addr == 0 ) {
1920
1941
if (!data -> free_rr_slots ) {
1921
1942
return - ENOSPC ;
@@ -1924,62 +1945,70 @@ static int cdns_i3c_master_get_rr_slot(const struct device *dev, uint8_t dyn_add
1924
1945
return find_lsb_set (data -> free_rr_slots ) - 1 ;
1925
1946
}
1926
1947
1927
- uint32_t activedevs = sys_read32 (config -> base + DEVS_CTRL ) & DEVS_CTRL_DEVS_ACTIVE_MASK ;
1928
-
1948
+ /* Device already has a Dynamic Address, so assume it is already in the RRs */
1949
+ activedevs = sys_read32 (config -> base + DEVS_CTRL ) & DEVS_CTRL_DEVS_ACTIVE_MASK ;
1950
+ /* skip itself */
1929
1951
activedevs &= ~BIT (0 );
1930
1952
1931
1953
/* loop through each set bit for new devices */
1932
- for (uint8_t i = find_lsb_set (activedevs ); i <= find_msb_set (activedevs ); i ++ ) {
1933
- if ( activedevs & BIT ( i )) {
1934
- uint32_t rr = sys_read32 ( config -> base + DEV_ID_RR0 ( i ));
1935
-
1936
- if (! (rr & DEV_ID_RR0_IS_I3C ) || DEV_ID_RR0_GET_DEV_ADDR (rr ) ! = dyn_addr ) {
1937
- continue ;
1954
+ for (i = find_lsb_set (activedevs ); i <= find_msb_set (activedevs ); i ++ ) {
1955
+ rr_idx = i - 1 ;
1956
+ if ( activedevs & BIT ( rr_idx )) {
1957
+ rr = sys_read32 ( config -> base + DEV_ID_RR0 ( rr_idx ));
1958
+ if ((rr & DEV_ID_RR0_IS_I3C ) && DEV_ID_RR0_GET_DEV_ADDR (rr ) = = dyn_addr ) {
1959
+ return rr_idx ;
1938
1960
}
1939
- return i ;
1940
1961
}
1941
1962
}
1942
1963
1943
1964
return - EINVAL ;
1944
1965
}
1945
1966
1946
- static int cdns_i3c_attach_device (const struct device * dev , struct i3c_device_desc * desc ,
1947
- uint8_t addr )
1967
+ static int cdns_i3c_attach_device (const struct device * dev , struct i3c_device_desc * desc )
1948
1968
{
1949
- const struct cdns_i3c_config * config = dev -> config ;
1950
- struct cdns_i3c_data * data = dev -> data ;
1951
- int slot = cdns_i3c_master_get_rr_slot (dev , desc -> dynamic_addr );
1952
-
1953
- if (slot < 0 ) {
1954
- LOG_ERR ("%s: no space for i3c device: %s" , dev -> name , desc -> dev -> name );
1955
- return slot ;
1956
- }
1969
+ /*
1970
+ * Mark Devices as active, devices that will be found and marked active during DAA,
1971
+ * it will be given the exact DA programmed in it's RR, otherwise they get set as active
1972
+ * here. If dynamic address is set, then it assumed that it was already initialized by the
1973
+ * primary controller. When assigned through ENTDAA, the dynamic address, bcr, dcr, and pid
1974
+ * are all set in the RR along with setting the device as active. If it has a static addr,
1975
+ * then it is assumed that it will be programmed with SETDASA and will need to be marked
1976
+ * as active before sending out SETDASA.
1977
+ */
1978
+ if ((desc -> static_addr != 0 ) || (desc -> dynamic_addr != 0 )) {
1979
+ const struct cdns_i3c_config * config = dev -> config ;
1980
+ struct cdns_i3c_data * data = dev -> data ;
1957
1981
1958
- k_mutex_lock (& data -> bus_lock , K_FOREVER );
1982
+ int slot = cdns_i3c_master_get_rr_slot (dev , desc -> dynamic_addr ? desc -> dynamic_addr
1983
+ : desc -> static_addr );
1959
1984
1960
- data -> cdns_i3c_i2c_priv_data [slot ].id = slot ;
1961
- desc -> controller_priv = & (data -> cdns_i3c_i2c_priv_data [slot ]);
1962
- data -> free_rr_slots &= ~BIT (slot );
1963
-
1964
- uint32_t dev_id_rr0 = DEV_ID_RR0_IS_I3C | prepare_rr0_dev_address (addr );
1965
- uint32_t dev_id_rr1 = DEV_ID_RR1_PID_MSB ((desc -> pid & 0xFFFFFFFF0000 ) >> 16 );
1966
- uint32_t dev_id_rr2 = DEV_ID_RR2_PID_LSB (desc -> pid & 0xFFFF );
1985
+ if (slot < 0 ) {
1986
+ LOG_ERR ("%s: no space for i3c device: %s" , dev -> name , desc -> dev -> name );
1987
+ return slot ;
1988
+ }
1967
1989
1968
- sys_write32 (dev_id_rr0 , config -> base + DEV_ID_RR0 (slot ));
1969
- sys_write32 (dev_id_rr1 , config -> base + DEV_ID_RR1 (slot ));
1970
- sys_write32 (dev_id_rr2 , config -> base + DEV_ID_RR2 (slot ));
1990
+ k_mutex_lock (& data -> bus_lock , K_FOREVER );
1971
1991
1972
- /** Mark Devices as active, devices that will be found and marked active during DAA,
1973
- * it will be given the exact DA programmed in it's RR if the PID matches and marked
1974
- * as active duing ENTDAA, otherwise they get set as active here. If dynamic address
1975
- * is set, then it assumed that it was already initialized by the primary controller.
1976
- */
1977
- if ((desc -> static_addr != 0 ) || (desc -> dynamic_addr != 0 )) {
1978
1992
sys_write32 (sys_read32 (config -> base + DEVS_CTRL ) | DEVS_CTRL_DEV_ACTIVE (slot ),
1979
1993
config -> base + DEVS_CTRL );
1980
- }
1981
1994
1982
- k_mutex_unlock (& data -> bus_lock );
1995
+ data -> cdns_i3c_i2c_priv_data [slot ].id = slot ;
1996
+ desc -> controller_priv = & (data -> cdns_i3c_i2c_priv_data [slot ]);
1997
+ data -> free_rr_slots &= ~BIT (slot );
1998
+
1999
+ uint32_t dev_id_rr0 =
2000
+ DEV_ID_RR0_IS_I3C |
2001
+ prepare_rr0_dev_address (desc -> dynamic_addr ? desc -> dynamic_addr
2002
+ : desc -> static_addr );
2003
+ uint32_t dev_id_rr1 = DEV_ID_RR1_PID_MSB ((desc -> pid & 0xFFFFFFFF0000 ) >> 16 );
2004
+ uint32_t dev_id_rr2 = DEV_ID_RR2_PID_LSB (desc -> pid & 0xFFFF );
2005
+
2006
+ sys_write32 (dev_id_rr0 , config -> base + DEV_ID_RR0 (slot ));
2007
+ sys_write32 (dev_id_rr1 , config -> base + DEV_ID_RR1 (slot ));
2008
+ sys_write32 (dev_id_rr2 , config -> base + DEV_ID_RR2 (slot ));
2009
+
2010
+ k_mutex_unlock (& data -> bus_lock );
2011
+ }
1983
2012
1984
2013
return 0 ;
1985
2014
}
0 commit comments