@@ -27,6 +27,7 @@
#include <linux/slab.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h>
+#include <linux/spi/spi_bitbang.h>
#include <linux/of_spi.h>
#include <linux/pm_runtime.h>
@@ -560,6 +561,24 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
}
EXPORT_SYMBOL_GPL(spi_alloc_master);
+struct spi_master *spi_alloc_master_bitbang(struct device *dev,
+ struct spi_bitbang *bitbang)
+{
+ struct spi_master *master;
+
+ master = kzalloc(sizeof(struct spi_master), GFP_KERNEL);
+ if (!master)
+ return NULL;
+
+ device_initialize(&master->dev);
+ master->dev.class = &spi_master_class;
+ master->dev.parent = get_device(dev);
+ spi_master_set_devdata(master, bitbang);
+
+ return master;
+}
+EXPORT_SYMBOL_GPL(spi_alloc_master_bitbang);
+
/**
* spi_register_master - register SPI master controller
* @master: initialized master, originally from spi_alloc_master()
@@ -329,12 +329,17 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
if (status < 0)
return status;
- master = spi_alloc_master(&pdev->dev, sizeof *spi_gpio);
- if (!master) {
+ spi_gpio = kzalloc(sizeof(struct spi_gpio), GFP_KERNEL);
+ if (!spi_gpio) {
status = -ENOMEM;
goto gpio_free;
}
- spi_gpio = spi_master_get_devdata(master);
+
+ master = spi_alloc_master_bitbang(&pdev->dev, &spi_gpio->bitbang);
+ if (!master) {
+ status = -ENOMEM;
+ goto spi_gpio_free;
+ }
platform_set_drvdata(pdev, spi_gpio);
spi_gpio->pdev = pdev;
@@ -367,6 +372,8 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
status = spi_bitbang_start(&spi_gpio->bitbang);
if (status < 0) {
spi_master_put(spi_gpio->bitbang.master);
+spi_gpio_free:
+ kfree(spi_gpio);
gpio_free:
if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
gpio_free(SPI_MISO_GPIO);
@@ -391,6 +398,7 @@ static int __exit spi_gpio_remove(struct platform_device *pdev)
/* stop() unregisters child devices too */
status = spi_bitbang_stop(&spi_gpio->bitbang);
spi_master_put(spi_gpio->bitbang.master);
+ kfree(spi_gpio);
platform_set_drvdata(pdev, NULL);
@@ -336,7 +336,8 @@ static inline void spi_master_put(struct spi_master *master)
/* the spi driver core manages memory for the spi_master classdev */
extern struct spi_master *
spi_alloc_master(struct device *host, unsigned size);
-
+extern struct spi_master *
+spi_alloc_master_bitbang(struct device *host, struct spi_bitbang *bitbang);
extern int spi_register_master(struct spi_master *master);
extern void spi_unregister_master(struct spi_master *master);