^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * smsc47m1.c - Part of lm_sensors, Linux kernel modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for hardware monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Supports the SMSC LPC47B27x, LPC47M10x, LPC47M112, LPC47M13x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * LPC47M14x, LPC47M15x, LPC47M192, LPC47M292 and LPC47M997
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Super-I/O chips.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2004-2007 Jean Delvare <jdelvare@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * and Jean Delvare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static unsigned short force_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) module_param(force_id, ushort, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) MODULE_PARM_DESC(force_id, "Override the detected device ID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DRVNAME "smsc47m1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) enum chips { smsc47m1, smsc47m2 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Super-I/0 registers and commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define REG 0x2e /* The register to read/write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define VAL 0x2f /* The value to read/write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) superio_outb(int reg, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) outb(reg, REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) outb(val, VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) superio_inb(int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) outb(reg, REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return inb(VAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* logical device for fans is 0x0A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define superio_select() superio_outb(0x07, 0x0A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) superio_enter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!request_muxed_region(REG, 2, DRVNAME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) outb(0x55, REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) superio_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) outb(0xAA, REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) release_region(REG, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define SUPERIO_REG_ACT 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SUPERIO_REG_BASE 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define SUPERIO_REG_DEVID 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define SUPERIO_REG_DEVREV 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Logical device registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define SMSC_EXTENT 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* nr is 0 or 1 in the macros below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define SMSC47M1_REG_ALARM 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define SMSC47M1_REG_TPIN(nr) (0x34 - (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define SMSC47M1_REG_PPIN(nr) (0x36 - (nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define SMSC47M1_REG_FANDIV 0x58
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static const u8 SMSC47M1_REG_FAN[3] = { 0x59, 0x5a, 0x6b };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static const u8 SMSC47M1_REG_FAN_PRELOAD[3] = { 0x5b, 0x5c, 0x6c };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static const u8 SMSC47M1_REG_PWM[3] = { 0x56, 0x57, 0x69 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define SMSC47M2_REG_ALARM6 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define SMSC47M2_REG_TPIN1 0x38
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define SMSC47M2_REG_TPIN2 0x37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SMSC47M2_REG_TPIN3 0x2d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SMSC47M2_REG_PPIN3 0x2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SMSC47M2_REG_FANDIV3 0x6a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define MIN_FROM_REG(reg, div) ((reg) >= 192 ? 0 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 983040 / ((192 - (reg)) * (div)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define FAN_FROM_REG(reg, div, preload) ((reg) <= (preload) || (reg) == 255 ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 0 : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 983040 / (((reg) - (preload)) * (div)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define DIV_FROM_REG(reg) (1 << (reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define PWM_FROM_REG(reg) (((reg) & 0x7E) << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define PWM_EN_FROM_REG(reg) ((~(reg)) & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define PWM_TO_REG(reg) (((reg) >> 1) & 0x7E)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct smsc47m1_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned short addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) enum chips type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned long last_updated; /* In jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u8 fan[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u8 fan_preload[3]; /* Register value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u8 fan_div[3]; /* Register encoding, shifted right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 alarms; /* Register encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 pwm[3]; /* Register value (bit 0 is disable) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct smsc47m1_sio_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) enum chips type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u8 activate; /* Remember initial device state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline int smsc47m1_read_value(struct smsc47m1_data *data, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return inb_p(data->addr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static inline void smsc47m1_write_value(struct smsc47m1_data *data, u8 reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) outb_p(value, data->addr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int i, fan_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) fan_nr = data->type == smsc47m2 ? 3 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) for (i = 0; i < fan_nr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) data->fan[i] = smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) SMSC47M1_REG_FAN[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) data->fan_preload[i] = smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) SMSC47M1_REG_FAN_PRELOAD[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) data->pwm[i] = smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) SMSC47M1_REG_PWM[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) i = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) data->fan_div[0] = (i >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) data->fan_div[1] = i >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) data->alarms = smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) SMSC47M1_REG_ALARM) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Clear alarms if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (data->alarms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) smsc47m1_write_value(data, SMSC47M1_REG_ALARM, 0xC0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (fan_nr >= 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) data->fan_div[2] = (smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) SMSC47M2_REG_FANDIV3) >> 4) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) data->alarms |= (smsc47m1_read_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) SMSC47M2_REG_ALARM6) & 0x40) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Clear alarm if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (data->alarms & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) smsc47m1_write_value(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) SMSC47M2_REG_ALARM6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) data->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static ssize_t fan_show(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * This chip (stupidly) stops monitoring fan speed if PWM is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * enabled and duty cycle is 0%. This is fine if the monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * and control concern the same fan, but troublesome if they are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * not (which could as well happen).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int rpm = (data->pwm[nr] & 0x7F) == 0x00 ? 0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) FAN_FROM_REG(data->fan[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) DIV_FROM_REG(data->fan_div[nr]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) data->fan_preload[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return sprintf(buf, "%d\n", rpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static ssize_t fan_min_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int rpm = MIN_FROM_REG(data->fan_preload[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) DIV_FROM_REG(data->fan_div[nr]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return sprintf(buf, "%d\n", rpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static ssize_t fan_div_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static ssize_t fan_alarm_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int bitnr = to_sensor_dev_attr(devattr)->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static ssize_t pwm_show(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[attr->index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static ssize_t pwm_en_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return sprintf(buf, "%d\n", PWM_EN_FROM_REG(data->pwm[attr->index]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t alarms_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return sprintf(buf, "%d\n", data->alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static ssize_t fan_min_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) long rpmdiv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) data->fan_preload[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * Note: we save and restore the fan minimum here, because its value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * determined in part by the fan clock divider. This follows the principle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * of least surprise; the user doesn't expect the fan minimum to change just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * because the divider changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static ssize_t fan_div_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) long new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u8 old_div = DIV_FROM_REG(data->fan_div[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) err = kstrtol(buf, 10, &new_div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (new_div == old_div) /* No change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) switch (new_div) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) data->fan_div[nr] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) data->fan_div[nr] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) data->fan_div[nr] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) data->fan_div[nr] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) switch (nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) tmp = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) & ~(0x03 << (4 + 2 * nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) tmp |= data->fan_div[nr] << (4 + 2 * nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) smsc47m1_write_value(data, SMSC47M1_REG_FANDIV, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) tmp = smsc47m1_read_value(data, SMSC47M2_REG_FANDIV3) & 0xCF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) tmp |= data->fan_div[2] << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) smsc47m1_write_value(data, SMSC47M2_REG_FANDIV3, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Preserve fan min */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) tmp = 192 - (old_div * (192 - data->fan_preload[nr])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) + new_div / 2) / new_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) data->fan_preload[nr] = clamp_val(tmp, 0, 191);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) data->fan_preload[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static ssize_t pwm_store(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) err = kstrtol(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (val < 0 || val > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) data->pwm[nr] &= 0x81; /* Preserve additional bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) data->pwm[nr] |= PWM_TO_REG(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) smsc47m1_write_value(data, SMSC47M1_REG_PWM[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) data->pwm[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static ssize_t pwm_en_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct device_attribute *devattr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int nr = attr->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) err = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (val > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) data->pwm[nr] &= 0xFE; /* preserve the other bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) data->pwm[nr] |= !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) smsc47m1_write_value(data, SMSC47M1_REG_PWM[nr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) data->pwm[nr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static SENSOR_DEVICE_ATTR_RO(fan1_alarm, fan_alarm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_en, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static SENSOR_DEVICE_ATTR_RO(fan2_alarm, fan_alarm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_en, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static SENSOR_DEVICE_ATTR_RW(fan3_div, fan_div, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static SENSOR_DEVICE_ATTR_RO(fan3_alarm, fan_alarm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_en, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static DEVICE_ATTR_RO(alarms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static ssize_t name_show(struct device *dev, struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct smsc47m1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return sprintf(buf, "%s\n", data->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static DEVICE_ATTR_RO(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static struct attribute *smsc47m1_attributes_fan1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) &sensor_dev_attr_fan1_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) &sensor_dev_attr_fan1_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) &sensor_dev_attr_fan1_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) &sensor_dev_attr_fan1_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static const struct attribute_group smsc47m1_group_fan1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) .attrs = smsc47m1_attributes_fan1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static struct attribute *smsc47m1_attributes_fan2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) &sensor_dev_attr_fan2_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) &sensor_dev_attr_fan2_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) &sensor_dev_attr_fan2_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) &sensor_dev_attr_fan2_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static const struct attribute_group smsc47m1_group_fan2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) .attrs = smsc47m1_attributes_fan2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static struct attribute *smsc47m1_attributes_fan3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) &sensor_dev_attr_fan3_input.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) &sensor_dev_attr_fan3_min.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) &sensor_dev_attr_fan3_div.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) &sensor_dev_attr_fan3_alarm.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static const struct attribute_group smsc47m1_group_fan3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .attrs = smsc47m1_attributes_fan3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static struct attribute *smsc47m1_attributes_pwm1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) &sensor_dev_attr_pwm1.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) &sensor_dev_attr_pwm1_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static const struct attribute_group smsc47m1_group_pwm1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) .attrs = smsc47m1_attributes_pwm1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static struct attribute *smsc47m1_attributes_pwm2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) &sensor_dev_attr_pwm2.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) &sensor_dev_attr_pwm2_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static const struct attribute_group smsc47m1_group_pwm2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) .attrs = smsc47m1_attributes_pwm2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static struct attribute *smsc47m1_attributes_pwm3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) &sensor_dev_attr_pwm3.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) &sensor_dev_attr_pwm3_enable.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static const struct attribute_group smsc47m1_group_pwm3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) .attrs = smsc47m1_attributes_pwm3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static struct attribute *smsc47m1_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) &dev_attr_alarms.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) &dev_attr_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static const struct attribute_group smsc47m1_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) .attrs = smsc47m1_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) unsigned short addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) err = superio_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * SMSC LPC47M10x/LPC47M112/LPC47M13x (device id 0x59), LPC47M14x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * (device id 0x5F) and LPC47B27x (device id 0x51) have fan control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * The LPC47M15x and LPC47M192 chips "with hardware monitoring block"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * can do much more besides (device id 0x60).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * The LPC47M997 is undocumented, but seems to be compatible with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * the LPC47M192, and has the same device id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * The LPC47M292 (device id 0x6B) is somewhat compatible, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * supports a 3rd fan, and the pin configuration registers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * unfortunately different.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * The LPC47M233 has the same device id (0x6B) but is not compatible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * We check the high bit of the device revision register to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * differentiate them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) case 0x51:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) pr_info("Found SMSC LPC47B27x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) sio_data->type = smsc47m1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) case 0x59:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) pr_info("Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) sio_data->type = smsc47m1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) case 0x5F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) pr_info("Found SMSC LPC47M14x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) sio_data->type = smsc47m1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) case 0x60:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) pr_info("Found SMSC LPC47M15x/LPC47M192/LPC47M997\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) sio_data->type = smsc47m1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) case 0x6B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (superio_inb(SUPERIO_REG_DEVREV) & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) pr_debug("Found SMSC LPC47M233, unsupported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) superio_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) pr_info("Found SMSC LPC47M292\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) sio_data->type = smsc47m2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) superio_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) superio_select();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) addr = (superio_inb(SUPERIO_REG_BASE) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) | superio_inb(SUPERIO_REG_BASE + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (addr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) pr_info("Device address not set, will not use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) superio_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * Enable only if address is set (needed at least on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * Compaq Presario S4000NX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sio_data->activate = superio_inb(SUPERIO_REG_ACT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if ((sio_data->activate & 0x01) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) pr_info("Enabling device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) superio_outb(SUPERIO_REG_ACT, sio_data->activate | 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) superio_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* Restore device to its initial state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if ((sio_data->activate & 0x01) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (!superio_enter()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) superio_select();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) pr_info("Disabling device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) superio_outb(SUPERIO_REG_ACT, sio_data->activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) superio_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) pr_warn("Failed to disable device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) #define CHECK 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) #define REQUEST 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * This function can be used to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * - test for resource conflicts with ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * - request the resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * We only allocate the I/O ports we really need, to minimize the risk of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * conflicts with ACPI or with other drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static int __init smsc47m1_handle_resources(unsigned short address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) enum chips type, int action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static const u8 ports_m1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* register, region length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 0x04, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 0x33, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 0x56, 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static const u8 ports_m2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* register, region length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 0x04, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 0x09, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 0x2c, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 0x35, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 0x56, 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 0x69, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int i, ports_size, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) const u8 *ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) case smsc47m1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) ports = ports_m1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) ports_size = ARRAY_SIZE(ports_m1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) case smsc47m2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ports = ports_m2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) ports_size = ARRAY_SIZE(ports_m2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) for (i = 0; i + 1 < ports_size; i += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) unsigned short start = address + ports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) unsigned short len = ports[i + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) case CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /* Only check for conflicts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) err = acpi_check_region(start, len, DRVNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) case REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* Request the resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (!devm_request_region(dev, start, len, DRVNAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) "Region 0x%hx-0x%hx already in use!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) start, start + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static void smsc47m1_remove_files(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) sysfs_remove_group(&dev->kobj, &smsc47m1_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static int __init smsc47m1_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct smsc47m1_sio_data *sio_data = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct smsc47m1_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) int fan1, fan2, fan3, pwm1, pwm2, pwm3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static const char * const names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) "smsc47m1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) "smsc47m2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) res = platform_get_resource(pdev, IORESOURCE_IO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) err = smsc47m1_handle_resources(res->start, sio_data->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) REQUEST, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) data = devm_kzalloc(dev, sizeof(struct smsc47m1_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) data->addr = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) data->type = sio_data->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) data->name = names[sio_data->type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) platform_set_drvdata(pdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) * If no function is properly configured, there's no point in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * actually registering the chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) pwm1 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(0)) & 0x05)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) == 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) pwm2 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(1)) & 0x05)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) == 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (data->type == smsc47m2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) fan1 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) & 0x0d) == 0x09;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) fan2 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) & 0x0d) == 0x09;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) fan3 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) & 0x0d) == 0x0d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) pwm3 = (smsc47m1_read_value(data, SMSC47M2_REG_PPIN3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) & 0x0d) == 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) fan1 = (smsc47m1_read_value(data, SMSC47M1_REG_TPIN(0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) & 0x05) == 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) fan2 = (smsc47m1_read_value(data, SMSC47M1_REG_TPIN(1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) & 0x05) == 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) fan3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) pwm3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) dev_warn(dev, "Device not configured, will not use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * Some values (fan min, clock dividers, pwm registers) may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * needed before any update is triggered, so we better read them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * at least once here. We don't usually do it that way, but in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * this particular case, manually reading 5 registers out of 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) * doesn't make much sense and we're better using the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) smsc47m1_update_device(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* Register sysfs hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (fan1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) &smsc47m1_group_fan1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) dev_dbg(dev, "Fan 1 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (fan2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) &smsc47m1_group_fan2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) dev_dbg(dev, "Fan 2 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (fan3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) &smsc47m1_group_fan3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) } else if (data->type == smsc47m2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) dev_dbg(dev, "Fan 3 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (pwm1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) &smsc47m1_group_pwm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) dev_dbg(dev, "PWM 1 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (pwm2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) &smsc47m1_group_pwm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) dev_dbg(dev, "PWM 2 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (pwm3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) err = sysfs_create_group(&dev->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) &smsc47m1_group_pwm3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) } else if (data->type == smsc47m2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) dev_dbg(dev, "PWM 3 not enabled by hardware, skipping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) err = sysfs_create_group(&dev->kobj, &smsc47m1_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) data->hwmon_dev = hwmon_device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (IS_ERR(data->hwmon_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) err = PTR_ERR(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) goto error_remove_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) error_remove_files:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) smsc47m1_remove_files(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) static int __exit smsc47m1_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct smsc47m1_data *data = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) hwmon_device_unregister(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) smsc47m1_remove_files(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) static struct platform_driver smsc47m1_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) .name = DRVNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) .remove = __exit_p(smsc47m1_remove),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) static int __init smsc47m1_device_add(unsigned short address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) const struct smsc47m1_sio_data *sio_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) struct resource res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) .start = address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) .end = address + SMSC_EXTENT - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) .name = DRVNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) .flags = IORESOURCE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) err = smsc47m1_handle_resources(address, sio_data->type, CHECK, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) pdev = platform_device_alloc(DRVNAME, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (!pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) pr_err("Device allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) err = platform_device_add_resources(pdev, &res, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) pr_err("Device resource addition failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) goto exit_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) err = platform_device_add_data(pdev, sio_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) sizeof(struct smsc47m1_sio_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) pr_err("Platform data allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) goto exit_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) err = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) pr_err("Device addition failed (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) goto exit_device_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) exit_device_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) static int __init sm_smsc47m1_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) unsigned short address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct smsc47m1_sio_data sio_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) err = smsc47m1_find(&sio_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) address = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) /* Sets global pdev as a side effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) err = smsc47m1_device_add(address, &sio_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) err = platform_driver_probe(&smsc47m1_driver, smsc47m1_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) goto exit_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) exit_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) smsc47m1_restore(&sio_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) static void __exit sm_smsc47m1_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) platform_driver_unregister(&smsc47m1_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) smsc47m1_restore(dev_get_platdata(&pdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) MODULE_DESCRIPTION("SMSC LPC47M1xx fan sensors driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) module_init(sm_smsc47m1_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) module_exit(sm_smsc47m1_exit);