30 #define SOURCEFILE_NAME "hpi6205.c"
41 #define HPI6205_ERROR_BASE 1000
44 #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
45 #define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
48 #define HPI6205_ERROR_6205_NO_IRQ 1002
49 #define HPI6205_ERROR_6205_INIT_FAILED 1003
50 #define HPI6205_ERROR_6205_REG 1006
51 #define HPI6205_ERROR_6205_DSPPAGE 1007
52 #define HPI6205_ERROR_C6713_HPIC 1009
53 #define HPI6205_ERROR_C6713_HPIA 1010
54 #define HPI6205_ERROR_C6713_PLL 1011
55 #define HPI6205_ERROR_DSP_INTMEM 1012
56 #define HPI6205_ERROR_DSP_EXTMEM 1013
57 #define HPI6205_ERROR_DSP_PLD 1014
58 #define HPI6205_ERROR_6205_EEPROM 1017
59 #define HPI6205_ERROR_DSP_EMIF1 1018
60 #define HPI6205_ERROR_DSP_EMIF2 1019
61 #define HPI6205_ERROR_DSP_EMIF3 1020
62 #define HPI6205_ERROR_DSP_EMIF4 1021
67 #define C6205_HSR_INTSRC 0x01
68 #define C6205_HSR_INTAVAL 0x02
69 #define C6205_HSR_INTAM 0x04
70 #define C6205_HSR_CFGERR 0x08
71 #define C6205_HSR_EEREAD 0x10
73 #define C6205_HDCR_WARMRESET 0x01
74 #define C6205_HDCR_DSPINT 0x02
75 #define C6205_HDCR_PCIBOOT 0x04
78 #define C6205_DSPP_MAP1 0x400
86 #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
87 #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
88 #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
89 #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
92 #define C6205_BAR0_TIMER1_CTL (0x01980000L)
95 #define HPICL_ADDR 0x01400000L
96 #define HPICH_ADDR 0x01400004L
97 #define HPIAL_ADDR 0x01410000L
98 #define HPIAH_ADDR 0x01410004L
99 #define HPIDIL_ADDR 0x01420000L
100 #define HPIDIH_ADDR 0x01420004L
101 #define HPIDL_ADDR 0x01430000L
102 #define HPIDH_ADDR 0x01430004L
104 #define C6713_EMIF_GCTL 0x01800000
105 #define C6713_EMIF_CE1 0x01800004
106 #define C6713_EMIF_CE0 0x01800008
107 #define C6713_EMIF_CE2 0x01800010
108 #define C6713_EMIF_CE3 0x01800014
109 #define C6713_EMIF_SDRAMCTL 0x01800018
110 #define C6713_EMIF_SDRAMTIMING 0x0180001C
111 #define C6713_EMIF_SDRAMEXT 0x01800020
139 #define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
141 static int wait_dsp_ack(
struct hpi_hw_obj *phw,
int state,
int timeout_us);
143 static void send_dsp_command(
struct hpi_hw_obj *phw,
int cmd);
146 u32 *pos_error_code);
154 #define HPI6205_TIMEOUT 1000000
156 static void subsys_create_adapter(
struct hpi_message *phm,
162 u32 *pos_error_code);
166 static void outstream_host_buffer_allocate(
struct hpi_adapter_obj *pao,
169 static void outstream_host_buffer_get_info(
struct hpi_adapter_obj *pao,
234 subsys_create_adapter(phm, phr);
247 u16 pending_cache_error = 0;
256 pending_cache_error =
260 hw_message(pao, phm, phr);
261 if (pending_cache_error && !phr->
error)
262 phr->
error = pending_cache_error;
265 hw_message(pao, phm, phr);
268 hw_message(pao, phm, phr);
284 adapter_delete(pao, phm, phr);
288 hw_message(pao, phm, phr);
300 "Message referencing invalid stream %d "
308 outstream_write(pao, phm, phr);
311 outstream_get_info(pao, phm, phr);
314 outstream_host_buffer_allocate(pao, phm, phr);
317 outstream_host_buffer_get_info(pao, phm, phr);
320 outstream_host_buffer_free(pao, phm, phr);
323 outstream_start(pao, phm, phr);
326 outstream_open(pao, phm, phr);
329 outstream_reset(pao, phm, phr);
332 hw_message(pao, phm, phr);
344 "Message referencing invalid stream %d "
352 instream_read(pao, phm, phr);
355 instream_get_info(pao, phm, phr);
358 instream_host_buffer_allocate(pao, phm, phr);
361 instream_host_buffer_get_info(pao, phm, phr);
364 instream_host_buffer_free(pao, phm, phr);
367 instream_start(pao, phm, phr);
370 hw_message(pao, phm, phr);
402 subsys_message(pao, phm, phr);
406 adapter_message(pao, phm, phr);
410 control_message(pao, phm, phr);
414 outstream_message(pao, phm, phr);
418 instream_message(pao, phm, phr);
422 hw_message(pao, phm, phr);
442 _HPI_6205(
NULL, phm, phr);
447 _HPI_6205(pao, phm, phr);
461 static void subsys_create_adapter(
struct hpi_message *phm,
471 memset(&ao, 0,
sizeof(ao));
480 ao.pci = *phm->
u.
s.resource.r.pci;
481 err = create_adapter_obj(&ao, &os_error_code);
483 delete_adapter_obj(&ao);
490 phr->
u.
s.data = os_error_code;
494 phr->
u.
s.adapter_type = ao.type;
495 phr->
u.
s.adapter_index = ao.index;
516 delete_adapter_obj(pao);
541 pao->
pci.ap_mem_base[1] +
544 pao->
pci.ap_mem_base[1] +
547 pao->
pci.ap_mem_base[1] +
569 err = adapter_boot_load_dsp(pao, pos_error_code);
582 interface = phw->p_interface_buffer;
594 u8 *p_control_cache_virtual;
602 (
void *)&p_control_cache_virtual);
604 memset(p_control_cache_virtual, 0,
609 control_cache.number_of_controls,
611 p_control_cache_virtual);
618 h_control_cache, &phys_addr);
639 memset(&hm, 0,
sizeof(hm));
642 hm.size =
sizeof(hm);
646 memset(&hr, 0,
sizeof(hr));
647 hr.size =
sizeof(hr);
649 err = message_response_sequence(pao, &hm, &hr);
658 pao->
type = hr.u.ax.info.adapter_type;
659 pao->
index = hr.u.ax.info.adapter_index;
662 hr.u.ax.info.num_outstreams +
663 hr.u.ax.info.num_instreams;
666 "got adapter info type %x index %d serial %d\n",
667 hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
668 hr.u.ax.info.serial_number);
722 static void outstream_host_buffer_allocate(
struct hpi_adapter_obj *pao,
737 phm->
u.
d.u.buffer.buffer_size =
741 phr->
u.
d.u.stream_info.data_available =
743 phr->
u.
d.u.stream_info.buffer_size =
744 phm->
u.
d.u.buffer.buffer_size;
747 phm->
u.
d.u.buffer.buffer_size) {
769 &phm->
u.
d.u.buffer.pci_address);
774 phr->
u.
d.u.stream_info.auxiliary_data_available =
775 phm->
u.
d.u.buffer.pci_address;
793 if (phm->
u.
d.u.buffer.buffer_size & (phm->
u.
d.u.buffer.
796 "Buffer size must be 2^N not %d\n",
797 phm->
u.
d.u.buffer.buffer_size);
802 phm->
u.
d.u.buffer.buffer_size;
812 hw_message(pao, phm, phr);
816 outstream_host_buffers[phm->
obj_index])) {
824 static void outstream_host_buffer_get_info(
struct hpi_adapter_obj *pao,
836 (
void *)&p_bbm_data)) {
844 phr->
u.
d.u.hostbuffer_info.p_buffer = p_bbm_data;
845 phr->
u.
d.u.hostbuffer_info.p_status =
status;
857 u32 command = phm->
u.
d.u.buffer.command;
863 hw_message(pao, phm, phr);
895 hw_message(pao, phm, phr);
902 space_available = outstream_get_space_available(status);
903 if (space_available < phm->
u.d.u.data.data_size) {
910 if (phm->
u.
d.u.data.pb_data
915 u8 *p_app_data = (
u8 *)phm->
u.
d.u.data.pb_data;
919 (
void *)&p_bbm_data)) {
927 min(phm->
u.
d.u.data.data_size,
933 p_app_data, l_first_write);
935 memcpy(p_bbm_data, p_app_data + l_first_write,
936 phm->
u.
d.u.data.data_size - l_first_write);
950 hw_message(pao, phm, phr);
967 hw_message(pao, phm, phr);
976 phr->
u.
d.u.stream_info.samples_transferred =
979 phr->
u.
d.u.stream_info.data_available =
980 status->
size_in_bytes - outstream_get_space_available(status);
981 phr->
u.
d.u.stream_info.auxiliary_data_available =
988 hw_message(pao, phm, phr);
996 hw_message(pao, phm, phr);
1002 outstream_reset(pao, phm, phr);
1008 static void instream_host_buffer_allocate(
struct hpi_adapter_obj *pao,
1012 u32 command = phm->
u.
d.u.buffer.command;
1021 phm->
u.
d.u.buffer.buffer_size =
1023 phr->
u.
d.u.stream_info.data_available =
1025 phr->
u.
d.u.stream_info.buffer_size =
1026 phm->
u.
d.u.buffer.buffer_size;
1029 phm->
u.
d.u.buffer.buffer_size) {
1040 obj_index], phm->
u.
d.u.buffer.buffer_size,
1051 &phm->
u.
d.u.buffer.pci_address);
1054 phr->
u.
d.u.stream_info.auxiliary_data_available =
1055 phm->
u.
d.u.buffer.pci_address;
1069 if (phm->
u.
d.u.buffer.buffer_size & (phm->
u.
d.u.buffer.
1072 "Buffer size must be 2^N not %d\n",
1073 phm->
u.
d.u.buffer.buffer_size);
1079 phm->
u.
d.u.buffer.buffer_size;
1089 hw_message(pao, phm, phr);
1093 instream_host_buffers[phm->
obj_index])) {
1101 static void instream_host_buffer_get_info(
struct hpi_adapter_obj *pao,
1113 (
void *)&p_bbm_data)) {
1121 phr->
u.
d.u.hostbuffer_info.p_buffer = p_bbm_data;
1122 phr->
u.
d.u.hostbuffer_info.p_status =
status;
1134 u32 command = phm->
u.
d.u.buffer.command;
1140 hw_message(pao, phm, phr);
1161 hw_message(pao, phm, phr);
1178 u8 *p_app_data = (
u8 *)phm->
u.
d.u.data.pb_data;
1181 hw_message(pao, phm, phr);
1187 data_available = instream_get_bytes_available(status);
1188 if (data_available < phm->
u.d.u.data.data_size) {
1197 (
void *)&p_bbm_data)) {
1205 min(phm->
u.
d.u.data.data_size,
1214 memcpy(p_app_data + l_first_read, p_bbm_data,
1215 phm->
u.
d.u.data.data_size - l_first_read);
1227 hw_message(pao, phm, phr);
1236 phr->
u.
d.u.stream_info.samples_transferred =
1239 phr->
u.
d.u.stream_info.data_available =
1240 instream_get_bytes_available(status);
1241 phr->
u.
d.u.stream_info.auxiliary_data_available =
1247 #define HPI6205_MAX_FILES_TO_LOAD 2
1250 u32 *pos_error_code)
1261 boot_code_id[1] = pao->
pci.pci_dev->subsystem_device;
1265 switch (boot_code_id[1]) {
1267 boot_code_id[0] = boot_code_id[1];
1268 boot_code_id[1] = 0;
1331 if (boot_code_id[1] != 0) {
1334 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
1340 boot_loader_read_mem32(pao, 0, 0);
1350 if (boot_code_id[dsp] == 0)
1353 err = boot_loader_config_emif(pao, dsp);
1357 err = boot_loader_test_internal_memory(pao, dsp);
1361 err = boot_loader_test_external_memory(pao, dsp);
1365 err = boot_loader_test_pld(pao, dsp);
1371 &dsp_code, pos_error_code);
1384 if (length == 0xFFFFFFFF)
1397 for (i = 0; i < (
int)length; i++) {
1398 boot_loader_write_mem32(pao, dsp, address,
1403 boot_loader_read_mem32(pao, dsp,
1425 if (length == 0xFFFFFFFF)
1432 for (i = 0; i < (
int)length; i++) {
1433 data = boot_loader_read_mem32(pao, dsp,
1435 if (data != *pcode) {
1455 u32 physicalPC_iaddress;
1457 phw->p_interface_buffer;
1458 u32 host_mailbox_address_on_dsp;
1459 u32 physicalPC_iaddress_verify = 0;
1467 &physicalPC_iaddress);
1470 host_mailbox_address_on_dsp = 0x80000000;
1471 while ((physicalPC_iaddress != physicalPC_iaddress_verify)
1473 boot_loader_write_mem32(pao, 0,
1474 host_mailbox_address_on_dsp,
1475 physicalPC_iaddress);
1476 physicalPC_iaddress_verify =
1477 boot_loader_read_mem32(pao, 0,
1478 host_mailbox_address_on_dsp);
1508 if (dsp_index == 0) {
1510 if ((address >= 0x01800000) & (address < 0x02000000)) {
1512 p_data = pao->
pci.ap_mem_base[1] +
1513 (address & 0x007fffff) /
1514 sizeof(*pao->
pci.ap_mem_base[1]);
1518 u32 dw4M_page = address >> 22
L;
1525 address &= 0x3fffff;
1527 p_data = pao->
pci.ap_mem_base[0] +
1528 address /
sizeof(
u32);
1531 }
else if (dsp_index == 1) {
1534 boot_loader_write_mem32(pao, 0,
HPIAL_ADDR, address);
1535 boot_loader_write_mem32(pao, 0,
HPIAH_ADDR, address >> 16);
1536 lsb = boot_loader_read_mem32(pao, 0,
HPIDL_ADDR);
1537 data = boot_loader_read_mem32(pao, 0,
HPIDH_ADDR);
1538 data = (data << 16) | (lsb & 0xFFFF);
1544 int dsp_index,
u32 address,
u32 data)
1550 if (dsp_index == 0) {
1552 if ((address >= 0x01800000) & (address < 0x02000000)) {
1555 p_data = pao->
pci.ap_mem_base[1] +
1556 (address & 0x007fffff) /
1557 sizeof(*pao->
pci.ap_mem_base[1]);
1561 u32 dw4M_page = address >> 22
L;
1568 address &= 0x3fffff;
1569 p_data = pao->
pci.ap_mem_base[0] +
1570 address /
sizeof(
u32);
1573 }
else if (dsp_index == 1) {
1575 boot_loader_write_mem32(pao, 0,
HPIAL_ADDR, address);
1576 boot_loader_write_mem32(pao, 0,
HPIAH_ADDR, address >> 16);
1579 boot_loader_read_mem32(pao, 0, 0);
1581 boot_loader_write_mem32(pao, 0,
HPIDL_ADDR, data);
1582 boot_loader_write_mem32(pao, 0,
HPIDH_ADDR, data >> 16);
1585 boot_loader_read_mem32(pao, 0, 0);
1591 if (dsp_index == 0) {
1604 boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
1614 setting = 0x00000030;
1615 boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
1616 if (setting != boot_loader_read_mem32(pao, dsp_index,
1626 (1L << RS_OFS) | (63
L <<
RST_OFS) | (1L << RH_OFS) |
1628 boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
1629 if (setting != boot_loader_read_mem32(pao, dsp_index,
1638 (1L << RS_OFS) | (63
L <<
RST_OFS) | (1L << RH_OFS) |
1640 boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
1641 if (setting != boot_loader_read_mem32(pao, dsp_index,
1649 (1L << RS_OFS) | (10
L <<
RST_OFS) | (1L << RH_OFS) |
1651 boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
1652 if (setting != boot_loader_read_mem32(pao, dsp_index,
1658 boot_loader_write_mem32(pao, dsp_index, 0x01800018,
1663 boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
1666 }
else if (dsp_index == 1) {
1668 u32 write_data = 0, read_data = 0, i = 0;
1672 boot_loader_write_mem32(pao, 0,
HPICL_ADDR, write_data);
1673 boot_loader_write_mem32(pao, 0,
HPICH_ADDR, write_data);
1676 0xFFF7 & boot_loader_read_mem32(pao, 0,
HPICL_ADDR);
1677 if (write_data != read_data) {
1684 for (i = 0; i < 32; i++) {
1688 (write_data >> 16));
1690 0xFFFF & boot_loader_read_mem32(pao, 0,
1693 read_data | ((0xFFFF &
1694 boot_loader_read_mem32(pao, 0,
1697 if (read_data != write_data) {
1699 write_data, read_data);
1702 write_data = write_data << 1;
1713 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
1716 boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
1718 boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
1720 boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
1725 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
1727 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
1730 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
1734 boot_loader_write_mem32(pao, 0, 0x01800004,
1735 (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
1736 (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
1743 if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
1811 boot_loader_write_mem32(pao, dsp_index,
1815 }
else if (dsp_index == 2) {
1827 u32 test_data = 0, data = 0;
1836 test_addr = start_address + i * 4;
1837 test_data = 0x00000001;
1838 for (
j = 0;
j < 32;
j++) {
1839 boot_loader_write_mem32(pao, dsp_index, test_addr,
1841 data = boot_loader_read_mem32(pao, dsp_index,
1843 if (data != test_data) {
1845 "Memtest error details "
1846 "%08x %08x %08x %i\n", test_addr,
1847 test_data, data, dsp_index);
1850 test_data = test_data << 1;
1857 for (i = 0; i < 100; i++) {
1858 test_addr = start_address + i * 4;
1859 test_data = 0xA5A55A5A;
1860 boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
1861 boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
1862 data = boot_loader_read_mem32(pao, dsp_index, test_addr);
1863 if (data != test_data) {
1865 "Memtest error details "
1866 "%08x %08x %08x %i\n", test_addr, test_data,
1871 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1875 for (i = 0; i <
length; i++) {
1876 test_addr = start_address + i * 4;
1877 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1886 if (dsp_index == 0) {
1889 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1893 err = boot_loader_test_memory(pao, dsp_index,
1894 0x80000000, 0x10000);
1895 }
else if (dsp_index == 1) {
1898 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1902 err = boot_loader_test_memory(pao, dsp_index,
1903 0x00030000, 0x10000);
1915 u32 dRAM_start_address = 0;
1918 if (dsp_index == 0) {
1920 if (pao->
pci.pci_dev->subsystem_device == 0x5000) {
1922 dRAM_start_address = 0x00400000;
1923 dRAM_size = 0x200000;
1927 }
else if (dsp_index == 1) {
1929 dRAM_start_address = 0x80000000;
1930 dRAM_size = 0x200000;
1934 if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
1943 if (dsp_index == 0) {
1945 if (pao->
pci.pci_dev->subsystem_device == 0x5000) {
1947 data = boot_loader_read_mem32(pao, dsp_index,
1949 if ((data & 0xF) != 0x5)
1951 data = boot_loader_read_mem32(pao, dsp_index,
1953 if ((data & 0xF) != 0xA)
1956 }
else if (dsp_index == 1) {
1958 if (pao->
pci.pci_dev->subsystem_device == 0x8700) {
1960 data = boot_loader_read_mem32(pao, dsp_index,
1962 if ((data & 0xFF) != 0xAA)
1965 boot_loader_write_mem32(pao, dsp_index, 0x90000000,
1979 u32 data_transferred = 0;
1993 while (data_transferred < data_size) {
1994 u32 this_copy = data_size - data_transferred;
2001 &p_data[data_transferred], this_copy);
2007 send_dsp_command(phw, operation);
2016 "Timed out waiting for " "state %d got %d\n",
2017 operation, interface->
dsp_ack);
2022 memcpy(&p_data[data_transferred],
2023 (
void *)&interface->
u.
b_data[0], this_copy);
2025 data_transferred += this_copy;
2027 if (interface->
dsp_ack != operation)
2029 interface->
dsp_ack, operation);
2040 static int wait_dsp_ack(
struct hpi_hw_obj *phw,
int state,
int timeout_us)
2043 int t = timeout_us / 4;
2046 while ((interface->
dsp_ack != state) && --t) {
2056 static void send_dsp_command(
struct hpi_hw_obj *phw,
int cmd)
2071 static unsigned int message_count;
2076 u32 time_out, time_out2;
2087 "message len %d too big for buffer %zd \n", phm->
size,
2108 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
2109 message_count, interface->
dsp_ack);
2112 "(%u) transition to GET_RESP after %u\n",
2125 "response len %d too big for buffer %d\n",
2139 if (!time_out || !time_out2) {
2148 "Timeout waiting for idle "
2149 "(on adapter_close)\n");
2165 err = message_response_sequence(pao, phm, phr);
2185 if (phr->
error != 0)
2191 err = hpi6205_transfer_data(pao, phm->
u.
d.u.data.pb_data,
2197 err = hpi6205_transfer_data(pao, phm->
u.
d.u.data.pb_data,