1 // SPDX-License-Identifier: GPL-2.0-only
3 * Radio tuning for Maxim max2820 on RTL8180
5 * Copyright 2007 Andrea Merello <andrea.merello@gmail.com>
7 * Code from the BSD driver and the rtl8181 project have been
8 * very useful to understand certain things
10 * I want to thanks the Authors of such projects and the Ndiswrapper
13 * A special Big Thanks also is for all people who donated me cards,
14 * making possible the creation of the original rtl8180 driver
15 * from which this code is derived!
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <net/mac80211.h>
25 static const u32 max2820_chan
[] = {
42 static void write_max2820(struct ieee80211_hw
*dev
, u8 addr
, u32 data
)
44 struct rtl8180_priv
*priv
= dev
->priv
;
47 phy_config
= 0x90 + (data
& 0xf);
51 phy_config
+= (data
>> 4) & 0xff;
53 rtl818x_iowrite32(priv
,
54 (__le32 __iomem
*) &priv
->map
->RFPinsOutput
, phy_config
);
59 static void max2820_write_phy_antenna(struct ieee80211_hw
*dev
, short chan
)
61 struct rtl8180_priv
*priv
= dev
->priv
;
65 if (priv
->rfparam
& RF_PARAM_ANTBDEFAULT
)
68 ant
|= BB_ANTATTEN_CHAN14
;
70 rtl8180_write_phy(dev
, 0x10, ant
);
73 static u8
max2820_rf_calc_rssi(u8 agc
, u8 sq
)
85 /* TODO: change addends above to avoid mult / div below */
86 return 65 * agc
/ 100;
89 static void max2820_rf_set_channel(struct ieee80211_hw
*dev
,
90 struct ieee80211_conf
*conf
)
92 struct rtl8180_priv
*priv
= dev
->priv
;
94 ieee80211_frequency_to_channel(conf
->chandef
.chan
->center_freq
) : 1;
95 unsigned int chan_idx
= channel
- 1;
96 u32 txpw
= priv
->channels
[chan_idx
].hw_value
& 0xFF;
97 u32 chan
= max2820_chan
[chan_idx
];
99 /* While philips SA2400 drive the PA bias from
100 * sa2400, for MAXIM we do this directly from BB */
101 rtl8180_write_phy(dev
, 3, txpw
);
103 max2820_write_phy_antenna(dev
, channel
);
104 write_max2820(dev
, 3, chan
);
107 static void max2820_rf_stop(struct ieee80211_hw
*dev
)
109 rtl8180_write_phy(dev
, 3, 0x8);
110 write_max2820(dev
, 1, 0);
114 static void max2820_rf_init(struct ieee80211_hw
*dev
)
116 struct rtl8180_priv
*priv
= dev
->priv
;
118 /* MAXIM from netbsd driver */
119 write_max2820(dev
, 0, 0x007); /* test mode as indicated in datasheet */
120 write_max2820(dev
, 1, 0x01e); /* enable register */
121 write_max2820(dev
, 2, 0x001); /* synt register */
123 max2820_rf_set_channel(dev
, NULL
);
125 write_max2820(dev
, 4, 0x313); /* rx register */
127 /* PA is driven directly by the BB, we keep the MAXIM bias
128 * at the highest value in case that setting it to lower
129 * values may introduce some further attenuation somewhere..
131 write_max2820(dev
, 5, 0x00f);
133 /* baseband configuration */
134 rtl8180_write_phy(dev
, 0, 0x88); /* sys1 */
135 rtl8180_write_phy(dev
, 3, 0x08); /* txagc */
136 rtl8180_write_phy(dev
, 4, 0xf8); /* lnadet */
137 rtl8180_write_phy(dev
, 5, 0x90); /* ifagcinit */
138 rtl8180_write_phy(dev
, 6, 0x1a); /* ifagclimit */
139 rtl8180_write_phy(dev
, 7, 0x64); /* ifagcdet */
141 max2820_write_phy_antenna(dev
, 1);
143 rtl8180_write_phy(dev
, 0x11, 0x88); /* trl */
145 if (rtl818x_ioread8(priv
, &priv
->map
->CONFIG2
) &
146 RTL818X_CONFIG2_ANTENNA_DIV
)
147 rtl8180_write_phy(dev
, 0x12, 0xc7);
149 rtl8180_write_phy(dev
, 0x12, 0x47);
151 rtl8180_write_phy(dev
, 0x13, 0x9b);
153 rtl8180_write_phy(dev
, 0x19, 0x0); /* CHESTLIM */
154 rtl8180_write_phy(dev
, 0x1a, 0x9f); /* CHSQLIM */
156 max2820_rf_set_channel(dev
, NULL
);
159 const struct rtl818x_rf_ops max2820_rf_ops
= {
161 .init
= max2820_rf_init
,
162 .stop
= max2820_rf_stop
,
163 .set_chan
= max2820_rf_set_channel
,
164 .calc_rssi
= max2820_rf_calc_rssi
,