Blame view
drivers/gpio/gpio-max7301.c
2.49 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 |
|
85ac860a5 gpio: max7301: fi... |
27 |
return spi_write_then_read(spi, &word, sizeof(word), NULL, 0); |
0c36ec314 gpio: gpio driver... |
28 |
} |
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 |
word = 0x8000 | (reg << 8); |
85ac860a5 gpio: max7301: fi... |
38 39 |
ret = spi_write_then_read(spi, &word, sizeof(word), &word, sizeof(word)); |
0c36ec314 gpio: gpio driver... |
40 41 42 43 |
if (ret) return ret; return word & 0xff; } |
3836309d9 gpio: remove use ... |
44 |
static int max7301_probe(struct spi_device *spi) |
0c36ec314 gpio: gpio driver... |
45 46 |
{ struct max7301 *ts; |
e952805d2 gpio: add driver ... |
47 |
int ret; |
0c36ec314 gpio: gpio driver... |
48 |
|
e952805d2 gpio: add driver ... |
49 |
/* bits_per_word cannot be configured in platform data */ |
31eb4b554 gpio: max7301: Re... |
50 |
spi->bits_per_word = 16; |
0c36ec314 gpio: gpio driver... |
51 52 53 |
ret = spi_setup(spi); if (ret < 0) return ret; |
4cb06cd58 gpio: max7301: us... |
54 |
ts = devm_kzalloc(&spi->dev, sizeof(struct max7301), GFP_KERNEL); |
0c36ec314 gpio: gpio driver... |
55 56 |
if (!ts) return -ENOMEM; |
e952805d2 gpio: add driver ... |
57 58 59 |
ts->read = max7301_spi_read; ts->write = max7301_spi_write; ts->dev = &spi->dev; |
0c36ec314 gpio: gpio driver... |
60 |
|
e952805d2 gpio: add driver ... |
61 |
ret = __max730x_probe(ts); |
0c36ec314 gpio: gpio driver... |
62 63 |
return ret; } |
206210ce6 gpio: remove use ... |
64 |
static int max7301_remove(struct spi_device *spi) |
0c36ec314 gpio: gpio driver... |
65 |
{ |
e952805d2 gpio: add driver ... |
66 |
return __max730x_remove(&spi->dev); |
0c36ec314 gpio: gpio driver... |
67 |
} |
e952805d2 gpio: add driver ... |
68 69 70 71 72 |
static const struct spi_device_id max7301_id[] = { { "max7301", 0 }, { } }; MODULE_DEVICE_TABLE(spi, max7301_id); |
0c36ec314 gpio: gpio driver... |
73 74 |
static struct spi_driver max7301_driver = { .driver = { |
e952805d2 gpio: add driver ... |
75 |
.name = "max7301", |
0c36ec314 gpio: gpio driver... |
76 |
}, |
e952805d2 gpio: add driver ... |
77 |
.probe = max7301_probe, |
8283c4ff5 gpio: remove use ... |
78 |
.remove = max7301_remove, |
e952805d2 gpio: add driver ... |
79 |
.id_table = max7301_id, |
0c36ec314 gpio: gpio driver... |
80 81 82 83 84 85 |
}; static int __init max7301_init(void) { return spi_register_driver(&max7301_driver); } |
673c0c003 spi: core and gpi... |
86 87 88 89 |
/* register after spi postcore initcall and before * subsys initcalls that may rely on these GPIOs */ subsys_initcall(max7301_init); |
0c36ec314 gpio: gpio driver... |
90 91 92 93 94 |
static void __exit max7301_exit(void) { spi_unregister_driver(&max7301_driver); } |
0c36ec314 gpio: gpio driver... |
95 |
module_exit(max7301_exit); |
e952805d2 gpio: add driver ... |
96 |
MODULE_AUTHOR("Juergen Beisert, Wolfram Sang"); |
0c36ec314 gpio: gpio driver... |
97 |
MODULE_LICENSE("GPL v2"); |
e952805d2 gpio: add driver ... |
98 |
MODULE_DESCRIPTION("MAX7301 GPIO-Expander"); |