Skip to content

Commit 6a7c924

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "Some bugfixes from I2C: - fix a uevent triggered boot problem by removing a useless debug print - fix sysfs-attributes of the new i2c-demux-pinctrl driver to follow standard kernel behaviour - fix a potential division-by-zero error (needed two takes)" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: jz4780: really prevent potential division by zero Revert "i2c: jz4780: prevent potential division by zero" i2c: jz4780: prevent potential division by zero i2c: mux: demux-pinctrl: Update docs to new sysfs-attributes i2c: mux: demux-pinctrl: Clean up sysfs attributes i2c: prevent endless uevent loop with CONFIG_I2C_DEBUG_CORE
2 parents 9f2394c + caf2808 commit 6a7c924

File tree

4 files changed

+49
-36
lines changed

4 files changed

+49
-36
lines changed
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
What: /sys/devices/platform/<i2c-demux-name>/cur_master
1+
What: /sys/devices/platform/<i2c-demux-name>/available_masters
22
Date: January 2016
33
KernelVersion: 4.6
44
Contact: Wolfram Sang <[email protected]>
55
Description:
6+
Reading the file will give you a list of masters which can be
7+
selected for a demultiplexed bus. The format is
8+
"<index>:<name>". Example from a Renesas Lager board:
69

7-
This file selects the active I2C master for a demultiplexed bus.
10+
0:/i2c@e6500000 1:/i2c@e6508000
811

9-
Write 0 there for the first master, 1 for the second etc. Reading the file will
10-
give you a list with the active master marked. Example from a Renesas Lager
11-
board:
12-
13-
root@Lager:~# cat /sys/devices/platform/i2c@8/cur_master
14-
* 0 - /i2c@9
15-
1 - /i2c@e6520000
16-
2 - /i2c@e6530000
17-
18-
root@Lager:~# echo 2 > /sys/devices/platform/i2c@8/cur_master
19-
20-
root@Lager:~# cat /sys/devices/platform/i2c@8/cur_master
21-
0 - /i2c@9
22-
1 - /i2c@e6520000
23-
* 2 - /i2c@e6530000
12+
What: /sys/devices/platform/<i2c-demux-name>/current_master
13+
Date: January 2016
14+
KernelVersion: 4.6
15+
Contact: Wolfram Sang <[email protected]>
16+
Description:
17+
This file selects/shows the active I2C master for a demultiplexed
18+
bus. It uses the <index> value from the file 'available_masters'.

drivers/i2c/busses/i2c-jz4780.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,16 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
771771
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
772772
&clk_freq);
773773
if (ret) {
774-
dev_err(&pdev->dev, "clock-frequency not specified in DT");
774+
dev_err(&pdev->dev, "clock-frequency not specified in DT\n");
775775
goto err;
776776
}
777777

778778
i2c->speed = clk_freq / 1000;
779+
if (i2c->speed == 0) {
780+
ret = -EINVAL;
781+
dev_err(&pdev->dev, "clock-frequency minimum is 1000\n");
782+
goto err;
783+
}
779784
jz4780_i2c_set_speed(i2c);
780785

781786
dev_info(&pdev->dev, "Bus frequency is %d KHz\n", i2c->speed);

drivers/i2c/i2c-core.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,22 +525,16 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
525525
return 0;
526526
}
527527

528-
529-
/* uevent helps with hotplug: modprobe -q $(MODALIAS) */
530528
static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
531529
{
532-
struct i2c_client *client = to_i2c_client(dev);
530+
struct i2c_client *client = to_i2c_client(dev);
533531
int rc;
534532

535533
rc = acpi_device_uevent_modalias(dev, env);
536534
if (rc != -ENODEV)
537535
return rc;
538536

539-
if (add_uevent_var(env, "MODALIAS=%s%s",
540-
I2C_MODULE_PREFIX, client->name))
541-
return -ENOMEM;
542-
dev_dbg(dev, "uevent\n");
543-
return 0;
537+
return add_uevent_var(env, "MODALIAS=%s%s", I2C_MODULE_PREFIX, client->name);
544538
}
545539

546540
/* i2c bus recovery routines */

drivers/i2c/muxes/i2c-demux-pinctrl.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,34 @@ static int i2c_demux_change_master(struct i2c_demux_pinctrl_priv *priv, u32 new_
140140
return i2c_demux_activate_master(priv, new_chan);
141141
}
142142

143-
static ssize_t cur_master_show(struct device *dev, struct device_attribute *attr,
144-
char *buf)
143+
static ssize_t available_masters_show(struct device *dev,
144+
struct device_attribute *attr,
145+
char *buf)
145146
{
146147
struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
147148
int count = 0, i;
148149

149150
for (i = 0; i < priv->num_chan && count < PAGE_SIZE; i++)
150-
count += scnprintf(buf + count, PAGE_SIZE - count, "%c %d - %s\n",
151-
i == priv->cur_chan ? '*' : ' ', i,
152-
priv->chan[i].parent_np->full_name);
151+
count += scnprintf(buf + count, PAGE_SIZE - count, "%d:%s%c",
152+
i, priv->chan[i].parent_np->full_name,
153+
i == priv->num_chan - 1 ? '\n' : ' ');
153154

154155
return count;
155156
}
157+
static DEVICE_ATTR_RO(available_masters);
156158

157-
static ssize_t cur_master_store(struct device *dev, struct device_attribute *attr,
158-
const char *buf, size_t count)
159+
static ssize_t current_master_show(struct device *dev,
160+
struct device_attribute *attr,
161+
char *buf)
162+
{
163+
struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
164+
165+
return sprintf(buf, "%d\n", priv->cur_chan);
166+
}
167+
168+
static ssize_t current_master_store(struct device *dev,
169+
struct device_attribute *attr,
170+
const char *buf, size_t count)
159171
{
160172
struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
161173
unsigned int val;
@@ -172,7 +184,7 @@ static ssize_t cur_master_store(struct device *dev, struct device_attribute *att
172184

173185
return ret < 0 ? ret : count;
174186
}
175-
static DEVICE_ATTR_RW(cur_master);
187+
static DEVICE_ATTR_RW(current_master);
176188

177189
static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
178190
{
@@ -218,12 +230,18 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
218230
/* switch to first parent as active master */
219231
i2c_demux_activate_master(priv, 0);
220232

221-
err = device_create_file(&pdev->dev, &dev_attr_cur_master);
233+
err = device_create_file(&pdev->dev, &dev_attr_available_masters);
222234
if (err)
223235
goto err_rollback;
224236

237+
err = device_create_file(&pdev->dev, &dev_attr_current_master);
238+
if (err)
239+
goto err_rollback_available;
240+
225241
return 0;
226242

243+
err_rollback_available:
244+
device_remove_file(&pdev->dev, &dev_attr_available_masters);
227245
err_rollback:
228246
for (j = 0; j < i; j++) {
229247
of_node_put(priv->chan[j].parent_np);
@@ -238,7 +256,8 @@ static int i2c_demux_pinctrl_remove(struct platform_device *pdev)
238256
struct i2c_demux_pinctrl_priv *priv = platform_get_drvdata(pdev);
239257
int i;
240258

241-
device_remove_file(&pdev->dev, &dev_attr_cur_master);
259+
device_remove_file(&pdev->dev, &dev_attr_current_master);
260+
device_remove_file(&pdev->dev, &dev_attr_available_masters);
242261

243262
i2c_demux_deactivate_master(priv);
244263

0 commit comments

Comments
 (0)