Browse Source

add raspi3 mbox option

bigmagic 5 years ago
parent
commit
2099924e20
2 changed files with 464 additions and 1 deletions
  1. 401 0
      bsp/raspberry-pi/raspi3-64/driver/mbox.c
  2. 63 1
      bsp/raspberry-pi/raspi3-64/driver/mbox.h

+ 401 - 0
bsp/raspberry-pi/raspi3-64/driver/mbox.c

@@ -47,3 +47,404 @@ int mbox_call(unsigned char ch, int mmu_enable)
     }
     }
     return 0;
     return 0;
 }
 }
+
+int bcm283x_mbox_hardware_get_model(void)
+{
+    mbox[0] = 8*4;                          // length of the message
+    mbox[1] = MBOX_REQUEST;                 // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_MODEL;
+    mbox[3] = 4;                            // buffer size
+    mbox[4] = 0;                            // len
+
+    mbox[5] = 0;                            
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    return mbox[5];
+}
+
+int bcm283x_mbox_hardware_get_revison(void)
+{
+    mbox[0] = 8*4;                          // length of the message
+    mbox[1] = MBOX_REQUEST;                 // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_REV;   
+    mbox[3] = 4;                            // buffer size
+    mbox[4] = 0;                            // len
+
+    mbox[5] = 0;                    
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    return mbox[5];
+}
+
+int bcm283x_mbox_hardware_get_mac_address(uint8_t * mac)
+{
+    mbox[0] = 8*4;                                 // length of the message
+    mbox[1] = MBOX_REQUEST;                        // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_MAC_ADDRESS;   
+    mbox[3] = 6;                                   // buffer size
+    mbox[4] = 0;                                   // len
+
+    mbox[5] = 0;                    
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    char * mac_str = (char *)&mbox[5];
+    mac[0] = mac_str[0];
+    mac[1] = mac_str[1];
+    mac[2] = mac_str[2];
+    mac[3] = mac_str[3];
+    mac[4] = mac_str[4];
+    mac[5] = mac_str[5];
+    return 0;
+}
+
+
+int bcm283x_mbox_hardware_get_serial(rt_uint64_t* sn)
+{
+    mbox[0] = 8*4;                              // length of the message
+    mbox[1] = MBOX_REQUEST;                     // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_SERIAL;    
+    mbox[3] = 8;                                // buffer size
+    mbox[4] = 0;                                // len
+
+    mbox[5] = 0;                    
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    sn = (rt_uint64_t *)&mbox[5];
+
+    return 0;
+}
+
+int bcm283x_mbox_hardware_get_arm_memory(rt_uint32_t * base, rt_uint32_t * size)
+{
+    mbox[0] = 8*4;                                  // length of the message
+    mbox[1] = MBOX_REQUEST;                         // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_ARM_MEMORY;   
+    mbox[3] = 8;                                    // buffer size
+    mbox[4] = 0;                                    // len
+
+    mbox[5] = 0;                    
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    *base = mbox[5];
+    *size = mbox[6];
+    
+    return 0;
+
+}
+
+int bcm283x_mbox_hardware_get_vc_memory(rt_uint32_t * base, rt_uint32_t * size)
+{
+    mbox[0] = 8*4;                               // length of the message
+    mbox[1] = MBOX_REQUEST;                      // this is a request message
+    
+    mbox[2] = MBOX_TAG_HARDWARE_GET_VC_MEMORY;
+    mbox[3] = 8;                                 // buffer size
+    mbox[4] = 0;                                 // len
+
+    mbox[5] = 0;                    
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    *base = mbox[5];
+    *size = mbox[6];
+    
+    return 0;
+}
+
+int bcm283x_mbox_clock_get_turbo(void)
+{
+    mbox[0] = 8*4;                      // length of the message
+    mbox[1] = MBOX_REQUEST;             // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_GET_TURBO; 
+    mbox[3] = 8;                        // buffer size
+    mbox[4] = 4;                        // len
+
+    mbox[5] = 0;                        // id
+    mbox[6] = 0;                        // val
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != 0)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_clock_set_turbo(int level)
+{
+    mbox[0] = 8*4;                      // length of the message
+    mbox[1] = MBOX_REQUEST;             // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_SET_TURBO;  
+    mbox[3] = 8;                        // buffer size
+    mbox[4] = 8;                        // len
+
+    mbox[5] = 0;                        // id
+    mbox[6] = level ? 1 : 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != 0)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_clock_get_state(int id)
+{
+    mbox[0] = 8*4;                       // length of the message
+    mbox[1] = MBOX_REQUEST;              // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_GET_STATE;
+    mbox[3] = 8;                         // buffer size
+    mbox[4] = 4;                         // len
+
+    mbox[5] = id;                        // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return (mbox[6] & 0x3);
+}
+
+int bcm283x_mbox_clock_set_state(int id, int state)
+{
+    mbox[0] = 8*4;                      // length of the message
+    mbox[1] = MBOX_REQUEST;             // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_SET_STATE;
+    mbox[3] = 8;                        // buffer size
+    mbox[4] = 8;                        // len
+
+    mbox[5] = id;                       // id
+    mbox[6] = state & 0x3;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return (mbox[6] & 0x3);
+}
+
+int bcm283x_mbox_clock_get_rate(int id)
+{
+    mbox[0] = 8*4;                      // length of the message
+    mbox[1] = MBOX_REQUEST;             // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_GET_RATE; 
+    mbox[3] = 8;                        // buffer size
+    mbox[4] = 4;                        // len
+
+    mbox[5] = id;                       // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_clock_set_rate(int id, int rate)
+{
+    mbox[0] = 8*4;                      // length of the message
+    mbox[1] = MBOX_REQUEST;             // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_SET_RATE;
+    mbox[3] = 8;                        // buffer size
+    mbox[4] = 8;                        // len
+
+    mbox[5] = id;                       // id
+    mbox[6] = rate;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_clock_get_max_rate(int id)
+{
+    mbox[0] = 8*4;                          // length of the message
+    mbox[1] = MBOX_REQUEST;                 // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_GET_MAX_RATE;
+    mbox[3] = 8;                            // buffer size
+    mbox[4] = 4;                            // len
+
+    mbox[5] = id;                           // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_clock_get_min_rate(int id)
+{
+    mbox[0] = 8*4;                          // length of the message
+    mbox[1] = MBOX_REQUEST;                 // this is a request message
+    
+    mbox[2] = MBOX_TAG_CLOCK_GET_MIN_RATE; 
+    mbox[3] = 8;                            // buffer size
+    mbox[4] = 4;                            // len
+
+    mbox[5] = id;                           // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_power_get_state(int id)
+{
+    mbox[0] = 8*4;                  // length of the message
+    mbox[1] = MBOX_REQUEST;         // this is a request message
+    
+    mbox[2] = MBOX_TAG_POWER_GET_STATE;
+    mbox[3] = 8;                    // buffer size
+    mbox[4] = 4;                    // len
+
+    mbox[5] = id;                   // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return (mbox[6] & 0x3);
+}
+
+int bcm283x_mbox_power_set_state(int id, int state)
+{
+    mbox[0] = 8*4;                  // length of the message
+    mbox[1] = MBOX_REQUEST;         // this is a request message
+    
+    mbox[2] = MBOX_TAG_POWER_SET_STATE;
+    mbox[3] = 8;                    // buffer size
+    mbox[4] = 8;                    // len
+
+    mbox[5] = id;                    // id
+    mbox[6] = state & 0x3;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != id)
+    {
+        return -1;
+    }
+
+    return (mbox[6] & 0x3);
+}
+
+int bcm283x_mbox_temp_get(void)
+{
+    mbox[0] = 8*4;                  // length of the message
+    mbox[1] = MBOX_REQUEST;         // this is a request message
+    
+    mbox[2] = MBOX_TAG_TEMP_GET;
+    mbox[3] = 8;                    // buffer size
+    mbox[4] = 4;                    // len
+
+    mbox[5] = 0;                    //id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != 0)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}
+
+int bcm283x_mbox_temp_get_max(void)
+{
+    mbox[0] = 8*4;                  // length of the message
+    mbox[1] = MBOX_REQUEST;         // this is a request message
+    
+    mbox[2] = MBOX_TAG_TEMP_GET_MAX;
+    mbox[3] = 8;                    // buffer size
+    mbox[4] = 4;                    // len
+
+    mbox[5] = 0;                    // id
+    mbox[6] = 0;
+
+    mbox[7] = MBOX_TAG_LAST;
+    mbox_call(8, MMU_DISABLE);
+
+    if(mbox[5] != 0)
+    {
+        return -1;
+    }
+
+    return mbox[6];
+}

+ 63 - 1
bsp/raspberry-pi/raspi3-64/driver/mbox.h

@@ -12,7 +12,7 @@
 #ifndef __MBOX_H__
 #ifndef __MBOX_H__
 #define __MBOX_H__
 #define __MBOX_H__
 
 
-
+#include <rtthread.h>
 /* a properly aligned buffer */
 /* a properly aligned buffer */
 extern volatile unsigned int* mbox;
 extern volatile unsigned int* mbox;
 
 
@@ -56,7 +56,69 @@ extern volatile unsigned int* mbox;
 #define MMU_ENABLE 1
 #define MMU_ENABLE 1
 #define MMU_DISABLE 0
 #define MMU_DISABLE 0
 
 
+/*
+ * raspi hardware info
+ */
+enum {
+    MBOX_TAG_HARDWARE_GET_MODEL         = 0x00010001,
+    MBOX_TAG_HARDWARE_GET_REV           = 0x00010002,
+    MBOX_TAG_HARDWARE_GET_MAC_ADDRESS   = 0x00010003,
+    MBOX_TAG_HARDWARE_GET_SERIAL        = 0x00010004,
+    MBOX_TAG_HARDWARE_GET_ARM_MEMORY    = 0x00010005,
+    MBOX_TAG_HARDWARE_GET_VC_MEMORY     = 0x00010006,
+    MBOX_TAG_HARDWARE_GET_CLOCKS        = 0x00010007,
+};
+
+/*
+ * raspi clock
+ */
+enum {
+    MBOX_TAG_CLOCK_GET_TURBO    = 0x00030009,
+    MBOX_TAG_CLOCK_SET_TURBO    = 0x00038009,
+    MBOX_TAG_CLOCK_GET_STATE    = 0x00030001,
+    MBOX_TAG_CLOCK_SET_STATE    = 0x00038001,
+    MBOX_TAG_CLOCK_GET_RATE     = 0x00030002,
+    MBOX_TAG_CLOCK_SET_RATE     = 0x00038002,
+    MBOX_TAG_CLOCK_GET_MAX_RATE = 0x00030004,
+    MBOX_TAG_CLOCK_GET_MIN_RATE = 0x00030007,
+};
+
+/*
+ * raspi power
+ */
+enum {
+    MBOX_TAG_POWER_GET_STATE    = 0x00020001,
+    MBOX_TAG_POWER_SET_STATE    = 0x00028001,
+};
+
+/*
+ * raspi temperature
+ */
+enum {
+    MBOX_TAG_TEMP_GET       = 0x00030006,
+    MBOX_TAG_TEMP_GET_MAX   = 0x0003000A,
+};
+
 #define MBOX_ADDR 0xc00000
 #define MBOX_ADDR 0xc00000
 
 
 int mbox_call(unsigned char ch, int mmu_enable);
 int mbox_call(unsigned char ch, int mmu_enable);
+int bcm283x_mbox_hardware_get_model(void);
+int bcm283x_mbox_hardware_get_revison(void);
+int bcm283x_mbox_hardware_get_mac_address(uint8_t * mac);
+int bcm283x_mbox_hardware_get_serial(rt_uint64_t* sn);
+int bcm283x_mbox_hardware_get_arm_memory(rt_uint32_t * base, rt_uint32_t * size);
+int bcm283x_mbox_hardware_get_vc_memory(rt_uint32_t * base, rt_uint32_t * size);
+int bcm283x_mbox_clock_get_turbo(void);
+int bcm283x_mbox_clock_set_turbo(int level);
+int bcm283x_mbox_clock_get_state(int id);
+int bcm283x_mbox_clock_set_state(int id, int state);
+int bcm283x_mbox_clock_get_rate(int id);
+int bcm283x_mbox_clock_set_rate(int id, int rate);
+int bcm283x_mbox_clock_get_max_rate(int id);
+int bcm283x_mbox_clock_get_min_rate(int id);
+int bcm283x_mbox_power_get_state(int id);
+int bcm283x_mbox_power_set_state(int id, int state);
+int bcm283x_mbox_temp_get(void);
+int bcm283x_mbox_temp_get_max(void);
+
 #endif
 #endif