Skip to content

Commit

Permalink
Merge tag 'w1-drv-6.14' of ssh://gitolite.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/krzk/linux-w1 into char-misc-next

Krzysztof writes:

1-Wire bus drivers for v6.14

1. ds2482: Add support for handling the VCC regulator supply and three
   more minor improvements/cleanups.

2. Constify 'struct bin_attribute' in all drivers.

3. W1 core: use sysfs_emit() instead of sprintf(), as preferred coding
   style.

* tag 'w1-drv-6.14' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/krzk/linux-w1:
  w1: core: use sysfs_emit() instead of sprintf()
  w1: ds28e04: Constify 'struct bin_attribute'
  w1: ds2805: Constify 'struct bin_attribute'
  w1: ds2781: Constify 'struct bin_attribute'
  w1: ds2780: Constify 'struct bin_attribute'
  w1: ds2438: Constify 'struct bin_attribute'
  w1: ds2433: Constify 'struct bin_attribute'
  w1: ds2431: Constify 'struct bin_attribute'
  w1: ds2430: Constify 'struct bin_attribute'
  w1: ds2413: Constify 'struct bin_attribute'
  w1: ds2408: Constify 'struct bin_attribute'
  w1: ds2406: Constify 'struct bin_attribute'
  w1: Constify 'struct bin_attribute'
  w1: ds2482: Fix datasheet URL
  w1: ds2482: Add regulator support
  w1: ds2482: switch to devm_kzalloc() from kzalloc()
  dt-bindings: w1: ds2482: Add vcc-supply property
  • Loading branch information
gregkh committed Jan 9, 2025
2 parents df7b2f2 + 419a40c commit b580b17
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 116 deletions.
2 changes: 2 additions & 0 deletions Documentation/devicetree/bindings/w1/maxim,ds2482.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ properties:
reg:
maxItems: 1

vcc-supply: true

required:
- compatible
- reg
Expand Down
26 changes: 12 additions & 14 deletions drivers/w1/masters/ds2482.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* It is a I2C to 1-wire bridge.
* There are two variations: -100 and -800, which have 1 or 8 1-wire ports.
* The complete datasheet can be obtained from MAXIM's website at:
* http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4382
* https://www.analog.com/en/products/ds2482-100.html
*/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/regulator/consumer.h>

#include <linux/w1.h>

Expand Down Expand Up @@ -445,25 +446,28 @@ static int ds2482_probe(struct i2c_client *client)
int err = -ENODEV;
int temp1;
int idx;
int ret;

if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
I2C_FUNC_SMBUS_BYTE))
return -ENODEV;

data = kzalloc(sizeof(struct ds2482_data), GFP_KERNEL);
if (!data) {
err = -ENOMEM;
goto exit;
}
data = devm_kzalloc(&client->dev, sizeof(struct ds2482_data), GFP_KERNEL);
if (!data)
return -ENOMEM;

ret = devm_regulator_get_enable(&client->dev, "vcc");
if (ret)
return dev_err_probe(&client->dev, ret, "Failed to enable regulator\n");

data->client = client;
i2c_set_clientdata(client, data);

/* Reset the device (sets the read_ptr to status) */
if (ds2482_send_cmd(data, DS2482_CMD_RESET) < 0) {
dev_warn(&client->dev, "DS2482 reset failed.\n");
goto exit_free;
return err;
}

/* Sleep at least 525ns to allow the reset to complete */
Expand All @@ -474,7 +478,7 @@ static int ds2482_probe(struct i2c_client *client)
if (temp1 != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) {
dev_warn(&client->dev, "DS2482 reset status "
"0x%02X - not a DS2482\n", temp1);
goto exit_free;
return err;
}

/* Detect the 8-port version */
Expand Down Expand Up @@ -516,9 +520,6 @@ static int ds2482_probe(struct i2c_client *client)
if (data->w1_ch[idx].pdev != NULL)
w1_remove_master_device(&data->w1_ch[idx].w1_bm);
}
exit_free:
kfree(data);
exit:
return err;
}

