blob: 35aa158fc9763cee8a011da7e86996e8b7254d33 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Anton Vorontsov61f71622008-01-09 22:10:41 +03002/*
3 * OF-platform PATA driver
4 *
5 * Copyright (c) 2007 MontaVista Software, Inc.
6 * Anton Vorontsov <avorontsov@ru.mvista.com>
Anton Vorontsov61f71622008-01-09 22:10:41 +03007 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
Pawel Moll37210fb2011-09-07 13:36:26 +010011#include <linux/of_address.h>
Rob Herringd0643aa2011-12-22 15:07:00 -050012#include <linux/platform_device.h>
Jeff Garzik0a87e3e2008-02-01 18:02:30 -050013#include <linux/ata_platform.h>
Brian Norris84043ac2012-12-03 10:34:42 -080014#include <linux/libata.h>
Anton Vorontsov61f71622008-01-09 22:10:41 +030015
Akinobu Mita17263902015-01-29 08:30:30 +090016#define DRV_NAME "pata_of_platform"
17
18static struct scsi_host_template pata_platform_sht = {
19 ATA_PIO_SHT(DRV_NAME),
20};
21
Greg Kroah-Hartman0ec24912012-12-21 13:19:58 -080022static int pata_of_platform_probe(struct platform_device *ofdev)
Anton Vorontsov61f71622008-01-09 22:10:41 +030023{
24 int ret;
Grant Likely61c7a082010-04-13 16:12:29 -070025 struct device_node *dn = ofdev->dev.of_node;
Anton Vorontsov61f71622008-01-09 22:10:41 +030026 struct resource io_res;
27 struct resource ctl_res;
Rob Herringd0643aa2011-12-22 15:07:00 -050028 struct resource *irq_res;
Anton Vorontsov61f71622008-01-09 22:10:41 +030029 unsigned int reg_shift = 0;
30 int pio_mode = 0;
31 int pio_mask;
Alexander Shiyanf3d5e4f2019-01-19 07:52:01 +030032 bool use16bit;
Anton Vorontsov61f71622008-01-09 22:10:41 +030033
34 ret = of_address_to_resource(dn, 0, &io_res);
35 if (ret) {
36 dev_err(&ofdev->dev, "can't get IO address from "
37 "device tree\n");
38 return -EINVAL;
39 }
40
Alexander Shiyanca991402014-08-23 14:46:10 +040041 ret = of_address_to_resource(dn, 1, &ctl_res);
42 if (ret) {
43 dev_err(&ofdev->dev, "can't get CTL address from "
44 "device tree\n");
45 return -EINVAL;
Anton Vorontsov61f71622008-01-09 22:10:41 +030046 }
47
Rob Herringd0643aa2011-12-22 15:07:00 -050048 irq_res = platform_get_resource(ofdev, IORESOURCE_IRQ, 0);
Anton Vorontsov61f71622008-01-09 22:10:41 +030049
Kefeng Wang73b29512017-01-24 20:08:29 +080050 of_property_read_u32(dn, "reg-shift", &reg_shift);
Anton Vorontsov61f71622008-01-09 22:10:41 +030051
Kefeng Wang73b29512017-01-24 20:08:29 +080052 if (!of_property_read_u32(dn, "pio-mode", &pio_mode)) {
Anton Vorontsov61f71622008-01-09 22:10:41 +030053 if (pio_mode > 6) {
54 dev_err(&ofdev->dev, "invalid pio-mode\n");
55 return -EINVAL;
56 }
57 } else {
58 dev_info(&ofdev->dev, "pio-mode unspecified, assuming PIO0\n");
59 }
60
Alexander Shiyanf3d5e4f2019-01-19 07:52:01 +030061 use16bit = of_property_read_bool(dn, "ata-generic,use16bit");
62
Anton Vorontsov61f71622008-01-09 22:10:41 +030063 pio_mask = 1 << pio_mode;
64 pio_mask |= (1 << pio_mode) - 1;
65
Rob Herringd0643aa2011-12-22 15:07:00 -050066 return __pata_platform_probe(&ofdev->dev, &io_res, &ctl_res, irq_res,
Alexander Shiyanf3d5e4f2019-01-19 07:52:01 +030067 reg_shift, pio_mask, &pata_platform_sht,
68 use16bit);
Anton Vorontsov61f71622008-01-09 22:10:41 +030069}
70
Bhumika Goyale3779f62017-03-02 01:03:28 +053071static const struct of_device_id pata_of_platform_match[] = {
Anton Vorontsov61f71622008-01-09 22:10:41 +030072 { .compatible = "ata-generic", },
Alexander Shiyanca991402014-08-23 14:46:10 +040073 { },
Anton Vorontsov61f71622008-01-09 22:10:41 +030074};
75MODULE_DEVICE_TABLE(of, pata_of_platform_match);
76
Grant Likely1c48a5c2011-02-17 02:43:24 -070077static struct platform_driver pata_of_platform_driver = {
Grant Likely40182942010-04-13 16:13:02 -070078 .driver = {
Akinobu Mita17263902015-01-29 08:30:30 +090079 .name = DRV_NAME,
Grant Likely40182942010-04-13 16:13:02 -070080 .of_match_table = pata_of_platform_match,
81 },
Anton Vorontsov61f71622008-01-09 22:10:41 +030082 .probe = pata_of_platform_probe,
Brian Norris3e7068d2012-11-02 00:46:22 -070083 .remove = ata_platform_remove_one,
Anton Vorontsov61f71622008-01-09 22:10:41 +030084};
85
Axel Lin99c8ea32011-11-27 14:44:26 +080086module_platform_driver(pata_of_platform_driver);
Anton Vorontsov61f71622008-01-09 22:10:41 +030087
88MODULE_DESCRIPTION("OF-platform PATA driver");
89MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
90MODULE_LICENSE("GPL");