Lines Matching +full:spi +full:- +full:present +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* MCP23S08 SPI GPIO driver */
8 #include <linux/spi/spi.h>
10 #include "pinctrl-mcp23s08.h"
18 * Driver data holds all the per-chip data.
29 struct spi_device *spi = to_spi_device(mcp->dev); in mcp23sxx_spi_write() local
31 struct spi_transfer t[2] = { { .tx_buf = &mcp->addr, .len = 1, }, in mcp23sxx_spi_write()
38 return spi_sync(spi, &m); in mcp23sxx_spi_write()
46 struct spi_device *spi = to_spi_device(mcp->dev); in mcp23sxx_spi_gather_write() local
48 struct spi_transfer t[3] = { { .tx_buf = &mcp->addr, .len = 1, }, in mcp23sxx_spi_gather_write()
57 return spi_sync(spi, &m); in mcp23sxx_spi_gather_write()
64 struct spi_device *spi = to_spi_device(mcp->dev); in mcp23sxx_spi_read() local
68 return -EINVAL; in mcp23sxx_spi_read()
70 tx[0] = mcp->addr | 0x01; in mcp23sxx_spi_read()
73 return spi_write_then_read(spi, tx, sizeof(tx), val, val_size); in mcp23sxx_spi_read()
89 switch (info->type) { in mcp23s08_spi_regmap_init()
91 mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d", addr); in mcp23s08_spi_regmap_init()
92 if (!mcp->chip.label) in mcp23s08_spi_regmap_init()
93 return -ENOMEM; in mcp23s08_spi_regmap_init()
97 return -ENOMEM; in mcp23s08_spi_regmap_init()
102 mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d", addr); in mcp23s08_spi_regmap_init()
103 if (!mcp->chip.label) in mcp23s08_spi_regmap_init()
104 return -ENOMEM; in mcp23s08_spi_regmap_init()
108 return -ENOMEM; in mcp23s08_spi_regmap_init()
113 mcp->chip.label = info->label; in mcp23s08_spi_regmap_init()
114 name = info->regmap->name; in mcp23s08_spi_regmap_init()
118 dev_err(dev, "invalid device type (%d)\n", info->type); in mcp23s08_spi_regmap_init()
119 return -EINVAL; in mcp23s08_spi_regmap_init()
122 mcp->reg_shift = info->reg_shift; in mcp23s08_spi_regmap_init()
123 mcp->chip.ngpio = info->ngpio; in mcp23s08_spi_regmap_init()
124 copy = devm_kmemdup(dev, info->regmap, sizeof(*info->regmap), GFP_KERNEL); in mcp23s08_spi_regmap_init()
126 return -ENOMEM; in mcp23s08_spi_regmap_init()
128 copy->name = name; in mcp23s08_spi_regmap_init()
130 mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, copy); in mcp23s08_spi_regmap_init()
131 if (IS_ERR(mcp->regmap)) in mcp23s08_spi_regmap_init()
132 dev_err(dev, "regmap init failed for %s\n", mcp->chip.label); in mcp23s08_spi_regmap_init()
133 return PTR_ERR_OR_ZERO(mcp->regmap); in mcp23s08_spi_regmap_init()
136 static int mcp23s08_probe(struct spi_device *spi) in mcp23s08_probe() argument
140 struct device *dev = &spi->dev; in mcp23s08_probe()
148 info = spi_get_device_match_data(spi); in mcp23s08_probe()
150 ret = device_property_read_u32(dev, "microchip,spi-present-mask", &v); in mcp23s08_probe()
152 ret = device_property_read_u32(dev, "mcp,spi-present-mask", &v); in mcp23s08_probe()
154 dev_err(dev, "missing spi-present-mask"); in mcp23s08_probe()
161 dev_err(dev, "invalid spi-present-mask"); in mcp23s08_probe()
162 return -ENODEV; in mcp23s08_probe()
169 return -ENOMEM; in mcp23s08_probe()
171 spi_set_drvdata(spi, data); in mcp23s08_probe()
174 data->mcp[addr] = &data->chip[--chips]; in mcp23s08_probe()
175 data->mcp[addr]->irq = spi->irq; in mcp23s08_probe()
177 ret = mcp23s08_spi_regmap_init(data->mcp[addr], dev, addr, info); in mcp23s08_probe()
181 data->mcp[addr]->pinctrl_desc.name = devm_kasprintf(dev, GFP_KERNEL, in mcp23s08_probe()
182 "mcp23xxx-pinctrl.%d", in mcp23s08_probe()
184 if (!data->mcp[addr]->pinctrl_desc.name) in mcp23s08_probe()
185 return -ENOMEM; in mcp23s08_probe()
187 ret = mcp23s08_probe_one(data->mcp[addr], dev, 0x40 | (addr << 1), in mcp23s08_probe()
188 info->type, -1); in mcp23s08_probe()
192 ngpio += data->mcp[addr]->chip.ngpio; in mcp23s08_probe()
194 data->ngpio = ngpio; in mcp23s08_probe()
227 MODULE_DEVICE_TABLE(spi, mcp23s08_ids);
255 * Register after SPI postcore initcall and before
266 MODULE_DESCRIPTION("MCP23S08 SPI GPIO driver");