+static ssize_t txpower_g_read_file(struct file *file, char __user *userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct bcm43xx_wldev *dev = file->private_data;
+ const size_t len = ARRAY_SIZE(big_buffer);
+ char *buf = big_buffer;
+ size_t pos = 0;
+ ssize_t res;
+ unsigned long flags;
+
+ mutex_lock(&big_buffer_mutex);
+ mutex_lock(&dev->wl->mutex);
+ spin_lock_irqsave(&dev->wl->irq_lock, flags);
+ if ((bcm43xx_status(dev) != BCM43xx_STAT_INITIALIZED) ||
+ !dev->started) {
+ fappend("Not initialized\n");
+ goto out;
+ }
+ if (dev->phy.type != BCM43xx_PHYTYPE_G) {
+ fappend("Device is not a G-PHY\n");
+ goto out;
+ }
+ fappend("Control: %s\n", dev->phy.manual_txpower_control ?
+ "MANUAL" : "AUTOMATIC");
+ fappend("Baseband attenuation: %u\n", dev->phy.bbatt.att);
+ fappend("Radio attenuation: %u\n", dev->phy.rfatt.att);
+ fappend("TX Mixer Gain: %s\n", (dev->phy.tx_control & BCM43xx_TXCTL_TXMIX) ?
+ "ON" : "OFF");
+ fappend("PA Gain 2dB: %s\n", (dev->phy.tx_control & BCM43xx_TXCTL_PA2DB) ?
+ "ON" : "OFF");
+ fappend("PA Gain 3dB: %s\n", (dev->phy.tx_control & BCM43xx_TXCTL_PA3DB) ?
+ "ON" : "OFF");
+ fappend("\n\n");
+ fappend("You can write to this file:\n");
+ fappend("Writing \"auto\" enables automatic txpower control.\n");
+ fappend("Writing the attenuation values as \"bbatt rfatt txmix pa2db pa3db\" "
+ "enables manual txpower control.\n");
+ fappend("Example: 5 4 0 0 1\n");
+ fappend("Enables manual control with Baseband attenuation 5, "
+ "Radio attenuation 4, No TX Mixer Gain, "
+ "No PA Gain 2dB, With PA Gain 3dB.\n");
+
+out:
+ spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
+ mutex_unlock(&dev->wl->mutex);
+ res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
+ mutex_unlock(&big_buffer_mutex);
+
+ return res;
+}
+
+static ssize_t txpower_g_write_file(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct bcm43xx_wldev *dev = file->private_data;
+ char *buf = big_buffer;
+ ssize_t buf_size;
+ ssize_t res;
+ unsigned long flags, phy_flags;
+
+ mutex_lock(&big_buffer_mutex);
+ buf_size = min(count, ARRAY_SIZE(big_buffer) - 1);
+ if (copy_from_user(buf, user_buf, buf_size)) {
+ res = -EFAULT;
+ goto out_unlock_bb;
+ }
+ mutex_lock(&dev->wl->mutex);
+ spin_lock_irqsave(&dev->wl->irq_lock, flags);
+ if ((bcm43xx_status(dev) != BCM43xx_STAT_INITIALIZED) ||
+ !dev->started) {
+ printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
+ res = -ENODEV;
+ goto out_unlock;
+ }
+ if (dev->phy.type != BCM43xx_PHYTYPE_G) {
+ printk(KERN_ERR PFX "debugfs: Device is not a G-PHY\n");
+ res = -ENODEV;
+ goto out_unlock;
+ }
+ if ((buf_size >= 4) && (memcmp(buf, "auto", 4) == 0)) {
+ /* Automatic control */
+ dev->phy.manual_txpower_control = 0;
+ bcm43xx_phy_xmitpower(dev);
+ } else {
+ int bbatt = 0, rfatt = 0, txmix = 0, pa2db = 0, pa3db = 0;
+ /* Manual control */
+ if (sscanf(buf, "%d %d %d %d %d", &bbatt, &rfatt,
+ &txmix, &pa2db, &pa3db) != 5) {
+ printk(KERN_INFO PFX "debugfs: invalid value for \"tx_power_g\"\n");
+ res = -EINVAL;
+ goto out_unlock;
+ }
+ bcm43xx_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
+ dev->phy.manual_txpower_control = 1;
+ dev->phy.bbatt.att = bbatt;
+ dev->phy.rfatt.att = rfatt;
+ dev->phy.tx_control = 0;
+ if (txmix)
+ dev->phy.tx_control |= BCM43xx_TXCTL_TXMIX;
+ if (pa2db)
+ dev->phy.tx_control |= BCM43xx_TXCTL_PA2DB;
+ if (pa3db)
+ dev->phy.tx_control |= BCM43xx_TXCTL_PA3DB;
+ bcm43xx_phy_lock(dev, phy_flags);
+ bcm43xx_radio_lock(dev);
+ bcm43xx_set_txpower_g(dev, &dev->phy.bbatt,
+ &dev->phy.rfatt, dev->phy.tx_control);
+ bcm43xx_radio_unlock(dev);
+ bcm43xx_phy_unlock(dev, phy_flags);
+ }
+ res = buf_size;
+out_unlock:
+ spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
+ mutex_unlock(&dev->wl->mutex);
+out_unlock_bb:
+ mutex_unlock(&big_buffer_mutex);
+
+ return res;
+}
+
+