mm/slab: sanity-check page type when looking up cache
[linux/fpc-iii.git] / drivers / w1 / masters / matrox_w1.c
blob3110791a2f1cdd6831190c42b5caf5d1d956e981
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * matrox_w1.c
5 * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net>
6 */
8 #include <asm/types.h>
9 #include <linux/atomic.h>
10 #include <asm/io.h>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/list.h>
16 #include <linux/interrupt.h>
17 #include <linux/spinlock.h>
18 #include <linux/timer.h>
19 #include <linux/slab.h>
20 #include <linux/pci_ids.h>
21 #include <linux/pci.h>
23 #include <linux/w1.h>
26 * Matrox G400 DDC registers.
29 #define MATROX_G400_DDC_CLK (1<<4)
30 #define MATROX_G400_DDC_DATA (1<<1)
32 #define MATROX_BASE 0x3C00
33 #define MATROX_STATUS 0x1e14
35 #define MATROX_PORT_INDEX_OFFSET 0x00
36 #define MATROX_PORT_DATA_OFFSET 0x0A
38 #define MATROX_GET_CONTROL 0x2A
39 #define MATROX_GET_DATA 0x2B
40 #define MATROX_CURSOR_CTL 0x06
42 struct matrox_device
44 void __iomem *base_addr;
45 void __iomem *port_index;
46 void __iomem *port_data;
47 u8 data_mask;
49 unsigned long phys_addr;
50 void __iomem *virt_addr;
51 unsigned long found;
53 struct w1_bus_master *bus_master;
57 * These functions read and write DDC Data bit.
59 * Using tristate pins, since i can't find any open-drain pin in whole motherboard.
60 * Unfortunately we can't connect to Intel's 82801xx IO controller
61 * since we don't know motherboard schema, which has pretty unused(may be not) GPIO.
63 * I've heard that PIIX also has open drain pin.
65 * Port mapping.
67 static __inline__ u8 matrox_w1_read_reg(struct matrox_device *dev, u8 reg)
69 u8 ret;
71 writeb(reg, dev->port_index);
72 ret = readb(dev->port_data);
73 barrier();
75 return ret;
78 static __inline__ void matrox_w1_write_reg(struct matrox_device *dev, u8 reg, u8 val)
80 writeb(reg, dev->port_index);
81 writeb(val, dev->port_data);
82 wmb();
85 static void matrox_w1_write_ddc_bit(void *data, u8 bit)
87 u8 ret;
88 struct matrox_device *dev = data;
90 if (bit)
91 bit = 0;
92 else
93 bit = dev->data_mask;
95 ret = matrox_w1_read_reg(dev, MATROX_GET_CONTROL);
96 matrox_w1_write_reg(dev, MATROX_GET_CONTROL, ((ret & ~dev->data_mask) | bit));
97 matrox_w1_write_reg(dev, MATROX_GET_DATA, 0x00);
100 static u8 matrox_w1_read_ddc_bit(void *data)
102 u8 ret;
103 struct matrox_device *dev = data;
105 ret = matrox_w1_read_reg(dev, MATROX_GET_DATA);
107 return ret;
110 static void matrox_w1_hw_init(struct matrox_device *dev)
112 matrox_w1_write_reg(dev, MATROX_GET_DATA, 0xFF);
113 matrox_w1_write_reg(dev, MATROX_GET_CONTROL, 0x00);
116 static int matrox_w1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
118 struct matrox_device *dev;
119 int err;
121 if (pdev->vendor != PCI_VENDOR_ID_MATROX || pdev->device != PCI_DEVICE_ID_MATROX_G400)
122 return -ENODEV;
124 dev = kzalloc(sizeof(struct matrox_device) +
125 sizeof(struct w1_bus_master), GFP_KERNEL);
126 if (!dev) {
127 dev_err(&pdev->dev,
128 "%s: Failed to create new matrox_device object.\n",
129 __func__);
130 return -ENOMEM;
134 dev->bus_master = (struct w1_bus_master *)(dev + 1);
137 * True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c
140 dev->phys_addr = pci_resource_start(pdev, 1);
142 dev->virt_addr = ioremap_nocache(dev->phys_addr, 16384);
143 if (!dev->virt_addr) {
144 dev_err(&pdev->dev, "%s: failed to ioremap(0x%lx, %d).\n",
145 __func__, dev->phys_addr, 16384);
146 err = -EIO;
147 goto err_out_free_device;
150 dev->base_addr = dev->virt_addr + MATROX_BASE;
151 dev->port_index = dev->base_addr + MATROX_PORT_INDEX_OFFSET;
152 dev->port_data = dev->base_addr + MATROX_PORT_DATA_OFFSET;
153 dev->data_mask = (MATROX_G400_DDC_DATA);
155 matrox_w1_hw_init(dev);
157 dev->bus_master->data = dev;
158 dev->bus_master->read_bit = &matrox_w1_read_ddc_bit;
159 dev->bus_master->write_bit = &matrox_w1_write_ddc_bit;
161 err = w1_add_master_device(dev->bus_master);
162 if (err)
163 goto err_out_free_device;
165 pci_set_drvdata(pdev, dev);
167 dev->found = 1;
169 dev_info(&pdev->dev, "Matrox G400 GPIO transport layer for 1-wire.\n");
171 return 0;
173 err_out_free_device:
174 if (dev->virt_addr)
175 iounmap(dev->virt_addr);
176 kfree(dev);
178 return err;
181 static void matrox_w1_remove(struct pci_dev *pdev)
183 struct matrox_device *dev = pci_get_drvdata(pdev);
185 if (dev->found) {
186 w1_remove_master_device(dev->bus_master);
187 iounmap(dev->virt_addr);
189 kfree(dev);
192 static struct pci_device_id matrox_w1_tbl[] = {
193 { PCI_DEVICE(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400) },
194 { },
196 MODULE_DEVICE_TABLE(pci, matrox_w1_tbl);
198 static struct pci_driver matrox_w1_pci_driver = {
199 .name = "matrox_w1",
200 .id_table = matrox_w1_tbl,
201 .probe = matrox_w1_probe,
202 .remove = matrox_w1_remove,
204 module_pci_driver(matrox_w1_pci_driver);
206 MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>");
207 MODULE_DESCRIPTION("Driver for transport(Dallas 1-wire protocol) over VGA DDC(matrox gpio).");
208 MODULE_LICENSE("GPL");