static void xpad360_process_packet(struct usb_xpad *xpad,
                                   u16 cmd, unsigned char *data)
{
    int i;
    struct input_dev *dev = xpad->dev; //得到设备的输入设备接口

    //dpad 左右上下 的绑定
    input_report_key(dev, BTN_DPAD_LEFT, data[2] & 0x04); //绑定成游戏柄的左键
    input_report_key(dev, BTN_DPAD_RIGHT, data[2] & 0x08); //绑定成游戏柄的右键
    input_report_key(dev, KEY_UP, data[2] & 0x01);//绑定成键盘的上键
    input_report_key(dev, KEY_DOWN, data[2] & 0x02); //绑定成键盘的下键

    //开始 返回键的绑定
    input_report_key(dev, BTN_START,  data[2] & 0x10); //绑定成游戏柄的开始键
    input_report_key(dev, BTN_SELECT, data[2] & 0x20);//绑定成游戏柄的选择键

    //左右大拇指键
    input_report_key(dev, BTN_THUMBL, data[2] & 0x40); //绑定成左大拇指键

    input_report_key(dev, KEY_ENTER, data[2] & 0x80); //绑定成回车键

    // A,B,X,Y,TL,TR 和微软键
    input_report_key(dev, BTN_RIGHT, data[3] & 0x10);//绑定成鼠标右键

    input_report_key(dev, BTN_B,   data[3] & 0x20);//绑定成游戏柄B键


    input_report_key(dev, BTN_LEFT, data[3] & 0x40); //绑定成鼠标左键

    input_report_key(dev, BTN_Y ,  data[3] & 0x80);//绑定成游戏柄Y键
   
    input_report_key(dev, BTN_TL, (data[3] & 0x01)); //绑定成TL键
    
    input_report_key(dev, BTN_TR,   (data[3] & 0x02)); //绑定成TR键


    input_report_key(dev, BTN_MODE, data[3] & 0x04);


    //左游戏杆的绑定
    input_report_abs(dev, ABS_X,
                     ((__s16) le16_to_cpup((__le16 *)(data + 6))) );
    input_report_abs(dev, ABS_Y,
                     ((~(__s16) le16_to_cpup((__le16 *)(data + 8))) + 1)  );

    //右游戏杆的绑定
    input_report_abs(dev, ABS_RX,
                     (__s16) le16_to_cpup((__le16 *)(data + 10)));
    input_report_abs(dev, ABS_RY,
                     ((~(__s16) le16_to_cpup((__le16 *)(data + 12))) + 1) );


   //LT RT的绑定
        input_report_key(dev, BTN_TL2, !!data[4] ); //绑定成按键 (本来是0~255的范围 转化成 0~1)
  
        input_report_key(dev, BTN_TR2, !!data[5] ); //绑定成按键 (本来是0~255的范围 转化成 0~1)


    input_sync(dev); //将处理后的packet 提交上去
}
static void xpad360_process_packet(struct usb_xpad *xpad,
				   u16 cmd, unsigned char *data)
{
	struct input_dev *dev = xpad->dev;

	/* digital pad */
	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
		/* dpad as buttons (right, left, down, up) */
		input_report_key(dev, BTN_LEFT, data[2] & 0x04);
		input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
		input_report_key(dev, BTN_0, data[2] & 0x01);	/* up */
		input_report_key(dev, BTN_1, data[2] & 0x02);	/* down */
	} else {
		input_report_abs(dev, ABS_HAT0X,
				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
		input_report_abs(dev, ABS_HAT0Y,
				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
	}

	/* start/back buttons */
	input_report_key(dev, BTN_START,  data[2] & 0x10);
	input_report_key(dev, BTN_BACK,   data[2] & 0x20);

	/* stick press left/right */
	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);

	/* buttons A,B,X,Y,TL,TR and MODE */
	input_report_key(dev, BTN_A,	data[3] & 0x10);
	input_report_key(dev, BTN_B,	data[3] & 0x20);
	input_report_key(dev, BTN_X,	data[3] & 0x40);
	input_report_key(dev, BTN_Y,	data[3] & 0x80);
	input_report_key(dev, BTN_TL,	data[3] & 0x01);
	input_report_key(dev, BTN_TR,	data[3] & 0x02);
	input_report_key(dev, BTN_MODE,	data[3] & 0x04);

	/* left stick */
	input_report_abs(dev, ABS_X,
			 (__s16) le16_to_cpup((__le16 *)(data + 6)));
	input_report_abs(dev, ABS_Y,
			 ~(__s16) le16_to_cpup((__le16 *)(data + 8)));

	/* right stick */
	input_report_abs(dev, ABS_RX,
			 (__s16) le16_to_cpup((__le16 *)(data + 10)));
	input_report_abs(dev, ABS_RY,
			 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));

	/* triggers left/right */
	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
		input_report_key(dev, BTN_TL2, data[4]);
		input_report_key(dev, BTN_TR2, data[5]);
	} else {
		input_report_abs(dev, ABS_Z, data[4]);
		input_report_abs(dev, ABS_RZ, data[5]);
	}

	input_sync(dev);
}
Example #3
0
File: xpad.c Project: 19Dan01/linux
static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
{
	struct input_dev *dev = xpad->dev;

	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
		/* left stick */
		input_report_abs(dev, ABS_X,
				 (__s16) le16_to_cpup((__le16 *)(data + 12)));
		input_report_abs(dev, ABS_Y,
				 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));

		/* right stick */
		input_report_abs(dev, ABS_RX,
				 (__s16) le16_to_cpup((__le16 *)(data + 16)));
		input_report_abs(dev, ABS_RY,
				 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
	}

	/* triggers left/right */
	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
		input_report_key(dev, BTN_TL2, data[10]);
		input_report_key(dev, BTN_TR2, data[11]);
	} else {
		input_report_abs(dev, ABS_Z, data[10]);
		input_report_abs(dev, ABS_RZ, data[11]);
	}

	/* digital pad */
	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
		/* dpad as buttons (left, right, up, down) */
		input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
		input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
		input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
		input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
	} else {
		input_report_abs(dev, ABS_HAT0X,
				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
		input_report_abs(dev, ABS_HAT0Y,
				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
	}

	/* start/back buttons and stick press left/right */
	input_report_key(dev, BTN_START,  data[2] & 0x10);
	input_report_key(dev, BTN_SELECT, data[2] & 0x20);
	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);

	/* "analog" buttons A, B, X, Y */
	input_report_key(dev, BTN_A, data[4]);
	input_report_key(dev, BTN_B, data[5]);
	input_report_key(dev, BTN_X, data[6]);
	input_report_key(dev, BTN_Y, data[7]);

	/* "analog" buttons black, white */
	input_report_key(dev, BTN_C, data[8]);
	input_report_key(dev, BTN_Z, data[9]);

	input_sync(dev);
}
Example #4
0
static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
{
	struct input_dev *dev = xpad->dev;

	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
		
		input_report_abs(dev, ABS_X,
				 (__s16) le16_to_cpup((__le16 *)(data + 12)));
		input_report_abs(dev, ABS_Y,
				 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));

		
		input_report_abs(dev, ABS_RX,
				 (__s16) le16_to_cpup((__le16 *)(data + 16)));
		input_report_abs(dev, ABS_RY,
				 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
	}

	
	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
		input_report_key(dev, BTN_TL2, data[10]);
		input_report_key(dev, BTN_TR2, data[11]);
	} else {
		input_report_abs(dev, ABS_Z, data[10]);
		input_report_abs(dev, ABS_RZ, data[11]);
	}

	
	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
		
		input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
		input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
		input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
		input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
	} else {
		input_report_abs(dev, ABS_HAT0X,
				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
		input_report_abs(dev, ABS_HAT0Y,
				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
	}

	
	input_report_key(dev, BTN_START,  data[2] & 0x10);
	input_report_key(dev, BTN_SELECT, data[2] & 0x20);
	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);

	
	input_report_key(dev, BTN_A, data[4]);
	input_report_key(dev, BTN_B, data[5]);
	input_report_key(dev, BTN_X, data[6]);
	input_report_key(dev, BTN_Y, data[7]);

	
	input_report_key(dev, BTN_C, data[8]);
	input_report_key(dev, BTN_Z, data[9]);

	input_sync(dev);
}
Example #5
0
static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
{
	struct input_dev *dev = xpad->dev;

	/* left stick */
	input_report_abs(dev, ABS_X,
			 (__s16) le16_to_cpup((__le16 *)(data + 12)));
	input_report_abs(dev, ABS_Y,
			 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));

	/* right stick */
	input_report_abs(dev, ABS_RX,
			 (__s16) le16_to_cpup((__le16 *)(data + 16)));
	input_report_abs(dev, ABS_RY,
			 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));

	/* triggers left/right */
	input_report_abs(dev, ABS_Z, data[10]);
	input_report_abs(dev, ABS_RZ, data[11]);

	/* digital pad */
	if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) {
		input_report_abs(dev, ABS_HAT0X,
				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
		input_report_abs(dev, ABS_HAT0Y,
				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
	} else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ {
		input_report_key(dev, BTN_LEFT,  data[2] & 0x04);
		input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
		input_report_key(dev, BTN_0,     data[2] & 0x01); /* up */
		input_report_key(dev, BTN_1,     data[2] & 0x02); /* down */
	}

	/* start/back buttons and stick press left/right */
	input_report_key(dev, BTN_START,  data[2] & 0x10);
	input_report_key(dev, BTN_BACK,   data[2] & 0x20);
	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);

	/* "analog" buttons A, B, X, Y */
	input_report_key(dev, BTN_A, data[4]);
	input_report_key(dev, BTN_B, data[5]);
	input_report_key(dev, BTN_X, data[6]);
	input_report_key(dev, BTN_Y, data[7]);

	/* "analog" buttons black, white */
	input_report_key(dev, BTN_C, data[8]);
	input_report_key(dev, BTN_Z, data[9]);

	input_sync(dev);
}
Example #6
0
static void silead_ts_read_data(struct i2c_client *client)
{
	struct silead_ts_data *data = i2c_get_clientdata(client);
	struct device *dev = &client->dev;
	u8 buf[SILEAD_TS_DATA_LEN];
	int x, y, id, touch_nr, ret, i, offset;

	ret = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_DATA,
					    SILEAD_TS_DATA_LEN, buf);
	if (ret < 0) {
		dev_err(dev, "Data read error %d\n", ret);
		return;
	}

	touch_nr = buf[0];

	if (touch_nr < 0)
		return;

	dev_dbg(dev, "Touch number: %d\n", touch_nr);

	for (i = 1; i <= touch_nr; i++) {
		offset = i * SILEAD_POINT_DATA_LEN;

		/* Bits 4-7 are the touch id */
		id = (buf[offset + SILEAD_POINT_X_MSB_OFF] &
		      SILEAD_TOUCH_ID_MASK) >> 4;

		/* Bits 0-3 are MSB of X */
		buf[offset + SILEAD_POINT_X_MSB_OFF] = buf[offset +
			SILEAD_POINT_X_MSB_OFF] & SILEAD_POINT_HSB_MASK;

		/* Bits 0-3 are MSB of Y */
		buf[offset + SILEAD_POINT_Y_MSB_OFF] = buf[offset +
			SILEAD_POINT_Y_MSB_OFF] & SILEAD_POINT_HSB_MASK;

		x = le16_to_cpup((__le16 *)(buf + offset + SILEAD_POINT_X_OFF));
		y = le16_to_cpup((__le16 *)(buf + offset + SILEAD_POINT_Y_OFF));

		dev_dbg(dev, "x=%d y=%d id=%d\n", x, y, id);
		if (data->chip_id == GSL1688_CHIP_ID)
			silead_ts_report_touch(data, (id * 256 + x),
					       data->y_max - y, id);
		else
			silead_ts_report_touch(data, x, y, id);
	}

	input_mt_sync_frame(data->input_dev);
	input_sync(data->input_dev);
}
Example #7
0
static void xpad360_receive(struct urb *urb)
{
	struct xpad360_controller *controller = urb->context;
	u8 *data = urb->transfer_buffer;
	
	switch (urb->status) {
	case 0: 
		break;
	case -ECONNRESET:
	case -ENOENT:
	case -ESHUTDOWN:
		return;
	default:
		goto finish;
	}
		
	switch(le16_to_cpup((u16*)&data[0])) {
	case 0x0301: /* LED status */
		break;
	case 0x0303: /* Possibly a packet concerning rumble effect */
		break;
	case 0x0308: /* Attachment */
		break;
	case 0x1400:
		xpad360_parse_input(controller->input_dev, &data[2]);
	}
	
finish:
	usb_submit_urb(urb, GFP_ATOMIC);
}
int iwl_phy_db_set_section(struct iwl_phy_db *phy_db,
			   enum iwl_phy_db_section_type type, u8 *data,
			   u16 size, gfp_t alloc_ctx)
{
	struct iwl_phy_db_entry *entry;
	u16 chg_id = 0;

	if (!phy_db)
		return -EINVAL;

	if (type == IWL_PHY_DB_CALIB_CHG_PAPD ||
	    type == IWL_PHY_DB_CALIB_CHG_TXP)
		chg_id = le16_to_cpup((__le16 *)data);

	entry = iwl_phy_db_get_section(phy_db, type, chg_id);
	if (!entry)
		return -EINVAL;

	kfree(entry->data);
	entry->data = kmemdup(data, size, alloc_ctx);
	if (!entry->data) {
		entry->size = 0;
		return -ENOMEM;
	}

	entry->size = size;

	if (type == IWL_PHY_DB_CALIB_CH) {
		phy_db->channel_num = le32_to_cpup((__le32 *)data);
		phy_db->channel_size =
		      (size - CHANNEL_NUM_SIZE) / phy_db->channel_num;
	}

	return 0;
}
Example #9
0
static int proc_ide_read_identify
(char *page, char **start, off_t off, int count, int *eof, void *data)
{
    ide_drive_t	*drive = (ide_drive_t *)data;
    int		len = 0, i = 0;
    int		err = 0;

    len = sprintf(page, "\n");

    if (drive) {
        __le16 *val = (__le16 *)page;

        err = taskfile_lib_get_identify(drive, page);
        if (!err) {
            char *out = (char *)page + SECTOR_SIZE;

            page = out;
            do {
                out += sprintf(out, "%04x%c",
                               le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
                val += 1;
            } while (i < SECTOR_SIZE / 2);
            len = out - page;
        }
    }
    PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
}
Example #10
0
static int r92su_bss_build_fw_bss(struct r92su *r92su, struct cfg80211_bss *bss,
				  u8 *ies_data, const unsigned int ies_len)
{
	struct r92su_bss_priv *bss_priv = r92su_get_bss_priv(bss);
	struct h2cc2h_bss *fw_bss = &bss_priv->fw_bss;
	u8 *tmp;
	int i;

	fw_bss->length = cpu_to_le32(sizeof(*fw_bss));
	memcpy(fw_bss->bssid, bss->bssid, ETH_ALEN);
	fw_bss->privacy = cpu_to_le32(!!(bss->capability &
					WLAN_CAPABILITY_PRIVACY));

	tmp = r92su_find_ie(ies_data, ies_len, WLAN_EID_SSID);
	if (!tmp || !(tmp[1] > 0))
		return -EINVAL;

	fw_bss->ssid.length = cpu_to_le32(tmp[1]);
	memcpy(fw_bss->ssid.ssid, &tmp[2],
	       min_t(unsigned int, sizeof(fw_bss->ssid.ssid), tmp[1]));
	fw_bss->type = cpu_to_le32(TYPE_11OFDM2GHZ);

	if (bss->capability & WLAN_CAPABILITY_IBSS)
		fw_bss->mode = cpu_to_le32(MODE_IBSS);
	else if (bss->capability & WLAN_CAPABILITY_ESS)
		fw_bss->mode = cpu_to_le32(MODE_BSS);
	else
		fw_bss->mode = cpu_to_le32(MODE_AUTO);

	fw_bss->config.length = cpu_to_le32(sizeof(fw_bss->config));
	fw_bss->config.beacon_period = cpu_to_le32(bss->beacon_interval);
	tmp = r92su_find_ie(ies_data, ies_len, WLAN_EID_IBSS_PARAMS);
	if (tmp && tmp[1] >= 2) {
		const __le16 *atim = (const __le16 *) &tmp[2];
		fw_bss->config.atim_window = cpu_to_le32(le16_to_cpup(atim));
	}

	tmp = r92su_find_ie(ies_data, ies_len, WLAN_EID_DS_PARAMS);
	if (!tmp || tmp[1] < 1)
		return -EINVAL;
	fw_bss->config.frequency = cpu_to_le32(tmp[2]);

	tmp = r92su_find_ie(ies_data, ies_len, WLAN_EID_SUPP_RATES);
	if (!tmp)
		return -EINVAL;
	i = min_t(unsigned int, 8u, tmp[1]);
	memcpy(fw_bss->rates.rates, &tmp[2], i);

	tmp = r92su_find_ie(ies_data, ies_len, WLAN_EID_EXT_SUPP_RATES);
	if (tmp) {
		u8 len = min_t(unsigned int, sizeof(fw_bss->rates.rates) - i,
			       tmp[1]);
		memcpy(&fw_bss->rates.rates[i], &tmp[2], len);
	}
	fw_bss->ies.timestamp = cpu_to_le64(0);
	fw_bss->ies.beaconint = cpu_to_le16(bss->beacon_interval);
	fw_bss->ies.caps = cpu_to_le16(bss->capability);
	return 0;
}
Example #11
0
static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
		       const __le16 *phy_sku)
{
	if (cfg->nvm_type != IWL_NVM_EXT)
		return le16_to_cpup(nvm_sw + SKU);

	return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
}
Example #12
0
static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
		       const __le16 *phy_sku)
{
	if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
		return le16_to_cpup(nvm_sw + SKU);

	return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
}
Example #13
0
static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
{
	if (cfg->nvm_type != IWL_NVM_EXT)
		return le16_to_cpup(nvm_sw + NVM_VERSION);
	else
		return le32_to_cpup((__le32 *)(nvm_sw +
					       NVM_VERSION_EXT_NVM));
}
Example #14
0
static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
{
	if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
		return le16_to_cpup(nvm_sw + NVM_VERSION);
	else
		return le32_to_cpup((__le32 *)(nvm_sw +
					       NVM_VERSION_FAMILY_8000));
}
Example #15
0
static int iwl_get_radio_cfg(const struct iwl_cfg *cfg,
			     const __le16 *nvm_sw)
{
	if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
		return le16_to_cpup(nvm_sw + RADIO_CFG);
	else
		return le32_to_cpup((__le32 *)(nvm_sw + RADIO_CFG_FAMILY_8000));
}
Example #16
0
File: wpan.c Project: 7799/linux
static int mac802154_parse_frame_start(struct sk_buff *skb)
{
	int hlen;
	struct ieee802154_hdr hdr;

	hlen = ieee802154_hdr_pull(skb, &hdr);
	if (hlen < 0)
		return -EINVAL;

	skb->mac_len = hlen;

	pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr.fc),
		 hdr.seq);

	mac_cb(skb)->flags = hdr.fc.type;

	if (hdr.fc.ack_request)
		mac_cb(skb)->flags |= MAC_CB_FLAG_ACKREQ;
	if (hdr.fc.security_enabled)
		mac_cb(skb)->flags |= MAC_CB_FLAG_SECEN;

	mac802154_print_addr("destination", &hdr.dest);
	mac802154_print_addr("source", &hdr.source);

	mac_cb(skb)->source = hdr.source;
	mac_cb(skb)->dest = hdr.dest;

	if (hdr.fc.security_enabled) {
		u64 key;

		pr_debug("seclevel %i\n", hdr.sec.level);

		switch (hdr.sec.key_id_mode) {
		case IEEE802154_SCF_KEY_IMPLICIT:
			pr_debug("implicit key\n");
			break;

		case IEEE802154_SCF_KEY_INDEX:
			pr_debug("key %02x\n", hdr.sec.key_id);
			break;

		case IEEE802154_SCF_KEY_SHORT_INDEX:
			pr_debug("key %04x:%04x %02x\n",
				 le32_to_cpu(hdr.sec.short_src) >> 16,
				 le32_to_cpu(hdr.sec.short_src) & 0xffff,
				 hdr.sec.key_id);
			break;

		case IEEE802154_SCF_KEY_HW_INDEX:
			key = swab64((__force u64) hdr.sec.extended_src);
			pr_debug("key source %8phC %02x\n", &key,
				 hdr.sec.key_id);
			break;
		}

		return -EINVAL;
	}
