hwmon: vt8231: Introduce a #define for the driver name and use it
Subsystems (2)
PATCH 1/2 hwmon: vt8231: Introduce a #define for the driver name and use it
Make use of the cpp symbol DRIVER_NAME to set the driver's name and use it instead of all explicit usages of the same string. Also make use of it instead of vt8231_driver.driver.name which breaks a cyclic dependency between vt8231_probe() and vt8231_driver that in the next commit allows to drop some forward declarations.
--- drivers/hwmon/vt8231.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/hwmon/vt8231.c +8 -6
@@ -38,6 +38,8 @@ static struct platform_device *pdev;#define VT8231_BASE_REG 0x70#define VT8231_ENABLE_REG 0x74 +#define DRIVER_NAME "vt8231" +/* * The VT8231 registers *
@@ -753,7 +755,7 @@ static const struct attribute_group vt8231_group = {static struct platform_driver vt8231_driver = { .driver = { - .name ="vt8231" , + .name =DRIVER_NAME , }, .probe = vt8231_probe, .remove = vt8231_remove,
@@ -770,7 +772,7 @@ static int vt8231_pci_probe(struct pci_dev *dev, const struct pci_device_id *id);static struct pci_driver vt8231_pci_driver = { - .name ="vt8231" , + .name =DRIVER_NAME , .id_table = vt8231_pci_ids, .probe = vt8231_pci_probe, };
@@ -784,7 +786,7 @@ static int vt8231_probe(struct platform_device *pdev)/* Reserve the ISA region */ res =platform_get_resource (pdev,IORESOURCE_IO ,0 );if (!devm_request_region (&pdev->dev, res->start,VT8231_EXTENT , - vt8231_driver.driver.name)) { +DRIVER_NAME )) {dev_err (&pdev->dev,"Region 0x%lx-0x%lx already in use!\n" , (unsigned long )res->start, (unsigned long )res->end);return -ENODEV ;
@@ -796,7 +798,7 @@ static int vt8231_probe(struct platform_device *pdev)platform_set_drvdata (pdev, data); data->addr = res->start; - data->name ="vt8231" ; + data->name =DRIVER_NAME ;mutex_init (&data->update_lock);vt8231_init_device (data);
@@ -942,7 +944,7 @@ static int vt8231_device_add(unsigned short address)struct resource res = { .start = address, .end = address +VT8231_EXTENT -1 , - .name ="vt8231" , + .name =DRIVER_NAME , .flags =IORESOURCE_IO , };int err;
@@ -951,7 +953,7 @@ static int vt8231_device_add(unsigned short address)if (err) goto exit; - pdev =platform_device_alloc ("vt8231" , address); + pdev =platform_device_alloc (DRIVER_NAME , address);if (!pdev) { err = -ENOMEM ;pr_err ("Device allocation failed\n" );
base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
Signature · 1 line
2.37.2
PATCH 2/2 hwmon: vt8231: Reorder symbols to get rid of a few forward declarations
Declarations for static symbols are useless repetition unless there are cyclic dependencies.
Reorder the functions and variables to get rid of 5 forward declarations.
--- drivers/hwmon/vt8231.c | 188 ++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 97 deletions(-)
drivers/hwmon/vt8231.c +91 -97
@@ -164,10 +164,6 @@ struct vt8231_data { };static struct pci_dev *s_bridge; -static int vt8231_probe (struct platform_device *pdev); -static int vt8231_remove (struct platform_device *pdev); -static struct vt8231_data *vt8231_update_device (struct device *dev); -static void vt8231_init_device (struct vt8231_data *data);static inline int vt8231_read_value (struct vt8231_data *data,u8 reg) {
@@ -180,6 +176,74 @@ static inline void vt8231_write_value(struct vt8231_data *data, u8 reg,outb_p (value, data->addr + reg); } +static struct vt8231_data *vt8231_update_device (struct device *dev) +{ +struct vt8231_data *data =dev_get_drvdata (dev); +int i; +u16 low; + +mutex_lock (&data->update_lock); + +if (time_after (jiffies, data->last_updated +HZ +HZ /2 ) + || !data->valid) { +for (i =0 ; i <6 ; i++) { +if (ISVOLT (i, data->uch_config)) { + data->in[i] =vt8231_read_value (data, + regvolt[i]); + data->in_min[i] =vt8231_read_value (data, + regvoltmin[i]); + data->in_max[i] =vt8231_read_value (data, + regvoltmax[i]); + } + } +for (i =0 ; i <2 ; i++) { + data->fan[i] =vt8231_read_value (data, +VT8231_REG_FAN (i)); + data->fan_min[i] =vt8231_read_value (data, +VT8231_REG_FAN_MIN (i)); + } + + low =vt8231_read_value (data,VT8231_REG_TEMP_LOW01 ); + low = (low >>6 ) | ((low &0x30 ) >>2 ) + | (vt8231_read_value (data,VT8231_REG_TEMP_LOW25 ) <<4 ); +for (i =0 ; i <6 ; i++) { +if (ISTEMP (i, data->uch_config)) { + data->temp[i] = (vt8231_read_value (data, + regtemp[i]) <<2 ) + | ((low >> (2 * i)) &0x03 ); + data->temp_max[i] =vt8231_read_value (data, + regtempmax[i]); + data->temp_min[i] =vt8231_read_value (data, + regtempmin[i]); + } + } + + i =vt8231_read_value (data,VT8231_REG_FANDIV ); + data->fan_div[0 ] = (i >>4 ) &0x03 ; + data->fan_div[1 ] = i >>6 ; + data->alarms =vt8231_read_value (data,VT8231_REG_ALARM1 ) | + (vt8231_read_value (data,VT8231_REG_ALARM2 ) <<8 ); + +/* Set alarm flags correctly */ +if (!data->fan[0 ] && data->fan_min[0 ]) + data->alarms |=0x40 ; +else if (data->fan[0 ] && !data->fan_min[0 ]) + data->alarms &= ~0x40 ; + +if (!data->fan[1 ] && data->fan_min[1 ]) + data->alarms |=0x80 ; +else if (data->fan[1 ] && !data->fan_min[1 ]) + data->alarms &= ~0x80 ; + + data->last_updated = jiffies; + data->valid = true; + } + +mutex_unlock (&data->update_lock); + +return data; +} +/* following are the sysfs callback functions */ static ssize_t in_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -753,29 +817,11 @@ static const struct attribute_group vt8231_group = { .attrs = vt8231_attributes, }; -static struct platform_driver vt8231_driver = { - .driver = { - .name =DRIVER_NAME , - }, - .probe = vt8231_probe, - .remove = vt8231_remove, -}; - -static const struct pci_device_id vt8231_pci_ids[] = { - {PCI_DEVICE (PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_8231_4 ) }, - {0 , } -}; - -MODULE_DEVICE_TABLE (pci, vt8231_pci_ids); - -static int vt8231_pci_probe (struct pci_dev *dev, -const struct pci_device_id *id); - -static struct pci_driver vt8231_pci_driver = { - .name =DRIVER_NAME , - .id_table = vt8231_pci_ids, - .probe = vt8231_pci_probe, -}; +static void vt8231_init_device (struct vt8231_data *data) +{ +vt8231_write_value (data,VT8231_REG_TEMP1_CONFIG ,0 ); +vt8231_write_value (data,VT8231_REG_TEMP2_CONFIG ,0 ); +}static int vt8231_probe (struct platform_device *pdev) {
@@ -865,79 +911,21 @@ static int vt8231_remove(struct platform_device *pdev)return 0 ; } -static void vt8231_init_device (struct vt8231_data *data) -{ -vt8231_write_value (data,VT8231_REG_TEMP1_CONFIG ,0 ); -vt8231_write_value (data,VT8231_REG_TEMP2_CONFIG ,0 ); -} - -static struct vt8231_data *vt8231_update_device (struct device *dev) -{ -struct vt8231_data *data =dev_get_drvdata (dev); -int i; -u16 low; - -mutex_lock (&data->update_lock); - -if (time_after (jiffies, data->last_updated +HZ +HZ /2 ) - || !data->valid) { -for (i =0 ; i <6 ; i++) { -if (ISVOLT (i, data->uch_config)) { - data->in[i] =vt8231_read_value (data, - regvolt[i]); - data->in_min[i] =vt8231_read_value (data, - regvoltmin[i]); - data->in_max[i] =vt8231_read_value (data, - regvoltmax[i]); - } - } -for (i =0 ; i <2 ; i++) { - data->fan[i] =vt8231_read_value (data, -VT8231_REG_FAN (i)); - data->fan_min[i] =vt8231_read_value (data, -VT8231_REG_FAN_MIN (i)); - } - low =vt8231_read_value (data,VT8231_REG_TEMP_LOW01 ); - low = (low >>6 ) | ((low &0x30 ) >>2 ) - | (vt8231_read_value (data,VT8231_REG_TEMP_LOW25 ) <<4 ); -for (i =0 ; i <6 ; i++) { -if (ISTEMP (i, data->uch_config)) { - data->temp[i] = (vt8231_read_value (data, - regtemp[i]) <<2 ) - | ((low >> (2 * i)) &0x03 ); - data->temp_max[i] =vt8231_read_value (data, - regtempmax[i]); - data->temp_min[i] =vt8231_read_value (data, - regtempmin[i]); - } - } - - i =vt8231_read_value (data,VT8231_REG_FANDIV ); - data->fan_div[0 ] = (i >>4 ) &0x03 ; - data->fan_div[1 ] = i >>6 ; - data->alarms =vt8231_read_value (data,VT8231_REG_ALARM1 ) | - (vt8231_read_value (data,VT8231_REG_ALARM2 ) <<8 ); - -/* Set alarm flags correctly */ -if (!data->fan[0 ] && data->fan_min[0 ]) - data->alarms |=0x40 ; -else if (data->fan[0 ] && !data->fan_min[0 ]) - data->alarms &= ~0x40 ; - -if (!data->fan[1 ] && data->fan_min[1 ]) - data->alarms |=0x80 ; -else if (data->fan[1 ] && !data->fan_min[1 ]) - data->alarms &= ~0x80 ; - - data->last_updated = jiffies; - data->valid = true; - } +static struct platform_driver vt8231_driver = { + .driver = { + .name =DRIVER_NAME , + }, + .probe = vt8231_probe, + .remove = vt8231_remove, +}; -mutex_unlock (&data->update_lock); +static const struct pci_device_id vt8231_pci_ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_8231_4 ) }, + {0 , } +}; -return data; -} +MODULE_DEVICE_TABLE (pci, vt8231_pci_ids);static int vt8231_device_add (unsigned short address) {
@@ -1042,6 +1030,12 @@ static int vt8231_pci_probe(struct pci_dev *dev,return -ENODEV ; } +static struct pci_driver vt8231_pci_driver = { + .name =DRIVER_NAME , + .id_table = vt8231_pci_ids, + .probe = vt8231_pci_probe, +}; +static int __init sm_vt8231_init (void ) {return pci_register_driver (&vt8231_pci_driver);
Signature · 1 line
2.37.2
Re: [PATCH 2/2] hwmon: vt8231: Reorder symbols to get rid of a few forward declarations
Quoted 6 lines · Uwe Kleine-König
Declarations for static symbols are useless repetition unless there are cyclic dependencies.
Reorder the functions and variables to get rid of 5 forward declarations.
Signed-off-by Uwe Kleine-König <[email protected]>
Applied to hwmon-next.
Thanks,
Guenter
Quoted 7 lines · Uwe Kleine-König
Make use of the cpp symbol
DRIVER_NAMEto set the driver's name and use it instead of all explicit usages of the same string. Also make use of it instead of vt8231_driver.driver.name which breaks a cyclic dependency betweenvt8231_probe()andvt8231_driverthat in the next commit allows to drop some forward declarations.Signed-off-by Uwe Kleine-König <[email protected]>
Applied to hwmon-next.
Thanks,
Guenter