Changeset 462054a in mainline
- Timestamp:
- 2015-01-29T17:46:19Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab365c4
- Parents:
- 01784d2
- Location:
- uspace/drv/bus/usb/ar9271
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ar9271/ar9271.c
r01784d2 r462054a 255 255 } 256 256 257 /** Get MAC address of the AR9271 adapter258 *259 * @param ar9271 The AR9271 device260 * @param address The place to store the address261 *262 * @return EOK if succeed, negative error code otherwise263 */264 inline static void ar9271_hw_get_addr(ar9271_t *ar9271, nic_address_t *addr)265 {266 assert(ar9271);267 assert(addr);268 269 // TODO270 }271 272 257 /** Force receiving all frames in the receive buffer 273 258 * … … 409 394 410 395 memset(ar9271, 0, sizeof(ar9271_t)); 396 397 ar9271->ddf_device = dev; 411 398 412 399 rc = ar9271_init(ar9271, usb_device); … … 492 479 nic_t *nic = nic_get_from_ddf_dev(dev); 493 480 494 /* TODO: Report HW address here. */495 496 481 /* Create AR9271 function.*/ 497 482 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); -
uspace/drv/bus/usb/ar9271/ar9271.h
r01784d2 r462054a 40 40 #include "htc.h" 41 41 42 /** Number of GPIO pin used for handling led light */ 43 #define AR9271_LED_PIN 15 44 42 45 /** AR9271 Registers */ 43 46 typedef enum { 47 /* EEPROM Addresses */ 48 AR9271_EEPROM_BASE = 0x2100, 49 AR9271_EEPROM_MAC_ADDR_START = 0x2118, 50 44 51 /* Reset MAC interface */ 45 52 AR9271_RC = 0x4000, 46 53 AR9271_RC_AHB = 0x00000001, 54 55 /* GPIO registers */ 56 AR9271_GPIO_IN_OUT = 0x4048, /**< GPIO value read/set */ 57 AR9271_GPIO_OE_OUT = 0x404C, /**< GPIO set to output */ 58 AR9271_GPIO_OE_OUT_ALWAYS = 0x3, /**< GPIO always drive output */ 59 AR9271_GPIO_OUT_MUX1 = 0x4060, 60 AR9271_GPIO_OUT_MUX2 = 0x4064, 61 AR9271_GPIO_OUT_MUX3 = 0x4068, 62 AR9271_GPIO_OUT_MUX_AS_OUT = 0x0, /**< GPIO set mux as output */ 47 63 48 64 /* Wakeup related registers */ … … 62 78 63 79 /* MAC Registers */ 64 AR9271_MAC_REG_OFFSET = 0x10000000, /**< MAC Registers offset */65 66 80 AR9271_MAC_PCU_STA_ADDR_L32 = 0x8000, /**< STA Address Lower 32 Bits */ 67 81 AR9271_MAC_PCU_STA_ADDR_U16 = 0x8004, /**< STA Address Upper 16 Bits */ … … 78 92 /** AR9271 device data */ 79 93 typedef struct { 94 /** DDF device pointer */ 95 ddf_dev_t *ddf_device; 96 80 97 /** USB device data */ 81 98 usb_device_t *usb_device; -
uspace/drv/bus/usb/ar9271/hw.c
r01784d2 r462054a 35 35 #include <usb/debug.h> 36 36 #include <unistd.h> 37 #include <nic.h> 37 38 38 39 #include "hw.h" … … 179 180 } 180 181 182 static int hw_addr_init(ar9271_t *ar9271) 183 { 184 int rc; 185 uint32_t value; 186 nic_address_t ar9271_address; 187 188 for(int i = 0; i < 3; i++) { 189 rc = wmi_reg_read(ar9271->htc_device, 190 AR9271_EEPROM_MAC_ADDR_START + i*4, 191 &value); 192 193 if(rc != EOK) { 194 usb_log_error("Failed to read %d. byte of MAC address." 195 "\n", i); 196 return rc; 197 } 198 199 uint16_t two_bytes = uint16_t_be2host(value); 200 ar9271_address.address[2*i] = two_bytes >> 8; 201 ar9271_address.address[2*i+1] = two_bytes & 0xff; 202 } 203 204 nic_t *nic = nic_get_from_ddf_dev(ar9271->ddf_device); 205 206 rc = nic_report_address(nic, &ar9271_address); 207 if(rc != EOK) { 208 usb_log_error("Failed to report NIC HW address.\n"); 209 return rc; 210 } 211 212 return EOK; 213 } 214 215 static int hw_gpio_set_output(ar9271_t *ar9271, uint32_t gpio, uint32_t type) 216 { 217 uint32_t address, gpio_shift, temp; 218 219 if(gpio > 11) { 220 address = AR9271_GPIO_OUT_MUX3; 221 } else if(gpio > 5) { 222 address = AR9271_GPIO_OUT_MUX2; 223 } else { 224 address = AR9271_GPIO_OUT_MUX1; 225 } 226 227 gpio_shift = (gpio % 6) * 5; 228 229 int rc = wmi_reg_read(ar9271->htc_device, address, &temp); 230 if(rc != EOK) { 231 usb_log_error("Failed to read GPIO output mux.\n"); 232 return rc; 233 } 234 235 temp = ((temp & 0x1F0) << 1) | (temp & ~0x1F0); 236 temp &= ~(0x1f << gpio_shift); 237 temp |= (type << gpio_shift); 238 239 rc = wmi_reg_write(ar9271->htc_device, address, temp); 240 if(rc != EOK) { 241 usb_log_error("Failed to write GPIO output mux.\n"); 242 return rc; 243 } 244 245 gpio_shift = 2 * gpio; 246 247 rc = wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT, 248 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift, 249 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift); 250 if(rc != EOK) { 251 usb_log_error("Failed to config GPIO as output.\n"); 252 return rc; 253 } 254 255 return EOK; 256 } 257 258 static int hw_gpio_set_value(ar9271_t *ar9271, uint32_t gpio, uint32_t value) 259 { 260 int rc = wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_GPIO_IN_OUT, 261 (~value & 1) << gpio, 1 << gpio); 262 if(rc != EOK) { 263 usb_log_error("Failed to set GPIO.\n"); 264 return rc; 265 } 266 267 return EOK; 268 } 269 181 270 /** 182 271 * Hardware reset of AR9271 device. … … 186 275 * @return EOK if succeed, negative error code otherwise. 187 276 */ 188 int hw_reset(ar9271_t *ar9271)277 static int hw_reset(ar9271_t *ar9271) 189 278 { 190 279 int rc = hw_reset_power_on(ar9271); … … 200 289 } 201 290 202 /* TODO: Finish HW init (EEPROM init, MAC ADDR init). */ 291 rc = hw_addr_init(ar9271); 292 if(rc != EOK) { 293 usb_log_error("Failed to init HW addr.\n"); 294 return rc; 295 } 296 297 return EOK; 298 } 299 300 static int hw_init_led(ar9271_t *ar9271) 301 { 302 int rc = hw_gpio_set_output(ar9271, AR9271_LED_PIN, 303 AR9271_GPIO_OUT_MUX_AS_OUT); 304 if(rc != EOK) { 305 usb_log_error("Failed to set led GPIO to output.\n"); 306 return rc; 307 } 308 309 rc = hw_gpio_set_value(ar9271, AR9271_LED_PIN, 0); 310 if(rc != EOK) { 311 usb_log_error("Failed to init bring up GPIO led.\n"); 312 return rc; 313 } 203 314 204 315 return EOK; … … 220 331 } 221 332 333 rc = hw_init_led(ar9271); 334 if(rc != EOK) { 335 usb_log_error("Failed to HW init led.\n"); 336 return rc; 337 } 338 222 339 usb_log_info("HW initialization finished successfully.\n"); 223 340 -
uspace/drv/bus/usb/ar9271/hw.h
r01784d2 r462054a 42 42 43 43 extern int hw_init(ar9271_t *ar9271); 44 extern int hw_reset(ar9271_t *ar9271);45 44 46 45 #endif /* ATHEROS_HW_H */ -
uspace/drv/bus/usb/ar9271/wmi.c
r01784d2 r462054a 115 115 * @return EOK if succeed, negative error code otherwise. 116 116 */ 117 int wmi_reg_ rmw(htc_device_t *htc_device, uint32_t reg_offset,117 int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset, 118 118 uint32_t set_bit, uint32_t clear_bit) 119 119 { … … 127 127 } 128 128 129 value &= ~clear_bit; 129 130 value |= set_bit; 130 value &= ~clear_bit;131 131 132 132 rc = wmi_reg_write(htc_device, reg_offset, value); … … 152 152 uint32_t set_bit) 153 153 { 154 return wmi_reg_ rmw(htc_device, reg_offset, set_bit, 0);154 return wmi_reg_clear_set_bit(htc_device, reg_offset, set_bit, 0); 155 155 } 156 156 … … 167 167 uint32_t clear_bit) 168 168 { 169 return wmi_reg_ rmw(htc_device, reg_offset, 0, clear_bit);169 return wmi_reg_clear_set_bit(htc_device, reg_offset, 0, clear_bit); 170 170 } 171 171 -
uspace/drv/bus/usb/ar9271/wmi.h
r01784d2 r462054a 118 118 extern int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset, 119 119 uint32_t val); 120 extern int wmi_reg_ rmw(htc_device_t *htc_device, uint32_t reg_offset,120 extern int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset, 121 121 uint32_t set_bit, uint32_t clear_bit); 122 122 extern int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
Note:
See TracChangeset
for help on using the changeset viewer.