2 * spi_parport.c - SPI master controller driver based on the parallel port adapter
4 * Copyright (C) 2008 Peter Henn <Peter.Henn@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * The spi_parport find its beginning in the spi_butterfly driver, but with the
21 * idea to isolate the SPI master controller part and move all additional SPI
22 * protocoll stuff into separate drivers.
23 * The most important settings can be given to the driver by module load parameter.
24 * Also the SPI-protocol driver can be configured by module load parameter. Make
25 * sure that all related SPI-protocol drivers are load before you load this SPI
27 * The SPI parport driver supports more than one SPI device. Therefore all module
28 * parameter can be given as an ARRAY with ',' as a delimiter. Starting from the
29 * first entry up to SPI_DEV_MAX devices will be handled. Therefore a successive
30 * chip selects will be reserved in the parport settings.
32 * Naturally this driver should normally use its gpio_parport base driver. But just
33 * to prevent additional performace issues I decice to finish this spi_parport.
34 * Both drivers may gives you also the possibility to use them hardware shared on
35 * one parport device, as long as you never use GPIO outputs in the gpio_parport from
36 * the parport data port and move the SPI control signals in the spi_parport driver
37 * to the parport control port - and visa verse, although its not a real software
38 * shared functionality.
40 #include <linux/kernel.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/device.h>
44 #include <linux/parport.h>
45 #include <linux/spinlock.h>
47 #include <linux/sched.h>
48 #include <linux/spi/spi.h>
49 #include <linux/spi/spi_bitbang.h>
51 #ifdef CONFIG_SPI_PARPORT_EXCLUSIVE
52 #define sCONFIG_SPI_PARPORT_EXCLUSIVE " CONFIG_SPI_PARPORT_EXCLUSIVE"
54 #define sCONFIG_SPI_PARPORT_EXCLUSIVE ""
58 * 0. Setup of the parport mode must be done. Therefore we read the
59 * supported modes: dev->dev->port->modes; Depending on the mode flags we change
60 * the mode value in the dev->dev->port->base_hi+0x02; Register, which is the ECR
61 * (extended control register). So first set to SPP (standard parport mode)
62 * 1. support better irq via array load parameter and values like AUTO, NONE. Additionally
63 * don't free any interrupt, if no interrupt might be requested
65 * Note: - SPI_LSB_FIRST is not yet supported and would need own txrx functions
66 * - SPI_LOOP is supported, but requires tx before rx in own transfer functions
67 * - SPI_3WIRE depends on signal routing, but is in principle possible
68 * and therefore supported.
69 * - SPI_CS_HIGH is supported
70 * - Slow CPU frequencies are currently not supported. The
71 * maximum Bit rate may be around 200 kBit/sec
73 * ToDo: - support also bits of the Control port
74 * - support more than one SPI controller
77 * Port Direction Register Name Signal
78 * ----------- --------- -------- ---------------------- ------
79 * nStrobe 1 --> nC0 PARPORT_CONTROL_STROBE
80 * D0 2 --> D0 (1 << 0) SCLK
81 * D1 3 --> D1 (1 << 1) MOSI
82 * D2 4 --> D2 (1 << 2) nCS0
83 * D3 5 --> D3 (1 << 3) nCS1
84 * D4 6 --> D4 (1 << 4) nCS2
85 * D5 7 --> D5 (1 << 5) nCS3
86 * D6 8 --> D6 (1 << 6) --
87 * D7 9 --> D7 (1 << 7) --
88 * nAckn 10 <-- S6 PARPORT_STATUS_ACK
89 * Busy 11 <-- nS7 PARPORT_STATUS_BUSY MISO
90 * Paper 12 <-- S5 PARPORT_STATUS_PAPEROUT --
91 * Sel 13 <-- S4 PARPORT_STATUS_SELECT --
92 * nFeed 14 --> nC1 PARPORT_CONTROL_AUTOFD --
93 * nError 15 <-- S3 PARPORT_STATUS_ERROR --
94 * nInit 16 --> C2 PARPORT_CONTROL_INIT --
95 * nSelIn 17 --> nC3 PARPORT_CONTROL_SELECT --
99 * - SCLK : SPI Master Clock
100 * - MOSI : SPI Master Data Output, Slave Data Input
101 * - MISO : SPI Master Date Input, Slave Data Output
102 * - nCSx : SPI Chip Select x, default low active
103 * Note: nCSx must be in consecutive bit order!
106 //*****************************************************************************
108 //*****************************************************************************
109 #define DRVNAME "spi_parport" /* name of the driver */
110 #define DRIVER_VERSION "0.3" /* helps identifying different versions of that driver */
112 #define SPI_PARPORT_SCLK (1 << 0) /* SPI Clock on parport D0 or pin 2 */
113 #define SPI_PARPORT_MOSI (1 << 1) /* SPI MOSI on parport D1 or pin 3 */
114 #define SPI_PARPORT_CS0 (1 << 2) /* first SPI chipselet on parport D2 or pin 4 */
115 #define SPI_PARPORT_MISO PARPORT_STATUS_BUSY /* SPI MISO on parport Status Busy or pin 11 */
117 #define SPI_PARPORT_STATUS_INV 0x80 /* invert internal bit 7 of status parport bit (Busy) */
118 #define SPI_PARPORT_CONTROL_INV 0x0b /* invert internal bit 0, 1 and 3 of control parport bits
119 (Strobe, Autofd, Select) */
121 #define SPI_PARPORT_MAX_SPEED 1*1000*1000 /* maximum allowed speed for any SPI device, currently not used */
122 #define SPI_DEV_MAX 4 /* maximum number of supported SPI devices and CS */
123 #define SPI_MODALIAS_LEN 32 /* spi protocol module alias name length, not defined in spi.h */
125 /* Module load parameter */
126 static int irq
=-1; /* force irq for parport pin 10 */
127 static char spi_modalias
[SPI_DEV_MAX
*(SPI_MODALIAS_LEN
+1)]="";
128 static unsigned int spi_mode
[SPI_DEV_MAX
] = {SPI_MODE_0
, SPI_MODE_0
, SPI_MODE_0
, SPI_MODE_0
};
129 static int spi_mode_cnt
= SPI_DEV_MAX
;
130 static unsigned int spi_bits
[SPI_DEV_MAX
] = {8, 8, 8, 8};
131 static int spi_bits_cnt
= SPI_DEV_MAX
;
134 struct spi_bitbang bitbang
; /* SPI bitbang controller data, must be the first item */
135 struct pardevice
*dev
; /* parport device entry */
136 struct parport
*port
; /* parport port entry */
137 u8 dcache
; /* parport data port mirror bits */
138 int irq
; /* parport interrupt */
139 struct list_head list
; /* spi_parport host controller list */
142 /* helps accessing the spi controller stucture */
143 static inline struct spi_parport
*spidev_to_pp(struct spi_device
*spi
)
145 return spi
->controller_data
;
147 /*----------------------------------------------------------------------*/
148 /* spi_parport to spi_bitbang interface functions */
151 ** parport data bit output function
153 static inline void spi_parport_data_set(struct spi_parport
*pp
, unsigned mask
, int value
)
155 u8 byte
= pp
->dcache
; // use old value from cache
160 pp
->dcache
= byte
; // restore cache
161 return parport_write_data(pp
->port
, byte
);
167 static inline void setsck(struct spi_device
*spi
, int value
)
169 struct spi_parport
*pp
= spidev_to_pp(spi
);
170 return spi_parport_data_set(pp
, SPI_PARPORT_SCLK
, value
);
176 static inline void setmosi(struct spi_device
*spi
, int value
)
178 struct spi_parport
*pp
= spidev_to_pp(spi
);
179 return spi_parport_data_set(pp
, SPI_PARPORT_MOSI
, value
);
182 /*----------------------------------------------------------------------*/
184 ** parport status bit input function
186 static inline int spi_parport_status_get(struct spi_parport
*pp
, unsigned mask
)
188 u8 byte
= SPI_PARPORT_STATUS_INV
^ parport_read_status(pp
->port
);
189 return ((byte
& mask
) != 0);
193 ** parport data bit input function, only need for loop back mode
194 ** Note: Neither the dcache is here updated nor the value is read from that dcache
195 ** to ensure similar system timing behavior as in standard MISO read mode.
197 static inline int spi_parport_data_get(struct spi_parport
*pp
, unsigned mask
)
199 u8 byte
= parport_read_data(pp
->port
);
200 return ((byte
& mask
) != 0);
205 ** supports also loop back mode in master controller
207 static inline int getmiso(struct spi_device
*spi
)
210 struct spi_parport
*pp
= spidev_to_pp(spi
);
211 if (spi
->mode
& SPI_LOOP
) {
212 /* Loop back mode, read direct from output port is possible, */
213 /* because setmosi will be done before getmiso in txrx */
214 value
= spi_parport_data_get(pp
, SPI_PARPORT_MOSI
);
216 /* default MISO read */
217 value
= spi_parport_status_get(pp
, SPI_PARPORT_MISO
);
224 ** sets corresponding CSx and CLK, depending on its polarity and mode
226 static void spi_parport_chipselect(struct spi_device
*spi
, int value
)
228 struct spi_parport
*pp
= spidev_to_pp(spi
);
229 /* set default clock polarity */
230 if (value
== BITBANG_CS_INACTIVE
) {
231 /* Deselect the slaves on the SPI bus by programming CS to inactive state */
232 spi_parport_data_set(pp
, SPI_PARPORT_CS0
<< spi
->chip_select
, (spi
->mode
& SPI_CS_HIGH
)==0);
233 } else if (value
== BITBANG_CS_ACTIVE
) {
234 /* Set the SPI clock phase and polarity */
235 setsck(spi
, (spi
->mode
& SPI_CPOL
)!=0);
236 /* Activate the chip select by programming CS to active state */
237 if ((spi
->chip_select
>= 0) && (spi
->chip_select
< SPI_DEV_MAX
)) {
238 spi_parport_data_set(pp
, SPI_PARPORT_CS0
<< spi
->chip_select
, (spi
->mode
& SPI_CS_HIGH
)!=0);
240 pr_err("%s: Use chip %sCS%d select out of range CS0 - CS%d\n",
241 DRVNAME
, ((spi
->mode
& SPI_CS_HIGH
)!=0)?
"":"/", spi
->chip_select
, SPI_DEV_MAX
);
246 /* use default TXRX bitbang interface functions from header file */
247 #define EXPAND_BITBANG_TXRX
249 /* currently we omit any additional delay, because parport is even slow.
250 Naturally for X > 10000, a delay would become more important */
251 #define spidelay(X) do{}while(0)
253 #include <linux/spi/spi_bitbang.h>
255 static u32
spi_parport_txrx_word_mode0(struct spi_device
*spi
,
259 return bitbang_txrx_be_cpha0(spi
, nsecs
, 0, word
, bits
);
262 static u32
spi_parport_txrx_word_mode1(struct spi_device
*spi
,
266 return bitbang_txrx_be_cpha1(spi
, nsecs
, 0, word
, bits
);
269 static u32
spi_parport_txrx_word_mode2(struct spi_device
*spi
,
273 return bitbang_txrx_be_cpha0(spi
, nsecs
, 1, word
, bits
);
276 static u32
spi_parport_txrx_word_mode3(struct spi_device
*spi
,
280 return bitbang_txrx_be_cpha1(spi
, nsecs
, 1, word
, bits
);
284 /*----------------------------------------------------------------------*/
286 ** copies src to dest string up to count characters or until a character is found
287 ** which matches the delim string set. As the return value will be returned the next
288 ** address of src, which can be used for the next stnarr of NULL if the found string
289 ** was longer than count.
291 const char *strnarr(char *dst
, const char *src
, const char *dlim
, size_t count
)
294 for(i
=0; i
<count
; i
++) {
299 if (strchr(dlim
, *src
)!=NULL
) {
305 *--dst
='\0'; /* add missing line end */
311 void parse_irqs(int nports
, const char *irqstr
, int irqval
[])
314 for (i
=0; i
<nports
&& irgstr
; i
++){
315 if (!strncmp(irqstr
, "auto", 4))
317 else if (!strncmp(irqstr
, "none", 4))
321 unsigned long r
= simple_strtoul(irqstr
, &ep
, 0);
325 printk("... bad irq specifier '%s'\n", irqstr
);
329 irqstr
= strchr(irqstr
, ',');
330 if (irqstr
) irqstr
++;
337 ** spi parport registers the SPI devices, defined by the given module load parameters.
338 ** Although the bit_per_word value is strongly recommended to set by the protocol driver
339 ** itself, spi_parport_register_spi_devices supports that for buggy drivers like the lm70.c
340 ** SPI temperature driver. But that requires using spi_add_device instead of spi_new_device
341 ** to ensure setting that bit_per_word value just before the protocol driver may change and
342 ** use that value for probing the connected SPI device hardware.
344 ** Additionally all SPI data structures will be first setup and all used spi chipselects will
345 ** be initialized to its inactive state before the spi_add_device is called. This ensures that
346 ** no early spi device usage by a spi protocol drivers probe sequence may toggle the spi clock,
347 ** although there might be another spi device at the bus, which has not yet properly setup its
348 ** chip select state as inactive.
350 static int spi_parport_register_spi_devices(struct spi_parport
*pp
)
352 const char *modalias_param
=spi_modalias
;
353 struct spi_device
*spi
[SPI_DEV_MAX
]; /* fill up here all settings instead using a board_info struct */
354 int i
; /* loop counter */
355 int max
; /* maximum loop value */
357 /* loop over all SPI device informations found in module parameter settings */
358 for (i
=0; (modalias_param
[0]!='\0') && (i
<SPI_DEV_MAX
); i
++) {
359 spi
[i
] = spi_alloc_device(pp
->bitbang
.master
); /* kzalloc memory and add device to master controller */
360 if (NULL
== spi
[i
]) {
362 spi_dev_put(spi
[--i
]); /* free all spi devices from former spi_alloc_device */
368 * first copy the modalias parameter
370 modalias_param
=strnarr(spi
[i
]->modalias
, modalias_param
, " ,", sizeof(spi
[i
]->modalias
));
371 if (NULL
== spi
[i
]->modalias
) {
372 pr_err("%s: %d given modalias name is too long! See only that '%s'!\n",
373 DRVNAME
, i
, spi
[i
]->modalias
);
375 spi_dev_put(spi
[i
--]); /* free all spi devices */
381 * now setup the rest as it would be done by
382 * the spi_new_device from a given board_info
385 spi
[i
]->max_speed_hz
= SPI_PARPORT_MAX_SPEED
;
386 spi
[i
]->chip_select
= i
;
387 spi
[i
]->master
= pp
->bitbang
.master
;
388 spi
[i
]->controller_data
= pp
; /* enable access to primary controller data */
389 spi
[i
]->controller_state
= NULL
; /* init state like in new_spi_device */
390 spi
[i
]->mode
= spi_mode
[i
];
391 spi
[i
]->irq
= pp
->irq
; /* TODO: separate IRQ setting */
392 spi
[i
]->bits_per_word
= spi_bits
[i
]; /* must normally be done by protocol driver */
393 spi
[i
]->dev
.platform_data
= (void *)NULL
; /* data area of SPI protocol driver,
394 hot plug drivers must do that itself */
396 * first only initialize the chipselect
397 * for that spi device to set it inactive
399 spi_parport_chipselect(spi
[i
], BITBANG_CS_INACTIVE
);
400 if (spi_mode_cnt
< (i
+1)) {
401 pr_warning("%s: No spi mode parameter given for device %d with driver '%s'. "
402 "Will use default setting: %d\n",
403 DRVNAME
, i
, spi
[i
]->modalias
, spi
[i
]->mode
);
406 /* additional parameter checks and possibly logged warnings */
407 if (modalias_param
[0]!='\0'){
408 pr_warning("%s: Found more modalias parameters of SPI devices than allowed (max: %d)!\n",
409 DRVNAME
, SPI_DEV_MAX
);
411 if (spi_mode_cnt
> i
) {
412 pr_warning("%s: Found further %d mode parameters than SPI devices used!\n",
413 DRVNAME
, spi_mode_cnt
-i
);
415 if (spi_bits_cnt
> i
) {
416 pr_warning("%s: Found further %d bits parameters than SPI devices used!\n",
417 DRVNAME
, spi_bits_cnt
-i
);
420 * Now all spi device structures are setup and all used
421 * chipselects are initialized. We will now add the
422 * spi devices for probing and usage. We use the same
425 max
= i
; /* remember the last value */
426 for (i
=0; i
<max
; i
++) {
429 err
= spi_add_device(spi
[i
]);
432 * free all further spi devices too.
433 * all already added spi devices will be freed
434 * later with the final call to spi_master_put
437 spi_dev_put(spi
[i
++]);
439 pr_err("%s: spi_new_device failed!\n", DRVNAME
);
442 pr_info("%s: SPI device successfully registered at bus %s as device %s with %d bits/word\n", DRVNAME
,
443 spi
[i
]->dev
.bus_id
, spi
[i
]->modalias
, spi
[i
]->bits_per_word
);
447 while ((modalias_param
[0]!='\0') && (i
<SPI_DEV_MAX
)) {
448 struct spi_device
*proxy
; /* just need to check spi device result and add additional settings */
449 struct spi_board_info chip
; /* parport SPI board description placeholder*/
451 modalias_param
=strnarr(chip
.modalias
, modalias_param
, " ,", sizeof(chip
.modalias
));
452 if (modalias_param
==NULL
) {
453 pr_err("%s: %d given modalias name is too long! See only that '%s'!\n", DRVNAME
, i
, chip
.modalias
);
458 * The modalias name MUST match the device_driver name
459 * for the bus glue code to match and subsequently bind them.
461 chip
.max_speed_hz
= SPI_PARPORT_MAX_SPEED
;
462 chip
.chip_select
= i
;
463 chip
.mode
= spi_mode
[i
];
465 chip
.controller_data
= pp
; /* enable access to primary controller data */
466 chip
.platform_data
= NULL
; /* data area of SPI protocol driver */
467 /* chip.bus_num = master->bus_num; // not needed for spi_new_device */
468 i
++; /* found new SPI protocol driver */
470 if (spi_mode_cnt
< i
) {
471 pr_warning("%s: No spi mode parameter given for device %d with driver '%s'. "
472 "Will use default setting: %d\n",
473 DRVNAME
, i
, chip
.modalias
, chip
.mode
);
475 pr_info("%s: Will load protocol driver: '%s' on CS%d with mode 0x%02x!\n",
476 DRVNAME
, chip
.modalias
, chip
.chip_select
, chip
.mode
);
479 * Register spi device from board info settings.
480 * Note that this will also call the probe inside the SPI protocall driver
482 proxy
= spi_new_device(pp
->bitbang
.master
, &chip
);
484 pr_err("%s: spi_new_device failed!\n", DRVNAME
);
487 pr_info("%s: SPI device successfully registered at bus %s as device %s with %d bits/word\n", DRVNAME
,
488 proxy
->dev
.bus_id
, chip
.modalias
, proxy
->bits_per_word
);
490 if (modalias_param
[0]!='\0'){
491 pr_warning("%s: Found more modalias parameters of SPI devices than allowed (max: %d)!\n",
492 DRVNAME
, SPI_DEV_MAX
);
498 /***************************************************************************
499 * Parallel port attaching and detaching routines *
500 ***************************************************************************/
502 static LIST_HEAD(spi_parport_hosts
);
505 ** If attaching the driver to parport is done with exclusive access, the driver
506 ** is still loaded, although the attach might not be done successful.
507 ** If you have already registered e.g. the lp driver, please unload any drivers
508 ** first as long as you use exclusive access.
510 static int __spi_parport_attach(struct parport
*pb
)
512 struct spi_master
*master
; /* is only temporary need */
513 struct device
*dev
= pb
->physport
->dev
;
514 struct spi_parport
*pp
;
521 /* spi_alloc_master gives zero initialized structure */
522 master
= spi_alloc_master(dev
, sizeof *pp
);
523 if (master
== NULL
) {
526 master
->bus_num
= -1; /* dynamic allocation of a bus number */
527 master
->num_chipselect
= SPI_DEV_MAX
; /* setup maximum capability */
529 /* call the container_of fkt */
530 pp
= spi_master_get_devdata(master
);
534 goto err_release_mem
;
537 /* ----------------- SPI BitBang Hook ---------------- */
538 /* use default setup(), cleanup(), and transfer() methods */
539 pp
->bitbang
.master
= spi_master_get(master
); /* now pp->bitbang.master = master */
540 pp
->bitbang
.chipselect
= spi_parport_chipselect
;
541 pp
->bitbang
.txrx_word
[SPI_MODE_0
] = spi_parport_txrx_word_mode0
;
542 pp
->bitbang
.txrx_word
[SPI_MODE_1
] = spi_parport_txrx_word_mode1
;
543 pp
->bitbang
.txrx_word
[SPI_MODE_2
] = spi_parport_txrx_word_mode2
;
544 pp
->bitbang
.txrx_word
[SPI_MODE_3
] = spi_parport_txrx_word_mode3
;
545 pp
->bitbang
.flags
= SPI_CS_HIGH
| SPI_3WIRE
| SPI_LOOP
; /* setup supported mode flags */
547 /* ----------------- ParPort Hook -------------------- */
548 /* REVISIT: no probe, just think it is there */
551 //ToDo: share parport with other device, but may need a mutex lock!
552 //ToDo: check supported modes are ok
553 //ToDo: PM support, e.g. Suspend and Resume
554 pp
->dev
= parport_register_device(pb
, /* port */
555 DRVNAME
, /* driver name */
556 NULL
, /* preemption fkt */
557 NULL
, /* wake-up fkt */
558 NULL
, /* no interrupt handler used */
559 #ifdef CONFIG_SPI_PARPORT_EXCLUSIVE
560 PARPORT_FLAG_EXCL
, /* flags */
562 0, /* flags, 0 means used port shared */
565 if (pp
->dev
== NULL
) {
566 pr_err("%s: unable to register with parport\n", DRVNAME
);
568 goto err_release_mem
;
571 err
= parport_claim(pp
->dev
);
573 pr_err("%s: unable to claim parport\n", DRVNAME
);
575 goto err_unregister_parport
;
578 /* ----------------- SPI ParPort init ---------------- */
579 /* cache initialization just preventing changing unused bits */
580 pp
->dcache
= parport_read_data(pp
->port
);
584 pr_info("%s: force usage IRQ %d\n", DRVNAME
, pp
->irq
);
585 if(pp
->port
->irq
== pp
->irq
) {
586 /* we free the standard parport handler, because we want to use our own later */
587 free_irq(pp
->irq
, pp
->port
);
588 pr_info("%s: Note parport driver will claim later irq as already freed during its module unload\n",
591 } else if(pp
->port
->irq
!= PARPORT_IRQ_NONE
) {
592 pp
->irq
= pp
->port
->irq
;
593 /* we free the standard parport handler, because we want to use our own later */
594 free_irq(pp
->irq
, pp
->port
);
595 pr_info("%s: will use IRQ %d exclusive\n", DRVNAME
, pp
->irq
);
596 pr_info("%s: Note parport driver will claim later irq as already freed during its module unload\n", DRVNAME
);
601 err
= spi_bitbang_start(&pp
->bitbang
);
603 pr_warning("%s: spi_bitbang_start failed with status %d\n",
605 goto err_release_parport
;
608 /* ----------------- SPI BoardInfo init -------------- */
609 err
= spi_parport_register_spi_devices(pp
);
611 pr_err("%s: at least one protocol driver name is needed, non found!\n", DRVNAME
);
613 goto err_spi_controller_stop
;
614 } else if (err
< 0) {
615 goto err_spi_controller_stop
;
617 list_add_tail(&pp
->list
, &spi_parport_hosts
);
620 err_spi_controller_stop
:
621 /* this will unregister child SPI devices too, if there any */
622 spi_bitbang_stop(&pp
->bitbang
);
624 parport_release(pp
->dev
);
625 err_unregister_parport
:
626 parport_unregister_device(pp
->dev
);
628 spi_master_put(master
); /* will release memory */
633 static void spi_parport_attach(struct parport
*pb
)
635 (void)__spi_parport_attach(pb
);
639 static int spi_parport_remove(struct spi_parport
*pp
)
643 /* stop and unregisters child devices too */
644 err
= spi_bitbang_stop(&pp
->bitbang
);
646 pr_err("%s: bitbang stop error: %d\n", DRVNAME
, err
);
648 parport_release(pp
->dev
);
649 parport_unregister_device(pp
->dev
);
650 /* this frees also the pp struct */
651 spi_master_put(pp
->bitbang
.master
);
655 static void spi_parport_detach(struct parport
*pb
)
657 struct spi_parport
*pp
;
659 list_for_each_entry(pp
, &spi_parport_hosts
, list
) {
660 if (pp
->port
== pb
) {
661 list_del_init(&pp
->list
);
662 (void)spi_parport_remove(pp
);
668 static struct parport_driver spi_parport_driver
= {
670 .attach
= spi_parport_attach
,
671 .detach
= spi_parport_detach
,
675 static int __init
spi_parport_init(void)
677 return parport_register_driver(&spi_parport_driver
);
679 device_initcall(spi_parport_init
);
681 static void __exit
spi_parport_exit(void)
683 parport_unregister_driver(&spi_parport_driver
);
685 module_exit(spi_parport_exit
);
687 MODULE_AUTHOR("Option Wireless");
688 MODULE_DESCRIPTION("SPI master controller driver for Parport Adapter");
689 MODULE_LICENSE("GPL");
691 module_param(irq
, uint
, S_IRUGO
);
692 MODULE_PARM_DESC(irq
, "Force IRQ for parport pin 10");
694 module_param_string(pdrv
, spi_modalias
, sizeof(spi_modalias
), S_IRUGO
);
695 MODULE_PARM_DESC(pdrv
, "array of spi protocol driver names");
697 module_param_array_named(mode
, spi_mode
, uint
, &spi_mode_cnt
, S_IRUGO
);
698 MODULE_PARM_DESC(mode
, "array of spi modes for each driver");
700 module_param_array_named(bits
, spi_bits
, uint
, &spi_bits_cnt
, S_IRUGO
);
701 MODULE_PARM_DESC(bits
, "array of spi bits per word for each driver");
703 MODULE_INFO(Flags
, sCONFIG_SPI_PARPORT_EXCLUSIVE
);
704 MODULE_INFO(Version
, DRIVER_VERSION
);