Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8826de8 authored by hayeswang's avatar hayeswang Committed by David S. Miller
Browse files

net/usb/r8152: adjust relative ocp function



- fix the conversion between cpu and __le32
 - replace some pla_ocp and usb_ocp functions with generic_ocp function

Signed-off-by: default avatarHayes Wang <hayeswang@realtek.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 31787f53
Loading
Loading
Loading
Loading
+23 −43
Original line number Original line Diff line number Diff line
@@ -514,37 +514,31 @@ int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)


static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
{
{
	u32 data;
	__le32 data;


	if (type == MCU_TYPE_PLA)
	generic_ocp_read(tp, index, sizeof(data), &data, type);
		pla_ocp_read(tp, index, sizeof(data), &data);
	else
		usb_ocp_read(tp, index, sizeof(data), &data);


	return __le32_to_cpu(data);
	return __le32_to_cpu(data);
}
}


static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
{
{
	if (type == MCU_TYPE_PLA)
	__le32 tmp = __cpu_to_le32(data);
		pla_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(data), &data);

	else
	generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type);
		usb_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(data), &data);
}
}


static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
{
{
	u32 data;
	u32 data;
	__le32 tmp;
	u8 shift = index & 2;
	u8 shift = index & 2;


	index &= ~3;
	index &= ~3;


	if (type == MCU_TYPE_PLA)
	generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
		pla_ocp_read(tp, index, sizeof(data), &data);
	else
		usb_ocp_read(tp, index, sizeof(data), &data);


	data = __le32_to_cpu(data);
	data = __le32_to_cpu(tmp);
	data >>= (shift * 8);
	data >>= (shift * 8);
	data &= 0xffff;
	data &= 0xffff;


@@ -553,7 +547,8 @@ static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)


static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
{
{
	u32 tmp, mask = 0xffff;
	u32 mask = 0xffff;
	__le32 tmp;
	u16 byen = BYTE_EN_WORD;
	u16 byen = BYTE_EN_WORD;
	u8 shift = index & 2;
	u8 shift = index & 2;


@@ -566,34 +561,25 @@ static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
		index &= ~3;
		index &= ~3;
	}
	}


	if (type == MCU_TYPE_PLA)
	generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
		pla_ocp_read(tp, index, sizeof(tmp), &tmp);
	else
		usb_ocp_read(tp, index, sizeof(tmp), &tmp);


	tmp = __le32_to_cpu(tmp) & ~mask;
	data |= __le32_to_cpu(tmp) & ~mask;
	tmp |= data;
	tmp = __cpu_to_le32(data);
	tmp = __cpu_to_le32(tmp);


	if (type == MCU_TYPE_PLA)
	generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
		pla_ocp_write(tp, index, byen, sizeof(tmp), &tmp);
	else
		usb_ocp_write(tp, index, byen, sizeof(tmp), &tmp);
}
}


static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)
static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)
{
{
	u32 data;
	u32 data;
	__le32 tmp;
	u8 shift = index & 3;
	u8 shift = index & 3;


	index &= ~3;
	index &= ~3;


	if (type == MCU_TYPE_PLA)
	generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
		pla_ocp_read(tp, index, sizeof(data), &data);
	else
		usb_ocp_read(tp, index, sizeof(data), &data);


	data = __le32_to_cpu(data);
	data = __le32_to_cpu(tmp);
	data >>= (shift * 8);
	data >>= (shift * 8);
	data &= 0xff;
	data &= 0xff;


@@ -602,7 +588,8 @@ static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)


static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
{
{
	u32 tmp, mask = 0xff;
	u32 mask = 0xff;
	__le32 tmp;
	u16 byen = BYTE_EN_BYTE;
	u16 byen = BYTE_EN_BYTE;
	u8 shift = index & 3;
	u8 shift = index & 3;


@@ -615,19 +602,12 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
		index &= ~3;
		index &= ~3;
	}
	}


	if (type == MCU_TYPE_PLA)
	generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
		pla_ocp_read(tp, index, sizeof(tmp), &tmp);
	else
		usb_ocp_read(tp, index, sizeof(tmp), &tmp);


	tmp = __le32_to_cpu(tmp) & ~mask;
	data |= __le32_to_cpu(tmp) & ~mask;
	tmp |= data;
	tmp = __cpu_to_le32(data);
	tmp = __cpu_to_le32(tmp);


	if (type == MCU_TYPE_PLA)
	generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
		pla_ocp_write(tp, index, byen, sizeof(tmp), &tmp);
	else
		usb_ocp_write(tp, index, byen, sizeof(tmp), &tmp);
}
}


static void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
static void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)