Example #17
0
static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
			     const __le16 *phy_sku)
{
	if (cfg->nvm_type != IWL_NVM_EXT)
		return le16_to_cpup(nvm_sw + RADIO_CFG);

	return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM));

}
Example #18
0
static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg,
			      const __le16 *nvm_sw)
{
	if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
		return le16_to_cpup(nvm_sw + N_HW_ADDRS);
	else
		return le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000))
		       & N_HW_ADDRS_MASK_FAMILY_8000;
}
Example #19
0
File: rx.c Project: Chong-Li/cse522
static int
ieee802154_parse_frame_start(struct sk_buff *skb, struct ieee802154_hdr *hdr)
{
	int hlen;
	struct ieee802154_mac_cb *cb = mac_cb_init(skb);

	skb_reset_mac_header(skb);

	hlen = ieee802154_hdr_pull(skb, hdr);
	if (hlen < 0)
		return -EINVAL;

	skb->mac_len = hlen;

	pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr->fc),
		 hdr->seq);

	cb->type = hdr->fc.type;
	cb->ackreq = hdr->fc.ack_request;
	cb->secen = hdr->fc.security_enabled;

	ieee802154_print_addr("destination", &hdr->dest);
	ieee802154_print_addr("source", &hdr->source);

	cb->source = hdr->source;
	cb->dest = hdr->dest;

	if (hdr->fc.security_enabled) {
		u64 key;

		pr_debug("seclevel %i\n", hdr->sec.level);

		switch (hdr->sec.key_id_mode) {
		case IEEE802154_SCF_KEY_IMPLICIT:
			pr_debug("implicit key\n");
			break;

		case IEEE802154_SCF_KEY_INDEX:
			pr_debug("key %02x\n", hdr->sec.key_id);
			break;

		case IEEE802154_SCF_KEY_SHORT_INDEX:
			pr_debug("key %04x:%04x %02x\n",
				 le32_to_cpu(hdr->sec.short_src) >> 16,
				 le32_to_cpu(hdr->sec.short_src) & 0xffff,
				 hdr->sec.key_id);
			break;

		case IEEE802154_SCF_KEY_HW_INDEX:
			key = swab64((__force u64)hdr->sec.extended_src);
			pr_debug("key source %8phC %02x\n", &key,
				 hdr->sec.key_id);
			break;
		}
	}
