17 #include <linux/errno.h>
23 #include <linux/slab.h>
28 #include <linux/module.h>
77 const unsigned char *
tx;
89 #define SPCON_DEFAULT (S3C2410_SPCON_MSTR | S3C2410_SPCON_SMOD_INT)
90 #define SPPIN_DEFAULT (S3C2410_SPPIN_KEEP)
94 return spi_master_get_devdata(sdev->
master);
124 static int s3c24xx_spi_update_state(
struct spi_device *spi,
144 dev_err(&spi->
dev,
"invalid bits-per-word (%d)\n", bpw);
168 dev_dbg(&spi->
dev,
"pre-scaler=%d (wanted %d, got %ld)\n",
169 div, hz, clk / (2 * (div + 1)));
178 static int s3c24xx_spi_setupxfer(
struct spi_device *spi,
185 ret = s3c24xx_spi_update_state(spi, t);
192 static int s3c24xx_spi_setup(
struct spi_device *spi)
202 dev_err(&spi->
dev,
"no memory for controller state\n");
212 ret = s3c24xx_spi_update_state(spi,
NULL);
221 spin_unlock(&hw->
bitbang.lock);
226 static void s3c24xx_spi_cleanup(
struct spi_device *spi)
236 #ifdef CONFIG_SPI_S3C24XX_FIQ
251 struct spi_fiq_code {
257 extern struct spi_fiq_code s3c24xx_spi_fiq_txrx;
258 extern struct spi_fiq_code s3c24xx_spi_fiq_tx;
259 extern struct spi_fiq_code s3c24xx_spi_fiq_rx;
267 static inline u32 ack_bit(
unsigned int irq)
287 struct spi_fiq_code *
code;
299 if (hw->
tx && !hw->
rx)
301 else if (hw->
rx && !hw->
tx)
321 code = &s3c24xx_spi_fiq_tx;
324 code = &s3c24xx_spi_fiq_rx;
327 code = &s3c24xx_spi_fiq_txrx;
335 ack_ptr = (
u32 *)&code->data[code->ack_offset];
336 *ack_ptr = ack_bit(hw->
irq);
356 static int s3c24xx_spi_fiqop(
void *
pw,
int release)
383 static inline void s3c24xx_spi_initfiq(
struct s3c24xx_spi *hw)
397 static inline bool s3c24xx_spi_usefiq(
struct s3c24xx_spi *hw)
399 return hw->
pdata->use_fiq;
409 static inline bool s3c24xx_spi_usingfiq(
struct s3c24xx_spi *spi)
415 static inline void s3c24xx_spi_initfiq(
struct s3c24xx_spi *
s) { }
416 static inline void s3c24xx_spi_tryfiq(
struct s3c24xx_spi *
s) { }
417 static inline bool s3c24xx_spi_usefiq(
struct s3c24xx_spi *
s) {
return false; }
418 static inline bool s3c24xx_spi_usingfiq(
struct s3c24xx_spi *
s) {
return false; }
431 init_completion(&hw->
done);
434 if (s3c24xx_spi_usefiq(hw) && t->
len >= 3)
435 s3c24xx_spi_tryfiq(hw);
462 if (!s3c24xx_spi_usingfiq(hw)) {
488 static void s3c24xx_spi_initialsetup(
struct s3c24xx_spi *hw)
501 if (hw->
set_cs == s3c24xx_spi_gpiocs)
504 if (hw->
pdata->gpio_setup)
518 if (master ==
NULL) {
519 dev_err(&pdev->
dev,
"No memory for spi_master\n");
524 hw = spi_master_get_devdata(master);
527 hw->
master = spi_master_get(master);
528 hw->
pdata = pdata = pdev->
dev.platform_data;
532 dev_err(&pdev->
dev,
"No platform data supplied\n");
537 platform_set_drvdata(pdev, hw);
538 init_completion(&hw->
done);
542 s3c24xx_spi_initfiq(hw);
555 hw->
bitbang.setup_transfer = s3c24xx_spi_setupxfer;
556 hw->
bitbang.chipselect = s3c24xx_spi_chipsel;
557 hw->
bitbang.txrx_bufs = s3c24xx_spi_txrx;
559 hw->
master->setup = s3c24xx_spi_setup;
560 hw->
master->cleanup = s3c24xx_spi_cleanup;
568 dev_err(&pdev->
dev,
"Cannot get IORESOURCE_MEM\n");
577 dev_err(&pdev->
dev,
"Cannot reserve region\n");
603 if (IS_ERR(hw->
clk)) {
605 err = PTR_ERR(hw->
clk);
620 dev_err(&pdev->
dev,
"Failed to get gpio for cs\n");
624 hw->
set_cs = s3c24xx_spi_gpiocs;
629 s3c24xx_spi_initialsetup(hw);
635 dev_err(&pdev->
dev,
"Failed to register SPI master\n");
642 if (hw->
set_cs == s3c24xx_spi_gpiocs)
660 spi_master_put(hw->
master);
668 struct s3c24xx_spi *hw = platform_get_drvdata(dev);
670 platform_set_drvdata(dev,
NULL);
680 if (hw->
set_cs == s3c24xx_spi_gpiocs)
686 spi_master_put(hw->
master);
693 static int s3c24xx_spi_suspend(
struct device *dev)
704 static int s3c24xx_spi_resume(
struct device *dev)
708 s3c24xx_spi_initialsetup(hw);
712 static const struct dev_pm_ops s3c24xx_spi_pmops = {
713 .
suspend = s3c24xx_spi_suspend,
714 .resume = s3c24xx_spi_resume,
717 #define S3C24XX_SPI_PMOPS &s3c24xx_spi_pmops
719 #define S3C24XX_SPI_PMOPS NULL
724 .probe = s3c24xx_spi_probe,
727 .name =
"s3c2410-spi",