Blame view
drivers/gpio/gpio-max7301.c
2.7 KB
e952805d2 gpio: add driver ... |
1 |
/* |
0c36ec314 gpio: gpio driver... |
2 3 |
* Copyright (C) 2006 Juergen Beisert, Pengutronix * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix |
e952805d2 gpio: add driver ... |
4 |
* Copyright (C) 2009 Wolfram Sang, Pengutronix |
0c36ec314 gpio: gpio driver... |
5 6 7 8 9 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * |
e952805d2 gpio: add driver ... |
10 |
* Check max730x.c for further details. |
0c36ec314 gpio: gpio driver... |
11 |
*/ |
e952805d2 gpio: add driver ... |
12 |
#include <linux/module.h> |
0c36ec314 gpio: gpio driver... |
13 14 15 |
#include <linux/init.h> #include <linux/platform_device.h> #include <linux/mutex.h> |
5a0e3ad6a include cleanup: ... |
16 |
#include <linux/slab.h> |
0c36ec314 gpio: gpio driver... |
17 18 |
#include <linux/spi/spi.h> #include <linux/spi/max7301.h> |
0c36ec314 gpio: gpio driver... |
19 |
|
e952805d2 gpio: add driver ... |
20 21 22 |
/* A write to the MAX7301 means one message with one transfer */ static int max7301_spi_write(struct device *dev, unsigned int reg, unsigned int val) |
0c36ec314 gpio: gpio driver... |
23 |
{ |
e952805d2 gpio: add driver ... |
24 |
struct spi_device *spi = to_spi_device(dev); |
0c36ec314 gpio: gpio driver... |
25 |
u16 word = ((reg & 0x7F) << 8) | (val & 0xFF); |
e952805d2 gpio: add driver ... |
26 |
|
0c36ec314 gpio: gpio driver... |
27 28 |
return spi_write(spi, (const u8 *)&word, sizeof(word)); } |
e952805d2 gpio: add driver ... |
29 30 31 |
/* A read from the MAX7301 means two transfers; here, one message each */ static int max7301_spi_read(struct device *dev, unsigned int reg) |
0c36ec314 gpio: gpio driver... |
32 33 34 |
{ int ret; u16 word; |
e952805d2 gpio: add driver ... |
35 |
struct spi_device *spi = to_spi_device(dev); |
0c36ec314 gpio: gpio driver... |
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
word = 0x8000 | (reg << 8); ret = spi_write(spi, (const u8 *)&word, sizeof(word)); if (ret) return ret; /* * This relies on the fact, that a transfer with NULL tx_buf shifts out * zero bytes (=NOOP for MAX7301) */ ret = spi_read(spi, (u8 *)&word, sizeof(word)); if (ret) return ret; return word & 0xff; } |
0c36ec314 gpio: gpio driver... |
50 51 52 |
static int __devinit max7301_probe(struct spi_device *spi) { struct max7301 *ts; |
e952805d2 gpio: add driver ... |
53 |
int ret; |
0c36ec314 gpio: gpio driver... |
54 |
|
e952805d2 gpio: add driver ... |
55 |
/* bits_per_word cannot be configured in platform data */ |
0c36ec314 gpio: gpio driver... |
56 |
spi->bits_per_word = 16; |
0c36ec314 gpio: gpio driver... |
57 58 59 60 61 62 63 |
ret = spi_setup(spi); if (ret < 0) return ret; ts = kzalloc(sizeof(struct max7301), GFP_KERNEL); if (!ts) return -ENOMEM; |
e952805d2 gpio: add driver ... |
64 65 66 |
ts->read = max7301_spi_read; ts->write = max7301_spi_write; ts->dev = &spi->dev; |
0c36ec314 gpio: gpio driver... |
67 |
|
e952805d2 gpio: add driver ... |
68 |
ret = __max730x_probe(ts); |
c557fa3e4 gpio: max7301: fi... |
69 |
if (ret) |
e952805d2 gpio: add driver ... |
70 |
kfree(ts); |
0c36ec314 gpio: gpio driver... |
71 72 |
return ret; } |
de3483b07 gpio: max7301: ad... |
73 |
static int __devexit max7301_remove(struct spi_device *spi) |
0c36ec314 gpio: gpio driver... |
74 |
{ |
e952805d2 gpio: add driver ... |
75 |
return __max730x_remove(&spi->dev); |
0c36ec314 gpio: gpio driver... |
76 |
} |
e952805d2 gpio: add driver ... |
77 78 79 80 81 |
static const struct spi_device_id max7301_id[] = { { "max7301", 0 }, { } }; MODULE_DEVICE_TABLE(spi, max7301_id); |
0c36ec314 gpio: gpio driver... |
82 83 |
static struct spi_driver max7301_driver = { .driver = { |
e952805d2 gpio: add driver ... |
84 85 |
.name = "max7301", .owner = THIS_MODULE, |
0c36ec314 gpio: gpio driver... |
86 |
}, |
e952805d2 gpio: add driver ... |
87 88 89 |
.probe = max7301_probe, .remove = __devexit_p(max7301_remove), .id_table = max7301_id, |
0c36ec314 gpio: gpio driver... |
90 91 92 93 94 95 |
}; static int __init max7301_init(void) { return spi_register_driver(&max7301_driver); } |
673c0c003 spi: core and gpi... |
96 97 98 99 |
/* register after spi postcore initcall and before * subsys initcalls that may rely on these GPIOs */ subsys_initcall(max7301_init); |
0c36ec314 gpio: gpio driver... |
100 101 102 103 104 |
static void __exit max7301_exit(void) { spi_unregister_driver(&max7301_driver); } |
0c36ec314 gpio: gpio driver... |
105 |
module_exit(max7301_exit); |
e952805d2 gpio: add driver ... |
106 |
MODULE_AUTHOR("Juergen Beisert, Wolfram Sang"); |
0c36ec314 gpio: gpio driver... |
107 |
MODULE_LICENSE("GPL v2"); |
e952805d2 gpio: add driver ... |
108 |
MODULE_DESCRIPTION("MAX7301 GPIO-Expander"); |