2 * ---------------------------------------------------------------------------
6 * Use the HIP core lib to initialise the UniFi chip.
7 * It is part of the porting exercise in Linux.
9 * Copyright (C) 2009 by Cambridge Silicon Radio Ltd.
11 * Refer to LICENSE.txt included with this source code for details on
14 * ---------------------------------------------------------------------------
16 #include "csr_wifi_hip_unifi.h"
17 #include "unifi_priv.h"
20 #define MAX_INIT_ATTEMPTS 4
26 * ---------------------------------------------------------------------------
29 * Resets hardware, downloads and initialises f/w.
30 * This function demonstrates how to use the HIP core lib API
31 * to implement the SME unifi_sys_wifi_on_req() part of the SYS API.
33 * In a simple implementation, all this function needs to do is call
34 * unifi_init_card() and then unifi_card_info().
35 * In the Linux implementation, it will retry to initialise UniFi or
36 * try to debug the reasons if unifi_init_card() returns an error.
39 * ospriv Pointer to OS driver structure for the device.
42 * O on success, non-zero otherwise.
44 * ---------------------------------------------------------------------------
47 uf_init_hw(unifi_priv_t
*priv
)
51 CsrResult csrResult
= CSR_RESULT_FAILURE
;
53 priv_instance
= uf_find_priv(priv
);
54 if (priv_instance
== -1) {
55 unifi_warning(priv
, "uf_init_hw: Unknown priv instance, will use fw_init[0]\n");
60 if (attempts
> MAX_INIT_ATTEMPTS
) {
61 unifi_error(priv
, "Failed to initialise UniFi after %d attempts, "
68 unifi_info(priv
, "Initialising UniFi, attempt %d\n", attempts
);
70 if (fw_init
[priv_instance
] > 0) {
71 unifi_notice(priv
, "f/w init prevented by module parameter\n");
73 } else if (fw_init
[priv_instance
] == 0) {
74 fw_init
[priv_instance
] ++;
78 * Initialise driver core. This will perform a reset of UniFi
79 * internals, but not the SDIO CCCR.
81 CsrSdioClaim(priv
->sdio
);
82 csrResult
= unifi_init_card(priv
->card
, led_mask
);
83 CsrSdioRelease(priv
->sdio
);
85 if (csrResult
== CSR_WIFI_HIP_RESULT_NO_DEVICE
) {
86 return CsrHipResultToStatus(csrResult
);
88 if (csrResult
== CSR_WIFI_HIP_RESULT_NOT_FOUND
) {
89 unifi_error(priv
, "Firmware file required, but not found.\n");
90 return CsrHipResultToStatus(csrResult
);
92 if (csrResult
!= CSR_RESULT_SUCCESS
) {
93 /* failed. Reset h/w and try again */
94 unifi_error(priv
, "Failed to initialise UniFi chip.\n");
98 /* Get the version information from the lib_hip */
99 unifi_card_info(priv
->card
, &priv
->card_info
);
101 return CsrHipResultToStatus(csrResult
);
104 return CsrHipResultToStatus(csrResult
);