2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
59 * @brief This file contains the implementation of the SGPIO register inteface
63 #include <dev/isci/scil/scic_sgpio.h>
64 #include <dev/isci/scil/scic_sds_controller_registers.h>
65 #include <dev/isci/scil/scic_user_callback.h>
68 * @brief Function writes Value to the
69 * SGPIO Output Data Select Register (SGODSR) for phys specified by
72 * @param[in] SCIC_SDS_CONTROLLER_T controller
73 * @param[in] phy_mask - This field is a bit mask that specifies the phys
75 * @param[in] value - Value for write
80 void scic_sgpio_write_SGODSR_register(
81 SCIC_SDS_CONTROLLER_T *controller,
88 for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++)
90 if (phy_mask >> phy_index & 1)
92 scu_sgpio_peg0_register_write(
93 controller, output_data_select[phy_index], value
99 void scic_sgpio_set_vendor_code(
100 SCI_CONTROLLER_HANDLE_T controller,
101 U8 vendor_specific_sequence
104 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
106 scu_sgpio_peg0_register_write(
107 core_controller, vendor_specific_code, vendor_specific_sequence);
110 void scic_sgpio_set_blink_patterns(
111 SCI_CONTROLLER_HANDLE_T controller,
119 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
121 value = (pattern_b_high << 12) + (pattern_b_low << 8) + (pattern_a_high << 4) + pattern_a_low;
123 scu_sgpio_peg0_register_write(
124 core_controller, blink_rate, value);
127 void scic_sgpio_set_functionality(
128 SCI_CONTROLLER_HANDLE_T controller,
132 U32 value = DISABLE_SGPIO_FUNCTIONALITY;
133 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
137 value = ENABLE_SGPIO_FUNCTIONALITY;
140 scu_sgpio_peg0_register_write(
141 core_controller, interface_control, value);
144 void scic_sgpio_apply_led_blink_pattern(
145 SCI_CONTROLLER_HANDLE_T controller,
153 U32 output_value = 0;
155 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
157 // Start with all LEDs turned off
158 output_value = (SGODSR_INVERT_BIT << SGODSR_ERROR_LED_SHIFT)
159 | (SGODSR_INVERT_BIT << SGODSR_LOCATE_LED_SHIFT)
160 | (SGODSR_INVERT_BIT << SGODSR_ACTIVITY_LED_SHIFT);
163 { //apply pattern to error LED
164 output_value |= pattern_selection << SGODSR_ERROR_LED_SHIFT;
165 output_value &= ~(SGODSR_INVERT_BIT << SGODSR_ERROR_LED_SHIFT);
168 { //apply pattern to locate LED
169 output_value |= pattern_selection << SGODSR_LOCATE_LED_SHIFT;
170 output_value &= ~(SGODSR_INVERT_BIT << SGODSR_LOCATE_LED_SHIFT);
173 { //apply pattern to activity LED
174 output_value |= pattern_selection << SGODSR_ACTIVITY_LED_SHIFT;
175 output_value &= ~(SGODSR_INVERT_BIT << SGODSR_ACTIVITY_LED_SHIFT);
178 scic_sgpio_write_SGODSR_register(core_controller, phy_mask, output_value);
181 void scic_sgpio_set_led_blink_pattern(
182 SCI_CONTROLLER_HANDLE_T controller,
183 SCI_PORT_HANDLE_T port_handle,
192 SCIC_SDS_PORT_T * port = (SCIC_SDS_PORT_T *) port_handle;
194 phy_mask = scic_sds_port_get_phys(port);
196 scic_sgpio_apply_led_blink_pattern(
197 controller, phy_mask, error, locate, activity, pattern_selection);
200 void scic_sgpio_update_led_state(
201 SCI_CONTROLLER_HANDLE_T controller,
210 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
212 // Start with all LEDs turned on
213 output_value = 0x00000000;
216 { //turn off error LED
217 output_value |= SGODSR_INVERT_BIT << SGODSR_ERROR_LED_SHIFT;
220 { //turn off locate LED
221 output_value |= SGODSR_INVERT_BIT << SGODSR_LOCATE_LED_SHIFT;
224 { //turn off activity LED
225 output_value |= SGODSR_INVERT_BIT << SGODSR_ACTIVITY_LED_SHIFT;
228 scic_sgpio_write_SGODSR_register(core_controller, phy_mask, output_value);
231 void scic_sgpio_set_led_state(
232 SCI_CONTROLLER_HANDLE_T controller,
233 SCI_PORT_HANDLE_T port_handle,
241 SCIC_SDS_PORT_T * port = (SCIC_SDS_PORT_T *) port_handle;
243 phy_mask = scic_sds_port_get_phys(port);
245 scic_sgpio_update_led_state(controller, phy_mask, error, locate, activity);
248 void scic_sgpio_set_to_hardware_control(
249 SCI_CONTROLLER_HANDLE_T controller,
250 BOOL is_hardware_controlled
253 SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
257 //turn on hardware control for LED's
258 if(is_hardware_controlled)
260 output_value = SGPIO_HARDWARE_CONTROL;
262 else //turn off hardware control
264 output_value = SGPIO_SOFTWARE_CONTROL;
267 for(i = 0; i < SCI_MAX_PHYS; i++)
269 scu_sgpio_peg0_register_write(
270 core_controller, output_data_select[i], output_value);
275 SCI_CONTROLLER_HANDLE_T controller
278 //Not supported in the SCU hardware returning 0xFFFFFFFF
282 void scic_sgpio_hardware_initialize(
283 SCI_CONTROLLER_HANDLE_T controller
286 scic_sgpio_set_functionality(controller, TRUE);
287 scic_sgpio_set_to_hardware_control(controller, TRUE);
288 scic_sgpio_set_vendor_code(controller, 0x00);
291 void scic_sgpio_initialize(
292 SCI_CONTROLLER_HANDLE_T controller
295 scic_sgpio_set_functionality(controller, TRUE);
296 scic_sgpio_set_to_hardware_control(controller, FALSE);
297 scic_sgpio_set_vendor_code(controller, 0x00);