Changeset 462054a in mainline


Ignore:
Timestamp:
2015-01-29T17:46:19Z (9 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab365c4
Parents:
01784d2
Message:

Finished HW initialization (but skipped several things, will finish them later if they will be necessary) and finally bringed up device led light :)

Location:
uspace/drv/bus/usb/ar9271
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ar9271/ar9271.c

    r01784d2 r462054a  
    255255}
    256256
    257 /** Get MAC address of the AR9271 adapter
    258  *
    259  *  @param ar9271 The AR9271 device
    260  *  @param address The place to store the address
    261  *
    262  *  @return EOK if succeed, negative error code otherwise
    263  */
    264 inline static void ar9271_hw_get_addr(ar9271_t *ar9271, nic_address_t *addr)
    265 {
    266         assert(ar9271);
    267         assert(addr);
    268        
    269         // TODO
    270 }
    271 
    272257/** Force receiving all frames in the receive buffer
    273258 *
     
    409394       
    410395        memset(ar9271, 0, sizeof(ar9271_t));
     396       
     397        ar9271->ddf_device = dev;
    411398       
    412399        rc = ar9271_init(ar9271, usb_device);
     
    492479        nic_t *nic = nic_get_from_ddf_dev(dev);
    493480       
    494         /* TODO: Report HW address here. */
    495        
    496481        /* Create AR9271 function.*/
    497482        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
  • uspace/drv/bus/usb/ar9271/ar9271.h

    r01784d2 r462054a  
    4040#include "htc.h"
    4141
     42/** Number of GPIO pin used for handling led light */
     43#define AR9271_LED_PIN 15
     44
    4245/** AR9271 Registers */
    4346typedef enum {
     47        /* EEPROM Addresses */
     48        AR9271_EEPROM_BASE = 0x2100,
     49        AR9271_EEPROM_MAC_ADDR_START = 0x2118,
     50       
    4451        /* Reset MAC interface */
    4552        AR9271_RC = 0x4000,
    4653        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 */
    4763   
    4864        /* Wakeup related registers */
     
    6278       
    6379        /* MAC Registers */
    64         AR9271_MAC_REG_OFFSET = 0x10000000, /**< MAC Registers offset */
    65                        
    6680        AR9271_MAC_PCU_STA_ADDR_L32 = 0x8000, /**< STA Address Lower 32 Bits */
    6781        AR9271_MAC_PCU_STA_ADDR_U16 = 0x8004, /**< STA Address Upper 16 Bits */
     
    7892/** AR9271 device data */
    7993typedef struct {
     94        /** DDF device pointer */
     95        ddf_dev_t *ddf_device;
     96       
    8097        /** USB device data */
    8198        usb_device_t *usb_device;
  • uspace/drv/bus/usb/ar9271/hw.c

    r01784d2 r462054a  
    3535#include <usb/debug.h>
    3636#include <unistd.h>
     37#include <nic.h>
    3738
    3839#include "hw.h"
     
    179180}
    180181
     182static 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
     215static 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
     258static 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
    181270/**
    182271 * Hardware reset of AR9271 device.
     
    186275 * @return EOK if succeed, negative error code otherwise.
    187276 */
    188 int hw_reset(ar9271_t *ar9271)
     277static int hw_reset(ar9271_t *ar9271)
    189278{
    190279        int rc = hw_reset_power_on(ar9271);
     
    200289        }
    201290       
    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
     300static 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        }
    203314       
    204315        return EOK;
     
    220331        }
    221332       
     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       
    222339        usb_log_info("HW initialization finished successfully.\n");
    223340       
  • uspace/drv/bus/usb/ar9271/hw.h

    r01784d2 r462054a  
    4242
    4343extern int hw_init(ar9271_t *ar9271);
    44 extern int hw_reset(ar9271_t *ar9271);
    4544
    4645#endif  /* ATHEROS_HW_H */
  • uspace/drv/bus/usb/ar9271/wmi.c

    r01784d2 r462054a  
    115115 * @return EOK if succeed, negative error code otherwise.
    116116 */
    117 int wmi_reg_rmw(htc_device_t *htc_device, uint32_t reg_offset,
     117int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
    118118        uint32_t set_bit, uint32_t clear_bit)
    119119{
     
    127127        }
    128128       
     129        value &= ~clear_bit;
    129130        value |= set_bit;
    130         value &= ~clear_bit;
    131131       
    132132        rc = wmi_reg_write(htc_device, reg_offset, value);
     
    152152        uint32_t set_bit)
    153153{
    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);
    155155}
    156156
     
    167167        uint32_t clear_bit)
    168168{
    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);
    170170}
    171171
  • uspace/drv/bus/usb/ar9271/wmi.h

    r01784d2 r462054a  
    118118extern int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset,
    119119        uint32_t val);
    120 extern int wmi_reg_rmw(htc_device_t *htc_device, uint32_t reg_offset,
     120extern int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
    121121        uint32_t set_bit, uint32_t clear_bit);
    122122extern int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
Note: See TracChangeset for help on using the changeset viewer.