ptp_ocp.c (5a728ac578c07f29d8b36bbd907cdea132c1607d) | ptp_ocp.c (aa56a7ffc0fb9ad5f754af79ee91ebe9ec96f28d) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* Copyright (c) 2020 Facebook */ 3 4#include <linux/err.h> 5#include <linux/kernel.h> 6#include <linux/module.h> 7#include <linux/debugfs.h> 8#include <linux/init.h> --- 307 unchanged lines hidden (view full) --- 316 bool has_eeprom_data; 317 u32 pps_req_map; 318 int flash_start; 319 u32 utc_tai_offset; 320 u32 ts_window_adjust; 321 u64 fw_cap; 322 struct ptp_ocp_signal signal[4]; 323 struct ptp_ocp_sma_connector sma[4]; | 1// SPDX-License-Identifier: GPL-2.0-only 2/* Copyright (c) 2020 Facebook */ 3 4#include <linux/err.h> 5#include <linux/kernel.h> 6#include <linux/module.h> 7#include <linux/debugfs.h> 8#include <linux/init.h> --- 307 unchanged lines hidden (view full) --- 316 bool has_eeprom_data; 317 u32 pps_req_map; 318 int flash_start; 319 u32 utc_tai_offset; 320 u32 ts_window_adjust; 321 u64 fw_cap; 322 struct ptp_ocp_signal signal[4]; 323 struct ptp_ocp_sma_connector sma[4]; |
324 u8 sma_tbl; |
|
324}; 325 326#define OCP_REQ_TIMESTAMP BIT(0) 327#define OCP_REQ_PPS BIT(1) 328 329struct ocp_resource { 330 unsigned long offset; 331 int size; --- 362 unchanged lines hidden (view full) --- 694 { .name = "GEN2", .value = 0x0080 }, 695 { .name = "GEN3", .value = 0x0100 }, 696 { .name = "GEN4", .value = 0x0200 }, 697 { .name = "GND", .value = 0x2000 }, 698 { .name = "VCC", .value = 0x4000 }, 699 { } 700}; 701 | 325}; 326 327#define OCP_REQ_TIMESTAMP BIT(0) 328#define OCP_REQ_PPS BIT(1) 329 330struct ocp_resource { 331 unsigned long offset; 332 int size; --- 362 unchanged lines hidden (view full) --- 695 { .name = "GEN2", .value = 0x0080 }, 696 { .name = "GEN3", .value = 0x0100 }, 697 { .name = "GEN4", .value = 0x0200 }, 698 { .name = "GND", .value = 0x2000 }, 699 { .name = "VCC", .value = 0x4000 }, 700 { } 701}; 702 |
703static struct ocp_selector *ocp_sma_tbl[][2] = { 704 { ptp_ocp_sma_in, ptp_ocp_sma_out }, 705}; 706 |
|
702static const char * 703ptp_ocp_select_name_from_val(struct ocp_selector *tbl, int val) 704{ 705 int i; 706 707 for (i = 0; tbl[i].name; i++) 708 if (tbl[i].value == val) 709 return tbl[i].name; --- 1373 unchanged lines hidden (view full) --- 2083 * ANT0 == gps (in) 2084 * ANT1 == sma1 (in) 2085 * ANT2 == sma2 (in) 2086 * ANT3 == sma3 (out) 2087 * ANT4 == sma4 (out) 2088 */ 2089 2090static ssize_t | 707static const char * 708ptp_ocp_select_name_from_val(struct ocp_selector *tbl, int val) 709{ 710 int i; 711 712 for (i = 0; tbl[i].name; i++) 713 if (tbl[i].value == val) 714 return tbl[i].name; --- 1373 unchanged lines hidden (view full) --- 2088 * ANT0 == gps (in) 2089 * ANT1 == sma1 (in) 2090 * ANT2 == sma2 (in) 2091 * ANT3 == sma3 (out) 2092 * ANT4 == sma4 (out) 2093 */ 2094 2095static ssize_t |
2091ptp_ocp_show_output(u32 val, char *buf, int def_val) | 2096ptp_ocp_show_output(struct ocp_selector *tbl, u32 val, char *buf, int def_val) |
2092{ 2093 const char *name; 2094 ssize_t count; 2095 2096 count = sysfs_emit(buf, "OUT: "); | 2097{ 2098 const char *name; 2099 ssize_t count; 2100 2101 count = sysfs_emit(buf, "OUT: "); |
2097 name = ptp_ocp_select_name_from_val(ptp_ocp_sma_out, val); | 2102 name = ptp_ocp_select_name_from_val(tbl, val); |
2098 if (!name) | 2103 if (!name) |
2099 name = ptp_ocp_select_name_from_val(ptp_ocp_sma_out, def_val); | 2104 name = ptp_ocp_select_name_from_val(tbl, def_val); |
2100 count += sysfs_emit_at(buf, count, "%s\n", name); 2101 return count; 2102} 2103 2104static ssize_t | 2105 count += sysfs_emit_at(buf, count, "%s\n", name); 2106 return count; 2107} 2108 2109static ssize_t |
2105ptp_ocp_show_inputs(u32 val, char *buf, int def_val) | 2110ptp_ocp_show_inputs(struct ocp_selector *tbl, u32 val, char *buf, int def_val) |
2106{ 2107 const char *name; 2108 ssize_t count; 2109 int i; 2110 2111 count = sysfs_emit(buf, "IN: "); | 2111{ 2112 const char *name; 2113 ssize_t count; 2114 int i; 2115 2116 count = sysfs_emit(buf, "IN: "); |
2112 for (i = 0; i < ARRAY_SIZE(ptp_ocp_sma_in); i++) { 2113 if (val & ptp_ocp_sma_in[i].value) { 2114 name = ptp_ocp_sma_in[i].name; | 2117 for (i = 0; tbl[i].name; i++) { 2118 if (val & tbl[i].value) { 2119 name = tbl[i].name; |
2115 count += sysfs_emit_at(buf, count, "%s ", name); 2116 } 2117 } 2118 if (!val && def_val >= 0) { | 2120 count += sysfs_emit_at(buf, count, "%s ", name); 2121 } 2122 } 2123 if (!val && def_val >= 0) { |
2119 name = ptp_ocp_select_name_from_val(ptp_ocp_sma_in, def_val); | 2124 name = ptp_ocp_select_name_from_val(tbl, def_val); |
2120 count += sysfs_emit_at(buf, count, "%s ", name); 2121 } 2122 if (count) 2123 count--; 2124 count += sysfs_emit_at(buf, count, "\n"); 2125 return count; 2126} 2127 2128static int | 2125 count += sysfs_emit_at(buf, count, "%s ", name); 2126 } 2127 if (count) 2128 count--; 2129 count += sysfs_emit_at(buf, count, "\n"); 2130 return count; 2131} 2132 2133static int |
2129sma_parse_inputs(const char *buf, enum ptp_ocp_sma_mode *mode) | 2134sma_parse_inputs(struct ocp_selector *tbl[], const char *buf, 2135 enum ptp_ocp_sma_mode *mode) |
2130{ | 2136{ |
2131 struct ocp_selector *tbl[] = { ptp_ocp_sma_in, ptp_ocp_sma_out }; | |
2132 int idx, count, dir; 2133 char **argv; 2134 int ret; 2135 2136 argv = argv_split(GFP_KERNEL, buf, &count); 2137 if (!argv) 2138 return -ENOMEM; 2139 --- 42 unchanged lines hidden (view full) --- 2182 return (ioread32(gpio) >> shift) & 0xffff; 2183} 2184 2185static ssize_t 2186ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf, 2187 int default_in_val, int default_out_val) 2188{ 2189 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; | 2137 int idx, count, dir; 2138 char **argv; 2139 int ret; 2140 2141 argv = argv_split(GFP_KERNEL, buf, &count); 2142 if (!argv) 2143 return -ENOMEM; 2144 --- 42 unchanged lines hidden (view full) --- 2187 return (ioread32(gpio) >> shift) & 0xffff; 2188} 2189 2190static ssize_t 2191ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf, 2192 int default_in_val, int default_out_val) 2193{ 2194 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; |
2195 struct ocp_selector **tbl; |
|
2190 u32 val; 2191 | 2196 u32 val; 2197 |
2198 tbl = ocp_sma_tbl[bp->sma_tbl]; 2199 |
|
2192 val = ptp_ocp_sma_get(bp, sma_nr, sma->mode) & SMA_SELECT_MASK; 2193 2194 if (sma->mode == SMA_MODE_IN) { 2195 if (sma->disabled) 2196 val = SMA_DISABLE; | 2200 val = ptp_ocp_sma_get(bp, sma_nr, sma->mode) & SMA_SELECT_MASK; 2201 2202 if (sma->mode == SMA_MODE_IN) { 2203 if (sma->disabled) 2204 val = SMA_DISABLE; |
2197 return ptp_ocp_show_inputs(val, buf, default_in_val); | 2205 return ptp_ocp_show_inputs(tbl[0], val, buf, default_in_val); |
2198 } 2199 | 2206 } 2207 |
2200 return ptp_ocp_show_output(val, buf, default_out_val); | 2208 return ptp_ocp_show_output(tbl[1], val, buf, default_out_val); |
2201} 2202 2203static ssize_t 2204sma1_show(struct device *dev, struct device_attribute *attr, char *buf) 2205{ 2206 struct ptp_ocp *bp = dev_get_drvdata(dev); 2207 2208 return ptp_ocp_sma_show(bp, 1, buf, 0, 1); --- 74 unchanged lines hidden (view full) --- 2283static int 2284ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) 2285{ 2286 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; 2287 enum ptp_ocp_sma_mode mode; 2288 int val; 2289 2290 mode = sma->mode; | 2209} 2210 2211static ssize_t 2212sma1_show(struct device *dev, struct device_attribute *attr, char *buf) 2213{ 2214 struct ptp_ocp *bp = dev_get_drvdata(dev); 2215 2216 return ptp_ocp_sma_show(bp, 1, buf, 0, 1); --- 74 unchanged lines hidden (view full) --- 2291static int 2292ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) 2293{ 2294 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; 2295 enum ptp_ocp_sma_mode mode; 2296 int val; 2297 2298 mode = sma->mode; |
2291 val = sma_parse_inputs(buf, &mode); | 2299 val = sma_parse_inputs(ocp_sma_tbl[bp->sma_tbl], buf, &mode); |
2292 if (val < 0) 2293 return val; 2294 2295 if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) 2296 return -EOPNOTSUPP; 2297 2298 if (sma->fixed_fcn) { 2299 if (val != ((sma_nr - 1) & 1)) --- 72 unchanged lines hidden (view full) --- 2372static DEVICE_ATTR_RW(sma2); 2373static DEVICE_ATTR_RW(sma3); 2374static DEVICE_ATTR_RW(sma4); 2375 2376static ssize_t 2377available_sma_inputs_show(struct device *dev, 2378 struct device_attribute *attr, char *buf) 2379{ | 2300 if (val < 0) 2301 return val; 2302 2303 if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) 2304 return -EOPNOTSUPP; 2305 2306 if (sma->fixed_fcn) { 2307 if (val != ((sma_nr - 1) & 1)) --- 72 unchanged lines hidden (view full) --- 2380static DEVICE_ATTR_RW(sma2); 2381static DEVICE_ATTR_RW(sma3); 2382static DEVICE_ATTR_RW(sma4); 2383 2384static ssize_t 2385available_sma_inputs_show(struct device *dev, 2386 struct device_attribute *attr, char *buf) 2387{ |
2380 return ptp_ocp_select_table_show(ptp_ocp_sma_in, buf); | 2388 struct ptp_ocp *bp = dev_get_drvdata(dev); 2389 2390 return ptp_ocp_select_table_show(ocp_sma_tbl[bp->sma_tbl][0], buf); |
2381} 2382static DEVICE_ATTR_RO(available_sma_inputs); 2383 2384static ssize_t 2385available_sma_outputs_show(struct device *dev, 2386 struct device_attribute *attr, char *buf) 2387{ | 2391} 2392static DEVICE_ATTR_RO(available_sma_inputs); 2393 2394static ssize_t 2395available_sma_outputs_show(struct device *dev, 2396 struct device_attribute *attr, char *buf) 2397{ |
2388 return ptp_ocp_select_table_show(ptp_ocp_sma_out, buf); | 2398 struct ptp_ocp *bp = dev_get_drvdata(dev); 2399 2400 return ptp_ocp_select_table_show(ocp_sma_tbl[bp->sma_tbl][1], buf); |
2389} 2390static DEVICE_ATTR_RO(available_sma_outputs); 2391 2392#define EXT_ATTR_RO(_group, _name, _val) \ 2393 struct dev_ext_attribute dev_attr_##_group##_val##_##_name = \ 2394 { __ATTR_RO(_name), (void *)_val } 2395#define EXT_ATTR_RW(_group, _name, _val) \ 2396 struct dev_ext_attribute dev_attr_##_group##_val##_##_name = \ --- 1377 unchanged lines hidden --- | 2401} 2402static DEVICE_ATTR_RO(available_sma_outputs); 2403 2404#define EXT_ATTR_RO(_group, _name, _val) \ 2405 struct dev_ext_attribute dev_attr_##_group##_val##_##_name = \ 2406 { __ATTR_RO(_name), (void *)_val } 2407#define EXT_ATTR_RW(_group, _name, _val) \ 2408 struct dev_ext_attribute dev_attr_##_group##_val##_##_name = \ --- 1377 unchanged lines hidden --- |