diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2014-02-10 13:18:36 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-13 12:34:49 -0500 |
commit | 58afc909772c9bffef24f20618693f64e7cfe96f (patch) | |
tree | 1a462ea7a46476e96bdf7c0ee64b052a595dd032 /drivers/tty/serial/max310x.c | |
parent | 5f529049cb044ed2cbea2599b246985912c0770d (diff) |
serial: max310x: Add devicetree support
This patch adds devicetree support for the MAX310X serial driver.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serial/max310x.c')
-rw-r--r-- | drivers/tty/serial/max310x.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index e27385438472..8a035d6b2d05 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/device.h> | 19 | #include <linux/device.h> |
20 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/of.h> | ||
23 | #include <linux/of_device.h> | ||
22 | #include <linux/regmap.h> | 24 | #include <linux/regmap.h> |
23 | #include <linux/serial_core.h> | 25 | #include <linux/serial_core.h> |
24 | #include <linux/serial.h> | 26 | #include <linux/serial.h> |
@@ -1093,7 +1095,7 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip, | |||
1093 | #endif | 1095 | #endif |
1094 | 1096 | ||
1095 | static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, | 1097 | static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, |
1096 | struct regmap *regmap, int irq) | 1098 | struct regmap *regmap, int irq, unsigned long flags) |
1097 | { | 1099 | { |
1098 | int i, ret, fmin, fmax, freq, uartclk; | 1100 | int i, ret, fmin, fmax, freq, uartclk; |
1099 | struct clk *clk_osc, *clk_xtal; | 1101 | struct clk *clk_osc, *clk_xtal; |
@@ -1237,8 +1239,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, | |||
1237 | 1239 | ||
1238 | /* Setup interrupt */ | 1240 | /* Setup interrupt */ |
1239 | ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, | 1241 | ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist, |
1240 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 1242 | IRQF_ONESHOT | flags, dev_name(dev), s); |
1241 | dev_name(dev), s); | ||
1242 | if (!ret) | 1243 | if (!ret) |
1243 | return 0; | 1244 | return 0; |
1244 | 1245 | ||
@@ -1284,6 +1285,15 @@ static int max310x_remove(struct device *dev) | |||
1284 | return ret; | 1285 | return ret; |
1285 | } | 1286 | } |
1286 | 1287 | ||
1288 | static const struct of_device_id __maybe_unused max310x_dt_ids[] = { | ||
1289 | { .compatible = "maxim,max3107", .data = &max3107_devtype, }, | ||
1290 | { .compatible = "maxim,max3108", .data = &max3108_devtype, }, | ||
1291 | { .compatible = "maxim,max3109", .data = &max3109_devtype, }, | ||
1292 | { .compatible = "maxim,max14830", .data = &max14830_devtype }, | ||
1293 | { } | ||
1294 | }; | ||
1295 | MODULE_DEVICE_TABLE(of, max310x_dt_ids); | ||
1296 | |||
1287 | static struct regmap_config regcfg = { | 1297 | static struct regmap_config regcfg = { |
1288 | .reg_bits = 8, | 1298 | .reg_bits = 8, |
1289 | .val_bits = 8, | 1299 | .val_bits = 8, |
@@ -1297,8 +1307,8 @@ static struct regmap_config regcfg = { | |||
1297 | #ifdef CONFIG_SPI_MASTER | 1307 | #ifdef CONFIG_SPI_MASTER |
1298 | static int max310x_spi_probe(struct spi_device *spi) | 1308 | static int max310x_spi_probe(struct spi_device *spi) |
1299 | { | 1309 | { |
1300 | struct max310x_devtype *devtype = | 1310 | struct max310x_devtype *devtype; |
1301 | (struct max310x_devtype *)spi_get_device_id(spi)->driver_data; | 1311 | unsigned long flags = 0; |
1302 | struct regmap *regmap; | 1312 | struct regmap *regmap; |
1303 | int ret; | 1313 | int ret; |
1304 | 1314 | ||
@@ -1310,10 +1320,22 @@ static int max310x_spi_probe(struct spi_device *spi) | |||
1310 | if (ret) | 1320 | if (ret) |
1311 | return ret; | 1321 | return ret; |
1312 | 1322 | ||
1323 | if (spi->dev.of_node) { | ||
1324 | const struct of_device_id *of_id = | ||
1325 | of_match_device(max310x_dt_ids, &spi->dev); | ||
1326 | |||
1327 | devtype = (struct max310x_devtype *)of_id->data; | ||
1328 | } else { | ||
1329 | const struct spi_device_id *id_entry = spi_get_device_id(spi); | ||
1330 | |||
1331 | devtype = (struct max310x_devtype *)id_entry->driver_data; | ||
1332 | flags = IRQF_TRIGGER_FALLING; | ||
1333 | } | ||
1334 | |||
1313 | regcfg.max_register = devtype->nr * 0x20 - 1; | 1335 | regcfg.max_register = devtype->nr * 0x20 - 1; |
1314 | regmap = devm_regmap_init_spi(spi, ®cfg); | 1336 | regmap = devm_regmap_init_spi(spi, ®cfg); |
1315 | 1337 | ||
1316 | return max310x_probe(&spi->dev, devtype, regmap, spi->irq); | 1338 | return max310x_probe(&spi->dev, devtype, regmap, spi->irq, flags); |
1317 | } | 1339 | } |
1318 | 1340 | ||
1319 | static int max310x_spi_remove(struct spi_device *spi) | 1341 | static int max310x_spi_remove(struct spi_device *spi) |
@@ -1332,9 +1354,10 @@ MODULE_DEVICE_TABLE(spi, max310x_id_table); | |||
1332 | 1354 | ||
1333 | static struct spi_driver max310x_uart_driver = { | 1355 | static struct spi_driver max310x_uart_driver = { |
1334 | .driver = { | 1356 | .driver = { |
1335 | .name = MAX310X_NAME, | 1357 | .name = MAX310X_NAME, |
1336 | .owner = THIS_MODULE, | 1358 | .owner = THIS_MODULE, |
1337 | .pm = &max310x_pm_ops, | 1359 | .of_match_table = of_match_ptr(max310x_dt_ids), |
1360 | .pm = &max310x_pm_ops, | ||
1338 | }, | 1361 | }, |
1339 | .probe = max310x_spi_probe, | 1362 | .probe = max310x_spi_probe, |
1340 | .remove = max310x_spi_remove, | 1363 | .remove = max310x_spi_remove, |