Expand All @@ -532,9 +533,6 @@ static void ds2482_remove(struct i2c_client *client)
if (data->w1_ch[idx].pdev != NULL)
w1_remove_master_device(&data->w1_ch[idx].w1_bm);
}

/* Free the memory */
kfree(data);
}

/*
Expand Down
10 changes: 5 additions & 5 deletions drivers/w1/slaves/w1_ds2406.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static ssize_t w1_f12_read_state(
struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
u8 w1_buf[6] = {W1_F12_FUNC_READ_STATUS, 7, 0, 0, 0, 0};
Expand Down Expand Up @@ -61,7 +61,7 @@ static ssize_t w1_f12_read_state(

static ssize_t w1_f12_write_output(
struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -95,22 +95,22 @@ static ssize_t w1_f12_write_output(
}

#define NB_SYSFS_BIN_FILES 2
static struct bin_attribute w1_f12_sysfs_bin_files[NB_SYSFS_BIN_FILES] = {
static const struct bin_attribute w1_f12_sysfs_bin_files[NB_SYSFS_BIN_FILES] = {
{
.attr = {
.name = "state",
.mode = 0444,
},
.size = 1,
.read = w1_f12_read_state,
.read_new = w1_f12_read_state,
},
{
.attr = {
.name = "output",
.mode = 0664,
},
.size = 1,
.write = w1_f12_write_output,
.write_new = w1_f12_write_output,
}
};

Expand Down
42 changes: 21 additions & 21 deletions drivers/w1/slaves/w1_ds2408.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ static int _read_reg(struct w1_slave *sl, u8 address, unsigned char *buf)
}

static ssize_t state_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf, loff_t off,
size_t count)
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
dev_dbg(&kobj_to_w1_slave(kobj)->dev,
"Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
Expand All @@ -77,7 +77,7 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
}

static ssize_t output_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
dev_dbg(&kobj_to_w1_slave(kobj)->dev,
Expand All @@ -90,7 +90,7 @@ static ssize_t output_read(struct file *filp, struct kobject *kobj,
}

static ssize_t activity_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
dev_dbg(&kobj_to_w1_slave(kobj)->dev,
Expand All @@ -103,8 +103,8 @@ static ssize_t activity_read(struct file *filp, struct kobject *kobj,
}

static ssize_t cond_search_mask_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
dev_dbg(&kobj_to_w1_slave(kobj)->dev,
"Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
Expand All @@ -117,7 +117,7 @@ static ssize_t cond_search_mask_read(struct file *filp, struct kobject *kobj,

static ssize_t cond_search_polarity_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
if (count != 1 || off != 0)
Expand All @@ -127,8 +127,8 @@ static ssize_t cond_search_polarity_read(struct file *filp,
}

static ssize_t status_control_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
if (count != 1 || off != 0)
return -EFAULT;
Expand Down Expand Up @@ -160,7 +160,7 @@ static bool optional_read_back_valid(struct w1_slave *sl, u8 expected)
#endif

static ssize_t output_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -210,7 +210,7 @@ static ssize_t output_write(struct file *filp, struct kobject *kobj,
* Writing to the activity file resets the activity latches.
*/
static ssize_t activity_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -240,8 +240,8 @@ static ssize_t activity_write(struct file *filp, struct kobject *kobj,
}

static ssize_t status_control_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
u8 w1_buf[4];
Expand Down Expand Up @@ -310,14 +310,14 @@ static int w1_f29_disable_test_mode(struct w1_slave *sl)
return res;
}

static BIN_ATTR_RO(state, 1);
static BIN_ATTR_RW(output, 1);
static BIN_ATTR_RW(activity, 1);
static BIN_ATTR_RO(cond_search_mask, 1);
static BIN_ATTR_RO(cond_search_polarity, 1);
static BIN_ATTR_RW(status_control, 1);
static const BIN_ATTR_RO(state, 1);
static const BIN_ATTR_RW(output, 1);
static const BIN_ATTR_RW(activity, 1);
static const BIN_ATTR_RO(cond_search_mask, 1);
static const BIN_ATTR_RO(cond_search_polarity, 1);
static const BIN_ATTR_RW(status_control, 1);

