pata_palmld.c (3149B)
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * drivers/ata/pata_palmld.c 4 * 5 * Driver for IDE channel in Palm LifeDrive 6 * 7 * Based on research of: 8 * Alex Osborne <ato@meshy.org> 9 * 10 * Rewrite for mainline: 11 * Marek Vasut <marek.vasut@gmail.com> 12 * 13 * Rewritten version based on pata_ixp4xx_cf.c: 14 * ixp4xx PATA/Compact Flash driver 15 * Copyright (C) 2006-07 Tower Technologies 16 * Author: Alessandro Zummo <a.zummo@towertech.it> 17 */ 18 19#include <linux/kernel.h> 20#include <linux/module.h> 21#include <linux/libata.h> 22#include <linux/irq.h> 23#include <linux/platform_device.h> 24#include <linux/delay.h> 25#include <linux/gpio/consumer.h> 26 27#include <scsi/scsi_host.h> 28 29#define DRV_NAME "pata_palmld" 30 31struct palmld_pata { 32 struct ata_host *host; 33 struct gpio_desc *power; 34 struct gpio_desc *reset; 35}; 36 37static struct scsi_host_template palmld_sht = { 38 ATA_PIO_SHT(DRV_NAME), 39}; 40 41static struct ata_port_operations palmld_port_ops = { 42 .inherits = &ata_sff_port_ops, 43 .sff_data_xfer = ata_sff_data_xfer32, 44 .cable_detect = ata_cable_40wire, 45}; 46 47static int palmld_pata_probe(struct platform_device *pdev) 48{ 49 struct palmld_pata *lda; 50 struct ata_port *ap; 51 void __iomem *mem; 52 struct device *dev = &pdev->dev; 53 int ret; 54 55 lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL); 56 if (!lda) 57 return -ENOMEM; 58 59 /* allocate host */ 60 lda->host = ata_host_alloc(dev, 1); 61 if (!lda->host) 62 return -ENOMEM; 63 64 /* remap drive's physical memory address */ 65 mem = devm_platform_ioremap_resource(pdev, 0); 66 if (!mem) 67 return -ENOMEM; 68 69 /* request and activate power and reset GPIOs */ 70 lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); 71 if (IS_ERR(lda->power)) 72 return PTR_ERR(lda->power); 73 lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 74 if (IS_ERR(lda->reset)) { 75 gpiod_set_value(lda->power, 0); 76 return PTR_ERR(lda->reset); 77 } 78 79 /* Assert reset to reset the drive */ 80 gpiod_set_value(lda->reset, 1); 81 msleep(30); 82 gpiod_set_value(lda->reset, 0); 83 msleep(30); 84 85 /* setup the ata port */ 86 ap = lda->host->ports[0]; 87 ap->ops = &palmld_port_ops; 88 ap->pio_mask = ATA_PIO4; 89 ap->flags |= ATA_FLAG_PIO_POLLING; 90 91 /* memory mapping voodoo */ 92 ap->ioaddr.cmd_addr = mem + 0x10; 93 ap->ioaddr.altstatus_addr = mem + 0xe; 94 ap->ioaddr.ctl_addr = mem + 0xe; 95 96 /* start the port */ 97 ata_sff_std_ports(&ap->ioaddr); 98 99 /* activate host */ 100 ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING, 101 &palmld_sht); 102 /* power down on failure */ 103 if (ret) { 104 gpiod_set_value(lda->power, 0); 105 return ret; 106 } 107 108 platform_set_drvdata(pdev, lda); 109 return 0; 110} 111 112static int palmld_pata_remove(struct platform_device *pdev) 113{ 114 struct palmld_pata *lda = platform_get_drvdata(pdev); 115 116 ata_platform_remove_one(pdev); 117 118 /* power down the HDD */ 119 gpiod_set_value(lda->power, 0); 120 121 return 0; 122} 123 124static struct platform_driver palmld_pata_platform_driver = { 125 .driver = { 126 .name = DRV_NAME, 127 }, 128 .probe = palmld_pata_probe, 129 .remove = palmld_pata_remove, 130}; 131 132module_platform_driver(palmld_pata_platform_driver); 133 134MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); 135MODULE_DESCRIPTION("PalmLD PATA driver"); 136MODULE_LICENSE("GPL"); 137MODULE_ALIAS("platform:" DRV_NAME);