Example #20
0
static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
{
	int n_hw_addr;

	if (cfg->nvm_type != IWL_NVM_EXT)
		return le16_to_cpup(nvm_sw + N_HW_ADDRS);

	n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));

	return n_hw_addr & N_HW_ADDR_MASK;
}
Example #21
0
static int asv5211_download_firmware(struct usb_device *udev,
		const struct firmware *fw)
{
	int ret = 0;
	u16 idx;
	u8 *buff, *fw_data;

	if (fw->size < 0xa90+0x4000) {
		err("firmware file is too small");
		return -EINVAL;
	}

	buff = kmalloc(0x1000, GFP_KERNEL);
	if (buff == NULL) {
		return -ENOMEM;
	}

	deb_info("download firmware: ");
	fw_data = (void *)fw->data;
	idx = le16_to_cpup((__le16 *)&fw_data[0xa88]);
	if ((idx == 0x4d66) /* CD 1.0 */ || (idx == 0x5121) /* CD 1.1 */) {
		deb_info("idx = 0x%x\n", idx);
	}
	else {
		err("unknown firmware file");
		ret = -EINVAL;
		goto done;
	}

	memcpy(buff, &fw_data[0xa90+0x0000], 0x0c00);
	ret = asv5211_send_firm(udev, 0xab, idx, buff, 0x0000, 0x0c00);
	if (ret != 0) {
		goto done;
	}
	memcpy(buff, &fw_data[0xa90+0x2000], 0x0400);
	ret = asv5211_send_firm(udev, 0xab, idx, buff, 0x2000, 0x0400);
	if (ret != 0) {
		goto done;
	}
	memcpy(buff, &fw_data[0xa90+0x2800], 0x1000);
	ret = asv5211_send_firm(udev, 0xab, idx, buff, 0x2800, 0x1000);
	if (ret != 0) {
		goto done;
	}
	memcpy(buff, &fw_data[0xa90+0x3800], 0x0800);
	ret = asv5211_send_firm(udev, 0xac, idx, buff, 0x3800, 0x0800);

done:
	kfree(buff);
	return ret;
}
Example #22
0
static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,
		uint16_t *plen, const uint8_t **pdat)
{
	uint16_t checksum[2];
	const uint8_t *mem;
	const uint8_t *end;

	/*
	 * firmware records are a binary, unaligned stream composed of:
	 * uint16_t type;
	 * uint32_t addr;
	 * uint16_t len;
	 * uint8_t dat[len];
	 * uint16_t checksum;
	 * all values in little endian.
	 * We could define a struct for this, with __attribute__((packed)),
	 * but would that solve the alignment in _all_ cases (cfr. the
	 * struct itself may be an odd address)?
	 *
	 * I chose to use leXX_to_cpup() since this solves both
	 * endianness & alignment.
	 */
	mem = *pmem;
	*ptype = le16_to_cpup((void *)&mem[0]);
	*paddr = le32_to_cpup((void *)&mem[2]);
	*plen = le16_to_cpup((void *)&mem[6]);
	*pdat = &mem[8];
	/* verify checksum */
	end = &mem[8 + *plen];
	checksum[0] = le16_to_cpup((void *)end);
	for (checksum[1] = 0; mem < end; ++mem)
		checksum[1] += *mem;
	if (checksum[0] != checksum[1])
		return -EINVAL;
	/* increment */
	*pmem += 10 + *plen;
	return 0;
}
static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr,
		uint16_t *plen, const uint8_t **pdat)
{
	uint16_t checksum[2];
	const uint8_t *mem;
	const uint8_t *end;

	mem = *pmem;
	*ptype = le16_to_cpup((void *)&mem[0]);
	*paddr = le32_to_cpup((void *)&mem[2]);
	*plen = le16_to_cpup((void *)&mem[6]);
	*pdat = &mem[8];
	
	end = &mem[8 + *plen];
	checksum[0] = le16_to_cpup((void *)end);
	for (checksum[1] = 0; mem < end; ++mem)
		checksum[1] += *mem;
	if (checksum[0] != checksum[1])
		return -EINVAL;
	
	*pmem += 10 + *plen;
	return 0;
}
Example #24
0
static void acm_ctrl_irq(struct urb *urb)
{
	struct acm *acm = urb->context;
	devrequest *dr = urb->transfer_buffer;
	unsigned char *data = (unsigned char *)(dr + 1);
	int newctrl;

	if (!ACM_READY(acm)) return;

	if (urb->status < 0) {
		dbg("nonzero ctrl irq status received: %d", urb->status);
		return;
	}

	switch (dr->request) {

		case ACM_IRQ_NETWORK:

			dbg("%s network", data[0] ? "connected to" : "disconnected from");
			return;

		case ACM_IRQ_LINE_STATE:

			newctrl = le16_to_cpup((__u16 *) data);

#if 0
			/* Please someone tell me how to do this properly to kill pppd and not kill minicom */
			if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
				dbg("calling hangup");
				tty_hangup(acm->tty);
			}
#endif

			acm->ctrlin = newctrl;

			dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
				acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',	acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
				acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',	acm->ctrlin & ACM_CTRL_RI  ? '+' : '-',
				acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',	acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
				acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');

			return;

		default:
			dbg("unknown control event received: request %d index %d len %d data0 %d data1 %d",
				dr->request, dr->index, dr->length, data[0], data[1]);
			return;
	}
}
Example #25
0
inline static void xpad360_parse_input(struct input_dev *input_dev, u8 *data)
{
	/* D-pad */
	input_report_abs(input_dev, ABS_HAT0X, !!(data[0] & 0x08) - !!(data[0] & 0x04));
	input_report_abs(input_dev, ABS_HAT0Y, !!(data[0] & 0x02) - !!(data[0] & 0x01));
	
	/* start/back buttons */
	input_report_key(input_dev, BTN_START,  data[0] & 0x10);
	input_report_key(input_dev, BTN_SELECT, data[0] & 0x20); /* Back */

	/* stick press left/right */
	input_report_key(input_dev, BTN_THUMBL, data[0] & 0x40);
	input_report_key(input_dev, BTN_THUMBR, data[0] & 0x80);

	input_report_key(input_dev, BTN_TL, data[1] & 0x01); /* Left Shoulder */
	input_report_key(input_dev, BTN_TR, data[1] & 0x02); /* Right Shoulder */
	input_report_key(input_dev, BTN_MODE, data[1] & 0x04); /* Guide */
	/* data[8] & 0x08 is a dummy value */
	input_report_key(input_dev, BTN_A, data[1] & 0x10);
	input_report_key(input_dev, BTN_B, data[1] & 0x20);
	input_report_key(input_dev, BTN_X, data[1] & 0x40);
	input_report_key(input_dev, BTN_Y, data[1] & 0x80);

	input_report_abs(input_dev, ABS_Z, data[2]);
	input_report_abs(input_dev, ABS_RZ, data[3]);

	/* Left Stick */
	input_report_abs(input_dev, ABS_X, (__s16)le16_to_cpup((__le16*)&data[4]));
	input_report_abs(input_dev, ABS_Y, ~(__s16)le16_to_cpup((__le16*)&data[6]));

	/* Right Stick */
	input_report_abs(input_dev, ABS_RX, (__s16)le16_to_cpup((__le16*)&data[8]));
	input_report_abs(input_dev, ABS_RY, ~(__s16)le16_to_cpup((__le16*)&data[10]));
	
	input_sync(input_dev);
}
Example #26
0
/**
 *	sdio_readw - read a 16 bit integer from a SDIO function
 *	@func: SDIO function to access
 *	@addr: address to read
 *	@err_ret: optional status value from transfer
 *
 *	Reads a 16 bit integer from the address space of a given SDIO
 *	function. If there is a problem reading the address, 0xffff
 *	is returned and @err_ret will contain the error code.
 */
