Merge tag 'chrome-platform-for-linus-4.13' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / net / dsa / lan9303_i2c.c
blobab3ce0da5071a1fe15d4943d84e1bed7bbb836a5
1 /*
2 * Copyright (C) 2017 Pengutronix, Juergen Borleis <kernel@pengutronix.de>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/i2c.h>
17 #include <linux/of.h>
19 #include "lan9303.h"
21 struct lan9303_i2c {
22 struct i2c_client *device;
23 struct lan9303 chip;
26 static const struct regmap_config lan9303_i2c_regmap_config = {
27 .reg_bits = 8,
28 .val_bits = 32,
29 .reg_stride = 1,
30 .can_multi_write = true,
31 .max_register = 0x0ff, /* address bits 0..1 are not used */
32 .reg_format_endian = REGMAP_ENDIAN_LITTLE,
34 .volatile_table = &lan9303_register_set,
35 .wr_table = &lan9303_register_set,
36 .rd_table = &lan9303_register_set,
38 .cache_type = REGCACHE_NONE,
41 static int lan9303_i2c_probe(struct i2c_client *client,
42 const struct i2c_device_id *id)
44 struct lan9303_i2c *sw_dev;
45 int ret;
47 sw_dev = devm_kzalloc(&client->dev, sizeof(struct lan9303_i2c),
48 GFP_KERNEL);
49 if (!sw_dev)
50 return -ENOMEM;
52 sw_dev->chip.regmap = devm_regmap_init_i2c(client,
53 &lan9303_i2c_regmap_config);
54 if (IS_ERR(sw_dev->chip.regmap)) {
55 ret = PTR_ERR(sw_dev->chip.regmap);
56 dev_err(&client->dev, "Failed to allocate register map: %d\n",
57 ret);
58 return ret;
61 /* link forward and backward */
62 sw_dev->device = client;
63 i2c_set_clientdata(client, sw_dev);
64 sw_dev->chip.dev = &client->dev;
66 ret = lan9303_probe(&sw_dev->chip, client->dev.of_node);
67 if (ret != 0)
68 return ret;
70 dev_info(&client->dev, "LAN9303 I2C driver loaded successfully\n");
72 return 0;
75 static int lan9303_i2c_remove(struct i2c_client *client)
77 struct lan9303_i2c *sw_dev;
79 sw_dev = i2c_get_clientdata(client);
80 if (!sw_dev)
81 return -ENODEV;
83 return lan9303_remove(&sw_dev->chip);
86 /*-------------------------------------------------------------------------*/
88 static const struct i2c_device_id lan9303_i2c_id[] = {
89 { "lan9303", 0 },
90 { /* sentinel */ }
92 MODULE_DEVICE_TABLE(i2c, lan9303_i2c_id);
94 static const struct of_device_id lan9303_i2c_of_match[] = {
95 { .compatible = "smsc,lan9303-i2c", },
96 { /* sentinel */ },
98 MODULE_DEVICE_TABLE(of, lan9303_i2c_of_match);
100 static struct i2c_driver lan9303_i2c_driver = {
101 .driver = {
102 .name = "LAN9303_I2C",
103 .of_match_table = of_match_ptr(lan9303_i2c_of_match),
105 .probe = lan9303_i2c_probe,
106 .remove = lan9303_i2c_remove,
107 .id_table = lan9303_i2c_id,
109 module_i2c_driver(lan9303_i2c_driver);
111 MODULE_AUTHOR("Juergen Borleis <kernel@pengutronix.de>");
112 MODULE_DESCRIPTION("Driver for SMSC/Microchip LAN9303 three port ethernet switch in I2C managed mode");
113 MODULE_LICENSE("GPL v2");