1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Driver for the NXP ISP1760 chip
4  *
5  * Copyright 2014 Laurent Pinchart
6  * Copyright 2007 Sebastian Siewior
7  *
8  * Contacts:
9  *	Sebastian Siewior <bigeasy@linutronix.de>
10  *	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
11  */
12 
13 #ifndef _ISP1760_CORE_H_
14 #define _ISP1760_CORE_H_
15 
16 #include <linux/ioport.h>
17 #include <linux/regmap.h>
18 
19 #include "isp1760-hcd.h"
20 #include "isp1760-udc.h"
21 
22 struct device;
23 struct gpio_desc;
24 
25 /*
26  * Device flags that can vary from board to board.  All of these
27  * indicate the most "atypical" case, so that a devflags of 0 is
28  * a sane default configuration.
29  */
30 #define ISP1760_FLAG_BUS_WIDTH_16	0x00000002 /* 16-bit data bus width */
31 #define ISP1760_FLAG_PERIPHERAL_EN	0x00000004 /* Port 1 supports Peripheral mode*/
32 #define ISP1760_FLAG_ANALOG_OC		0x00000008 /* Analog overcurrent */
33 #define ISP1760_FLAG_DACK_POL_HIGH	0x00000010 /* DACK active high */
34 #define ISP1760_FLAG_DREQ_POL_HIGH	0x00000020 /* DREQ active high */
35 #define ISP1760_FLAG_ISP1761		0x00000040 /* Chip is ISP1761 */
36 #define ISP1760_FLAG_INTR_POL_HIGH	0x00000080 /* Interrupt polarity active high */
37 #define ISP1760_FLAG_INTR_EDGE_TRIG	0x00000100 /* Interrupt edge triggered */
38 
39 struct isp1760_device {
40 	struct device *dev;
41 
42 	unsigned int devflags;
43 	struct gpio_desc *rst_gpio;
44 
45 	struct isp1760_hcd hcd;
46 	struct isp1760_udc udc;
47 };
48 
49 int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
50 		     struct device *dev, unsigned int devflags);
51 void isp1760_unregister(struct device *dev);
52 
53 void isp1760_set_pullup(struct isp1760_device *isp, bool enable);
54 
55 static inline u32 isp1760_field_read(struct regmap_field **fields, u32 field)
56 {
57 	unsigned int val;
58 
59 	regmap_field_read(fields[field], &val);
60 
61 	return val;
62 }
63 
64 static inline void isp1760_field_write(struct regmap_field **fields, u32 field,
65 				       u32 val)
66 {
67 	regmap_field_write(fields[field], val);
68 }
69 
70 static inline void isp1760_field_set(struct regmap_field **fields, u32 field)
71 {
72 	isp1760_field_write(fields, field, 0xFFFFFFFF);
73 }
74 
75 static inline void isp1760_field_clear(struct regmap_field **fields, u32 field)
76 {
77 	isp1760_field_write(fields, field, 0);
78 }
79 
80 static inline u32 isp1760_reg_read(struct regmap *regs, u32 reg)
81 {
82 	unsigned int val;
83 
84 	regmap_read(regs, reg, &val);
85 
86 	return val;
87 }
88 
89 static inline void isp1760_reg_write(struct regmap *regs, u32 reg, u32 val)
90 {
91 	regmap_write(regs, reg, val);
92 }
93 #endif
94