int xenon_smc_ana_write(uint8_t addr, uint32_t val) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = 0x60; buf[3] = 0x80 | 0x70; buf[6] = addr; buf[8] = val; buf[9] = val >> 8; buf[10] = val >> 16; buf[11] = val >> 24; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_ana_write failed, addr=%02x, err=%d\n", addr, buf[1]); return -1; } return 0; }
int xenon_smc_i2c_write(uint16_t addr, uint8_t val) { uint8_t buf[16]; memset(buf, 0, 16); int tmp=(addr>=0x200)?0x3d:0x39; int ddc=(addr>=0x1d0 && addr<=0x1f5); buf[0] = 0x11; buf[1] = (ddc)?0x21:0x20; buf[3] = tmp | 0x80; //3d buf[6] = addr & 0xff; //3a buf[7] = val; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_write failed, addr=%04x, err=%d\n", addr, buf[1]); return -1; } return 0; }
void xenon_sound_init(void) { // reset DAC (init from scratch) xenon_gpio_control(5,0x1000,0x1000); xenon_gpio_control(0,0x1000,0x1000); xenon_gpio_control(4,0x1000,0x1000); if(xenos_is_hdmi){ // HDMI audio enable xenon_smc_i2c_write(0x0214, 0x11); xenon_smc_i2c_write(0x0202, 0x03); xenon_smc_i2c_write(0x0203, 0x00); xenon_smc_i2c_write(0x0204, 0x18); xenon_smc_i2c_write(0x0205, 0x00); xenon_smc_i2c_write(0x021d, 0x40); xenon_smc_i2c_write(0x0221, 0x02); xenon_smc_i2c_write(0x0222, 0x2b); xenon_smc_i2c_write(0x022f,0x01); xenon_smc_i2c_write(0x023e,0x3f); xenon_smc_i2c_write(0x02df,0x10);// Av mute ? } static unsigned char smc_snd[32] = {0x8d, 1, 1}; xenon_smc_send_message(smc_snd); uint32_t *descr = memalign(256, 0x20 * 8); int descr_base = ((int)descr) & 0x1FFFFFFF; buffer_len = 64*1024; buffer = memalign(256, buffer_len); memset(buffer, 0, buffer_len); memdcbst(buffer, buffer_len); int buffer_base = ((int)buffer) & 0x1fffffff; int i; for (i = 0; i < 0x20; ++i) { descr[i * 2] = __builtin_bswap32(buffer_base + (buffer_len/0x20) * i); descr[i * 2 + 1] = __builtin_bswap32(0x80000000 | (buffer_len/0x20)); } memdcbst(descr, 0x20 * 2 * 4); write32(snd_base + 8, 0); write32(snd_base + 8, 0x2000000); write32(snd_base + 0, descr_base); write32(snd_base + 8, 0x1d08001c); write32(snd_base + 0xC, 0x1c); // write32(snd_base + 8, read32(snd_base) | 0x1000000); wptr = 0; }
int gettimeofday(struct timeval * tp, void * tzp) { unsigned char msg[16] = {0x04}; unsigned long long msec; unsigned long sec; xenon_smc_send_message(msg); xenon_smc_receive_response(msg); msec = msg[1] | (msg[2] << 8) | (msg[3] << 16) | (msg[4] << 24) | ((unsigned long long) msg[5] << 32); sec = msec / 1000; tp->tv_sec = sec + RTC_BASE; msec -= sec * 1000; tp->tv_usec = msec * 1000; return 0; }
int xenon_smc_i2c_ddc_lock(int lock) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = (lock)?3:5; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_ddc_lock failed, err=%d\n", buf[1]); return -1; } return 0; }
int main(){ printf("Xenos/console init!"); mainInit(); uint8_t msg[16]; while(1) { memset(msg, 0, 16); msg[0] = 0x16; xenon_smc_send_message(msg); f_xenon_smc_receive_response(msg); } return 0; }
static int xenon_gettimeofday(struct _reent *ptr, struct timeval *tp, struct timezone *tz) { unsigned char msg[16] = {0x04}; union{ uint8_t u8[8]; uint64_t t; } time; time.t = 0; xenon_smc_send_message(msg); xenon_smc_receive_response(msg); time.u8[3] = msg[5]; time.u8[4] = msg[4]; time.u8[5] = msg[3]; time.u8[6] = msg[2]; time.u8[7] = msg[1]; tp->tv_sec = (time.t / 1000) + RTC_BASE; tp->tv_usec = (time.t % 1000) * 1000; return 0; }
int xenon_smc_ana_read(uint8_t addr, uint32_t *val) { uint8_t buf[16]; memset(buf, 0, 16); buf[0] = 0x11; buf[1] = 0x10; buf[2] = 5; buf[3] = 0x80 | 0x70; buf[5] = 0xF0; buf[6] = addr; xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_ana_read failed, addr=%02x, err=%d\n", addr, buf[1]); return -1; } *val = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24); return 0; }
int xenon_smc_i2c_read(uint16_t addr, uint8_t *val) { uint8_t buf[16]; memset(buf, 0, 16); int tmp=(addr>=0x200)?0x3d:0x39; int ddc=(addr>=0x1d0 && addr<=0x1f5); buf[0] = 0x11; //40 buf[1] = (ddc)?0x11:0x10;//3f buf[2] = 1; //3e buf[3] = buf[5] = tmp | 0x80; //3d 3b buf[6] = addr & 0xff; //3a xenon_smc_send_message(buf); xenon_smc_receive_response(buf); if (buf[1] != 0) { printf("xenon_smc_i2c_read failed, addr=%04x, err=%d\n", addr, buf[1]); return -1; } *val = buf[3]; return 0; }