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