u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
{
	int ret;

	if (err_ret)
		*err_ret = 0;

	ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
	if (ret) {
		if (err_ret)
			*err_ret = ret;
		return 0xFFFF;
	}

	return le16_to_cpup((__le16 *)func->tmpbuf);
}
Example #27
0
File: rx.c Project: 3bsa/linux
/* Handle a received packet.  Second half: Touches packet payload. */
void __efx_rx_packet(struct efx_channel *channel)
{
	struct efx_nic *efx = channel->efx;
	struct efx_rx_buffer *rx_buf =
		efx_rx_buffer(&channel->rx_queue, channel->rx_pkt_index);
	u8 *eh = efx_rx_buf_va(rx_buf);

	/* Read length from the prefix if necessary.  This already
	 * excludes the length of the prefix itself.
	 */
	if (rx_buf->flags & EFX_RX_PKT_PREFIX_LEN)
		rx_buf->len = le16_to_cpup((__le16 *)
					   (eh + efx->rx_packet_len_offset));

	/* If we're in loopback test, then pass the packet directly to the
	 * loopback layer, and free the rx_buf here
	 */
	if (unlikely(efx->loopback_selftest)) {
		struct efx_rx_queue *rx_queue;

		efx_loopback_rx_packet(efx, eh, rx_buf->len);
		rx_queue = efx_channel_get_rx_queue(channel);
		efx_free_rx_buffers(rx_queue, rx_buf,
				    channel->rx_pkt_n_frags);
		goto out;
	}

	if (unlikely(!(efx->net_dev->features & NETIF_F_RXCSUM)))
		rx_buf->flags &= ~EFX_RX_PKT_CSUMMED;

	if ((rx_buf->flags & EFX_RX_PKT_TCP) && !channel->type->receive_skb &&
	    !efx_channel_busy_polling(channel))
		efx_rx_packet_gro(channel, rx_buf, channel->rx_pkt_n_frags, eh);
	else
		efx_rx_deliver(channel, eh, rx_buf, channel->rx_pkt_n_frags);
out:
	channel->rx_pkt_n_frags = 0;
}
Example #28
0
static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
{
	int i;
	u8 data[3], tmp;

	data[0] = phy;
	data[1] = data[2] = 0;
	tmp = indx | PHY_READ | PHY_GO;
	i = 0;

	set_registers(dev, PHYADD, sizeof(data), data);
	set_registers(dev, PHYCNT, 1, &tmp);
	do {
		get_registers(dev, PHYCNT, 1, data);
	} while ((data[0] & PHY_GO) && (i++ < HZ));

	if (i < HZ) {
		get_registers(dev, PHYDAT, 2, data);
		*reg = le16_to_cpup((u16 *)data);
		return 0;
	} else
		return 1;
}
Example #29
0
int iwl_phy_db_set_section(struct iwl_phy_db *phy_db, struct iwl_rx_packet *pkt,
			   gfp_t alloc_ctx)
{
	struct iwl_calib_res_notif_phy_db *phy_db_notif =
			(struct iwl_calib_res_notif_phy_db *)pkt->data;
	enum iwl_phy_db_section_type type = le16_to_cpu(phy_db_notif->type);
	u16 size  = le16_to_cpu(phy_db_notif->length);
	struct iwl_phy_db_entry *entry;
	u16 chg_id = 0;

	if (!phy_db)
		return -EINVAL;

	if (type == IWL_PHY_DB_CALIB_CHG_PAPD ||
	    type == IWL_PHY_DB_CALIB_CHG_TXP)
		chg_id = le16_to_cpup((__le16 *)phy_db_notif->data);

	entry = iwl_phy_db_get_section(phy_db, type, chg_id);
	if (!entry)
		return -EINVAL;

	kfree(entry->data);
	entry->data = kmemdup(phy_db_notif->data, size, alloc_ctx);
	if (!entry->data) {
		entry->size = 0;
		return -ENOMEM;
	}

	entry->size = size;

	IWL_DEBUG_INFO(phy_db->trans,
		       "%s(%d): [PHYDB]SET: Type %d , Size: %d\n",
		       __func__, __LINE__, type, size);

	return 0;
}
Example #30
0
static void usb_hub_events(void)
{
	unsigned long flags;
	struct list_head *tmp;
	struct usb_device *dev;
	struct usb_hub *hub;
	struct usb_hub_status hubsts;
	u16 hubstatus;
	u16 hubchange;
	u16 portstatus;
	u16 portchange;
	int i, ret;

	/*
	 *  We restart the list everytime to avoid a deadlock with
	 * deleting hubs downstream from this one. This should be
	 * safe since we delete the hub from the event list.
	 * Not the most efficient, but avoids deadlocks.
	 */
    DBG_HOST_HUB("### >>> Enter hub.c file --> usb_hub_events function \n");

	while (1) {
		spin_lock_irqsave(&hub_event_lock, flags);

		if (list_empty(&hub_event_list))
			break;

		/* Grab the next entry from the beginning of the list */
		tmp = hub_event_list.next;

		hub = list_entry(tmp, struct usb_hub, event_list);
		dev = hub->dev;

		list_del(tmp);
		INIT_LIST_HEAD(tmp);

		down(&hub->khubd_sem); /* never blocks, we were on list */
		spin_unlock_irqrestore(&hub_event_lock, flags);

		if (hub->error) {
			dbg("resetting hub %d for error %d", dev->devnum, hub->error);

			if (usb_hub_reset(hub)) {
				err("error resetting hub %d - disconnecting", dev->devnum);
				up(&hub->khubd_sem);
				usb_hub_disconnect(dev);
				continue;
			}

			hub->nerrors = 0;
			hub->error = 0;
		}

		for (i = 0; i < hub->descriptor->bNbrPorts; i++) {
			ret = usb_hub_port_status(dev, i, &portstatus, &portchange);
			if (ret < 0) {
				continue;
			}


			if (portchange & USB_PORT_STAT_C_CONNECTION) {
				dbg("port %d connection change", i + 1);

				usb_hub_port_connect_change(hub, i, portstatus, portchange);
			} else if (portchange & USB_PORT_STAT_C_ENABLE) {
				dbg("port %d enable change, status %x", i + 1, portstatus);
				usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE);

				/*
				 * EM interference sometimes causes bad shielded USB devices to 
				 * be shutdown by the hub, this hack enables them again.
				 * Works at least with mouse driver. 
				 */
				if (!(portstatus & USB_PORT_STAT_ENABLE) && 
				    (portstatus & USB_PORT_STAT_CONNECTION) && (dev->children[i])) {
					err("already running port %i disabled by hub (EMI?), re-enabling...",
						i + 1);
					usb_hub_port_connect_change(hub, i, portstatus, portchange);
				}
			}

			if (portchange & USB_PORT_STAT_C_SUSPEND) {
				dbg("port %d suspend change", i + 1);
				usb_clear_port_feature(dev, i + 1,  USB_PORT_FEAT_C_SUSPEND);
			}
			
			if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
				err("port %d over-current change", i + 1);
				usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT);
				usb_hub_power_on(hub);
			}

			if (portchange & USB_PORT_STAT_C_RESET) {
				dbg("port %d reset change", i + 1);
				usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET);
			}
		} /* end for i */

		/* deal with hub status changes */
		if (usb_get_hub_status(dev, &hubsts) < 0)
			err("get_hub_status failed");
		else {
			hubstatus = le16_to_cpup(&hubsts.wHubStatus);
			hubchange = le16_to_cpup(&hubsts.wHubChange);
			if (hubchange & HUB_CHANGE_LOCAL_POWER) {
				dbg("hub power change");
				usb_clear_hub_feature(dev, C_HUB_LOCAL_POWER);
			}
			if (hubchange & HUB_CHANGE_OVERCURRENT) {
				dbg("hub overcurrent change");
				wait_ms(500);	/* Cool down */
				usb_clear_hub_feature(dev, C_HUB_OVER_CURRENT);
                        	usb_hub_power_on(hub);
			}
		}
		up(&hub->khubd_sem);
        } /* end while (1) */

	spin_unlock_irqrestore(&hub_event_lock, flags);
}