static struct bin_attribute *w1_f29_bin_attrs[] = {
static const struct bin_attribute *const w1_f29_bin_attrs[] = {
&bin_attr_state,
&bin_attr_output,
&bin_attr_activity,
Expand All @@ -328,7 +328,7 @@ static struct bin_attribute *w1_f29_bin_attrs[] = {
};

static const struct attribute_group w1_f29_group = {
.bin_attrs = w1_f29_bin_attrs,
.bin_attrs_new = w1_f29_bin_attrs,
};

static const struct attribute_group *w1_f29_groups[] = {
Expand Down
14 changes: 7 additions & 7 deletions drivers/w1/slaves/w1_ds2413.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#define W1_F3A_INVALID_PIO_STATE 0xFF

static ssize_t state_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf, loff_t off,
size_t count)
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
unsigned int retries = W1_F3A_RETRIES;
Expand Down Expand Up @@ -78,10 +78,10 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
return bytes_read;
}

static BIN_ATTR_RO(state, 1);
static const BIN_ATTR_RO(state, 1);

static ssize_t output_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -128,16 +128,16 @@ static ssize_t output_write(struct file *filp, struct kobject *kobj,
return bytes_written;
}

static BIN_ATTR(output, 0664, NULL, output_write, 1);
static const BIN_ATTR(output, 0664, NULL, output_write, 1);

static struct bin_attribute *w1_f3a_bin_attrs[] = {
static const struct bin_attribute *const w1_f3a_bin_attrs[] = {
&bin_attr_state,
&bin_attr_output,
NULL,
};

static const struct attribute_group w1_f3a_group = {
.bin_attrs = w1_f3a_bin_attrs,
.bin_attrs_new = w1_f3a_bin_attrs,
};

static const struct attribute_group *w1_f3a_groups[] = {
Expand Down
10 changes: 5 additions & 5 deletions drivers/w1/slaves/w1_ds2430.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int w1_f14_readblock(struct w1_slave *sl, int off, int count, char *buf)
}

static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -202,7 +202,7 @@ static int w1_f14_write(struct w1_slave *sl, int addr, int len, const u8 *data)
}

static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -263,15 +263,15 @@ static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
return count;
}

static BIN_ATTR_RW(eeprom, W1_F14_EEPROM_SIZE);
static const BIN_ATTR_RW(eeprom, W1_F14_EEPROM_SIZE);

static struct bin_attribute *w1_f14_bin_attrs[] = {
static const struct bin_attribute *const w1_f14_bin_attrs[] = {
&bin_attr_eeprom,
NULL,
};

static const struct attribute_group w1_f14_group = {
.bin_attrs = w1_f14_bin_attrs,
.bin_attrs_new = w1_f14_bin_attrs,
};

static const struct attribute_group *w1_f14_groups[] = {
Expand Down
10 changes: 5 additions & 5 deletions drivers/w1/slaves/w1_ds2431.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int w1_f2d_readblock(struct w1_slave *sl, int off, int count, char *buf)
}

static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -201,7 +201,7 @@ static int w1_f2d_write(struct w1_slave *sl, int addr, int len, const u8 *data)
}

static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct w1_slave *sl = kobj_to_w1_slave(kobj);
Expand Down Expand Up @@ -262,15 +262,15 @@ static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
return count;
}

static BIN_ATTR_RW(eeprom, W1_F2D_EEPROM_SIZE);
static const BIN_ATTR_RW(eeprom, W1_F2D_EEPROM_SIZE);

static struct bin_attribute *w1_f2d_bin_attrs[] = {
static const struct bin_attribute *const w1_f2d_bin_attrs[] = {
&bin_attr_eeprom,
NULL,
};

static const struct attribute_group w1_f2d_group = {
.bin_attrs = w1_f2d_bin_attrs,
.bin_attrs_new = w1_f2d_bin_attrs,
};

static const struct attribute_group *w1_f2d_groups[] = {
Expand Down
Loading

0 comments on commit b580b17

Please sign in to comment.